Skip to content

Commit cddb31b

Browse files
committed
Encapsulate RNGState better
1 parent 152146e commit cddb31b

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/random.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,13 +278,14 @@ void LockingCallbackOpenSSL(int mode, int i, const char* file, int line);
278278

279279
namespace {
280280

281-
struct RNGState {
281+
class RNGState {
282282
Mutex m_mutex;
283283
unsigned char m_state[32] GUARDED_BY(m_mutex) = {0};
284284
uint64_t m_counter GUARDED_BY(m_mutex) = 0;
285285
bool m_strongly_seeded GUARDED_BY(m_mutex) = false;
286286
std::unique_ptr<Mutex[]> m_mutex_openssl;
287287

288+
public:
288289
RNGState() noexcept
289290
{
290291
InitHardwareRand();
@@ -342,6 +343,8 @@ struct RNGState {
342343
memory_cleanse(buf, 64);
343344
return ret;
344345
}
346+
347+
Mutex& GetOpenSSLMutex(int i) { return m_mutex_openssl[i]; }
345348
};
346349

347350
RNGState& GetRNGState() noexcept
@@ -358,9 +361,9 @@ void LockingCallbackOpenSSL(int mode, int i, const char* file, int line) NO_THRE
358361
RNGState& rng = GetRNGState();
359362

360363
if (mode & CRYPTO_LOCK) {
361-
rng.m_mutex_openssl[i].lock();
364+
rng.GetOpenSSLMutex(i).lock();
362365
} else {
363-
rng.m_mutex_openssl[i].unlock();
366+
rng.GetOpenSSLMutex(i).unlock();
364367
}
365368
}
366369

0 commit comments

Comments
 (0)