X-Git-Url: https://git.saurik.com/apple/security.git/blobdiff_plain/914fc88e61be54aed6b18205ff2775b48793a3b6..866f8763175ff60e4fa455b92b5eb660a12fe6c7:/OSX/libsecurity_utilities/lib/devrandom.cpp diff --git a/OSX/libsecurity_utilities/lib/devrandom.cpp b/OSX/libsecurity_utilities/lib/devrandom.cpp index f08c2d97..626ed7ef 100644 --- a/OSX/libsecurity_utilities/lib/devrandom.cpp +++ b/OSX/libsecurity_utilities/lib/devrandom.cpp @@ -27,6 +27,7 @@ // #include #include +#include using namespace UnixPlusPlus; @@ -37,7 +38,6 @@ namespace Security { // // The common (shared) open file descriptor to /dev/random // -ModuleNexus DevRandomGenerator::mReader; ModuleNexus DevRandomGenerator::mWriter; @@ -54,18 +54,10 @@ DevRandomGenerator::DevRandomGenerator(bool writable) // void DevRandomGenerator::random(void *data, size_t length) { - try { - size_t bytesRead = mReader().read(data, length); - if (bytesRead != length) { // short read (shouldn't happen) - Syslog::error("DevRandomGenerator: wanted %ld got %ld bytes", - length, bytesRead); - UnixError::throwMe(EIO); - } - } catch(const UnixError &uerr) { - Syslog::error("DevRandomGenerator: error %d reading /dev/random", - uerr.error); - throw; - } + if (CCRandomCopyBytes(kCCRandomDefault, data, length)) { + Syslog::error("DevRandomGenerator: failed to generate random"); + UnixError::throwMe(EIO); + } }