From f96f7b607a59754bc37a8b3f9c563620666db3e7 Mon Sep 17 00:00:00 2001 From: Paul Bakker Date: Wed, 30 Apr 2014 16:02:38 +0200 Subject: [PATCH] On OpenBSD, use arc4random_buf() instead of rand() to prevent warnings --- ChangeLog | 1 + library/rsa.c | 7 +++++++ tests/suites/helpers.function | 7 +++++++ 3 files changed, 15 insertions(+) diff --git a/ChangeLog b/ChangeLog index 5b1529c4a4..2f5be94a90 100644 --- a/ChangeLog +++ b/ChangeLog @@ -24,6 +24,7 @@ Bugfix * Improve interoperability by not writing extension length in ClientHello / ServerHello when no extensions are present (found by Matthew Page) * rsa_check_pubkey() now allows an E up to N + * On OpenBSD, use arc4random_buf() instead of rand() to prevent warnings = PolarSSL 1.3.6 released on 2014-04-11 diff --git a/library/rsa.c b/library/rsa.c index 7869d22d1d..17861496d8 100644 --- a/library/rsa.c +++ b/library/rsa.c @@ -1469,6 +1469,7 @@ void rsa_free( rsa_context *ctx ) #if defined(POLARSSL_PKCS1_V15) static int myrand( void *rng_state, unsigned char *output, size_t len ) { +#if !defined(__OpenBSD__) size_t i; if( rng_state != NULL ) @@ -1476,6 +1477,12 @@ static int myrand( void *rng_state, unsigned char *output, size_t len ) for( i = 0; i < len; ++i ) output[i] = rand(); +#else + if( rng_state != NULL ) + rng_state = NULL; + + arc4random_buf( output, len ); +#endif /* !OpenBSD */ return( 0 ); } diff --git a/tests/suites/helpers.function b/tests/suites/helpers.function index 1e09666503..f6a35295bb 100644 --- a/tests/suites/helpers.function +++ b/tests/suites/helpers.function @@ -105,6 +105,7 @@ static void hexify(unsigned char *obuf, const unsigned char *ibuf, int len) */ static int rnd_std_rand( void *rng_state, unsigned char *output, size_t len ) { +#if !defined(__OpenBSD__) size_t i; if( rng_state != NULL ) @@ -112,6 +113,12 @@ static int rnd_std_rand( void *rng_state, unsigned char *output, size_t len ) for( i = 0; i < len; ++i ) output[i] = rand(); +#else + if( rng_state != NULL ) + rng_state = NULL; + + arc4random_buf( output, len ); +#endif /* !OpenBSD */ return( 0 ); }