Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix clear_entropy infinite loop #5

Merged
merged 4 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions drbg.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,13 +332,11 @@ static drbg_error _drbg_instantiate(drbg_ctx *ctx,
if(entropy_pool1 != NULL){
if(clear_entropy_input(entropy_pool1)){
ret = DRBG_ENTROPY_ERROR;
goto err;
}
}
if(entropy_pool2 != NULL){
if(clear_entropy_input(entropy_pool2)){
ret = DRBG_ENTROPY_ERROR;
goto err;
}
}

Expand Down Expand Up @@ -402,7 +400,6 @@ static drbg_error _drbg_reseed(drbg_ctx *ctx,
if(entropy_pool != NULL){
if(clear_entropy_input(entropy_pool)){
ret = DRBG_ENTROPY_ERROR;
goto err;
}
}

Expand Down Expand Up @@ -645,11 +642,14 @@ drbg_error drbg_generate_with_user_entropy(drbg_ctx *ctx,
/* DRBG uninstantiate */
drbg_error drbg_uninstantiate(drbg_ctx *ctx)
{

drbg_error ret = DRBG_OK;

if(drbg_check_instantiated(ctx)){
/* NOTE: we ignore the return value on purpose to clean up
* the other fields in any case
/* NOTE: do not return immediately if an error happened,
* empty the other fields first.
*/
ctx->methods->uninstantiate(ctx);
ret = ctx->methods->uninstantiate(ctx);
}

ctx->prediction_resistance = false;
Expand All @@ -659,5 +659,5 @@ drbg_error drbg_uninstantiate(drbg_ctx *ctx)

ctx->magic = 0;

return DRBG_OK;
return ret;
}
5 changes: 5 additions & 0 deletions entropy.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ int clear_entropy_input(uint8_t *buf)
/* Clean the buffer until pos */
memset(curr_entropy_pool.entropy_buff, 0, curr_entropy_pool.entropy_buff_pos);

/* Ensure the pool is in an uninit state,
* so it is fully reset by the next get_entropy_input call
*/
curr_entropy_pool_init = false;

ret = 0;
err:
return ret;
Expand Down