Debian Codegraph @

fiat-zig/src/curve25519_32.zig

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