Debian Codegraph @

external/blake3/blake3_impl.h

raw symbols SCIP
1 #cxx . . $ `<file>/external/blake3/blake3_impl.h`/ifndef BLAKE3_IMPL_H
2 #define BLAKE3_IMPL_Hcxx . . $ `external/blake3/blake3_impl.h:2:9`!
3
4 #include <assert.h>
5 #include <stdbool.h>
6 #include <stddef.h>
7 #include <stdint.h>
8 #include <string.h>
9
10 #include "blake3.h"cxx . . $ `<file>/external/blake3/blake3.h`/
11
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15
16 // internal flags
17 enum blake3_flagscxx . . $ blake3_flags# {
18 CHUNK_STARTcxx . . $ CHUNK_START. = 1 << 0,
19 CHUNK_ENDcxx . . $ CHUNK_END. = 1 << 1,
20 PARENTcxx . . $ PARENT. = 1 << 2,
21 ROOTcxx . . $ ROOT. = 1 << 3,
22 KEYED_HASHcxx . . $ KEYED_HASH. = 1 << 4,
23 DERIVE_KEY_CONTEXTcxx . . $ DERIVE_KEY_CONTEXT. = 1 << 5,
24 DERIVE_KEY_MATERIALcxx . . $ DERIVE_KEY_MATERIAL. = 1 << 6,
25 };
26
27 // This C implementation tries to support recent versions of GCC, Clang, and
28 // MSVC.
29 #if defined(_MSC_VER)
30 #define INLINE static __forceinline
31 #else
32 #define INLINEcxx . . $ `external/blake3/blake3_impl.h:32:9`! static inline __attribute__((always_inline))
33 #endif
34
35 #ifdef __cplusplus
36 #define NOEXCEPT noexcept
37 #else
38 #define NOEXCEPTcxx . . $ `external/blake3/blake3_impl.h:38:9`!
39 #endif
40
41 #if (defined(__x86_64__cxx . . $ `<built-in>:374:9`!) || defined(_M_X64)) && !defined(_M_ARM64EC)
42 #define IS_X86cxx . . $ `external/blake3/blake3_impl.h:42:9`!
43 #define IS_X86_64cxx . . $ `external/blake3/blake3_impl.h:43:9`!
44 #endif
45
46 #if defined(__i386__) || defined(_M_IX86)
47 #define IS_X86
48 #define IS_X86_32
49 #endif
50
51 #if defined(__aarch64__) || defined(_M_ARM64) || defined(_M_ARM64EC)
52 #define IS_AARCH64
53 #endif
54
55 #if defined(IS_X86cxx . . $ `external/blake3/blake3_impl.h:42:9`!)
56 #if defined(_MSC_VER)
57 #include <intrin.h>
58 #endif
59 #endif
60
61 #if !defined(BLAKE3_USE_NEONcxx . . $ `external/blake3/blake3.h:13:9`!)
62 // If BLAKE3_USE_NEON not manually set, autodetect based on AArch64ness
63 #if defined(IS_AARCH64)
64 #if defined(__ARM_BIG_ENDIAN)
65 #define BLAKE3_USE_NEON 0
66 #else
67 #define BLAKE3_USE_NEON 1
68 #endif
69 #else
70 #define BLAKE3_USE_NEON 0
71 #endif
72 #endif
73
74 #if defined(IS_X86cxx . . $ `external/blake3/blake3_impl.h:42:9`!)
75 #define MAX_SIMD_DEGREEcxx . . $ `external/blake3/blake3_impl.h:75:9`! 16
76 #elif BLAKE3_USE_NEON == 1
77 #define MAX_SIMD_DEGREE 4
78 #else
79 #define MAX_SIMD_DEGREE 1
80 #endif
81
82 // There are some places where we want a static size that's equal to the
83 // MAX_SIMD_DEGREE, but also at least 2.
84 #define MAX_SIMD_DEGREE_OR_2cxx . . $ `external/blake3/blake3_impl.h:84:9`! (MAX_SIMD_DEGREEcxx . . $ `external/blake3/blake3_impl.h:75:9`! > 2 ? MAX_SIMD_DEGREEcxx . . $ `external/blake3/blake3_impl.h:75:9`! : 2)
85
86 static const uint32_tcxx . . $ uint32_t# IVcxx . . $ IV.[8] = {0x6A09E667UL, 0xBB67AE85UL, 0x3C6EF372UL,
87 0xA54FF53AUL, 0x510E527FUL, 0x9B05688CUL,
88 0x1F83D9ABUL, 0x5BE0CD19UL};
89
90 static const uint8_tcxx . . $ uint8_t# MSG_SCHEDULEcxx . . $ MSG_SCHEDULE.[7][16] = {
91 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
92 {2, 6, 3, 10, 7, 0, 4, 13, 1, 11, 12, 5, 9, 14, 15, 8},
93 {3, 4, 10, 12, 13, 2, 7, 14, 6, 5, 9, 0, 11, 15, 8, 1},
94 {10, 7, 12, 9, 14, 3, 13, 15, 4, 0, 11, 2, 5, 8, 1, 6},
95 {12, 13, 9, 11, 15, 10, 14, 8, 7, 2, 5, 3, 0, 1, 6, 4},
96 {9, 14, 11, 5, 8, 12, 15, 1, 13, 3, 0, 10, 2, 6, 4, 7},
97 {11, 15, 5, 0, 1, 9, 8, 6, 14, 10, 2, 12, 3, 4, 7, 13},
98 };
99
100 /* Find index of the highest set bit */
101 /* x is assumed to be nonzero. */
102 static unsigned int highest_onecxx . . $ highest_one(ea88b852781e8a38).(uint64_tcxx . . $ uint64_t# x) {
103 #if defined(__GNUC__cxx . . $ `<built-in>:8:9`!) || defined(__clang__cxx . . $ `<built-in>:3:9`!)
104 return 63 ^ (unsigned int)__builtin_clzllcxx . . $ __builtin_clzll(642c2e9948c4ad2).(x);
105 #elif defined(_MSC_VER) && defined(IS_X86_64)
106 unsigned long index;
107 _BitScanReverse64(&index, x);
108 return index;
109 #elif defined(_MSC_VER) && defined(IS_X86_32)
110 if(x >> 32) {
111 unsigned long index;
112 _BitScanReverse(&index, (unsigned long)(x >> 32));
113 return 32 + index;
114 } else {
115 unsigned long index;
116 _BitScanReverse(&index, (unsigned long)x);
117 return index;
118 }
119 #else
120 unsigned int c = 0;
121 if(x & 0xffffffff00000000ULL) { x >>= 32; c += 32; }
122 if(x & 0x00000000ffff0000ULL) { x >>= 16; c += 16; }
123 if(x & 0x000000000000ff00ULL) { x >>= 8; c += 8; }
124 if(x & 0x00000000000000f0ULL) { x >>= 4; c += 4; }
125 if(x & 0x000000000000000cULL) { x >>= 2; c += 2; }
126 if(x & 0x0000000000000002ULL) { c += 1; }
127 return c;
128 #endif
129 }
130
131 // Count the number of 1 bits.
132 INLINEcxx . . $ `external/blake3/blake3_impl.h:32:9`! unsigned int popcntcxx . . $ popcnt(ea88b852781e8a38).(uint64_tcxx . . $ uint64_t# x) {
133 #if defined(__GNUC__cxx . . $ `<built-in>:8:9`!) || defined(__clang__cxx . . $ `<built-in>:3:9`!)
134 return (unsigned int)__builtin_popcountllcxx . . $ __builtin_popcountll(642c2e9948c4ad2).(x);
135 #else
136 unsigned int count = 0;
137 while (x != 0) {
138 count += 1;
139 x &= x - 1;
140 }
141 return count;
142 #endif
143 }
144
145 // Largest power of two less than or equal to x. As a special case, returns 1
146 // when x is 0.
147 INLINEcxx . . $ `external/blake3/blake3_impl.h:32:9`! uint64_tcxx . . $ uint64_t# round_down_to_power_of_2cxx . . $ round_down_to_power_of_2(ecdaa1632f49f591).(uint64_tcxx . . $ uint64_t# x) {
148 return 1ULL << highest_onecxx . . $ highest_one(ea88b852781e8a38).(x | 1);
149 }
150
151 INLINEcxx . . $ `external/blake3/blake3_impl.h:32:9`! uint32_tcxx . . $ uint32_t# counter_lowcxx . . $ counter_low(ea88b852781e8a38).(uint64_tcxx . . $ uint64_t# counter) { return (uint32_tcxx . . $ uint32_t#)counter; }
152
153 INLINEcxx . . $ `external/blake3/blake3_impl.h:32:9`! uint32_tcxx . . $ uint32_t# counter_highcxx . . $ counter_high(ea88b852781e8a38).(uint64_tcxx . . $ uint64_t# counter) {
154 return (uint32_tcxx . . $ uint32_t#)(counter >> 32);
155 }
156
157 INLINEcxx . . $ `external/blake3/blake3_impl.h:32:9`! uint32_tcxx . . $ uint32_t# load32cxx . . $ load32(b11f534102b1ad6).(const void *src) {
158 const uint8_tcxx . . $ uint8_t# *p = (const uint8_tcxx . . $ uint8_t# *)src;
159 return ((uint32_tcxx . . $ uint32_t#)(p[0]) << 0) | ((uint32_tcxx . . $ uint32_t#)(p[1]) << 8) |
160 ((uint32_tcxx . . $ uint32_t#)(p[2]) << 16) | ((uint32_tcxx . . $ uint32_t#)(p[3]) << 24);
161 }
162
163 INLINEcxx . . $ `external/blake3/blake3_impl.h:32:9`! void load_key_wordscxx . . $ load_key_words(c4f0954631f88756).(const uint8_tcxx . . $ uint8_t# key[BLAKE3_KEY_LENcxx . . $ `external/blake3/blake3.h:42:9`!],
164 uint32_tcxx . . $ uint32_t# key_words[8]) {
165 key_words[0] = load32cxx . . $ load32(b11f534102b1ad6).(&key[0 * 4]);
166 key_words[1] = load32cxx . . $ load32(b11f534102b1ad6).(&key[1 * 4]);
167 key_words[2] = load32cxx . . $ load32(b11f534102b1ad6).(&key[2 * 4]);
168 key_words[3] = load32cxx . . $ load32(b11f534102b1ad6).(&key[3 * 4]);
169 key_words[4] = load32cxx . . $ load32(b11f534102b1ad6).(&key[4 * 4]);
170 key_words[5] = load32cxx . . $ load32(b11f534102b1ad6).(&key[5 * 4]);
171 key_words[6] = load32cxx . . $ load32(b11f534102b1ad6).(&key[6 * 4]);
172 key_words[7] = load32cxx . . $ load32(b11f534102b1ad6).(&key[7 * 4]);
173 }
174
175 INLINEcxx . . $ `external/blake3/blake3_impl.h:32:9`! void load_block_wordscxx . . $ load_block_words(c4f0954631f88756).(const uint8_tcxx . . $ uint8_t# block[BLAKE3_BLOCK_LENcxx . . $ `external/blake3/blake3.h:44:9`!],
176 uint32_tcxx . . $ uint32_t# block_words[16]) {
177 for (size_tcxx . . $ size_t# i = 0; i < 16; i++) {
178 block_words[i] = load32cxx . . $ load32(b11f534102b1ad6).(&block[i * 4]);
179 }
180 }
181
182 INLINEcxx . . $ `external/blake3/blake3_impl.h:32:9`! void store32cxx . . $ store32(67abb4dd43ac34c5).(void *dst, uint32_tcxx . . $ uint32_t# w) {
183 uint8_tcxx . . $ uint8_t# *p = (uint8_tcxx . . $ uint8_t# *)dst;
184 p[0] = (uint8_tcxx . . $ uint8_t#)(w >> 0);
185 p[1] = (uint8_tcxx . . $ uint8_t#)(w >> 8);
186 p[2] = (uint8_tcxx . . $ uint8_t#)(w >> 16);
187 p[3] = (uint8_tcxx . . $ uint8_t#)(w >> 24);
188 }
189
190 INLINEcxx . . $ `external/blake3/blake3_impl.h:32:9`! void store_cv_wordscxx . . $ store_cv_words(3dae8022d7d56a90).(uint8_tcxx . . $ uint8_t# bytes_out[32], uint32_tcxx . . $ uint32_t# cv_words[8]) {
191 store32cxx . . $ store32(67abb4dd43ac34c5).(&bytes_out[0 * 4], cv_words[0]);
192 store32cxx . . $ store32(67abb4dd43ac34c5).(&bytes_out[1 * 4], cv_words[1]);
193 store32cxx . . $ store32(67abb4dd43ac34c5).(&bytes_out[2 * 4], cv_words[2]);
194 store32cxx . . $ store32(67abb4dd43ac34c5).(&bytes_out[3 * 4], cv_words[3]);
195 store32cxx . . $ store32(67abb4dd43ac34c5).(&bytes_out[4 * 4], cv_words[4]);
196 store32cxx . . $ store32(67abb4dd43ac34c5).(&bytes_out[5 * 4], cv_words[5]);
197 store32cxx . . $ store32(67abb4dd43ac34c5).(&bytes_out[6 * 4], cv_words[6]);
198 store32cxx . . $ store32(67abb4dd43ac34c5).(&bytes_out[7 * 4], cv_words[7]);
199 }
200
201 void blake3_compress_in_placecxx . . $ blake3_compress_in_place(389a45aab4533bf).(uint32_tcxx . . $ uint32_t# cv[8],
202 const uint8_tcxx . . $ uint8_t# block[BLAKE3_BLOCK_LENcxx . . $ `external/blake3/blake3.h:44:9`!],
203 uint8_tcxx . . $ uint8_t# block_len, uint64_tcxx . . $ uint64_t# counter,
204 uint8_tcxx . . $ uint8_t# flags);
205
206 void blake3_compress_xofcxx . . $ blake3_compress_xof(bd57d77544a3558d).(const uint32_tcxx . . $ uint32_t# cv[8],
207 const uint8_tcxx . . $ uint8_t# block[BLAKE3_BLOCK_LENcxx . . $ `external/blake3/blake3.h:44:9`!],
208 uint8_tcxx . . $ uint8_t# block_len, uint64_tcxx . . $ uint64_t# counter, uint8_tcxx . . $ uint8_t# flags,
209 uint8_tcxx . . $ uint8_t# out[64]);
210
211 void blake3_xof_manycxx . . $ blake3_xof_many(79b1dc8506f1c101).(const uint32_tcxx . . $ uint32_t# cv[8],
212 const uint8_tcxx . . $ uint8_t# block[BLAKE3_BLOCK_LENcxx . . $ `external/blake3/blake3.h:44:9`!],
213 uint8_tcxx . . $ uint8_t# block_len, uint64_tcxx . . $ uint64_t# counter, uint8_tcxx . . $ uint8_t# flags,
214 uint8_tcxx . . $ uint8_t# out[64], size_tcxx . . $ size_t# outblocks);
215
216 void blake3_hash_manycxx . . $ blake3_hash_many(6d9d480067751c4).(const uint8_tcxx . . $ uint8_t# *const *inputs, size_tcxx . . $ size_t# num_inputs,
217 size_tcxx . . $ size_t# blocks, const uint32_tcxx . . $ uint32_t# key[8], uint64_tcxx . . $ uint64_t# counter,
218 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! increment_counter, uint8_tcxx . . $ uint8_t# flags,
219 uint8_tcxx . . $ uint8_t# flags_start, uint8_tcxx . . $ uint8_t# flags_end, uint8_tcxx . . $ uint8_t# *out);
220
221 size_tcxx . . $ size_t# blake3_simd_degreecxx . . $ blake3_simd_degree(f708dce9a8856c70).(void);
222
223 BLAKE3_PRIVATEcxx . . $ `external/blake3/blake3.h:30:12`! size_tcxx . . $ size_t# blake3_compress_subtree_widecxx . . $ blake3_compress_subtree_wide(813e9ce5a527dc66).(const uint8_tcxx . . $ uint8_t# *input, size_tcxx . . $ size_t# input_len,
224 const uint32_tcxx . . $ uint32_t# key[8],
225 uint64_tcxx . . $ uint64_t# chunk_counter, uint8_tcxx . . $ uint8_t# flags,
226 uint8_tcxx . . $ uint8_t# *out, boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! use_tbb);
227
228 #if defined(BLAKE3_USE_TBB)
229 BLAKE3_PRIVATE void blake3_compress_subtree_wide_join_tbb(
230 // shared params
231 const uint32_t key[8], uint8_t flags, bool use_tbb,
232 // left-hand side params
233 const uint8_t *l_input, size_t l_input_len, uint64_t l_chunk_counter,
234 uint8_t *l_cvs, size_t *l_n,
235 // right-hand side params
236 const uint8_t *r_input, size_t r_input_len, uint64_t r_chunk_counter,
237 uint8_t *r_cvs, size_t *r_n) NOEXCEPT;
238 #endif
239
240 // Declarations for implementation-specific functions.
241 void blake3_compress_in_place_portablecxx . . $ blake3_compress_in_place_portable(389a45aab4533bf).(uint32_tcxx . . $ uint32_t# cv[8],
242 const uint8_tcxx . . $ uint8_t# block[BLAKE3_BLOCK_LENcxx . . $ `external/blake3/blake3.h:44:9`!],
243 uint8_tcxx . . $ uint8_t# block_len, uint64_tcxx . . $ uint64_t# counter,
244 uint8_tcxx . . $ uint8_t# flags);
245
246 void blake3_compress_xof_portablecxx . . $ blake3_compress_xof_portable(bd57d77544a3558d).(const uint32_tcxx . . $ uint32_t# cv[8],
247 const uint8_tcxx . . $ uint8_t# block[BLAKE3_BLOCK_LENcxx . . $ `external/blake3/blake3.h:44:9`!],
248 uint8_tcxx . . $ uint8_t# block_len, uint64_tcxx . . $ uint64_t# counter,
249 uint8_tcxx . . $ uint8_t# flags, uint8_tcxx . . $ uint8_t# out[64]);
250
251 void blake3_hash_many_portablecxx . . $ blake3_hash_many_portable(6d9d480067751c4).(const uint8_tcxx . . $ uint8_t# *const *inputs, size_tcxx . . $ size_t# num_inputs,
252 size_tcxx . . $ size_t# blocks, const uint32_tcxx . . $ uint32_t# key[8],
253 uint64_tcxx . . $ uint64_t# counter, boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! increment_counter,
254 uint8_tcxx . . $ uint8_t# flags, uint8_tcxx . . $ uint8_t# flags_start,
255 uint8_tcxx . . $ uint8_t# flags_end, uint8_tcxx . . $ uint8_t# *out);
256
257 #if defined(IS_X86cxx . . $ `external/blake3/blake3_impl.h:42:9`!)
258 #if !defined(BLAKE3_NO_SSE2cxx . . $ `external/blake3/blake3.h:9:9`!)
259 void blake3_compress_in_place_sse2(uint32_t cv[8],
260 const uint8_t block[BLAKE3_BLOCK_LEN],
261 uint8_t block_len, uint64_t counter,
262 uint8_t flags);
263 void blake3_compress_xof_sse2(const uint32_t cv[8],
264 const uint8_t block[BLAKE3_BLOCK_LEN],
265 uint8_t block_len, uint64_t counter,
266 uint8_t flags, uint8_t out[64]);
267 void blake3_hash_many_sse2(const uint8_t *const *inputs, size_t num_inputs,
268 size_t blocks, const uint32_t key[8],
269 uint64_t counter, bool increment_counter,
270 uint8_t flags, uint8_t flags_start,
271 uint8_t flags_end, uint8_t *out);
272 #endif
273 #if !defined(BLAKE3_NO_SSE41cxx . . $ `external/blake3/blake3.h:10:9`!)
274 void blake3_compress_in_place_sse41(uint32_t cv[8],
275 const uint8_t block[BLAKE3_BLOCK_LEN],
276 uint8_t block_len, uint64_t counter,
277 uint8_t flags);
278 void blake3_compress_xof_sse41(const uint32_t cv[8],
279 const uint8_t block[BLAKE3_BLOCK_LEN],
280 uint8_t block_len, uint64_t counter,
281 uint8_t flags, uint8_t out[64]);
282 void blake3_hash_many_sse41(const uint8_t *const *inputs, size_t num_inputs,
283 size_t blocks, const uint32_t key[8],
284 uint64_t counter, bool increment_counter,
285 uint8_t flags, uint8_t flags_start,
286 uint8_t flags_end, uint8_t *out);
287 #endif
288 #if !defined(BLAKE3_NO_AVX2cxx . . $ `external/blake3/blake3.h:11:9`!)
289 void blake3_hash_many_avx2(const uint8_t *const *inputs, size_t num_inputs,
290 size_t blocks, const uint32_t key[8],
291 uint64_t counter, bool increment_counter,
292 uint8_t flags, uint8_t flags_start,
293 uint8_t flags_end, uint8_t *out);
294 #endif
295 #if !defined(BLAKE3_NO_AVX512cxx . . $ `external/blake3/blake3.h:12:9`!)
296 void blake3_compress_in_place_avx512(uint32_t cv[8],
297 const uint8_t block[BLAKE3_BLOCK_LEN],
298 uint8_t block_len, uint64_t counter,
299 uint8_t flags);
300
301 void blake3_compress_xof_avx512(const uint32_t cv[8],
302 const uint8_t block[BLAKE3_BLOCK_LEN],
303 uint8_t block_len, uint64_t counter,
304 uint8_t flags, uint8_t out[64]);
305
306 void blake3_hash_many_avx512(const uint8_t *const *inputs, size_t num_inputs,
307 size_t blocks, const uint32_t key[8],
308 uint64_t counter, bool increment_counter,
309 uint8_t flags, uint8_t flags_start,
310 uint8_t flags_end, uint8_t *out);
311
312 #if !defined(_WIN32) && !defined(__CYGWIN__)
313 void blake3_xof_many_avx512(const uint32_t cv[8],
314 const uint8_t block[BLAKE3_BLOCK_LEN],
315 uint8_t block_len, uint64_t counter, uint8_t flags,
316 uint8_t* out, size_t outblocks);
317 #endif
318 #endif
319 #endif
320
321 #if BLAKE3_USE_NEONcxx . . $ `external/blake3/blake3.h:13:9`! == 1
322 void blake3_hash_many_neon(const uint8_t *const *inputs, size_t num_inputs,
323 size_t blocks, const uint32_t key[8],
324 uint64_t counter, bool increment_counter,
325 uint8_t flags, uint8_t flags_start,
326 uint8_t flags_end, uint8_t *out);
327 #endif
328
329 #ifdef __cplusplus
330 }
331 #endif
332
333 #endif /* BLAKE3_IMPL_H */