From f2342603340bca4d689ec84ca37dc874ebd48a18 Mon Sep 17 00:00:00 2001 From: Flavio Ceolin Date: Sun, 26 Jan 2020 22:23:34 -0800 Subject: [PATCH] random: rand32_ctr_drbg: Handle error in initialize function Initialize function has to fail when a call to get entropy fails. TinyCrypt prng_init relies on a proper entropy data, so we need to check if the driver return it properly. Signed-off-by: Flavio Ceolin --- subsys/random/rand32_ctr_drbg.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/subsys/random/rand32_ctr_drbg.c b/subsys/random/rand32_ctr_drbg.c index 0d28544d401..6efdfe68ea7 100644 --- a/subsys/random/rand32_ctr_drbg.c +++ b/subsys/random/rand32_ctr_drbg.c @@ -82,7 +82,11 @@ static int ctr_drbg_initialize(void) u8_t entropy[TC_AES_KEY_SIZE + TC_AES_BLOCK_SIZE]; - entropy_get_entropy(entropy_driver, (void *)&entropy, sizeof(entropy)); + ret = entropy_get_entropy(entropy_driver, (void *)&entropy, + sizeof(entropy)); + if (ret != 0) { + return -EIO; + } ret = tc_ctr_prng_init(&ctr_ctx, (uint8_t *)&entropy,