Debian Codegraph @

lib/alg-yescrypt-opt.c

raw symbols SCIP
1 /*-
2 * Copyright 2009 Colin Percival
3 * Copyright 2012-2025 Alexander Peslyak
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 * This file was originally written by Colin Percival as part of the Tarsnap
28 * online backup system.
29 */
30
31 #include "crypt-port.h"cxx . . $ `<file>/lib/crypt-port.h`/
32
33 #if INCLUDE_yescryptcxx . . $ `crypt-hashes.h:23:9`! || INCLUDE_scryptcxx . . $ `crypt-hashes.h:16:9`! || INCLUDE_gost_yescryptcxx . . $ `crypt-hashes.h:13:9`! || \
34 INCLUDE_sm3_yescryptcxx . . $ `crypt-hashes.h:20:9`!
35
36 #pragma GCC diagnostic ignored "-Wcast-align"
37 #pragma GCC diagnostic ignored "-Wconversion"
38 #ifdef __clang__cxx . . $ `<built-in>:3:9`!
39 #pragma GCC diagnostic ignored "-Wtautological-constant-out-of-range-compare"
40 #endif
41
42 /*
43 * AVX and especially XOP speed up Salsa20 a lot, but this mostly matters for
44 * classic scrypt and for YESCRYPT_WORM (which use 8 rounds of Salsa20 per
45 * sub-block), and much less so for YESCRYPT_RW (which uses 2 rounds of Salsa20
46 * per block except during pwxform S-box initialization).
47 */
48 #if 0
49 #ifdef __XOP__
50 #warning "Note: XOP is enabled. That's great."
51 #elif defined(__AVX512VL__)
52 #warning "Note: AVX512VL is enabled. That's great."
53 #elif defined(__AVX__)
54 #warning "Note: AVX is enabled, which is great for classic scrypt and YESCRYPT_WORM, but is sometimes slightly slower than plain SSE2 for YESCRYPT_RW"
55 #elif defined(__SSE2__)
56 #warning "Note: AVX and XOP are not enabled, which is great for YESCRYPT_RW, but they would substantially improve performance at classic scrypt and YESCRYPT_WORM"
57 #elif defined(__x86_64__) || defined(__i386__)
58 #warning "SSE2 not enabled. Expect poor performance."
59 #else
60 #warning "Note: building generic code for non-x86. That's OK."
61 #endif
62 #endif
63
64 /*
65 * The SSE4 code version has fewer instructions than the generic SSE2 version,
66 * but all of the instructions are SIMD, thereby wasting the scalar execution
67 * units. Thus, the generic SSE2 version below actually runs faster on some
68 * CPUs due to its balanced mix of SIMD and scalar instructions.
69 */
70 #undef USE_SSE4_FOR_32BIT
71
72 #ifdef __SSE2__cxx . . $ `<built-in>:385:9`!
73 /*
74 * GCC before 4.9 would by default unnecessarily use store/load (without
75 * SSE4.1) or (V)PEXTR (with SSE4.1 or AVX) instead of simply (V)MOV.
76 * This was tracked as GCC bug 54349.
77 * "-mtune=corei7" works around this, but is only supported for GCC 4.6+.
78 * We use inline asm for pre-4.6 GCC, further down this file.
79 */
80 #if __GNUC__cxx . . $ `<built-in>:8:9`! == 4 && __GNUC_MINOR__cxx . . $ `<built-in>:9:9`! >= 6 && __GNUC_MINOR__cxx . . $ `<built-in>:9:9`! < 9 && \
81 !defined(__clang__cxx . . $ `<built-in>:3:9`!) && !defined(__ICC)
82 #pragma GCC target ("tune=corei7")
83 #endif
84 #include <emmintrin.h>
85 #ifdef __XOP__
86 #include <x86intrin.h>
87 #elif defined(__AVX512VL__)
88 #include <immintrin.h>
89 #endif
90 #elif defined(__SSE__)
91 #include <xmmintrin.h>
92 #endif
93
94 #include <assert.h>
95 #include <errno.h>
96 #include <stdint.h>
97 #include <stdlib.h>
98 #include <string.h>
99
100 #include "alg-sha256.h"cxx . . $ `<file>/lib/alg-sha256.h`/
101 #include "byteorder.h"cxx . . $ `<file>/lib/byteorder.h`/
102
103 #define YESCRYPT_INTERNALcxx . . $ `lib/alg-yescrypt-opt.c:103:9`!
104 #include "alg-yescrypt.h"cxx . . $ `<file>/lib/alg-yescrypt.h`/
105
106 #include "alg-yescrypt-platform.c"cxx . . $ `<file>/lib/alg-yescrypt-platform.c`/
107
108 #if __STDC_VERSION__cxx . . $ `<built-in>:405:9`! >= 199901L
109 /* Have restrict */
110 #elif defined(__GNUC__)
111 #define restrict __restrict
112 #else
113 #define restrict
114 #endif
115
116 #ifdef __GNUC__cxx . . $ `<built-in>:8:9`!
117 #define unlikelycxx . . $ `lib/alg-yescrypt-opt.c:117:9`!(exp) __builtin_expect(exp, 0)
118 #else
119 #define unlikely(exp) (exp)
120 #endif
121
122 #ifdef __SSE__cxx . . $ `<built-in>:387:9`!
123 #define PREFETCHcxx . . $ `lib/alg-yescrypt-opt.c:123:9`!(x, hint) _mm_prefetch((x), (hint));
124 /* Older versions of clang have a bug in their xmmintrin.h that causes
125 spurious -Wcast-qual warnings on uses of _mm_prefetch. */
126 # if defined __clang_major__cxx . . $ `<built-in>:4:9`! && __clang_major__cxx . . $ `<built-in>:4:9`! < 11
127 # pragma clang diagnostic ignored "-Wcast-qual"
128 # endif
129 #else
130 #undef PREFETCH
131 #endif
132
133 typedef unioncxx . . $ $anonymous_type_9397105a3f57d04f_0# {
134 uint32_tcxx . . $ uint32_t# wcxx . . $ $anonymous_type_9397105a3f57d04f_0#w.[16];
135 uint64_tcxx . . $ uint64_t# dcxx . . $ $anonymous_type_9397105a3f57d04f_0#d.[8];
136 #ifdef __SSE2__cxx . . $ `<built-in>:385:9`!
137 __m128icxx . . $ __m128i# qcxx . . $ $anonymous_type_9397105a3f57d04f_0#q.[4];
138 #endif
139 } salsa20_blk_tcxx . . $ salsa20_blk_t#;
140
141 static inline void salsa20_simd_shufflecxx . . $ salsa20_simd_shuffle(8eca042884f1eb58).(const salsa20_blk_tcxx . . $ salsa20_blk_t# *Bin,
142 salsa20_blk_tcxx . . $ salsa20_blk_t# *Bout)
143 {
144 #define COMBINEcxx . . $ `lib/alg-yescrypt-opt.c:144:9`!(out, in1, in2) \
145 Bout->d[out] = Bin->w[in1 * 2] | ((uint64_t)Bin->w[in2 * 2 + 1] << 32);
146 COMBINEcxx . . $ `lib/alg-yescrypt-opt.c:144:9`!(0, 0, 2)
147 COMBINEcxx . . $ `lib/alg-yescrypt-opt.c:144:9`!(1, 5, 7)
148 COMBINEcxx . . $ `lib/alg-yescrypt-opt.c:144:9`!(2, 2, 4)
149 COMBINEcxx . . $ `lib/alg-yescrypt-opt.c:144:9`!(3, 7, 1)
150 COMBINEcxx . . $ `lib/alg-yescrypt-opt.c:144:9`!(4, 4, 6)
151 COMBINEcxx . . $ `lib/alg-yescrypt-opt.c:144:9`!(5, 1, 3)
152 COMBINEcxx . . $ `lib/alg-yescrypt-opt.c:144:9`!(6, 6, 0)
153 COMBINEcxx . . $ `lib/alg-yescrypt-opt.c:144:9`!(7, 3, 5)
154 #undef COMBINEcxx . . $ `lib/alg-yescrypt-opt.c:144:9`!
155 }
156
157 static inline void salsa20_simd_unshufflecxx . . $ salsa20_simd_unshuffle(8eca042884f1eb58).(const salsa20_blk_tcxx . . $ salsa20_blk_t# *Bin,
158 salsa20_blk_tcxx . . $ salsa20_blk_t# *Bout)
159 {
160 #define UNCOMBINEcxx . . $ `lib/alg-yescrypt-opt.c:160:9`!(out, in1, in2) \
161 Bout->w[out * 2] = Bin->d[in1]; \
162 Bout->w[out * 2 + 1] = Bin->d[in2] >> 32;
163 UNCOMBINEcxx . . $ `lib/alg-yescrypt-opt.c:160:9`!(0, 0, 6)
164 UNCOMBINEcxx . . $ `lib/alg-yescrypt-opt.c:160:9`!(1, 5, 3)
165 UNCOMBINEcxx . . $ `lib/alg-yescrypt-opt.c:160:9`!(2, 2, 0)
166 UNCOMBINEcxx . . $ `lib/alg-yescrypt-opt.c:160:9`!(3, 7, 5)
167 UNCOMBINEcxx . . $ `lib/alg-yescrypt-opt.c:160:9`!(4, 4, 2)
168 UNCOMBINEcxx . . $ `lib/alg-yescrypt-opt.c:160:9`!(5, 1, 7)
169 UNCOMBINEcxx . . $ `lib/alg-yescrypt-opt.c:160:9`!(6, 6, 4)
170 UNCOMBINEcxx . . $ `lib/alg-yescrypt-opt.c:160:9`!(7, 3, 1)
171 #undef UNCOMBINEcxx . . $ `lib/alg-yescrypt-opt.c:160:9`!
172 }
173
174 #ifdef __SSE2__cxx . . $ `<built-in>:385:9`!
175 #define DECL_Xcxx . . $ `lib/alg-yescrypt-opt.c:175:9`! \
176 __m128i X0, X1, X2, X3;
177 #define DECL_Ycxx . . $ `lib/alg-yescrypt-opt.c:177:9`! \
178 __m128i Y0, Y1, Y2, Y3;
179 #define READ_Xcxx . . $ `lib/alg-yescrypt-opt.c:179:9`!(in) \
180 X0 = (in).q[0]; X1 = (in).q[1]; X2 = (in).q[2]; X3 = (in).q[3];
181 #define WRITE_Xcxx . . $ `lib/alg-yescrypt-opt.c:181:9`!(out) \
182 (out).q[0] = X0; (out).q[1] = X1; (out).q[2] = X2; (out).q[3] = X3;
183
184 #ifdef __XOP__
185 #define ARX(out, in1, in2, s) \
186 out = _mm_xor_si128(out, _mm_roti_epi32(_mm_add_epi32(in1, in2), s));
187 #elif defined(__AVX512VL__)
188 #define ARX(out, in1, in2, s) \
189 out = _mm_xor_si128(out, _mm_rol_epi32(_mm_add_epi32(in1, in2), s));
190 #else
191 #define ARXcxx . . $ `lib/alg-yescrypt-opt.c:191:9`!(out, in1, in2, s) { \
192 __m128i tmp = _mm_add_epi32(in1, in2); \
193 out = _mm_xor_si128(out, _mm_slli_epi32(tmp, s)); \
194 out = _mm_xor_si128(out, _mm_srli_epi32(tmp, 32 - s)); \
195 }
196 #endif
197
198 #define SALSA20_2ROUNDScxx . . $ `lib/alg-yescrypt-opt.c:198:9`! \
199 /* Operate on "columns" */ \
200 ARXcxx . . $ `lib/alg-yescrypt-opt.c:191:9`!(X1, X0, X3, 7) \
201 ARXcxx . . $ `lib/alg-yescrypt-opt.c:191:9`!(X2, X1, X0, 9) \
202 ARXcxx . . $ `lib/alg-yescrypt-opt.c:191:9`!(X3, X2, X1, 13) \
203 ARXcxx . . $ `lib/alg-yescrypt-opt.c:191:9`!(X0, X3, X2, 18) \
204 /* Rearrange data */ \
205 X1 = _mm_shuffle_epi32(X1, 0x93); \
206 X2 = _mm_shuffle_epi32(X2, 0x4E); \
207 X3 = _mm_shuffle_epi32(X3, 0x39); \
208 /* Operate on "rows" */ \
209 ARXcxx . . $ `lib/alg-yescrypt-opt.c:191:9`!(X3, X0, X1, 7) \
210 ARXcxx . . $ `lib/alg-yescrypt-opt.c:191:9`!(X2, X3, X0, 9) \
211 ARXcxx . . $ `lib/alg-yescrypt-opt.c:191:9`!(X1, X2, X3, 13) \
212 ARXcxx . . $ `lib/alg-yescrypt-opt.c:191:9`!(X0, X1, X2, 18) \
213 /* Rearrange data */ \
214 X1 = _mm_shuffle_epi32(X1, 0x39); \
215 X2 = _mm_shuffle_epi32(X2, 0x4E); \
216 X3 = _mm_shuffle_epi32(X3, 0x93);
217
218 /**
219 * Apply the Salsa20 core to the block provided in (X0 ... X3).
220 */
221 #define SALSA20_wrappercxx . . $ `lib/alg-yescrypt-opt.c:221:9`!(out, rounds) { \
222 __m128i Z0 = X0, Z1 = X1, Z2 = X2, Z3 = X3; \
223 rounds \
224 (out).q[0] = X0 = _mm_add_epi32(X0, Z0); \
225 (out).q[1] = X1 = _mm_add_epi32(X1, Z1); \
226 (out).q[2] = X2 = _mm_add_epi32(X2, Z2); \
227 (out).q[3] = X3 = _mm_add_epi32(X3, Z3); \
228 }
229
230 /**
231 * Apply the Salsa20/2 core to the block provided in X.
232 */
233 #define SALSA20_2cxx . . $ `lib/alg-yescrypt-opt.c:233:9`!(out) \
234 SALSA20_wrappercxx . . $ `lib/alg-yescrypt-opt.c:221:9`!(out, SALSA20_2ROUNDScxx . . $ `lib/alg-yescrypt-opt.c:198:9`!)
235
236 #define SALSA20_8ROUNDScxx . . $ `lib/alg-yescrypt-opt.c:236:9`! \
237 SALSA20_2ROUNDScxx . . $ `lib/alg-yescrypt-opt.c:198:9`! SALSA20_2ROUNDScxx . . $ `lib/alg-yescrypt-opt.c:198:9`! SALSA20_2ROUNDScxx . . $ `lib/alg-yescrypt-opt.c:198:9`! SALSA20_2ROUNDScxx . . $ `lib/alg-yescrypt-opt.c:198:9`!
238
239 #define XOR_Xcxx . . $ `lib/alg-yescrypt-opt.c:239:9`!(in) \
240 X0 = _mm_xor_si128(X0, (in).q[0]); \
241 X1 = _mm_xor_si128(X1, (in).q[1]); \
242 X2 = _mm_xor_si128(X2, (in).q[2]); \
243 X3 = _mm_xor_si128(X3, (in).q[3]);
244
245 #define XOR_X_2cxx . . $ `lib/alg-yescrypt-opt.c:245:9`!(in1, in2) \
246 X0 = _mm_xor_si128((in1).q[0], (in2).q[0]); \
247 X1 = _mm_xor_si128((in1).q[1], (in2).q[1]); \
248 X2 = _mm_xor_si128((in1).q[2], (in2).q[2]); \
249 X3 = _mm_xor_si128((in1).q[3], (in2).q[3]);
250
251 #define XOR_X_WRITE_XOR_Y_2cxx . . $ `lib/alg-yescrypt-opt.c:251:9`!(out, in) \
252 (out).q[0] = Y0 = _mm_xor_si128((out).q[0], (in).q[0]); \
253 (out).q[1] = Y1 = _mm_xor_si128((out).q[1], (in).q[1]); \
254 (out).q[2] = Y2 = _mm_xor_si128((out).q[2], (in).q[2]); \
255 (out).q[3] = Y3 = _mm_xor_si128((out).q[3], (in).q[3]); \
256 X0 = _mm_xor_si128(X0, Y0); \
257 X1 = _mm_xor_si128(X1, Y1); \
258 X2 = _mm_xor_si128(X2, Y2); \
259 X3 = _mm_xor_si128(X3, Y3);
260
261 /**
262 * Apply the Salsa20/8 core to the block provided in X ^ in.
263 */
264 #define SALSA20_8_XOR_MEMcxx . . $ `lib/alg-yescrypt-opt.c:264:9`!(in, out) \
265 XOR_Xcxx . . $ `lib/alg-yescrypt-opt.c:239:9`!(in) \
266 SALSA20_wrappercxx . . $ `lib/alg-yescrypt-opt.c:221:9`!(out, SALSA20_8ROUNDScxx . . $ `lib/alg-yescrypt-opt.c:236:9`!)
267
268 #define INTEGERIFYcxx . . $ `lib/alg-yescrypt-opt.c:268:9`! (uint32_t)_mm_cvtsi128_si32(X0)
269
270 #else /* !defined(__SSE2__) */
271
272 #define DECL_X \
273 salsa20_blk_t X;
274 #define DECL_Y \
275 salsa20_blk_t Y;
276
277 #define COPY(out, in) \
278 (out).d[0] = (in).d[0]; \
279 (out).d[1] = (in).d[1]; \
280 (out).d[2] = (in).d[2]; \
281 (out).d[3] = (in).d[3]; \
282 (out).d[4] = (in).d[4]; \
283 (out).d[5] = (in).d[5]; \
284 (out).d[6] = (in).d[6]; \
285 (out).d[7] = (in).d[7];
286
287 #define READ_X(in) COPY(X, in)
288 #define WRITE_X(out) COPY(out, X)
289
290 /**
291 * salsa20(B):
292 * Apply the Salsa20 core to the provided block.
293 */
294 static inline void salsa20(salsa20_blk_t *restrict B,
295 salsa20_blk_t *restrict Bout, uint32_t doublerounds)
296 {
297 salsa20_blk_t X;
298 #define x X.w
299
300 salsa20_simd_unshuffle(B, &X);
301
302 do {
303 #define R(a,b) (((a) << (b)) | ((a) >> (32 - (b))))
304 /* Operate on columns */
305 x[ 4] ^= R(x[ 0]+x[12], 7); x[ 8] ^= R(x[ 4]+x[ 0], 9);
306 x[12] ^= R(x[ 8]+x[ 4],13); x[ 0] ^= R(x[12]+x[ 8],18);
307
308 x[ 9] ^= R(x[ 5]+x[ 1], 7); x[13] ^= R(x[ 9]+x[ 5], 9);
309 x[ 1] ^= R(x[13]+x[ 9],13); x[ 5] ^= R(x[ 1]+x[13],18);
310
311 x[14] ^= R(x[10]+x[ 6], 7); x[ 2] ^= R(x[14]+x[10], 9);
312 x[ 6] ^= R(x[ 2]+x[14],13); x[10] ^= R(x[ 6]+x[ 2],18);
313
314 x[ 3] ^= R(x[15]+x[11], 7); x[ 7] ^= R(x[ 3]+x[15], 9);
315 x[11] ^= R(x[ 7]+x[ 3],13); x[15] ^= R(x[11]+x[ 7],18);
316
317 /* Operate on rows */
318 x[ 1] ^= R(x[ 0]+x[ 3], 7); x[ 2] ^= R(x[ 1]+x[ 0], 9);
319 x[ 3] ^= R(x[ 2]+x[ 1],13); x[ 0] ^= R(x[ 3]+x[ 2],18);
320
321 x[ 6] ^= R(x[ 5]+x[ 4], 7); x[ 7] ^= R(x[ 6]+x[ 5], 9);
322 x[ 4] ^= R(x[ 7]+x[ 6],13); x[ 5] ^= R(x[ 4]+x[ 7],18);
323
324 x[11] ^= R(x[10]+x[ 9], 7); x[ 8] ^= R(x[11]+x[10], 9);
325 x[ 9] ^= R(x[ 8]+x[11],13); x[10] ^= R(x[ 9]+x[ 8],18);
326
327 x[12] ^= R(x[15]+x[14], 7); x[13] ^= R(x[12]+x[15], 9);
328 x[14] ^= R(x[13]+x[12],13); x[15] ^= R(x[14]+x[13],18);
329 #undef R
330 } while (--doublerounds);
331 #undef x
332
333 {
334 uint32_t i;
335 salsa20_simd_shuffle(&X, Bout);
336 for (i = 0; i < 16; i += 4) {
337 B->w[i] = Bout->w[i] += B->w[i];
338 B->w[i + 1] = Bout->w[i + 1] += B->w[i + 1];
339 B->w[i + 2] = Bout->w[i + 2] += B->w[i + 2];
340 B->w[i + 3] = Bout->w[i + 3] += B->w[i + 3];
341 }
342 }
343
344 #if 0
345 /* Too expensive */
346 explicit_bzero(&X, sizeof(X));
347 #endif
348 }
349
350 /**
351 * Apply the Salsa20/2 core to the block provided in X.
352 */
353 #define SALSA20_2(out) \
354 salsa20(&X, &out, 1);
355
356 #define XOR(out, in1, in2) \
357 (out).d[0] = (in1).d[0] ^ (in2).d[0]; \
358 (out).d[1] = (in1).d[1] ^ (in2).d[1]; \
359 (out).d[2] = (in1).d[2] ^ (in2).d[2]; \
360 (out).d[3] = (in1).d[3] ^ (in2).d[3]; \
361 (out).d[4] = (in1).d[4] ^ (in2).d[4]; \
362 (out).d[5] = (in1).d[5] ^ (in2).d[5]; \
363 (out).d[6] = (in1).d[6] ^ (in2).d[6]; \
364 (out).d[7] = (in1).d[7] ^ (in2).d[7];
365
366 #define XOR_X(in) XOR(X, X, in)
367 #define XOR_X_2(in1, in2) XOR(X, in1, in2)
368 #define XOR_X_WRITE_XOR_Y_2(out, in) \
369 XOR(Y, out, in) \
370 COPY(out, Y) \
371 XOR(X, X, Y)
372
373 /**
374 * Apply the Salsa20/8 core to the block provided in X ^ in.
375 */
376 #define SALSA20_8_XOR_MEM(in, out) \
377 XOR_X(in); \
378 salsa20(&X, &out, 4);
379
380 #define INTEGERIFY (uint32_t)X.d[0]
381 #endif
382
383 /**
384 * blockmix_salsa8(Bin, Bout, r):
385 * Compute Bout = BlockMix_{salsa20/8, r}(Bin). The input Bin must be 128r
386 * bytes in length; the output Bout must also be the same size.
387 */
388 static void blockmix_salsa8cxx . . $ blockmix_salsa8(6a8b81a2e78455a9).(const salsa20_blk_tcxx . . $ salsa20_blk_t# *restrict Bin,
389 salsa20_blk_tcxx . . $ salsa20_blk_t# *restrict Bout, size_t r)
390 {
391 size_t i;
392 DECL_Xcxx . . $ `lib/alg-yescrypt-opt.c:175:9`!
393
394 READ_Xcxx . . $ `lib/alg-yescrypt-opt.c:179:9`!(Bin[r * 2 - 1])
395 for (i = 0; i < r; i++) {
396 SALSA20_8_XOR_MEMcxx . . $ `lib/alg-yescrypt-opt.c:264:9`!(Bin[i * 2], Bout[i])
397 SALSA20_8_XOR_MEMcxx . . $ `lib/alg-yescrypt-opt.c:264:9`!(Bin[i * 2 + 1], Bout[r + i])
398 }
399 }
400
401 static uint32_tcxx . . $ uint32_t# blockmix_salsa8_xorcxx . . $ blockmix_salsa8_xor(c7e508c8978a8b0).(const salsa20_blk_tcxx . . $ salsa20_blk_t# *restrict Bin1,
402 const salsa20_blk_tcxx . . $ salsa20_blk_t# *restrict Bin2, salsa20_blk_tcxx . . $ salsa20_blk_t# *restrict Bout,
403 size_t r)
404 {
405 size_t i;
406 DECL_Xcxx . . $ `lib/alg-yescrypt-opt.c:175:9`!
407
408 #ifdef PREFETCHcxx . . $ `lib/alg-yescrypt-opt.c:123:9`!
409 PREFETCHcxx . . $ `lib/alg-yescrypt-opt.c:123:9`!(&Bin2[r * 2 - 1], _MM_HINT_T0)
410 for (i = 0; i < r - 1; i++) {
411 PREFETCHcxx . . $ `lib/alg-yescrypt-opt.c:123:9`!(&Bin2[i * 2], _MM_HINT_T0)
412 PREFETCHcxx . . $ `lib/alg-yescrypt-opt.c:123:9`!(&Bin2[i * 2 + 1], _MM_HINT_T0)
413 }
414 PREFETCHcxx . . $ `lib/alg-yescrypt-opt.c:123:9`!(&Bin2[i * 2], _MM_HINT_T0)
415 #endif
416
417 XOR_X_2cxx . . $ `lib/alg-yescrypt-opt.c:245:9`!(Bin1[r * 2 - 1], Bin2[r * 2 - 1])
418 for (i = 0; i < r; i++) {
419 XOR_Xcxx . . $ `lib/alg-yescrypt-opt.c:239:9`!(Bin1[i * 2])
420 SALSA20_8_XOR_MEMcxx . . $ `lib/alg-yescrypt-opt.c:264:9`!(Bin2[i * 2], Bout[i])
421 XOR_Xcxx . . $ `lib/alg-yescrypt-opt.c:239:9`!(Bin1[i * 2 + 1])
422 SALSA20_8_XOR_MEMcxx . . $ `lib/alg-yescrypt-opt.c:264:9`!(Bin2[i * 2 + 1], Bout[r + i])
423 }
424
425 return INTEGERIFYcxx . . $ `lib/alg-yescrypt-opt.c:268:9`!;
426 }
427
428 /* This is tunable */
429 #define Swidthcxx . . $ `lib/alg-yescrypt-opt.c:429:9`! 8
430
431 /* Not tunable in this implementation, hard-coded in a few places */
432 #define PWXsimplecxx . . $ `lib/alg-yescrypt-opt.c:432:9`! 2
433 #define PWXgathercxx . . $ `lib/alg-yescrypt-opt.c:433:9`! 4
434
435 /* Derived values. Not tunable except via Swidth above. */
436 #define PWXbytescxx . . $ `lib/alg-yescrypt-opt.c:436:9`! (PWXgather * PWXsimple * 8)
437 #define Sbytescxx . . $ `lib/alg-yescrypt-opt.c:437:9`! (3 * (1 << Swidthcxx . . $ `lib/alg-yescrypt-opt.c:429:9`!) * PWXsimplecxx . . $ `lib/alg-yescrypt-opt.c:432:9`! * 8)
438 #define Smaskcxx . . $ `lib/alg-yescrypt-opt.c:438:9`! (((1 << Swidthcxx . . $ `lib/alg-yescrypt-opt.c:429:9`!) - 1) * PWXsimplecxx . . $ `lib/alg-yescrypt-opt.c:432:9`! * 8)
439 #define Smask2cxx . . $ `lib/alg-yescrypt-opt.c:439:9`! (((uint64_t)Smaskcxx . . $ `lib/alg-yescrypt-opt.c:438:9`! << 32) | Smaskcxx . . $ `lib/alg-yescrypt-opt.c:438:9`!)
440
441 #define DECL_SMASK2REGcxx . . $ `lib/alg-yescrypt-opt.c:441:9`! /* empty */
442 #define FORCE_REGALLOC_3cxx . . $ `lib/alg-yescrypt-opt.c:442:9`! /* empty */
443 #define MAYBE_MEMORY_BARRIERcxx . . $ `lib/alg-yescrypt-opt.c:443:9`! /* empty */
444
445 #ifdef __SSE2__cxx . . $ `<built-in>:385:9`!
446 /*
447 * (V)PSRLDQ and (V)PSHUFD have higher throughput than (V)PSRLQ on some CPUs
448 * starting with Sandy Bridge. Additionally, PSHUFD uses separate source and
449 * destination registers, whereas the shifts would require an extra move
450 * instruction for our code when building without AVX. Unfortunately, PSHUFD
451 * is much slower on Conroe (4 cycles latency vs. 1 cycle latency for PSRLQ)
452 * and somewhat slower on some non-Intel CPUs (luckily not including AMD
453 * Bulldozer and Piledriver).
454 */
455 #ifdef __AVX__
456 #define HI32(X) \
457 _mm_srli_si128((X), 4)
458 #elif 1 /* As an option, check for __SSE4_1__ here not to hurt Conroe */
459 #define HI32cxx . . $ `lib/alg-yescrypt-opt.c:459:9`!(X) \
460 _mm_shuffle_epi32((X), _MM_SHUFFLE(2,3,0,1))
461 #else
462 #define HI32(X) \
463 _mm_srli_epi64((X), 32)
464 #endif
465
466 #if defined(__x86_64__cxx . . $ `<built-in>:374:9`!) && \
467 __GNUC__cxx . . $ `<built-in>:8:9`! == 4 && __GNUC_MINOR__cxx . . $ `<built-in>:9:9`! < 6 && !defined(__ICC)
468 #ifdef __AVX__
469 #define MOVQ "vmovq"
470 #else
471 /* "movq" would be more correct, but "movd" is supported by older binutils
472 * due to an error in AMD's spec for x86-64. */
473 #define MOVQcxx . . $ `lib/alg-yescrypt-opt.c:473:9`! "movd"
474 #endif
475 #define EXTRACT64cxx . . $ `lib/alg-yescrypt-opt.c:475:9`!(X) ({ \
476 uint64_t result; \
477 __asm__(MOVQ " %1, %0" : "=r" (result) : "x" (X)); \
478 result; \
479 })
480 #elif defined(__x86_64__) && !defined(_MSC_VER) && !defined(__OPEN64__)
481 /* MSVC and Open64 had bugs */
482 #define EXTRACT64(X) _mm_cvtsi128_si64(X)
483 #elif defined(__x86_64__) && defined(__SSE4_1__)
484 /* No known bugs for this intrinsic */
485 #include <smmintrin.h>
486 #define EXTRACT64(X) _mm_extract_epi64((X), 0)
487 #elif defined(USE_SSE4_FOR_32BIT) && defined(__SSE4_1__)
488 /* 32-bit */
489 #include <smmintrin.h>
490 #if 0
491 /* This is currently unused by the code below, which instead uses these two
492 * intrinsics explicitly when (!defined(__x86_64__) && defined(__SSE4_1__)) */
493 #define EXTRACT64(X) \
494 ((uint64_t)(uint32_t)_mm_cvtsi128_si32(X) | \
495 ((uint64_t)(uint32_t)_mm_extract_epi32((X), 1) << 32))
496 #endif
497 #else
498 /* 32-bit or compilers with known past bugs in _mm_cvtsi128_si64() */
499 #define EXTRACT64(X) \
500 ((uint64_t)(uint32_t)_mm_cvtsi128_si32(X) | \
501 ((uint64_t)(uint32_t)_mm_cvtsi128_si32(HI32(X)) << 32))
502 #endif
503
504 #if defined(__x86_64__cxx . . $ `<built-in>:374:9`!) && (defined(__AVX__) || !defined(__GNUC__cxx . . $ `<built-in>:8:9`!))
505 /* 64-bit with AVX */
506 /* Force use of 64-bit AND instead of two 32-bit ANDs */
507 #undef DECL_SMASK2REG
508 #if defined(__GNUC__) && !defined(__ICC)
509 #define DECL_SMASK2REG uint64_t Smask2reg = Smask2;
510 /* Force use of lower-numbered registers to reduce number of prefixes, relying
511 * on out-of-order execution and register renaming. */
512 #define FORCE_REGALLOC_1 \
513 __asm__("" : "=a" (x), "+d" (Smask2reg), "+S" (S0), "+D" (S1));
514 #define FORCE_REGALLOC_2 \
515 __asm__("" : : "c" (lo));
516 #else
517 static volatile uint64_t Smask2var = Smask2;
518 #define DECL_SMASK2REG uint64_t Smask2reg = Smask2var;
519 #define FORCE_REGALLOC_1 /* empty */
520 #define FORCE_REGALLOC_2 /* empty */
521 #endif
522 #define PWXFORM_SIMD(X) { \
523 uint64_t x; \
524 FORCE_REGALLOC_1 \
525 uint32_t lo = (uint32_t)(x = ((uint64_t)EXTRACT64(X)) & Smask2reg); \
526 FORCE_REGALLOC_2 \
527 uint32_t hi = x >> 32; \
528 X = _mm_mul_epu32(HI32(X), X); \
529 X = _mm_add_epi64(X, *(__m128i *)(S0 + lo)); \
530 X = _mm_xor_si128(X, *(__m128i *)(S1 + hi)); \
531 }
532 #elif defined(__x86_64__cxx . . $ `<built-in>:374:9`!)
533 /* 64-bit without AVX. This relies on out-of-order execution and register
534 * renaming. It may actually be fastest on CPUs with AVX(2) as well - e.g.,
535 * it runs great on Haswell. */
536 #if 0
537 #warning "Note: using x86-64 inline assembly for YESCRYPT_RW. That's great."
538 #endif
539 /* We need a compiler memory barrier between sub-blocks to ensure that none of
540 * the writes into what was S2 during processing of the previous sub-block are
541 * postponed until after a read from S0 or S1 in the inline asm code below. */
542 #undef MAYBE_MEMORY_BARRIERcxx . . $ `lib/alg-yescrypt-opt.c:443:9`!
543 #define MAYBE_MEMORY_BARRIERcxx . . $ `lib/alg-yescrypt-opt.c:543:9`! \
544 __asm__("" : : : "memory");
545 #ifdef __ILP32__ /* x32 */
546 #define REGISTER_PREFIX "e"
547 #else
548 #define REGISTER_PREFIXcxx . . $ `lib/alg-yescrypt-opt.c:548:9`! "r"
549 #endif
550 #define PWXFORM_SIMDcxx . . $ `lib/alg-yescrypt-opt.c:550:9`!(X) { \
551 __m128i H; \
552 __asm__( \
553 "movd %0, %%rax\n\t" \
554 "pshufd $0xb1, %0, %1\n\t" \
555 "andq %2, %%rax\n\t" \
556 "pmuludq %1, %0\n\t" \
557 "movl %%eax, %%ecx\n\t" \
558 "shrq $0x20, %%rax\n\t" \
559 "paddq (%3,%%" REGISTER_PREFIXcxx . . $ `lib/alg-yescrypt-opt.c:548:9`! "cx), %0\n\t" \
560 "pxor (%4,%%" REGISTER_PREFIXcxx . . $ `lib/alg-yescrypt-opt.c:548:9`! "ax), %0\n\t" \
561 : "+x" (X), "=x" (H) \
562 : "d" (Smask2cxx . . $ `lib/alg-yescrypt-opt.c:439:9`!), "S" (S0), "D" (S1) \
563 : "cc", "ax", "cx"); \
564 }
565 #elif defined(USE_SSE4_FOR_32BIT) && defined(__SSE4_1__)
566 /* 32-bit with SSE4.1 */
567 #define PWXFORM_SIMD(X) { \
568 __m128i x = _mm_and_si128(X, _mm_set1_epi64x(Smask2)); \
569 __m128i s0 = *(__m128i *)(S0 + (uint32_t)_mm_cvtsi128_si32(x)); \
570 __m128i s1 = *(__m128i *)(S1 + (uint32_t)_mm_extract_epi32(x, 1)); \
571 X = _mm_mul_epu32(HI32(X), X); \
572 X = _mm_add_epi64(X, s0); \
573 X = _mm_xor_si128(X, s1); \
574 }
575 #else
576 /* 32-bit without SSE4.1 */
577 #define PWXFORM_SIMD(X) { \
578 uint64_t x = EXTRACT64(X) & Smask2; \
579 __m128i s0 = *(__m128i *)(S0 + (uint32_t)x); \
580 __m128i s1 = *(__m128i *)(S1 + (x >> 32)); \
581 X = _mm_mul_epu32(HI32(X), X); \
582 X = _mm_add_epi64(X, s0); \
583 X = _mm_xor_si128(X, s1); \
584 }
585 #endif
586
587 #define PWXFORM_ROUNDcxx . . $ `lib/alg-yescrypt-opt.c:587:9`! \
588 PWXFORM_SIMDcxx . . $ `lib/alg-yescrypt-opt.c:550:9`!(X0) \
589 PWXFORM_SIMDcxx . . $ `lib/alg-yescrypt-opt.c:550:9`!(X1) \
590 PWXFORM_SIMDcxx . . $ `lib/alg-yescrypt-opt.c:550:9`!(X2) \
591 PWXFORM_SIMDcxx . . $ `lib/alg-yescrypt-opt.c:550:9`!(X3)
592
593 #if defined(__x86_64__cxx . . $ `<built-in>:374:9`!) && defined(__GNUC__cxx . . $ `<built-in>:8:9`!) && !defined(__ICC)
594 #undef FORCE_REGALLOC_3cxx . . $ `lib/alg-yescrypt-opt.c:442:9`!
595 #define FORCE_REGALLOC_3cxx . . $ `lib/alg-yescrypt-opt.c:595:9`! __asm__("" : : "b" (Sw));
596 #endif
597
598 #else /* !defined(__SSE2__) */
599
600 #define PWXFORM_SIMD(x0, x1) { \
601 uint64_t x = x0 & Smask2; \
602 uint64_t *p0 = (uint64_t *)(S0 + (uint32_t)x); \
603 uint64_t *p1 = (uint64_t *)(S1 + (x >> 32)); \
604 x0 = ((x0 >> 32) * (uint32_t)x0 + p0[0]) ^ p1[0]; \
605 x1 = ((x1 >> 32) * (uint32_t)x1 + p0[1]) ^ p1[1]; \
606 }
607
608 #define PWXFORM_ROUND \
609 PWXFORM_SIMD(X.d[0], X.d[1]) \
610 PWXFORM_SIMD(X.d[2], X.d[3]) \
611 PWXFORM_SIMD(X.d[4], X.d[5]) \
612 PWXFORM_SIMD(X.d[6], X.d[7])
613 #endif
614
615 /*
616 * This offset helps address the 256-byte write block via the single-byte
617 * displacements encodable in x86(-64) instructions. It is needed because the
618 * displacements are signed. Without it, we'd get 4-byte displacements for
619 * half of the writes. Setting it to 0x80 instead of 0x7c would avoid needing
620 * a displacement for one of the writes, but then the LEA instruction would
621 * need a 4-byte displacement.
622 */
623 #define PWXFORM_WRITE_OFFSETcxx . . $ `lib/alg-yescrypt-opt.c:623:9`! 0x7c
624
625 #define PWXFORM_WRITEcxx . . $ `lib/alg-yescrypt-opt.c:625:9`! \
626 WRITE_Xcxx . . $ `lib/alg-yescrypt-opt.c:181:9`!(*(salsa20_blk_t *)(Sw - PWXFORM_WRITE_OFFSETcxx . . $ `lib/alg-yescrypt-opt.c:623:9`!)) \
627 Sw += 64;
628
629 #define PWXFORMcxx . . $ `lib/alg-yescrypt-opt.c:629:9`! { \
630 uint8_t *Sw = S2 + w + PWXFORM_WRITE_OFFSETcxx . . $ `lib/alg-yescrypt-opt.c:623:9`!; \
631 FORCE_REGALLOC_3cxx . . $ `lib/alg-yescrypt-opt.c:595:9`! \
632 MAYBE_MEMORY_BARRIERcxx . . $ `lib/alg-yescrypt-opt.c:543:9`! \
633 PWXFORM_ROUNDcxx . . $ `lib/alg-yescrypt-opt.c:587:9`! \
634 PWXFORM_ROUNDcxx . . $ `lib/alg-yescrypt-opt.c:587:9`! PWXFORM_WRITEcxx . . $ `lib/alg-yescrypt-opt.c:625:9`! \
635 PWXFORM_ROUNDcxx . . $ `lib/alg-yescrypt-opt.c:587:9`! PWXFORM_WRITEcxx . . $ `lib/alg-yescrypt-opt.c:625:9`! \
636 PWXFORM_ROUNDcxx . . $ `lib/alg-yescrypt-opt.c:587:9`! PWXFORM_WRITEcxx . . $ `lib/alg-yescrypt-opt.c:625:9`! \
637 PWXFORM_ROUNDcxx . . $ `lib/alg-yescrypt-opt.c:587:9`! PWXFORM_WRITEcxx . . $ `lib/alg-yescrypt-opt.c:625:9`! \
638 PWXFORM_ROUNDcxx . . $ `lib/alg-yescrypt-opt.c:587:9`! \
639 w = (w + 64 * 4) & Smask2cxx . . $ `lib/alg-yescrypt-opt.c:439:9`!; \
640 { \
641 uint8_t *Stmp = S2; \
642 S2 = S1; \
643 S1 = S0; \
644 S0 = Stmp; \
645 } \
646 }
647
648 typedef structcxx . . $ $anonymous_type_9397105a3f57d04f_1# {
649 uint8_tcxx . . $ uint8_t# *S0cxx . . $ $anonymous_type_9397105a3f57d04f_1#S0., *S1cxx . . $ $anonymous_type_9397105a3f57d04f_1#S1., *S2cxx . . $ $anonymous_type_9397105a3f57d04f_1#S2.;
650 size_t wcxx . . $ $anonymous_type_9397105a3f57d04f_1#w.;
651 } pwxform_ctx_tcxx . . $ pwxform_ctx_t#;
652
653 #define Salloccxx . . $ `lib/alg-yescrypt-opt.c:653:9`! (Sbytescxx . . $ `lib/alg-yescrypt-opt.c:437:9`! + ((sizeof(pwxform_ctx_t) + 63) & ~63U))
654
655 /**
656 * blockmix_pwxform(Bin, Bout, r, S):
657 * Compute Bout = BlockMix_pwxform{salsa20/2, r, S}(Bin). The input Bin must
658 * be 128r bytes in length; the output Bout must also be the same size.
659 */
660 static void blockmixcxx . . $ blockmix(186a4c4d36740426).(const salsa20_blk_tcxx . . $ salsa20_blk_t# *restrict Bin,
661 salsa20_blk_tcxx . . $ salsa20_blk_t# *restrict Bout, size_t r, pwxform_ctx_tcxx . . $ pwxform_ctx_t# *restrict ctx)
662 {
663 /* ctx MUST NOT be NULL */
664 assertcxx . . $ `<external>/4398592474888995393/assert.h:156:12`!(ctx != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
665
666 uint8_tcxx . . $ uint8_t# *S0 = ctx->S0cxx . . $ $anonymous_type_9397105a3f57d04f_1#S0., *S1 = ctx->S1cxx . . $ $anonymous_type_9397105a3f57d04f_1#S1., *S2 = ctx->S2cxx . . $ $anonymous_type_9397105a3f57d04f_1#S2.;
667 size_t w = ctx->wcxx . . $ $anonymous_type_9397105a3f57d04f_1#w.;
668 size_t i;
669 DECL_Xcxx . . $ `lib/alg-yescrypt-opt.c:175:9`!
670
671 /* Convert count of 128-byte blocks to max index of 64-byte block */
672 r = r * 2 - 1;
673
674 READ_Xcxx . . $ `lib/alg-yescrypt-opt.c:179:9`!(Bin[r])
675
676 DECL_SMASK2REGcxx . . $ `lib/alg-yescrypt-opt.c:441:9`!
677
678 i = 0;
679 do {
680 XOR_Xcxx . . $ `lib/alg-yescrypt-opt.c:239:9`!(Bin[i])
681 PWXFORMcxx . . $ `lib/alg-yescrypt-opt.c:629:9`!
682 if (unlikelycxx . . $ `lib/alg-yescrypt-opt.c:117:9`!(i >= r))
683 break;
684 WRITE_Xcxx . . $ `lib/alg-yescrypt-opt.c:181:9`!(Bout[i])
685 i++;
686 } while (1);
687
688 ctx->S0cxx . . $ $anonymous_type_9397105a3f57d04f_1#S0. = S0; ctx->S1cxx . . $ $anonymous_type_9397105a3f57d04f_1#S1. = S1; ctx->S2cxx . . $ $anonymous_type_9397105a3f57d04f_1#S2. = S2;
689 ctx->wcxx . . $ $anonymous_type_9397105a3f57d04f_1#w. = w;
690
691 SALSA20_2cxx . . $ `lib/alg-yescrypt-opt.c:233:9`!(Bout[i])
692 }
693
694 static uint32_tcxx . . $ uint32_t# blockmix_xorcxx . . $ blockmix_xor(afd6c372c519b3f7).(const salsa20_blk_tcxx . . $ salsa20_blk_t# *Bin1,
695 const salsa20_blk_tcxx . . $ salsa20_blk_t# *restrict Bin2, salsa20_blk_tcxx . . $ salsa20_blk_t# *Bout,
696 size_t r, int Bin2_in_ROM, pwxform_ctx_tcxx . . $ pwxform_ctx_t# *restrict ctx)
697 {
698 /* ctx MUST NOT be NULL */
699 assertcxx . . $ `<external>/4398592474888995393/assert.h:156:12`!(ctx != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
700
701 uint8_tcxx . . $ uint8_t# *S0 = ctx->S0cxx . . $ $anonymous_type_9397105a3f57d04f_1#S0., *S1 = ctx->S1cxx . . $ $anonymous_type_9397105a3f57d04f_1#S1., *S2 = ctx->S2cxx . . $ $anonymous_type_9397105a3f57d04f_1#S2.;
702 size_t w = ctx->wcxx . . $ $anonymous_type_9397105a3f57d04f_1#w.;
703 size_t i;
704 DECL_Xcxx . . $ `lib/alg-yescrypt-opt.c:175:9`!
705
706 /* Convert count of 128-byte blocks to max index of 64-byte block */
707 r = r * 2 - 1;
708
709 #ifdef PREFETCHcxx . . $ `lib/alg-yescrypt-opt.c:123:9`!
710 if (Bin2_in_ROM) {
711 PREFETCHcxx . . $ `lib/alg-yescrypt-opt.c:123:9`!(&Bin2[r], _MM_HINT_NTA)
712 for (i = 0; i < r; i++) {
713 PREFETCHcxx . . $ `lib/alg-yescrypt-opt.c:123:9`!(&Bin2[i], _MM_HINT_NTA)
714 }
715 } else {
716 PREFETCHcxx . . $ `lib/alg-yescrypt-opt.c:123:9`!(&Bin2[r], _MM_HINT_T0)
717 for (i = 0; i < r; i++) {
718 PREFETCHcxx . . $ `lib/alg-yescrypt-opt.c:123:9`!(&Bin2[i], _MM_HINT_T0)
719 }
720 }
721 #else
722 (void)Bin2_in_ROM; /* unused */
723 #endif
724
725 XOR_X_2cxx . . $ `lib/alg-yescrypt-opt.c:245:9`!(Bin1[r], Bin2[r])
726
727 DECL_SMASK2REGcxx . . $ `lib/alg-yescrypt-opt.c:441:9`!
728
729 i = 0;
730 r--;
731 do {
732 XOR_Xcxx . . $ `lib/alg-yescrypt-opt.c:239:9`!(Bin1[i])
733 XOR_Xcxx . . $ `lib/alg-yescrypt-opt.c:239:9`!(Bin2[i])
734 PWXFORMcxx . . $ `lib/alg-yescrypt-opt.c:629:9`!
735 WRITE_Xcxx . . $ `lib/alg-yescrypt-opt.c:181:9`!(Bout[i])
736
737 XOR_Xcxx . . $ `lib/alg-yescrypt-opt.c:239:9`!(Bin1[i + 1])
738 XOR_Xcxx . . $ `lib/alg-yescrypt-opt.c:239:9`!(Bin2[i + 1])
739 PWXFORMcxx . . $ `lib/alg-yescrypt-opt.c:629:9`!
740
741 if (unlikelycxx . . $ `lib/alg-yescrypt-opt.c:117:9`!(i >= r))
742 break;
743
744 WRITE_Xcxx . . $ `lib/alg-yescrypt-opt.c:181:9`!(Bout[i + 1])
745
746 i += 2;
747 } while (1);
748 i++;
749
750 ctx->S0cxx . . $ $anonymous_type_9397105a3f57d04f_1#S0. = S0; ctx->S1cxx . . $ $anonymous_type_9397105a3f57d04f_1#S1. = S1; ctx->S2cxx . . $ $anonymous_type_9397105a3f57d04f_1#S2. = S2;
751 ctx->wcxx . . $ $anonymous_type_9397105a3f57d04f_1#w. = w;
752
753 SALSA20_2cxx . . $ `lib/alg-yescrypt-opt.c:233:9`!(Bout[i])
754
755 return INTEGERIFYcxx . . $ `lib/alg-yescrypt-opt.c:268:9`!;
756 }
757
758 static uint32_tcxx . . $ uint32_t# blockmix_xor_savecxx . . $ blockmix_xor_save(a2fd50704503b77e).(salsa20_blk_tcxx . . $ salsa20_blk_t# *restrict Bin1out,
759 salsa20_blk_tcxx . . $ salsa20_blk_t# *restrict Bin2,
760 size_t r, pwxform_ctx_tcxx . . $ pwxform_ctx_t# *restrict ctx)
761 {
762 /* ctx MUST NOT be NULL */
763 assertcxx . . $ `<external>/4398592474888995393/assert.h:156:12`!(ctx != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
764
765 uint8_tcxx . . $ uint8_t# *S0 = ctx->S0cxx . . $ $anonymous_type_9397105a3f57d04f_1#S0., *S1 = ctx->S1cxx . . $ $anonymous_type_9397105a3f57d04f_1#S1., *S2 = ctx->S2cxx . . $ $anonymous_type_9397105a3f57d04f_1#S2.;
766 size_t w = ctx->wcxx . . $ $anonymous_type_9397105a3f57d04f_1#w.;
767 size_t i;
768 DECL_Xcxx . . $ `lib/alg-yescrypt-opt.c:175:9`!
769 DECL_Ycxx . . $ `lib/alg-yescrypt-opt.c:177:9`!
770
771 /* Convert count of 128-byte blocks to max index of 64-byte block */
772 r = r * 2 - 1;
773
774 #ifdef PREFETCHcxx . . $ `lib/alg-yescrypt-opt.c:123:9`!
775 PREFETCHcxx . . $ `lib/alg-yescrypt-opt.c:123:9`!(&Bin2[r], _MM_HINT_T0)
776 for (i = 0; i < r; i++) {
777 PREFETCHcxx . . $ `lib/alg-yescrypt-opt.c:123:9`!(&Bin2[i], _MM_HINT_T0)
778 }
779 #endif
780
781 XOR_X_2cxx . . $ `lib/alg-yescrypt-opt.c:245:9`!(Bin1out[r], Bin2[r])
782
783 DECL_SMASK2REGcxx . . $ `lib/alg-yescrypt-opt.c:441:9`!
784
785 i = 0;
786 r--;
787 do {
788 XOR_X_WRITE_XOR_Y_2cxx . . $ `lib/alg-yescrypt-opt.c:251:9`!(Bin2[i], Bin1out[i])
789 PWXFORMcxx . . $ `lib/alg-yescrypt-opt.c:629:9`!
790 WRITE_Xcxx . . $ `lib/alg-yescrypt-opt.c:181:9`!(Bin1out[i])
791
792 XOR_X_WRITE_XOR_Y_2cxx . . $ `lib/alg-yescrypt-opt.c:251:9`!(Bin2[i + 1], Bin1out[i + 1])
793 PWXFORMcxx . . $ `lib/alg-yescrypt-opt.c:629:9`!
794
795 if (unlikelycxx . . $ `lib/alg-yescrypt-opt.c:117:9`!(i >= r))
796 break;
797
798 WRITE_Xcxx . . $ `lib/alg-yescrypt-opt.c:181:9`!(Bin1out[i + 1])
799
800 i += 2;
801 } while (1);
802 i++;
803
804 ctx->S0cxx . . $ $anonymous_type_9397105a3f57d04f_1#S0. = S0; ctx->S1cxx . . $ $anonymous_type_9397105a3f57d04f_1#S1. = S1; ctx->S2cxx . . $ $anonymous_type_9397105a3f57d04f_1#S2. = S2;
805 ctx->wcxx . . $ $anonymous_type_9397105a3f57d04f_1#w. = w;
806
807 SALSA20_2cxx . . $ `lib/alg-yescrypt-opt.c:233:9`!(Bin1out[i])
808
809 return INTEGERIFYcxx . . $ `lib/alg-yescrypt-opt.c:268:9`!;
810 }
811
812 /**
813 * integerify(B, r):
814 * Return the result of parsing B_{2r-1} as a little-endian integer.
815 */
816 static inline uint32_tcxx . . $ uint32_t# integerifycxx . . $ integerify(29801ae1c2c21110).(const salsa20_blk_tcxx . . $ salsa20_blk_t# *B, size_t r)
817 {
818 /*
819 * Our 64-bit words are in host byte order, which is why we don't just read
820 * w[0] here (would be wrong on big-endian). Also, our 32-bit words are
821 * SIMD-shuffled (so the next 32 bits would be part of d[6]), but currently
822 * this does not matter as we only care about the least significant 32 bits.
823 */
824 return (uint32_tcxx . . $ uint32_t#)B[2 * r - 1].dcxx . . $ $anonymous_type_9397105a3f57d04f_0#d.[0];
825 }
826
827 /**
828 * smix1(B, r, N, flags, V, NROM, VROM, XY, ctx):
829 * Compute first loop of B = SMix_r(B, N). The input B must be 128r bytes in
830 * length; the temporary storage V must be 128rN bytes in length; the temporary
831 * storage XY must be 128r+64 bytes in length. N must be even and at least 4.
832 * The array V must be aligned to a multiple of 64 bytes, and arrays B and XY
833 * to a multiple of at least 16 bytes.
834 */
835 static void smix1cxx . . $ smix1(fbd2cf9bbfbe6904).(uint8_tcxx . . $ uint8_t# *B, size_t r, uint32_tcxx . . $ uint32_t# N, yescrypt_flags_tcxx . . $ yescrypt_flags_t# flags,
836 salsa20_blk_tcxx . . $ salsa20_blk_t# *V, uint32_tcxx . . $ uint32_t# NROM, const salsa20_blk_tcxx . . $ salsa20_blk_t# *VROM,
837 salsa20_blk_tcxx . . $ salsa20_blk_t# *XY, pwxform_ctx_tcxx . . $ pwxform_ctx_t# *ctx)
838 {
839 size_t s = 2 * r;
840 salsa20_blk_tcxx . . $ salsa20_blk_t# *X = V, *Y = &V[s];
841 uint32_tcxx . . $ uint32_t# i, j;
842
843 for (i = 0; i < 2 * r; i++) {
844 const salsa20_blk_tcxx . . $ salsa20_blk_t# *src = (salsa20_blk_tcxx . . $ salsa20_blk_t# *)&B[i * 64];
845 salsa20_blk_tcxx . . $ salsa20_blk_t# *tmp = Y;
846 salsa20_blk_tcxx . . $ salsa20_blk_t# *dst = &X[i];
847 size_t k;
848 for (k = 0; k < 16; k++)
849 tmp->wcxx . . $ $anonymous_type_9397105a3f57d04f_0#w.[k] = le32deccxx . . $ `lib/byteorder.h:150:9`!((const uint8_tcxx . . $ uint8_t# *) &src->wcxx . . $ $anonymous_type_9397105a3f57d04f_0#w.[k]);
850 salsa20_simd_shufflecxx . . $ salsa20_simd_shuffle(8eca042884f1eb58).(tmp, dst);
851 }
852
853 if (VROM) {
854 uint32_tcxx . . $ uint32_t# n;
855 const salsa20_blk_tcxx . . $ salsa20_blk_t# *V_j;
856
857 V_j = &VROM[(NROM - 1) * s];
858 j = blockmix_xorcxx . . $ blockmix_xor(afd6c372c519b3f7).(X, V_j, Y, r, 1, ctx) & (NROM - 1);
859 V_j = &VROM[j * s];
860 X = Y + s;
861 j = blockmix_xorcxx . . $ blockmix_xor(afd6c372c519b3f7).(Y, V_j, X, r, 1, ctx);
862
863 for (n = 2; n < N; n <<= 1) {
864 uint32_tcxx . . $ uint32_t# m = (n < N / 2) ? n : (N - 1 - n);
865 for (i = 1; i < m; i += 2) {
866 j &= n - 1;
867 j += i - 1;
868 V_j = &V[j * s];
869 Y = X + s;
870 j = blockmix_xorcxx . . $ blockmix_xor(afd6c372c519b3f7).(X, V_j, Y, r, 0, ctx) & (NROM - 1);
871 V_j = &VROM[j * s];
872 X = Y + s;
873 j = blockmix_xorcxx . . $ blockmix_xor(afd6c372c519b3f7).(Y, V_j, X, r, 1, ctx);
874 }
875 }
876 n >>= 1;
877
878 j &= n - 1;
879 j += N - 2 - n;
880 V_j = &V[j * s];
881 Y = X + s;
882 j = blockmix_xorcxx . . $ blockmix_xor(afd6c372c519b3f7).(X, V_j, Y, r, 0, ctx) & (NROM - 1);
883 V_j = &VROM[j * s];
884 blockmix_xorcxx . . $ blockmix_xor(afd6c372c519b3f7).(Y, V_j, XY, r, 1, ctx);
885 } else if (flags & YESCRYPT_RWcxx . . $ `lib/alg-yescrypt.h:90:9`!) {
886 uint32_tcxx . . $ uint32_t# n;
887 salsa20_blk_tcxx . . $ salsa20_blk_t# *V_j;
888
889 blockmixcxx . . $ blockmix(186a4c4d36740426).(X, Y, r, ctx);
890 X = Y + s;
891 blockmixcxx . . $ blockmix(186a4c4d36740426).(Y, X, r, ctx);
892 j = integerifycxx . . $ integerify(29801ae1c2c21110).(X, r);
893
894 for (n = 2; n < N; n <<= 1) {
895 uint32_tcxx . . $ uint32_t# m = (n < N / 2) ? n : (N - 1 - n);
896 for (i = 1; i < m; i += 2) {
897 Y = X + s;
898 j &= n - 1;
899 j += i - 1;
900 V_j = &V[j * s];
901 j = blockmix_xorcxx . . $ blockmix_xor(afd6c372c519b3f7).(X, V_j, Y, r, 0, ctx);
902 j &= n - 1;
903 j += i;
904 V_j = &V[j * s];
905 X = Y + s;
906 j = blockmix_xorcxx . . $ blockmix_xor(afd6c372c519b3f7).(Y, V_j, X, r, 0, ctx);
907 }
908 }
909 n >>= 1;
910
911 j &= n - 1;
912 j += N - 2 - n;
913 V_j = &V[j * s];
914 Y = X + s;
915 j = blockmix_xorcxx . . $ blockmix_xor(afd6c372c519b3f7).(X, V_j, Y, r, 0, ctx);
916 j &= n - 1;
917 j += N - 1 - n;
918 V_j = &V[j * s];
919 blockmix_xorcxx . . $ blockmix_xor(afd6c372c519b3f7).(Y, V_j, XY, r, 0, ctx);
920 } else {
921 N -= 2;
922 do {
923 blockmix_salsa8cxx . . $ blockmix_salsa8(6a8b81a2e78455a9).(X, Y, r);
924 X = Y + s;
925 blockmix_salsa8cxx . . $ blockmix_salsa8(6a8b81a2e78455a9).(Y, X, r);
926 Y = X + s;
927 } while ((N -= 2));
928
929 blockmix_salsa8cxx . . $ blockmix_salsa8(6a8b81a2e78455a9).(X, Y, r);
930 blockmix_salsa8cxx . . $ blockmix_salsa8(6a8b81a2e78455a9).(Y, XY, r);
931 }
932
933 for (i = 0; i < 2 * r; i++) {
934 const salsa20_blk_tcxx . . $ salsa20_blk_t# *src = &XY[i];
935 salsa20_blk_tcxx . . $ salsa20_blk_t# *tmp = &XY[s];
936 salsa20_blk_tcxx . . $ salsa20_blk_t# *dst = (salsa20_blk_tcxx . . $ salsa20_blk_t# *)&B[i * 64];
937 size_t k;
938 for (k = 0; k < 16; k++)
939 le32enccxx . . $ `lib/byteorder.h:149:9`!((uint8_tcxx . . $ uint8_t# *)&tmp->wcxx . . $ $anonymous_type_9397105a3f57d04f_0#w.[k], src->wcxx . . $ $anonymous_type_9397105a3f57d04f_0#w.[k]);
940 salsa20_simd_unshufflecxx . . $ salsa20_simd_unshuffle(8eca042884f1eb58).(tmp, dst);
941 }
942 }
943
944 /**
945 * smix2(B, r, N, Nloop, flags, V, NROM, VROM, XY, ctx):
946 * Compute second loop of B = SMix_r(B, N). The input B must be 128r bytes in
947 * length; the temporary storage V must be 128rN bytes in length; the temporary
948 * storage XY must be 256r bytes in length. N must be a power of 2 and at
949 * least 2. Nloop must be even. The array V must be aligned to a multiple of
950 * 64 bytes, and arrays B and XY to a multiple of at least 16 bytes.
951 */
952 static void smix2cxx . . $ smix2(e4c2e9d7a9348391).(uint8_tcxx . . $ uint8_t# *B, size_t r, uint32_tcxx . . $ uint32_t# N, uint64_tcxx . . $ uint64_t# Nloop,
953 yescrypt_flags_tcxx . . $ yescrypt_flags_t# flags, salsa20_blk_tcxx . . $ salsa20_blk_t# *V, uint32_tcxx . . $ uint32_t# NROM,
954 const salsa20_blk_tcxx . . $ salsa20_blk_t# *VROM, salsa20_blk_tcxx . . $ salsa20_blk_t# *XY, pwxform_ctx_tcxx . . $ pwxform_ctx_t# *ctx)
955 {
956 size_t s = 2 * r;
957 salsa20_blk_tcxx . . $ salsa20_blk_t# *X = XY, *Y = &XY[s];
958 uint32_tcxx . . $ uint32_t# i, j;
959
960 if (Nloop == 0)
961 return;
962
963 for (i = 0; i < 2 * r; i++) {
964 const salsa20_blk_tcxx . . $ salsa20_blk_t# *src = (salsa20_blk_tcxx . . $ salsa20_blk_t# *)&B[i * 64];
965 salsa20_blk_tcxx . . $ salsa20_blk_t# *tmp = Y;
966 salsa20_blk_tcxx . . $ salsa20_blk_t# *dst = &X[i];
967 size_t k;
968 for (k = 0; k < 16; k++)
969 tmp->wcxx . . $ $anonymous_type_9397105a3f57d04f_0#w.[k] = le32deccxx . . $ `lib/byteorder.h:150:9`!((const uint8_tcxx . . $ uint8_t# *)&src->wcxx . . $ $anonymous_type_9397105a3f57d04f_0#w.[k]);
970 salsa20_simd_shufflecxx . . $ salsa20_simd_shuffle(8eca042884f1eb58).(tmp, dst);
971 }
972
973 j = integerifycxx . . $ integerify(29801ae1c2c21110).(X, r) & (N - 1);
974
975 /*
976 * Normally, VROM implies YESCRYPT_RW, but we check for these separately
977 * because our SMix resets YESCRYPT_RW for the smix2() calls operating on the
978 * entire V when p > 1.
979 */
980 if (VROM && (flags & YESCRYPT_RWcxx . . $ `lib/alg-yescrypt.h:90:9`!)) {
981 do {
982 salsa20_blk_tcxx . . $ salsa20_blk_t# *V_j = &V[j * s];
983 const salsa20_blk_tcxx . . $ salsa20_blk_t# *VROM_j;
984 j = blockmix_xor_savecxx . . $ blockmix_xor_save(a2fd50704503b77e).(X, V_j, r, ctx) & (NROM - 1);
985 VROM_j = &VROM[j * s];
986 j = blockmix_xorcxx . . $ blockmix_xor(afd6c372c519b3f7).(X, VROM_j, X, r, 1, ctx) & (N - 1);
987 } while (Nloop -= 2);
988 } else if (VROM) {
989 do {
990 const salsa20_blk_tcxx . . $ salsa20_blk_t# *V_j = &V[j * s];
991 j = blockmix_xorcxx . . $ blockmix_xor(afd6c372c519b3f7).(X, V_j, X, r, 0, ctx) & (NROM - 1);
992 V_j = &VROM[j * s];
993 j = blockmix_xorcxx . . $ blockmix_xor(afd6c372c519b3f7).(X, V_j, X, r, 1, ctx) & (N - 1);
994 } while (Nloop -= 2);
995 } else if (flags & YESCRYPT_RWcxx . . $ `lib/alg-yescrypt.h:90:9`!) {
996 do {
997 salsa20_blk_tcxx . . $ salsa20_blk_t# *V_j = &V[j * s];
998 j = blockmix_xor_savecxx . . $ blockmix_xor_save(a2fd50704503b77e).(X, V_j, r, ctx) & (N - 1);
999 V_j = &V[j * s];
1000 j = blockmix_xor_savecxx . . $ blockmix_xor_save(a2fd50704503b77e).(X, V_j, r, ctx) & (N - 1);
1001 } while (Nloop -= 2);
1002 } else if (ctx) {
1003 do {
1004 const salsa20_blk_tcxx . . $ salsa20_blk_t# *V_j = &V[j * s];
1005 j = blockmix_xorcxx . . $ blockmix_xor(afd6c372c519b3f7).(X, V_j, X, r, 0, ctx) & (N - 1);
1006 V_j = &V[j * s];
1007 j = blockmix_xorcxx . . $ blockmix_xor(afd6c372c519b3f7).(X, V_j, X, r, 0, ctx) & (N - 1);
1008 } while (Nloop -= 2);
1009 } else {
1010 do {
1011 const salsa20_blk_tcxx . . $ salsa20_blk_t# *V_j = &V[j * s];
1012 j = blockmix_salsa8_xorcxx . . $ blockmix_salsa8_xor(c7e508c8978a8b0).(X, V_j, Y, r) & (N - 1);
1013 V_j = &V[j * s];
1014 j = blockmix_salsa8_xorcxx . . $ blockmix_salsa8_xor(c7e508c8978a8b0).(Y, V_j, X, r) & (N - 1);
1015 } while (Nloop -= 2);
1016 }
1017
1018 for (i = 0; i < 2 * r; i++) {
1019 const salsa20_blk_tcxx . . $ salsa20_blk_t# *src = &X[i];
1020 salsa20_blk_tcxx . . $ salsa20_blk_t# *tmp = Y;
1021 salsa20_blk_tcxx . . $ salsa20_blk_t# *dst = (salsa20_blk_tcxx . . $ salsa20_blk_t# *)&B[i * 64];
1022 size_t k;
1023 for (k = 0; k < 16; k++)
1024 le32enccxx . . $ `lib/byteorder.h:149:9`!((uint8_tcxx . . $ uint8_t# *)&tmp->wcxx . . $ $anonymous_type_9397105a3f57d04f_0#w.[k], src->wcxx . . $ $anonymous_type_9397105a3f57d04f_0#w.[k]);
1025 salsa20_simd_unshufflecxx . . $ salsa20_simd_unshuffle(8eca042884f1eb58).(tmp, dst);
1026 }
1027 }
1028
1029 /**
1030 * p2floor(x):
1031 * Largest power of 2 not greater than argument.
1032 */
1033 static uint64_tcxx . . $ uint64_t# p2floorcxx . . $ p2floor(ecdaa1632f49f591).(uint64_tcxx . . $ uint64_t# x)
1034 {
1035 uint64_tcxx . . $ uint64_t# y;
1036 while ((y = x & (x - 1)))
1037 x = y;
1038 return x;
1039 }
1040
1041 /**
1042 * smix(B, r, N, p, t, flags, V, NROM, VROM, XY, S, passwd):
1043 * Compute B = SMix_r(B, N). The input B must be 128rp bytes in length; the
1044 * temporary storage V must be 128rN bytes in length; the temporary storage
1045 * XY must be 256r or 256rp bytes in length (the larger size is required with
1046 * OpenMP-enabled builds). N must be a power of 2 and at least 4. The array V
1047 * must be aligned to a multiple of 64 bytes, and arrays B and XY to a multiple
1048 * of at least 16 bytes (aligning them to 64 bytes as well saves cache lines
1049 * and helps avoid false sharing in OpenMP-enabled builds when p > 1, but it
1050 * might also result in cache bank conflicts).
1051 */
1052 static void smixcxx . . $ smix(d90d48d4433e8791).(uint8_tcxx . . $ uint8_t# *B, size_t r, uint32_tcxx . . $ uint32_t# N, uint32_tcxx . . $ uint32_t# p, uint32_tcxx . . $ uint32_t# t,
1053 yescrypt_flags_tcxx . . $ yescrypt_flags_t# flags,
1054 salsa20_blk_tcxx . . $ salsa20_blk_t# *V, uint32_tcxx . . $ uint32_t# NROM, const salsa20_blk_tcxx . . $ salsa20_blk_t# *VROM,
1055 salsa20_blk_tcxx . . $ salsa20_blk_t# *XY, uint8_tcxx . . $ uint8_t# *S, uint8_tcxx . . $ uint8_t# *passwd)
1056 {
1057 size_t s = 2 * r;
1058 uint32_tcxx . . $ uint32_t# Nchunk;
1059 uint64_tcxx . . $ uint64_t# Nloop_all, Nloop_rw;
1060 uint32_tcxx . . $ uint32_t# i;
1061
1062 Nchunk = N / p;
1063 Nloop_all = Nchunk;
1064 if (flags & YESCRYPT_RWcxx . . $ `lib/alg-yescrypt.h:90:9`!) {
1065 if (t <= 1) {
1066 if (t)
1067 Nloop_all *= 2; /* 2/3 */
1068 Nloop_all = (Nloop_all + 2) / 3; /* 1/3, round up */
1069 } else {
1070 Nloop_all *= t - 1;
1071 }
1072 } else if (t) {
1073 if (t == 1)
1074 Nloop_all += (Nloop_all + 1) / 2; /* 1.5, round up */
1075 Nloop_all *= t;
1076 }
1077
1078 Nloop_rw = 0;
1079 if (flags & YESCRYPT_INIT_SHAREDcxx . . $ `lib/alg-yescrypt.h:115:9`!)
1080 Nloop_rw = Nloop_all;
1081 else if (flags & YESCRYPT_RWcxx . . $ `lib/alg-yescrypt.h:90:9`!)
1082 Nloop_rw = Nloop_all / p;
1083
1084 Nchunk &= ~(uint32_tcxx . . $ uint32_t#)1; /* round down to even */
1085 Nloop_all++; Nloop_all &= ~(uint64_tcxx . . $ uint64_t#)1; /* round up to even */
1086 Nloop_rw++; Nloop_rw &= ~(uint64_tcxx . . $ uint64_t#)1; /* round up to even */
1087
1088 #ifdef _OPENMP
1089 #pragma omp parallel if (p > 1) default(none) private(i) shared(B, r, N, p, flags, V, NROM, VROM, XY, S, passwd, s, Nchunk, Nloop_all, Nloop_rw)
1090 {
1091 #pragma omp for
1092 #endif
1093 for (i = 0; i < p; i++) {
1094 uint32_tcxx . . $ uint32_t# Vchunk = i * Nchunk;
1095 uint32_tcxx . . $ uint32_t# Np = (i < p - 1) ? Nchunk : (N - Vchunk);
1096 uint8_tcxx . . $ uint8_t# *Bp = &B[128 * r * i];
1097 salsa20_blk_tcxx . . $ salsa20_blk_t# *Vp = &V[Vchunk * s];
1098 #ifdef _OPENMP
1099 salsa20_blk_t *XYp = &XY[i * (2 * s)];
1100 #else
1101 salsa20_blk_tcxx . . $ salsa20_blk_t# *XYp = XY;
1102 #endif
1103 pwxform_ctx_tcxx . . $ pwxform_ctx_t# *ctx_i = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
1104 if (flags & YESCRYPT_RWcxx . . $ `lib/alg-yescrypt.h:90:9`!) {
1105 uint8_tcxx . . $ uint8_t# *Si = S + i * Salloccxx . . $ `lib/alg-yescrypt-opt.c:653:9`!;
1106 smix1cxx . . $ smix1(fbd2cf9bbfbe6904).(Bp, 1, Sbytescxx . . $ `lib/alg-yescrypt-opt.c:437:9`! / 128, 0 /* no flags */,
1107 (salsa20_blk_tcxx . . $ salsa20_blk_t# *)Si, 0, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, XYp, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
1108 ctx_i = (pwxform_ctx_tcxx . . $ pwxform_ctx_t# *)(Si + Sbytescxx . . $ `lib/alg-yescrypt-opt.c:437:9`!);
1109 ctx_i->S2cxx . . $ $anonymous_type_9397105a3f57d04f_1#S2. = Si;
1110 ctx_i->S1cxx . . $ $anonymous_type_9397105a3f57d04f_1#S1. = Si + Sbytescxx . . $ `lib/alg-yescrypt-opt.c:437:9`! / 3;
1111 ctx_i->S0cxx . . $ $anonymous_type_9397105a3f57d04f_1#S0. = Si + Sbytescxx . . $ `lib/alg-yescrypt-opt.c:437:9`! / 3 * 2;
1112 ctx_i->wcxx . . $ $anonymous_type_9397105a3f57d04f_1#w. = 0;
1113 if (i == 0)
1114 HMAC_SHA256_Bufcxx . . $ `lib/alg-sha256.h:47:9`!(Bp + (128 * r - 64), 64,
1115 passwd, 32, passwd);
1116 }
1117 smix1cxx . . $ smix1(fbd2cf9bbfbe6904).(Bp, r, Np, flags, Vp, NROM, VROM, XYp, ctx_i);
1118 smix2cxx . . $ smix2(e4c2e9d7a9348391).(Bp, r, p2floorcxx . . $ p2floor(ecdaa1632f49f591).(Np), Nloop_rw, flags, Vp,
1119 NROM, VROM, XYp, ctx_i);
1120 }
1121
1122 if (Nloop_all > Nloop_rw) {
1123 #ifdef _OPENMP
1124 #pragma omp for
1125 #endif
1126 for (i = 0; i < p; i++) {
1127 uint8_tcxx . . $ uint8_t# *Bp = &B[128 * r * i];
1128 #ifdef _OPENMP
1129 salsa20_blk_t *XYp = &XY[i * (2 * s)];
1130 #else
1131 salsa20_blk_tcxx . . $ salsa20_blk_t# *XYp = XY;
1132 #endif
1133 pwxform_ctx_tcxx . . $ pwxform_ctx_t# *ctx_i = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
1134 if (flags & YESCRYPT_RWcxx . . $ `lib/alg-yescrypt.h:90:9`!) {
1135 uint8_tcxx . . $ uint8_t# *Si = S + i * Salloccxx . . $ `lib/alg-yescrypt-opt.c:653:9`!;
1136 ctx_i = (pwxform_ctx_tcxx . . $ pwxform_ctx_t# *)(Si + Sbytescxx . . $ `lib/alg-yescrypt-opt.c:437:9`!);
1137 }
1138 smix2cxx . . $ smix2(e4c2e9d7a9348391).(Bp, r, N, Nloop_all - Nloop_rw,
1139 flags & (yescrypt_flags_tcxx . . $ yescrypt_flags_t#)~YESCRYPT_RWcxx . . $ `lib/alg-yescrypt.h:90:9`!,
1140 V, NROM, VROM, XYp, ctx_i);
1141 }
1142 }
1143 #ifdef _OPENMP
1144 }
1145 #endif
1146 }
1147
1148 /**
1149 * yescrypt_kdf_body(shared, local, passwd, passwdlen, salt, saltlen,
1150 * flags, N, r, p, t, NROM, buf, buflen):
1151 * Compute scrypt(passwd[0 .. passwdlen - 1], salt[0 .. saltlen - 1], N, r,
1152 * p, buflen), or a revision of scrypt as requested by flags and shared, and
1153 * write the result into buf.
1154 *
1155 * shared and flags may request special modes as described in yescrypt.h.
1156 *
1157 * local is the thread-local data structure, allowing to preserve and reuse a
1158 * memory allocation across calls, thereby reducing its overhead.
1159 *
1160 * t controls computation time while not affecting peak memory usage.
1161 *
1162 * Return 0 on success; or -1 on error.
1163 *
1164 * This optimized implementation currently limits N to the range from 4 to
1165 * 2^31, but other implementations might not.
1166 */
1167 static int yescrypt_kdf_bodycxx . . $ yescrypt_kdf_body(a294d32fc7c5c6b7).(const yescrypt_shared_tcxx . . $ yescrypt_shared_t# *shared,
1168 yescrypt_local_tcxx . . $ yescrypt_local_t# *local,
1169 const uint8_tcxx . . $ uint8_t# *passwd, size_t passwdlen,
1170 const uint8_tcxx . . $ uint8_t# *salt, size_t saltlen,
1171 yescrypt_flags_tcxx . . $ yescrypt_flags_t# flags, uint64_tcxx . . $ uint64_t# N, uint32_tcxx . . $ uint32_t# r, uint32_tcxx . . $ uint32_t# p, uint32_tcxx . . $ uint32_t# t,
1172 uint64_tcxx . . $ uint64_t# NROM,
1173 uint8_tcxx . . $ uint8_t# *buf, size_t buflen)
1174 {
1175 yescrypt_region_tcxx . . $ yescrypt_region_t# tmp;
1176 const salsa20_blk_tcxx . . $ salsa20_blk_t# *VROM;
1177 size_t B_size, V_size, XY_size, need;
1178 uint8_tcxx . . $ uint8_t# *B, *S;
1179 salsa20_blk_tcxx . . $ salsa20_blk_t# *V, *XY;
1180 uint8_tcxx . . $ uint8_t# sha256[32];
1181 uint8_tcxx . . $ uint8_t# dk[sizeof(sha256)], *dkp = buf;
1182
1183 /* Sanity-check parameters */
1184 switch (flags & YESCRYPT_MODE_MASKcxx . . $ `lib/alg-yescrypt.h:113:9`!) {
1185 case 0: /* classic scrypt - can't have anything non-standard */
1186 if (flags || t || NROM)
1187 goto out_EINVAL;
1188 break;
1189 case YESCRYPT_WORMcxx . . $ `lib/alg-yescrypt.h:89:9`!:
1190 if (flags != YESCRYPT_WORMcxx . . $ `lib/alg-yescrypt.h:89:9`! || NROM)
1191 goto out_EINVAL;
1192 break;
1193 case YESCRYPT_RWcxx . . $ `lib/alg-yescrypt.h:90:9`!:
1194 if (flags != (flags & YESCRYPT_KNOWN_FLAGScxx . . $ `lib/alg-yescrypt.h:128:9`!))
1195 goto out_EINVAL;
1196 #if PWXsimplecxx . . $ `lib/alg-yescrypt-opt.c:432:9`! == 2 && PWXgathercxx . . $ `lib/alg-yescrypt-opt.c:433:9`! == 4 && Sbytescxx . . $ `lib/alg-yescrypt-opt.c:437:9`! == 12288
1197 if ((flags & YESCRYPT_RW_FLAVOR_MASKcxx . . $ `lib/alg-yescrypt.h:114:9`!) ==
1198 (YESCRYPT_ROUNDS_6cxx . . $ `lib/alg-yescrypt.h:92:9`! | YESCRYPT_GATHER_4cxx . . $ `lib/alg-yescrypt.h:95:9`! |
1199 YESCRYPT_SIMPLE_2cxx . . $ `lib/alg-yescrypt.h:98:9`! | YESCRYPT_SBOX_12Kcxx . . $ `lib/alg-yescrypt.h:102:9`!))
1200 break;
1201 #else
1202 #error "Unsupported pwxform settings"
1203 #endif
1204 /* FALLTHRU */
1205 default:
1206 goto out_EINVAL;
1207 }
1208 #if SIZE_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:222:11`! > UINT32_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:124:10`!
1209 if (buflen > (((uint64_tcxx . . $ uint64_t#)1 << 32) - 1) * 32)
1210 goto out_EINVAL;
1211 #endif
1212 if ((uint64_tcxx . . $ uint64_t#)r * (uint64_tcxx . . $ uint64_t#)p >= 1 << 30)
1213 goto out_EINVAL;
1214 if (N > UINT32_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:124:10`!)
1215 goto out_EINVAL;
1216 if ((N & (N - 1)) != 0 || N <= 3 || r < 1 || p < 1)
1217 goto out_EINVAL;
1218 if (r > SIZE_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:222:11`! / 256 / p ||
1219 N > SIZE_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:222:11`! / 128 / r)
1220 goto out_EINVAL;
1221 if (flags & YESCRYPT_RWcxx . . $ `lib/alg-yescrypt.h:90:9`!) {
1222 /* p cannot be greater than SIZE_MAX/Salloc on 64-bit systems,
1223 but it can on 32-bit systems. */
1224 #pragma GCC diagnostic push
1225 #pragma GCC diagnostic ignored "-Wtype-limits"
1226 if (N / p <= 3 || p > SIZE_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:222:11`! / Salloccxx . . $ `lib/alg-yescrypt-opt.c:653:9`!)
1227 goto out_EINVAL;
1228 #pragma GCC diagnostic pop
1229 }
1230 #ifdef _OPENMP
1231 else if (N > SIZE_MAX / 128 / (r * p)) {
1232 goto out_EINVAL;
1233 }
1234 #endif
1235
1236 VROM = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
1237 if (shared) {
1238 uint64_tcxx . . $ uint64_t# expected_size = (size_t)128 * r * NROM;
1239 // coverity[overflow_const]
1240 if ((NROM & (NROM - 1)) != 0 ||
1241 NROM <= 1 || NROM > UINT32_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:124:10`! ||
1242 shared->aligned_sizecxx . . $ $anonymous_type_b025ac6af4ec7e0f_0#aligned_size. < expected_size)
1243 goto out_EINVAL;
1244 if (!(flags & YESCRYPT_INIT_SHAREDcxx . . $ `lib/alg-yescrypt.h:115:9`!)) {
1245 uint64_tcxx . . $ uint64_t# *tag = (uint64_tcxx . . $ uint64_t# *)
1246 ((uint8_tcxx . . $ uint8_t# *)shared->alignedcxx . . $ $anonymous_type_b025ac6af4ec7e0f_0#aligned. + expected_size - 48);
1247 if (tag[0] != YESCRYPT_ROM_TAG1cxx . . $ `lib/alg-yescrypt.h:77:9`! || tag[1] != YESCRYPT_ROM_TAG2cxx . . $ `lib/alg-yescrypt.h:78:9`!)
1248 goto out_EINVAL;
1249 }
1250 VROM = shared->alignedcxx . . $ $anonymous_type_b025ac6af4ec7e0f_0#aligned.;
1251 } else {
1252 if (NROM)
1253 goto out_EINVAL;
1254 }
1255
1256 /* Allocate memory */
1257 V = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
1258 V_size = (size_t)128 * r * N;
1259 #ifdef _OPENMP
1260 if (!(flags & YESCRYPT_RW))
1261 V_size *= p;
1262 #endif
1263 need = V_size;
1264 if (flags & YESCRYPT_INIT_SHAREDcxx . . $ `lib/alg-yescrypt.h:115:9`!) {
1265 if (local->aligned_sizecxx . . $ $anonymous_type_b025ac6af4ec7e0f_0#aligned_size. < need) {
1266 if (local->basecxx . . $ $anonymous_type_b025ac6af4ec7e0f_0#base. || local->alignedcxx . . $ $anonymous_type_b025ac6af4ec7e0f_0#aligned. ||
1267 local->base_sizecxx . . $ $anonymous_type_b025ac6af4ec7e0f_0#base_size. || local->aligned_sizecxx . . $ $anonymous_type_b025ac6af4ec7e0f_0#aligned_size.)
1268 goto out_EINVAL;
1269 if (!alloc_regioncxx . . $ alloc_region(a6b0cddae93ea2fa).(local, need))
1270 return -1;
1271 }
1272 if (flags & YESCRYPT_ALLOC_ONLYcxx . . $ `lib/alg-yescrypt.h:116:9`!)
1273 return -2; /* expected "failure" */
1274 V = (salsa20_blk_tcxx . . $ salsa20_blk_t# *)local->alignedcxx . . $ $anonymous_type_b025ac6af4ec7e0f_0#aligned.;
1275 need = 0;
1276 }
1277 B_size = (size_t)128 * r * p;
1278 need += B_size;
1279 if (need < B_size)
1280 goto out_EINVAL;
1281 XY_size = (size_t)256 * r;
1282 #ifdef _OPENMP
1283 XY_size *= p;
1284 #endif
1285 need += XY_size;
1286 if (need < XY_size)
1287 goto out_EINVAL;
1288 if (flags & YESCRYPT_RWcxx . . $ `lib/alg-yescrypt.h:90:9`!) {
1289 size_t S_size = (size_t)Salloccxx . . $ `lib/alg-yescrypt-opt.c:653:9`! * p;
1290 need += S_size;
1291 if (need < S_size)
1292 goto out_EINVAL;
1293 }
1294 if (flags & YESCRYPT_INIT_SHAREDcxx . . $ `lib/alg-yescrypt.h:115:9`!) {
1295 if (!alloc_regioncxx . . $ alloc_region(a6b0cddae93ea2fa).(&tmp, need))
1296 return -1;
1297 B = (uint8_tcxx . . $ uint8_t# *)tmp.alignedcxx . . $ $anonymous_type_b025ac6af4ec7e0f_0#aligned.;
1298 XY = (salsa20_blk_tcxx . . $ salsa20_blk_t# *)((uint8_tcxx . . $ uint8_t# *)B + B_size);
1299 } else {
1300 init_regioncxx . . $ init_region(fd3272d669fc1463).(&tmp);
1301 if (local->aligned_sizecxx . . $ $anonymous_type_b025ac6af4ec7e0f_0#aligned_size. < need) {
1302 if (free_regioncxx . . $ free_region(32522aed775e25b7).(local))
1303 return -1;
1304 if (!alloc_regioncxx . . $ alloc_region(a6b0cddae93ea2fa).(local, need))
1305 return -1;
1306 }
1307 if (flags & YESCRYPT_ALLOC_ONLYcxx . . $ `lib/alg-yescrypt.h:116:9`!)
1308 return -3; /* expected "failure" */
1309 B = (uint8_tcxx . . $ uint8_t# *)local->alignedcxx . . $ $anonymous_type_b025ac6af4ec7e0f_0#aligned.;
1310 V = (salsa20_blk_tcxx . . $ salsa20_blk_t# *)((uint8_tcxx . . $ uint8_t# *)B + B_size);
1311 XY = (salsa20_blk_tcxx . . $ salsa20_blk_t# *)((uint8_tcxx . . $ uint8_t# *)V + V_size);
1312 }
1313 S = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
1314 if (flags & YESCRYPT_RWcxx . . $ `lib/alg-yescrypt.h:90:9`!)
1315 S = (uint8_tcxx . . $ uint8_t# *)XY + XY_size;
1316
1317 if (flags) {
1318 HMAC_SHA256_Bufcxx . . $ `lib/alg-sha256.h:47:9`!("yescrypt-prehash",
1319 (flags & YESCRYPT_PREHASHcxx . . $ `lib/alg-yescrypt.h:117:9`!) ? 16 : 8,
1320 passwd, passwdlen, sha256);
1321 passwd = sha256;
1322 passwdlen = sizeof(sha256);
1323 }
1324
1325 PBKDF2_SHA256cxx . . $ `lib/crypt-port.h:376:9`!(passwd, passwdlen, salt, saltlen, 1, B, B_size);
1326
1327 if (flags)
1328 memcpycxx . . $ memcpy(cc817cb175f282d).(sha256, B, sizeof(sha256));
1329
1330 if (p == 1 || (flags & YESCRYPT_RWcxx . . $ `lib/alg-yescrypt.h:90:9`!)) {
1331 smixcxx . . $ smix(d90d48d4433e8791).(B, r, N, p, t, flags, V, NROM, VROM, XY, S, sha256);
1332 } else {
1333 uint32_tcxx . . $ uint32_t# i;
1334 #ifdef _OPENMP
1335 #pragma omp parallel for default(none) private(i) shared(B, r, N, p, t, flags, V, NROM, VROM, XY, S)
1336 #endif
1337 for (i = 0; i < p; i++) {
1338 #ifdef _OPENMP
1339 smix(&B[(size_t)128 * r * i], r, N, 1, t, flags,
1340 &V[(size_t)2 * r * i * N],
1341 NROM, VROM,
1342 &XY[(size_t)4 * r * i], NULL, NULL);
1343 #else
1344 smixcxx . . $ smix(d90d48d4433e8791).(&B[(size_t)128 * r * i], r, N, 1, t, flags, V,
1345 NROM, VROM, XY, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
1346 #endif
1347 }
1348 }
1349
1350 dkp = buf;
1351 if (flags && buflen < sizeof(dk)) {
1352 PBKDF2_SHA256cxx . . $ `lib/crypt-port.h:376:9`!(passwd, passwdlen, B, B_size, 1, dk, sizeof(dk));
1353 dkp = dk;
1354 }
1355
1356 PBKDF2_SHA256cxx . . $ `lib/crypt-port.h:376:9`!(passwd, passwdlen, B, B_size, 1, buf, buflen);
1357
1358 /*
1359 * Except when computing classic scrypt, allow all computation so far
1360 * to be performed on the client. The final steps below match those of
1361 * SCRAM (RFC 5802), so that an extension of SCRAM (with the steps so
1362 * far in place of SCRAM's use of PBKDF2 and with SHA-256 in place of
1363 * SCRAM's use of SHA-1) would be usable with yescrypt hashes.
1364 */
1365 if (flags && !(flags & YESCRYPT_PREHASHcxx . . $ `lib/alg-yescrypt.h:117:9`!)) {
1366 /* Compute ClientKey */
1367 HMAC_SHA256_Bufcxx . . $ `lib/alg-sha256.h:47:9`!(dkp, sizeof(dk), "Client Key", 10, sha256);
1368 /* Compute StoredKey */
1369 {
1370 size_t clen = buflen;
1371 if (clen > sizeof(dk))
1372 clen = sizeof(dk);
1373 SHA256_Bufcxx . . $ `lib/alg-sha256.h:42:9`!(sha256, sizeof(sha256), dk);
1374 memcpycxx . . $ memcpy(cc817cb175f282d).(buf, dk, clen);
1375 }
1376 }
1377
1378 if (flags) {
1379 explicit_bzerocxx . . $ `lib/crypt-port.h:166:9`!(sha256, sizeof(sha256));
1380 explicit_bzerocxx . . $ `lib/crypt-port.h:166:9`!(dk, sizeof(dk));
1381 }
1382
1383 if (free_regioncxx . . $ free_region(32522aed775e25b7).(&tmp)) {
1384 explicit_bzerocxx . . $ `lib/crypt-port.h:166:9`!(buf, buflen); /* must preserve errno */
1385 return -1;
1386 }
1387
1388 /* Success! */
1389 return 0;
1390
1391 out_EINVAL:
1392 errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!;
1393 return -1;
1394 }
1395
1396 /**
1397 * yescrypt_kdf(shared, local, passwd, passwdlen, salt, saltlen, params,
1398 * buf, buflen):
1399 * Compute scrypt or its revision as requested by the parameters. The inputs
1400 * to this function are the same as those for yescrypt_kdf_body() above, with
1401 * the addition of g, which controls hash upgrades (0 for no upgrades so far).
1402 */
1403 int yescrypt_kdfcxx . . $ `lib/crypt-port.h:388:9`!(const yescrypt_shared_tcxx . . $ yescrypt_shared_t# *shared, yescrypt_local_tcxx . . $ yescrypt_local_t# *local,
1404 const uint8_tcxx . . $ uint8_t# *passwd, size_t passwdlen,
1405 const uint8_tcxx . . $ uint8_t# *salt, size_t saltlen,
1406 const yescrypt_params_tcxx . . $ yescrypt_params_t# *params,
1407 uint8_tcxx . . $ uint8_t# *buf, size_t buflen)
1408 {
1409 yescrypt_flags_tcxx . . $ yescrypt_flags_t# flags = params->flagscxx . . $ $anonymous_type_b025ac6af4ec7e0f_1#flags.;
1410 uint64_tcxx . . $ uint64_t# N = params->Ncxx . . $ $anonymous_type_b025ac6af4ec7e0f_1#N.;
1411 uint32_tcxx . . $ uint32_t# r = params->rcxx . . $ $anonymous_type_b025ac6af4ec7e0f_1#r.;
1412 uint32_tcxx . . $ uint32_t# p = params->pcxx . . $ $anonymous_type_b025ac6af4ec7e0f_1#p.;
1413 uint32_tcxx . . $ uint32_t# t = params->tcxx . . $ $anonymous_type_b025ac6af4ec7e0f_1#t.;
1414 uint32_tcxx . . $ uint32_t# g = params->gcxx . . $ $anonymous_type_b025ac6af4ec7e0f_1#g.;
1415 uint64_tcxx . . $ uint64_t# NROM = params->NROMcxx . . $ $anonymous_type_b025ac6af4ec7e0f_1#NROM.;
1416 uint8_tcxx . . $ uint8_t# dk[32];
1417 int retval;
1418
1419 /* Support for hash upgrades has been temporarily removed */
1420 if (g) {
1421 errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!;
1422 return -1;
1423 }
1424
1425 if ((flags & (YESCRYPT_RWcxx . . $ `lib/alg-yescrypt.h:90:9`! | YESCRYPT_INIT_SHAREDcxx . . $ `lib/alg-yescrypt.h:115:9`!)) == YESCRYPT_RWcxx . . $ `lib/alg-yescrypt.h:90:9`! &&
1426 p >= 1 && N / p >= 0x100 && N / p * r >= 0x20000) {
1427 if (yescrypt_kdf_bodycxx . . $ yescrypt_kdf_body(a294d32fc7c5c6b7).(shared, local,
1428 passwd, passwdlen, salt, saltlen,
1429 flags | YESCRYPT_ALLOC_ONLYcxx . . $ `lib/alg-yescrypt.h:116:9`!, N, r, p, t, NROM,
1430 buf, buflen) != -3) {
1431 errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!;
1432 return -1;
1433 }
1434 if ((retval = yescrypt_kdf_bodycxx . . $ yescrypt_kdf_body(a294d32fc7c5c6b7).(shared, local,
1435 passwd, passwdlen, salt, saltlen,
1436 flags | YESCRYPT_PREHASHcxx . . $ `lib/alg-yescrypt.h:117:9`!, N >> 6, r, p, 0, NROM,
1437 dk, sizeof(dk))))
1438 return retval;
1439 passwd = dk;
1440 passwdlen = sizeof(dk);
1441 }
1442
1443 retval = yescrypt_kdf_bodycxx . . $ yescrypt_kdf_body(a294d32fc7c5c6b7).(shared, local,
1444 passwd, passwdlen, salt, saltlen,
1445 flags, N, r, p, t, NROM, buf, buflen);
1446 #ifndef SKIP_MEMZERO
1447 if (passwd == dk)
1448 explicit_bzerocxx . . $ `lib/crypt-port.h:166:9`!(dk, sizeof(dk));
1449 #endif
1450 return retval;
1451 }
1452
1453 int yescrypt_init_sharedcxx . . $ `lib/crypt-port.h:387:9`!(yescrypt_shared_tcxx . . $ yescrypt_shared_t# *shared,
1454 const uint8_tcxx . . $ uint8_t# *seed, size_t seedlen,
1455 const yescrypt_params_tcxx . . $ yescrypt_params_t# *params)
1456 {
1457 yescrypt_params_tcxx . . $ yescrypt_params_t# subparams;
1458 yescrypt_shared_tcxx . . $ yescrypt_shared_t# half1, half2;
1459 uint8_tcxx . . $ uint8_t# salt[32];
1460 uint64_tcxx . . $ uint64_t# *tag;
1461
1462 subparams = *params;
1463 subparams.flagscxx . . $ $anonymous_type_b025ac6af4ec7e0f_1#flags. |= YESCRYPT_INIT_SHAREDcxx . . $ `lib/alg-yescrypt.h:115:9`!;
1464 subparams.Ncxx . . $ $anonymous_type_b025ac6af4ec7e0f_1#N. = params->NROMcxx . . $ $anonymous_type_b025ac6af4ec7e0f_1#NROM.;
1465 subparams.NROMcxx . . $ $anonymous_type_b025ac6af4ec7e0f_1#NROM. = 0;
1466
1467 if (!(params->flagscxx . . $ $anonymous_type_b025ac6af4ec7e0f_1#flags. & YESCRYPT_RWcxx . . $ `lib/alg-yescrypt.h:90:9`!) || params->Ncxx . . $ $anonymous_type_b025ac6af4ec7e0f_1#N. || params->gcxx . . $ $anonymous_type_b025ac6af4ec7e0f_1#g.)
1468 return -1;
1469
1470 if (params->flagscxx . . $ $anonymous_type_b025ac6af4ec7e0f_1#flags. & YESCRYPT_SHARED_PREALLOCATEDcxx . . $ `lib/alg-yescrypt.h:110:9`!) {
1471 if (!shared->alignedcxx . . $ $anonymous_type_b025ac6af4ec7e0f_0#aligned. || !shared->aligned_sizecxx . . $ $anonymous_type_b025ac6af4ec7e0f_0#aligned_size.)
1472 return -1;
1473
1474 /* Overwrite a possible old ROM tag before we overwrite the rest */
1475 tag = (uint64_tcxx . . $ uint64_t# *)
1476 ((uint8_tcxx . . $ uint8_t# *)shared->alignedcxx . . $ $anonymous_type_b025ac6af4ec7e0f_0#aligned. + shared->aligned_sizecxx . . $ $anonymous_type_b025ac6af4ec7e0f_0#aligned_size. - 48);
1477 memsetcxx . . $ memset(d1de1e4fb215f1c6).(tag, 0, 48);
1478 } else {
1479 init_regioncxx . . $ init_region(fd3272d669fc1463).(shared);
1480
1481 subparams.flagscxx . . $ $anonymous_type_b025ac6af4ec7e0f_1#flags. |= YESCRYPT_ALLOC_ONLYcxx . . $ `lib/alg-yescrypt.h:116:9`!;
1482 if (yescrypt_kdfcxx . . $ `lib/crypt-port.h:388:9`!(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, shared, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, 0, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, 0, &subparams,
1483 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, 0) != -2 || !shared->alignedcxx . . $ $anonymous_type_b025ac6af4ec7e0f_0#aligned.)
1484 return -1;
1485 subparams.flagscxx . . $ $anonymous_type_b025ac6af4ec7e0f_1#flags. -= YESCRYPT_ALLOC_ONLYcxx . . $ `lib/alg-yescrypt.h:116:9`!;
1486 }
1487
1488 subparams.Ncxx . . $ $anonymous_type_b025ac6af4ec7e0f_1#N. /= 2;
1489
1490 half1 = *shared;
1491 half1.aligned_sizecxx . . $ $anonymous_type_b025ac6af4ec7e0f_0#aligned_size. /= 2;
1492 half2 = half1;
1493 half2.alignedcxx . . $ $anonymous_type_b025ac6af4ec7e0f_0#aligned. = (uint8_tcxx . . $ uint8_t# *)half2.alignedcxx . . $ $anonymous_type_b025ac6af4ec7e0f_0#aligned. + half1.aligned_sizecxx . . $ $anonymous_type_b025ac6af4ec7e0f_0#aligned_size.;
1494
1495 if (yescrypt_kdfcxx . . $ `lib/crypt-port.h:388:9`!(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, &half1,
1496 seed, seedlen, (const uint8_tcxx . . $ uint8_t# *)"yescrypt-ROMhash", 16, &subparams,
1497 salt, sizeof(salt)))
1498 goto fail;
1499
1500 subparams.NROMcxx . . $ $anonymous_type_b025ac6af4ec7e0f_1#NROM. = subparams.Ncxx . . $ $anonymous_type_b025ac6af4ec7e0f_1#N.;
1501
1502 if (yescrypt_kdfcxx . . $ `lib/crypt-port.h:388:9`!(&half1, &half2,
1503 seed, seedlen, salt, sizeof(salt), &subparams, salt, sizeof(salt)))
1504 goto fail;
1505
1506 if (yescrypt_kdfcxx . . $ `lib/crypt-port.h:388:9`!(&half2, &half1,
1507 seed, seedlen, salt, sizeof(salt), &subparams, salt, sizeof(salt)))
1508 goto fail;
1509
1510 tag = (uint64_tcxx . . $ uint64_t# *)
1511 ((uint8_tcxx . . $ uint8_t# *)shared->alignedcxx . . $ $anonymous_type_b025ac6af4ec7e0f_0#aligned. + shared->aligned_sizecxx . . $ $anonymous_type_b025ac6af4ec7e0f_0#aligned_size. - 48);
1512 tag[0] = YESCRYPT_ROM_TAG1cxx . . $ `lib/alg-yescrypt.h:77:9`!;
1513 tag[1] = YESCRYPT_ROM_TAG2cxx . . $ `lib/alg-yescrypt.h:78:9`!;
1514 tag[2] = le64deccxx . . $ `lib/byteorder.h:152:9`!(salt);
1515 tag[3] = le64deccxx . . $ `lib/byteorder.h:152:9`!(salt + 8);
1516 tag[4] = le64deccxx . . $ `lib/byteorder.h:152:9`!(salt + 16);
1517 tag[5] = le64deccxx . . $ `lib/byteorder.h:152:9`!(salt + 24);
1518
1519 explicit_bzerocxx . . $ `lib/crypt-port.h:166:9`!(salt, sizeof(salt));
1520 return 0;
1521
1522 fail:
1523 explicit_bzerocxx . . $ `lib/crypt-port.h:166:9`!(salt, sizeof(salt));
1524 if (!(params->flagscxx . . $ $anonymous_type_b025ac6af4ec7e0f_1#flags. & YESCRYPT_SHARED_PREALLOCATEDcxx . . $ `lib/alg-yescrypt.h:110:9`!))
1525 free_regioncxx . . $ free_region(32522aed775e25b7).(shared);
1526 return -1;
1527 }
1528
1529 yescrypt_binary_tcxx . . $ yescrypt_binary_t# *yescrypt_digest_sharedcxx . . $ `lib/crypt-port.h:380:9`!(yescrypt_shared_tcxx . . $ yescrypt_shared_t# *shared)
1530 {
1531 static yescrypt_binary_tcxx . . $ yescrypt_binary_t# digest;
1532 uint64_tcxx . . $ uint64_t# *tag;
1533
1534 if (shared->aligned_sizecxx . . $ $anonymous_type_b025ac6af4ec7e0f_0#aligned_size. < 48)
1535 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
1536
1537 tag = (uint64_tcxx . . $ uint64_t# *)
1538 ((uint8_tcxx . . $ uint8_t# *)shared->alignedcxx . . $ $anonymous_type_b025ac6af4ec7e0f_0#aligned. + shared->aligned_sizecxx . . $ $anonymous_type_b025ac6af4ec7e0f_0#aligned_size. - 48);
1539
1540 if (tag[0] != YESCRYPT_ROM_TAG1cxx . . $ `lib/alg-yescrypt.h:77:9`! || tag[1] != YESCRYPT_ROM_TAG2cxx . . $ `lib/alg-yescrypt.h:78:9`!)
1541 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
1542
1543 le64enccxx . . $ `lib/byteorder.h:151:9`!(digest.uccxx . . $ $anonymous_type_b025ac6af4ec7e0f_2#uc., tag[2]);
1544 le64enccxx . . $ `lib/byteorder.h:151:9`!(digest.uccxx . . $ $anonymous_type_b025ac6af4ec7e0f_2#uc. + 8, tag[3]);
1545 le64enccxx . . $ `lib/byteorder.h:151:9`!(digest.uccxx . . $ $anonymous_type_b025ac6af4ec7e0f_2#uc. + 16, tag[4]);
1546 le64enccxx . . $ `lib/byteorder.h:151:9`!(digest.uccxx . . $ $anonymous_type_b025ac6af4ec7e0f_2#uc. + 24, tag[5]);
1547
1548 return &digest;
1549 }
1550
1551 int yescrypt_free_sharedcxx . . $ `lib/crypt-port.h:385:9`!(yescrypt_shared_tcxx . . $ yescrypt_shared_t# *shared)
1552 {
1553 return free_regioncxx . . $ free_region(32522aed775e25b7).(shared);
1554 }
1555
1556 int yescrypt_init_localcxx . . $ `lib/crypt-port.h:386:9`!(yescrypt_local_tcxx . . $ yescrypt_local_t# *local)
1557 {
1558 init_regioncxx . . $ init_region(fd3272d669fc1463).(local);
1559 return 0;
1560 }
1561
1562 int yescrypt_free_localcxx . . $ `lib/crypt-port.h:384:9`!(yescrypt_local_tcxx . . $ yescrypt_local_t# *local)
1563 {
1564 return free_regioncxx . . $ free_region(32522aed775e25b7).(local);
1565 }
1566
1567 #endif /* INCLUDE_yescrypt || INCLUDE_scrypt || INCLUDE_gost_yescrypt ||
1568 INCLUDE_sm3_yescrypt */