Increase the Hamming distance of uECC_generate_random_int returns
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
diff --git a/include/tinycrypt/ecc.h b/include/tinycrypt/ecc.h
index b6fbc69..57aa508 100644
--- a/include/tinycrypt/ecc.h
+++ b/include/tinycrypt/ecc.h
@@ -155,7 +155,8 @@
* @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 57b3228..ca91e12 100644
--- a/tinycrypt/ecc.c
+++ b/tinycrypt/ecc.c
@@ -1080,7 +1080,7 @@
/* 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 @@
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 70f9c8b..bb3ed81 100644
--- a/tinycrypt/ecc_dsa.c
+++ b/tinycrypt/ecc_dsa.c
@@ -109,7 +109,7 @@
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;
}