Debian Codegraph @

fiat-go/32/poly1305/poly1305.go

raw symbols SCIP
1 // Code generated by Fiat Cryptography. DO NOT EDIT.
2 //
3 // Autogenerated: 'src/ExtractionOCaml/unsaturated_solinas' --lang Go --relax-primitive-carry-to-bitwidth 32,64 --cmovznz-by-mul --internal-static --package-case flatcase --public-function-case UpperCamelCase --private-function-case camelCase --public-type-case UpperCamelCase --private-type-case camelCase --no-prefix-fiat --doc-newline-in-typedef-bounds --doc-prepend-header 'Code generated by Fiat Cryptography. DO NOT EDIT.' --doc-text-before-function-name '' --doc-text-before-type-name '' --package-name poly1305 '' 32 '(auto)' '2^130 - 5' carry_mul carry_square carry add sub opp selectznz to_bytes from_bytes relax carry_add carry_sub carry_opp
4 //
5 // curve description (via package name): poly1305
6 //
7 // machine_wordsize = 32 (from "32")
8 //
9 // requested operations: carry_mul, carry_square, carry, add, sub, opp, selectznz, to_bytes, from_bytes, relax, carry_add, carry_sub, carry_opp
10 //
11 // n = 5 (from "(auto)")
12 //
13 // s-c = 2^130 - [(1, 5)] (from "2^130 - 5")
14 //
15 // tight_bounds_multiplier = 1 (from "")
16 //
17 //
18 //
19 // Computed values:
20 //
21 // carry_chain = [0, 1, 2, 3, 4, 0, 1]
22 //
23 // eval z = z[0] + (z[1] << 26) + (z[2] << 52) + (z[3] << 78) + (z[4] << 104)
24 //
25 // 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)
26 //
27 // balance = [0x7fffff6, 0x7fffffe, 0x7fffffe, 0x7fffffe, 0x7fffffe]
28 package poly1305
29
30 type uint1 uint64 // We use uint64 instead of a more narrow type for performance reasons; see https://github.com/mit-plv/fiat-crypto/pull/1006#issuecomment-892625927
31 type int1 int64 // We use uint64 instead of a more narrow type for performance reasons; see https://github.com/mit-plv/fiat-crypto/pull/1006#issuecomment-892625927
32
33 // LooseFieldElement is a field element with loose bounds.
34 //
35 // Bounds:
36 //
37 // [[0x0 ~> 0xc000000], [0x0 ~> 0xc000000], [0x0 ~> 0xc000000], [0x0 ~> 0xc000000], [0x0 ~> 0xc000000]]
38 type LooseFieldElement [5]uint32
39
40 // TightFieldElement is a field element with tight bounds.
41 //
42 // Bounds:
43 //
44 // [[0x0 ~> 0x4000000], [0x0 ~> 0x4000000], [0x0 ~> 0x4000000], [0x0 ~> 0x4000000], [0x0 ~> 0x4000000]]
45 type TightFieldElement [5]uint32
46
47 // addcarryxU26 is an addition with carry.
48 //
49 // Postconditions:
50 // out1 = (arg1 + arg2 + arg3) mod 2^26
51 // out2 = ⌊(arg1 + arg2 + arg3) / 2^26⌋
52 //
53 // Input Bounds:
54 // arg1: [0x0 ~> 0x1]
55 // arg2: [0x0 ~> 0x3ffffff]
56 // arg3: [0x0 ~> 0x3ffffff]
57 // Output Bounds:
58 // out1: [0x0 ~> 0x3ffffff]
59 // out2: [0x0 ~> 0x1]
60 func addcarryxU26(out1 *uint32, out2 *uint1, arg1 uint1, arg2 uint32, arg3 uint32) {
61 x1 := ((uint32(arg1) + arg2) + arg3)
62 x2 := (x1 & 0x3ffffff)
63 x3 := uint1((x1 >> 26))
64 *out1 = x2
65 *out2 = x3
66 }
67
68 // subborrowxU26 is a subtraction with borrow.
69 //
70 // Postconditions:
71 // out1 = (-arg1 + arg2 + -arg3) mod 2^26
72 // out2 = -⌊(-arg1 + arg2 + -arg3) / 2^26⌋
73 //
74 // Input Bounds:
75 // arg1: [0x0 ~> 0x1]
76 // arg2: [0x0 ~> 0x3ffffff]
77 // arg3: [0x0 ~> 0x3ffffff]
78 // Output Bounds:
79 // out1: [0x0 ~> 0x3ffffff]
80 // out2: [0x0 ~> 0x1]
81 func subborrowxU26(out1 *uint32, out2 *uint1, arg1 uint1, arg2 uint32, arg3 uint32) {
82 x1 := ((int32(arg2) - int32(arg1)) - int32(arg3))
83 x2 := int1((x1 >> 26))
84 x3 := (uint32(x1) & 0x3ffffff)
85 *out1 = x3
86 *out2 = (0x0 - uint1(x2))
87 }
88
89 // cmovznzU32 is a single-word conditional move.
90 //
91 // Postconditions:
92 // out1 = (if arg1 = 0 then arg2 else arg3)
93 //
94 // Input Bounds:
95 // arg1: [0x0 ~> 0x1]
96 // arg2: [0x0 ~> 0xffffffff]
97 // arg3: [0x0 ~> 0xffffffff]
98 // Output Bounds:
99 // out1: [0x0 ~> 0xffffffff]
100 func cmovznzU32(out1 *uint32, arg1 uint1, arg2 uint32, arg3 uint32) {
101 x1 := (uint32(arg1) * 0xffffffff)
102 x2 := ((x1 & arg3) | ((^x1) & arg2))
103 *out1 = x2
104 }
105
106 // CarryMul multiplies two field elements and reduces the result.
107 //
108 // Postconditions:
109 // eval out1 mod m = (eval arg1 * eval arg2) mod m
110 //
111 func CarryMul(out1 *TightFieldElement, arg1 *LooseFieldElement, arg2 *LooseFieldElement) {
112 x1 := (uint64(arg1[4]) * uint64((arg2[4] * 0x5)))
113 x2 := (uint64(arg1[4]) * uint64((arg2[3] * 0x5)))
114 x3 := (uint64(arg1[4]) * uint64((arg2[2] * 0x5)))
115 x4 := (uint64(arg1[4]) * uint64((arg2[1] * 0x5)))
116 x5 := (uint64(arg1[3]) * uint64((arg2[4] * 0x5)))
117 x6 := (uint64(arg1[3]) * uint64((arg2[3] * 0x5)))
118 x7 := (uint64(arg1[3]) * uint64((arg2[2] * 0x5)))
119 x8 := (uint64(arg1[2]) * uint64((arg2[4] * 0x5)))
120 x9 := (uint64(arg1[2]) * uint64((arg2[3] * 0x5)))
121 x10 := (uint64(arg1[1]) * uint64((arg2[4] * 0x5)))
122 x11 := (uint64(arg1[4]) * uint64(arg2[0]))
123 x12 := (uint64(arg1[3]) * uint64(arg2[1]))
124 x13 := (uint64(arg1[3]) * uint64(arg2[0]))
125 x14 := (uint64(arg1[2]) * uint64(arg2[2]))
126 x15 := (uint64(arg1[2]) * uint64(arg2[1]))
127 x16 := (uint64(arg1[2]) * uint64(arg2[0]))
128 x17 := (uint64(arg1[1]) * uint64(arg2[3]))
129 x18 := (uint64(arg1[1]) * uint64(arg2[2]))
130 x19 := (uint64(arg1[1]) * uint64(arg2[1]))
131 x20 := (uint64(arg1[1]) * uint64(arg2[0]))
132 x21 := (uint64(arg1[0]) * uint64(arg2[4]))
133 x22 := (uint64(arg1[0]) * uint64(arg2[3]))
134 x23 := (uint64(arg1[0]) * uint64(arg2[2]))
135 x24 := (uint64(arg1[0]) * uint64(arg2[1]))
136 x25 := (uint64(arg1[0]) * uint64(arg2[0]))
137 x26 := (x25 + (x10 + (x9 + (x7 + x4))))
138 x27 := (x26 >> 26)
139 x28 := (uint32(x26) & 0x3ffffff)
140 x29 := (x21 + (x17 + (x14 + (x12 + x11))))
141 x30 := (x22 + (x18 + (x15 + (x13 + x1))))
142 x31 := (x23 + (x19 + (x16 + (x5 + x2))))
143 x32 := (x24 + (x20 + (x8 + (x6 + x3))))
144 x33 := (x27 + x32)
145 x34 := (x33 >> 26)
146 x35 := (uint32(x33) & 0x3ffffff)
147 x36 := (x34 + x31)
148 x37 := (x36 >> 26)
149 x38 := (uint32(x36) & 0x3ffffff)
150 x39 := (x37 + x30)
151 x40 := (x39 >> 26)
152 x41 := (uint32(x39) & 0x3ffffff)
153 x42 := (x40 + x29)
154 x43 := uint32((x42 >> 26))
155 x44 := (uint32(x42) & 0x3ffffff)
156 x45 := (uint64(x43) * uint64(0x5))
157 x46 := (uint64(x28) + x45)
158 x47 := uint32((x46 >> 26))
159 x48 := (uint32(x46) & 0x3ffffff)
160 x49 := (x47 + x35)
161 x50 := uint1((x49 >> 26))
162 x51 := (x49 & 0x3ffffff)
163 x52 := (uint32(x50) + x38)
164 out1[0] = x48
165 out1[1] = x51
166 out1[2] = x52
167 out1[3] = x41
168 out1[4] = x44
169 }
170
171 // CarrySquare squares a field element and reduces the result.
172 //
173 // Postconditions:
174 // eval out1 mod m = (eval arg1 * eval arg1) mod m
175 //
176 func CarrySquare(out1 *TightFieldElement, arg1 *LooseFieldElement) {
177 x1 := (arg1[4] * 0x5)
178 x2 := (x1 * 0x2)
179 x3 := (arg1[4] * 0x2)
180 x4 := (arg1[3] * 0x5)
181 x5 := (x4 * 0x2)
182 x6 := (arg1[3] * 0x2)
183 x7 := (arg1[2] * 0x2)
184 x8 := (arg1[1] * 0x2)
185 x9 := (uint64(arg1[4]) * uint64(x1))
186 x10 := (uint64(arg1[3]) * uint64(x2))
187 x11 := (uint64(arg1[3]) * uint64(x4))
188 x12 := (uint64(arg1[2]) * uint64(x2))
189 x13 := (uint64(arg1[2]) * uint64(x5))
190 x14 := (uint64(arg1[2]) * uint64(arg1[2]))
191 x15 := (uint64(arg1[1]) * uint64(x2))
192 x16 := (uint64(arg1[1]) * uint64(x6))
193 x17 := (uint64(arg1[1]) * uint64(x7))
194 x18 := (uint64(arg1[1]) * uint64(arg1[1]))
195 x19 := (uint64(arg1[0]) * uint64(x3))
196 x20 := (uint64(arg1[0]) * uint64(x6))
197 x21 := (uint64(arg1[0]) * uint64(x7))
198 x22 := (uint64(arg1[0]) * uint64(x8))
199 x23 := (uint64(arg1[0]) * uint64(arg1[0]))
200 x24 := (x23 + (x15 + x13))
201 x25 := (x24 >> 26)
202 x26 := (uint32(x24) & 0x3ffffff)
203 x27 := (x19 + (x16 + x14))
204 x28 := (x20 + (x17 + x9))
205 x29 := (x21 + (x18 + x10))
206 x30 := (x22 + (x12 + x11))
207 x31 := (x25 + x30)
208 x32 := (x31 >> 26)
209 x33 := (uint32(x31) & 0x3ffffff)
210 x34 := (x32 + x29)
211 x35 := (x34 >> 26)
212 x36 := (uint32(x34) & 0x3ffffff)
213 x37 := (x35 + x28)
214 x38 := (x37 >> 26)
215 x39 := (uint32(x37) & 0x3ffffff)
216 x40 := (x38 + x27)
217 x41 := uint32((x40 >> 26))
218 x42 := (uint32(x40) & 0x3ffffff)
219 x43 := (uint64(x41) * uint64(0x5))
220 x44 := (uint64(x26) + x43)
221 x45 := uint32((x44 >> 26))
222 x46 := (uint32(x44) & 0x3ffffff)
223 x47 := (x45 + x33)
224 x48 := uint1((x47 >> 26))
225 x49 := (x47 & 0x3ffffff)
226 x50 := (uint32(x48) + x36)
227 out1[0] = x46
228 out1[1] = x49
229 out1[2] = x50
230 out1[3] = x39
231 out1[4] = x42
232 }
233
234 // Carry reduces a field element.
235 //
236 // Postconditions:
237 // eval out1 mod m = eval arg1 mod m
238 //
239 func Carry(out1 *TightFieldElement, arg1 *LooseFieldElement) {
240 x1 := arg1[0]
241 x2 := ((x1 >> 26) + arg1[1])
242 x3 := ((x2 >> 26) + arg1[2])
243 x4 := ((x3 >> 26) + arg1[3])
244 x5 := ((x4 >> 26) + arg1[4])
245 x6 := ((x1 & 0x3ffffff) + ((x5 >> 26) * 0x5))
246 x7 := (uint32(uint1((x6 >> 26))) + (x2 & 0x3ffffff))
247 x8 := (x6 & 0x3ffffff)
248 x9 := (x7 & 0x3ffffff)
249 x10 := (uint32(uint1((x7 >> 26))) + (x3 & 0x3ffffff))
250 x11 := (x4 & 0x3ffffff)
251 x12 := (x5 & 0x3ffffff)
252 out1[0] = x8
253 out1[1] = x9
254 out1[2] = x10
255 out1[3] = x11
256 out1[4] = x12
257 }
258
259 // Add adds two field elements.
260 //
261 // Postconditions:
262 // eval out1 mod m = (eval arg1 + eval arg2) mod m
263 //
264 func Add(out1 *LooseFieldElement, arg1 *TightFieldElement, arg2 *TightFieldElement) {
265 x1 := (arg1[0] + arg2[0])
266 x2 := (arg1[1] + arg2[1])
267 x3 := (arg1[2] + arg2[2])
268 x4 := (arg1[3] + arg2[3])
269 x5 := (arg1[4] + arg2[4])
270 out1[0] = x1
271 out1[1] = x2
272 out1[2] = x3
273 out1[3] = x4
274 out1[4] = x5
275 }
276
277 // Sub subtracts two field elements.
278 //
279 // Postconditions:
280 // eval out1 mod m = (eval arg1 - eval arg2) mod m
281 //
282 func Sub(out1 *LooseFieldElement, arg1 *TightFieldElement, arg2 *TightFieldElement) {
283 x1 := ((0x7fffff6 + arg1[0]) - arg2[0])
284 x2 := ((0x7fffffe + arg1[1]) - arg2[1])
285 x3 := ((0x7fffffe + arg1[2]) - arg2[2])
286 x4 := ((0x7fffffe + arg1[3]) - arg2[3])
287 x5 := ((0x7fffffe + arg1[4]) - arg2[4])
288 out1[0] = x1
289 out1[1] = x2
290 out1[2] = x3
291 out1[3] = x4
292 out1[4] = x5
293 }
294
295 // Opp negates a field element.
296 //
297 // Postconditions:
298 // eval out1 mod m = -eval arg1 mod m
299 //
300 func Opp(out1 *LooseFieldElement, arg1 *TightFieldElement) {
301 x1 := (0x7fffff6 - arg1[0])
302 x2 := (0x7fffffe - arg1[1])
303 x3 := (0x7fffffe - arg1[2])
304 x4 := (0x7fffffe - arg1[3])
305 x5 := (0x7fffffe - arg1[4])
306 out1[0] = x1
307 out1[1] = x2
308 out1[2] = x3
309 out1[3] = x4
310 out1[4] = x5
311 }
312
313 // Selectznz is a multi-limb conditional select.
314 //
315 // Postconditions:
316 // out1 = (if arg1 = 0 then arg2 else arg3)
317 //
318 // Input Bounds:
319 // arg1: [0x0 ~> 0x1]
320 // arg2: [[0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff]]
321 // arg3: [[0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff]]
322 // Output Bounds:
323 // out1: [[0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff]]
324 func Selectznz(out1 *[5]uint32, arg1 uint1, arg2 *[5]uint32, arg3 *[5]uint32) {
325 var x1 uint32
326 cmovznzU32(&x1, arg1, arg2[0], arg3[0])
327 var x2 uint32
328 cmovznzU32(&x2, arg1, arg2[1], arg3[1])
329 var x3 uint32
330 cmovznzU32(&x3, arg1, arg2[2], arg3[2])
331 var x4 uint32
332 cmovznzU32(&x4, arg1, arg2[3], arg3[3])
333 var x5 uint32
334 cmovznzU32(&x5, arg1, arg2[4], arg3[4])
335 out1[0] = x1
336 out1[1] = x2
337 out1[2] = x3
338 out1[3] = x4
339 out1[4] = x5
340 }
341
342 // ToBytes serializes a field element to bytes in little-endian order.
343 //
344 // Postconditions:
345 // out1 = map (λ x, ⌊((eval arg1 mod m) mod 2^(8 * (x + 1))) / 2^(8 * x)⌋) [0..16]
346 //
347 // Output Bounds:
348 // out1: [[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]]
349 func ToBytes(out1 *[17]uint8, arg1 *TightFieldElement) {
350 var x1 uint32
351 var x2 uint1
352 subborrowxU26(&x1, &x2, 0x0, arg1[0], 0x3fffffb)
353 var x3 uint32
354 var x4 uint1
355 subborrowxU26(&x3, &x4, x2, arg1[1], 0x3ffffff)
356 var x5 uint32
357 var x6 uint1
358 subborrowxU26(&x5, &x6, x4, arg1[2], 0x3ffffff)
359 var x7 uint32
360 var x8 uint1
361 subborrowxU26(&x7, &x8, x6, arg1[3], 0x3ffffff)
362 var x9 uint32
363 var x10 uint1
364 subborrowxU26(&x9, &x10, x8, arg1[4], 0x3ffffff)
365 var x11 uint32
366 cmovznzU32(&x11, x10, uint32(0x0), 0xffffffff)
367 var x12 uint32
368 var x13 uint1
369 addcarryxU26(&x12, &x13, 0x0, x1, (x11 & 0x3fffffb))
370 var x14 uint32
371 var x15 uint1
372 addcarryxU26(&x14, &x15, x13, x3, (x11 & 0x3ffffff))
373 var x16 uint32
374 var x17 uint1
375 addcarryxU26(&x16, &x17, x15, x5, (x11 & 0x3ffffff))
376 var x18 uint32
377 var x19 uint1
378 addcarryxU26(&x18, &x19, x17, x7, (x11 & 0x3ffffff))
379 var x20 uint32
380 var x21 uint1
381 addcarryxU26(&x20, &x21, x19, x9, (x11 & 0x3ffffff))
382 x22 := (x18 << 6)
383 x23 := (x16 << 4)
384 x24 := (x14 << 2)
385 x25 := (uint8(x12) & 0xff)
386 x26 := (x12 >> 8)
387 x27 := (uint8(x26) & 0xff)
388 x28 := (x26 >> 8)
389 x29 := (uint8(x28) & 0xff)
390 x30 := uint8((x28 >> 8))
391 x31 := (x24 + uint32(x30))
392 x32 := (uint8(x31) & 0xff)
393 x33 := (x31 >> 8)
394 x34 := (uint8(x33) & 0xff)
395 x35 := (x33 >> 8)
396 x36 := (uint8(x35) & 0xff)
397 x37 := uint8((x35 >> 8))
398 x38 := (x23 + uint32(x37))
399 x39 := (uint8(x38) & 0xff)
400 x40 := (x38 >> 8)
401 x41 := (uint8(x40) & 0xff)
402 x42 := (x40 >> 8)
403 x43 := (uint8(x42) & 0xff)
404 x44 := uint8((x42 >> 8))
405 x45 := (x22 + uint32(x44))
406 x46 := (uint8(x45) & 0xff)
407 x47 := (x45 >> 8)
408 x48 := (uint8(x47) & 0xff)
409 x49 := (x47 >> 8)
410 x50 := (uint8(x49) & 0xff)
411 x51 := uint8((x49 >> 8))
412 x52 := (uint8(x20) & 0xff)
413 x53 := (x20 >> 8)
414 x54 := (uint8(x53) & 0xff)
415 x55 := (x53 >> 8)
416 x56 := (uint8(x55) & 0xff)
417 x57 := uint8((x55 >> 8))
418 out1[0] = x25
419 out1[1] = x27
420 out1[2] = x29
421 out1[3] = x32
422 out1[4] = x34
423 out1[5] = x36
424 out1[6] = x39
425 out1[7] = x41
426 out1[8] = x43
427 out1[9] = x46
428 out1[10] = x48
429 out1[11] = x50
430 out1[12] = x51
431 out1[13] = x52
432 out1[14] = x54
433 out1[15] = x56
434 out1[16] = x57
435 }
436
437 // FromBytes deserializes a field element from bytes in little-endian order.
438 //
439 // Postconditions:
440 // eval out1 mod m = bytes_eval arg1 mod m
441 //
442 // Input Bounds:
443 // arg1: [[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]]
444 func FromBytes(out1 *TightFieldElement, arg1 *[17]uint8) {
445 x1 := (uint32(arg1[16]) << 24)
446 x2 := (uint32(arg1[15]) << 16)
447 x3 := (uint32(arg1[14]) << 8)
448 x4 := arg1[13]
449 x5 := (uint32(arg1[12]) << 18)
450 x6 := (uint32(arg1[11]) << 10)
451 x7 := (uint32(arg1[10]) << 2)
452 x8 := (uint32(arg1[9]) << 20)
453 x9 := (uint32(arg1[8]) << 12)
454 x10 := (uint32(arg1[7]) << 4)
455 x11 := (uint32(arg1[6]) << 22)
456 x12 := (uint32(arg1[5]) << 14)
457 x13 := (uint32(arg1[4]) << 6)
458 x14 := (uint32(arg1[3]) << 24)
459 x15 := (uint32(arg1[2]) << 16)
460 x16 := (uint32(arg1[1]) << 8)
461 x17 := arg1[0]
462 x18 := (x16 + uint32(x17))
463 x19 := (x15 + x18)
464 x20 := (x14 + x19)
465 x21 := (x20 & 0x3ffffff)
466 x22 := uint8((x20 >> 26))
467 x23 := (x13 + uint32(x22))
468 x24 := (x12 + x23)
469 x25 := (x11 + x24)
470 x26 := (x25 & 0x3ffffff)
471 x27 := uint8((x25 >> 26))
472 x28 := (x10 + uint32(x27))
473 x29 := (x9 + x28)
474 x30 := (x8 + x29)
475 x31 := (x30 & 0x3ffffff)
476 x32 := uint8((x30 >> 26))
477 x33 := (x7 + uint32(x32))
478 x34 := (x6 + x33)
479 x35 := (x5 + x34)
480 x36 := (x3 + uint32(x4))
481 x37 := (x2 + x36)
482 x38 := (x1 + x37)
483 out1[0] = x21
484 out1[1] = x26
485 out1[2] = x31
486 out1[3] = x35
487 out1[4] = x38
488 }
489
490 // Relax is the identity function converting from tight field elements to loose field elements.
491 //
492 // Postconditions:
493 // out1 = arg1
494 //
495 func Relax(out1 *LooseFieldElement, arg1 *TightFieldElement) {
496 x1 := arg1[0]
497 x2 := arg1[1]
498 x3 := arg1[2]
499 x4 := arg1[3]
500 x5 := arg1[4]
501 out1[0] = x1
502 out1[1] = x2
503 out1[2] = x3
504 out1[3] = x4
505 out1[4] = x5
506 }
507
508 // CarryAdd adds two field elements.
509 //
510 // Postconditions:
511 // eval out1 mod m = (eval arg1 + eval arg2) mod m
512 //
513 func CarryAdd(out1 *TightFieldElement, arg1 *TightFieldElement, arg2 *TightFieldElement) {
514 x1 := (arg1[0] + arg2[0])
515 x2 := ((x1 >> 26) + (arg1[1] + arg2[1]))
516 x3 := ((x2 >> 26) + (arg1[2] + arg2[2]))
517 x4 := ((x3 >> 26) + (arg1[3] + arg2[3]))
518 x5 := ((x4 >> 26) + (arg1[4] + arg2[4]))
519 x6 := ((x1 & 0x3ffffff) + ((x5 >> 26) * 0x5))
520 x7 := (uint32(uint1((x6 >> 26))) + (x2 & 0x3ffffff))
521 x8 := (x6 & 0x3ffffff)
522 x9 := (x7 & 0x3ffffff)
523 x10 := (uint32(uint1((x7 >> 26))) + (x3 & 0x3ffffff))
524 x11 := (x4 & 0x3ffffff)
525 x12 := (x5 & 0x3ffffff)
526 out1[0] = x8
527 out1[1] = x9
528 out1[2] = x10
529 out1[3] = x11
530 out1[4] = x12
531 }
532
533 // CarrySub subtracts two field elements.
534 //
535 // Postconditions:
536 // eval out1 mod m = (eval arg1 - eval arg2) mod m
537 //
538 func CarrySub(out1 *TightFieldElement, arg1 *TightFieldElement, arg2 *TightFieldElement) {
539 x1 := ((0x7fffff6 + arg1[0]) - arg2[0])
540 x2 := ((x1 >> 26) + ((0x7fffffe + arg1[1]) - arg2[1]))
541 x3 := ((x2 >> 26) + ((0x7fffffe + arg1[2]) - arg2[2]))
542 x4 := ((x3 >> 26) + ((0x7fffffe + arg1[3]) - arg2[3]))
543 x5 := ((x4 >> 26) + ((0x7fffffe + arg1[4]) - arg2[4]))
544 x6 := ((x1 & 0x3ffffff) + ((x5 >> 26) * 0x5))
545 x7 := (uint32(uint1((x6 >> 26))) + (x2 & 0x3ffffff))
546 x8 := (x6 & 0x3ffffff)
547 x9 := (x7 & 0x3ffffff)
548 x10 := (uint32(uint1((x7 >> 26))) + (x3 & 0x3ffffff))
549 x11 := (x4 & 0x3ffffff)
550 x12 := (x5 & 0x3ffffff)
551 out1[0] = x8
552 out1[1] = x9
553 out1[2] = x10
554 out1[3] = x11
555 out1[4] = x12
556 }
557
558 // CarryOpp negates a field element.
559 //
560 // Postconditions:
561 // eval out1 mod m = -eval arg1 mod m
562 //
563 func CarryOpp(out1 *TightFieldElement, arg1 *TightFieldElement) {
564 x1 := (0x7fffff6 - arg1[0])
565 x2 := (uint32(uint1((x1 >> 26))) + (0x7fffffe - arg1[1]))
566 x3 := (uint32(uint1((x2 >> 26))) + (0x7fffffe - arg1[2]))
567 x4 := (uint32(uint1((x3 >> 26))) + (0x7fffffe - arg1[3]))
568 x5 := (uint32(uint1((x4 >> 26))) + (0x7fffffe - arg1[4]))
569 x6 := ((x1 & 0x3ffffff) + (uint32(uint1((x5 >> 26))) * 0x5))
570 x7 := (uint32(uint1((x6 >> 26))) + (x2 & 0x3ffffff))
571 x8 := (x6 & 0x3ffffff)
572 x9 := (x7 & 0x3ffffff)
573 x10 := (uint32(uint1((x7 >> 26))) + (x3 & 0x3ffffff))
574 x11 := (x4 & 0x3ffffff)
575 x12 := (x5 & 0x3ffffff)
576 out1[0] = x8
577 out1[1] = x9
578 out1[2] = x10
579 out1[3] = x11
580 out1[4] = x12
581 }