[lvc-project] [PATCH] crypto: drbg - simplify drbg_get_random_bytes()
Sergey Shtylyov
s.shtylyov at omp.ru
Sat Nov 15 23:45:12 MSK 2025
To begin with, drbg_fips_continuous_test() only returns 0 and -EAGAIN,
so an early return from the *do/while* loop in drbg_get_random_bytes()
just isn't possible. Then, the loop condition needs to be adjusted to
only continue the loop while -EAGAIN is returned and the final *return*
statement needs to be adjusted as well, in order to be prepared for the
case of drbg_fips_continuous_test() starting to return some other error
codes...
Found by Linux Verification Center (linuxtesting.org) with the Svace static
analysis tool.
Suggested-by: Yann Droneaud <yann at droneaud.fr>
Signed-off-by: Sergey Shtylyov <s.shtylyov at omp.ru>
---
The patch is against the master branch of Herbert Xu's cryptodev-2.6.git repo.
crypto/drbg.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
Index: cryptodev-2.6/crypto/drbg.c
===================================================================
--- cryptodev-2.6.orig/crypto/drbg.c
+++ cryptodev-2.6/crypto/drbg.c
@@ -854,11 +854,9 @@ static inline int drbg_get_random_bytes(
do {
get_random_bytes(entropy, entropylen);
ret = drbg_fips_continuous_test(drbg, entropy);
- if (ret && ret != -EAGAIN)
- return ret;
- } while (ret);
+ } while (ret == -EAGAIN);
- return 0;
+ return ret;
}
static int drbg_seed_from_random(struct drbg_state *drbg)
More information about the lvc-project
mailing list