diff --git Source/WTF/wtf/RandomDevice.cpp Source/WTF/wtf/RandomDevice.cpp index 61d6057..90fa30c 100644 --- Source/WTF/wtf/RandomDevice.cpp +++ Source/WTF/wtf/RandomDevice.cpp @@ -30,24 +30,12 @@ #include <stdint.h> #include <stdlib.h> -#if !OS(DARWIN) && OS(UNIX) #include <errno.h> #include <fcntl.h> #include <unistd.h> -#endif - -#if OS(WINDOWS) -#include <windows.h> -#include <wincrypt.h> // windows.h must be included before wincrypt.h. -#endif - -#if OS(DARWIN) -#include "CommonCryptoSPI.h" -#endif namespace WTF { -#if !OS(DARWIN) && OS(UNIX) NEVER_INLINE NO_RETURN_DUE_TO_CRASH static void crashUnableToOpenURandom() { CRASH(); @@ -57,9 +45,7 @@ NEVER_INLINE NO_RETURN_DUE_TO_CRASH static void crashUnableToReadFromURandom() { CRASH(); } -#endif -#if !OS(DARWIN) && !OS(WINDOWS) RandomDevice::RandomDevice() { int ret = 0; @@ -70,22 +56,16 @@ RandomDevice::RandomDevice() if (m_fd < 0) crashUnableToOpenURandom(); // We need /dev/urandom for this API to work... } -#endif -#if !OS(DARWIN) && !OS(WINDOWS) RandomDevice::~RandomDevice() { close(m_fd); } -#endif // FIXME: Make this call fast by creating the pool in RandomDevice. // https://bugs.webkit.org/show_bug.cgi?id=170190 void RandomDevice::cryptographicallyRandomValues(unsigned char* buffer, size_t length) { -#if OS(DARWIN) - RELEASE_ASSERT(!CCRandomCopyBytes(kCCRandomDefault, buffer, length)); -#elif OS(UNIX) ssize_t amountRead = 0; while (static_cast<size_t>(amountRead) < length) { ssize_t currentRead = read(m_fd, buffer + amountRead, length - amountRead); @@ -97,20 +77,6 @@ void RandomDevice::cryptographicallyRandomValues(unsigned char* buffer, size_t l } else amountRead += currentRead; } -#elif OS(WINDOWS) - // FIXME: We cannot ensure that Cryptographic Service Provider context and CryptGenRandom are safe across threads. - // If it is safe, we can acquire context per RandomDevice. - HCRYPTPROV hCryptProv = 0; - if (!CryptAcquireContext(&hCryptProv, 0, MS_DEF_PROV, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) - CRASH(); - if (!CryptGenRandom(hCryptProv, length, buffer)) - CRASH(); - CryptReleaseContext(hCryptProv, 0); -#else -#error "This configuration doesn't have a strong source of randomness." -// WARNING: When adding new sources of OS randomness, the randomness must -// be of cryptographic quality! -#endif } } diff --git Source/WTF/wtf/RandomDevice.h Source/WTF/wtf/RandomDevice.h index 86636c9..410ccd0 100644 --- Source/WTF/wtf/RandomDevice.h +++ Source/WTF/wtf/RandomDevice.h @@ -34,12 +34,8 @@ namespace WTF { class RandomDevice { WTF_MAKE_NONCOPYABLE(RandomDevice); public: -#if OS(DARWIN) || OS(WINDOWS) - RandomDevice() = default; -#else RandomDevice(); ~RandomDevice(); -#endif // This function attempts to fill buffer with randomness from the operating // system. Rather than calling this function directly, consider calling @@ -47,14 +43,7 @@ public: void cryptographicallyRandomValues(unsigned char* buffer, size_t length); private: -#if OS(DARWIN) || OS(WINDOWS) -#elif OS(UNIX) int m_fd { -1 }; -#else -#error "This configuration doesn't have a strong source of randomness." -// WARNING: When adding new sources of OS randomness, the randomness must -// be of cryptographic quality! -#endif }; }