fiatScalarToBytes function
fiatScalarToBytes serializes a field element NOT in the Montgomery domain to bytes in little-endian order.
Preconditions:
0 ≤ eval arg1 < m
Postconditions:
out1 = map (λ x, ⌊((eval arg1 mod m) mod 2^(8 * (x + 1))) / 2^(8 * x)⌋) 0..31
Input Bounds:
arg1: [0x0 ~> 0xffffffffffffffff
, 0x0 ~> 0xffffffffffffffff
, 0x0 ~> 0xffffffffffffffff
, 0x0 ~> 0x1fffffffffffffff
]
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 ~> 0x1f
]
Implementation
void fiatScalarToBytes(List<int> out1, List<BigInt> arg1) {
final x1 = arg1[3];
final x2 = arg1[2];
final x3 = arg1[1];
final x4 = arg1[0];
final x5 = (x4.toUnsigned(8).toInt());
final x6 = (x4 >> 8);
final x7 = (x6.toUnsigned(8).toInt());
final x8 = (x6 >> 8);
final x9 = (x8.toUnsigned(8).toInt());
final x10 = (x8 >> 8);
final x11 = (x10.toUnsigned(8).toInt());
final x12 = (x10 >> 8);
final x13 = (x12.toUnsigned(8).toInt());
final x14 = (x12 >> 8);
final x15 = (x14.toUnsigned(8).toInt());
final x16 = (x14 >> 8);
final x17 = (x16.toUnsigned(8).toInt());
final x18 = (x16 >> 8).toInt();
final x19 = (x3.toUnsigned(8).toInt());
final x20 = (x3 >> 8);
final x21 = (x20.toUnsigned(8).toInt());
final x22 = (x20 >> 8);
final x23 = (x22.toUnsigned(8).toInt());
final x24 = (x22 >> 8);
final x25 = (x24.toUnsigned(8).toInt());
final x26 = (x24 >> 8);
final x27 = (x26.toUnsigned(8).toInt());
final x28 = (x26 >> 8);
final x29 = (x28.toUnsigned(8).toInt());
final x30 = (x28 >> 8);
final x31 = (x30.toUnsigned(8).toInt());
final x32 = (x30 >> 8).toInt();
final x33 = (x2.toUnsigned(8).toInt());
final x34 = (x2 >> 8);
final x35 = (x34.toUnsigned(8).toInt());
final x36 = (x34 >> 8);
final x37 = (x36.toUnsigned(8).toInt());
final x38 = (x36 >> 8);
final x39 = (x38.toUnsigned(8).toInt());
final x40 = (x38 >> 8);
final x41 = (x40.toUnsigned(8).toInt());
final x42 = (x40 >> 8);
final x43 = (x42.toUnsigned(8).toInt());
final x44 = (x42 >> 8);
final x45 = (x44.toUnsigned(8).toInt());
final x46 = (x44 >> 8).toInt();
final x47 = (x1.toUnsigned(8).toInt());
final x48 = (x1 >> 8);
final x49 = (x48.toUnsigned(8).toInt());
final x50 = (x48 >> 8);
final x51 = (x50.toUnsigned(8).toInt());
final x52 = (x50 >> 8);
final x53 = (x52.toUnsigned(8).toInt());
final x54 = (x52 >> 8);
final x55 = (x54.toUnsigned(8).toInt());
final x56 = (x54 >> 8);
final x57 = (x56.toUnsigned(8).toInt());
final x58 = (x56 >> 8);
final x59 = (x58.toUnsigned(8).toInt());
final x60 = (x58 >> 8).toInt();
out1[0] = x5;
out1[1] = x7;
out1[2] = x9;
out1[3] = x11;
out1[4] = x13;
out1[5] = x15;
out1[6] = x17;
out1[7] = x18;
out1[8] = x19;
out1[9] = x21;
out1[10] = x23;
out1[11] = x25;
out1[12] = x27;
out1[13] = x29;
out1[14] = x31;
out1[15] = x32;
out1[16] = x33;
out1[17] = x35;
out1[18] = x37;
out1[19] = x39;
out1[20] = x41;
out1[21] = x43;
out1[22] = x45;
out1[23] = x46;
out1[24] = x47;
out1[25] = x49;
out1[26] = x51;
out1[27] = x53;
out1[28] = x55;
out1[29] = x57;
out1[30] = x59;
out1[31] = x60;
}