[PATCH v2 25/25] crypto: ansi_cprng - If non-deterministic, don't buffer old output

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The standards documents are silent on how to handle multi-part
output, so this is an RFC for something in the spirit of the
source specifications, but not actually required by them.

Signed-off-by: George Spelvin <linux@xxxxxxxxxxx>
---
 crypto/ansi_cprng.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/crypto/ansi_cprng.c b/crypto/ansi_cprng.c
index d39ce301..b88d3446 100644
--- a/crypto/ansi_cprng.c
+++ b/crypto/ansi_cprng.c
@@ -198,12 +198,14 @@ static int get_prng_bytes(u8 *buf, unsigned int nbytes,
 
 	read_pos = ctx->rand_read_pos;
 	if (byte_count > DEFAULT_BLK_SZ - read_pos) {
-		/* Leading partial block */
-		unsigned int avail = DEFAULT_BLK_SZ - read_pos;
+		if (ctx->flags & PRNG_DETERMINISTIC) {
+			/* Return leftover data from previous call */
+			unsigned int avail = DEFAULT_BLK_SZ - read_pos;
 
-		memcpy(ptr, ctx->rand_data.b + read_pos, avail);
-		ptr += avail;
-		byte_count -= avail;
+			memcpy(ptr, ctx->rand_data.b + read_pos, avail);
+			ptr += avail;
+			byte_count -= avail;
+		}
 		read_pos = 0;
 
 		/* Intermediate full blocks */
-- 
2.1.3

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Kernel]     [Gnu Classpath]     [Gnu Crypto]     [DM Crypt]     [Netfilter]     [Bugtraq]

  Powered by Linux