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