Debian Codegraph @

debian/rust-vendor/blake3/c/blake3.h

raw
1 #ifndef BLAKE3_H
2 #define BLAKE3_H
3
4 #include <stddef.h>
5 #include <stdint.h>
6
7 #if !defined(BLAKE3_API)
8 # if defined(_WIN32) || defined(__CYGWIN__)
9 # if defined(BLAKE3_DLL)
10 # if defined(BLAKE3_DLL_EXPORTS)
11 # define BLAKE3_API __declspec(dllexport)
12 # else
13 # define BLAKE3_API __declspec(dllimport)
14 # endif
15 # define BLAKE3_PRIVATE
16 # else
17 # define BLAKE3_API
18 # define BLAKE3_PRIVATE
19 # endif
20 # elif __GNUC__ >= 4
21 # define BLAKE3_API __attribute__((visibility("default")))
22 # define BLAKE3_PRIVATE __attribute__((visibility("hidden")))
23 # else
24 # define BLAKE3_API
25 # define BLAKE3_PRIVATE
26 # endif
27 #endif
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 #define BLAKE3_VERSION_STRING "1.8.7"
34 #define BLAKE3_KEY_LEN 32
35 #define BLAKE3_OUT_LEN 32
36 #define BLAKE3_BLOCK_LEN 64
37 #define BLAKE3_CHUNK_LEN 1024
38 #define BLAKE3_MAX_DEPTH 54
39
40 // This struct is a private implementation detail. It has to be here because
41 // it's part of the blake3_hasher structure defined below.
42 typedef struct {
43 uint32_t cv[8];
44 uint64_t chunk_counter;
45 uint8_t buf[BLAKE3_BLOCK_LEN];
46 uint8_t buf_len;
47 uint8_t blocks_compressed;
48 uint8_t flags;
49 } blake3_chunk_state;
50
51 typedef struct {
52 uint32_t key[8];
53 blake3_chunk_state chunk;
54 uint8_t cv_stack_len;
55 // The stack size is MAX_DEPTH + 1 because we do lazy merging. For example,
56 // with 7 chunks, we have 3 entries in the stack. Adding an 8th chunk
57 // requires a 4th entry, rather than merging everything down to 1, because we
58 // don't know whether more input is coming. This is different from how the
59 // reference implementation does things.
60 uint8_t cv_stack[(BLAKE3_MAX_DEPTH + 1) * BLAKE3_OUT_LEN];
61 } blake3_hasher;
62
63 BLAKE3_API const char *blake3_version(void);
64 BLAKE3_API void blake3_hasher_init(blake3_hasher *self);
65 BLAKE3_API void blake3_hasher_init_keyed(blake3_hasher *self,
66 const uint8_t key[BLAKE3_KEY_LEN]);
67 BLAKE3_API void blake3_hasher_init_derive_key(blake3_hasher *self, const char *context);
68 BLAKE3_API void blake3_hasher_init_derive_key_raw(blake3_hasher *self, const void *context,
69 size_t context_len);
70 BLAKE3_API void blake3_hasher_update(blake3_hasher *self, const void *input,
71 size_t input_len);
72 #if defined(BLAKE3_USE_TBB)
73 BLAKE3_API void blake3_hasher_update_tbb(blake3_hasher *self, const void *input,
74 size_t input_len);
75 #endif // BLAKE3_USE_TBB
76 BLAKE3_API void blake3_hasher_finalize(const blake3_hasher *self, uint8_t *out,
77 size_t out_len);
78 BLAKE3_API void blake3_hasher_finalize_seek(const blake3_hasher *self, uint64_t seek,
79 uint8_t *out, size_t out_len);
80 BLAKE3_API void blake3_hasher_reset(blake3_hasher *self);
81
82 #ifdef __cplusplus
83 }
84 #endif
85
86 #endif /* BLAKE3_H */