Skip to content

Commit

Permalink
Merge pull request #5 from Aurum-Vale/fix_entropy_inf_loop
Browse files Browse the repository at this point in the history
Fix clear_entropy infinite loop
  • Loading branch information
ae-anssi authored Jul 8, 2024
2 parents ea2d18b + 35d5456 commit 738ab48
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
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

0 comments on commit 738ab48

Please sign in to comment.