Debian Codegraph @

fiat-bedrock2/src/poly1305_32.c

raw symbols SCIP
1 /* Autogenerated: 'src/ExtractionOCaml/bedrock2_unsaturated_solinas' --lang bedrock2 --static --no-wide-int --widen-carry --widen-bytes --split-multiret --no-select --no-field-element-typedefs poly1305 32 '(auto)' '2^130 - 5' carry_mul carry_square carry add sub opp selectznz to_bytes from_bytes relax */
2 /* curve description: poly1305 */
3 /* machine_wordsize = 32 (from "32") */
4 /* requested operations: carry_mul, carry_square, carry, add, sub, opp, selectznz, to_bytes, from_bytes, relax */
5 /* n = 5 (from "(auto)") */
6 /* s-c = 2^130 - [(1, 5)] (from "2^130 - 5") */
7 /* tight_bounds_multiplier = 1 (from "") */
8 /* */
9 /* Computed values: */
10 /* carry_chain = [0, 1, 2, 3, 4, 0, 1] */
11 /* eval z = z[0] + (z[1] << 26) + (z[2] << 52) + (z[3] << 78) + (z[4] << 104) */
12 /* bytes_eval z = z[0] + (z[1] << 8) + (z[2] << 16) + (z[3] << 24) + (z[4] << 32) + (z[5] << 40) + (z[6] << 48) + (z[7] << 56) + (z[8] << 64) + (z[9] << 72) + (z[10] << 80) + (z[11] << 88) + (z[12] << 96) + (z[13] << 104) + (z[14] << 112) + (z[15] << 120) + (z[16] << 128) */
13 /* balance = [0x7fffff6, 0x7fffffe, 0x7fffffe, 0x7fffffe, 0x7fffffe] */
14
15 // Generated from Bedrock code. Avoid editing directly.
16 #include <stdint.h>
17 #include <string.h>
18 #include <assert.h>
19
20 #define BR_WORD_MAX UINTPTR_MAX
21 typedef uintptr_t br_word_t;
22 typedef intptr_t br_signed_t;
23
24 static_assert(sizeof(br_word_t) == sizeof(br_signed_t), "signed size");
25 static_assert(UINTPTR_MAX <= BR_WORD_MAX, "pointer fits in int");
26 static_assert(~(br_signed_t)0 == -(br_signed_t)1, "two's complement");
27
28 #if __STDC_VERSION__ >= 202311L && __has_include(<stdbit.h>)
29 #include <stdbit.h>
30 static_assert(__STDC_ENDIAN_NATIVE__ == __STDC_ENDIAN_LITTLE__, "little-endian");
31 #elif defined(__GNUC__) && defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__)
32 static_assert(__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__, "little-endian");
33 #elif defined(_MSC_VER) && !defined(__clang__) && \
34 (defined(_M_IX86) || defined(_M_X64) || defined(_M_ARM) || defined(_M_ARM64))
35 // these MSVC targets are little-endian
36 #else
37 #error "failed to confirm that target is little-endian"
38 #endif
39
40 // "An object shall have its stored value accessed only ... a character type."
41 static inline br_word_t _br_load1(br_word_t a) {
42 return *((uint8_t *)a);
43 }
44
45 static inline br_word_t _br_load2(br_word_t a) {
46 uint16_t r = 0;
47 memcpy(&r, (void *)a, sizeof(r));
48 return r;
49 }
50
51 static inline br_word_t _br_load4(br_word_t a) {
52 uint32_t r = 0;
53 memcpy(&r, (void *)a, sizeof(r));
54 return r;
55 }
56
57 static inline br_word_t _br_load(br_word_t a) {
58 br_word_t r = 0;
59 memcpy(&r, (void *)a, sizeof(r));
60 return r;
61 }
62
63 static inline void _br_store1(br_word_t a, uint8_t v) {
64 *((uint8_t *)a) = v;
65 }
66
67 static inline void _br_store2(br_word_t a, uint16_t v) {
68 memcpy((void *)a, &v, sizeof(v));
69 }
70
71 static inline void _br_store4(br_word_t a, uint32_t v) {
72 memcpy((void *)a, &v, sizeof(v));
73 }
74
75 static inline void _br_store(br_word_t a, br_word_t v) {
76 memcpy((void *)a, &v, sizeof(v));
77 }
78
79 static inline br_word_t _br_mulhuu(br_word_t a, br_word_t b) {
80 #if BR_WORD_MAX == UINT32_MAX
81 return ((uint64_t)a * b) >> 32;
82 #elif BR_WORD_MAX == UINT64_MAX && (defined(__GNUC__) || defined(__clang__))
83 return ((unsigned __int128)a * b) >> 64;
84 #elif defined(_M_X64)
85 uint64_t hi;
86 _umul128(a, b, &hi);
87 return hi;
88 #elif defined(_M_ARM64)
89 return __umulh(a, b);
90 #else
91 // See full_mul.v
92 br_word_t hh, lh, hl, low, second_halfword_w_oflow, n, ll, M;
93 n = ((((0u-(br_word_t)0x1)>>27)&0x3f)+0x1)>>1;
94 M = ((br_word_t)0x1<<n)-0x1;
95 ll = (a&M)*(b&M);
96 lh = (a&M)*(b>>n);
97 hl = (a>>n)*(b&M);
98 hh = (a>>n)*(b>>n);
99 second_halfword_w_oflow = ((ll>>n)+(lh&M))+(hl&M);
100 return ((hh+(lh>>n))+(hl>>n))+(second_halfword_w_oflow>>n);
101 #endif
102 }
103
104 static inline br_word_t _br_divu(br_word_t a, br_word_t b) {
105 if (!b) return -1;
106 return a/b;
107 }
108
109 static inline br_word_t _br_remu(br_word_t a, br_word_t b) {
110 if (!b) return a;
111 return a%b;
112 }
113
114
115 /*
116 * Input Bounds:
117 * in0: [[0x0 ~> 0xc000000], [0x0 ~> 0xc000000], [0x0 ~> 0xc000000], [0x0 ~> 0xc000000], [0x0 ~> 0xc000000]]
118 * in1: [[0x0 ~> 0xc000000], [0x0 ~> 0xc000000], [0x0 ~> 0xc000000], [0x0 ~> 0xc000000], [0x0 ~> 0xc000000]]
119 * Output Bounds:
120 * out0: [[0x0 ~> 0x4000000], [0x0 ~> 0x4000000], [0x0 ~> 0x4000000], [0x0 ~> 0x4000000], [0x0 ~> 0x4000000]]
121 */
122 static
123 void internal_fiat_poly1305_carry_mul(br_word_t out0, br_word_t in0, br_word_t in1) {
124 br_word_t x4, x3, x2, x1, x9, x8, x7, x6, x0, x5, x16, x22, x61, x23, x62, x17, x60, x26, x65, x27, x66, x63, x64, x28, x69, x29, x70, x67, x68, x58, x73, x59, x74, x71, x75, x72, x30, x32, x80, x33, x81, x31, x79, x36, x84, x37, x85, x82, x83, x42, x88, x43, x89, x86, x87, x50, x92, x51, x93, x90, x10, x34, x96, x35, x97, x11, x95, x38, x100, x39, x101, x98, x99, x44, x104, x45, x105, x102, x103, x52, x108, x53, x109, x106, x12, x18, x112, x19, x113, x13, x111, x40, x116, x41, x117, x114, x115, x46, x120, x47, x121, x118, x119, x54, x124, x55, x125, x122, x14, x20, x128, x21, x129, x15, x127, x24, x132, x25, x133, x130, x131, x48, x136, x49, x137, x134, x135, x56, x140, x57, x141, x138, x139, x76, x144, x77, x145, x142, x146, x143, x123, x147, x151, x148, x152, x126, x153, x150, x107, x154, x158, x155, x159, x110, x160, x157, x91, x161, x165, x162, x166, x94, x167, x164, x168, x170, x78, x173, x171, x174, x172, x175, x149, x177, x178, x156, x176, x179, x180, x163, x169, x181, x182, x183, x184, x185;
125 x0 = _br_load(in0+0);
126 x1 = _br_load(in0+4);
127 x2 = _br_load(in0+8);
128 x3 = _br_load(in0+12);
129 x4 = _br_load(in0+16);
130 /*skip*/
131 x5 = _br_load(in1+0);
132 x6 = _br_load(in1+4);
133 x7 = _br_load(in1+8);
134 x8 = _br_load(in1+12);
135 x9 = _br_load(in1+16);
136 /*skip*/
137 /*skip*/
138 x10 = x4*(x9*5);
139 x11 = _br_mulhuu(x4, (x9*5));
140 x12 = x4*(x8*5);
141 x13 = _br_mulhuu(x4, (x8*5));
142 x14 = x4*(x7*5);
143 x15 = _br_mulhuu(x4, (x7*5));
144 x16 = x4*(x6*5);
145 x17 = _br_mulhuu(x4, (x6*5));
146 x18 = x3*(x9*5);
147 x19 = _br_mulhuu(x3, (x9*5));
148 x20 = x3*(x8*5);
149 x21 = _br_mulhuu(x3, (x8*5));
150 x22 = x3*(x7*5);
151 x23 = _br_mulhuu(x3, (x7*5));
152 x24 = x2*(x9*5);
153 x25 = _br_mulhuu(x2, (x9*5));
154 x26 = x2*(x8*5);
155 x27 = _br_mulhuu(x2, (x8*5));
156 x28 = x1*(x9*5);
157 x29 = _br_mulhuu(x1, (x9*5));
158 x30 = x4*x5;
159 x31 = _br_mulhuu(x4, x5);
160 x32 = x3*x6;
161 x33 = _br_mulhuu(x3, x6);
162 x34 = x3*x5;
163 x35 = _br_mulhuu(x3, x5);
164 x36 = x2*x7;
165 x37 = _br_mulhuu(x2, x7);
166 x38 = x2*x6;
167 x39 = _br_mulhuu(x2, x6);
168 x40 = x2*x5;
169 x41 = _br_mulhuu(x2, x5);
170 x42 = x1*x8;
171 x43 = _br_mulhuu(x1, x8);
172 x44 = x1*x7;
173 x45 = _br_mulhuu(x1, x7);
174 x46 = x1*x6;
175 x47 = _br_mulhuu(x1, x6);
176 x48 = x1*x5;
177 x49 = _br_mulhuu(x1, x5);
178 x50 = x0*x9;
179 x51 = _br_mulhuu(x0, x9);
180 x52 = x0*x8;
181 x53 = _br_mulhuu(x0, x8);
182 x54 = x0*x7;
183 x55 = _br_mulhuu(x0, x7);
184 x56 = x0*x6;
185 x57 = _br_mulhuu(x0, x6);
186 x58 = x0*x5;
187 x59 = _br_mulhuu(x0, x5);
188 x60 = x22+x16;
189 x61 = (br_word_t)(x60<x22);
190 x62 = x61+x23;
191 x63 = x62+x17;
192 x64 = x26+x60;
193 x65 = (br_word_t)(x64<x26);
194 x66 = x65+x27;
195 x67 = x66+x63;
196 x68 = x28+x64;
197 x69 = (br_word_t)(x68<x28);
198 x70 = x69+x29;
199 x71 = x70+x67;
200 x72 = x58+x68;
201 x73 = (br_word_t)(x72<x58);
202 x74 = x73+x59;
203 x75 = x74+x71;
204 x76 = (x72>>26)|(x75<<6);
205 x77 = x75>>26;
206 x78 = x72&0x3ffffff;
207 x79 = x32+x30;
208 x80 = (br_word_t)(x79<x32);
209 x81 = x80+x33;
210 x82 = x81+x31;
211 x83 = x36+x79;
212 x84 = (br_word_t)(x83<x36);
213 x85 = x84+x37;
214 x86 = x85+x82;
215 x87 = x42+x83;
216 x88 = (br_word_t)(x87<x42);
217 x89 = x88+x43;
218 x90 = x89+x86;
219 x91 = x50+x87;
220 x92 = (br_word_t)(x91<x50);
221 x93 = x92+x51;
222 x94 = x93+x90;
223 x95 = x34+x10;
224 x96 = (br_word_t)(x95<x34);
225 x97 = x96+x35;
226 x98 = x97+x11;
227 x99 = x38+x95;
228 x100 = (br_word_t)(x99<x38);
229 x101 = x100+x39;
230 x102 = x101+x98;
231 x103 = x44+x99;
232 x104 = (br_word_t)(x103<x44);
233 x105 = x104+x45;
234 x106 = x105+x102;
235 x107 = x52+x103;
236 x108 = (br_word_t)(x107<x52);
237 x109 = x108+x53;
238 x110 = x109+x106;
239 x111 = x18+x12;
240 x112 = (br_word_t)(x111<x18);
241 x113 = x112+x19;
242 x114 = x113+x13;
243 x115 = x40+x111;
244 x116 = (br_word_t)(x115<x40);
245 x117 = x116+x41;
246 x118 = x117+x114;
247 x119 = x46+x115;
248 x120 = (br_word_t)(x119<x46);
249 x121 = x120+x47;
250 x122 = x121+x118;
251 x123 = x54+x119;
252 x124 = (br_word_t)(x123<x54);
253 x125 = x124+x55;
254 x126 = x125+x122;
255 x127 = x20+x14;
256 x128 = (br_word_t)(x127<x20);
257 x129 = x128+x21;
258 x130 = x129+x15;
259 x131 = x24+x127;
260 x132 = (br_word_t)(x131<x24);
261 x133 = x132+x25;
262 x134 = x133+x130;
263 x135 = x48+x131;
264 x136 = (br_word_t)(x135<x48);
265 x137 = x136+x49;
266 x138 = x137+x134;
267 x139 = x56+x135;
268 x140 = (br_word_t)(x139<x56);
269 x141 = x140+x57;
270 x142 = x141+x138;
271 x143 = x76+x139;
272 x144 = (br_word_t)(x143<x76);
273 x145 = x144+x77;
274 x146 = x145+x142;
275 x147 = (x143>>26)|(x146<<6);
276 x148 = x146>>26;
277 x149 = x143&0x3ffffff;
278 x150 = x147+x123;
279 x151 = (br_word_t)(x150<x147);
280 x152 = x151+x148;
281 x153 = x152+x126;
282 x154 = (x150>>26)|(x153<<6);
283 x155 = x153>>26;
284 x156 = x150&0x3ffffff;
285 x157 = x154+x107;
286 x158 = (br_word_t)(x157<x154);
287 x159 = x158+x155;
288 x160 = x159+x110;
289 x161 = (x157>>26)|(x160<<6);
290 x162 = x160>>26;
291 x163 = x157&0x3ffffff;
292 x164 = x161+x91;
293 x165 = (br_word_t)(x164<x161);
294 x166 = x165+x162;
295 x167 = x166+x94;
296 x168 = (x164>>26)|(x167<<6);
297 x169 = x164&0x3ffffff;
298 x170 = x168*5;
299 x171 = _br_mulhuu(x168, (br_word_t)5);
300 x172 = x78+x170;
301 x173 = (br_word_t)(x172<x78);
302 x174 = x173+x171;
303 x175 = (x172>>26)|(x174<<6);
304 x176 = x172&0x3ffffff;
305 x177 = x175+x149;
306 x178 = x177>>26;
307 x179 = x177&0x3ffffff;
308 x180 = x178+x156;
309 x181 = x176;
310 x182 = x179;
311 x183 = x180;
312 x184 = x163;
313 x185 = x169;
314 /*skip*/
315 _br_store(out0+0, x181);
316 _br_store(out0+4, x182);
317 _br_store(out0+8, x183);
318 _br_store(out0+12, x184);
319 _br_store(out0+16, x185);
320 /*skip*/
321 }
322
323 /* NOTE: The following wrapper function is not covered by Coq proofs */
324 static void fiat_poly1305_carry_mul(uint32_t out1[5], const uint32_t arg1[5], const uint32_t arg2[5]) {
325 internal_fiat_poly1305_carry_mul((uintptr_t)out1, (uintptr_t)arg1, (uintptr_t)arg2);
326 }
327
328
329 /*
330 * Input Bounds:
331 * in0: [[0x0 ~> 0xc000000], [0x0 ~> 0xc000000], [0x0 ~> 0xc000000], [0x0 ~> 0xc000000], [0x0 ~> 0xc000000]]
332 * Output Bounds:
333 * out0: [[0x0 ~> 0x4000000], [0x0 ~> 0x4000000], [0x0 ~> 0x4000000], [0x0 ~> 0x4000000], [0x0 ~> 0x4000000]]
334 */
335 static
336 void internal_fiat_poly1305_carry_square(br_word_t out0, br_word_t in0) {
337 br_word_t x4, x5, x3, x8, x9, x2, x6, x1, x7, x10, x11, x12, x0, x21, x25, x44, x26, x45, x22, x43, x41, x48, x42, x49, x46, x50, x47, x23, x27, x55, x28, x56, x24, x54, x33, x59, x34, x60, x57, x13, x29, x63, x30, x64, x14, x62, x35, x67, x36, x68, x65, x15, x31, x71, x32, x72, x16, x70, x37, x75, x38, x76, x73, x17, x19, x79, x20, x80, x18, x78, x39, x83, x40, x84, x81, x82, x51, x87, x52, x88, x85, x89, x86, x74, x90, x94, x91, x95, x77, x96, x93, x66, x97, x101, x98, x102, x69, x103, x100, x58, x104, x108, x105, x109, x61, x110, x107, x111, x113, x53, x116, x114, x117, x115, x118, x92, x120, x121, x99, x119, x122, x123, x106, x112, x124, x125, x126, x127, x128;
338 x0 = _br_load(in0+0);
339 x1 = _br_load(in0+4);
340 x2 = _br_load(in0+8);
341 x3 = _br_load(in0+12);
342 x4 = _br_load(in0+16);
343 /*skip*/
344 /*skip*/
345 x5 = x4*5;
346 x6 = x5*2;
347 x7 = x4*2;
348 x8 = x3*5;
349 x9 = x8*2;
350 x10 = x3*2;
351 x11 = x2*2;
352 x12 = x1*2;
353 x13 = x4*x5;
354 x14 = _br_mulhuu(x4, x5);
355 x15 = x3*x6;
356 x16 = _br_mulhuu(x3, x6);
357 x17 = x3*x8;
358 x18 = _br_mulhuu(x3, x8);
359 x19 = x2*x6;
360 x20 = _br_mulhuu(x2, x6);
361 x21 = x2*x9;
362 x22 = _br_mulhuu(x2, x9);
363 x23 = x2*x2;
364 x24 = _br_mulhuu(x2, x2);
365 x25 = x1*x6;
366 x26 = _br_mulhuu(x1, x6);
367 x27 = x1*x10;
368 x28 = _br_mulhuu(x1, x10);
369 x29 = x1*x11;
370 x30 = _br_mulhuu(x1, x11);
371 x31 = x1*x1;
372 x32 = _br_mulhuu(x1, x1);
373 x33 = x0*x7;
374 x34 = _br_mulhuu(x0, x7);
375 x35 = x0*x10;
376 x36 = _br_mulhuu(x0, x10);
377 x37 = x0*x11;
378 x38 = _br_mulhuu(x0, x11);
379 x39 = x0*x12;
380 x40 = _br_mulhuu(x0, x12);
381 x41 = x0*x0;
382 x42 = _br_mulhuu(x0, x0);
383 x43 = x25+x21;
384 x44 = (br_word_t)(x43<x25);
385 x45 = x44+x26;
386 x46 = x45+x22;
387 x47 = x41+x43;
388 x48 = (br_word_t)(x47<x41);
389 x49 = x48+x42;
390 x50 = x49+x46;
391 x51 = (x47>>26)|(x50<<6);
392 x52 = x50>>26;
393 x53 = x47&0x3ffffff;
394 x54 = x27+x23;
395 x55 = (br_word_t)(x54<x27);
396 x56 = x55+x28;
397 x57 = x56+x24;
398 x58 = x33+x54;
399 x59 = (br_word_t)(x58<x33);
400 x60 = x59+x34;
401 x61 = x60+x57;
402 x62 = x29+x13;
403 x63 = (br_word_t)(x62<x29);
404 x64 = x63+x30;
405 x65 = x64+x14;
406 x66 = x35+x62;
407 x67 = (br_word_t)(x66<x35);
408 x68 = x67+x36;
409 x69 = x68+x65;
410 x70 = x31+x15;
411 x71 = (br_word_t)(x70<x31);
412 x72 = x71+x32;
413 x73 = x72+x16;
414 x74 = x37+x70;
415 x75 = (br_word_t)(x74<x37);
416 x76 = x75+x38;
417 x77 = x76+x73;
418 x78 = x19+x17;
419 x79 = (br_word_t)(x78<x19);
420 x80 = x79+x20;
421 x81 = x80+x18;
422 x82 = x39+x78;
423 x83 = (br_word_t)(x82<x39);
424 x84 = x83+x40;
425 x85 = x84+x81;
426 x86 = x51+x82;
427 x87 = (br_word_t)(x86<x51);
428 x88 = x87+x52;
429 x89 = x88+x85;
430 x90 = (x86>>26)|(x89<<6);
431 x91 = x89>>26;
432 x92 = x86&0x3ffffff;
433 x93 = x90+x74;
434 x94 = (br_word_t)(x93<x90);
435 x95 = x94+x91;
436 x96 = x95+x77;
437 x97 = (x93>>26)|(x96<<6);
438 x98 = x96>>26;
439 x99 = x93&0x3ffffff;
440 x100 = x97+x66;
441 x101 = (br_word_t)(x100<x97);
442 x102 = x101+x98;
443 x103 = x102+x69;
444 x104 = (x100>>26)|(x103<<6);
445 x105 = x103>>26;
446 x106 = x100&0x3ffffff;
447 x107 = x104+x58;
448 x108 = (br_word_t)(x107<x104);
449 x109 = x108+x105;
450 x110 = x109+x61;
451 x111 = (x107>>26)|(x110<<6);
452 x112 = x107&0x3ffffff;
453 x113 = x111*5;
454 x114 = _br_mulhuu(x111, (br_word_t)5);
455 x115 = x53+x113;
456 x116 = (br_word_t)(x115<x53);
457 x117 = x116+x114;
458 x118 = (x115>>26)|(x117<<6);
459 x119 = x115&0x3ffffff;
460 x120 = x118+x92;
461 x121 = x120>>26;
462 x122 = x120&0x3ffffff;
463 x123 = x121+x99;
464 x124 = x119;
465 x125 = x122;
466 x126 = x123;
467 x127 = x106;
468 x128 = x112;
469 /*skip*/
470 _br_store(out0+0, x124);
471 _br_store(out0+4, x125);
472 _br_store(out0+8, x126);
473 _br_store(out0+12, x127);
474 _br_store(out0+16, x128);
475 /*skip*/
476 }
477
478 /* NOTE: The following wrapper function is not covered by Coq proofs */
479 static void fiat_poly1305_carry_square(uint32_t out1[5], const uint32_t arg1[5]) {
480 internal_fiat_poly1305_carry_square((uintptr_t)out1, (uintptr_t)arg1);
481 }
482
483
484 /*
485 * Input Bounds:
486 * in0: [[0x0 ~> 0xc000000], [0x0 ~> 0xc000000], [0x0 ~> 0xc000000], [0x0 ~> 0xc000000], [0x0 ~> 0xc000000]]
487 * Output Bounds:
488 * out0: [[0x0 ~> 0x4000000], [0x0 ~> 0x4000000], [0x0 ~> 0x4000000], [0x0 ~> 0x4000000], [0x0 ~> 0x4000000]]
489 */
490 static
491 void internal_fiat_poly1305_carry(br_word_t out0, br_word_t in0) {
492 br_word_t x0, x1, x2, x3, x4, x5, x6, x10, x11, x7, x8, x9, x12, x13, x14, x15, x16, x17, x18, x19, x20, x21;
493 x0 = _br_load(in0+0);
494 x1 = _br_load(in0+4);
495 x2 = _br_load(in0+8);
496 x3 = _br_load(in0+12);
497 x4 = _br_load(in0+16);
498 /*skip*/
499 /*skip*/
500 x5 = x0;
501 x6 = (x5>>26)+x1;
502 x7 = (x6>>26)+x2;
503 x8 = (x7>>26)+x3;
504 x9 = (x8>>26)+x4;
505 x10 = (x5&0x3ffffff)+((x9>>26)*5);
506 x11 = (x10>>26)+(x6&0x3ffffff);
507 x12 = x10&0x3ffffff;
508 x13 = x11&0x3ffffff;
509 x14 = (x11>>26)+(x7&0x3ffffff);
510 x15 = x8&0x3ffffff;
511 x16 = x9&0x3ffffff;
512 x17 = x12;
513 x18 = x13;
514 x19 = x14;
515 x20 = x15;
516 x21 = x16;
517 /*skip*/
518 _br_store(out0+0, x17);
519 _br_store(out0+4, x18);
520 _br_store(out0+8, x19);
521 _br_store(out0+12, x20);
522 _br_store(out0+16, x21);
523 /*skip*/
524 }
525
526 /* NOTE: The following wrapper function is not covered by Coq proofs */
527 static void fiat_poly1305_carry(uint32_t out1[5], const uint32_t arg1[5]) {
528 internal_fiat_poly1305_carry((uintptr_t)out1, (uintptr_t)arg1);
529 }
530
531
532 /*
533 * Input Bounds:
534 * in0: [[0x0 ~> 0x4000000], [0x0 ~> 0x4000000], [0x0 ~> 0x4000000], [0x0 ~> 0x4000000], [0x0 ~> 0x4000000]]
535 * in1: [[0x0 ~> 0x4000000], [0x0 ~> 0x4000000], [0x0 ~> 0x4000000], [0x0 ~> 0x4000000], [0x0 ~> 0x4000000]]
536 * Output Bounds:
537 * out0: [[0x0 ~> 0xc000000], [0x0 ~> 0xc000000], [0x0 ~> 0xc000000], [0x0 ~> 0xc000000], [0x0 ~> 0xc000000]]
538 */
539 static
540 void internal_fiat_poly1305_add(br_word_t out0, br_word_t in0, br_word_t in1) {
541 br_word_t x0, x5, x1, x6, x2, x7, x3, x8, x4, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18, x19;
542 x0 = _br_load(in0+0);
543 x1 = _br_load(in0+4);
544 x2 = _br_load(in0+8);
545 x3 = _br_load(in0+12);
546 x4 = _br_load(in0+16);
547 /*skip*/
548 x5 = _br_load(in1+0);
549 x6 = _br_load(in1+4);
550 x7 = _br_load(in1+8);
551 x8 = _br_load(in1+12);
552 x9 = _br_load(in1+16);
553 /*skip*/
554 /*skip*/
555 x10 = x0+x5;
556 x11 = x1+x6;
557 x12 = x2+x7;
558 x13 = x3+x8;
559 x14 = x4+x9;
560 x15 = x10;
561 x16 = x11;
562 x17 = x12;
563 x18 = x13;
564 x19 = x14;
565 /*skip*/
566 _br_store(out0+0, x15);
567 _br_store(out0+4, x16);
568 _br_store(out0+8, x17);
569 _br_store(out0+12, x18);
570 _br_store(out0+16, x19);
571 /*skip*/
572 }
573
574 /* NOTE: The following wrapper function is not covered by Coq proofs */
575 static void fiat_poly1305_add(uint32_t out1[5], const uint32_t arg1[5], const uint32_t arg2[5]) {
576 internal_fiat_poly1305_add((uintptr_t)out1, (uintptr_t)arg1, (uintptr_t)arg2);
577 }
578
579
580 /*
581 * Input Bounds:
582 * in0: [[0x0 ~> 0x4000000], [0x0 ~> 0x4000000], [0x0 ~> 0x4000000], [0x0 ~> 0x4000000], [0x0 ~> 0x4000000]]
583 * in1: [[0x0 ~> 0x4000000], [0x0 ~> 0x4000000], [0x0 ~> 0x4000000], [0x0 ~> 0x4000000], [0x0 ~> 0x4000000]]
584 * Output Bounds:
585 * out0: [[0x0 ~> 0xc000000], [0x0 ~> 0xc000000], [0x0 ~> 0xc000000], [0x0 ~> 0xc000000], [0x0 ~> 0xc000000]]
586 */
587 static
588 void internal_fiat_poly1305_sub(br_word_t out0, br_word_t in0, br_word_t in1) {
589 br_word_t x0, x5, x1, x6, x2, x7, x3, x8, x4, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18, x19;
590 x0 = _br_load(in0+0);
591 x1 = _br_load(in0+4);
592 x2 = _br_load(in0+8);
593 x3 = _br_load(in0+12);
594 x4 = _br_load(in0+16);
595 /*skip*/
596 x5 = _br_load(in1+0);
597 x6 = _br_load(in1+4);
598 x7 = _br_load(in1+8);
599 x8 = _br_load(in1+12);
600 x9 = _br_load(in1+16);
601 /*skip*/
602 /*skip*/
603 x10 = ((br_word_t)0x7fffff6+x0)-x5;
604 x11 = ((br_word_t)0x7fffffe +x1)-x6;
605 x12 = ((br_word_t)0x7fffffe +x2)-x7;
606 x13 = ((br_word_t)0x7fffffe +x3)-x8;
607 x14 = ((br_word_t)0x7fffffe +x4)-x9;
608 x15 = x10;
609 x16 = x11;
610 x17 = x12;
611 x18 = x13;
612 x19 = x14;
613 /*skip*/
614 _br_store(out0+0, x15);
615 _br_store(out0+4, x16);
616 _br_store(out0+8, x17);
617 _br_store(out0+12, x18);
618 _br_store(out0+16, x19);
619 /*skip*/
620 }
621
622 /* NOTE: The following wrapper function is not covered by Coq proofs */
623 static void fiat_poly1305_sub(uint32_t out1[5], const uint32_t arg1[5], const uint32_t arg2[5]) {
624 internal_fiat_poly1305_sub((uintptr_t)out1, (uintptr_t)arg1, (uintptr_t)arg2);
625 }
626
627
628 /*
629 * Input Bounds:
630 * in0: [[0x0 ~> 0x4000000], [0x0 ~> 0x4000000], [0x0 ~> 0x4000000], [0x0 ~> 0x4000000], [0x0 ~> 0x4000000]]
631 * Output Bounds:
632 * out0: [[0x0 ~> 0xc000000], [0x0 ~> 0xc000000], [0x0 ~> 0xc000000], [0x0 ~> 0xc000000], [0x0 ~> 0xc000000]]
633 */
634 static
635 void internal_fiat_poly1305_opp(br_word_t out0, br_word_t in0) {
636 br_word_t x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14;
637 x0 = _br_load(in0+0);
638 x1 = _br_load(in0+4);
639 x2 = _br_load(in0+8);
640 x3 = _br_load(in0+12);
641 x4 = _br_load(in0+16);
642 /*skip*/
643 /*skip*/
644 x5 = (br_word_t)0x7fffff6-x0;
645 x6 = (br_word_t)0x7fffffe -x1;
646 x7 = (br_word_t)0x7fffffe -x2;
647 x8 = (br_word_t)0x7fffffe -x3;
648 x9 = (br_word_t)0x7fffffe -x4;
649 x10 = x5;
650 x11 = x6;
651 x12 = x7;
652 x13 = x8;
653 x14 = x9;
654 /*skip*/
655 _br_store(out0+0, x10);
656 _br_store(out0+4, x11);
657 _br_store(out0+8, x12);
658 _br_store(out0+12, x13);
659 _br_store(out0+16, x14);
660 /*skip*/
661 }
662
663 /* NOTE: The following wrapper function is not covered by Coq proofs */
664 static void fiat_poly1305_opp(uint32_t out1[5], const uint32_t arg1[5]) {
665 internal_fiat_poly1305_opp((uintptr_t)out1, (uintptr_t)arg1);
666 }
667
668
669 /*
670 * Input Bounds:
671 * in0: [0x0 ~> 0x1]
672 * in1: [[0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff]]
673 * in2: [[0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff]]
674 * Output Bounds:
675 * out0: [[0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff]]
676 */
677 static
678 void internal_fiat_poly1305_selectznz(br_word_t out0, br_word_t in0, br_word_t in1, br_word_t in2) {
679 br_word_t x5, x10, x0, x11, x6, x13, x1, x14, x7, x16, x2, x17, x8, x19, x3, x20, x9, x22, x4, x23, x12, x15, x18, x21, x24, x25, x26, x27, x28, x29;
680 /*skip*/
681 x0 = _br_load(in1+0);
682 x1 = _br_load(in1+4);
683 x2 = _br_load(in1+8);
684 x3 = _br_load(in1+12);
685 x4 = _br_load(in1+16);
686 /*skip*/
687 x5 = _br_load(in2+0);
688 x6 = _br_load(in2+4);
689 x7 = _br_load(in2+8);
690 x8 = _br_load(in2+12);
691 x9 = _br_load(in2+16);
692 /*skip*/
693 /*skip*/
694 x10 = (0u-(br_word_t)1)+((br_word_t)(in0==(br_word_t)0));
695 x11 = x10^0xffffffff;
696 x12 = (x5&x10)|(x0&x11);
697 x13 = (0u-(br_word_t)1)+((br_word_t)(in0==(br_word_t)0));
698 x14 = x13^0xffffffff;
699 x15 = (x6&x13)|(x1&x14);
700 x16 = (0u-(br_word_t)1)+((br_word_t)(in0==(br_word_t)0));
701 x17 = x16^0xffffffff;
702 x18 = (x7&x16)|(x2&x17);
703 x19 = (0u-(br_word_t)1)+((br_word_t)(in0==(br_word_t)0));
704 x20 = x19^0xffffffff;
705 x21 = (x8&x19)|(x3&x20);
706 x22 = (0u-(br_word_t)1)+((br_word_t)(in0==(br_word_t)0));
707 x23 = x22^0xffffffff;
708 x24 = (x9&x22)|(x4&x23);
709 x25 = x12;
710 x26 = x15;
711 x27 = x18;
712 x28 = x21;
713 x29 = x24;
714 /*skip*/
715 _br_store(out0+0, x25);
716 _br_store(out0+4, x26);
717 _br_store(out0+8, x27);
718 _br_store(out0+12, x28);
719 _br_store(out0+16, x29);
720 /*skip*/
721 }
722
723 /* NOTE: The following wrapper function is not covered by Coq proofs */
724 static void fiat_poly1305_selectznz(uint32_t out1[5], uint8_t arg1, const uint32_t arg2[5], const uint32_t arg3[5]) {
725 internal_fiat_poly1305_selectznz((uintptr_t)out1, (uintptr_t)arg1, (uintptr_t)arg2, (uintptr_t)arg3);
726 }
727
728
729 /*
730 * Input Bounds:
731 * in0: [[0x0 ~> 0x4000000], [0x0 ~> 0x4000000], [0x0 ~> 0x4000000], [0x0 ~> 0x4000000], [0x0 ~> 0x4000000]]
732 * Output Bounds:
733 * out0: [[0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0x3]]
734 */
735 static
736 void internal_fiat_poly1305_to_bytes(br_word_t out0, br_word_t in0) {
737 br_word_t x0, x6, x5, x1, x8, x9, x10, x12, x13, x11, x2, x15, x16, x17, x19, x20, x18, x3, x22, x23, x24, x26, x27, x25, x4, x29, x30, x31, x33, x34, x32, x36, x7, x38, x39, x41, x14, x42, x43, x45, x44, x46, x48, x21, x49, x50, x52, x51, x53, x55, x28, x56, x57, x59, x58, x60, x62, x35, x63, x37, x64, x61, x54, x47, x40, x70, x72, x68, x74, x75, x77, x79, x67, x81, x82, x84, x86, x66, x88, x89, x91, x93, x65, x97, x99, x69, x71, x73, x76, x78, x80, x83, x85, x87, x90, x92, x94, x95, x96, x98, x100, x101, x102, x103, x104, x105, x106, x107, x108, x109, x110, x111, x112, x113, x114, x115, x116, x117, x118;
738 x0 = _br_load(in0+0);
739 x1 = _br_load(in0+4);
740 x2 = _br_load(in0+8);
741 x3 = _br_load(in0+12);
742 x4 = _br_load(in0+16);
743 /*skip*/
744 /*skip*/
745 x5 = x0-0x3fffffb;
746 x6 = (br_word_t)(x0<x5);
747 x7 = x5&0x3ffffff;
748 x8 = (x6<<6)-(x5>>26);
749 x9 = x1-0x3ffffff;
750 x10 = (br_word_t)(x1<x9);
751 x11 = x9-x8;
752 x12 = (br_word_t)(x9<x11);
753 x13 = x10+x12;
754 x14 = x11&0x3ffffff;
755 x15 = (x13<<6)-(x11>>26);
756 x16 = x2-0x3ffffff;
757 x17 = (br_word_t)(x2<x16);
758 x18 = x16-x15;
759 x19 = (br_word_t)(x16<x18);
760 x20 = x17+x19;
761 x21 = x18&0x3ffffff;
762 x22 = (x20<<6)-(x18>>26);
763 x23 = x3-0x3ffffff;
764 x24 = (br_word_t)(x3<x23);
765 x25 = x23-x22;
766 x26 = (br_word_t)(x23<x25);
767 x27 = x24+x26;
768 x28 = x25&0x3ffffff;
769 x29 = (x27<<6)-(x25>>26);
770 x30 = x4-0x3ffffff;
771 x31 = (br_word_t)(x4<x30);
772 x32 = x30-x29;
773 x33 = (br_word_t)(x30<x32);
774 x34 = x31+x33;
775 x35 = x32&0x3ffffff;
776 x36 = (x34<<6)-(x32>>26);
777 x37 = (0u-(br_word_t)1)+((br_word_t)(x36==(br_word_t)0));
778 x38 = x7+(x37&0x3fffffb);
779 x39 = (br_word_t)(x38<x7);
780 x40 = x38&0x3ffffff;
781 x41 = (x38>>26)+(x39<<6);
782 x42 = x41+x14;
783 x43 = (br_word_t)(x42<x14);
784 x44 = x42+(x37&0x3ffffff);
785 x45 = (br_word_t)(x44<(x37&0x3ffffff));
786 x46 = x43+x45;
787 x47 = x44&0x3ffffff;
788 x48 = (x44>>26)+(x46<<6);
789 x49 = x48+x21;
790 x50 = (br_word_t)(x49<x21);
791 x51 = x49+(x37&0x3ffffff);
792 x52 = (br_word_t)(x51<(x37&0x3ffffff));
793 x53 = x50+x52;
794 x54 = x51&0x3ffffff;
795 x55 = (x51>>26)+(x53<<6);
796 x56 = x55+x28;
797 x57 = (br_word_t)(x56<x28);
798 x58 = x56+(x37&0x3ffffff);
799 x59 = (br_word_t)(x58<(x37&0x3ffffff));
800 x60 = x57+x59;
801 x61 = x58&0x3ffffff;
802 x62 = (x58>>26)+(x60<<6);
803 x63 = x62+x35;
804 x64 = x63+(x37&0x3ffffff);
805 x65 = x64&0x3ffffff;
806 x66 = x61<<6;
807 x67 = x54<<4;
808 x68 = x47<<2;
809 x69 = x40&0xff;
810 x70 = x40>>8;
811 x71 = x70&0xff;
812 x72 = x70>>8;
813 x73 = x72&0xff;
814 x74 = x72>>8;
815 x75 = x68+x74;
816 x76 = x75&0xff;
817 x77 = x75>>8;
818 x78 = x77&0xff;
819 x79 = x77>>8;
820 x80 = x79&0xff;
821 x81 = x79>>8;
822 x82 = x67+x81;
823 x83 = x82&0xff;
824 x84 = x82>>8;
825 x85 = x84&0xff;
826 x86 = x84>>8;
827 x87 = x86&0xff;
828 x88 = x86>>8;
829 x89 = x66+x88;
830 x90 = x89&0xff;
831 x91 = x89>>8;
832 x92 = x91&0xff;
833 x93 = x91>>8;
834 x94 = x93&0xff;
835 x95 = x93>>8;
836 x96 = x65&0xff;
837 x97 = x65>>8;
838 x98 = x97&0xff;
839 x99 = x97>>8;
840 x100 = x99&0xff;
841 x101 = x99>>8;
842 x102 = x69;
843 x103 = x71;
844 x104 = x73;
845 x105 = x76;
846 x106 = x78;
847 x107 = x80;
848 x108 = x83;
849 x109 = x85;
850 x110 = x87;
851 x111 = x90;
852 x112 = x92;
853 x113 = x94;
854 x114 = x95;
855 x115 = x96;
856 x116 = x98;
857 x117 = x100;
858 x118 = x101;
859 /*skip*/
860 _br_store1(out0+0, x102);
861 _br_store1(out0+1, x103);
862 _br_store1(out0+2, x104);
863 _br_store1(out0+3, x105);
864 _br_store1(out0+4, x106);
865 _br_store1(out0+5, x107);
866 _br_store1(out0+6, x108);
867 _br_store1(out0+7, x109);
868 _br_store1(out0+8, x110);
869 _br_store1(out0+9, x111);
870 _br_store1(out0+10, x112);
871 _br_store1(out0+11, x113);
872 _br_store1(out0+12, x114);
873 _br_store1(out0+13, x115);
874 _br_store1(out0+14, x116);
875 _br_store1(out0+15, x117);
876 _br_store1(out0+16, x118);
877 /*skip*/
878 }
879
880 /* NOTE: The following wrapper function is not covered by Coq proofs */
881 static void fiat_poly1305_to_bytes(uint8_t out1[17], const uint32_t arg1[5]) {
882 internal_fiat_poly1305_to_bytes((uintptr_t)out1, (uintptr_t)arg1);
883 }
884
885
886 /*
887 * Input Bounds:
888 * in0: [[0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0x3]]
889 * Output Bounds:
890 * out0: [[0x0 ~> 0x4000000], [0x0 ~> 0x4000000], [0x0 ~> 0x4000000], [0x0 ~> 0x4000000], [0x0 ~> 0x4000000]]
891 */
892 static
893 void internal_fiat_poly1305_from_bytes(br_word_t out0, br_word_t in0) {
894 br_word_t x16, x15, x14, x13, x12, x11, x10, x9, x8, x7, x6, x5, x4, x3, x2, x1, x0, x32, x33, x31, x34, x30, x35, x36, x29, x38, x28, x39, x27, x40, x41, x26, x43, x25, x44, x24, x45, x46, x23, x48, x22, x49, x21, x50, x19, x20, x18, x52, x17, x53, x37, x42, x47, x51, x54, x55, x56, x57, x58, x59;
895 x0 = _br_load1(in0+0);
896 x1 = _br_load1(in0+1);
897 x2 = _br_load1(in0+2);
898 x3 = _br_load1(in0+3);
899 x4 = _br_load1(in0+4);
900 x5 = _br_load1(in0+5);
901 x6 = _br_load1(in0+6);
902 x7 = _br_load1(in0+7);
903 x8 = _br_load1(in0+8);
904 x9 = _br_load1(in0+9);
905 x10 = _br_load1(in0+10);
906 x11 = _br_load1(in0+11);
907 x12 = _br_load1(in0+12);
908 x13 = _br_load1(in0+13);
909 x14 = _br_load1(in0+14);
910 x15 = _br_load1(in0+15);
911 x16 = _br_load1(in0+16);
912 /*skip*/
913 /*skip*/
914 x17 = x16<<24;
915 x18 = x15<<16;
916 x19 = x14<<8;
917 x20 = x13;
918 x21 = x12<<18;
919 x22 = x11<<10;
920 x23 = x10<<2;
921 x24 = x9<<20;
922 x25 = x8<<12;
923 x26 = x7<<4;
924 x27 = x6<<22;
925 x28 = x5<<14;
926 x29 = x4<<6;
927 x30 = x3<<24;
928 x31 = x2<<16;
929 x32 = x1<<8;
930 x33 = x0;
931 x34 = x32+x33;
932 x35 = x31+x34;
933 x36 = x30+x35;
934 x37 = x36&0x3ffffff;
935 x38 = x36>>26;
936 x39 = x29+x38;
937 x40 = x28+x39;
938 x41 = x27+x40;
939 x42 = x41&0x3ffffff;
940 x43 = x41>>26;
941 x44 = x26+x43;
942 x45 = x25+x44;
943 x46 = x24+x45;
944 x47 = x46&0x3ffffff;
945 x48 = x46>>26;
946 x49 = x23+x48;
947 x50 = x22+x49;
948 x51 = x21+x50;
949 x52 = x19+x20;
950 x53 = x18+x52;
951 x54 = x17+x53;
952 x55 = x37;
953 x56 = x42;
954 x57 = x47;
955 x58 = x51;
956 x59 = x54;
957 /*skip*/
958 _br_store(out0+0, x55);
959 _br_store(out0+4, x56);
960 _br_store(out0+8, x57);
961 _br_store(out0+12, x58);
962 _br_store(out0+16, x59);
963 /*skip*/
964 }
965
966 /* NOTE: The following wrapper function is not covered by Coq proofs */
967 static void fiat_poly1305_from_bytes(uint32_t out1[5], const uint8_t arg1[17]) {
968 internal_fiat_poly1305_from_bytes((uintptr_t)out1, (uintptr_t)arg1);
969 }
970
971
972 /*
973 * Input Bounds:
974 * in0: [[0x0 ~> 0x4000000], [0x0 ~> 0x4000000], [0x0 ~> 0x4000000], [0x0 ~> 0x4000000], [0x0 ~> 0x4000000]]
975 * Output Bounds:
976 * out0: [[0x0 ~> 0xc000000], [0x0 ~> 0xc000000], [0x0 ~> 0xc000000], [0x0 ~> 0xc000000], [0x0 ~> 0xc000000]]
977 */
978 static
979 void internal_fiat_poly1305_relax(br_word_t out0, br_word_t in0) {
980 br_word_t x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14;
981 x0 = _br_load(in0+0);
982 x1 = _br_load(in0+4);
983 x2 = _br_load(in0+8);
984 x3 = _br_load(in0+12);
985 x4 = _br_load(in0+16);
986 /*skip*/
987 /*skip*/
988 x5 = x0;
989 x6 = x1;
990 x7 = x2;
991 x8 = x3;
992 x9 = x4;
993 x10 = x5;
994 x11 = x6;
995 x12 = x7;
996 x13 = x8;
997 x14 = x9;
998 /*skip*/
999 _br_store(out0+0, x10);
1000 _br_store(out0+4, x11);
1001 _br_store(out0+8, x12);
1002 _br_store(out0+12, x13);
1003 _br_store(out0+16, x14);
1004 /*skip*/
1005 }
1006
1007 /* NOTE: The following wrapper function is not covered by Coq proofs */
1008 static void fiat_poly1305_relax(uint32_t out1[5], const uint32_t arg1[5]) {
1009 internal_fiat_poly1305_relax((uintptr_t)out1, (uintptr_t)arg1);
1010 }