From 6adf8f2ae055973c9949dec463749aed768f54ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20AUZEMERY?= Date: Thu, 4 Jul 2024 15:41:10 +0200 Subject: [PATCH 1/4] Propagate error code of the uninstanciate method --- drbg.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drbg.c b/drbg.c index fac8b77..98da6c3 100644 --- a/drbg.c +++ b/drbg.c @@ -645,11 +645,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 +662,5 @@ drbg_error drbg_uninstantiate(drbg_ctx *ctx) ctx->magic = 0; - return DRBG_OK; + return ret; } From 10d6ccfd0f66875ac8a339a4d7cd59be2728dd0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20AUZEMERY?= Date: Thu, 4 Jul 2024 16:14:55 +0200 Subject: [PATCH 2/4] Remove infinite loop when clearing entropy fails --- drbg.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drbg.c b/drbg.c index 98da6c3..592e2be 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; } } From 4cfb54c808ea5ad84825f6c83efa09b7fc560c06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20AUZEMERY?= Date: Thu, 4 Jul 2024 16:48:49 +0200 Subject: [PATCH 3/4] Fix uninit of the entropy pool --- entropy.c | 5 +++++ 1 file changed, 5 insertions(+) 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; From 35d5456f337487033cf02bed86bdabfefd151946 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20AUZEMERY?= <86488911+Aurum-Vale@users.noreply.github.com> Date: Fri, 5 Jul 2024 20:33:03 +0200 Subject: [PATCH 4/4] Fix another instance of the entropy clear infinite loop --- drbg.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drbg.c b/drbg.c index 592e2be..4ce8ad9 100644 --- a/drbg.c +++ b/drbg.c @@ -400,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; } }