43
43
#include < sys/sysctl.h>
44
44
#endif
45
45
46
- #include < openssl/err.h>
47
- #include < openssl/rand.h>
48
- #include < openssl/conf.h>
49
-
50
46
[[noreturn]] static void RandFailure ()
51
47
{
52
48
LogPrintf (" Failed to read randomness, aborting\n " );
@@ -347,8 +343,6 @@ void GetOSRand(unsigned char *ent32)
347
343
#endif
348
344
}
349
345
350
- void LockingCallbackOpenSSL (int mode, int i, const char * file, int line);
351
-
352
346
namespace {
353
347
354
348
class RNGState {
@@ -364,31 +358,15 @@ class RNGState {
364
358
unsigned char m_state[32 ] GUARDED_BY(m_mutex) = {0 };
365
359
uint64_t m_counter GUARDED_BY (m_mutex) = 0;
366
360
bool m_strongly_seeded GUARDED_BY (m_mutex) = false;
367
- std::unique_ptr<Mutex[]> m_mutex_openssl;
368
361
369
362
public:
370
363
RNGState () noexcept
371
364
{
372
365
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 ();
384
366
}
385
367
386
368
~RNGState ()
387
369
{
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 );
392
370
}
393
371
394
372
/* * Extract up to 32 bytes of entropy from the RNG state, mixing in new entropy from hasher.
@@ -424,8 +402,6 @@ class RNGState {
424
402
memory_cleanse (buf, 64 );
425
403
return ret;
426
404
}
427
-
428
- Mutex& GetOpenSSLMutex (int i) { return m_mutex_openssl[i]; }
429
405
};
430
406
431
407
RNGState& GetRNGState () noexcept
@@ -437,17 +413,6 @@ RNGState& GetRNGState() noexcept
437
413
}
438
414
}
439
415
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
-
451
416
/* A note on the use of noexcept in the seeding functions below:
452
417
*
453
418
* None of the RNG code should ever throw any exception, with the sole exception
0 commit comments