46
46
#include < sys/sysctl.h>
47
47
#endif
48
48
49
- #include < mutex>
50
-
51
- #include < openssl/err.h>
52
- #include < openssl/rand.h>
53
- #include < openssl/conf.h>
54
-
55
49
[[noreturn]] static void RandFailure ()
56
50
{
57
51
LogPrintf (" Failed to read randomness, aborting\n " );
@@ -352,8 +346,6 @@ void GetOSRand(unsigned char *ent32)
352
346
#endif
353
347
}
354
348
355
- void LockingCallbackOpenSSL (int mode, int i, const char * file, int line);
356
-
357
349
namespace {
358
350
359
351
class RNGState {
@@ -369,7 +361,6 @@ class RNGState {
369
361
unsigned char m_state[32 ] GUARDED_BY(m_mutex) = {0 };
370
362
uint64_t m_counter GUARDED_BY (m_mutex) = 0;
371
363
bool m_strongly_seeded GUARDED_BY (m_mutex) = false;
372
- std::unique_ptr<Mutex[]> m_mutex_openssl;
373
364
374
365
Mutex m_events_mutex;
375
366
CSHA256 m_events_hasher GUARDED_BY (m_events_mutex);
@@ -378,25 +369,10 @@ class RNGState {
378
369
RNGState () noexcept
379
370
{
380
371
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 ();
392
372
}
393
373
394
374
~RNGState ()
395
375
{
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 );
400
376
}
401
377
402
378
void AddEvent (uint32_t event_info) noexcept
@@ -461,8 +437,6 @@ class RNGState {
461
437
memory_cleanse (buf, 64 );
462
438
return ret;
463
439
}
464
-
465
- Mutex& GetOpenSSLMutex (int i) { return m_mutex_openssl[i]; }
466
440
};
467
441
468
442
RNGState& GetRNGState () noexcept
@@ -474,17 +448,6 @@ RNGState& GetRNGState() noexcept
474
448
}
475
449
}
476
450
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
-
488
451
/* A note on the use of noexcept in the seeding functions below:
489
452
*
490
453
* None of the RNG code should ever throw any exception.
0 commit comments