7#ifndef SECP256K1_FIELD_REPR_IMPL_H
8#define SECP256K1_FIELD_REPR_IMPL_H
16 const uint32_t *d = a->
n;
17 int m = a->normalized ? 1 : 2 * a->magnitude, r = 1;
18 r &= (d[0] <= 0x3FFFFFFUL * m);
19 r &= (d[1] <= 0x3FFFFFFUL * m);
20 r &= (d[2] <= 0x3FFFFFFUL * m);
21 r &= (d[3] <= 0x3FFFFFFUL * m);
22 r &= (d[4] <= 0x3FFFFFFUL * m);
23 r &= (d[5] <= 0x3FFFFFFUL * m);
24 r &= (d[6] <= 0x3FFFFFFUL * m);
25 r &= (d[7] <= 0x3FFFFFFUL * m);
26 r &= (d[8] <= 0x3FFFFFFUL * m);
27 r &= (d[9] <= 0x03FFFFFUL * m);
28 r &= (a->magnitude >= 0);
29 r &= (a->magnitude <= 32);
31 r &= (a->magnitude <= 1);
32 if (r && (d[9] == 0x03FFFFFUL)) {
33 uint32_t mid = d[8] & d[7] & d[6] & d[5] & d[4] & d[3] & d[2];
34 if (mid == 0x3FFFFFFUL) {
35 r &= ((d[1] + 0x40UL + ((d[0] + 0x3D1UL) >> 26)) <= 0x3FFFFFFUL);
44 uint32_t t0 = r->
n[0], t1 = r->
n[1], t2 = r->
n[2], t3 = r->
n[3], t4 = r->
n[4],
45 t5 = r->
n[5], t6 = r->
n[6], t7 = r->
n[7], t8 = r->
n[8], t9 = r->
n[9];
49 uint32_t x = t9 >> 22; t9 &= 0x03FFFFFUL;
52 t0 += x * 0x3D1UL; t1 += (x << 6);
53 t1 += (t0 >> 26); t0 &= 0x3FFFFFFUL;
54 t2 += (t1 >> 26); t1 &= 0x3FFFFFFUL;
55 t3 += (t2 >> 26); t2 &= 0x3FFFFFFUL; m = t2;
56 t4 += (t3 >> 26); t3 &= 0x3FFFFFFUL; m &= t3;
57 t5 += (t4 >> 26); t4 &= 0x3FFFFFFUL; m &= t4;
58 t6 += (t5 >> 26); t5 &= 0x3FFFFFFUL; m &= t5;
59 t7 += (t6 >> 26); t6 &= 0x3FFFFFFUL; m &= t6;
60 t8 += (t7 >> 26); t7 &= 0x3FFFFFFUL; m &= t7;
61 t9 += (t8 >> 26); t8 &= 0x3FFFFFFUL; m &= t8;
67 x = (t9 >> 22) | ((t9 == 0x03FFFFFUL) & (m == 0x3FFFFFFUL)
68 & ((t1 + 0x40UL + ((t0 + 0x3D1UL) >> 26)) > 0x3FFFFFFUL));
71 t0 += x * 0x3D1UL; t1 += (x << 6);
72 t1 += (t0 >> 26); t0 &= 0x3FFFFFFUL;
73 t2 += (t1 >> 26); t1 &= 0x3FFFFFFUL;
74 t3 += (t2 >> 26); t2 &= 0x3FFFFFFUL;
75 t4 += (t3 >> 26); t3 &= 0x3FFFFFFUL;
76 t5 += (t4 >> 26); t4 &= 0x3FFFFFFUL;
77 t6 += (t5 >> 26); t5 &= 0x3FFFFFFUL;
78 t7 += (t6 >> 26); t6 &= 0x3FFFFFFUL;
79 t8 += (t7 >> 26); t7 &= 0x3FFFFFFUL;
80 t9 += (t8 >> 26); t8 &= 0x3FFFFFFUL;
88 r->
n[0] = t0; r->
n[1] = t1; r->
n[2] = t2; r->
n[3] = t3; r->
n[4] = t4;
89 r->
n[5] = t5; r->
n[6] = t6; r->
n[7] = t7; r->
n[8] = t8; r->
n[9] = t9;
94 secp256k1_fe_verify(r);
99 uint32_t t0 = r->
n[0], t1 = r->
n[1], t2 = r->
n[2], t3 = r->
n[3], t4 = r->
n[4],
100 t5 = r->
n[5], t6 = r->
n[6], t7 = r->
n[7], t8 = r->
n[8], t9 = r->
n[9];
103 uint32_t x = t9 >> 22; t9 &= 0x03FFFFFUL;
106 t0 += x * 0x3D1UL; t1 += (x << 6);
107 t1 += (t0 >> 26); t0 &= 0x3FFFFFFUL;
108 t2 += (t1 >> 26); t1 &= 0x3FFFFFFUL;
109 t3 += (t2 >> 26); t2 &= 0x3FFFFFFUL;
110 t4 += (t3 >> 26); t3 &= 0x3FFFFFFUL;
111 t5 += (t4 >> 26); t4 &= 0x3FFFFFFUL;
112 t6 += (t5 >> 26); t5 &= 0x3FFFFFFUL;
113 t7 += (t6 >> 26); t6 &= 0x3FFFFFFUL;
114 t8 += (t7 >> 26); t7 &= 0x3FFFFFFUL;
115 t9 += (t8 >> 26); t8 &= 0x3FFFFFFUL;
120 r->
n[0] = t0; r->
n[1] = t1; r->
n[2] = t2; r->
n[3] = t3; r->
n[4] = t4;
121 r->
n[5] = t5; r->
n[6] = t6; r->
n[7] = t7; r->
n[8] = t8; r->
n[9] = t9;
125 secp256k1_fe_verify(r);
130 uint32_t t0 = r->
n[0], t1 = r->
n[1], t2 = r->
n[2], t3 = r->
n[3], t4 = r->
n[4],
131 t5 = r->
n[5], t6 = r->
n[6], t7 = r->
n[7], t8 = r->
n[8], t9 = r->
n[9];
135 uint32_t x = t9 >> 22; t9 &= 0x03FFFFFUL;
138 t0 += x * 0x3D1UL; t1 += (x << 6);
139 t1 += (t0 >> 26); t0 &= 0x3FFFFFFUL;
140 t2 += (t1 >> 26); t1 &= 0x3FFFFFFUL;
141 t3 += (t2 >> 26); t2 &= 0x3FFFFFFUL; m = t2;
142 t4 += (t3 >> 26); t3 &= 0x3FFFFFFUL; m &= t3;
143 t5 += (t4 >> 26); t4 &= 0x3FFFFFFUL; m &= t4;
144 t6 += (t5 >> 26); t5 &= 0x3FFFFFFUL; m &= t5;
145 t7 += (t6 >> 26); t6 &= 0x3FFFFFFUL; m &= t6;
146 t8 += (t7 >> 26); t7 &= 0x3FFFFFFUL; m &= t7;
147 t9 += (t8 >> 26); t8 &= 0x3FFFFFFUL; m &= t8;
153 x = (t9 >> 22) | ((t9 == 0x03FFFFFUL) & (m == 0x3FFFFFFUL)
154 & ((t1 + 0x40UL + ((t0 + 0x3D1UL) >> 26)) > 0x3FFFFFFUL));
157 t0 += 0x3D1UL; t1 += (x << 6);
158 t1 += (t0 >> 26); t0 &= 0x3FFFFFFUL;
159 t2 += (t1 >> 26); t1 &= 0x3FFFFFFUL;
160 t3 += (t2 >> 26); t2 &= 0x3FFFFFFUL;
161 t4 += (t3 >> 26); t3 &= 0x3FFFFFFUL;
162 t5 += (t4 >> 26); t4 &= 0x3FFFFFFUL;
163 t6 += (t5 >> 26); t5 &= 0x3FFFFFFUL;
164 t7 += (t6 >> 26); t6 &= 0x3FFFFFFUL;
165 t8 += (t7 >> 26); t7 &= 0x3FFFFFFUL;
166 t9 += (t8 >> 26); t8 &= 0x3FFFFFFUL;
175 r->
n[0] = t0; r->
n[1] = t1; r->
n[2] = t2; r->
n[3] = t3; r->
n[4] = t4;
176 r->
n[5] = t5; r->
n[6] = t6; r->
n[7] = t7; r->
n[8] = t8; r->
n[9] = t9;
181 secp256k1_fe_verify(r);
186 uint32_t t0 = r->
n[0], t1 = r->
n[1], t2 = r->
n[2], t3 = r->
n[3], t4 = r->
n[4],
187 t5 = r->
n[5], t6 = r->
n[6], t7 = r->
n[7], t8 = r->
n[8], t9 = r->
n[9];
193 uint32_t x = t9 >> 22; t9 &= 0x03FFFFFUL;
196 t0 += x * 0x3D1UL; t1 += (x << 6);
197 t1 += (t0 >> 26); t0 &= 0x3FFFFFFUL; z0 = t0; z1 = t0 ^ 0x3D0UL;
198 t2 += (t1 >> 26); t1 &= 0x3FFFFFFUL; z0 |= t1; z1 &= t1 ^ 0x40UL;
199 t3 += (t2 >> 26); t2 &= 0x3FFFFFFUL; z0 |= t2; z1 &= t2;
200 t4 += (t3 >> 26); t3 &= 0x3FFFFFFUL; z0 |= t3; z1 &= t3;
201 t5 += (t4 >> 26); t4 &= 0x3FFFFFFUL; z0 |= t4; z1 &= t4;
202 t6 += (t5 >> 26); t5 &= 0x3FFFFFFUL; z0 |= t5; z1 &= t5;
203 t7 += (t6 >> 26); t6 &= 0x3FFFFFFUL; z0 |= t6; z1 &= t6;
204 t8 += (t7 >> 26); t7 &= 0x3FFFFFFUL; z0 |= t7; z1 &= t7;
205 t9 += (t8 >> 26); t8 &= 0x3FFFFFFUL; z0 |= t8; z1 &= t8;
206 z0 |= t9; z1 &= t9 ^ 0x3C00000UL;
211 return (z0 == 0) | (z1 == 0x3FFFFFFUL);
215 uint32_t t0, t1, t2, t3, t4, t5, t6, t7, t8, t9;
229 z0 = t0 & 0x3FFFFFFUL;
233 if ((z0 != 0UL) & (z1 != 0x3FFFFFFUL)) {
250 t2 += (t1 >> 26); t1 &= 0x3FFFFFFUL; z0 |= t1; z1 &= t1 ^ 0x40UL;
251 t3 += (t2 >> 26); t2 &= 0x3FFFFFFUL; z0 |= t2; z1 &= t2;
252 t4 += (t3 >> 26); t3 &= 0x3FFFFFFUL; z0 |= t3; z1 &= t3;
253 t5 += (t4 >> 26); t4 &= 0x3FFFFFFUL; z0 |= t4; z1 &= t4;
254 t6 += (t5 >> 26); t5 &= 0x3FFFFFFUL; z0 |= t5; z1 &= t5;
255 t7 += (t6 >> 26); t6 &= 0x3FFFFFFUL; z0 |= t6; z1 &= t6;
256 t8 += (t7 >> 26); t7 &= 0x3FFFFFFUL; z0 |= t7; z1 &= t7;
257 t9 += (t8 >> 26); t8 &= 0x3FFFFFFUL; z0 |= t8; z1 &= t8;
258 z0 |= t9; z1 &= t9 ^ 0x3C00000UL;
263 return (z0 == 0) | (z1 == 0x3FFFFFFUL);
268 r->
n[1] = r->
n[2] = r->
n[3] = r->
n[4] = r->
n[5] = r->
n[6] = r->
n[7] = r->
n[8] = r->
n[9] = 0;
272 secp256k1_fe_verify(r);
277 const uint32_t *t = a->
n;
280 secp256k1_fe_verify(a);
282 return (t[0] | t[1] | t[2] | t[3] | t[4] | t[5] | t[6] | t[7] | t[8] | t[9]) == 0;
288 secp256k1_fe_verify(a);
299 for (i=0; i<10; i++) {
309 secp256k1_fe_verify(a);
310 secp256k1_fe_verify(b);
312 for (i = 9; i >= 0; i--) {
313 if (a->
n[i] > b->
n[i]) {
316 if (a->
n[i] < b->
n[i]) {
325 r->
n[0] = (uint32_t)a[31] | ((uint32_t)a[30] << 8) | ((uint32_t)a[29] << 16) | ((uint32_t)(a[28] & 0x3) << 24);
326 r->
n[1] = (uint32_t)((a[28] >> 2) & 0x3f) | ((uint32_t)a[27] << 6) | ((uint32_t)a[26] << 14) | ((uint32_t)(a[25] & 0xf) << 22);
327 r->
n[2] = (uint32_t)((a[25] >> 4) & 0xf) | ((uint32_t)a[24] << 4) | ((uint32_t)a[23] << 12) | ((uint32_t)(a[22] & 0x3f) << 20);
328 r->
n[3] = (uint32_t)((a[22] >> 6) & 0x3) | ((uint32_t)a[21] << 2) | ((uint32_t)a[20] << 10) | ((uint32_t)a[19] << 18);
329 r->
n[4] = (uint32_t)a[18] | ((uint32_t)a[17] << 8) | ((uint32_t)a[16] << 16) | ((uint32_t)(a[15] & 0x3) << 24);
330 r->
n[5] = (uint32_t)((a[15] >> 2) & 0x3f) | ((uint32_t)a[14] << 6) | ((uint32_t)a[13] << 14) | ((uint32_t)(a[12] & 0xf) << 22);
331 r->
n[6] = (uint32_t)((a[12] >> 4) & 0xf) | ((uint32_t)a[11] << 4) | ((uint32_t)a[10] << 12) | ((uint32_t)(a[9] & 0x3f) << 20);
332 r->
n[7] = (uint32_t)((a[9] >> 6) & 0x3) | ((uint32_t)a[8] << 2) | ((uint32_t)a[7] << 10) | ((uint32_t)a[6] << 18);
333 r->
n[8] = (uint32_t)a[5] | ((uint32_t)a[4] << 8) | ((uint32_t)a[3] << 16) | ((uint32_t)(a[2] & 0x3) << 24);
334 r->
n[9] = (uint32_t)((a[2] >> 2) & 0x3f) | ((uint32_t)a[1] << 6) | ((uint32_t)a[0] << 14);
336 ret = !((r->
n[9] == 0x3FFFFFUL) & ((r->
n[8] & r->
n[7] & r->
n[6] & r->
n[5] & r->
n[4] & r->
n[3] & r->
n[2]) == 0x3FFFFFFUL) & ((r->
n[1] + 0x40UL + ((r->
n[0] + 0x3D1UL) >> 26)) > 0x3FFFFFFUL));
341 secp256k1_fe_verify(r);
353 secp256k1_fe_verify(a);
355 r[0] = (a->
n[9] >> 14) & 0xff;
356 r[1] = (a->
n[9] >> 6) & 0xff;
357 r[2] = ((a->
n[9] & 0x3F) << 2) | ((a->
n[8] >> 24) & 0x3);
358 r[3] = (a->
n[8] >> 16) & 0xff;
359 r[4] = (a->
n[8] >> 8) & 0xff;
360 r[5] = a->
n[8] & 0xff;
361 r[6] = (a->
n[7] >> 18) & 0xff;
362 r[7] = (a->
n[7] >> 10) & 0xff;
363 r[8] = (a->
n[7] >> 2) & 0xff;
364 r[9] = ((a->
n[7] & 0x3) << 6) | ((a->
n[6] >> 20) & 0x3f);
365 r[10] = (a->
n[6] >> 12) & 0xff;
366 r[11] = (a->
n[6] >> 4) & 0xff;
367 r[12] = ((a->
n[6] & 0xf) << 4) | ((a->
n[5] >> 22) & 0xf);
368 r[13] = (a->
n[5] >> 14) & 0xff;
369 r[14] = (a->
n[5] >> 6) & 0xff;
370 r[15] = ((a->
n[5] & 0x3f) << 2) | ((a->
n[4] >> 24) & 0x3);
371 r[16] = (a->
n[4] >> 16) & 0xff;
372 r[17] = (a->
n[4] >> 8) & 0xff;
373 r[18] = a->
n[4] & 0xff;
374 r[19] = (a->
n[3] >> 18) & 0xff;
375 r[20] = (a->
n[3] >> 10) & 0xff;
376 r[21] = (a->
n[3] >> 2) & 0xff;
377 r[22] = ((a->
n[3] & 0x3) << 6) | ((a->
n[2] >> 20) & 0x3f);
378 r[23] = (a->
n[2] >> 12) & 0xff;
379 r[24] = (a->
n[2] >> 4) & 0xff;
380 r[25] = ((a->
n[2] & 0xf) << 4) | ((a->
n[1] >> 22) & 0xf);
381 r[26] = (a->
n[1] >> 14) & 0xff;
382 r[27] = (a->
n[1] >> 6) & 0xff;
383 r[28] = ((a->
n[1] & 0x3f) << 2) | ((a->
n[0] >> 24) & 0x3);
384 r[29] = (a->
n[0] >> 16) & 0xff;
385 r[30] = (a->
n[0] >> 8) & 0xff;
386 r[31] = a->
n[0] & 0xff;
392 secp256k1_fe_verify(a);
394 r->
n[0] = 0x3FFFC2FUL * 2 * (m + 1) - a->
n[0];
395 r->
n[1] = 0x3FFFFBFUL * 2 * (m + 1) - a->
n[1];
396 r->
n[2] = 0x3FFFFFFUL * 2 * (m + 1) - a->
n[2];
397 r->
n[3] = 0x3FFFFFFUL * 2 * (m + 1) - a->
n[3];
398 r->
n[4] = 0x3FFFFFFUL * 2 * (m + 1) - a->
n[4];
399 r->
n[5] = 0x3FFFFFFUL * 2 * (m + 1) - a->
n[5];
400 r->
n[6] = 0x3FFFFFFUL * 2 * (m + 1) - a->
n[6];
401 r->
n[7] = 0x3FFFFFFUL * 2 * (m + 1) - a->
n[7];
402 r->
n[8] = 0x3FFFFFFUL * 2 * (m + 1) - a->
n[8];
403 r->
n[9] = 0x03FFFFFUL * 2 * (m + 1) - a->
n[9];
405 r->magnitude = m + 1;
407 secp256k1_fe_verify(r);
425 secp256k1_fe_verify(r);
431 secp256k1_fe_verify(a);
444 r->magnitude += a->magnitude;
446 secp256k1_fe_verify(r);
450#if defined(USE_EXTERNAL_ASM)
459#define VERIFY_BITS(x, n) VERIFY_CHECK(((x) >> (n)) == 0)
461#define VERIFY_BITS(x, n) do { } while(0)
466 uint64_t u0, u1, u2, u3, u4, u5, u6, u7, u8;
467 uint32_t t9, t1, t0, t2, t3, t4, t5, t6, t7;
468 const uint32_t M = 0x3FFFFFFUL, R0 = 0x3D10UL, R1 = 0x400UL;
497 d = (uint64_t)a[0] * b[9]
498 + (uint64_t)a[1] * b[8]
499 + (uint64_t)a[2] * b[7]
500 + (uint64_t)a[3] * b[6]
501 + (uint64_t)a[4] * b[5]
502 + (uint64_t)a[5] * b[4]
503 + (uint64_t)a[6] * b[3]
504 + (uint64_t)a[7] * b[2]
505 + (uint64_t)a[8] * b[1]
506 + (uint64_t)a[9] * b[0];
509 t9 = d & M; d >>= 26;
514 c = (uint64_t)a[0] * b[0];
517 d += (uint64_t)a[1] * b[9]
518 + (uint64_t)a[2] * b[8]
519 + (uint64_t)a[3] * b[7]
520 + (uint64_t)a[4] * b[6]
521 + (uint64_t)a[5] * b[5]
522 + (uint64_t)a[6] * b[4]
523 + (uint64_t)a[7] * b[3]
524 + (uint64_t)a[8] * b[2]
525 + (uint64_t)a[9] * b[1];
528 u0 = d & M; d >>= 26; c += u0 * R0;
533 t0 = c & M; c >>= 26; c += u0 * R1;
539 c += (uint64_t)a[0] * b[1]
540 + (uint64_t)a[1] * b[0];
543 d += (uint64_t)a[2] * b[9]
544 + (uint64_t)a[3] * b[8]
545 + (uint64_t)a[4] * b[7]
546 + (uint64_t)a[5] * b[6]
547 + (uint64_t)a[6] * b[5]
548 + (uint64_t)a[7] * b[4]
549 + (uint64_t)a[8] * b[3]
550 + (uint64_t)a[9] * b[2];
553 u1 = d & M; d >>= 26; c += u1 * R0;
558 t1 = c & M; c >>= 26; c += u1 * R1;
564 c += (uint64_t)a[0] * b[2]
565 + (uint64_t)a[1] * b[1]
566 + (uint64_t)a[2] * b[0];
569 d += (uint64_t)a[3] * b[9]
570 + (uint64_t)a[4] * b[8]
571 + (uint64_t)a[5] * b[7]
572 + (uint64_t)a[6] * b[6]
573 + (uint64_t)a[7] * b[5]
574 + (uint64_t)a[8] * b[4]
575 + (uint64_t)a[9] * b[3];
578 u2 = d & M; d >>= 26; c += u2 * R0;
583 t2 = c & M; c >>= 26; c += u2 * R1;
589 c += (uint64_t)a[0] * b[3]
590 + (uint64_t)a[1] * b[2]
591 + (uint64_t)a[2] * b[1]
592 + (uint64_t)a[3] * b[0];
595 d += (uint64_t)a[4] * b[9]
596 + (uint64_t)a[5] * b[8]
597 + (uint64_t)a[6] * b[7]
598 + (uint64_t)a[7] * b[6]
599 + (uint64_t)a[8] * b[5]
600 + (uint64_t)a[9] * b[4];
603 u3 = d & M; d >>= 26; c += u3 * R0;
608 t3 = c & M; c >>= 26; c += u3 * R1;
614 c += (uint64_t)a[0] * b[4]
615 + (uint64_t)a[1] * b[3]
616 + (uint64_t)a[2] * b[2]
617 + (uint64_t)a[3] * b[1]
618 + (uint64_t)a[4] * b[0];
621 d += (uint64_t)a[5] * b[9]
622 + (uint64_t)a[6] * b[8]
623 + (uint64_t)a[7] * b[7]
624 + (uint64_t)a[8] * b[6]
625 + (uint64_t)a[9] * b[5];
628 u4 = d & M; d >>= 26; c += u4 * R0;
633 t4 = c & M; c >>= 26; c += u4 * R1;
639 c += (uint64_t)a[0] * b[5]
640 + (uint64_t)a[1] * b[4]
641 + (uint64_t)a[2] * b[3]
642 + (uint64_t)a[3] * b[2]
643 + (uint64_t)a[4] * b[1]
644 + (uint64_t)a[5] * b[0];
647 d += (uint64_t)a[6] * b[9]
648 + (uint64_t)a[7] * b[8]
649 + (uint64_t)a[8] * b[7]
650 + (uint64_t)a[9] * b[6];
653 u5 = d & M; d >>= 26; c += u5 * R0;
658 t5 = c & M; c >>= 26; c += u5 * R1;
664 c += (uint64_t)a[0] * b[6]
665 + (uint64_t)a[1] * b[5]
666 + (uint64_t)a[2] * b[4]
667 + (uint64_t)a[3] * b[3]
668 + (uint64_t)a[4] * b[2]
669 + (uint64_t)a[5] * b[1]
670 + (uint64_t)a[6] * b[0];
673 d += (uint64_t)a[7] * b[9]
674 + (uint64_t)a[8] * b[8]
675 + (uint64_t)a[9] * b[7];
678 u6 = d & M; d >>= 26; c += u6 * R0;
683 t6 = c & M; c >>= 26; c += u6 * R1;
689 c += (uint64_t)a[0] * b[7]
690 + (uint64_t)a[1] * b[6]
691 + (uint64_t)a[2] * b[5]
692 + (uint64_t)a[3] * b[4]
693 + (uint64_t)a[4] * b[3]
694 + (uint64_t)a[5] * b[2]
695 + (uint64_t)a[6] * b[1]
696 + (uint64_t)a[7] * b[0];
700 d += (uint64_t)a[8] * b[9]
701 + (uint64_t)a[9] * b[8];
704 u7 = d & M; d >>= 26; c += u7 * R0;
710 t7 = c & M; c >>= 26; c += u7 * R1;
716 c += (uint64_t)a[0] * b[8]
717 + (uint64_t)a[1] * b[7]
718 + (uint64_t)a[2] * b[6]
719 + (uint64_t)a[3] * b[5]
720 + (uint64_t)a[4] * b[4]
721 + (uint64_t)a[5] * b[3]
722 + (uint64_t)a[6] * b[2]
723 + (uint64_t)a[7] * b[1]
724 + (uint64_t)a[8] * b[0];
728 d += (uint64_t)a[9] * b[9];
731 u8 = d & M; d >>= 26; c += u8 * R0;
754 r[8] = c & M; c >>= 26; c += u8 * R1;
762 r[9] = c & (M >> 4); c >>= 22; c += d * (R1 << 4);
769 d = c * (R0 >> 4) + t0;
772 r[0] = d & M; d >>= 26;
776 d += c * (R1 >> 4) + t1;
781 r[1] = d & M; d >>= 26;
796 uint64_t u0, u1, u2, u3, u4, u5, u6, u7, u8;
797 uint32_t t9, t0, t1, t2, t3, t4, t5, t6, t7;
798 const uint32_t M = 0x3FFFFFFUL, R0 = 0x3D10UL, R1 = 0x400UL;
816 d = (uint64_t)(a[0]*2) * a[9]
817 + (uint64_t)(a[1]*2) * a[8]
818 + (uint64_t)(a[2]*2) * a[7]
819 + (uint64_t)(a[3]*2) * a[6]
820 + (uint64_t)(a[4]*2) * a[5];
823 t9 = d & M; d >>= 26;
828 c = (uint64_t)a[0] * a[0];
831 d += (uint64_t)(a[1]*2) * a[9]
832 + (uint64_t)(a[2]*2) * a[8]
833 + (uint64_t)(a[3]*2) * a[7]
834 + (uint64_t)(a[4]*2) * a[6]
835 + (uint64_t)a[5] * a[5];
838 u0 = d & M; d >>= 26; c += u0 * R0;
843 t0 = c & M; c >>= 26; c += u0 * R1;
849 c += (uint64_t)(a[0]*2) * a[1];
852 d += (uint64_t)(a[2]*2) * a[9]
853 + (uint64_t)(a[3]*2) * a[8]
854 + (uint64_t)(a[4]*2) * a[7]
855 + (uint64_t)(a[5]*2) * a[6];
858 u1 = d & M; d >>= 26; c += u1 * R0;
863 t1 = c & M; c >>= 26; c += u1 * R1;
869 c += (uint64_t)(a[0]*2) * a[2]
870 + (uint64_t)a[1] * a[1];
873 d += (uint64_t)(a[3]*2) * a[9]
874 + (uint64_t)(a[4]*2) * a[8]
875 + (uint64_t)(a[5]*2) * a[7]
876 + (uint64_t)a[6] * a[6];
879 u2 = d & M; d >>= 26; c += u2 * R0;
884 t2 = c & M; c >>= 26; c += u2 * R1;
890 c += (uint64_t)(a[0]*2) * a[3]
891 + (uint64_t)(a[1]*2) * a[2];
894 d += (uint64_t)(a[4]*2) * a[9]
895 + (uint64_t)(a[5]*2) * a[8]
896 + (uint64_t)(a[6]*2) * a[7];
899 u3 = d & M; d >>= 26; c += u3 * R0;
904 t3 = c & M; c >>= 26; c += u3 * R1;
910 c += (uint64_t)(a[0]*2) * a[4]
911 + (uint64_t)(a[1]*2) * a[3]
912 + (uint64_t)a[2] * a[2];
915 d += (uint64_t)(a[5]*2) * a[9]
916 + (uint64_t)(a[6]*2) * a[8]
917 + (uint64_t)a[7] * a[7];
920 u4 = d & M; d >>= 26; c += u4 * R0;
925 t4 = c & M; c >>= 26; c += u4 * R1;
931 c += (uint64_t)(a[0]*2) * a[5]
932 + (uint64_t)(a[1]*2) * a[4]
933 + (uint64_t)(a[2]*2) * a[3];
936 d += (uint64_t)(a[6]*2) * a[9]
937 + (uint64_t)(a[7]*2) * a[8];
940 u5 = d & M; d >>= 26; c += u5 * R0;
945 t5 = c & M; c >>= 26; c += u5 * R1;
951 c += (uint64_t)(a[0]*2) * a[6]
952 + (uint64_t)(a[1]*2) * a[5]
953 + (uint64_t)(a[2]*2) * a[4]
954 + (uint64_t)a[3] * a[3];
957 d += (uint64_t)(a[7]*2) * a[9]
958 + (uint64_t)a[8] * a[8];
961 u6 = d & M; d >>= 26; c += u6 * R0;
966 t6 = c & M; c >>= 26; c += u6 * R1;
972 c += (uint64_t)(a[0]*2) * a[7]
973 + (uint64_t)(a[1]*2) * a[6]
974 + (uint64_t)(a[2]*2) * a[5]
975 + (uint64_t)(a[3]*2) * a[4];
979 d += (uint64_t)(a[8]*2) * a[9];
982 u7 = d & M; d >>= 26; c += u7 * R0;
988 t7 = c & M; c >>= 26; c += u7 * R1;
994 c += (uint64_t)(a[0]*2) * a[8]
995 + (uint64_t)(a[1]*2) * a[7]
996 + (uint64_t)(a[2]*2) * a[6]
997 + (uint64_t)(a[3]*2) * a[5]
998 + (uint64_t)a[4] * a[4];
1002 d += (uint64_t)a[9] * a[9];
1005 u8 = d & M; d >>= 26; c += u8 * R0;
1028 r[8] = c & M; c >>= 26; c += u8 * R1;
1036 r[9] = c & (M >> 4); c >>= 22; c += d * (R1 << 4);
1043 d = c * (R0 >> 4) + t0;
1046 r[0] = d & M; d >>= 26;
1050 d += c * (R1 >> 4) + t1;
1055 r[1] = d & M; d >>= 26;
1073 secp256k1_fe_verify(a);
1074 secp256k1_fe_verify(b);
1082 secp256k1_fe_verify(r);
1089 secp256k1_fe_verify(a);
1095 secp256k1_fe_verify(r);
1100 uint32_t mask0, mask1;
1102 mask0 = flag + ~((uint32_t)0);
1104 r->
n[0] = (r->
n[0] & mask0) | (a->
n[0] & mask1);
1105 r->
n[1] = (r->
n[1] & mask0) | (a->
n[1] & mask1);
1106 r->
n[2] = (r->
n[2] & mask0) | (a->
n[2] & mask1);
1107 r->
n[3] = (r->
n[3] & mask0) | (a->
n[3] & mask1);
1108 r->
n[4] = (r->
n[4] & mask0) | (a->
n[4] & mask1);
1109 r->
n[5] = (r->
n[5] & mask0) | (a->
n[5] & mask1);
1110 r->
n[6] = (r->
n[6] & mask0) | (a->
n[6] & mask1);
1111 r->
n[7] = (r->
n[7] & mask0) | (a->
n[7] & mask1);
1112 r->
n[8] = (r->
n[8] & mask0) | (a->
n[8] & mask1);
1113 r->
n[9] = (r->
n[9] & mask0) | (a->
n[9] & mask1);
1116 r->magnitude = a->magnitude;
1117 r->normalized = a->normalized;
1123 uint32_t mask0, mask1;
1125 mask0 = flag + ~((uint32_t)0);
1127 r->
n[0] = (r->
n[0] & mask0) | (a->
n[0] & mask1);
1128 r->
n[1] = (r->
n[1] & mask0) | (a->
n[1] & mask1);
1129 r->
n[2] = (r->
n[2] & mask0) | (a->
n[2] & mask1);
1130 r->
n[3] = (r->
n[3] & mask0) | (a->
n[3] & mask1);
1131 r->
n[4] = (r->
n[4] & mask0) | (a->
n[4] & mask1);
1132 r->
n[5] = (r->
n[5] & mask0) | (a->
n[5] & mask1);
1133 r->
n[6] = (r->
n[6] & mask0) | (a->
n[6] & mask1);
1134 r->
n[7] = (r->
n[7] & mask0) | (a->
n[7] & mask1);
1141 r->
n[0] = a->
n[0] | a->
n[1] << 26;
1142 r->
n[1] = a->
n[1] >> 6 | a->
n[2] << 20;
1143 r->
n[2] = a->
n[2] >> 12 | a->
n[3] << 14;
1144 r->
n[3] = a->
n[3] >> 18 | a->
n[4] << 8;
1145 r->
n[4] = a->
n[4] >> 24 | a->
n[5] << 2 | a->
n[6] << 28;
1146 r->
n[5] = a->
n[6] >> 4 | a->
n[7] << 22;
1147 r->
n[6] = a->
n[7] >> 10 | a->
n[8] << 16;
1148 r->
n[7] = a->
n[8] >> 16 | a->
n[9] << 10;
1152 r->
n[0] = a->
n[0] & 0x3FFFFFFUL;
1153 r->
n[1] = a->
n[0] >> 26 | ((a->
n[1] << 6) & 0x3FFFFFFUL);
1154 r->
n[2] = a->
n[1] >> 20 | ((a->
n[2] << 12) & 0x3FFFFFFUL);
1155 r->
n[3] = a->
n[2] >> 14 | ((a->
n[3] << 18) & 0x3FFFFFFUL);
1156 r->
n[4] = a->
n[3] >> 8 | ((a->
n[4] << 24) & 0x3FFFFFFUL);
1157 r->
n[5] = (a->
n[4] >> 2) & 0x3FFFFFFUL;
1158 r->
n[6] = a->
n[4] >> 28 | ((a->
n[5] << 4) & 0x3FFFFFFUL);
1159 r->
n[7] = a->
n[5] >> 22 | ((a->
n[6] << 10) & 0x3FFFFFFUL);
1160 r->
n[8] = a->
n[6] >> 16 | ((a->
n[7] << 16) & 0x3FFFFFFUL);
1161 r->
n[9] = a->
n[7] >> 10;
1169 const uint32_t M26 = UINT32_MAX >> 6;
1170 const uint32_t a0 = a->
v[0], a1 = a->
v[1], a2 = a->
v[2], a3 = a->
v[3], a4 = a->
v[4],
1171 a5 = a->
v[5], a6 = a->
v[6], a7 = a->
v[7], a8 = a->
v[8];
1187 r->
n[1] = (a0 >> 26 | a1 << 4) & M26;
1188 r->
n[2] = (a1 >> 22 | a2 << 8) & M26;
1189 r->
n[3] = (a2 >> 18 | a3 << 12) & M26;
1190 r->
n[4] = (a3 >> 14 | a4 << 16) & M26;
1191 r->
n[5] = (a4 >> 10 | a5 << 20) & M26;
1192 r->
n[6] = (a5 >> 6 | a6 << 24) & M26;
1193 r->
n[7] = (a6 >> 2 ) & M26;
1194 r->
n[8] = (a6 >> 28 | a7 << 2) & M26;
1195 r->
n[9] = (a7 >> 24 | a8 << 6);
1200 secp256k1_fe_verify(r);
1205 const uint32_t M30 = UINT32_MAX >> 2;
1206 const uint64_t a0 = a->
n[0], a1 = a->
n[1], a2 = a->
n[2], a3 = a->
n[3], a4 = a->
n[4],
1207 a5 = a->
n[5], a6 = a->
n[6], a7 = a->
n[7], a8 = a->
n[8], a9 = a->
n[9];
1213 r->
v[0] = (a0 | a1 << 26) & M30;
1214 r->
v[1] = (a1 >> 4 | a2 << 22) & M30;
1215 r->
v[2] = (a2 >> 8 | a3 << 18) & M30;
1216 r->
v[3] = (a3 >> 12 | a4 << 14) & M30;
1217 r->
v[4] = (a4 >> 16 | a5 << 10) & M30;
1218 r->
v[5] = (a5 >> 20 | a6 << 6) & M30;
1219 r->
v[6] = (a6 >> 24 | a7 << 2
1221 r->
v[7] = (a8 >> 2 | a9 << 24) & M30;
1226 {{-0x3D1, -4, 0, 0, 0, 0, 0, 0, 65536}},
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 void secp256k1_fe_sqr_inner(uint32_t *r, const uint32_t *a)
static const secp256k1_modinv32_modinfo secp256k1_const_modinfo_fe
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 SECP256K1_INLINE void secp256k1_fe_mul_inner(uint32_t *r, const uint32_t *a, const uint32_t *SECP256K1_RESTRICT b)
static int secp256k1_fe_set_b32(secp256k1_fe *r, const unsigned char *a)
static void secp256k1_fe_from_signed30(secp256k1_fe *r, const secp256k1_modinv32_signed30 *a)
static SECP256K1_INLINE void secp256k1_fe_storage_cmov(secp256k1_fe_storage *r, const secp256k1_fe_storage *a, int flag)
static int secp256k1_fe_normalizes_to_zero_var(secp256k1_fe *r)
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 SECP256K1_INLINE void secp256k1_fe_negate(secp256k1_fe *r, const secp256k1_fe *a, int m)
static void secp256k1_fe_normalize(secp256k1_fe *r)
#define VERIFY_BITS(x, n)
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_to_signed30(secp256k1_modinv32_signed30 *r, const secp256k1_fe *a)
static int secp256k1_fe_normalizes_to_zero(secp256k1_fe *r)
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_modinv32_var(secp256k1_modinv32_signed30 *x, const secp256k1_modinv32_modinfo *modinfo)
static void secp256k1_modinv32(secp256k1_modinv32_signed30 *x, const secp256k1_modinv32_modinfo *modinfo)
#define VG_CHECK_VERIFY(x, y)
#define VERIFY_CHECK(cond)
#define SECP256K1_RESTRICT