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 | |
parent | afe3d5fe0a528f7addae6bba999b739789b8b3a8 (diff) |
Enable system_rng on Windows and MinGW (untested)
-rw-r--r-- | doc/relnotes/1_11_11.rst | 10 | ||||
-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 |
6 files changed, 27 insertions, 5 deletions
diff --git a/doc/relnotes/1_11_11.rst b/doc/relnotes/1_11_11.rst index 4eb7e948c..6191bd431 100644 --- a/doc/relnotes/1_11_11.rst +++ b/doc/relnotes/1_11_11.rst @@ -13,3 +13,13 @@ Version 1.11.11, Not Yet Released Applications which would like to use a different db can now do so without having to reimplement the session cache logic simply by implementing a database wrapper subtype. + +* The CryptGenRandom entropy source is now also used on MinGW. + +* The system_rng API is now also available on systems with CryptGenRandom + +* With GCC use -fstack-protector for linking as well as compiling, + as this is required on MinGW. Github issue 34. + +* Fix missing dependency in filters that caused compilation problem + in amalgamation builds. Github issue 33. 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(); } |