diff options
author | Jack Lloyd <[email protected]> | 2018-05-07 20:11:44 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2018-05-07 20:11:44 -0400 |
commit | cc2b24f85695653a3a6701339ffc57e76b2f1c60 (patch) | |
tree | 9717360ef6597ef3e5133b05d5d3ebbb1517afe2 /src/lib/rng/system_rng/system_rng.cpp | |
parent | 312f0194e09a2f2cef5af3750fd750a1d0137945 (diff) | |
parent | 819b7febe479dfa7f1c07ab52c890ca33b00f023 (diff) |
Merge GH #1563 Use correct calling convention for RtlGenRandom
Diffstat (limited to 'src/lib/rng/system_rng/system_rng.cpp')
-rw-r--r-- | src/lib/rng/system_rng/system_rng.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/lib/rng/system_rng/system_rng.cpp b/src/lib/rng/system_rng/system_rng.cpp index 32dabbe9f..3c2e98661 100644 --- a/src/lib/rng/system_rng/system_rng.cpp +++ b/src/lib/rng/system_rng/system_rng.cpp @@ -36,12 +36,13 @@ class System_RNG_Impl final : public RandomNumberGenerator System_RNG_Impl() : m_advapi("advapi32.dll") { // This throws if the function is not found - m_rtlgenrandom = m_advapi.resolve<RtlGenRandom_f>("SystemFunction036"); + m_rtlgenrandom = m_advapi.resolve<RtlGenRandom_fptr>("SystemFunction036"); } void randomize(uint8_t buf[], size_t len) override { - if(m_rtlgenrandom(buf, len) == false) + bool success = m_rtlgenrandom(buf, len) == TRUE; + if(!success) throw Exception("RtlGenRandom failed"); } @@ -50,10 +51,13 @@ class System_RNG_Impl final : public RandomNumberGenerator void clear() override { /* not possible */ } std::string name() const override { return "RtlGenRandom"; } private: - typedef BOOL (*RtlGenRandom_f)(PVOID, ULONG); + // Use type BYTE instead of BOOLEAN because of a naming conflict + // https://msdn.microsoft.com/en-us/library/windows/desktop/aa387694(v=vs.85).aspx + // https://msdn.microsoft.com/en-us/library/windows/desktop/aa383751(v=vs.85).aspx + using RtlGenRandom_fptr = BYTE (NTAPI *)(PVOID, ULONG); Dynamically_Loaded_Library m_advapi; - RtlGenRandom_f m_rtlgenrandom; + RtlGenRandom_fptr m_rtlgenrandom; }; #elif defined(BOTAN_TARGET_OS_HAS_ARC4RANDOM) |