From 83bf58817976fdfceead0ddb842c19dcb99721a3 Mon Sep 17 00:00:00 2001 From: Fletcher Dunn Date: Tue, 14 Jun 2022 17:51:54 -0700 Subject: [PATCH] Don't customize OpenSSL rand if >= OpenSSL 3.0 The functions are deprecreated and it's breaking the build. Should fix #236 --- src/common/opensslwrapper.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/common/opensslwrapper.cpp b/src/common/opensslwrapper.cpp index 92128e7..fa497ae 100644 --- a/src/common/opensslwrapper.cpp +++ b/src/common/opensslwrapper.cpp @@ -32,8 +32,12 @@ struct CRYPTO_dynlock_value std::recursive_mutex m_Mutex; }; +// Custom random number generation. I am not sure why we are doing this. +// Apparently it was important in earlier versions of OpenSSL, but I am +// doubtful we still need it. It's deprecated in 3.0. +#if !IsAndroid() && ( OPENSSL_VERSION_NUMBER < 0x30000000 ) +#define OPENSSL_CUSTOM_RAND -#ifndef ANDROID static int RAND_CryptoGenRandom_bytes( unsigned char *buf, int num ) { CCrypto::GenerateRandomBlock( buf, num ); return 1; @@ -48,6 +52,7 @@ static const RAND_METHOD RAND_CryptoGenRandom = RAND_CryptoGenRandom_bytes, // generate pseudo-random RAND_CryptoGenRandom_status // status }; + #endif //----------------------------------------------------------------------------- @@ -69,9 +74,9 @@ void COpenSSLWrapper::Initialize() CRYPTO_set_dynlock_destroy_callback( COpenSSLWrapper::OpenSSLDynLockDestroyCallback ); CRYPTO_set_dynlock_lock_callback( COpenSSLWrapper::OpenSSLDynLockLockCallback ); -#ifndef ANDROID - RAND_set_rand_method( &RAND_CryptoGenRandom ); -#endif + #ifdef OPENSSL_CUSTOM_RAND + RAND_set_rand_method( &RAND_CryptoGenRandom ); + #endif iStatus = RAND_status(); AssertMsg( iStatus == 1, "OpenSSL random number system reports not enough entropy" );