Line data Source code
1 : // Source originally from https://github.com/BLAKE3-team/BLAKE3 2 : // From commit: df610ddc3b93841ffc59a87e3da659a15910eb46 3 : 4 : #ifndef BLAKE3_H 5 : #define BLAKE3_H 6 : 7 : #include <stddef.h> 8 : #include <stdint.h> 9 : 10 : #ifdef __cplusplus 11 : extern "C" { 12 : #endif 13 : 14 : #define BLAKE3_API 15 : 16 0 : #define BLAKE3_VERSION_STRING "1.8.2" 17 52429839 : #define BLAKE3_KEY_LEN 32 18 20112854 : #define BLAKE3_OUT_LEN 32 19 349473688 : #define BLAKE3_BLOCK_LEN 64 20 58147185 : #define BLAKE3_CHUNK_LEN 1024 21 : #define BLAKE3_MAX_DEPTH 54 22 : 23 : // This struct is a private implementation detail. It has to be here because 24 : // it's part of blake3_hasher below. 25 : typedef struct { 26 : uint32_t cv[8]; 27 : uint64_t chunk_counter; 28 : uint8_t buf[BLAKE3_BLOCK_LEN]; 29 : uint8_t buf_len; 30 : uint8_t blocks_compressed; 31 : uint8_t flags; 32 : } blake3_chunk_state; 33 : 34 : typedef struct { 35 : uint32_t key[8]; 36 : blake3_chunk_state chunk; 37 : uint8_t cv_stack_len; 38 : // The stack size is MAX_DEPTH + 1 because we do lazy merging. For example, 39 : // with 7 chunks, we have 3 entries in the stack. Adding an 8th chunk 40 : // requires a 4th entry, rather than merging everything down to 1, because we 41 : // don't know whether more input is coming. This is different from how the 42 : // reference implementation does things. 43 : uint8_t cv_stack[(BLAKE3_MAX_DEPTH + 1) * BLAKE3_OUT_LEN]; 44 : } blake3_hasher; 45 : 46 : BLAKE3_API const char *blake3_version(void); 47 : BLAKE3_API void blake3_hasher_init(blake3_hasher *self); 48 : BLAKE3_API void blake3_hasher_init_keyed(blake3_hasher *self, 49 : const uint8_t key[BLAKE3_KEY_LEN]); 50 : BLAKE3_API void blake3_hasher_init_derive_key(blake3_hasher *self, const char *context); 51 : BLAKE3_API void blake3_hasher_init_derive_key_raw(blake3_hasher *self, const void *context, 52 : size_t context_len); 53 : BLAKE3_API void blake3_hasher_update(blake3_hasher *self, const void *input, 54 : size_t input_len); 55 : BLAKE3_API void blake3_hasher_finalize(const blake3_hasher *self, uint8_t *out, 56 : size_t out_len); 57 : BLAKE3_API void blake3_hasher_finalize_seek(const blake3_hasher *self, uint64_t seek, 58 : uint8_t *out, size_t out_len); 59 : BLAKE3_API void blake3_hasher_reset(blake3_hasher *self); 60 : 61 : #ifdef __cplusplus 62 : } 63 : #endif 64 : 65 : #endif /* BLAKE3_H */