forked from mit-plv/fiat-crypto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsecp256k1_dettman_64.c
209 lines (203 loc) · 9.61 KB
/
secp256k1_dettman_64.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/* Autogenerated: 'src/ExtractionOCaml/dettman_multiplication' --inline --static --use-value-barrier secp256k1_dettman 64 5 48 2 '2^256 - 4294968273' mul square */
/* curve description: secp256k1_dettman */
/* machine_wordsize = 64 (from "64") */
/* requested operations: mul, square */
/* n = 5 (from "5") */
/* last_limb_width = 48 (from "48") */
/* last_reduction = 2 (from "2") */
/* s-c = 2^256 - [(1, 4294968273)] (from "2^256 - 4294968273") */
/* inbounds_multiplier: None (from "") */
/* */
/* Computed values: */
/* */
/* */
#include <stdint.h>
#if defined(__GNUC__) || defined(__clang__)
# define FIAT_SECP256K1_DETTMAN_FIAT_EXTENSION __extension__
# define FIAT_SECP256K1_DETTMAN_FIAT_INLINE __inline__
#else
# define FIAT_SECP256K1_DETTMAN_FIAT_EXTENSION
# define FIAT_SECP256K1_DETTMAN_FIAT_INLINE
#endif
FIAT_SECP256K1_DETTMAN_FIAT_EXTENSION typedef signed __int128 fiat_secp256k1_dettman_int128;
FIAT_SECP256K1_DETTMAN_FIAT_EXTENSION typedef unsigned __int128 fiat_secp256k1_dettman_uint128;
#if (-1 & 3) != 3
#error "This code only works on a two's complement system"
#endif
/*
* The function fiat_secp256k1_dettman_mul multiplies two field elements.
*
* Postconditions:
* eval out1 mod 115792089237316195423570985008687907853269984665640564039457584007908834671663 = (eval arg1 * eval arg2) mod 115792089237316195423570985008687907853269984665640564039457584007908834671663
*
* Input Bounds:
* arg1: [[0x0 ~> 0x1ffffffffffffe], [0x0 ~> 0x1ffffffffffffe], [0x0 ~> 0x1ffffffffffffe], [0x0 ~> 0x1ffffffffffffe], [0x0 ~> 0x1fffffffffffe]]
* arg2: [[0x0 ~> 0x1ffffffffffffe], [0x0 ~> 0x1ffffffffffffe], [0x0 ~> 0x1ffffffffffffe], [0x0 ~> 0x1ffffffffffffe], [0x0 ~> 0x1fffffffffffe]]
* Output Bounds:
* out1: [[0x0 ~> 0x1ffffffffffffe], [0x0 ~> 0x1ffffffffffffe], [0x0 ~> 0x1ffffffffffffe], [0x0 ~> 0x1ffffffffffffe], [0x0 ~> 0x17fffffffffff]]
*/
static FIAT_SECP256K1_DETTMAN_FIAT_INLINE void fiat_secp256k1_dettman_mul(uint64_t out1[5], const uint64_t arg1[5], const uint64_t arg2[5]) {
fiat_secp256k1_dettman_uint128 x1;
uint64_t x2;
uint64_t x3;
fiat_secp256k1_dettman_uint128 x4;
uint64_t x5;
uint64_t x6;
fiat_secp256k1_dettman_uint128 x7;
uint64_t x8;
uint64_t x9;
fiat_secp256k1_dettman_uint128 x10;
uint64_t x11;
uint64_t x12;
uint64_t x13;
uint64_t x14;
fiat_secp256k1_dettman_uint128 x15;
uint64_t x16;
uint64_t x17;
fiat_secp256k1_dettman_uint128 x18;
uint64_t x19;
uint64_t x20;
fiat_secp256k1_dettman_uint128 x21;
uint64_t x22;
uint64_t x23;
fiat_secp256k1_dettman_uint128 x24;
uint64_t x25;
uint64_t x26;
fiat_secp256k1_dettman_uint128 x27;
uint64_t x28;
uint64_t x29;
fiat_secp256k1_dettman_uint128 x30;
uint64_t x31;
uint64_t x32;
uint64_t x33;
x1 = ((fiat_secp256k1_dettman_uint128)(arg1[4]) * (arg2[4]));
x2 = (uint64_t)(x1 >> 64);
x3 = (uint64_t)(x1 & UINT64_C(0xffffffffffffffff));
x4 = ((((fiat_secp256k1_dettman_uint128)(arg1[0]) * (arg2[3])) + (((fiat_secp256k1_dettman_uint128)(arg1[1]) * (arg2[2])) + (((fiat_secp256k1_dettman_uint128)(arg1[2]) * (arg2[1])) + ((fiat_secp256k1_dettman_uint128)(arg1[3]) * (arg2[0]))))) + ((fiat_secp256k1_dettman_uint128)x3 * UINT64_C(0x1000003d10)));
x5 = (uint64_t)(x4 >> 52);
x6 = (uint64_t)(x4 & UINT64_C(0xfffffffffffff));
x7 = ((x5 + (((fiat_secp256k1_dettman_uint128)(arg1[0]) * (arg2[4])) + (((fiat_secp256k1_dettman_uint128)(arg1[1]) * (arg2[3])) + (((fiat_secp256k1_dettman_uint128)(arg1[2]) * (arg2[2])) + (((fiat_secp256k1_dettman_uint128)(arg1[3]) * (arg2[1])) + ((fiat_secp256k1_dettman_uint128)(arg1[4]) * (arg2[0]))))))) + ((fiat_secp256k1_dettman_uint128)x2 * UINT64_C(0x1000003d10000)));
x8 = (uint64_t)(x7 >> 52);
x9 = (uint64_t)(x7 & UINT64_C(0xfffffffffffff));
x10 = (x8 + (((fiat_secp256k1_dettman_uint128)(arg1[1]) * (arg2[4])) + (((fiat_secp256k1_dettman_uint128)(arg1[2]) * (arg2[3])) + (((fiat_secp256k1_dettman_uint128)(arg1[3]) * (arg2[2])) + ((fiat_secp256k1_dettman_uint128)(arg1[4]) * (arg2[1]))))));
x11 = (uint64_t)(x10 >> 52);
x12 = (uint64_t)(x10 & UINT64_C(0xfffffffffffff));
x13 = (x9 >> 48);
x14 = (x9 & UINT64_C(0xffffffffffff));
x15 = (((fiat_secp256k1_dettman_uint128)(arg1[0]) * (arg2[0])) + ((fiat_secp256k1_dettman_uint128)(x13 + (x12 << 4)) * UINT64_C(0x1000003d1)));
x16 = (uint64_t)(x15 >> 52);
x17 = (uint64_t)(x15 & UINT64_C(0xfffffffffffff));
x18 = (x11 + (((fiat_secp256k1_dettman_uint128)(arg1[2]) * (arg2[4])) + (((fiat_secp256k1_dettman_uint128)(arg1[3]) * (arg2[3])) + ((fiat_secp256k1_dettman_uint128)(arg1[4]) * (arg2[2])))));
x19 = (uint64_t)(x18 >> 52);
x20 = (uint64_t)(x18 & UINT64_C(0xfffffffffffff));
x21 = ((x16 + (((fiat_secp256k1_dettman_uint128)(arg1[0]) * (arg2[1])) + ((fiat_secp256k1_dettman_uint128)(arg1[1]) * (arg2[0])))) + ((fiat_secp256k1_dettman_uint128)x20 * UINT64_C(0x1000003d10)));
x22 = (uint64_t)(x21 >> 52);
x23 = (uint64_t)(x21 & UINT64_C(0xfffffffffffff));
x24 = (x19 + (((fiat_secp256k1_dettman_uint128)(arg1[3]) * (arg2[4])) + ((fiat_secp256k1_dettman_uint128)(arg1[4]) * (arg2[3]))));
x25 = (uint64_t)(x24 >> 64);
x26 = (uint64_t)(x24 & UINT64_C(0xffffffffffffffff));
x27 = ((x22 + (((fiat_secp256k1_dettman_uint128)(arg1[0]) * (arg2[2])) + (((fiat_secp256k1_dettman_uint128)(arg1[1]) * (arg2[1])) + ((fiat_secp256k1_dettman_uint128)(arg1[2]) * (arg2[0]))))) + ((fiat_secp256k1_dettman_uint128)x26 * UINT64_C(0x1000003d10)));
x28 = (uint64_t)(x27 >> 52);
x29 = (uint64_t)(x27 & UINT64_C(0xfffffffffffff));
x30 = ((x28 + x6) + ((fiat_secp256k1_dettman_uint128)x25 * UINT64_C(0x1000003d10000)));
x31 = (uint64_t)(x30 >> 52);
x32 = (uint64_t)(x30 & UINT64_C(0xfffffffffffff));
x33 = (x31 + x14);
out1[0] = x17;
out1[1] = x23;
out1[2] = x29;
out1[3] = x32;
out1[4] = x33;
}
/*
* The function fiat_secp256k1_dettman_square squares a field element.
*
* Postconditions:
* eval out1 mod 115792089237316195423570985008687907853269984665640564039457584007908834671663 = (eval arg1 * eval arg1) mod 115792089237316195423570985008687907853269984665640564039457584007908834671663
*
* Input Bounds:
* arg1: [[0x0 ~> 0x1ffffffffffffe], [0x0 ~> 0x1ffffffffffffe], [0x0 ~> 0x1ffffffffffffe], [0x0 ~> 0x1ffffffffffffe], [0x0 ~> 0x1fffffffffffe]]
* Output Bounds:
* out1: [[0x0 ~> 0x1ffffffffffffe], [0x0 ~> 0x1ffffffffffffe], [0x0 ~> 0x1ffffffffffffe], [0x0 ~> 0x1ffffffffffffe], [0x0 ~> 0x17fffffffffff]]
*/
static FIAT_SECP256K1_DETTMAN_FIAT_INLINE void fiat_secp256k1_dettman_square(uint64_t out1[5], const uint64_t arg1[5]) {
uint64_t x1;
uint64_t x2;
uint64_t x3;
uint64_t x4;
fiat_secp256k1_dettman_uint128 x5;
uint64_t x6;
uint64_t x7;
fiat_secp256k1_dettman_uint128 x8;
uint64_t x9;
uint64_t x10;
fiat_secp256k1_dettman_uint128 x11;
uint64_t x12;
uint64_t x13;
fiat_secp256k1_dettman_uint128 x14;
uint64_t x15;
uint64_t x16;
uint64_t x17;
uint64_t x18;
fiat_secp256k1_dettman_uint128 x19;
uint64_t x20;
uint64_t x21;
fiat_secp256k1_dettman_uint128 x22;
uint64_t x23;
uint64_t x24;
fiat_secp256k1_dettman_uint128 x25;
uint64_t x26;
uint64_t x27;
fiat_secp256k1_dettman_uint128 x28;
uint64_t x29;
uint64_t x30;
fiat_secp256k1_dettman_uint128 x31;
uint64_t x32;
uint64_t x33;
fiat_secp256k1_dettman_uint128 x34;
uint64_t x35;
uint64_t x36;
uint64_t x37;
x1 = ((arg1[3]) * 0x2);
x2 = ((arg1[2]) * 0x2);
x3 = ((arg1[1]) * 0x2);
x4 = ((arg1[0]) * 0x2);
x5 = ((fiat_secp256k1_dettman_uint128)(arg1[4]) * (arg1[4]));
x6 = (uint64_t)(x5 >> 64);
x7 = (uint64_t)(x5 & UINT64_C(0xffffffffffffffff));
x8 = ((((fiat_secp256k1_dettman_uint128)x4 * (arg1[3])) + ((fiat_secp256k1_dettman_uint128)x3 * (arg1[2]))) + ((fiat_secp256k1_dettman_uint128)x7 * UINT64_C(0x1000003d10)));
x9 = (uint64_t)(x8 >> 52);
x10 = (uint64_t)(x8 & UINT64_C(0xfffffffffffff));
x11 = ((x9 + (((fiat_secp256k1_dettman_uint128)x4 * (arg1[4])) + (((fiat_secp256k1_dettman_uint128)x3 * (arg1[3])) + ((fiat_secp256k1_dettman_uint128)(arg1[2]) * (arg1[2]))))) + ((fiat_secp256k1_dettman_uint128)x6 * UINT64_C(0x1000003d10000)));
x12 = (uint64_t)(x11 >> 52);
x13 = (uint64_t)(x11 & UINT64_C(0xfffffffffffff));
x14 = (x12 + (((fiat_secp256k1_dettman_uint128)x3 * (arg1[4])) + ((fiat_secp256k1_dettman_uint128)x2 * (arg1[3]))));
x15 = (uint64_t)(x14 >> 52);
x16 = (uint64_t)(x14 & UINT64_C(0xfffffffffffff));
x17 = (x13 >> 48);
x18 = (x13 & UINT64_C(0xffffffffffff));
x19 = (((fiat_secp256k1_dettman_uint128)(arg1[0]) * (arg1[0])) + ((fiat_secp256k1_dettman_uint128)(x17 + (x16 << 4)) * UINT64_C(0x1000003d1)));
x20 = (uint64_t)(x19 >> 52);
x21 = (uint64_t)(x19 & UINT64_C(0xfffffffffffff));
x22 = (x15 + (((fiat_secp256k1_dettman_uint128)x2 * (arg1[4])) + ((fiat_secp256k1_dettman_uint128)(arg1[3]) * (arg1[3]))));
x23 = (uint64_t)(x22 >> 52);
x24 = (uint64_t)(x22 & UINT64_C(0xfffffffffffff));
x25 = ((x20 + ((fiat_secp256k1_dettman_uint128)x4 * (arg1[1]))) + ((fiat_secp256k1_dettman_uint128)x24 * UINT64_C(0x1000003d10)));
x26 = (uint64_t)(x25 >> 52);
x27 = (uint64_t)(x25 & UINT64_C(0xfffffffffffff));
x28 = (x23 + ((fiat_secp256k1_dettman_uint128)x1 * (arg1[4])));
x29 = (uint64_t)(x28 >> 64);
x30 = (uint64_t)(x28 & UINT64_C(0xffffffffffffffff));
x31 = ((x26 + (((fiat_secp256k1_dettman_uint128)x4 * (arg1[2])) + ((fiat_secp256k1_dettman_uint128)(arg1[1]) * (arg1[1])))) + ((fiat_secp256k1_dettman_uint128)x30 * UINT64_C(0x1000003d10)));
x32 = (uint64_t)(x31 >> 52);
x33 = (uint64_t)(x31 & UINT64_C(0xfffffffffffff));
x34 = ((x32 + x10) + ((fiat_secp256k1_dettman_uint128)x29 * UINT64_C(0x1000003d10000)));
x35 = (uint64_t)(x34 >> 52);
x36 = (uint64_t)(x34 & UINT64_C(0xfffffffffffff));
x37 = (x35 + x18);
out1[0] = x21;
out1[1] = x27;
out1[2] = x33;
out1[3] = x36;
out1[4] = x37;
}