Skip to contentSkip to conversation

crypto: drbg - simplify drbg_get_random_bytes()

PATCH In review Sergey Shtylyov 2 participants 2 messages Nov 15, 2025 – Nov 22, 2025 Crypto API

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: drbg - simplify drbg_get_random_bytes()

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.

---
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(-)
crypto/drbg.c +2 -4
Index: 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)
maintainer
#1 lore raw
Quoted 8 lines · Sergey Shtylyov

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...

Quoted 8 lines

Found by Linux Verification Center (linuxtesting.org) with the Svace static analysis tool.

---
The patch is against the master branch of Herbert Xu's cryptodev-2.6.git repo.

https://lore.kernel.org/linux-crypto/[email protected]/

Cheers,

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt