diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/build-data/os/mingw.txt | 1 | ||||
-rw-r--r-- | src/build-data/os/windows.txt | 1 | ||||
-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 |
5 files changed, 17 insertions, 5 deletions
diff --git a/src/build-data/os/mingw.txt b/src/build-data/os/mingw.txt index 1268298cb..59d9db348 100644 --- a/src/build-data/os/mingw.txt +++ b/src/build-data/os/mingw.txt @@ -20,6 +20,7 @@ mingw32 </aliases> <target_features> +cryptgenrandom loadlibrary win32_virtual_lock win32_get_systemtime diff --git a/src/build-data/os/windows.txt b/src/build-data/os/windows.txt index bba2e14ec..5afd2596b 100644 --- a/src/build-data/os/windows.txt +++ b/src/build-data/os/windows.txt @@ -11,6 +11,7 @@ install_cmd_data "copy" install_cmd_exec "copy" <target_features> +cryptgenrandom gmtime_s loadlibrary query_perf_counter 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(); } |