summaryrefslogtreecommitdiff
path: root/cpp/src/IceUtil/Random.cpp
diff options
context:
space:
mode:
authorBenoit Foucher <benoit@zeroc.com>2014-07-07 12:33:30 +0200
committerBenoit Foucher <benoit@zeroc.com>2014-07-07 12:33:30 +0200
commite247bd81d2fc3ef556365c2c54bff571a880f2a7 (patch)
treeee7018543a36e0045340b4d40506072a06be128e /cpp/src/IceUtil/Random.cpp
parentFixed ICE-5394: removed deprecated C++ ice_getHash method (diff)
downloadice-e247bd81d2fc3ef556365c2c54bff571a880f2a7.tar.bz2
ice-e247bd81d2fc3ef556365c2c54bff571a880f2a7.tar.xz
ice-e247bd81d2fc3ef556365c2c54bff571a880f2a7.zip
Fixed ICE-5532: removed un-used CryptGenRandom code
Diffstat (limited to 'cpp/src/IceUtil/Random.cpp')
-rw-r--r--cpp/src/IceUtil/Random.cpp51
1 files changed, 5 insertions, 46 deletions
diff --git a/cpp/src/IceUtil/Random.cpp b/cpp/src/IceUtil/Random.cpp
index 0e557ab2b20..68c125ebb25 100644
--- a/cpp/src/IceUtil/Random.cpp
+++ b/cpp/src/IceUtil/Random.cpp
@@ -15,9 +15,7 @@
#include <IceUtil/Mutex.h>
#include <IceUtil/MutexPtrLock.h>
-#ifdef _WIN32
-# include <Wincrypt.h>
-#else
+#ifndef _WIN32
# include <unistd.h>
# include <fcntl.h>
#endif
@@ -25,14 +23,13 @@
using namespace std;
using namespace IceUtil;
-#if !defined(_WIN32) || !defined(_MSC_VER)
+#if !defined(_WIN32)
namespace
{
//
// The static mutex is required to lazy initialize the file
-// descriptor for /dev/urandom (Unix) or the cryptographic
-// context (Windows).
+// descriptor for /dev/urandom (Unix)
//
// Also, unfortunately on Linux (at least up to 2.6.9), concurrent
// access to /dev/urandom can return the same value. Search for
@@ -43,10 +40,8 @@ namespace
// static mutex.
//
Mutex* staticMutex = 0;
-#ifdef _WIN32
-HCRYPTPROV context = 0;
-#else
int fd = -1;
+
//
// Callback to use with pthread_atfork to reset the "/dev/urandom"
// fd state. We don't need to close the fd here as that is done
@@ -64,7 +59,6 @@ void childAtFork()
}
}
-#endif
class Init
{
@@ -73,30 +67,21 @@ public:
Init()
{
staticMutex = new IceUtil::Mutex;
-#ifndef _WIN32
+
//
// Register a callback to reset the "/dev/urandom" fd
// state after fork.
//
pthread_atfork(0, 0, &childAtFork);
-#endif
}
~Init()
{
-#ifdef _WIN32
- if(context != 0)
- {
- CryptReleaseContext(context, 0);
- context = 0;
- }
-#else
if(fd != -1)
{
close(fd);
fd = -1;
}
-#endif
delete staticMutex;
staticMutex = 0;
}
@@ -111,37 +96,11 @@ void
IceUtilInternal::generateRandom(char* buffer, int size)
{
#ifdef _WIN32
-
-# if defined(_MSC_VER)
for(int i = 0; i < size; ++i)
{
buffer[i] = random(256);
}
-# else
- //
- // It's not clear from the Microsoft documentation if CryptGenRandom
- // can be called concurrently from several threads. To be on the safe
- // side, we also serialize calls to CryptGenRandom with the static
- // mutex.
- //
-
- IceUtilInternal::MutexPtrLock<IceUtil::Mutex> lock(staticMutex);
- if(context == 0)
- {
- if(!CryptAcquireContext(&context, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))
- {
- throw SyscallException(__FILE__, __LINE__, GetLastError());
- }
- }
-
- if(!CryptGenRandom(context, size, reinterpret_cast<unsigned char*>(buffer)))
- {
- throw SyscallException(__FILE__, __LINE__, GetLastError());
- }
-# endif
-
#else
-
//
// Serialize access to /dev/urandom; see comment above.
//