diff options
author | Pauli <pauli@openssl.org> | 2021-05-31 16:30:50 +1000 |
---|---|---|
committer | Pauli <pauli@openssl.org> | 2021-06-01 18:13:36 +1000 |
commit | 528685fe7767b376fe299a602217f3a3a7e1d21d (patch) | |
tree | a3b62613d3357ce7769bbaf67d03927d5f62d4a2 /crypto | |
parent | f7c1b472bf0a790b9c87e1c87e48897d6413ec45 (diff) |
rand: use size_t for size argument to RAND_bytes_ex()
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/15540)
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/rand/rand_lib.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/crypto/rand/rand_lib.c b/crypto/rand/rand_lib.c index 7ad05ea008..56e615f6b9 100644 --- a/crypto/rand/rand_lib.c +++ b/crypto/rand/rand_lib.c @@ -315,7 +315,7 @@ const RAND_METHOD *RAND_get_rand_method(void) * the default method, then just call RAND_bytes(). Otherwise make * sure we're instantiated and use the private DRBG. */ -int RAND_priv_bytes_ex(OSSL_LIB_CTX *ctx, unsigned char *buf, int num, +int RAND_priv_bytes_ex(OSSL_LIB_CTX *ctx, unsigned char *buf, size_t num, unsigned int strength) { EVP_RAND_CTX *rand; @@ -339,10 +339,12 @@ int RAND_priv_bytes_ex(OSSL_LIB_CTX *ctx, unsigned char *buf, int num, int RAND_priv_bytes(unsigned char *buf, int num) { - return RAND_priv_bytes_ex(NULL, buf, num, 0); + if (num < 0) + return 0; + return RAND_priv_bytes_ex(NULL, buf, (size_t)num, 0); } -int RAND_bytes_ex(OSSL_LIB_CTX *ctx, unsigned char *buf, int num, +int RAND_bytes_ex(OSSL_LIB_CTX *ctx, unsigned char *buf, size_t num, unsigned int strength) { EVP_RAND_CTX *rand; @@ -366,7 +368,9 @@ int RAND_bytes_ex(OSSL_LIB_CTX *ctx, unsigned char *buf, int num, int RAND_bytes(unsigned char *buf, int num) { - return RAND_bytes_ex(NULL, buf, num, 0); + if (num < 0) + return 0; + return RAND_bytes_ex(NULL, buf, (size_t)num, 0); } typedef struct rand_global_st { |