📄 esrccryptoapi.cpp
字号:
/* Copyright 2001,2002,2003 NAH6 BV
* All Rights Reserved
*
* $Header: /var/lib/cvs/secphone/ui/rng/sources/esrcCryptoApi.cpp,v 1.4 2003/11/21 16:12:58 itsme Exp $
*
*
* this module implements entropy gathering from the microsoft crypto api
*
* this is called at regular intervals.
*
* only on the win32 desktop version this provides proper random.
*
*/
#include <windows.h> // nescesary for wincrypt
#include <wincrypt.h>
#include "debug.h"
#include "esrcCryptoApi.h"
esrcCryptoApi::esrcCryptoApi()
{
if (!CryptAcquireContext(&m_hProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))
{
error("esrcCryptoApi: ginitializing cryptoapi\n");
m_hProv= NULL;
}
}
esrcCryptoApi::~esrcCryptoApi()
{
if (m_hProv!=NULL)
{
CryptReleaseContext(m_hProv, 0);
m_hProv= NULL;
}
}
bool esrcCryptoApi::IsPolledSource() const
{
return true;
}
void esrcCryptoApi::HandleSource()
{
ByteVector data; data.resize(16);
if (!CryptGenRandom(m_hProv, data.size(), vectorptr(data)))
{
error("esrcCryptoApi: getting random data\n");
return;
}
AddRandom(data);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -