fiat_crypto/
poly1305_64.rs1#![allow(unused_parens)]
16#![allow(non_camel_case_types)]
17
18pub type fiat_poly1305_u1 = u8;
20pub type fiat_poly1305_i1 = i8;
22pub type fiat_poly1305_u2 = u8;
24pub type fiat_poly1305_i2 = i8;
26
27#[derive(Clone, Copy)]
30pub struct fiat_poly1305_loose_field_element(pub [u64; 3]);
31
32impl core::ops::Index<usize> for fiat_poly1305_loose_field_element {
33 type Output = u64;
34 #[inline]
35 fn index(&self, index: usize) -> &Self::Output {
36 &self.0[index]
37 }
38}
39
40impl core::ops::IndexMut<usize> for fiat_poly1305_loose_field_element {
41 #[inline]
42 fn index_mut(&mut self, index: usize) -> &mut Self::Output {
43 &mut self.0[index]
44 }
45}
46
47#[derive(Clone, Copy)]
50pub struct fiat_poly1305_tight_field_element(pub [u64; 3]);
51
52impl core::ops::Index<usize> for fiat_poly1305_tight_field_element {
53 type Output = u64;
54 #[inline]
55 fn index(&self, index: usize) -> &Self::Output {
56 &self.0[index]
57 }
58}
59
60impl core::ops::IndexMut<usize> for fiat_poly1305_tight_field_element {
61 #[inline]
62 fn index_mut(&mut self, index: usize) -> &mut Self::Output {
63 &mut self.0[index]
64 }
65}
66
67
68#[inline]
82pub fn fiat_poly1305_addcarryx_u44(out1: &mut u64, out2: &mut fiat_poly1305_u1, arg1: fiat_poly1305_u1, arg2: u64, arg3: u64) {
83 let x1: u64 = (((arg1 as u64) + arg2) + arg3);
84 let x2: u64 = (x1 & 0xfffffffffff);
85 let x3: fiat_poly1305_u1 = ((x1 >> 44) as fiat_poly1305_u1);
86 *out1 = x2;
87 *out2 = x3;
88}
89
90#[inline]
104pub fn fiat_poly1305_subborrowx_u44(out1: &mut u64, out2: &mut fiat_poly1305_u1, arg1: fiat_poly1305_u1, arg2: u64, arg3: u64) {
105 let x1: i64 = ((((((arg2 as i128) - (arg1 as i128)) as i64) as i128) - (arg3 as i128)) as i64);
106 let x2: fiat_poly1305_i1 = ((x1 >> 44) as fiat_poly1305_i1);
107 let x3: u64 = (((x1 as i128) & (0xfffffffffff as i128)) as u64);
108 *out1 = x3;
109 *out2 = (((0x0 as fiat_poly1305_i2) - (x2 as fiat_poly1305_i2)) as fiat_poly1305_u1);
110}
111
112#[inline]
126pub fn fiat_poly1305_addcarryx_u43(out1: &mut u64, out2: &mut fiat_poly1305_u1, arg1: fiat_poly1305_u1, arg2: u64, arg3: u64) {
127 let x1: u64 = (((arg1 as u64) + arg2) + arg3);
128 let x2: u64 = (x1 & 0x7ffffffffff);
129 let x3: fiat_poly1305_u1 = ((x1 >> 43) as fiat_poly1305_u1);
130 *out1 = x2;
131 *out2 = x3;
132}
133
134#[inline]
148pub fn fiat_poly1305_subborrowx_u43(out1: &mut u64, out2: &mut fiat_poly1305_u1, arg1: fiat_poly1305_u1, arg2: u64, arg3: u64) {
149 let x1: i64 = ((((((arg2 as i128) - (arg1 as i128)) as i64) as i128) - (arg3 as i128)) as i64);
150 let x2: fiat_poly1305_i1 = ((x1 >> 43) as fiat_poly1305_i1);
151 let x3: u64 = (((x1 as i128) & (0x7ffffffffff as i128)) as u64);
152 *out1 = x3;
153 *out2 = (((0x0 as fiat_poly1305_i2) - (x2 as fiat_poly1305_i2)) as fiat_poly1305_u1);
154}
155
156#[inline]
168pub fn fiat_poly1305_cmovznz_u64(out1: &mut u64, arg1: fiat_poly1305_u1, arg2: u64, arg3: u64) {
169 let x1: fiat_poly1305_u1 = (!(!arg1));
170 let x2: u64 = ((((((0x0 as fiat_poly1305_i2) - (x1 as fiat_poly1305_i2)) as fiat_poly1305_i1) as i128) & (0xffffffffffffffff as i128)) as u64);
171 let x3: u64 = ((x2 & arg3) | ((!x2) & arg2));
172 *out1 = x3;
173}
174
175#[inline]
181pub fn fiat_poly1305_carry_mul(out1: &mut fiat_poly1305_tight_field_element, arg1: &fiat_poly1305_loose_field_element, arg2: &fiat_poly1305_loose_field_element) {
182 let x1: u128 = (((arg1[2]) as u128) * (((arg2[2]) * 0x5) as u128));
183 let x2: u128 = (((arg1[2]) as u128) * (((arg2[1]) * 0xa) as u128));
184 let x3: u128 = (((arg1[1]) as u128) * (((arg2[2]) * 0xa) as u128));
185 let x4: u128 = (((arg1[2]) as u128) * ((arg2[0]) as u128));
186 let x5: u128 = (((arg1[1]) as u128) * (((arg2[1]) * 0x2) as u128));
187 let x6: u128 = (((arg1[1]) as u128) * ((arg2[0]) as u128));
188 let x7: u128 = (((arg1[0]) as u128) * ((arg2[2]) as u128));
189 let x8: u128 = (((arg1[0]) as u128) * ((arg2[1]) as u128));
190 let x9: u128 = (((arg1[0]) as u128) * ((arg2[0]) as u128));
191 let x10: u128 = (x9 + (x3 + x2));
192 let x11: u64 = ((x10 >> 44) as u64);
193 let x12: u64 = ((x10 & (0xfffffffffff as u128)) as u64);
194 let x13: u128 = (x7 + (x5 + x4));
195 let x14: u128 = (x8 + (x6 + x1));
196 let x15: u128 = ((x11 as u128) + x14);
197 let x16: u64 = ((x15 >> 43) as u64);
198 let x17: u64 = ((x15 & (0x7ffffffffff as u128)) as u64);
199 let x18: u128 = ((x16 as u128) + x13);
200 let x19: u64 = ((x18 >> 43) as u64);
201 let x20: u64 = ((x18 & (0x7ffffffffff as u128)) as u64);
202 let x21: u64 = (x19 * 0x5);
203 let x22: u64 = (x12 + x21);
204 let x23: u64 = (x22 >> 44);
205 let x24: u64 = (x22 & 0xfffffffffff);
206 let x25: u64 = (x23 + x17);
207 let x26: fiat_poly1305_u1 = ((x25 >> 43) as fiat_poly1305_u1);
208 let x27: u64 = (x25 & 0x7ffffffffff);
209 let x28: u64 = ((x26 as u64) + x20);
210 out1[0] = x24;
211 out1[1] = x27;
212 out1[2] = x28;
213}
214
215#[inline]
221pub fn fiat_poly1305_carry_square(out1: &mut fiat_poly1305_tight_field_element, arg1: &fiat_poly1305_loose_field_element) {
222 let x1: u64 = ((arg1[2]) * 0x5);
223 let x2: u64 = (x1 * 0x2);
224 let x3: u64 = ((arg1[2]) * 0x2);
225 let x4: u64 = ((arg1[1]) * 0x2);
226 let x5: u128 = (((arg1[2]) as u128) * (x1 as u128));
227 let x6: u128 = (((arg1[1]) as u128) * ((x2 * 0x2) as u128));
228 let x7: u128 = (((arg1[1]) as u128) * (((arg1[1]) * 0x2) as u128));
229 let x8: u128 = (((arg1[0]) as u128) * (x3 as u128));
230 let x9: u128 = (((arg1[0]) as u128) * (x4 as u128));
231 let x10: u128 = (((arg1[0]) as u128) * ((arg1[0]) as u128));
232 let x11: u128 = (x10 + x6);
233 let x12: u64 = ((x11 >> 44) as u64);
234 let x13: u64 = ((x11 & (0xfffffffffff as u128)) as u64);
235 let x14: u128 = (x8 + x7);
236 let x15: u128 = (x9 + x5);
237 let x16: u128 = ((x12 as u128) + x15);
238 let x17: u64 = ((x16 >> 43) as u64);
239 let x18: u64 = ((x16 & (0x7ffffffffff as u128)) as u64);
240 let x19: u128 = ((x17 as u128) + x14);
241 let x20: u64 = ((x19 >> 43) as u64);
242 let x21: u64 = ((x19 & (0x7ffffffffff as u128)) as u64);
243 let x22: u64 = (x20 * 0x5);
244 let x23: u64 = (x13 + x22);
245 let x24: u64 = (x23 >> 44);
246 let x25: u64 = (x23 & 0xfffffffffff);
247 let x26: u64 = (x24 + x18);
248 let x27: fiat_poly1305_u1 = ((x26 >> 43) as fiat_poly1305_u1);
249 let x28: u64 = (x26 & 0x7ffffffffff);
250 let x29: u64 = ((x27 as u64) + x21);
251 out1[0] = x25;
252 out1[1] = x28;
253 out1[2] = x29;
254}
255
256#[inline]
262pub fn fiat_poly1305_carry(out1: &mut fiat_poly1305_tight_field_element, arg1: &fiat_poly1305_loose_field_element) {
263 let x1: u64 = (arg1[0]);
264 let x2: u64 = ((x1 >> 44) + (arg1[1]));
265 let x3: u64 = ((x2 >> 43) + (arg1[2]));
266 let x4: u64 = ((x1 & 0xfffffffffff) + ((x3 >> 43) * 0x5));
267 let x5: u64 = ((((x4 >> 44) as fiat_poly1305_u1) as u64) + (x2 & 0x7ffffffffff));
268 let x6: u64 = (x4 & 0xfffffffffff);
269 let x7: u64 = (x5 & 0x7ffffffffff);
270 let x8: u64 = ((((x5 >> 43) as fiat_poly1305_u1) as u64) + (x3 & 0x7ffffffffff));
271 out1[0] = x6;
272 out1[1] = x7;
273 out1[2] = x8;
274}
275
276#[inline]
282pub fn fiat_poly1305_add(out1: &mut fiat_poly1305_loose_field_element, arg1: &fiat_poly1305_tight_field_element, arg2: &fiat_poly1305_tight_field_element) {
283 let x1: u64 = ((arg1[0]) + (arg2[0]));
284 let x2: u64 = ((arg1[1]) + (arg2[1]));
285 let x3: u64 = ((arg1[2]) + (arg2[2]));
286 out1[0] = x1;
287 out1[1] = x2;
288 out1[2] = x3;
289}
290
291#[inline]
297pub fn fiat_poly1305_sub(out1: &mut fiat_poly1305_loose_field_element, arg1: &fiat_poly1305_tight_field_element, arg2: &fiat_poly1305_tight_field_element) {
298 let x1: u64 = ((0x1ffffffffff6 + (arg1[0])) - (arg2[0]));
299 let x2: u64 = ((0xffffffffffe + (arg1[1])) - (arg2[1]));
300 let x3: u64 = ((0xffffffffffe + (arg1[2])) - (arg2[2]));
301 out1[0] = x1;
302 out1[1] = x2;
303 out1[2] = x3;
304}
305
306#[inline]
312pub fn fiat_poly1305_opp(out1: &mut fiat_poly1305_loose_field_element, arg1: &fiat_poly1305_tight_field_element) {
313 let x1: u64 = (0x1ffffffffff6 - (arg1[0]));
314 let x2: u64 = (0xffffffffffe - (arg1[1]));
315 let x3: u64 = (0xffffffffffe - (arg1[2]));
316 out1[0] = x1;
317 out1[1] = x2;
318 out1[2] = x3;
319}
320
321#[inline]
333pub fn fiat_poly1305_selectznz(out1: &mut [u64; 3], arg1: fiat_poly1305_u1, arg2: &[u64; 3], arg3: &[u64; 3]) {
334 let mut x1: u64 = 0;
335 fiat_poly1305_cmovznz_u64(&mut x1, arg1, (arg2[0]), (arg3[0]));
336 let mut x2: u64 = 0;
337 fiat_poly1305_cmovznz_u64(&mut x2, arg1, (arg2[1]), (arg3[1]));
338 let mut x3: u64 = 0;
339 fiat_poly1305_cmovznz_u64(&mut x3, arg1, (arg2[2]), (arg3[2]));
340 out1[0] = x1;
341 out1[1] = x2;
342 out1[2] = x3;
343}
344
345#[inline]
353pub fn fiat_poly1305_to_bytes(out1: &mut [u8; 17], arg1: &fiat_poly1305_tight_field_element) {
354 let mut x1: u64 = 0;
355 let mut x2: fiat_poly1305_u1 = 0;
356 fiat_poly1305_subborrowx_u44(&mut x1, &mut x2, 0x0, (arg1[0]), 0xffffffffffb);
357 let mut x3: u64 = 0;
358 let mut x4: fiat_poly1305_u1 = 0;
359 fiat_poly1305_subborrowx_u43(&mut x3, &mut x4, x2, (arg1[1]), 0x7ffffffffff);
360 let mut x5: u64 = 0;
361 let mut x6: fiat_poly1305_u1 = 0;
362 fiat_poly1305_subborrowx_u43(&mut x5, &mut x6, x4, (arg1[2]), 0x7ffffffffff);
363 let mut x7: u64 = 0;
364 fiat_poly1305_cmovznz_u64(&mut x7, x6, (0x0 as u64), 0xffffffffffffffff);
365 let mut x8: u64 = 0;
366 let mut x9: fiat_poly1305_u1 = 0;
367 fiat_poly1305_addcarryx_u44(&mut x8, &mut x9, 0x0, x1, (x7 & 0xffffffffffb));
368 let mut x10: u64 = 0;
369 let mut x11: fiat_poly1305_u1 = 0;
370 fiat_poly1305_addcarryx_u43(&mut x10, &mut x11, x9, x3, (x7 & 0x7ffffffffff));
371 let mut x12: u64 = 0;
372 let mut x13: fiat_poly1305_u1 = 0;
373 fiat_poly1305_addcarryx_u43(&mut x12, &mut x13, x11, x5, (x7 & 0x7ffffffffff));
374 let x14: u64 = (x12 << 7);
375 let x15: u64 = (x10 << 4);
376 let x16: u8 = ((x8 & (0xff as u64)) as u8);
377 let x17: u64 = (x8 >> 8);
378 let x18: u8 = ((x17 & (0xff as u64)) as u8);
379 let x19: u64 = (x17 >> 8);
380 let x20: u8 = ((x19 & (0xff as u64)) as u8);
381 let x21: u64 = (x19 >> 8);
382 let x22: u8 = ((x21 & (0xff as u64)) as u8);
383 let x23: u64 = (x21 >> 8);
384 let x24: u8 = ((x23 & (0xff as u64)) as u8);
385 let x25: u8 = ((x23 >> 8) as u8);
386 let x26: u64 = (x15 + (x25 as u64));
387 let x27: u8 = ((x26 & (0xff as u64)) as u8);
388 let x28: u64 = (x26 >> 8);
389 let x29: u8 = ((x28 & (0xff as u64)) as u8);
390 let x30: u64 = (x28 >> 8);
391 let x31: u8 = ((x30 & (0xff as u64)) as u8);
392 let x32: u64 = (x30 >> 8);
393 let x33: u8 = ((x32 & (0xff as u64)) as u8);
394 let x34: u64 = (x32 >> 8);
395 let x35: u8 = ((x34 & (0xff as u64)) as u8);
396 let x36: u8 = ((x34 >> 8) as u8);
397 let x37: u64 = (x14 + (x36 as u64));
398 let x38: u8 = ((x37 & (0xff as u64)) as u8);
399 let x39: u64 = (x37 >> 8);
400 let x40: u8 = ((x39 & (0xff as u64)) as u8);
401 let x41: u64 = (x39 >> 8);
402 let x42: u8 = ((x41 & (0xff as u64)) as u8);
403 let x43: u64 = (x41 >> 8);
404 let x44: u8 = ((x43 & (0xff as u64)) as u8);
405 let x45: u64 = (x43 >> 8);
406 let x46: u8 = ((x45 & (0xff as u64)) as u8);
407 let x47: u64 = (x45 >> 8);
408 let x48: u8 = ((x47 & (0xff as u64)) as u8);
409 let x49: u8 = ((x47 >> 8) as u8);
410 out1[0] = x16;
411 out1[1] = x18;
412 out1[2] = x20;
413 out1[3] = x22;
414 out1[4] = x24;
415 out1[5] = x27;
416 out1[6] = x29;
417 out1[7] = x31;
418 out1[8] = x33;
419 out1[9] = x35;
420 out1[10] = x38;
421 out1[11] = x40;
422 out1[12] = x42;
423 out1[13] = x44;
424 out1[14] = x46;
425 out1[15] = x48;
426 out1[16] = x49;
427}
428
429#[inline]
437pub fn fiat_poly1305_from_bytes(out1: &mut fiat_poly1305_tight_field_element, arg1: &[u8; 17]) {
438 let x1: u64 = (((arg1[16]) as u64) << 41);
439 let x2: u64 = (((arg1[15]) as u64) << 33);
440 let x3: u64 = (((arg1[14]) as u64) << 25);
441 let x4: u64 = (((arg1[13]) as u64) << 17);
442 let x5: u64 = (((arg1[12]) as u64) << 9);
443 let x6: u64 = (((arg1[11]) as u64) * (0x2 as u64));
444 let x7: u64 = (((arg1[10]) as u64) << 36);
445 let x8: u64 = (((arg1[9]) as u64) << 28);
446 let x9: u64 = (((arg1[8]) as u64) << 20);
447 let x10: u64 = (((arg1[7]) as u64) << 12);
448 let x11: u64 = (((arg1[6]) as u64) << 4);
449 let x12: u64 = (((arg1[5]) as u64) << 40);
450 let x13: u64 = (((arg1[4]) as u64) << 32);
451 let x14: u64 = (((arg1[3]) as u64) << 24);
452 let x15: u64 = (((arg1[2]) as u64) << 16);
453 let x16: u64 = (((arg1[1]) as u64) << 8);
454 let x17: u8 = (arg1[0]);
455 let x18: u64 = (x16 + (x17 as u64));
456 let x19: u64 = (x15 + x18);
457 let x20: u64 = (x14 + x19);
458 let x21: u64 = (x13 + x20);
459 let x22: u64 = (x12 + x21);
460 let x23: u64 = (x22 & 0xfffffffffff);
461 let x24: u8 = ((x22 >> 44) as u8);
462 let x25: u64 = (x11 + (x24 as u64));
463 let x26: u64 = (x10 + x25);
464 let x27: u64 = (x9 + x26);
465 let x28: u64 = (x8 + x27);
466 let x29: u64 = (x7 + x28);
467 let x30: u64 = (x29 & 0x7ffffffffff);
468 let x31: fiat_poly1305_u1 = ((x29 >> 43) as fiat_poly1305_u1);
469 let x32: u64 = (x6 + (x31 as u64));
470 let x33: u64 = (x5 + x32);
471 let x34: u64 = (x4 + x33);
472 let x35: u64 = (x3 + x34);
473 let x36: u64 = (x2 + x35);
474 let x37: u64 = (x1 + x36);
475 out1[0] = x23;
476 out1[1] = x30;
477 out1[2] = x37;
478}
479
480#[inline]
486pub fn fiat_poly1305_relax(out1: &mut fiat_poly1305_loose_field_element, arg1: &fiat_poly1305_tight_field_element) {
487 let x1: u64 = (arg1[0]);
488 let x2: u64 = (arg1[1]);
489 let x3: u64 = (arg1[2]);
490 out1[0] = x1;
491 out1[1] = x2;
492 out1[2] = x3;
493}