diff options
author | lloyd <[email protected]> | 2014-12-21 19:40:13 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2014-12-21 19:40:13 +0000 |
commit | 2882141ba37e7605dcb2104234b3b4d11ba57810 (patch) | |
tree | 6d5d70dbd42c2d1b6284c55d63484e56527143a4 /src/lib/rng/system_rng | |
parent | afe3d5fe0a528f7addae6bba999b739789b8b3a8 (diff) |
Enable system_rng on Windows and MinGW (untested)
Diffstat (limited to 'src/lib/rng/system_rng')
-rw-r--r-- | src/lib/rng/system_rng/info.txt | 4 | ||||
-rw-r--r-- | src/lib/rng/system_rng/system_rng.cpp | 11 | ||||
-rw-r--r-- | src/lib/rng/system_rng/system_rng.h | 5 |
3 files changed, 15 insertions, 5 deletions
diff --git a/src/lib/rng/system_rng/info.txt b/src/lib/rng/system_rng/info.txt index 387b7e1dd..a452a7d9b 100644 --- a/src/lib/rng/system_rng/info.txt +++ b/src/lib/rng/system_rng/info.txt @@ -1,5 +1,7 @@ define SYSTEM_RNG 20141202 +# Any system with /dev/random or CryptGenRandom + <os> aix cygwin @@ -11,9 +13,11 @@ hpux hurd irix linux +mingw netbsd openbsd qnx solaris tru64 +windows </os> diff --git a/src/lib/rng/system_rng/system_rng.cpp b/src/lib/rng/system_rng/system_rng.cpp index cdf85ef29..70222530c 100644 --- a/src/lib/rng/system_rng/system_rng.cpp +++ b/src/lib/rng/system_rng/system_rng.cpp @@ -7,7 +7,7 @@ #include <botan/system_rng.h> -#if defined(BOTAN_TARGET_OS_IS_WINDOWS) +#if defined(BOTAN_TARGET_OS_HAS_CRYPTGENRANDOM) #include <windows.h> #include <wincrypt.h> @@ -45,7 +45,7 @@ class System_RNG : public RandomNumberGenerator void add_entropy(const byte[], size_t) {} private: -#if defined(BOTAN_TARGET_OS_IS_WINDOWS) +#if defined(BOTAN_TARGET_OS_HAS_CRYPTGENRANDOM) HCRYPTPROV m_prov; #else int m_fd; @@ -54,7 +54,7 @@ class System_RNG : public RandomNumberGenerator System_RNG::System_RNG() { -#if defined(BOTAN_TARGET_OS_IS_WINDOWS) +#if defined(BOTAN_TARGET_OS_HAS_CRYPTGENRANDOM) if(!CryptAcquireContext(&m_prov, 0, 0, RSA_FULL, CRYPT_VERIFYCONTEXT)) throw std::runtime_error("System_RNG failed to acquire crypto provider"); @@ -69,16 +69,17 @@ System_RNG::System_RNG() System_RNG::~System_RNG() { -#if defined(BOTAN_TARGET_OS_IS_WINDOWS) +#if defined(BOTAN_TARGET_OS_HAS_CRYPTGENRANDOM) ::CryptReleaseContext(m_prov, 0); #else ::close(m_fd); + m_fd = -1; #endif } void System_RNG::randomize(byte buf[], size_t len) { -#if defined(BOTAN_TARGET_OS_IS_WINDOWS) +#if defined(BOTAN_TARGET_OS_HAS_CRYPTGENRANDOM) ::CryptGenRandom(m_prov, static_cast<DWORD>(len), buf)) #else while(len) diff --git a/src/lib/rng/system_rng/system_rng.h b/src/lib/rng/system_rng/system_rng.h index 6b4746a9c..db91b4ad3 100644 --- a/src/lib/rng/system_rng/system_rng.h +++ b/src/lib/rng/system_rng/system_rng.h @@ -12,6 +12,11 @@ namespace Botan { +/** +* Return a shared reference to a global PRNG instance provided by the +* operating system. For instance might be instantiated by /dev/urandom +* or CryptGenRandom. +*/ BOTAN_DLL RandomNumberGenerator& system_rng(); } |