crypto: drbg - simplify drbg_get_random_bytes()
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
@@ -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)
Herbert Xu
maintainerQuoted 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 indrbg_get_random_bytes()just isn't possible. Then, the loop condition needs to be adjusted to only continue the loop while-EAGAINis returned and the final *return* statement needs to be adjusted as well, in order to be prepared for the case ofdrbg_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.
Suggested-by Yann Droneaud <[email protected]>Signed-off-by Sergey Shtylyov <[email protected]>---
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