summaryrefslogtreecommitdiffstats
path: root/crypto/rand/drbg_lib.c
diff options
context:
space:
mode:
authorRich Salz <rsalz@openssl.org>2017-08-22 18:24:23 -0400
committerRich Salz <rsalz@openssl.org>2017-08-22 22:02:57 -0400
commit9d951a7872e5fa2b2a83fe8cfda3af5c52581172 (patch)
tree3f54472c58a671e915f437d636bd5c759537bd11 /crypto/rand/drbg_lib.c
parent27c6d63dad0844280b9db3c7e9ad8dd5befb51c3 (diff)
Move randomness to allocated buffer
Don't keep it in the DRBG object, just allocate/free as needed. Reviewed-by: Paul Dale <paul.dale@oracle.com> (Merged from https://github.com/openssl/openssl/pull/4226)
Diffstat (limited to 'crypto/rand/drbg_lib.c')
-rw-r--r--crypto/rand/drbg_lib.c7
1 files changed, 1 insertions, 6 deletions
diff --git a/crypto/rand/drbg_lib.c b/crypto/rand/drbg_lib.c
index 0da4d48f55..6aced40fd4 100644
--- a/crypto/rand/drbg_lib.c
+++ b/crypto/rand/drbg_lib.c
@@ -64,14 +64,12 @@ int RAND_DRBG_set(RAND_DRBG *drbg, int nid, unsigned int flags)
RAND_DRBG *RAND_DRBG_new(int type, unsigned int flags, RAND_DRBG *parent)
{
RAND_DRBG *drbg = OPENSSL_zalloc(sizeof(*drbg));
- unsigned char *ucp = OPENSSL_zalloc(RANDOMNESS_NEEDED);
- if (drbg == NULL || ucp == NULL) {
+ if (drbg == NULL) {
RANDerr(RAND_F_RAND_DRBG_NEW, ERR_R_MALLOC_FAILURE);
goto err;
}
drbg->size = RANDOMNESS_NEEDED;
- drbg->randomness = ucp;
drbg->fork_count = rand_fork_count;
drbg->parent = parent;
if (RAND_DRBG_set(drbg, type, flags) < 0)
@@ -96,7 +94,6 @@ RAND_DRBG *RAND_DRBG_new(int type, unsigned int flags, RAND_DRBG *parent)
return drbg;
err:
- OPENSSL_free(ucp);
OPENSSL_free(drbg);
return NULL;
}
@@ -116,8 +113,6 @@ void RAND_DRBG_free(RAND_DRBG *drbg)
return;
ctr_uninstantiate(drbg);
- OPENSSL_cleanse(drbg->randomness, drbg->size);
- OPENSSL_free(drbg->randomness);
CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DRBG, drbg, &drbg->ex_data);
OPENSSL_clear_free(drbg, sizeof(*drbg));
}