diff --git a/include/tinycrypt/ecc.h b/include/tinycrypt/ecc.h index b6fbc6906..57aa5087d 100644 --- a/include/tinycrypt/ecc.h +++ b/include/tinycrypt/ecc.h @@ -155,7 +155,8 @@ extern const uECC_word_t curve_b[NUM_ECC_WORDS]; * @param random OUT -- random integer in the range 0 < random < top * @param top IN -- upper limit * @param num_words IN -- number of words - * @return a random integer in the range 0 < random < top + * @return UECC_SUCCESS in case of success + * @return UECC_FAILURE upon failure */ int uECC_generate_random_int(uECC_word_t *random, const uECC_word_t *top, wordcount_t num_words); diff --git a/tinycrypt/ecc.c b/tinycrypt/ecc.c index 57b3228dd..ca91e12f4 100644 --- a/tinycrypt/ecc.c +++ b/tinycrypt/ecc.c @@ -1080,7 +1080,7 @@ int EccPoint_mult_safer(uECC_word_t * result, const uECC_word_t * point, /* If an RNG function was specified, get a random initial Z value to * protect against side-channel attacks such as Template SPA */ if (g_rng_function) { - if (!uECC_generate_random_int(k2[carry], curve_p, num_words)) { + if (uECC_generate_random_int(k2[carry], curve_p, num_words) != UECC_SUCCESS) { r = UECC_FAILURE; goto clear_and_out; } @@ -1165,21 +1165,21 @@ int uECC_generate_random_int(uECC_word_t *random, const uECC_word_t *top, bitcount_t num_bits = uECC_vli_numBits(top); if (!g_rng_function) { - return 0; + return UECC_FAILURE; } for (tries = 0; tries < uECC_RNG_MAX_TRIES; ++tries) { if (g_rng_function((uint8_t *)random, num_words * uECC_WORD_SIZE) != num_words * uECC_WORD_SIZE) { - return 0; + return UECC_FAILURE; } 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) == 1) { - return 1; + return UECC_SUCCESS; } } - return 0; + return UECC_FAILURE; } diff --git a/tinycrypt/ecc_dsa.c b/tinycrypt/ecc_dsa.c index 70f9c8bc6..bb3ed813b 100644 --- a/tinycrypt/ecc_dsa.c +++ b/tinycrypt/ecc_dsa.c @@ -109,7 +109,7 @@ int uECC_sign_with_k(const uint8_t *private_key, const uint8_t *message_hash, uECC_vli_clear(tmp); tmp[0] = 1; } - else if (!uECC_generate_random_int(tmp, curve_n, num_n_words)) { + else if (uECC_generate_random_int(tmp, curve_n, num_n_words) != UECC_SUCCESS) { return UECC_FAILURE; }