drbg: The drbg instance owns the entropy rng
This commit is contained in:
committed by
Tobias Brunner
parent
ccaedf8761
commit
11e9d2b8d1
@@ -236,6 +236,7 @@ METHOD(drbg_t, destroy, void,
|
||||
{
|
||||
if (ref_put(&this->ref))
|
||||
{
|
||||
DESTROY_IF(this->entropy);
|
||||
this->crypter->destroy(this->crypter);
|
||||
chunk_clear(&this->key);
|
||||
chunk_clear(&this->value);
|
||||
@@ -318,7 +319,6 @@ drbg_ctr_t *drbg_ctr_create(drbg_type_t type, uint32_t strength,
|
||||
},
|
||||
.type = type,
|
||||
.strength = strength,
|
||||
.entropy = entropy,
|
||||
.crypter = crypter,
|
||||
.key = chunk_alloc(key_len),
|
||||
.value = chunk_alloc(out_len),
|
||||
@@ -333,7 +333,7 @@ drbg_ctr_t *drbg_ctr_create(drbg_type_t type, uint32_t strength,
|
||||
seed = chunk_alloc(seed_len);
|
||||
DBG2(DBG_LIB, "DRBG requests %u bytes of entropy", seed_len);
|
||||
|
||||
if (!this->entropy->get_bytes(this->entropy, seed.len, seed.ptr))
|
||||
if (!entropy->get_bytes(entropy, seed.len, seed.ptr))
|
||||
{
|
||||
chunk_free(&seed);
|
||||
destroy(this);
|
||||
@@ -351,5 +351,8 @@ drbg_ctr_t *drbg_ctr_create(drbg_type_t type, uint32_t strength,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* ownership of entropy source is transferred to DRBG */
|
||||
this->entropy = entropy;
|
||||
|
||||
return &this->public;
|
||||
}
|
||||
|
||||
@@ -206,6 +206,7 @@ METHOD(drbg_t, destroy, void,
|
||||
{
|
||||
if (ref_put(&this->ref))
|
||||
{
|
||||
DESTROY_IF(this->entropy);
|
||||
this->prf->destroy(this->prf);
|
||||
chunk_clear(&this->key);
|
||||
chunk_clear(&this->value);
|
||||
@@ -280,7 +281,6 @@ drbg_hmac_t *drbg_hmac_create(drbg_type_t type, uint32_t strength,
|
||||
},
|
||||
.type = type,
|
||||
.strength = strength,
|
||||
.entropy = entropy,
|
||||
.prf = prf,
|
||||
.key = chunk_alloc(out_len),
|
||||
.value = chunk_alloc(out_len),
|
||||
@@ -296,7 +296,7 @@ drbg_hmac_t *drbg_hmac_create(drbg_type_t type, uint32_t strength,
|
||||
seed = chunk_alloc(entropy_len + personalization_str.len);
|
||||
DBG2(DBG_LIB, "DRBG requests %u bytes of entropy", entropy_len);
|
||||
|
||||
if (!this->entropy->get_bytes(this->entropy, entropy_len, seed.ptr))
|
||||
if (!entropy->get_bytes(entropy, entropy_len, seed.ptr))
|
||||
{
|
||||
chunk_free(&seed);
|
||||
destroy(this);
|
||||
@@ -315,5 +315,8 @@ drbg_hmac_t *drbg_hmac_create(drbg_type_t type, uint32_t strength,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* ownership of entropy source is transferred to DRBG */
|
||||
this->entropy = entropy;
|
||||
|
||||
return &this->public;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user