From 206cb39116280f4f9f1a5208578651cbfee74052 Mon Sep 17 00:00:00 2001 From: gufe44 Date: Mon, 3 Aug 2020 17:56:50 +0200 Subject: [PATCH 1/3] 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 --- library/rsa.c | 6 +++--- tests/suites/helpers.function | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/library/rsa.c b/library/rsa.c index 96afccb0e..db6d195e2 100644 --- a/library/rsa.c +++ b/library/rsa.c @@ -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 #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 ); } diff --git a/tests/suites/helpers.function b/tests/suites/helpers.function index 96e18da16..e38df8281 100644 --- a/tests/suites/helpers.function +++ b/tests/suites/helpers.function @@ -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 ); } From 6f837332f0bb35ad34acb2f8458f7d83645b792b Mon Sep 17 00:00:00 2001 From: gufe44 Date: Thu, 6 Aug 2020 12:52:04 +0200 Subject: [PATCH 2/3] Add changelog entry Signed-off-by: gufe44 --- ChangeLog.d/netbsd-rand-arc4random_buf.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 ChangeLog.d/netbsd-rand-arc4random_buf.txt diff --git a/ChangeLog.d/netbsd-rand-arc4random_buf.txt b/ChangeLog.d/netbsd-rand-arc4random_buf.txt new file mode 100644 index 000000000..7f5802e8c --- /dev/null +++ b/ChangeLog.d/netbsd-rand-arc4random_buf.txt @@ -0,0 +1,3 @@ +Changes + * Use arc4random_buf on NetBSD instead of rand implementation with cyclical + lower bits. Fix contributed in #3540. From da0ea9e9dfccf01782e80d3d1710e9bc7f1e7e16 Mon Sep 17 00:00:00 2001 From: gufe44 Date: Thu, 13 Aug 2020 06:24:42 +0200 Subject: [PATCH 3/3] Log change as bugfix Signed-off-by: gufe44 --- ChangeLog.d/netbsd-rand-arc4random_buf.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChangeLog.d/netbsd-rand-arc4random_buf.txt b/ChangeLog.d/netbsd-rand-arc4random_buf.txt index 7f5802e8c..8539d1f5e 100644 --- a/ChangeLog.d/netbsd-rand-arc4random_buf.txt +++ b/ChangeLog.d/netbsd-rand-arc4random_buf.txt @@ -1,3 +1,3 @@ -Changes +Bugfix * Use arc4random_buf on NetBSD instead of rand implementation with cyclical lower bits. Fix contributed in #3540.