Skip to content

Commit b49b6b0

Browse files
committed
random: Remove remaining OpenSSL calls and locking infrastructure
1 parent 4fcfcc2 commit b49b6b0

File tree

1 file changed

+0
-35
lines changed

1 file changed

+0
-35
lines changed

src/random.cpp

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@
4343
#include <sys/sysctl.h>
4444
#endif
4545

46-
#include <openssl/err.h>
47-
#include <openssl/rand.h>
48-
#include <openssl/conf.h>
49-
5046
[[noreturn]] static void RandFailure()
5147
{
5248
LogPrintf("Failed to read randomness, aborting\n");
@@ -347,8 +343,6 @@ void GetOSRand(unsigned char *ent32)
347343
#endif
348344
}
349345

350-
void LockingCallbackOpenSSL(int mode, int i, const char* file, int line);
351-
352346
namespace {
353347

354348
class RNGState {
@@ -364,31 +358,15 @@ class RNGState {
364358
unsigned char m_state[32] GUARDED_BY(m_mutex) = {0};
365359
uint64_t m_counter GUARDED_BY(m_mutex) = 0;
366360
bool m_strongly_seeded GUARDED_BY(m_mutex) = false;
367-
std::unique_ptr<Mutex[]> m_mutex_openssl;
368361

369362
public:
370363
RNGState() noexcept
371364
{
372365
InitHardwareRand();
373-
374-
// Init OpenSSL library multithreading support
375-
m_mutex_openssl.reset(new Mutex[CRYPTO_num_locks()]);
376-
CRYPTO_set_locking_callback(LockingCallbackOpenSSL);
377-
378-
// OpenSSL can optionally load a config file which lists optional loadable modules and engines.
379-
// We don't use them so we don't require the config. However some of our libs may call functions
380-
// which attempt to load the config file, possibly resulting in an exit() or crash if it is missing
381-
// or corrupt. Explicitly tell OpenSSL not to try to load the file. The result for our libs will be
382-
// that the config appears to have been loaded and there are no modules/engines available.
383-
OPENSSL_no_config();
384366
}
385367

386368
~RNGState()
387369
{
388-
// Securely erase the memory used by the OpenSSL PRNG
389-
RAND_cleanup();
390-
// Shutdown OpenSSL library multithreading support
391-
CRYPTO_set_locking_callback(nullptr);
392370
}
393371

394372
/** Extract up to 32 bytes of entropy from the RNG state, mixing in new entropy from hasher.
@@ -424,8 +402,6 @@ class RNGState {
424402
memory_cleanse(buf, 64);
425403
return ret;
426404
}
427-
428-
Mutex& GetOpenSSLMutex(int i) { return m_mutex_openssl[i]; }
429405
};
430406

431407
RNGState& GetRNGState() noexcept
@@ -437,17 +413,6 @@ RNGState& GetRNGState() noexcept
437413
}
438414
}
439415

440-
void LockingCallbackOpenSSL(int mode, int i, const char* file, int line) NO_THREAD_SAFETY_ANALYSIS
441-
{
442-
RNGState& rng = GetRNGState();
443-
444-
if (mode & CRYPTO_LOCK) {
445-
rng.GetOpenSSLMutex(i).lock();
446-
} else {
447-
rng.GetOpenSSLMutex(i).unlock();
448-
}
449-
}
450-
451416
/* A note on the use of noexcept in the seeding functions below:
452417
*
453418
* None of the RNG code should ever throw any exception, with the sole exception

0 commit comments

Comments
 (0)