From 2cb3eea92244ce03eedc617c09e776565f1a77fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Mon, 4 Nov 2019 14:43:35 +0100 Subject: [PATCH] Hardcode numwords in vli_cmp --- include/tinycrypt/ecc.h | 3 +-- tinycrypt/ecc.c | 8 +++----- tinycrypt/ecc_dsa.c | 2 +- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/include/tinycrypt/ecc.h b/include/tinycrypt/ecc.h index 74c096053..c4dad0bb6 100644 --- a/include/tinycrypt/ecc.h +++ b/include/tinycrypt/ecc.h @@ -320,8 +320,7 @@ uECC_word_t EccPoint_isZero(const uECC_word_t *point, uECC_Curve curve); * @param num_words IN -- number of words * @return the sign of left - right */ -cmpresult_t uECC_vli_cmp(const uECC_word_t *left, const uECC_word_t *right, - wordcount_t num_words); +cmpresult_t uECC_vli_cmp(const uECC_word_t *left, const uECC_word_t *right); /* * @brief computes sign of left - right, not in constant time. diff --git a/tinycrypt/ecc.c b/tinycrypt/ecc.c index 47acf2a70..10d3972b6 100644 --- a/tinycrypt/ecc.c +++ b/tinycrypt/ecc.c @@ -226,13 +226,11 @@ static uECC_word_t uECC_vli_add(uECC_word_t *result, const uECC_word_t *left, return carry; } -cmpresult_t uECC_vli_cmp(const uECC_word_t *left, const uECC_word_t *right, - wordcount_t num_words) +cmpresult_t uECC_vli_cmp(const uECC_word_t *left, const uECC_word_t *right) { uECC_word_t tmp[NUM_ECC_WORDS]; uECC_word_t neg = !!uECC_vli_sub(tmp, left, right); uECC_word_t equal = uECC_vli_isZero(tmp); - (void) num_words; return (!equal - 2 * neg); } @@ -1039,7 +1037,7 @@ int uECC_generate_random_int(uECC_word_t *random, const uECC_word_t *top, random[num_words - 1] &= mask >> ((bitcount_t)(num_words * uECC_WORD_SIZE * 8 - num_bits)); if (!uECC_vli_isZero(random) && - uECC_vli_cmp(top, random, num_words) == 1) { + uECC_vli_cmp(top, random) == 1) { return 1; } } @@ -1109,7 +1107,7 @@ int uECC_compute_public_key(const uint8_t *private_key, uint8_t *public_key, return 0; } - if (uECC_vli_cmp(curve->n, _private, BITS_TO_WORDS(curve->num_n_bits)) != 1) { + if (uECC_vli_cmp(curve->n, _private) != 1) { return 0; } diff --git a/tinycrypt/ecc_dsa.c b/tinycrypt/ecc_dsa.c index 1685c208a..8cc09c76f 100644 --- a/tinycrypt/ecc_dsa.c +++ b/tinycrypt/ecc_dsa.c @@ -121,7 +121,7 @@ int uECC_sign_with_k(const uint8_t *private_key, const uint8_t *message_hash, /* Make sure 0 < k < curve_n */ if (uECC_vli_isZero(k) || - uECC_vli_cmp(curve->n, k, num_n_words) != 1) { + uECC_vli_cmp(curve->n, k) != 1) { return 0; }