Use arc4random_buf instead of rand on NetBSD

Avoid old implementation of rand returning numbers with cyclical lower bits. Allow tests to pass.

Signed-off-by: gufe44 <gu981@protonmail.com>
This commit is contained in:
gufe44 2020-08-03 17:56:50 +02:00
parent 22b265b9f2
commit 206cb39116
2 changed files with 5 additions and 5 deletions

View file

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