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