// 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 p521 '' 64 '(auto)' '2^521 - 1' carry_mul carry_square carry add sub opp selectznz to_bytes from_bytes relax // curve description (via package name): p521 // machine_wordsize = 64 (from "64") // requested operations: carry_mul, carry_square, carry, add, sub, opp, selectznz, to_bytes, from_bytes, relax // n = 9 (from "(auto)") // s-c = 2^521 - [(1, 1)] (from "2^521 - 1") // tight_bounds_multiplier = 1 (from "") // // Computed values: // carry_chain = [0, 1, 2, 3, 4, 5, 6, 7, 8, 0, 1] // eval z = z[0] + (z[1] << 58) + (z[2] << 116) + (z[3] << 174) + (z[4] << 232) + (z[5] << 0x122) + (z[6] << 0x15c) + (z[7] << 0x196) + (z[8] << 0x1d0) // 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) + (z[32] << 256) + (z[33] << 0x108) + (z[34] << 0x110) + (z[35] << 0x118) + (z[36] << 0x120) + (z[37] << 0x128) + (z[38] << 0x130) + (z[39] << 0x138) + (z[40] << 0x140) + (z[41] << 0x148) + (z[42] << 0x150) + (z[43] << 0x158) + (z[44] << 0x160) + (z[45] << 0x168) + (z[46] << 0x170) + (z[47] << 0x178) + (z[48] << 0x180) + (z[49] << 0x188) + (z[50] << 0x190) + (z[51] << 0x198) + (z[52] << 0x1a0) + (z[53] << 0x1a8) + (z[54] << 0x1b0) + (z[55] << 0x1b8) + (z[56] << 0x1c0) + (z[57] << 0x1c8) + (z[58] << 0x1d0) + (z[59] << 0x1d8) + (z[60] << 0x1e0) + (z[61] << 0x1e8) + (z[62] << 0x1f0) + (z[63] << 0x1f8) + (z[64] << 2^9) + (z[65] << 0x208) // balance = [0x7fffffffffffffe, 0x7fffffffffffffe, 0x7fffffffffffffe, 0x7fffffffffffffe, 0x7fffffffffffffe, 0x7fffffffffffffe, 0x7fffffffffffffe, 0x7fffffffffffffe, 0x3fffffffffffffe] const std = @import("std"); const mode = @import("builtin").mode; // Checked arithmetic is disabled in non-debug modes to avoid side channels inline fn cast(comptime DestType: type, target: anytype) DestType { @setEvalBranchQuota(10000); if (@typeInfo(@TypeOf(target)) == .int) { const dest = @typeInfo(DestType).int; const source = @typeInfo(@TypeOf(target)).int; if (dest.bits < source.bits) { const T = std.meta.Int(source.signedness, dest.bits); return @bitCast(@as(T, @truncate(target))); } } return target; } // The type LooseFieldElement is a field element with loose bounds. // Bounds: [[0x0 ~> 0xc00000000000000], [0x0 ~> 0xc00000000000000], [0x0 ~> 0xc00000000000000], [0x0 ~> 0xc00000000000000], [0x0 ~> 0xc00000000000000], [0x0 ~> 0xc00000000000000], [0x0 ~> 0xc00000000000000], [0x0 ~> 0xc00000000000000], [0x0 ~> 0x600000000000000]] pub const LooseFieldElement = [9]u64; // The type TightFieldElement is a field element with tight bounds. // Bounds: [[0x0 ~> 0x400000000000000], [0x0 ~> 0x400000000000000], [0x0 ~> 0x400000000000000], [0x0 ~> 0x400000000000000], [0x0 ~> 0x400000000000000], [0x0 ~> 0x400000000000000], [0x0 ~> 0x400000000000000], [0x0 ~> 0x400000000000000], [0x0 ~> 0x200000000000000]] pub const TightFieldElement = [9]u64; /// The function addcarryxU58 is an addition with carry. /// /// Postconditions: /// out1 = (arg1 + arg2 + arg3) mod 2^58 /// out2 = ⌊(arg1 + arg2 + arg3) / 2^58⌋ /// /// Input Bounds: /// arg1: [0x0 ~> 0x1] /// arg2: [0x0 ~> 0x3ffffffffffffff] /// arg3: [0x0 ~> 0x3ffffffffffffff] /// Output Bounds: /// out1: [0x0 ~> 0x3ffffffffffffff] /// out2: [0x0 ~> 0x1] inline fn addcarryxU58(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) void { @setRuntimeSafety(mode == .Debug); const x1 = ((cast(u64, arg1) + arg2) + arg3); const x2 = (x1 & 0x3ffffffffffffff); const x3 = cast(u1, (x1 >> 58)); out1.* = x2; out2.* = x3; } /// The function subborrowxU58 is a subtraction with borrow. /// /// Postconditions: /// out1 = (-arg1 + arg2 + -arg3) mod 2^58 /// out2 = -⌊(-arg1 + arg2 + -arg3) / 2^58⌋ /// /// Input Bounds: /// arg1: [0x0 ~> 0x1] /// arg2: [0x0 ~> 0x3ffffffffffffff] /// arg3: [0x0 ~> 0x3ffffffffffffff] /// Output Bounds: /// out1: [0x0 ~> 0x3ffffffffffffff] /// out2: [0x0 ~> 0x1] inline fn subborrowxU58(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) void { @setRuntimeSafety(mode == .Debug); const x1 = cast(i64, (cast(i128, cast(i64, (cast(i128, arg2) - cast(i128, arg1)))) - cast(i128, arg3))); const x2 = cast(i1, (x1 >> 58)); const x3 = cast(u64, (cast(i128, x1) & cast(i128, 0x3ffffffffffffff))); out1.* = x3; out2.* = cast(u1, (cast(i2, 0x0) - cast(i2, x2))); } /// The function addcarryxU57 is an addition with carry. /// /// Postconditions: /// out1 = (arg1 + arg2 + arg3) mod 2^57 /// out2 = ⌊(arg1 + arg2 + arg3) / 2^57⌋ /// /// Input Bounds: /// arg1: [0x0 ~> 0x1] /// arg2: [0x0 ~> 0x1ffffffffffffff] /// arg3: [0x0 ~> 0x1ffffffffffffff] /// Output Bounds: /// out1: [0x0 ~> 0x1ffffffffffffff] /// out2: [0x0 ~> 0x1] inline fn addcarryxU57(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) void { @setRuntimeSafety(mode == .Debug); const x1 = ((cast(u64, arg1) + arg2) + arg3); const x2 = (x1 & 0x1ffffffffffffff); const x3 = cast(u1, (x1 >> 57)); out1.* = x2; out2.* = x3; } /// The function subborrowxU57 is a subtraction with borrow. /// /// Postconditions: /// out1 = (-arg1 + arg2 + -arg3) mod 2^57 /// out2 = -⌊(-arg1 + arg2 + -arg3) / 2^57⌋ /// /// Input Bounds: /// arg1: [0x0 ~> 0x1] /// arg2: [0x0 ~> 0x1ffffffffffffff] /// arg3: [0x0 ~> 0x1ffffffffffffff] /// Output Bounds: /// out1: [0x0 ~> 0x1ffffffffffffff] /// out2: [0x0 ~> 0x1] inline fn subborrowxU57(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) void { @setRuntimeSafety(mode == .Debug); const x1 = cast(i64, (cast(i128, cast(i64, (cast(i128, arg2) - cast(i128, arg1)))) - cast(i128, arg3))); const x2 = cast(i1, (x1 >> 57)); const x3 = cast(u64, (cast(i128, x1) & cast(i128, 0x1ffffffffffffff))); out1.* = x3; out2.* = cast(u1, (cast(i2, 0x0) - cast(i2, x2))); } /// The function cmovznzU64 is a single-word conditional move. /// /// Postconditions: /// out1 = (if arg1 = 0 then arg2 else arg3) /// /// Input Bounds: /// arg1: [0x0 ~> 0x1] /// arg2: [0x0 ~> 0xffffffffffffffff] /// arg3: [0x0 ~> 0xffffffffffffffff] /// Output Bounds: /// out1: [0x0 ~> 0xffffffffffffffff] inline fn cmovznzU64(out1: *u64, arg1: u1, arg2: u64, arg3: u64) void { @setRuntimeSafety(mode == .Debug); const x1 = (~(~arg1)); const x2 = cast(u64, (cast(i128, cast(i1, (cast(i2, 0x0) - cast(i2, x1)))) & cast(i128, 0xffffffffffffffff))); const x3 = ((x2 & arg3) | ((~x2) & arg2)); out1.* = x3; } /// The function carryMul multiplies two field elements and reduces the result. /// /// Postconditions: /// eval out1 mod m = (eval arg1 * eval arg2) mod m /// pub fn carryMul(out1: *TightFieldElement, arg1: LooseFieldElement, arg2: LooseFieldElement) void { @setRuntimeSafety(mode == .Debug); const x1 = (cast(u128, (arg1[8])) * cast(u128, ((arg2[8]) * 0x2))); const x2 = (cast(u128, (arg1[8])) * cast(u128, ((arg2[7]) * 0x2))); const x3 = (cast(u128, (arg1[8])) * cast(u128, ((arg2[6]) * 0x2))); const x4 = (cast(u128, (arg1[8])) * cast(u128, ((arg2[5]) * 0x2))); const x5 = (cast(u128, (arg1[8])) * cast(u128, ((arg2[4]) * 0x2))); const x6 = (cast(u128, (arg1[8])) * cast(u128, ((arg2[3]) * 0x2))); const x7 = (cast(u128, (arg1[8])) * cast(u128, ((arg2[2]) * 0x2))); const x8 = (cast(u128, (arg1[8])) * cast(u128, ((arg2[1]) * 0x2))); const x9 = (cast(u128, (arg1[7])) * cast(u128, ((arg2[8]) * 0x2))); const x10 = (cast(u128, (arg1[7])) * cast(u128, ((arg2[7]) * 0x2))); const x11 = (cast(u128, (arg1[7])) * cast(u128, ((arg2[6]) * 0x2))); const x12 = (cast(u128, (arg1[7])) * cast(u128, ((arg2[5]) * 0x2))); const x13 = (cast(u128, (arg1[7])) * cast(u128, ((arg2[4]) * 0x2))); const x14 = (cast(u128, (arg1[7])) * cast(u128, ((arg2[3]) * 0x2))); const x15 = (cast(u128, (arg1[7])) * cast(u128, ((arg2[2]) * 0x2))); const x16 = (cast(u128, (arg1[6])) * cast(u128, ((arg2[8]) * 0x2))); const x17 = (cast(u128, (arg1[6])) * cast(u128, ((arg2[7]) * 0x2))); const x18 = (cast(u128, (arg1[6])) * cast(u128, ((arg2[6]) * 0x2))); const x19 = (cast(u128, (arg1[6])) * cast(u128, ((arg2[5]) * 0x2))); const x20 = (cast(u128, (arg1[6])) * cast(u128, ((arg2[4]) * 0x2))); const x21 = (cast(u128, (arg1[6])) * cast(u128, ((arg2[3]) * 0x2))); const x22 = (cast(u128, (arg1[5])) * cast(u128, ((arg2[8]) * 0x2))); const x23 = (cast(u128, (arg1[5])) * cast(u128, ((arg2[7]) * 0x2))); const x24 = (cast(u128, (arg1[5])) * cast(u128, ((arg2[6]) * 0x2))); const x25 = (cast(u128, (arg1[5])) * cast(u128, ((arg2[5]) * 0x2))); const x26 = (cast(u128, (arg1[5])) * cast(u128, ((arg2[4]) * 0x2))); const x27 = (cast(u128, (arg1[4])) * cast(u128, ((arg2[8]) * 0x2))); const x28 = (cast(u128, (arg1[4])) * cast(u128, ((arg2[7]) * 0x2))); const x29 = (cast(u128, (arg1[4])) * cast(u128, ((arg2[6]) * 0x2))); const x30 = (cast(u128, (arg1[4])) * cast(u128, ((arg2[5]) * 0x2))); const x31 = (cast(u128, (arg1[3])) * cast(u128, ((arg2[8]) * 0x2))); const x32 = (cast(u128, (arg1[3])) * cast(u128, ((arg2[7]) * 0x2))); const x33 = (cast(u128, (arg1[3])) * cast(u128, ((arg2[6]) * 0x2))); const x34 = (cast(u128, (arg1[2])) * cast(u128, ((arg2[8]) * 0x2))); const x35 = (cast(u128, (arg1[2])) * cast(u128, ((arg2[7]) * 0x2))); const x36 = (cast(u128, (arg1[1])) * cast(u128, ((arg2[8]) * 0x2))); const x37 = (cast(u128, (arg1[8])) * cast(u128, (arg2[0]))); const x38 = (cast(u128, (arg1[7])) * cast(u128, (arg2[1]))); const x39 = (cast(u128, (arg1[7])) * cast(u128, (arg2[0]))); const x40 = (cast(u128, (arg1[6])) * cast(u128, (arg2[2]))); const x41 = (cast(u128, (arg1[6])) * cast(u128, (arg2[1]))); const x42 = (cast(u128, (arg1[6])) * cast(u128, (arg2[0]))); const x43 = (cast(u128, (arg1[5])) * cast(u128, (arg2[3]))); const x44 = (cast(u128, (arg1[5])) * cast(u128, (arg2[2]))); const x45 = (cast(u128, (arg1[5])) * cast(u128, (arg2[1]))); const x46 = (cast(u128, (arg1[5])) * cast(u128, (arg2[0]))); const x47 = (cast(u128, (arg1[4])) * cast(u128, (arg2[4]))); const x48 = (cast(u128, (arg1[4])) * cast(u128, (arg2[3]))); const x49 = (cast(u128, (arg1[4])) * cast(u128, (arg2[2]))); const x50 = (cast(u128, (arg1[4])) * cast(u128, (arg2[1]))); const x51 = (cast(u128, (arg1[4])) * cast(u128, (arg2[0]))); const x52 = (cast(u128, (arg1[3])) * cast(u128, (arg2[5]))); const x53 = (cast(u128, (arg1[3])) * cast(u128, (arg2[4]))); const x54 = (cast(u128, (arg1[3])) * cast(u128, (arg2[3]))); const x55 = (cast(u128, (arg1[3])) * cast(u128, (arg2[2]))); const x56 = (cast(u128, (arg1[3])) * cast(u128, (arg2[1]))); const x57 = (cast(u128, (arg1[3])) * cast(u128, (arg2[0]))); const x58 = (cast(u128, (arg1[2])) * cast(u128, (arg2[6]))); const x59 = (cast(u128, (arg1[2])) * cast(u128, (arg2[5]))); const x60 = (cast(u128, (arg1[2])) * cast(u128, (arg2[4]))); const x61 = (cast(u128, (arg1[2])) * cast(u128, (arg2[3]))); const x62 = (cast(u128, (arg1[2])) * cast(u128, (arg2[2]))); const x63 = (cast(u128, (arg1[2])) * cast(u128, (arg2[1]))); const x64 = (cast(u128, (arg1[2])) * cast(u128, (arg2[0]))); const x65 = (cast(u128, (arg1[1])) * cast(u128, (arg2[7]))); const x66 = (cast(u128, (arg1[1])) * cast(u128, (arg2[6]))); const x67 = (cast(u128, (arg1[1])) * cast(u128, (arg2[5]))); const x68 = (cast(u128, (arg1[1])) * cast(u128, (arg2[4]))); const x69 = (cast(u128, (arg1[1])) * cast(u128, (arg2[3]))); const x70 = (cast(u128, (arg1[1])) * cast(u128, (arg2[2]))); const x71 = (cast(u128, (arg1[1])) * cast(u128, (arg2[1]))); const x72 = (cast(u128, (arg1[1])) * cast(u128, (arg2[0]))); const x73 = (cast(u128, (arg1[0])) * cast(u128, (arg2[8]))); const x74 = (cast(u128, (arg1[0])) * cast(u128, (arg2[7]))); const x75 = (cast(u128, (arg1[0])) * cast(u128, (arg2[6]))); const x76 = (cast(u128, (arg1[0])) * cast(u128, (arg2[5]))); const x77 = (cast(u128, (arg1[0])) * cast(u128, (arg2[4]))); const x78 = (cast(u128, (arg1[0])) * cast(u128, (arg2[3]))); const x79 = (cast(u128, (arg1[0])) * cast(u128, (arg2[2]))); const x80 = (cast(u128, (arg1[0])) * cast(u128, (arg2[1]))); const x81 = (cast(u128, (arg1[0])) * cast(u128, (arg2[0]))); const x82 = (x81 + (x36 + (x35 + (x33 + (x30 + (x26 + (x21 + (x15 + x8)))))))); const x83 = (x82 >> 58); const x84 = cast(u64, (x82 & cast(u128, 0x3ffffffffffffff))); const x85 = (x73 + (x65 + (x58 + (x52 + (x47 + (x43 + (x40 + (x38 + x37)))))))); const x86 = (x74 + (x66 + (x59 + (x53 + (x48 + (x44 + (x41 + (x39 + x1)))))))); const x87 = (x75 + (x67 + (x60 + (x54 + (x49 + (x45 + (x42 + (x9 + x2)))))))); const x88 = (x76 + (x68 + (x61 + (x55 + (x50 + (x46 + (x16 + (x10 + x3)))))))); const x89 = (x77 + (x69 + (x62 + (x56 + (x51 + (x22 + (x17 + (x11 + x4)))))))); const x90 = (x78 + (x70 + (x63 + (x57 + (x27 + (x23 + (x18 + (x12 + x5)))))))); const x91 = (x79 + (x71 + (x64 + (x31 + (x28 + (x24 + (x19 + (x13 + x6)))))))); const x92 = (x80 + (x72 + (x34 + (x32 + (x29 + (x25 + (x20 + (x14 + x7)))))))); const x93 = (x83 + x92); const x94 = (x93 >> 58); const x95 = cast(u64, (x93 & cast(u128, 0x3ffffffffffffff))); const x96 = (x94 + x91); const x97 = (x96 >> 58); const x98 = cast(u64, (x96 & cast(u128, 0x3ffffffffffffff))); const x99 = (x97 + x90); const x100 = (x99 >> 58); const x101 = cast(u64, (x99 & cast(u128, 0x3ffffffffffffff))); const x102 = (x100 + x89); const x103 = (x102 >> 58); const x104 = cast(u64, (x102 & cast(u128, 0x3ffffffffffffff))); const x105 = (x103 + x88); const x106 = (x105 >> 58); const x107 = cast(u64, (x105 & cast(u128, 0x3ffffffffffffff))); const x108 = (x106 + x87); const x109 = (x108 >> 58); const x110 = cast(u64, (x108 & cast(u128, 0x3ffffffffffffff))); const x111 = (x109 + x86); const x112 = (x111 >> 58); const x113 = cast(u64, (x111 & cast(u128, 0x3ffffffffffffff))); const x114 = (x112 + x85); const x115 = (x114 >> 57); const x116 = cast(u64, (x114 & cast(u128, 0x1ffffffffffffff))); const x117 = (cast(u128, x84) + x115); const x118 = cast(u64, (x117 >> 58)); const x119 = cast(u64, (x117 & cast(u128, 0x3ffffffffffffff))); const x120 = (x118 + x95); const x121 = cast(u1, (x120 >> 58)); const x122 = (x120 & 0x3ffffffffffffff); const x123 = (cast(u64, x121) + x98); out1[0] = x119; out1[1] = x122; out1[2] = x123; out1[3] = x101; out1[4] = x104; out1[5] = x107; out1[6] = x110; out1[7] = x113; out1[8] = x116; } /// The function carrySquare squares a field element and reduces the result. /// /// Postconditions: /// eval out1 mod m = (eval arg1 * eval arg1) mod m /// pub fn carrySquare(out1: *TightFieldElement, arg1: LooseFieldElement) void { @setRuntimeSafety(mode == .Debug); const x1 = (arg1[8]); const x2 = (x1 * 0x2); const x3 = ((arg1[8]) * 0x2); const x4 = (arg1[7]); const x5 = (x4 * 0x2); const x6 = ((arg1[7]) * 0x2); const x7 = (arg1[6]); const x8 = (x7 * 0x2); const x9 = ((arg1[6]) * 0x2); const x10 = (arg1[5]); const x11 = (x10 * 0x2); const x12 = ((arg1[5]) * 0x2); const x13 = ((arg1[4]) * 0x2); const x14 = ((arg1[3]) * 0x2); const x15 = ((arg1[2]) * 0x2); const x16 = ((arg1[1]) * 0x2); const x17 = (cast(u128, (arg1[8])) * cast(u128, (x1 * 0x2))); const x18 = (cast(u128, (arg1[7])) * cast(u128, (x2 * 0x2))); const x19 = (cast(u128, (arg1[7])) * cast(u128, (x4 * 0x2))); const x20 = (cast(u128, (arg1[6])) * cast(u128, (x2 * 0x2))); const x21 = (cast(u128, (arg1[6])) * cast(u128, (x5 * 0x2))); const x22 = (cast(u128, (arg1[6])) * cast(u128, (x7 * 0x2))); const x23 = (cast(u128, (arg1[5])) * cast(u128, (x2 * 0x2))); const x24 = (cast(u128, (arg1[5])) * cast(u128, (x5 * 0x2))); const x25 = (cast(u128, (arg1[5])) * cast(u128, (x8 * 0x2))); const x26 = (cast(u128, (arg1[5])) * cast(u128, (x10 * 0x2))); const x27 = (cast(u128, (arg1[4])) * cast(u128, (x2 * 0x2))); const x28 = (cast(u128, (arg1[4])) * cast(u128, (x5 * 0x2))); const x29 = (cast(u128, (arg1[4])) * cast(u128, (x8 * 0x2))); const x30 = (cast(u128, (arg1[4])) * cast(u128, (x11 * 0x2))); const x31 = (cast(u128, (arg1[4])) * cast(u128, (arg1[4]))); const x32 = (cast(u128, (arg1[3])) * cast(u128, (x2 * 0x2))); const x33 = (cast(u128, (arg1[3])) * cast(u128, (x5 * 0x2))); const x34 = (cast(u128, (arg1[3])) * cast(u128, (x8 * 0x2))); const x35 = (cast(u128, (arg1[3])) * cast(u128, x12)); const x36 = (cast(u128, (arg1[3])) * cast(u128, x13)); const x37 = (cast(u128, (arg1[3])) * cast(u128, (arg1[3]))); const x38 = (cast(u128, (arg1[2])) * cast(u128, (x2 * 0x2))); const x39 = (cast(u128, (arg1[2])) * cast(u128, (x5 * 0x2))); const x40 = (cast(u128, (arg1[2])) * cast(u128, x9)); const x41 = (cast(u128, (arg1[2])) * cast(u128, x12)); const x42 = (cast(u128, (arg1[2])) * cast(u128, x13)); const x43 = (cast(u128, (arg1[2])) * cast(u128, x14)); const x44 = (cast(u128, (arg1[2])) * cast(u128, (arg1[2]))); const x45 = (cast(u128, (arg1[1])) * cast(u128, (x2 * 0x2))); const x46 = (cast(u128, (arg1[1])) * cast(u128, x6)); const x47 = (cast(u128, (arg1[1])) * cast(u128, x9)); const x48 = (cast(u128, (arg1[1])) * cast(u128, x12)); const x49 = (cast(u128, (arg1[1])) * cast(u128, x13)); const x50 = (cast(u128, (arg1[1])) * cast(u128, x14)); const x51 = (cast(u128, (arg1[1])) * cast(u128, x15)); const x52 = (cast(u128, (arg1[1])) * cast(u128, (arg1[1]))); const x53 = (cast(u128, (arg1[0])) * cast(u128, x3)); const x54 = (cast(u128, (arg1[0])) * cast(u128, x6)); const x55 = (cast(u128, (arg1[0])) * cast(u128, x9)); const x56 = (cast(u128, (arg1[0])) * cast(u128, x12)); const x57 = (cast(u128, (arg1[0])) * cast(u128, x13)); const x58 = (cast(u128, (arg1[0])) * cast(u128, x14)); const x59 = (cast(u128, (arg1[0])) * cast(u128, x15)); const x60 = (cast(u128, (arg1[0])) * cast(u128, x16)); const x61 = (cast(u128, (arg1[0])) * cast(u128, (arg1[0]))); const x62 = (x61 + (x45 + (x39 + (x34 + x30)))); const x63 = (x62 >> 58); const x64 = cast(u64, (x62 & cast(u128, 0x3ffffffffffffff))); const x65 = (x53 + (x46 + (x40 + (x35 + x31)))); const x66 = (x54 + (x47 + (x41 + (x36 + x17)))); const x67 = (x55 + (x48 + (x42 + (x37 + x18)))); const x68 = (x56 + (x49 + (x43 + (x20 + x19)))); const x69 = (x57 + (x50 + (x44 + (x23 + x21)))); const x70 = (x58 + (x51 + (x27 + (x24 + x22)))); const x71 = (x59 + (x52 + (x32 + (x28 + x25)))); const x72 = (x60 + (x38 + (x33 + (x29 + x26)))); const x73 = (x63 + x72); const x74 = (x73 >> 58); const x75 = cast(u64, (x73 & cast(u128, 0x3ffffffffffffff))); const x76 = (x74 + x71); const x77 = (x76 >> 58); const x78 = cast(u64, (x76 & cast(u128, 0x3ffffffffffffff))); const x79 = (x77 + x70); const x80 = (x79 >> 58); const x81 = cast(u64, (x79 & cast(u128, 0x3ffffffffffffff))); const x82 = (x80 + x69); const x83 = (x82 >> 58); const x84 = cast(u64, (x82 & cast(u128, 0x3ffffffffffffff))); const x85 = (x83 + x68); const x86 = (x85 >> 58); const x87 = cast(u64, (x85 & cast(u128, 0x3ffffffffffffff))); const x88 = (x86 + x67); const x89 = (x88 >> 58); const x90 = cast(u64, (x88 & cast(u128, 0x3ffffffffffffff))); const x91 = (x89 + x66); const x92 = (x91 >> 58); const x93 = cast(u64, (x91 & cast(u128, 0x3ffffffffffffff))); const x94 = (x92 + x65); const x95 = (x94 >> 57); const x96 = cast(u64, (x94 & cast(u128, 0x1ffffffffffffff))); const x97 = (cast(u128, x64) + x95); const x98 = cast(u64, (x97 >> 58)); const x99 = cast(u64, (x97 & cast(u128, 0x3ffffffffffffff))); const x100 = (x98 + x75); const x101 = cast(u1, (x100 >> 58)); const x102 = (x100 & 0x3ffffffffffffff); const x103 = (cast(u64, x101) + x78); out1[0] = x99; out1[1] = x102; out1[2] = x103; out1[3] = x81; out1[4] = x84; out1[5] = x87; out1[6] = x90; out1[7] = x93; out1[8] = x96; } /// The function carry reduces a field element. /// /// Postconditions: /// eval out1 mod m = eval arg1 mod m /// pub fn carry(out1: *TightFieldElement, arg1: LooseFieldElement) void { @setRuntimeSafety(mode == .Debug); const x1 = (arg1[0]); const x2 = ((x1 >> 58) + (arg1[1])); const x3 = ((x2 >> 58) + (arg1[2])); const x4 = ((x3 >> 58) + (arg1[3])); const x5 = ((x4 >> 58) + (arg1[4])); const x6 = ((x5 >> 58) + (arg1[5])); const x7 = ((x6 >> 58) + (arg1[6])); const x8 = ((x7 >> 58) + (arg1[7])); const x9 = ((x8 >> 58) + (arg1[8])); const x10 = ((x1 & 0x3ffffffffffffff) + (x9 >> 57)); const x11 = (cast(u64, cast(u1, (x10 >> 58))) + (x2 & 0x3ffffffffffffff)); const x12 = (x10 & 0x3ffffffffffffff); const x13 = (x11 & 0x3ffffffffffffff); const x14 = (cast(u64, cast(u1, (x11 >> 58))) + (x3 & 0x3ffffffffffffff)); const x15 = (x4 & 0x3ffffffffffffff); const x16 = (x5 & 0x3ffffffffffffff); const x17 = (x6 & 0x3ffffffffffffff); const x18 = (x7 & 0x3ffffffffffffff); const x19 = (x8 & 0x3ffffffffffffff); const x20 = (x9 & 0x1ffffffffffffff); out1[0] = x12; out1[1] = x13; out1[2] = x14; out1[3] = x15; out1[4] = x16; out1[5] = x17; out1[6] = x18; out1[7] = x19; out1[8] = x20; } /// The function add adds two field elements. /// /// Postconditions: /// eval out1 mod m = (eval arg1 + eval arg2) mod m /// pub fn add(out1: *LooseFieldElement, arg1: TightFieldElement, arg2: TightFieldElement) void { @setRuntimeSafety(mode == .Debug); const x1 = ((arg1[0]) + (arg2[0])); const x2 = ((arg1[1]) + (arg2[1])); const x3 = ((arg1[2]) + (arg2[2])); const x4 = ((arg1[3]) + (arg2[3])); const x5 = ((arg1[4]) + (arg2[4])); const x6 = ((arg1[5]) + (arg2[5])); const x7 = ((arg1[6]) + (arg2[6])); const x8 = ((arg1[7]) + (arg2[7])); const x9 = ((arg1[8]) + (arg2[8])); out1[0] = x1; out1[1] = x2; out1[2] = x3; out1[3] = x4; out1[4] = x5; out1[5] = x6; out1[6] = x7; out1[7] = x8; out1[8] = x9; } /// The function sub subtracts two field elements. /// /// Postconditions: /// eval out1 mod m = (eval arg1 - eval arg2) mod m /// pub fn sub(out1: *LooseFieldElement, arg1: TightFieldElement, arg2: TightFieldElement) void { @setRuntimeSafety(mode == .Debug); const x1 = ((0x7fffffffffffffe + (arg1[0])) - (arg2[0])); const x2 = ((0x7fffffffffffffe + (arg1[1])) - (arg2[1])); const x3 = ((0x7fffffffffffffe + (arg1[2])) - (arg2[2])); const x4 = ((0x7fffffffffffffe + (arg1[3])) - (arg2[3])); const x5 = ((0x7fffffffffffffe + (arg1[4])) - (arg2[4])); const x6 = ((0x7fffffffffffffe + (arg1[5])) - (arg2[5])); const x7 = ((0x7fffffffffffffe + (arg1[6])) - (arg2[6])); const x8 = ((0x7fffffffffffffe + (arg1[7])) - (arg2[7])); const x9 = ((0x3fffffffffffffe + (arg1[8])) - (arg2[8])); out1[0] = x1; out1[1] = x2; out1[2] = x3; out1[3] = x4; out1[4] = x5; out1[5] = x6; out1[6] = x7; out1[7] = x8; out1[8] = x9; } /// The function opp negates a field element. /// /// Postconditions: /// eval out1 mod m = -eval arg1 mod m /// pub fn opp(out1: *LooseFieldElement, arg1: TightFieldElement) void { @setRuntimeSafety(mode == .Debug); const x1 = (0x7fffffffffffffe - (arg1[0])); const x2 = (0x7fffffffffffffe - (arg1[1])); const x3 = (0x7fffffffffffffe - (arg1[2])); const x4 = (0x7fffffffffffffe - (arg1[3])); const x5 = (0x7fffffffffffffe - (arg1[4])); const x6 = (0x7fffffffffffffe - (arg1[5])); const x7 = (0x7fffffffffffffe - (arg1[6])); const x8 = (0x7fffffffffffffe - (arg1[7])); const x9 = (0x3fffffffffffffe - (arg1[8])); out1[0] = x1; out1[1] = x2; out1[2] = x3; out1[3] = x4; out1[4] = x5; out1[5] = x6; out1[6] = x7; out1[7] = x8; out1[8] = x9; } /// The function selectznz is a multi-limb conditional select. /// /// Postconditions: /// out1 = (if arg1 = 0 then arg2 else arg3) /// /// Input Bounds: /// arg1: [0x0 ~> 0x1] /// arg2: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]] /// arg3: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]] /// Output Bounds: /// out1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]] pub fn selectznz(out1: *[9]u64, arg1: u1, arg2: [9]u64, arg3: [9]u64) void { @setRuntimeSafety(mode == .Debug); var x1: u64 = undefined; cmovznzU64(&x1, arg1, (arg2[0]), (arg3[0])); var x2: u64 = undefined; cmovznzU64(&x2, arg1, (arg2[1]), (arg3[1])); var x3: u64 = undefined; cmovznzU64(&x3, arg1, (arg2[2]), (arg3[2])); var x4: u64 = undefined; cmovznzU64(&x4, arg1, (arg2[3]), (arg3[3])); var x5: u64 = undefined; cmovznzU64(&x5, arg1, (arg2[4]), (arg3[4])); var x6: u64 = undefined; cmovznzU64(&x6, arg1, (arg2[5]), (arg3[5])); var x7: u64 = undefined; cmovznzU64(&x7, arg1, (arg2[6]), (arg3[6])); var x8: u64 = undefined; cmovznzU64(&x8, arg1, (arg2[7]), (arg3[7])); var x9: u64 = undefined; cmovznzU64(&x9, arg1, (arg2[8]), (arg3[8])); out1[0] = x1; out1[1] = x2; out1[2] = x3; out1[3] = x4; out1[4] = x5; out1[5] = x6; out1[6] = x7; out1[7] = x8; out1[8] = x9; } /// The function toBytes serializes a field element to bytes in little-endian order. /// /// Postconditions: /// out1 = map (λ x, ⌊((eval arg1 mod m) mod 2^(8 * (x + 1))) / 2^(8 * x)⌋) [0..65] /// /// Output Bounds: /// 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 ~> 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 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0x1]] pub fn toBytes(out1: *[66]u8, arg1: TightFieldElement) void { @setRuntimeSafety(mode == .Debug); var x1: u64 = undefined; var x2: u1 = undefined; subborrowxU58(&x1, &x2, 0x0, (arg1[0]), 0x3ffffffffffffff); var x3: u64 = undefined; var x4: u1 = undefined; subborrowxU58(&x3, &x4, x2, (arg1[1]), 0x3ffffffffffffff); var x5: u64 = undefined; var x6: u1 = undefined; subborrowxU58(&x5, &x6, x4, (arg1[2]), 0x3ffffffffffffff); var x7: u64 = undefined; var x8: u1 = undefined; subborrowxU58(&x7, &x8, x6, (arg1[3]), 0x3ffffffffffffff); var x9: u64 = undefined; var x10: u1 = undefined; subborrowxU58(&x9, &x10, x8, (arg1[4]), 0x3ffffffffffffff); var x11: u64 = undefined; var x12: u1 = undefined; subborrowxU58(&x11, &x12, x10, (arg1[5]), 0x3ffffffffffffff); var x13: u64 = undefined; var x14: u1 = undefined; subborrowxU58(&x13, &x14, x12, (arg1[6]), 0x3ffffffffffffff); var x15: u64 = undefined; var x16: u1 = undefined; subborrowxU58(&x15, &x16, x14, (arg1[7]), 0x3ffffffffffffff); var x17: u64 = undefined; var x18: u1 = undefined; subborrowxU57(&x17, &x18, x16, (arg1[8]), 0x1ffffffffffffff); var x19: u64 = undefined; cmovznzU64(&x19, x18, cast(u64, 0x0), 0xffffffffffffffff); var x20: u64 = undefined; var x21: u1 = undefined; addcarryxU58(&x20, &x21, 0x0, x1, (x19 & 0x3ffffffffffffff)); var x22: u64 = undefined; var x23: u1 = undefined; addcarryxU58(&x22, &x23, x21, x3, (x19 & 0x3ffffffffffffff)); var x24: u64 = undefined; var x25: u1 = undefined; addcarryxU58(&x24, &x25, x23, x5, (x19 & 0x3ffffffffffffff)); var x26: u64 = undefined; var x27: u1 = undefined; addcarryxU58(&x26, &x27, x25, x7, (x19 & 0x3ffffffffffffff)); var x28: u64 = undefined; var x29: u1 = undefined; addcarryxU58(&x28, &x29, x27, x9, (x19 & 0x3ffffffffffffff)); var x30: u64 = undefined; var x31: u1 = undefined; addcarryxU58(&x30, &x31, x29, x11, (x19 & 0x3ffffffffffffff)); var x32: u64 = undefined; var x33: u1 = undefined; addcarryxU58(&x32, &x33, x31, x13, (x19 & 0x3ffffffffffffff)); var x34: u64 = undefined; var x35: u1 = undefined; addcarryxU58(&x34, &x35, x33, x15, (x19 & 0x3ffffffffffffff)); var x36: u64 = undefined; var x37: u1 = undefined; addcarryxU57(&x36, &x37, x35, x17, (x19 & 0x1ffffffffffffff)); const x38 = (x34 << 6); const x39 = (x32 << 4); const x40 = (x30 << 2); const x41 = (x26 << 6); const x42 = (x24 << 4); const x43 = (x22 << 2); const x44 = cast(u8, (x20 & cast(u64, 0xff))); const x45 = (x20 >> 8); const x46 = cast(u8, (x45 & cast(u64, 0xff))); const x47 = (x45 >> 8); const x48 = cast(u8, (x47 & cast(u64, 0xff))); const x49 = (x47 >> 8); const x50 = cast(u8, (x49 & cast(u64, 0xff))); const x51 = (x49 >> 8); const x52 = cast(u8, (x51 & cast(u64, 0xff))); const x53 = (x51 >> 8); const x54 = cast(u8, (x53 & cast(u64, 0xff))); const x55 = (x53 >> 8); const x56 = cast(u8, (x55 & cast(u64, 0xff))); const x57 = cast(u8, (x55 >> 8)); const x58 = (x43 + cast(u64, x57)); const x59 = cast(u8, (x58 & cast(u64, 0xff))); const x60 = (x58 >> 8); const x61 = cast(u8, (x60 & cast(u64, 0xff))); const x62 = (x60 >> 8); const x63 = cast(u8, (x62 & cast(u64, 0xff))); const x64 = (x62 >> 8); const x65 = cast(u8, (x64 & cast(u64, 0xff))); const x66 = (x64 >> 8); const x67 = cast(u8, (x66 & cast(u64, 0xff))); const x68 = (x66 >> 8); const x69 = cast(u8, (x68 & cast(u64, 0xff))); const x70 = (x68 >> 8); const x71 = cast(u8, (x70 & cast(u64, 0xff))); const x72 = cast(u8, (x70 >> 8)); const x73 = (x42 + cast(u64, x72)); const x74 = cast(u8, (x73 & cast(u64, 0xff))); const x75 = (x73 >> 8); const x76 = cast(u8, (x75 & cast(u64, 0xff))); const x77 = (x75 >> 8); const x78 = cast(u8, (x77 & cast(u64, 0xff))); const x79 = (x77 >> 8); const x80 = cast(u8, (x79 & cast(u64, 0xff))); const x81 = (x79 >> 8); const x82 = cast(u8, (x81 & cast(u64, 0xff))); const x83 = (x81 >> 8); const x84 = cast(u8, (x83 & cast(u64, 0xff))); const x85 = (x83 >> 8); const x86 = cast(u8, (x85 & cast(u64, 0xff))); const x87 = cast(u8, (x85 >> 8)); const x88 = (x41 + cast(u64, x87)); const x89 = cast(u8, (x88 & cast(u64, 0xff))); const x90 = (x88 >> 8); const x91 = cast(u8, (x90 & cast(u64, 0xff))); const x92 = (x90 >> 8); const x93 = cast(u8, (x92 & cast(u64, 0xff))); const x94 = (x92 >> 8); const x95 = cast(u8, (x94 & cast(u64, 0xff))); const x96 = (x94 >> 8); const x97 = cast(u8, (x96 & cast(u64, 0xff))); const x98 = (x96 >> 8); const x99 = cast(u8, (x98 & cast(u64, 0xff))); const x100 = (x98 >> 8); const x101 = cast(u8, (x100 & cast(u64, 0xff))); const x102 = cast(u8, (x100 >> 8)); const x103 = cast(u8, (x28 & cast(u64, 0xff))); const x104 = (x28 >> 8); const x105 = cast(u8, (x104 & cast(u64, 0xff))); const x106 = (x104 >> 8); const x107 = cast(u8, (x106 & cast(u64, 0xff))); const x108 = (x106 >> 8); const x109 = cast(u8, (x108 & cast(u64, 0xff))); const x110 = (x108 >> 8); const x111 = cast(u8, (x110 & cast(u64, 0xff))); const x112 = (x110 >> 8); const x113 = cast(u8, (x112 & cast(u64, 0xff))); const x114 = (x112 >> 8); const x115 = cast(u8, (x114 & cast(u64, 0xff))); const x116 = cast(u8, (x114 >> 8)); const x117 = (x40 + cast(u64, x116)); const x118 = cast(u8, (x117 & cast(u64, 0xff))); const x119 = (x117 >> 8); const x120 = cast(u8, (x119 & cast(u64, 0xff))); const x121 = (x119 >> 8); const x122 = cast(u8, (x121 & cast(u64, 0xff))); const x123 = (x121 >> 8); const x124 = cast(u8, (x123 & cast(u64, 0xff))); const x125 = (x123 >> 8); const x126 = cast(u8, (x125 & cast(u64, 0xff))); const x127 = (x125 >> 8); const x128 = cast(u8, (x127 & cast(u64, 0xff))); const x129 = (x127 >> 8); const x130 = cast(u8, (x129 & cast(u64, 0xff))); const x131 = cast(u8, (x129 >> 8)); const x132 = (x39 + cast(u64, x131)); const x133 = cast(u8, (x132 & cast(u64, 0xff))); const x134 = (x132 >> 8); const x135 = cast(u8, (x134 & cast(u64, 0xff))); const x136 = (x134 >> 8); const x137 = cast(u8, (x136 & cast(u64, 0xff))); const x138 = (x136 >> 8); const x139 = cast(u8, (x138 & cast(u64, 0xff))); const x140 = (x138 >> 8); const x141 = cast(u8, (x140 & cast(u64, 0xff))); const x142 = (x140 >> 8); const x143 = cast(u8, (x142 & cast(u64, 0xff))); const x144 = (x142 >> 8); const x145 = cast(u8, (x144 & cast(u64, 0xff))); const x146 = cast(u8, (x144 >> 8)); const x147 = (x38 + cast(u64, x146)); const x148 = cast(u8, (x147 & cast(u64, 0xff))); const x149 = (x147 >> 8); const x150 = cast(u8, (x149 & cast(u64, 0xff))); const x151 = (x149 >> 8); const x152 = cast(u8, (x151 & cast(u64, 0xff))); const x153 = (x151 >> 8); const x154 = cast(u8, (x153 & cast(u64, 0xff))); const x155 = (x153 >> 8); const x156 = cast(u8, (x155 & cast(u64, 0xff))); const x157 = (x155 >> 8); const x158 = cast(u8, (x157 & cast(u64, 0xff))); const x159 = (x157 >> 8); const x160 = cast(u8, (x159 & cast(u64, 0xff))); const x161 = cast(u8, (x159 >> 8)); const x162 = cast(u8, (x36 & cast(u64, 0xff))); const x163 = (x36 >> 8); const x164 = cast(u8, (x163 & cast(u64, 0xff))); const x165 = (x163 >> 8); const x166 = cast(u8, (x165 & cast(u64, 0xff))); const x167 = (x165 >> 8); const x168 = cast(u8, (x167 & cast(u64, 0xff))); const x169 = (x167 >> 8); const x170 = cast(u8, (x169 & cast(u64, 0xff))); const x171 = (x169 >> 8); const x172 = cast(u8, (x171 & cast(u64, 0xff))); const x173 = (x171 >> 8); const x174 = cast(u8, (x173 & cast(u64, 0xff))); const x175 = cast(u1, (x173 >> 8)); out1[0] = x44; out1[1] = x46; out1[2] = x48; out1[3] = x50; out1[4] = x52; out1[5] = x54; out1[6] = x56; out1[7] = x59; out1[8] = x61; out1[9] = x63; out1[10] = x65; out1[11] = x67; out1[12] = x69; out1[13] = x71; out1[14] = x74; out1[15] = x76; out1[16] = x78; out1[17] = x80; out1[18] = x82; out1[19] = x84; out1[20] = x86; out1[21] = x89; out1[22] = x91; out1[23] = x93; out1[24] = x95; out1[25] = x97; out1[26] = x99; out1[27] = x101; out1[28] = x102; out1[29] = x103; out1[30] = x105; out1[31] = x107; out1[32] = x109; out1[33] = x111; out1[34] = x113; out1[35] = x115; out1[36] = x118; out1[37] = x120; out1[38] = x122; out1[39] = x124; out1[40] = x126; out1[41] = x128; out1[42] = x130; out1[43] = x133; out1[44] = x135; out1[45] = x137; out1[46] = x139; out1[47] = x141; out1[48] = x143; out1[49] = x145; out1[50] = x148; out1[51] = x150; out1[52] = x152; out1[53] = x154; out1[54] = x156; out1[55] = x158; out1[56] = x160; out1[57] = x161; out1[58] = x162; out1[59] = x164; out1[60] = x166; out1[61] = x168; out1[62] = x170; out1[63] = x172; out1[64] = x174; out1[65] = cast(u8, x175); } /// The function fromBytes deserializes a field element from bytes in little-endian order. /// /// Postconditions: /// eval out1 mod m = bytes_eval arg1 mod m /// /// Input Bounds: /// 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 ~> 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 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0x1]] pub fn fromBytes(out1: *TightFieldElement, arg1: [66]u8) void { @setRuntimeSafety(mode == .Debug); const x1 = (cast(u64, cast(u1, (arg1[65]))) << 56); const x2 = (cast(u64, (arg1[64])) << 48); const x3 = (cast(u64, (arg1[63])) << 40); const x4 = (cast(u64, (arg1[62])) << 32); const x5 = (cast(u64, (arg1[61])) << 24); const x6 = (cast(u64, (arg1[60])) << 16); const x7 = (cast(u64, (arg1[59])) << 8); const x8 = (arg1[58]); const x9 = (cast(u64, (arg1[57])) << 50); const x10 = (cast(u64, (arg1[56])) << 42); const x11 = (cast(u64, (arg1[55])) << 34); const x12 = (cast(u64, (arg1[54])) << 26); const x13 = (cast(u64, (arg1[53])) << 18); const x14 = (cast(u64, (arg1[52])) << 10); const x15 = (cast(u64, (arg1[51])) << 2); const x16 = (cast(u64, (arg1[50])) << 52); const x17 = (cast(u64, (arg1[49])) << 44); const x18 = (cast(u64, (arg1[48])) << 36); const x19 = (cast(u64, (arg1[47])) << 28); const x20 = (cast(u64, (arg1[46])) << 20); const x21 = (cast(u64, (arg1[45])) << 12); const x22 = (cast(u64, (arg1[44])) << 4); const x23 = (cast(u64, (arg1[43])) << 54); const x24 = (cast(u64, (arg1[42])) << 46); const x25 = (cast(u64, (arg1[41])) << 38); const x26 = (cast(u64, (arg1[40])) << 30); const x27 = (cast(u64, (arg1[39])) << 22); const x28 = (cast(u64, (arg1[38])) << 14); const x29 = (cast(u64, (arg1[37])) << 6); const x30 = (cast(u64, (arg1[36])) << 56); const x31 = (cast(u64, (arg1[35])) << 48); const x32 = (cast(u64, (arg1[34])) << 40); const x33 = (cast(u64, (arg1[33])) << 32); const x34 = (cast(u64, (arg1[32])) << 24); const x35 = (cast(u64, (arg1[31])) << 16); const x36 = (cast(u64, (arg1[30])) << 8); const x37 = (arg1[29]); const x38 = (cast(u64, (arg1[28])) << 50); const x39 = (cast(u64, (arg1[27])) << 42); const x40 = (cast(u64, (arg1[26])) << 34); const x41 = (cast(u64, (arg1[25])) << 26); const x42 = (cast(u64, (arg1[24])) << 18); const x43 = (cast(u64, (arg1[23])) << 10); const x44 = (cast(u64, (arg1[22])) << 2); const x45 = (cast(u64, (arg1[21])) << 52); const x46 = (cast(u64, (arg1[20])) << 44); const x47 = (cast(u64, (arg1[19])) << 36); const x48 = (cast(u64, (arg1[18])) << 28); const x49 = (cast(u64, (arg1[17])) << 20); const x50 = (cast(u64, (arg1[16])) << 12); const x51 = (cast(u64, (arg1[15])) << 4); const x52 = (cast(u64, (arg1[14])) << 54); const x53 = (cast(u64, (arg1[13])) << 46); const x54 = (cast(u64, (arg1[12])) << 38); const x55 = (cast(u64, (arg1[11])) << 30); const x56 = (cast(u64, (arg1[10])) << 22); const x57 = (cast(u64, (arg1[9])) << 14); const x58 = (cast(u64, (arg1[8])) << 6); const x59 = (cast(u64, (arg1[7])) << 56); const x60 = (cast(u64, (arg1[6])) << 48); const x61 = (cast(u64, (arg1[5])) << 40); const x62 = (cast(u64, (arg1[4])) << 32); const x63 = (cast(u64, (arg1[3])) << 24); const x64 = (cast(u64, (arg1[2])) << 16); const x65 = (cast(u64, (arg1[1])) << 8); const x66 = (arg1[0]); const x67 = (x65 + cast(u64, x66)); const x68 = (x64 + x67); const x69 = (x63 + x68); const x70 = (x62 + x69); const x71 = (x61 + x70); const x72 = (x60 + x71); const x73 = (x59 + x72); const x74 = (x73 & 0x3ffffffffffffff); const x75 = cast(u8, (x73 >> 58)); const x76 = (x58 + cast(u64, x75)); const x77 = (x57 + x76); const x78 = (x56 + x77); const x79 = (x55 + x78); const x80 = (x54 + x79); const x81 = (x53 + x80); const x82 = (x52 + x81); const x83 = (x82 & 0x3ffffffffffffff); const x84 = cast(u8, (x82 >> 58)); const x85 = (x51 + cast(u64, x84)); const x86 = (x50 + x85); const x87 = (x49 + x86); const x88 = (x48 + x87); const x89 = (x47 + x88); const x90 = (x46 + x89); const x91 = (x45 + x90); const x92 = (x91 & 0x3ffffffffffffff); const x93 = cast(u8, (x91 >> 58)); const x94 = (x44 + cast(u64, x93)); const x95 = (x43 + x94); const x96 = (x42 + x95); const x97 = (x41 + x96); const x98 = (x40 + x97); const x99 = (x39 + x98); const x100 = (x38 + x99); const x101 = (x36 + cast(u64, x37)); const x102 = (x35 + x101); const x103 = (x34 + x102); const x104 = (x33 + x103); const x105 = (x32 + x104); const x106 = (x31 + x105); const x107 = (x30 + x106); const x108 = (x107 & 0x3ffffffffffffff); const x109 = cast(u8, (x107 >> 58)); const x110 = (x29 + cast(u64, x109)); const x111 = (x28 + x110); const x112 = (x27 + x111); const x113 = (x26 + x112); const x114 = (x25 + x113); const x115 = (x24 + x114); const x116 = (x23 + x115); const x117 = (x116 & 0x3ffffffffffffff); const x118 = cast(u8, (x116 >> 58)); const x119 = (x22 + cast(u64, x118)); const x120 = (x21 + x119); const x121 = (x20 + x120); const x122 = (x19 + x121); const x123 = (x18 + x122); const x124 = (x17 + x123); const x125 = (x16 + x124); const x126 = (x125 & 0x3ffffffffffffff); const x127 = cast(u8, (x125 >> 58)); const x128 = (x15 + cast(u64, x127)); const x129 = (x14 + x128); const x130 = (x13 + x129); const x131 = (x12 + x130); const x132 = (x11 + x131); const x133 = (x10 + x132); const x134 = (x9 + x133); const x135 = (x7 + cast(u64, x8)); const x136 = (x6 + x135); const x137 = (x5 + x136); const x138 = (x4 + x137); const x139 = (x3 + x138); const x140 = (x2 + x139); const x141 = (x1 + x140); out1[0] = x74; out1[1] = x83; out1[2] = x92; out1[3] = x100; out1[4] = x108; out1[5] = x117; out1[6] = x126; out1[7] = x134; out1[8] = x141; } /// The function relax is the identity function converting from tight field elements to loose field elements. /// /// Postconditions: /// out1 = arg1 /// pub fn relax(out1: *LooseFieldElement, arg1: TightFieldElement) void { @setRuntimeSafety(mode == .Debug); const x1 = (arg1[0]); const x2 = (arg1[1]); const x3 = (arg1[2]); const x4 = (arg1[3]); const x5 = (arg1[4]); const x6 = (arg1[5]); const x7 = (arg1[6]); const x8 = (arg1[7]); const x9 = (arg1[8]); out1[0] = x1; out1[1] = x2; out1[2] = x3; out1[3] = x4; out1[4] = x5; out1[5] = x6; out1[6] = x7; out1[7] = x8; out1[8] = x9; }