Bitcoin ABC 0.32.6
P2P Digital Currency
field_5x52_impl.h
Go to the documentation of this file.
1/***********************************************************************
2 * Copyright (c) 2013, 2014 Pieter Wuille *
3 * Distributed under the MIT software license, see the accompanying *
4 * file COPYING or https://www.opensource.org/licenses/mit-license.php.*
5 ***********************************************************************/
6
7#ifndef SECP256K1_FIELD_REPR_IMPL_H
8#define SECP256K1_FIELD_REPR_IMPL_H
9
10#if defined HAVE_CONFIG_H
11#include "libsecp256k1-config.h"
12#endif
13
14#include "util.h"
15#include "field.h"
16#include "modinv64_impl.h"
17
18#if defined(USE_ASM_X86_64)
19#include "field_5x52_asm_impl.h"
20#else
22#endif
23
32#ifdef VERIFY
33static void secp256k1_fe_verify(const secp256k1_fe *a) {
34 const uint64_t *d = a->n;
35 int m = a->normalized ? 1 : 2 * a->magnitude, r = 1;
36 /* secp256k1 'p' value defined in "Standards for Efficient Cryptography" (SEC2) 2.7.1. */
37 r &= (d[0] <= 0xFFFFFFFFFFFFFULL * m);
38 r &= (d[1] <= 0xFFFFFFFFFFFFFULL * m);
39 r &= (d[2] <= 0xFFFFFFFFFFFFFULL * m);
40 r &= (d[3] <= 0xFFFFFFFFFFFFFULL * m);
41 r &= (d[4] <= 0x0FFFFFFFFFFFFULL * m);
42 r &= (a->magnitude >= 0);
43 r &= (a->magnitude <= 2048);
44 if (a->normalized) {
45 r &= (a->magnitude <= 1);
46 if (r && (d[4] == 0x0FFFFFFFFFFFFULL) && ((d[3] & d[2] & d[1]) == 0xFFFFFFFFFFFFFULL)) {
47 r &= (d[0] < 0xFFFFEFFFFFC2FULL);
48 }
49 }
50 VERIFY_CHECK(r == 1);
51}
52#endif
53
55 uint64_t t0 = r->n[0], t1 = r->n[1], t2 = r->n[2], t3 = r->n[3], t4 = r->n[4];
56
57 /* Reduce t4 at the start so there will be at most a single carry from the first pass */
58 uint64_t m;
59 uint64_t x = t4 >> 48; t4 &= 0x0FFFFFFFFFFFFULL;
60
61 /* The first pass ensures the magnitude is 1, ... */
62 t0 += x * 0x1000003D1ULL;
63 t1 += (t0 >> 52); t0 &= 0xFFFFFFFFFFFFFULL;
64 t2 += (t1 >> 52); t1 &= 0xFFFFFFFFFFFFFULL; m = t1;
65 t3 += (t2 >> 52); t2 &= 0xFFFFFFFFFFFFFULL; m &= t2;
66 t4 += (t3 >> 52); t3 &= 0xFFFFFFFFFFFFFULL; m &= t3;
67
68 /* ... except for a possible carry at bit 48 of t4 (i.e. bit 256 of the field element) */
69 VERIFY_CHECK(t4 >> 49 == 0);
70
71 /* At most a single final reduction is needed; check if the value is >= the field characteristic */
72 x = (t4 >> 48) | ((t4 == 0x0FFFFFFFFFFFFULL) & (m == 0xFFFFFFFFFFFFFULL)
73 & (t0 >= 0xFFFFEFFFFFC2FULL));
74
75 /* Apply the final reduction (for constant-time behaviour, we do it always) */
76 t0 += x * 0x1000003D1ULL;
77 t1 += (t0 >> 52); t0 &= 0xFFFFFFFFFFFFFULL;
78 t2 += (t1 >> 52); t1 &= 0xFFFFFFFFFFFFFULL;
79 t3 += (t2 >> 52); t2 &= 0xFFFFFFFFFFFFFULL;
80 t4 += (t3 >> 52); t3 &= 0xFFFFFFFFFFFFFULL;
81
82 /* If t4 didn't carry to bit 48 already, then it should have after any final reduction */
83 VERIFY_CHECK(t4 >> 48 == x);
84
85 /* Mask off the possible multiple of 2^256 from the final reduction */
86 t4 &= 0x0FFFFFFFFFFFFULL;
87
88 r->n[0] = t0; r->n[1] = t1; r->n[2] = t2; r->n[3] = t3; r->n[4] = t4;
89
90#ifdef VERIFY
91 r->magnitude = 1;
92 r->normalized = 1;
93 secp256k1_fe_verify(r);
94#endif
95}
96
98 uint64_t t0 = r->n[0], t1 = r->n[1], t2 = r->n[2], t3 = r->n[3], t4 = r->n[4];
99
100 /* Reduce t4 at the start so there will be at most a single carry from the first pass */
101 uint64_t x = t4 >> 48; t4 &= 0x0FFFFFFFFFFFFULL;
102
103 /* The first pass ensures the magnitude is 1, ... */
104 t0 += x * 0x1000003D1ULL;
105 t1 += (t0 >> 52); t0 &= 0xFFFFFFFFFFFFFULL;
106 t2 += (t1 >> 52); t1 &= 0xFFFFFFFFFFFFFULL;
107 t3 += (t2 >> 52); t2 &= 0xFFFFFFFFFFFFFULL;
108 t4 += (t3 >> 52); t3 &= 0xFFFFFFFFFFFFFULL;
109
110 /* ... except for a possible carry at bit 48 of t4 (i.e. bit 256 of the field element) */
111 VERIFY_CHECK(t4 >> 49 == 0);
112
113 r->n[0] = t0; r->n[1] = t1; r->n[2] = t2; r->n[3] = t3; r->n[4] = t4;
114
115#ifdef VERIFY
116 r->magnitude = 1;
117 secp256k1_fe_verify(r);
118#endif
119}
120
122 uint64_t t0 = r->n[0], t1 = r->n[1], t2 = r->n[2], t3 = r->n[3], t4 = r->n[4];
123
124 /* Reduce t4 at the start so there will be at most a single carry from the first pass */
125 uint64_t m;
126 uint64_t x = t4 >> 48; t4 &= 0x0FFFFFFFFFFFFULL;
127
128 /* The first pass ensures the magnitude is 1, ... */
129 t0 += x * 0x1000003D1ULL;
130 t1 += (t0 >> 52); t0 &= 0xFFFFFFFFFFFFFULL;
131 t2 += (t1 >> 52); t1 &= 0xFFFFFFFFFFFFFULL; m = t1;
132 t3 += (t2 >> 52); t2 &= 0xFFFFFFFFFFFFFULL; m &= t2;
133 t4 += (t3 >> 52); t3 &= 0xFFFFFFFFFFFFFULL; m &= t3;
134
135 /* ... except for a possible carry at bit 48 of t4 (i.e. bit 256 of the field element) */
136 VERIFY_CHECK(t4 >> 49 == 0);
137
138 /* At most a single final reduction is needed; check if the value is >= the field characteristic */
139 x = (t4 >> 48) | ((t4 == 0x0FFFFFFFFFFFFULL) & (m == 0xFFFFFFFFFFFFFULL)
140 & (t0 >= 0xFFFFEFFFFFC2FULL));
141
142 if (x) {
143 t0 += 0x1000003D1ULL;
144 t1 += (t0 >> 52); t0 &= 0xFFFFFFFFFFFFFULL;
145 t2 += (t1 >> 52); t1 &= 0xFFFFFFFFFFFFFULL;
146 t3 += (t2 >> 52); t2 &= 0xFFFFFFFFFFFFFULL;
147 t4 += (t3 >> 52); t3 &= 0xFFFFFFFFFFFFFULL;
148
149 /* If t4 didn't carry to bit 48 already, then it should have after any final reduction */
150 VERIFY_CHECK(t4 >> 48 == x);
151
152 /* Mask off the possible multiple of 2^256 from the final reduction */
153 t4 &= 0x0FFFFFFFFFFFFULL;
154 }
155
156 r->n[0] = t0; r->n[1] = t1; r->n[2] = t2; r->n[3] = t3; r->n[4] = t4;
157
158#ifdef VERIFY
159 r->magnitude = 1;
160 r->normalized = 1;
161 secp256k1_fe_verify(r);
162#endif
163}
164
166 uint64_t t0 = r->n[0], t1 = r->n[1], t2 = r->n[2], t3 = r->n[3], t4 = r->n[4];
167
168 /* z0 tracks a possible raw value of 0, z1 tracks a possible raw value of P */
169 uint64_t z0, z1;
170
171 /* Reduce t4 at the start so there will be at most a single carry from the first pass */
172 uint64_t x = t4 >> 48; t4 &= 0x0FFFFFFFFFFFFULL;
173
174 /* The first pass ensures the magnitude is 1, ... */
175 t0 += x * 0x1000003D1ULL;
176 t1 += (t0 >> 52); t0 &= 0xFFFFFFFFFFFFFULL; z0 = t0; z1 = t0 ^ 0x1000003D0ULL;
177 t2 += (t1 >> 52); t1 &= 0xFFFFFFFFFFFFFULL; z0 |= t1; z1 &= t1;
178 t3 += (t2 >> 52); t2 &= 0xFFFFFFFFFFFFFULL; z0 |= t2; z1 &= t2;
179 t4 += (t3 >> 52); t3 &= 0xFFFFFFFFFFFFFULL; z0 |= t3; z1 &= t3;
180 z0 |= t4; z1 &= t4 ^ 0xF000000000000ULL;
181
182 /* ... except for a possible carry at bit 48 of t4 (i.e. bit 256 of the field element) */
183 VERIFY_CHECK(t4 >> 49 == 0);
184
185 return (z0 == 0) | (z1 == 0xFFFFFFFFFFFFFULL);
186}
187
189 uint64_t t0, t1, t2, t3, t4;
190 uint64_t z0, z1;
191 uint64_t x;
192
193 t0 = r->n[0];
194 t4 = r->n[4];
195
196 /* Reduce t4 at the start so there will be at most a single carry from the first pass */
197 x = t4 >> 48;
198
199 /* The first pass ensures the magnitude is 1, ... */
200 t0 += x * 0x1000003D1ULL;
201
202 /* z0 tracks a possible raw value of 0, z1 tracks a possible raw value of P */
203 z0 = t0 & 0xFFFFFFFFFFFFFULL;
204 z1 = z0 ^ 0x1000003D0ULL;
205
206 /* Fast return path should catch the majority of cases */
207 if ((z0 != 0ULL) & (z1 != 0xFFFFFFFFFFFFFULL)) {
208 return 0;
209 }
210
211 t1 = r->n[1];
212 t2 = r->n[2];
213 t3 = r->n[3];
214
215 t4 &= 0x0FFFFFFFFFFFFULL;
216
217 t1 += (t0 >> 52);
218 t2 += (t1 >> 52); t1 &= 0xFFFFFFFFFFFFFULL; z0 |= t1; z1 &= t1;
219 t3 += (t2 >> 52); t2 &= 0xFFFFFFFFFFFFFULL; z0 |= t2; z1 &= t2;
220 t4 += (t3 >> 52); t3 &= 0xFFFFFFFFFFFFFULL; z0 |= t3; z1 &= t3;
221 z0 |= t4; z1 &= t4 ^ 0xF000000000000ULL;
222
223 /* ... except for a possible carry at bit 48 of t4 (i.e. bit 256 of the field element) */
224 VERIFY_CHECK(t4 >> 49 == 0);
225
226 return (z0 == 0) | (z1 == 0xFFFFFFFFFFFFFULL);
227}
228
230 VERIFY_CHECK(0 <= a && a <= 0x7FFF);
231 r->n[0] = a;
232 r->n[1] = r->n[2] = r->n[3] = r->n[4] = 0;
233#ifdef VERIFY
234 r->magnitude = (a != 0);
235 r->normalized = 1;
236 secp256k1_fe_verify(r);
237#endif
238}
239
241 const uint64_t *t = a->n;
242#ifdef VERIFY
243 VERIFY_CHECK(a->normalized);
244 secp256k1_fe_verify(a);
245#endif
246 return (t[0] | t[1] | t[2] | t[3] | t[4]) == 0;
247}
248
250#ifdef VERIFY
251 VERIFY_CHECK(a->normalized);
252 secp256k1_fe_verify(a);
253#endif
254 return a->n[0] & 1;
255}
256
258 int i;
259#ifdef VERIFY
260 a->magnitude = 0;
261 a->normalized = 1;
262#endif
263 for (i=0; i<5; i++) {
264 a->n[i] = 0;
265 }
266}
267
268static int secp256k1_fe_cmp_var(const secp256k1_fe *a, const secp256k1_fe *b) {
269 int i;
270#ifdef VERIFY
271 VERIFY_CHECK(a->normalized);
272 VERIFY_CHECK(b->normalized);
273 secp256k1_fe_verify(a);
274 secp256k1_fe_verify(b);
275#endif
276 for (i = 4; i >= 0; i--) {
277 if (a->n[i] > b->n[i]) {
278 return 1;
279 }
280 if (a->n[i] < b->n[i]) {
281 return -1;
282 }
283 }
284 return 0;
285}
286
287static int secp256k1_fe_set_b32(secp256k1_fe *r, const unsigned char *a) {
288 int ret;
289 r->n[0] = (uint64_t)a[31]
290 | ((uint64_t)a[30] << 8)
291 | ((uint64_t)a[29] << 16)
292 | ((uint64_t)a[28] << 24)
293 | ((uint64_t)a[27] << 32)
294 | ((uint64_t)a[26] << 40)
295 | ((uint64_t)(a[25] & 0xF) << 48);
296 r->n[1] = (uint64_t)((a[25] >> 4) & 0xF)
297 | ((uint64_t)a[24] << 4)
298 | ((uint64_t)a[23] << 12)
299 | ((uint64_t)a[22] << 20)
300 | ((uint64_t)a[21] << 28)
301 | ((uint64_t)a[20] << 36)
302 | ((uint64_t)a[19] << 44);
303 r->n[2] = (uint64_t)a[18]
304 | ((uint64_t)a[17] << 8)
305 | ((uint64_t)a[16] << 16)
306 | ((uint64_t)a[15] << 24)
307 | ((uint64_t)a[14] << 32)
308 | ((uint64_t)a[13] << 40)
309 | ((uint64_t)(a[12] & 0xF) << 48);
310 r->n[3] = (uint64_t)((a[12] >> 4) & 0xF)
311 | ((uint64_t)a[11] << 4)
312 | ((uint64_t)a[10] << 12)
313 | ((uint64_t)a[9] << 20)
314 | ((uint64_t)a[8] << 28)
315 | ((uint64_t)a[7] << 36)
316 | ((uint64_t)a[6] << 44);
317 r->n[4] = (uint64_t)a[5]
318 | ((uint64_t)a[4] << 8)
319 | ((uint64_t)a[3] << 16)
320 | ((uint64_t)a[2] << 24)
321 | ((uint64_t)a[1] << 32)
322 | ((uint64_t)a[0] << 40);
323 ret = !((r->n[4] == 0x0FFFFFFFFFFFFULL) & ((r->n[3] & r->n[2] & r->n[1]) == 0xFFFFFFFFFFFFFULL) & (r->n[0] >= 0xFFFFEFFFFFC2FULL));
324#ifdef VERIFY
325 r->magnitude = 1;
326 if (ret) {
327 r->normalized = 1;
328 secp256k1_fe_verify(r);
329 } else {
330 r->normalized = 0;
331 }
332#endif
333 return ret;
334}
335
337static void secp256k1_fe_get_b32(unsigned char *r, const secp256k1_fe *a) {
338#ifdef VERIFY
339 VERIFY_CHECK(a->normalized);
340 secp256k1_fe_verify(a);
341#endif
342 r[0] = (a->n[4] >> 40) & 0xFF;
343 r[1] = (a->n[4] >> 32) & 0xFF;
344 r[2] = (a->n[4] >> 24) & 0xFF;
345 r[3] = (a->n[4] >> 16) & 0xFF;
346 r[4] = (a->n[4] >> 8) & 0xFF;
347 r[5] = a->n[4] & 0xFF;
348 r[6] = (a->n[3] >> 44) & 0xFF;
349 r[7] = (a->n[3] >> 36) & 0xFF;
350 r[8] = (a->n[3] >> 28) & 0xFF;
351 r[9] = (a->n[3] >> 20) & 0xFF;
352 r[10] = (a->n[3] >> 12) & 0xFF;
353 r[11] = (a->n[3] >> 4) & 0xFF;
354 r[12] = ((a->n[2] >> 48) & 0xF) | ((a->n[3] & 0xF) << 4);
355 r[13] = (a->n[2] >> 40) & 0xFF;
356 r[14] = (a->n[2] >> 32) & 0xFF;
357 r[15] = (a->n[2] >> 24) & 0xFF;
358 r[16] = (a->n[2] >> 16) & 0xFF;
359 r[17] = (a->n[2] >> 8) & 0xFF;
360 r[18] = a->n[2] & 0xFF;
361 r[19] = (a->n[1] >> 44) & 0xFF;
362 r[20] = (a->n[1] >> 36) & 0xFF;
363 r[21] = (a->n[1] >> 28) & 0xFF;
364 r[22] = (a->n[1] >> 20) & 0xFF;
365 r[23] = (a->n[1] >> 12) & 0xFF;
366 r[24] = (a->n[1] >> 4) & 0xFF;
367 r[25] = ((a->n[0] >> 48) & 0xF) | ((a->n[1] & 0xF) << 4);
368 r[26] = (a->n[0] >> 40) & 0xFF;
369 r[27] = (a->n[0] >> 32) & 0xFF;
370 r[28] = (a->n[0] >> 24) & 0xFF;
371 r[29] = (a->n[0] >> 16) & 0xFF;
372 r[30] = (a->n[0] >> 8) & 0xFF;
373 r[31] = a->n[0] & 0xFF;
374}
375
377#ifdef VERIFY
378 VERIFY_CHECK(a->magnitude <= m);
379 secp256k1_fe_verify(a);
380#endif
381 r->n[0] = 0xFFFFEFFFFFC2FULL * 2 * (m + 1) - a->n[0];
382 r->n[1] = 0xFFFFFFFFFFFFFULL * 2 * (m + 1) - a->n[1];
383 r->n[2] = 0xFFFFFFFFFFFFFULL * 2 * (m + 1) - a->n[2];
384 r->n[3] = 0xFFFFFFFFFFFFFULL * 2 * (m + 1) - a->n[3];
385 r->n[4] = 0x0FFFFFFFFFFFFULL * 2 * (m + 1) - a->n[4];
386#ifdef VERIFY
387 r->magnitude = m + 1;
388 r->normalized = 0;
389 secp256k1_fe_verify(r);
390#endif
391}
392
394 r->n[0] *= a;
395 r->n[1] *= a;
396 r->n[2] *= a;
397 r->n[3] *= a;
398 r->n[4] *= a;
399#ifdef VERIFY
400 r->magnitude *= a;
401 r->normalized = 0;
402 secp256k1_fe_verify(r);
403#endif
404}
405
407#ifdef VERIFY
408 secp256k1_fe_verify(a);
409#endif
410 r->n[0] += a->n[0];
411 r->n[1] += a->n[1];
412 r->n[2] += a->n[2];
413 r->n[3] += a->n[3];
414 r->n[4] += a->n[4];
415#ifdef VERIFY
416 r->magnitude += a->magnitude;
417 r->normalized = 0;
418 secp256k1_fe_verify(r);
419#endif
420}
421
423#ifdef VERIFY
424 VERIFY_CHECK(a->magnitude <= 8);
425 VERIFY_CHECK(b->magnitude <= 8);
426 secp256k1_fe_verify(a);
427 secp256k1_fe_verify(b);
428 VERIFY_CHECK(r != b);
429 VERIFY_CHECK(a != b);
430#endif
431 secp256k1_fe_mul_inner(r->n, a->n, b->n);
432#ifdef VERIFY
433 r->magnitude = 1;
434 r->normalized = 0;
435 secp256k1_fe_verify(r);
436#endif
437}
438
439static void secp256k1_fe_sqr(secp256k1_fe *r, const secp256k1_fe *a) {
440#ifdef VERIFY
441 VERIFY_CHECK(a->magnitude <= 8);
442 secp256k1_fe_verify(a);
443#endif
444 secp256k1_fe_sqr_inner(r->n, a->n);
445#ifdef VERIFY
446 r->magnitude = 1;
447 r->normalized = 0;
448 secp256k1_fe_verify(r);
449#endif
450}
451
452static SECP256K1_INLINE void secp256k1_fe_cmov(secp256k1_fe *r, const secp256k1_fe *a, int flag) {
453 uint64_t mask0, mask1;
454 volatile int vflag = flag;
455 VG_CHECK_VERIFY(r->n, sizeof(r->n));
456 mask0 = vflag + ~((uint64_t)0);
457 mask1 = ~mask0;
458 r->n[0] = (r->n[0] & mask0) | (a->n[0] & mask1);
459 r->n[1] = (r->n[1] & mask0) | (a->n[1] & mask1);
460 r->n[2] = (r->n[2] & mask0) | (a->n[2] & mask1);
461 r->n[3] = (r->n[3] & mask0) | (a->n[3] & mask1);
462 r->n[4] = (r->n[4] & mask0) | (a->n[4] & mask1);
463#ifdef VERIFY
464 if (flag) {
465 r->magnitude = a->magnitude;
466 r->normalized = a->normalized;
467 }
468#endif
469}
470
472 uint64_t mask0, mask1;
473 volatile int vflag = flag;
474 VG_CHECK_VERIFY(r->n, sizeof(r->n));
475 mask0 = vflag + ~((uint64_t)0);
476 mask1 = ~mask0;
477 r->n[0] = (r->n[0] & mask0) | (a->n[0] & mask1);
478 r->n[1] = (r->n[1] & mask0) | (a->n[1] & mask1);
479 r->n[2] = (r->n[2] & mask0) | (a->n[2] & mask1);
480 r->n[3] = (r->n[3] & mask0) | (a->n[3] & mask1);
481}
482
484#ifdef VERIFY
485 VERIFY_CHECK(a->normalized);
486#endif
487 r->n[0] = a->n[0] | a->n[1] << 52;
488 r->n[1] = a->n[1] >> 12 | a->n[2] << 40;
489 r->n[2] = a->n[2] >> 24 | a->n[3] << 28;
490 r->n[3] = a->n[3] >> 36 | a->n[4] << 16;
491}
492
494 r->n[0] = a->n[0] & 0xFFFFFFFFFFFFFULL;
495 r->n[1] = a->n[0] >> 52 | ((a->n[1] << 12) & 0xFFFFFFFFFFFFFULL);
496 r->n[2] = a->n[1] >> 40 | ((a->n[2] << 24) & 0xFFFFFFFFFFFFFULL);
497 r->n[3] = a->n[2] >> 28 | ((a->n[3] << 36) & 0xFFFFFFFFFFFFFULL);
498 r->n[4] = a->n[3] >> 16;
499#ifdef VERIFY
500 r->magnitude = 1;
501 r->normalized = 1;
502 secp256k1_fe_verify(r);
503#endif
504}
505
507 const uint64_t M52 = UINT64_MAX >> 12;
508 const uint64_t a0 = a->v[0], a1 = a->v[1], a2 = a->v[2], a3 = a->v[3], a4 = a->v[4];
509
510 /* The output from secp256k1_modinv64{_var} should be normalized to range [0,modulus), and
511 * have limbs in [0,2^62). The modulus is < 2^256, so the top limb must be below 2^(256-62*4).
512 */
513 VERIFY_CHECK(a0 >> 62 == 0);
514 VERIFY_CHECK(a1 >> 62 == 0);
515 VERIFY_CHECK(a2 >> 62 == 0);
516 VERIFY_CHECK(a3 >> 62 == 0);
517 VERIFY_CHECK(a4 >> 8 == 0);
518
519 r->n[0] = a0 & M52;
520 r->n[1] = (a0 >> 52 | a1 << 10) & M52;
521 r->n[2] = (a1 >> 42 | a2 << 20) & M52;
522 r->n[3] = (a2 >> 32 | a3 << 30) & M52;
523 r->n[4] = (a3 >> 22 | a4 << 40);
524
525#ifdef VERIFY
526 r->magnitude = 1;
527 r->normalized = 1;
528 secp256k1_fe_verify(r);
529#endif
530}
531
533 const uint64_t M62 = UINT64_MAX >> 2;
534 const uint64_t a0 = a->n[0], a1 = a->n[1], a2 = a->n[2], a3 = a->n[3], a4 = a->n[4];
535
536#ifdef VERIFY
537 VERIFY_CHECK(a->normalized);
538#endif
539
540 r->v[0] = (a0 | a1 << 52) & M62;
541 r->v[1] = (a1 >> 10 | a2 << 42) & M62;
542 r->v[2] = (a2 >> 20 | a3 << 32) & M62;
543 r->v[3] = (a3 >> 30 | a4 << 22) & M62;
544 r->v[4] = a4 >> 40;
545}
546
548 {{-0x1000003D1LL, 0, 0, 0, 256}},
549 0x27C7F6E22DDACACFLL
550};
551
552static void secp256k1_fe_inv(secp256k1_fe *r, const secp256k1_fe *x) {
553 secp256k1_fe tmp;
555
556 tmp = *x;
558 secp256k1_fe_to_signed62(&s, &tmp);
561
562#ifdef VERIFY
564#endif
565}
566
568 secp256k1_fe tmp;
570
571 tmp = *x;
573 secp256k1_fe_to_signed62(&s, &tmp);
576
577#ifdef VERIFY
579#endif
580}
581
582#endif /* SECP256K1_FIELD_REPR_IMPL_H */
static SECP256K1_INLINE void secp256k1_fe_sqr_inner(uint32_t *r, const uint32_t *a)
static SECP256K1_INLINE void secp256k1_fe_mul_inner(uint32_t *r, const uint32_t *a, const uint32_t *SECP256K1_RESTRICT b)
static int secp256k1_fe_normalizes_to_zero_var(const secp256k1_fe *r)
static SECP256K1_INLINE void secp256k1_fe_set_int(secp256k1_fe *r, int a)
static void secp256k1_fe_normalize_weak(secp256k1_fe *r)
static SECP256K1_INLINE int secp256k1_fe_is_zero(const secp256k1_fe *a)
static void secp256k1_fe_normalize_var(secp256k1_fe *r)
static SECP256K1_INLINE void secp256k1_fe_mul_int(secp256k1_fe *r, int a)
static void secp256k1_fe_mul(secp256k1_fe *r, const secp256k1_fe *a, const secp256k1_fe *SECP256K1_RESTRICT b)
static int secp256k1_fe_set_b32(secp256k1_fe *r, const unsigned char *a)
static SECP256K1_INLINE void secp256k1_fe_storage_cmov(secp256k1_fe_storage *r, const secp256k1_fe_storage *a, int flag)
static void secp256k1_fe_sqr(secp256k1_fe *r, const secp256k1_fe *a)
static SECP256K1_INLINE void secp256k1_fe_cmov(secp256k1_fe *r, const secp256k1_fe *a, int flag)
static int secp256k1_fe_normalizes_to_zero(const secp256k1_fe *r)
static SECP256K1_INLINE void secp256k1_fe_negate(secp256k1_fe *r, const secp256k1_fe *a, int m)
static void secp256k1_fe_to_signed62(secp256k1_modinv64_signed62 *r, const secp256k1_fe *a)
static void secp256k1_fe_normalize(secp256k1_fe *r)
Implements arithmetic modulo FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE FFFFFC2F,...
static SECP256K1_INLINE int secp256k1_fe_is_odd(const secp256k1_fe *a)
static SECP256K1_INLINE void secp256k1_fe_clear(secp256k1_fe *a)
static void secp256k1_fe_to_storage(secp256k1_fe_storage *r, const secp256k1_fe *a)
static SECP256K1_INLINE void secp256k1_fe_from_storage(secp256k1_fe *r, const secp256k1_fe_storage *a)
static void secp256k1_fe_get_b32(unsigned char *r, const secp256k1_fe *a)
Convert a field element to a 32-byte big endian value.
static SECP256K1_INLINE void secp256k1_fe_add(secp256k1_fe *r, const secp256k1_fe *a)
static void secp256k1_fe_from_signed62(secp256k1_fe *r, const secp256k1_modinv64_signed62 *a)
static const secp256k1_modinv64_modinfo secp256k1_const_modinfo_fe
static int secp256k1_fe_cmp_var(const secp256k1_fe *a, const secp256k1_fe *b)
static void secp256k1_fe_inv(secp256k1_fe *r, const secp256k1_fe *x)
static void secp256k1_fe_inv_var(secp256k1_fe *r, const secp256k1_fe *x)
static void secp256k1_modinv64(secp256k1_modinv64_signed62 *x, const secp256k1_modinv64_modinfo *modinfo)
static void secp256k1_modinv64_var(secp256k1_modinv64_signed62 *x, const secp256k1_modinv64_modinfo *modinfo)
#define VG_CHECK_VERIFY(x, y)
Definition: util.h:88
#define VERIFY_CHECK(cond)
Definition: util.h:68
#define SECP256K1_RESTRICT
Definition: util.h:160
#define SECP256K1_INLINE
Definition: secp256k1.h:127
uint32_t n[10]
Definition: field_10x26.h:16