chibipub

experimental activitypub node in C
git clone git://jb55.com/chibipub
Log | Files | Refs | README | LICENSE

blake3.h (1974B)


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