7 #ifndef SECP256K1_NUM_REPR_IMPL_H 8 #define SECP256K1_NUM_REPR_IMPL_H 22 #define secp256k1_num_sanity(a) do { } while(0) 29 static void secp256k1_num_get_bin(
unsigned char *r,
unsigned int rlen,
const secp256k1_num *
a) {
30 unsigned char tmp[65];
34 len = mpn_get_str(tmp, 256, (mp_limb_t*)a->
data, a->
limbs);
36 while (shift < len && tmp[shift] == 0) shift++;
38 memset(r, 0, rlen - len + shift);
40 memcpy(r + rlen - len + shift, tmp + shift, len - shift);
42 memset(tmp, 0,
sizeof(tmp));
45 static void secp256k1_num_set_bin(
secp256k1_num *r,
const unsigned char *a,
unsigned int alen) {
49 len = mpn_set_str(r->
data, a, alen, 256);
88 memset(t, 0,
sizeof(t));
96 secp256k1_num_sub_abs(r, m, r);
123 for (i = 0; i < m->
limbs; i++) {
142 memset(g, 0,
sizeof(g));
143 memset(u, 0,
sizeof(u));
144 memset(v, 0,
sizeof(v));
154 mpz_inits(ga, gb, NULL);
156 mpz_import(gb, b->
limbs, -1,
sizeof(mp_limb_t), 0, 0, b->
data);
157 mpz_import(ga, a->
limbs, -1,
sizeof(mp_limb_t), 0, 0, a->
data);
162 ret = mpz_jacobi(ga, gb);
164 mpz_clears(ga, gb, NULL);
170 return (a->
limbs == 1 && a->
data[0] == 1);
174 return (a->
limbs == 1 && a->
data[0] == 0);
198 if ((a->
neg && !secp256k1_num_is_zero(a)) != (b->
neg && !secp256k1_num_is_zero(b))) {
205 if (!(b->
neg ^ bneg ^ a->
neg)) {
208 secp256k1_num_add_abs(r, a, b);
210 secp256k1_num_add_abs(r, b, a);
213 if (secp256k1_num_cmp(a, b) > 0) {
215 secp256k1_num_sub_abs(r, a, b);
218 secp256k1_num_sub_abs(r, b, a);
226 secp256k1_num_subadd(r, a, b, 0);
232 secp256k1_num_subadd(r, a, b, 1);
259 memset(tmp, 0,
sizeof(tmp));
262 static void secp256k1_num_shift(
secp256k1_num *r,
int bits) {
263 if (bits % GMP_NUMB_BITS) {
265 mpn_rshift(r->
data, r->
data, r->
limbs, bits % GMP_NUMB_BITS);
267 if (bits >= GMP_NUMB_BITS) {
270 for (i = 0; i < r->
limbs; i++) {
271 int index = i + (bits / GMP_NUMB_BITS);
272 if (index < r->limbs && index < 2*
NUM_LIMBS) {
#define VERIFY_CHECK(cond)
mp_limb_t data[2 *NUM_LIMBS]
#define secp256k1_num_sanity(a)
void * memcpy(void *a, const void *b, size_t c)