From bf3c038fa97d83561f47c48732eb7bef45291570 Mon Sep 17 00:00:00 2001 From: Han Xinrong Date: Tue, 8 Dec 2020 11:14:15 +0800 Subject: [PATCH] sys/random/fortuna/fortuna.c:add error check of aes_encrypt() --- sys/random/fortuna/fortuna.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sys/random/fortuna/fortuna.c b/sys/random/fortuna/fortuna.c index 97726d6abf..9c5f31d337 100644 --- a/sys/random/fortuna/fortuna.c +++ b/sys/random/fortuna/fortuna.c @@ -53,6 +53,7 @@ static void fortuna_reseed(fortuna_state_t *state, const uint8_t *seed, /* * Corresponds to section 9.4.3. + * Returns 0 on success; A negative value otherwise */ static int fortuna_generate_blocks(fortuna_state_t *state, uint8_t *out, size_t blocks) @@ -75,7 +76,10 @@ static int fortuna_generate_blocks(fortuna_state_t *state, uint8_t *out, } for (size_t i = 0; i < blocks; i++) { - aes_encrypt(&cipher, state->gen.counter.bytes, out + (i * 16)); + res = aes_encrypt(&cipher, state->gen.counter.bytes, out + (i * 16)); + if (res != 1) { + return -3; + } fortuna_increment_counter(state); }