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)
goto err;
return drbg;
err:
- OPENSSL_free(ucp);
OPENSSL_free(drbg);
return NULL;
}
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));
}
return 0;
}
+ if (drbg->fork_count != rand_fork_count) {
+ drbg->fork_count = rand_fork_count;
+ drbg->state = DRBG_RESEED;
+ }
+
if (drbg->reseed_counter >= drbg->reseed_interval)
drbg->state = DRBG_RESEED;
int ret;
CRYPTO_THREAD_write_lock(rand_drbg.lock);
+ if (rand_drbg.state == DRBG_UNINITIALISED)
+ RAND_DRBG_instantiate(&rand_drbg, NULL, 0);
ret = rand_drbg.state == DRBG_READY ? 1 : 0;
CRYPTO_THREAD_unlock(rand_drbg.lock);
return ret;