Latest update
This commit is contained in:
+17
-12
@@ -286,7 +286,7 @@ static RAND_DRBG *rand_drbg_new(int secure,
|
||||
|
||||
return drbg;
|
||||
|
||||
err:
|
||||
err:
|
||||
if (drbg->secure)
|
||||
OPENSSL_secure_free(drbg);
|
||||
else
|
||||
@@ -378,7 +378,7 @@ int RAND_DRBG_instantiate(RAND_DRBG *drbg,
|
||||
entropylen = drbg->get_entropy(drbg, &entropy, min_entropy,
|
||||
min_entropylen, max_entropylen, 0);
|
||||
if (entropylen < min_entropylen
|
||||
|| entropylen > max_entropylen) {
|
||||
|| entropylen > max_entropylen) {
|
||||
RANDerr(RAND_F_RAND_DRBG_INSTANTIATE, RAND_R_ERROR_RETRIEVING_ENTROPY);
|
||||
goto end;
|
||||
}
|
||||
@@ -408,10 +408,10 @@ int RAND_DRBG_instantiate(RAND_DRBG *drbg,
|
||||
drbg->reseed_prop_counter = drbg->parent->reseed_prop_counter;
|
||||
}
|
||||
|
||||
end:
|
||||
end:
|
||||
if (entropy != NULL && drbg->cleanup_entropy != NULL)
|
||||
drbg->cleanup_entropy(drbg, entropy, entropylen);
|
||||
if (nonce != NULL && drbg->cleanup_nonce!= NULL )
|
||||
if (nonce != NULL && drbg->cleanup_nonce != NULL)
|
||||
drbg->cleanup_nonce(drbg, nonce, noncelen);
|
||||
if (drbg->pool != NULL) {
|
||||
if (drbg->state == DRBG_READY) {
|
||||
@@ -504,7 +504,7 @@ int RAND_DRBG_reseed(RAND_DRBG *drbg,
|
||||
drbg->max_entropylen,
|
||||
prediction_resistance);
|
||||
if (entropylen < drbg->min_entropylen
|
||||
|| entropylen > drbg->max_entropylen) {
|
||||
|| entropylen > drbg->max_entropylen) {
|
||||
RANDerr(RAND_F_RAND_DRBG_RESEED, RAND_R_ERROR_RETRIEVING_ENTROPY);
|
||||
goto end;
|
||||
}
|
||||
@@ -522,7 +522,7 @@ int RAND_DRBG_reseed(RAND_DRBG *drbg,
|
||||
drbg->reseed_prop_counter = drbg->parent->reseed_prop_counter;
|
||||
}
|
||||
|
||||
end:
|
||||
end:
|
||||
if (entropy != NULL && drbg->cleanup_entropy != NULL)
|
||||
drbg->cleanup_entropy(drbg, entropy, entropylen);
|
||||
if (drbg->state == DRBG_READY)
|
||||
@@ -556,8 +556,10 @@ int rand_drbg_restart(RAND_DRBG *drbg,
|
||||
|
||||
if (drbg->pool != NULL) {
|
||||
RANDerr(RAND_F_RAND_DRBG_RESTART, ERR_R_INTERNAL_ERROR);
|
||||
drbg->state = DRBG_ERROR;
|
||||
rand_pool_free(drbg->pool);
|
||||
drbg->pool = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (buffer != NULL) {
|
||||
@@ -565,24 +567,25 @@ int rand_drbg_restart(RAND_DRBG *drbg,
|
||||
if (drbg->max_entropylen < len) {
|
||||
RANDerr(RAND_F_RAND_DRBG_RESTART,
|
||||
RAND_R_ENTROPY_INPUT_TOO_LONG);
|
||||
drbg->state = DRBG_ERROR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (entropy > 8 * len) {
|
||||
RANDerr(RAND_F_RAND_DRBG_RESTART, RAND_R_ENTROPY_OUT_OF_RANGE);
|
||||
drbg->state = DRBG_ERROR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* will be picked up by the rand_drbg_get_entropy() callback */
|
||||
drbg->pool = rand_pool_new(entropy, len, len);
|
||||
drbg->pool = rand_pool_attach(buffer, len, entropy);
|
||||
if (drbg->pool == NULL)
|
||||
return 0;
|
||||
|
||||
rand_pool_add(drbg->pool, buffer, len, entropy);
|
||||
} else {
|
||||
if (drbg->max_adinlen < len) {
|
||||
RANDerr(RAND_F_RAND_DRBG_RESTART,
|
||||
RAND_R_ADDITIONAL_INPUT_TOO_LONG);
|
||||
drbg->state = DRBG_ERROR;
|
||||
return 0;
|
||||
}
|
||||
adin = buffer;
|
||||
@@ -1040,14 +1043,16 @@ static int drbg_add(const void *buf, int num, double randomness)
|
||||
if (num < 0 || randomness < 0.0)
|
||||
return 0;
|
||||
|
||||
if (randomness > (double)drbg->max_entropylen) {
|
||||
if (randomness > (double)RAND_DRBG_STRENGTH) {
|
||||
/*
|
||||
* The purpose of this check is to bound |randomness| by a
|
||||
* relatively small value in order to prevent an integer
|
||||
* overflow when multiplying by 8 in the rand_drbg_restart()
|
||||
* call below.
|
||||
* call below. Note that randomness is measured in bytes,
|
||||
* not bits, so this value corresponds to eight times the
|
||||
* security strength.
|
||||
*/
|
||||
return 0;
|
||||
randomness = (double)RAND_DRBG_STRENGTH;
|
||||
}
|
||||
|
||||
rand_drbg_lock(drbg);
|
||||
|
||||
Reference in New Issue
Block a user