diff options
Diffstat (limited to 'src/field_impl.h')
-rw-r--r-- | src/field_impl.h | 32 |
1 files changed, 4 insertions, 28 deletions
diff --git a/src/field_impl.h b/src/field_impl.h index 4d25e53715..24d3104ed1 100644 --- a/src/field_impl.h +++ b/src/field_impl.h @@ -66,7 +66,7 @@ static int secp256k1_fe_set_hex(secp256k1_fe_t *r, const char *a, int alen) { return secp256k1_fe_set_b32(r, tmp); } -static int secp256k1_fe_sqrt(secp256k1_fe_t *r, const secp256k1_fe_t *a) { +static int secp256k1_fe_sqrt_var(secp256k1_fe_t *r, const secp256k1_fe_t *a) { /** The binary representation of (p + 1)/4 has 3 blocks of 1s, with lengths in * { 2, 22, 223 }. Use an addition chain to calculate 2^n - 1 for each block: @@ -132,7 +132,7 @@ static int secp256k1_fe_sqrt(secp256k1_fe_t *r, const secp256k1_fe_t *a) { secp256k1_fe_sqr(&t1, r); secp256k1_fe_negate(&t1, &t1, 1); secp256k1_fe_add(&t1, a); - secp256k1_fe_normalize(&t1); + secp256k1_fe_normalize_var(&t1); return secp256k1_fe_is_zero(&t1); } @@ -206,7 +206,7 @@ static void secp256k1_fe_inv_var(secp256k1_fe_t *r, const secp256k1_fe_t *a) { #elif defined(USE_FIELD_INV_NUM) unsigned char b[32]; secp256k1_fe_t c = *a; - secp256k1_fe_normalize(&c); + secp256k1_fe_normalize_var(&c); secp256k1_fe_get_b32(b, &c); secp256k1_num_t n; secp256k1_num_set_bin(&n, b, 32); @@ -218,30 +218,6 @@ static void secp256k1_fe_inv_var(secp256k1_fe_t *r, const secp256k1_fe_t *a) { #endif } -static void secp256k1_fe_inv_all(size_t len, secp256k1_fe_t r[len], const secp256k1_fe_t a[len]) { - if (len < 1) - return; - - VERIFY_CHECK((r + len <= a) || (a + len <= r)); - - r[0] = a[0]; - - size_t i = 0; - while (++i < len) { - secp256k1_fe_mul(&r[i], &r[i - 1], &a[i]); - } - - secp256k1_fe_t u; secp256k1_fe_inv(&u, &r[--i]); - - while (i > 0) { - int j = i--; - secp256k1_fe_mul(&r[j], &r[i], &u); - secp256k1_fe_mul(&u, &u, &a[j]); - } - - r[0] = u; -} - static void secp256k1_fe_inv_all_var(size_t len, secp256k1_fe_t r[len], const secp256k1_fe_t a[len]) { if (len < 1) return; @@ -277,7 +253,7 @@ static void secp256k1_fe_start(void) { #endif if (secp256k1_fe_consts == NULL) { secp256k1_fe_inner_start(); - secp256k1_fe_consts_t *ret = (secp256k1_fe_consts_t*)malloc(sizeof(secp256k1_fe_consts_t)); + secp256k1_fe_consts_t *ret = (secp256k1_fe_consts_t*)checked_malloc(sizeof(secp256k1_fe_consts_t)); #ifndef USE_NUM_NONE secp256k1_num_set_bin(&ret->p, secp256k1_fe_consts_p, sizeof(secp256k1_fe_consts_p)); #endif |