Merge pull request #3559 from gufe44/netbsd-rand-arc4random_buf-2.7

[Backport 2.7] Use arc4random_buf instead of rand on NetBSD
This commit is contained in:
Gilles Peskine 2020-08-13 15:27:57 +02:00 committed by GitHub
commit 99d67823a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 5 deletions

View File

@ -0,0 +1,3 @@
Bugfix
* Use arc4random_buf on NetBSD instead of rand implementation with cyclical
lower bits. Fix contributed in #3540.

View File

@ -82,7 +82,7 @@
#include "mbedtls/md.h"
#endif
#if defined(MBEDTLS_PKCS1_V15) && !defined(__OpenBSD__)
#if defined(MBEDTLS_PKCS1_V15) && !defined(__OpenBSD__) && !defined(__NetBSD__)
#include <stdlib.h>
#endif
@ -2404,7 +2404,7 @@ void mbedtls_rsa_free( mbedtls_rsa_context *ctx )
#if defined(MBEDTLS_PKCS1_V15)
static int myrand( void *rng_state, unsigned char *output, size_t len )
{
#if !defined(__OpenBSD__)
#if !defined(__OpenBSD__) && !defined(__NetBSD__)
size_t i;
if( rng_state != NULL )
@ -2417,7 +2417,7 @@ static int myrand( void *rng_state, unsigned char *output, size_t len )
rng_state = NULL;
arc4random_buf( output, len );
#endif /* !OpenBSD */
#endif /* !OpenBSD && !NetBSD */
return( 0 );
}

View File

@ -330,7 +330,7 @@ unsigned char *unhexify_alloc( const char *ibuf, size_t *olen )
*/
static int rnd_std_rand( void *rng_state, unsigned char *output, size_t len )
{
#if !defined(__OpenBSD__)
#if !defined(__OpenBSD__) && !defined(__NetBSD__)
size_t i;
if( rng_state != NULL )
@ -343,7 +343,7 @@ static int rnd_std_rand( void *rng_state, unsigned char *output, size_t len )
rng_state = NULL;
arc4random_buf( output, len );
#endif /* !OpenBSD */
#endif /* !OpenBSD && !NetBSD */
return( 0 );
}