diff --git a/include/tinycrypt/ecc.h b/include/tinycrypt/ecc.h index 6a85a5578..b6fbc6906 100644 --- a/include/tinycrypt/ecc.h +++ b/include/tinycrypt/ecc.h @@ -163,9 +163,9 @@ int uECC_generate_random_int(uECC_word_t *random, const uECC_word_t *top, /* uECC_RNG_Function type * The RNG function should fill 'size' random bytes into 'dest'. It should - * return 1 if 'dest' was filled with random data, or 0 if the random data could - * not be generated. The filled-in values should be either truly random, or from - * a cryptographically-secure PRNG. + * return 'size' if 'dest' was filled with random data of 'size' length, or 0 + * if the random data could not be generated. The filled-in values should be + * either truly random, or from a cryptographically-secure PRNG. * * A correctly functioning RNG function must be set (using uECC_set_rng()) * before calling uECC_make_key() or uECC_sign(). @@ -181,8 +181,8 @@ typedef int(*uECC_RNG_Function)(uint8_t *dest, unsigned int size); /* * @brief Set the function that will be used to generate random bytes. The RNG - * function should return 1 if the random data was generated, or 0 if the random - * data could not be generated. + * function should return 'size' if the random data of length 'size' was + * generated, or 0 if the random data could not be generated. * * @note On platforms where there is no predefined RNG function, this must be * called before uECC_make_key() or uECC_sign() are used. diff --git a/tinycrypt/ecc.c b/tinycrypt/ecc.c index b3e3ed327..57b3228dd 100644 --- a/tinycrypt/ecc.c +++ b/tinycrypt/ecc.c @@ -1169,7 +1169,7 @@ int uECC_generate_random_int(uECC_word_t *random, const uECC_word_t *top, } for (tries = 0; tries < uECC_RNG_MAX_TRIES; ++tries) { - if (!g_rng_function((uint8_t *)random, num_words * uECC_WORD_SIZE)) { + if (g_rng_function((uint8_t *)random, num_words * uECC_WORD_SIZE) != num_words * uECC_WORD_SIZE) { return 0; } random[num_words - 1] &= diff --git a/tinycrypt/ecc_dh.c b/tinycrypt/ecc_dh.c index ceabb0005..a63c84bba 100644 --- a/tinycrypt/ecc_dh.c +++ b/tinycrypt/ecc_dh.c @@ -119,7 +119,7 @@ int uECC_make_key(uint8_t *public_key, uint8_t *private_key) /* Generating _private uniformly at random: */ uECC_RNG_Function rng_function = uECC_get_rng(); if (!rng_function || - !rng_function((uint8_t *)_random, 2 * NUM_ECC_WORDS*uECC_WORD_SIZE)) { + rng_function((uint8_t *)_random, 2 * NUM_ECC_WORDS*uECC_WORD_SIZE) != 2 * NUM_ECC_WORDS*uECC_WORD_SIZE) { return UECC_FAILURE; } diff --git a/tinycrypt/ecc_dsa.c b/tinycrypt/ecc_dsa.c index 230f6890c..70f9c8bc6 100644 --- a/tinycrypt/ecc_dsa.c +++ b/tinycrypt/ecc_dsa.c @@ -151,7 +151,7 @@ int uECC_sign(const uint8_t *private_key, const uint8_t *message_hash, /* Generating _random uniformly at random: */ uECC_RNG_Function rng_function = uECC_get_rng(); if (!rng_function || - !rng_function((uint8_t *)_random, 2*NUM_ECC_WORDS*uECC_WORD_SIZE)) { + rng_function((uint8_t *)_random, 2*NUM_ECC_WORDS*uECC_WORD_SIZE) != 2*NUM_ECC_WORDS*uECC_WORD_SIZE) { return UECC_FAILURE; }