From 8d4d9ff129e12bd02f0a88ddb359cf228bcf1e4e Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Tue, 4 Feb 2014 09:18:10 -0600 Subject: cryptgenrandom returns all requested bytes or errors, so no loop required --- cryptography/hazmat/bindings/openssl/osrand_engine.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/cryptography/hazmat/bindings/openssl/osrand_engine.py b/cryptography/hazmat/bindings/openssl/osrand_engine.py index 2313a61f..4163668b 100644 --- a/cryptography/hazmat/bindings/openssl/osrand_engine.py +++ b/cryptography/hazmat/bindings/openssl/osrand_engine.py @@ -48,20 +48,13 @@ static int osrandom_init(ENGINE *e) { } static int osrandom_rand_bytes(unsigned char *buffer, int size) { - size_t chunk; - if (hCryptProv == 0) { return 0; } - while (size > 0) { - chunk = size; - if (!CryptGenRandom(hCryptProv, (DWORD)chunk, buffer)) { - ERR_put_error(ERR_LIB_RAND, 0, ERR_R_RAND_LIB, "osrandom.py", 0); - return 0; - } - buffer += chunk; - size -= chunk; + if (!CryptGenRandom(hCryptProv, (DWORD)size, buffer)) { + ERR_put_error(ERR_LIB_RAND, 0, ERR_R_RAND_LIB, "osrandom.py", 0); + return 0; } return 1; } -- cgit v1.2.3