Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
field_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_IMPL_H
8#define SECP256K1_FIELD_IMPL_H
9
10#if defined HAVE_CONFIG_H
11#include "libsecp256k1-config.h"
12#endif
13
14#include "util.h"
15
16#if defined(SECP256K1_WIDEMUL_INT128)
17#include "field_5x52_impl.h"
18#elif defined(SECP256K1_WIDEMUL_INT64)
19#include "field_10x26_impl.h"
20#else
21#error "Please select wide multiplication implementation"
22#endif
23
30
37
49 int j;
50
51 VERIFY_CHECK(r != a);
52
60
63
64 x6 = x3;
65 for (j=0; j<3; j++) {
67 }
69
70 x9 = x6;
71 for (j=0; j<3; j++) {
73 }
75
76 x11 = x9;
77 for (j=0; j<2; j++) {
79 }
81
82 x22 = x11;
83 for (j=0; j<11; j++) {
85 }
87
88 x44 = x22;
89 for (j=0; j<22; j++) {
91 }
93
94 x88 = x44;
95 for (j=0; j<44; j++) {
97 }
99
100 x176 = x88;
101 for (j=0; j<88; j++) {
103 }
105
106 x220 = x176;
107 for (j=0; j<44; j++) {
109 }
111
112 x223 = x220;
113 for (j=0; j<3; j++) {
115 }
117
118 /* The final result is then assembled using a sliding window over the blocks. */
119
120 t1 = x223;
121 for (j=0; j<23; j++) {
123 }
125 for (j=0; j<6; j++) {
127 }
128 secp256k1_fe_mul(&t1, &t1, &x2);
130 secp256k1_fe_sqr(r, &t1);
131
132 /* Check that a square root was actually calculated */
133
134 secp256k1_fe_sqr(&t1, r);
135 return secp256k1_fe_equal(&t1, a);
136}
137
139 secp256k1_fe r;
140 return secp256k1_fe_sqrt(&r, a);
141}
142
143static const secp256k1_fe secp256k1_fe_one = SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 1);
144
145#endif /* SECP256K1_FIELD_IMPL_H */
static void secp256k1_fe_negate(secp256k1_fe *r, const secp256k1_fe *a, int m)
Set a field element equal to the additive inverse of another.
static void secp256k1_fe_mul(secp256k1_fe *r, const secp256k1_fe *a, const secp256k1_fe *SECP256K1_RESTRICT b)
Sets a field element to be the product of two others.
static int secp256k1_fe_normalizes_to_zero_var(secp256k1_fe *r)
Verify whether a field element represents zero i.e.
static void secp256k1_fe_sqr(secp256k1_fe *r, const secp256k1_fe *a)
Sets a field element to be the square of another.
static void secp256k1_fe_add(secp256k1_fe *r, const secp256k1_fe *a)
Adds a field element to another.
static int secp256k1_fe_normalizes_to_zero(secp256k1_fe *r)
Verify whether a field element represents zero i.e.
#define SECP256K1_FE_CONST(d7, d6, d5, d4, d3, d2, d1, d0)
Definition field_10x26.h:40
static int secp256k1_fe_is_quad_var(const secp256k1_fe *a)
Definition field_impl.h:138
static int secp256k1_fe_sqrt(secp256k1_fe *r, const secp256k1_fe *a)
Definition field_impl.h:38
static SECP256K1_INLINE int secp256k1_fe_equal_var(const secp256k1_fe *a, const secp256k1_fe *b)
Definition field_impl.h:31
static const secp256k1_fe secp256k1_fe_one
Definition field_impl.h:143
static SECP256K1_INLINE int secp256k1_fe_equal(const secp256k1_fe *a, const secp256k1_fe *b)
Definition field_impl.h:24
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition random.h:85
#define VERIFY_CHECK(cond)
Definition util.h:68
#define SECP256K1_INLINE
Definition secp256k1.h:127