That thread_specific_ptr was rubbish...

This commit is contained in:
lotodore
2007-03-02 00:34:50 +00:00
parent 991ec9e5e6
commit cb3c17573d
+34 -37
View File
@@ -16,21 +16,20 @@
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef _WIN32
#ifndef _WIN32
#error This source code is Win32 only.
#endif
#include <windows.h>
#include <wincrypt.h>
#endif
#include <boost/thread.hpp>
#include <core/rand.h>
class CryptData
{
public:
CryptData()
{
#include <windows.h>
#include <wincrypt.h>
#include <core/rand.h>
class CryptData
{
public:
CryptData()
{
if (!::CryptAcquireContext(
&cryptProvider,
NULL,
@@ -40,27 +39,25 @@ public:
{
cryptProvider = 0;
}
}
~CryptData()
{
if (cryptProvider) CryptReleaseContext(cryptProvider, 0);
}
HCRYPTPROV cryptProvider;
};
void
RandomBytes(unsigned char *buf, unsigned size)
{
static boost::thread_specific_ptr<CryptData> m_cryptData;
if (!m_cryptData.get())
m_cryptData.reset(new CryptData);
HCRYPTPROV provider = m_cryptData.get()->cryptProvider;
if (provider)
::CryptGenRandom(provider, size, buf);
}
}
~CryptData()
{
if (cryptProvider)
CryptReleaseContext(cryptProvider, 0);
}
HCRYPTPROV cryptProvider;
};
static CryptData g_cryptData;
void
RandomBytes(unsigned char *buf, unsigned size)
{
HCRYPTPROV provider = g_cryptData.cryptProvider;
if (provider)
::CryptGenRandom(provider, size, buf);
}