Hardcode numwords in vli_mmod

This commit is contained in:
Manuel Pégourié-Gonnard 2019-11-04 14:57:53 +01:00
parent 1b0875d863
commit 10349e4912
4 changed files with 7 additions and 5 deletions

View file

@ -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)

View file

@ -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,

View file

@ -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)) {

View file

@ -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)) {