Skip to content

Commit 690c938

Browse files
fanquakeFuzzbawls
authored andcommitted
random: Remove remaining OpenSSL calls and locking infrastructure
1 parent 602c0b2 commit 690c938

File tree

1 file changed

+0
-37
lines changed

1 file changed

+0
-37
lines changed

src/random.cpp

-37
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,6 @@
4646
#include <sys/sysctl.h>
4747
#endif
4848

49-
#include <mutex>
50-
51-
#include <openssl/err.h>
52-
#include <openssl/rand.h>
53-
#include <openssl/conf.h>
54-
5549
[[noreturn]] static void RandFailure()
5650
{
5751
LogPrintf("Failed to read randomness, aborting\n");
@@ -352,8 +346,6 @@ void GetOSRand(unsigned char *ent32)
352346
#endif
353347
}
354348

355-
void LockingCallbackOpenSSL(int mode, int i, const char* file, int line);
356-
357349
namespace {
358350

359351
class RNGState {
@@ -369,7 +361,6 @@ class RNGState {
369361
unsigned char m_state[32] GUARDED_BY(m_mutex) = {0};
370362
uint64_t m_counter GUARDED_BY(m_mutex) = 0;
371363
bool m_strongly_seeded GUARDED_BY(m_mutex) = false;
372-
std::unique_ptr<Mutex[]> m_mutex_openssl;
373364

374365
Mutex m_events_mutex;
375366
CSHA256 m_events_hasher GUARDED_BY(m_events_mutex);
@@ -378,25 +369,10 @@ class RNGState {
378369
RNGState() noexcept
379370
{
380371
InitHardwareRand();
381-
382-
// Init OpenSSL library multithreading support
383-
m_mutex_openssl.reset(new Mutex[CRYPTO_num_locks()]);
384-
CRYPTO_set_locking_callback(LockingCallbackOpenSSL);
385-
386-
// OpenSSL can optionally load a config file which lists optional loadable modules and engines.
387-
// We don't use them so we don't require the config. However some of our libs may call functions
388-
// which attempt to load the config file, possibly resulting in an exit() or crash if it is missing
389-
// or corrupt. Explicitly tell OpenSSL not to try to load the file. The result for our libs will be
390-
// that the config appears to have been loaded and there are no modules/engines available.
391-
OPENSSL_no_config();
392372
}
393373

394374
~RNGState()
395375
{
396-
// Securely erase the memory used by the OpenSSL PRNG
397-
RAND_cleanup();
398-
// Shutdown OpenSSL library multithreading support
399-
CRYPTO_set_locking_callback(nullptr);
400376
}
401377

402378
void AddEvent(uint32_t event_info) noexcept
@@ -461,8 +437,6 @@ class RNGState {
461437
memory_cleanse(buf, 64);
462438
return ret;
463439
}
464-
465-
Mutex& GetOpenSSLMutex(int i) { return m_mutex_openssl[i]; }
466440
};
467441

468442
RNGState& GetRNGState() noexcept
@@ -474,17 +448,6 @@ RNGState& GetRNGState() noexcept
474448
}
475449
}
476450

477-
void LockingCallbackOpenSSL(int mode, int i, const char* file, int line) NO_THREAD_SAFETY_ANALYSIS
478-
{
479-
RNGState& rng = GetRNGState();
480-
481-
if (mode & CRYPTO_LOCK) {
482-
rng.GetOpenSSLMutex(i).lock();
483-
} else {
484-
rng.GetOpenSSLMutex(i).unlock();
485-
}
486-
}
487-
488451
/* A note on the use of noexcept in the seeding functions below:
489452
*
490453
* None of the RNG code should ever throw any exception.

0 commit comments

Comments
 (0)