From e37ba822e627550a453a1678d180f7e056b3d98f Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Tue, 17 Mar 2015 14:15:38 +0100 Subject: [PATCH] bn_substract -> bn_subtractmod, bn_substract_noprime -> bn_subtract remove dead code --- bignum.c | 27 ++------------------------- bignum.h | 8 ++------ ecdsa.c | 16 ++++++++-------- 3 files changed, 12 insertions(+), 39 deletions(-) diff --git a/bignum.c b/bignum.c index 60846195aa..7c1484962c 100644 --- a/bignum.c +++ b/bignum.c @@ -154,29 +154,6 @@ void bn_mod(bignum256 *x, const bignum256 *prime) } } -// a = a + b -void bn_addi(bignum256 *a, uint32_t b) -{ - uint64_t t = a->val[0]; - t += b; - a->val[0] = t & 0x3FFFFFFFu; - t >>= 30; - a->val[1] += t; -} - -// a = a * b -void bn_muli(bignum256 *a, uint32_t b) -{ - uint64_t t = 0; - int i; - for (i = 0; i < 8; i++) { - t = (uint64_t)(a->val[i]) * b + t; - a->val[i] = t & 0x3FFFFFFFu; - t >>= 30; - } - a->val[8] += t; -} - // Compute x := k * x (mod prime) // both inputs must be smaller than 2 * prime. // result is reduced to 0 <= x < 2 * prime @@ -657,7 +634,7 @@ void bn_addmodi(bignum256 *a, uint32_t b, const bignum256 *prime) { // res = a - b // b < 2*prime; result not normalized -void bn_substract(const bignum256 *a, const bignum256 *b, bignum256 *res) +void bn_subtractmod(const bignum256 *a, const bignum256 *b, bignum256 *res) { int i; uint32_t temp = 0; @@ -669,7 +646,7 @@ void bn_substract(const bignum256 *a, const bignum256 *b, bignum256 *res) } // res = a - b ; a > b -void bn_substract_noprime(const bignum256 *a, const bignum256 *b, bignum256 *res) +void bn_subtract(const bignum256 *a, const bignum256 *b, bignum256 *res) { int i; uint32_t tmp = 1; diff --git a/bignum.h b/bignum.h index 168354643c..de71fba0eb 100644 --- a/bignum.h +++ b/bignum.h @@ -59,10 +59,6 @@ void bn_rshift(bignum256 *a); void bn_mod(bignum256 *x, const bignum256 *prime); -void bn_addi(bignum256 *a, uint32_t b); - -void bn_muli(bignum256 *a, uint32_t b); - void bn_multiply(const bignum256 *k, bignum256 *x, const bignum256 *prime); void bn_fast_mod(bignum256 *x, const bignum256 *prime); @@ -77,9 +73,9 @@ void bn_addmod(bignum256 *a, const bignum256 *b, const bignum256 *prime); void bn_addmodi(bignum256 *a, uint32_t b, const bignum256 *prime); -void bn_substract(const bignum256 *a, const bignum256 *b, bignum256 *res); +void bn_subtractmod(const bignum256 *a, const bignum256 *b, bignum256 *res); -void bn_substract_noprime(const bignum256 *a, const bignum256 *b, bignum256 *res); +void bn_subtract(const bignum256 *a, const bignum256 *b, bignum256 *res); void bn_divmod58(bignum256 *a, uint32_t *r); diff --git a/ecdsa.c b/ecdsa.c index 831098cb22..0c5b5a625b 100644 --- a/ecdsa.c +++ b/ecdsa.c @@ -63,9 +63,9 @@ void point_add(const curve_point *cp1, curve_point *cp2) return; } - bn_substract(&(cp2->x), &(cp1->x), &inv); + bn_subtractmod(&(cp2->x), &(cp1->x), &inv); bn_inverse(&inv, &prime256k1); - bn_substract(&(cp2->y), &(cp1->y), &lambda); + bn_subtractmod(&(cp2->y), &(cp1->y), &lambda); bn_multiply(&inv, &lambda, &prime256k1); memcpy(&xr, &lambda, sizeof(bignum256)); bn_multiply(&xr, &xr, &prime256k1); @@ -76,11 +76,11 @@ void point_add(const curve_point *cp1, curve_point *cp2) temp >>= 30; } bn_fast_mod(&xr, &prime256k1); - bn_substract(&(cp1->x), &xr, &yr); + bn_subtractmod(&(cp1->x), &xr, &yr); // no need to fast_mod here // bn_fast_mod(&yr); bn_multiply(&lambda, &yr, &prime256k1); - bn_substract(&yr, &(cp1->y), &yr); + bn_subtractmod(&yr, &(cp1->y), &yr); bn_fast_mod(&yr, &prime256k1); memcpy(&(cp2->x), &xr, sizeof(bignum256)); memcpy(&(cp2->y), &yr, sizeof(bignum256)); @@ -118,11 +118,11 @@ void point_double(curve_point *cp) temp >>= 30; } bn_fast_mod(&xr, &prime256k1); - bn_substract(&(cp->x), &xr, &yr); + bn_subtractmod(&(cp->x), &xr, &yr); // no need to fast_mod here // bn_fast_mod(&yr); bn_multiply(&lambda, &yr, &prime256k1); - bn_substract(&yr, &(cp->y), &yr); + bn_subtractmod(&yr, &(cp->y), &yr); bn_fast_mod(&yr, &prime256k1); memcpy(&(cp->x), &xr, sizeof(bignum256)); memcpy(&(cp->y), &yr, sizeof(bignum256)); @@ -363,7 +363,7 @@ int ecdsa_sign_digest(const uint8_t *priv_key, const uint8_t *digest, uint8_t *s // if S > order/2 => S = -S if (bn_is_less(&order256k1_half, &k)) { - bn_substract_noprime(&order256k1, &k, &k); + bn_subtract(&order256k1, &k, &k); if (pby) { *pby = !*pby; } @@ -451,7 +451,7 @@ void uncompress_coords(uint8_t odd, const bignum256 *x, bignum256 *y) bn_addmodi(y, 7, &prime256k1); // y is x^3 + 7 bn_sqrt(y, &prime256k1); // y = sqrt(y) if ((odd & 0x01) != (y->val[0] & 1)) { - bn_substract_noprime(&prime256k1, y, y); // y = -y + bn_subtract(&prime256k1, y, y); // y = -y } }