Debian Codegraph @

external/blake3/blake3.h

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