diff options
-rw-r--r-- | crypto/ansi_cprng.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/crypto/ansi_cprng.c b/crypto/ansi_cprng.c index 486aa93646f7..1b3b1da1fd35 100644 --- a/crypto/ansi_cprng.c +++ b/crypto/ansi_cprng.c | |||
@@ -223,9 +223,10 @@ remainder: | |||
223 | } | 223 | } |
224 | 224 | ||
225 | /* | 225 | /* |
226 | * Copy up to the next whole block size | 226 | * Copy any data less than an entire block |
227 | */ | 227 | */ |
228 | if (byte_count < DEFAULT_BLK_SZ) { | 228 | if (byte_count < DEFAULT_BLK_SZ) { |
229 | empty_rbuf: | ||
229 | for (; ctx->rand_data_valid < DEFAULT_BLK_SZ; | 230 | for (; ctx->rand_data_valid < DEFAULT_BLK_SZ; |
230 | ctx->rand_data_valid++) { | 231 | ctx->rand_data_valid++) { |
231 | *ptr = ctx->rand_data[ctx->rand_data_valid]; | 232 | *ptr = ctx->rand_data[ctx->rand_data_valid]; |
@@ -240,18 +241,22 @@ remainder: | |||
240 | * Now copy whole blocks | 241 | * Now copy whole blocks |
241 | */ | 242 | */ |
242 | for (; byte_count >= DEFAULT_BLK_SZ; byte_count -= DEFAULT_BLK_SZ) { | 243 | for (; byte_count >= DEFAULT_BLK_SZ; byte_count -= DEFAULT_BLK_SZ) { |
243 | if (_get_more_prng_bytes(ctx) < 0) { | 244 | if (ctx->rand_data_valid == DEFAULT_BLK_SZ) { |
244 | memset(buf, 0, nbytes); | 245 | if (_get_more_prng_bytes(ctx) < 0) { |
245 | err = -EINVAL; | 246 | memset(buf, 0, nbytes); |
246 | goto done; | 247 | err = -EINVAL; |
248 | goto done; | ||
249 | } | ||
247 | } | 250 | } |
251 | if (ctx->rand_data_valid > 0) | ||
252 | goto empty_rbuf; | ||
248 | memcpy(ptr, ctx->rand_data, DEFAULT_BLK_SZ); | 253 | memcpy(ptr, ctx->rand_data, DEFAULT_BLK_SZ); |
249 | ctx->rand_data_valid += DEFAULT_BLK_SZ; | 254 | ctx->rand_data_valid += DEFAULT_BLK_SZ; |
250 | ptr += DEFAULT_BLK_SZ; | 255 | ptr += DEFAULT_BLK_SZ; |
251 | } | 256 | } |
252 | 257 | ||
253 | /* | 258 | /* |
254 | * Now copy any extra partial data | 259 | * Now go back and get any remaining partial block |
255 | */ | 260 | */ |
256 | if (byte_count) | 261 | if (byte_count) |
257 | goto remainder; | 262 | goto remainder; |