2c51e4
Stephan Mueller reported to me recently a error in random number generation in
2c51e4
the ansi cprng. If several small requests are made that are less than the
2c51e4
instances block size, the remainder for loop code doesn't increment
2c51e4
rand_data_valid in the last iteration, meaning that the last bytes in the
2c51e4
rand_data buffer gets reused on the subsequent smaller-than-a-block request for
2c51e4
random data.
2c51e4
2c51e4
The fix is pretty easy, just re-code the for loop to make sure that
2c51e4
rand_data_valid gets incremented appropriately
2c51e4
2c51e4
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
2c51e4
Reported-by: Stephan Mueller <stephan.mueller@atsec.com>
2c51e4
CC: Stephan Mueller <stephan.mueller@atsec.com>
2c51e4
CC: Petr Matousek <pmatouse@redhat.com>
2c51e4
CC: Herbert Xu <herbert@gondor.apana.org.au>
2c51e4
CC: "David S. Miller" <davem@davemloft.net>
2c51e4
---
2c51e4
 crypto/ansi_cprng.c | 4 ++--
2c51e4
 1 file changed, 2 insertions(+), 2 deletions(-)
2c51e4
2c51e4
diff --git a/crypto/ansi_cprng.c b/crypto/ansi_cprng.c
2c51e4
index c0bb377..666f196 100644
2c51e4
--- a/crypto/ansi_cprng.c
2c51e4
+++ b/crypto/ansi_cprng.c
2c51e4
@@ -230,11 +230,11 @@ remainder:
2c51e4
 	 */
2c51e4
 	if (byte_count < DEFAULT_BLK_SZ) {
2c51e4
 empty_rbuf:
2c51e4
-		for (; ctx->rand_data_valid < DEFAULT_BLK_SZ;
2c51e4
-			ctx->rand_data_valid++) {
2c51e4
+		while (ctx->rand_data_valid < DEFAULT_BLK_SZ) {
2c51e4
 			*ptr = ctx->rand_data[ctx->rand_data_valid];
2c51e4
 			ptr++;
2c51e4
 			byte_count--;
2c51e4
+			ctx->rand_data_valid++;
2c51e4
 			if (byte_count == 0)
2c51e4
 				goto done;
2c51e4
 		}
2c51e4
-- 
2c51e4
1.8.3.1