diff --git a/drbg.c b/drbg.c index fac8b77..4ce8ad9 100644 --- a/drbg.c +++ b/drbg.c @@ -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; } } @@ -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; } } @@ -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; @@ -659,5 +659,5 @@ drbg_error drbg_uninstantiate(drbg_ctx *ctx) ctx->magic = 0; - return DRBG_OK; + return ret; } diff --git a/entropy.c b/entropy.c index c056d06..2f4aac4 100644 --- a/entropy.c +++ b/entropy.c @@ -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;