From: Martin Willi Date: Thu, 4 Jul 2013 09:09:54 +0000 (+0200) Subject: openssl: RAND_pseudo_bytes() returns 0 if bytes are not cryptographically strong X-Git-Tag: 5.1.0dr2~19 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=324b90cc46e3af52731fa98eb947e412ab56a2f5;p=thirdparty%2Fstrongswan.git openssl: RAND_pseudo_bytes() returns 0 if bytes are not cryptographically strong For our purposes with RNG_WEAK this is fine, so accept a zero return value. --- diff --git a/src/libstrongswan/plugins/openssl/openssl_rng.c b/src/libstrongswan/plugins/openssl/openssl_rng.c index 10db6293a3..815cf4f0c1 100644 --- a/src/libstrongswan/plugins/openssl/openssl_rng.c +++ b/src/libstrongswan/plugins/openssl/openssl_rng.c @@ -47,17 +47,14 @@ struct private_openssl_rng_t { METHOD(rng_t, get_bytes, bool, private_openssl_rng_t *this, size_t bytes, u_int8_t *buffer) { - u_int32_t ret; - - if (this->quality == RNG_STRONG) - { - ret = RAND_bytes((char*)buffer, bytes); - } - else + if (this->quality == RNG_WEAK) { - ret = RAND_pseudo_bytes((char*)buffer, bytes); + /* RAND_pseudo_bytes() returns 1 if returned bytes are strong, + * 0 if of not. Both is acceptable for RNG_WEAK. */ + return RAND_pseudo_bytes((char*)buffer, bytes) != -1; } - return ret == 1; + /* A 0 return value is a failure for RAND_bytes() */ + return RAND_bytes((char*)buffer, bytes) == 1; } METHOD(rng_t, allocate_bytes, bool,