diff --git a/include/tinycrypt/ecc.h b/include/tinycrypt/ecc.h index 3d60267cc..e016c696b 100644 --- a/include/tinycrypt/ecc.h +++ b/include/tinycrypt/ecc.h @@ -386,7 +386,7 @@ uECC_word_t uECC_vli_testBit(const uECC_word_t *vli, bitcount_t bit); * @warning Currently only designed to work for curve_p or curve_n. */ void uECC_vli_mmod(uECC_word_t *result, uECC_word_t *product, - const uECC_word_t *mod, wordcount_t num_words); + const uECC_word_t *mod); /* * @brief Computes modular product (using curve->mmod_fast) diff --git a/tinycrypt/ecc.c b/tinycrypt/ecc.c index e7558e9a0..508831cb2 100644 --- a/tinycrypt/ecc.c +++ b/tinycrypt/ecc.c @@ -444,12 +444,13 @@ void uECC_vli_modSub(uECC_word_t *result, const uECC_word_t *left, /* Computes result = product % mod, where product is 2N words long. */ /* Currently only designed to work for curve_p or curve_n. */ void uECC_vli_mmod(uECC_word_t *result, uECC_word_t *product, - const uECC_word_t *mod, wordcount_t num_words) + const uECC_word_t *mod) { uECC_word_t mod_multiple[2 * NUM_ECC_WORDS]; uECC_word_t tmp[2 * NUM_ECC_WORDS]; uECC_word_t *v[2] = {tmp, product}; uECC_word_t index; + const wordcount_t num_words = NUM_ECC_WORDS; /* Shift mod so its highest set bit is at the maximum position. */ bitcount_t shift = (num_words * 2 * uECC_WORD_BITS) - @@ -493,7 +494,8 @@ void uECC_vli_modMult(uECC_word_t *result, const uECC_word_t *left, { uECC_word_t product[2 * NUM_ECC_WORDS]; uECC_vli_mult_rnd(product, left, right, NULL); - uECC_vli_mmod(result, product, mod, num_words); + uECC_vli_mmod(result, product, mod); + (void) num_words; } static void uECC_vli_modMult_rnd(uECC_word_t *result, const uECC_word_t *left, diff --git a/tinycrypt/ecc_dh.c b/tinycrypt/ecc_dh.c index 52208ad9d..71c51f5a8 100644 --- a/tinycrypt/ecc_dh.c +++ b/tinycrypt/ecc_dh.c @@ -123,7 +123,7 @@ int uECC_make_key(uint8_t *public_key, uint8_t *private_key, uECC_Curve curve) } /* computing modular reduction of _random (see FIPS 186.4 B.4.1): */ - uECC_vli_mmod(_private, _random, curve->n, BITS_TO_WORDS(curve->num_n_bits)); + uECC_vli_mmod(_private, _random, curve->n); /* Computing public-key from private: */ if (EccPoint_compute_public_key(_public, _private, curve)) { diff --git a/tinycrypt/ecc_dsa.c b/tinycrypt/ecc_dsa.c index 77e3efee7..ca07eb191 100644 --- a/tinycrypt/ecc_dsa.c +++ b/tinycrypt/ecc_dsa.c @@ -182,7 +182,7 @@ int uECC_sign(const uint8_t *private_key, const uint8_t *message_hash, } // computing k as modular reduction of _random (see FIPS 186.4 B.5.1): - uECC_vli_mmod(k, _random, curve->n, BITS_TO_WORDS(curve->num_n_bits)); + uECC_vli_mmod(k, _random, curve->n); if (uECC_sign_with_k(private_key, message_hash, hash_size, k, signature, curve)) {