本文整理汇总了C++中cryptopp::AutoSeededRandomPool类的典型用法代码示例。如果您正苦于以下问题:C++ AutoSeededRandomPool类的具体用法?C++ AutoSeededRandomPool怎么用?C++ AutoSeededRandomPool使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AutoSeededRandomPool类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: genKeyIv
std::size_t genKeyIv(char* _chunk)
{
char* chunk = _chunk;
CryptoPP::AutoSeededRandomPool rnd;
{
CryptoPP::SecByteBlock key(0x00, CryptoPP::AES::DEFAULT_KEYLENGTH);
rnd.GenerateBlock(key, key.size());
byte iv[CryptoPP::AES::BLOCKSIZE];
rnd.GenerateBlock(iv, sizeof(iv));
setEncKeyWithIv(key.data(), key.SizeInBytes(), iv, sizeof(iv));
std::memcpy(chunk, key.data(), key.SizeInBytes());
chunk += key.SizeInBytes();
std::memcpy(chunk, iv, sizeof(iv));
chunk += sizeof(iv);
}
{
CryptoPP::SecByteBlock key(0x00, CryptoPP::AES::DEFAULT_KEYLENGTH);
rnd.GenerateBlock(key, key.size());
byte iv[CryptoPP::AES::BLOCKSIZE];
rnd.GenerateBlock(iv, sizeof(iv));
setDecKeyWithIv(key.data(), key.SizeInBytes(), iv, sizeof(iv));
std::memcpy(chunk, key.data(), key.SizeInBytes());
chunk += key.SizeInBytes();
std::memcpy(chunk, iv, sizeof(iv));
chunk += sizeof(iv);
}
return chunk - _chunk;
}
开发者ID:wumch,项目名称:pvdesktop,代码行数:34,代码来源:Crypto.hpp
示例2:
uint32_t
generateWord32()
{
static CryptoPP::AutoSeededRandomPool rng;
return rng.GenerateWord32();
}
开发者ID:PatrickGuo,项目名称:ndn-cxx-master,代码行数:7,代码来源:random.cpp
示例3: testMac
void VhsmTest::testMac() {
VHSM vhsm;
ClientId cid;
cid.pid = 0; cid.veid = 0;
std::string user = "user";
std::string password = "password";
unsigned int mdsize;
char msg[BUF_SIZE];
std::vector<char> md;
CryptoPP::AutoSeededRandomPool rnd;
rnd.GenerateBlock((byte*)msg, BUF_SIZE);
byte realmd[CryptoPP::HMAC<CryptoPP::SHA1>::DIGESTSIZE];
CryptoPP::HMAC<CryptoPP::SHA1>((byte*)"", 0).CalculateDigest(realmd, (byte*)msg, BUF_SIZE);
VhsmSession s = vhsm.openSession(cid);
CPPUNIT_ASSERT_MESSAGE("login user failed", vhsm.loginUser(user, password, s.sid()));
CPPUNIT_ASSERT_MESSAGE("macInit failed", vhsm.macInit(HMAC, SHA1, s.sid(), "") == ERR_NO_ERROR);
CPPUNIT_ASSERT_MESSAGE("unsupported method accepted", vhsm.macInit((VhsmMacMechanismId)0, (VhsmDigestMechanismId)0, s.sid(), "") == ERR_BAD_MAC_METHOD);
CPPUNIT_ASSERT_MESSAGE("macUpdate failed", vhsm.macUpdate(s.sid(), std::string(msg, BUF_SIZE)) == ERR_NO_ERROR);
CPPUNIT_ASSERT_MESSAGE("invalid session id accepted", vhsm.macUpdate(s.sid() + 1, std::string(msg, BUF_SIZE)) == ERR_MAC_NOT_INITIALIZED);
CPPUNIT_ASSERT_MESSAGE("macGetSize failed", vhsm.macGetSize(s.sid(), &mdsize) == ERR_NO_ERROR);
CPPUNIT_ASSERT_MESSAGE("wrong size returned", mdsize == CryptoPP::HMAC<CryptoPP::SHA1>::DIGESTSIZE);
CPPUNIT_ASSERT_MESSAGE("invalid session id accepted", vhsm.macGetSize(s.sid() + 1, &mdsize) == ERR_MAC_NOT_INITIALIZED);
CPPUNIT_ASSERT_MESSAGE("macFinal failed", vhsm.macFinal(s.sid(), md) == ERR_NO_ERROR);
CPPUNIT_ASSERT_MESSAGE("double digest finalization", vhsm.macFinal(s.sid(), md) == ERR_MAC_NOT_INITIALIZED);
CPPUNIT_ASSERT_MESSAGE("wrong digest", memcmp(realmd, md.data(), CryptoPP::HMAC<CryptoPP::SHA1>::DIGESTSIZE) == 0);
CPPUNIT_ASSERT_MESSAGE("close session failed", vhsm.closeSession(cid, s));
}
开发者ID:GarysRefererence2014,项目名称:vhsm,代码行数:32,代码来源:VhsmTest.cpp
示例4: GenerateRandom
SecureBinaryData SecureBinaryData::GenerateRandom(uint32_t numBytes)
{
static CryptoPP::AutoSeededRandomPool prng;
SecureBinaryData randData(numBytes);
prng.GenerateBlock(randData.getPtr(), numBytes);
return randData;
}
开发者ID:vtcex,项目名称:BitcoinArmory,代码行数:7,代码来源:EncryptionUtils.cpp
示例5:
int Reseeder::ReseedNowSU3 ()
{
CryptoPP::AutoSeededRandomPool rnd;
auto ind = rnd.GenerateWord32 (0, httpReseedHostList.size() - 1);
std::string reseedHost = httpReseedHostList[ind];
return ReseedFromSU3 (reseedHost);
}
开发者ID:hagen-i2p,项目名称:i2pd,代码行数:7,代码来源:Reseed.cpp
示例6: generateRandomKey
void generateRandomKey(std::string name, byte* key, long unsigned int length)
{
CryptoPP::AutoSeededRandomPool prng;
//byte key[CryptoPP::AES::DEFAULT_KEYLENGTH];
prng.GenerateBlock(key, length);
std::string encoded;
CryptoPP::StringSource(key, length, true,
new CryptoPP::HexEncoder(
new CryptoPP::StringSink(encoded)
) // HexEncoder
); // StringSource
std::ofstream outfile;
std::string keyFile = "keys/" + name + ".key";
std::ofstream file_out(keyFile.c_str());
if(file_out.is_open())
{
file_out << encoded;
} //end if valid outfstream
file_out.close();
}
开发者ID:benjaminhkaiser,项目名称:SKB-Protocol,代码行数:26,代码来源:util.cpp
示例7: HandleSubscriptionsUpdateTimer
void AddressBook::HandleSubscriptionsUpdateTimer (const boost::system::error_code& ecode)
{
if (ecode != boost::asio::error::operation_aborted)
{
if (!m_SharedLocalDestination)
return; // TODO: error handling
if (m_IsLoaded && !m_IsDownloading && m_SharedLocalDestination->IsReady ())
{
// pick random subscription
CryptoPP::AutoSeededRandomPool rnd;
auto ind = rnd.GenerateWord32 (0, m_Subscriptions.size() - 1);
m_IsDownloading = true;
m_Subscriptions[ind]->CheckSubscription ();
}
else
{
if (!m_IsLoaded)
LoadHosts ();
// try it again later
m_SubscriptionsUpdateTimer->expires_from_now (boost::posix_time::minutes(INITIAL_SUBSCRIPTION_RETRY_TIMEOUT));
m_SubscriptionsUpdateTimer->async_wait (std::bind (&AddressBook::HandleSubscriptionsUpdateTimer,
this, std::placeholders::_1));
}
}
}
开发者ID:01BTC10,项目名称:i2pd,代码行数:25,代码来源:AddressBook.cpp
示例8: setPassword
void securityInfo::setPassword(const std::string &pw){
password=pw;
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHA1> pbkdf;
CryptoPP::AutoSeededRandomPool rng;
rng.GenerateBlock(pwsalt,pwsalt.size());
icpw=pbkdf.DeriveKey( key, key.size(), 0x00, (byte *) password.data(), password.size(),
pwsalt, pwsalt.size(), 0,0.5);
iciv=pbkdf.DeriveKey(iv, iv.size(), 0x00,(byte *) password.data(), password.size(), pwsalt, pwsalt.size(),
0,0.5);
}
开发者ID:m89264907339,项目名称:2,代码行数:26,代码来源:securityInfo.cpp
示例9: node
// --------------------------------------------------------------------------
document::document () :
node(std::shared_ptr<document>(this, [](document*){})),
m_implementation(m_document)
// --------------------------------------------------------------------------
{
m_html = false;
m_mode = no_quirks_mode;
m_content_type = "application/xml";
m_encoding = "utf-8";
m_url = "about:blank";
if (global_object)
{
m_origin = global_object->m_document->m_origin;
m_script_origin = global_object->m_document->m_script_origin;
}
else
{
// Default is a globally unique identifier.
// We'll just generate 32 random bytes as the ID.
CryptoPP::AutoSeededRandomPool rng;
CryptoPP::HexEncoder enc;
byte bin[32];
char hex[64];
rng.GenerateBlock(bin, 32);
enc.PutMessageEnd(bin, 32);
enc.Get(reinterpret_cast<byte*>(hex), 64);
m_origin = hex;
m_script_origin = m_origin;
}
}
开发者ID:fumu-no-kagomeko,项目名称:libkueea-dom,代码行数:35,代码来源:document.cpp
示例10: seed
static std::string generateChallenge()
{
CryptoPP::AutoSeededRandomPool prng;
CryptoPP::SecByteBlock seed(16);
prng.GenerateBlock(seed, seed.size());
std::string challenge;
CryptoPP::ArraySource(seed, seed.size(), true, new CryptoPP::HexEncoder(new CryptoPP::StringSink(challenge)));
return challenge;
}
开发者ID:Meehanick,项目名称:-TIN-Karbowy,代码行数:9,代码来源:protocol.cpp
示例11: encryptPacket
bool encryptPacket(char* packet, byte* aes_key)
{
try
{
std::string plaintext(packet);
//Decode the key from the file
GCM< AES >::Encryption p;
//iv will help us with keying out cipher
//it is also randomly generated
byte iv[ AES::BLOCKSIZE ];
CryptoPP::AutoSeededRandomPool prng;
prng.GenerateBlock( iv, sizeof(iv) );
//Merge the iv and key
p.SetKeyWithIV( aes_key, CryptoPP::AES::DEFAULT_KEYLENGTH, iv, sizeof(iv) );
//Encode the IV
std::string encoded_iv;
CryptoPP::StringSource(iv, sizeof(iv), true,
new CryptoPP::HexEncoder(
new CryptoPP::StringSink(encoded_iv)
) // HexEncoder
);
//Create the ciphertext from the plaintext
std::string ciphertext;
CryptoPP::StringSource(plaintext, true,
new CryptoPP::AuthenticatedEncryptionFilter(p,
new CryptoPP::StringSink(ciphertext)
)
);
//Encode the cipher to be sent
std::string encodedCipher;
CryptoPP::StringSource(ciphertext, true,
new CryptoPP::HexEncoder(
new CryptoPP::StringSink(encodedCipher)
) // HexEncoder
);
//replace the packet with the econded ciphertext
strcpy(packet, (encoded_iv+encodedCipher).c_str());
packet[(encoded_iv+encodedCipher).size()] = '\0';
//printf("Encrypted packet size: %d\n", (int)strlen(packet));
}
catch(std::exception e)
{
return false;
}
return true;
} //end encryptPacket function
开发者ID:benjaminhkaiser,项目名称:SKB-Protocol,代码行数:53,代码来源:util.cpp
示例12: ss
std::string I2PControlSession::generateToken() const
{
byte random_data[I2P_CONTROL_TOKEN_SIZE] = {};
CryptoPP::AutoSeededRandomPool rng;
rng.GenerateBlock(random_data, I2P_CONTROL_TOKEN_SIZE);
std::string token;
CryptoPP::StringSource ss(
random_data, I2P_CONTROL_TOKEN_SIZE, true,
new CryptoPP::HexEncoder(new CryptoPP::StringSink(token))
);
return token;
}
开发者ID:01BTC10,项目名称:i2pd,代码行数:12,代码来源:I2PControl.cpp
示例13: catch
bool
SecTpmFile::generateRandomBlock(uint8_t* res, size_t size)
{
try {
CryptoPP::AutoSeededRandomPool rng;
rng.GenerateBlock(res, size);
return true;
}
catch (const CryptoPP::Exception& e) {
return false;
}
}
开发者ID:named-data-ndnSIM,项目名称:ndn-cxx,代码行数:12,代码来源:sec-tpm-file.cpp
示例14: do_key_exchange
bool Session::do_key_exchange()
{
aes_buffer aes_tmp;
CryptoPP::AutoSeededRandomPool prng;
prng.GenerateBlock(this->aes.key, sizeof(aes_key));
prng.GenerateBlock(this->aes.iv, sizeof(aes_iv));
std::memcpy(&aes_tmp, &this->aes, sizeof(aes_buffer));
CryptoPP::CFB_Mode<CryptoPP::AES>::Encryption encryptor(aes_hard_key, sizeof(aes_key),
aes_hard_iv);
encryptor.ProcessData((uint8_t*)&aes_tmp, (uint8_t const*)&this->aes, sizeof(aes_buffer));
return (write(this->fd, &aes_tmp, sizeof(aes_buffer)) > 0);
}
开发者ID:nealp9084,项目名称:pen_auth,代码行数:16,代码来源:session.cpp
示例15: set_seed
void Container::set_seed(CryptoPP::SecByteBlock seed)
{
seed_ = seed;
CryptoPP::AutoSeededRandomPool prng;
CryptoPP::SecByteBlock t(seed.size());
prng.GenerateBlock(t, t.size());
for (auto p : mtl::count_until(t.size()))
{
seed_[p] ^= t[p];
}
prng_.IncorporateEntropy(seed_, seed_.size());
//enhance pw
for (auto b : seed)
{
enhanced_passphrase_.push_back(b);
}
}
开发者ID:KaiSta,项目名称:scrates,代码行数:18,代码来源:Container.cpp
示例16: s3fs_encrypt
int s3fs_encrypt(int fd, byte *key)
{
//randomly generate iv
CryptoPP::AutoSeededRandomPool prng;
byte iv[CryptoPP::AES::BLOCKSIZE];
prng.GenerateBlock(iv, sizeof(iv));
string rawiv(reinterpret_cast<char*>(iv), CryptoPP::AES::BLOCKSIZE), striv;
CryptoPP::StringSource s2(rawiv, true,
new CryptoPP::HexEncoder(
new CryptoPP::StringSink(striv)
)
);
//read file into char array
int flength = lseek(fd, 0, SEEK_END);
unsigned char* fcontents;
fcontents = (unsigned char*) calloc(flength, sizeof(char));
pread(fd, fcontents, flength, 0);
string plain(reinterpret_cast<char*>(fcontents), flength);
//encrypt plaintext into ciphertext
string cipher;
CryptoPP::CBC_Mode<CryptoPP::AES>::Encryption e;
e.SetKeyWithIV(key, CryptoPP::AES::DEFAULT_KEYLENGTH, iv);
CryptoPP::StringSource ss(plain, true,
new CryptoPP::StreamTransformationFilter(e,
new CryptoPP::HexEncoder(
new CryptoPP::StringSink(cipher)
)
)
);
//write iv and encrypted data to file
string output = striv+cipher;
const char *buf = output.c_str();
pwrite(fd, buf, output.length(), 0);
ftruncate(fd, output.length());
return 0;
}
开发者ID:mklim,项目名称:crypto-s3fs-fuse,代码行数:40,代码来源:crypt.cpp
示例17: sendPacket
//Takes the socket and packet and sends the packet
bool sendPacket(long int &csock, void* packet)
{
CryptoPP::AutoSeededRandomPool prng;
sleepTime(prng.GenerateWord32()); //wait for random amount of time
int length = 0;
length = strlen((char*)packet);
//printf("Packet size: %d\n", length);
if(sizeof(int) != send(csock, &length, sizeof(int), 0))
{
printf("[error] fail to send packet length\n");
return false;
}
if(length != send(csock, packet, length, 0))
{
printf("[error] fail to send packet\n");
return false;
}
return true;
}
开发者ID:benjaminhkaiser,项目名称:SKB-Protocol,代码行数:23,代码来源:util.cpp
示例18: byte_Derived
void Pbkdf2::Work()
{
static const unsigned _PBKDF2_BYTE_ = 512 / 8;
boost::chrono::steady_clock::time_point start = boost::chrono::steady_clock::now();
CryptoPP::SecByteBlock byte_Derived(_PBKDF2_BYTE_);
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Whirlpool> pbkdf2;
if(h_Worker == PBKDF2_GENERATE)
{
CryptoPP::SecByteBlock byte_Salt(_PBKDF2_BYTE_);
CryptoPP::AutoSeededRandomPool RNG;
RNG.GenerateBlock(byte_Salt, byte_Salt.size());
CryptoPP::ArraySource(byte_Salt, byte_Salt.size(), true, new CryptoPP::HexEncoder(new CryptoPP::StringSink(h_Salt)));
pbkdf2.DeriveKey(byte_Derived, byte_Derived.size(), 0x0, reinterpret_cast<const byte *>(h_Key.data()), h_Key.size(), reinterpret_cast<const byte *>(h_Salt.data()), h_Salt.size(), h_Iterations, 0);
CryptoPP::ArraySource(byte_Derived, byte_Derived.size(), true, new CryptoPP::HexEncoder(new CryptoPP::StringSink(h_Hash)));
}
else if(h_Worker == PBKDF2_VALIDATE)
{
pbkdf2.DeriveKey(byte_Derived, byte_Derived.size(), 0x0, reinterpret_cast<const byte *>(h_Key.data()), h_Key.size(), reinterpret_cast<const byte *>(h_Salt.data()), h_Salt.size(), h_Iterations, 0);
CryptoPP::SecByteBlock byte_Validate(_PBKDF2_BYTE_);
CryptoPP::StringSource(h_Hash, true, new CryptoPP::HexDecoder(new CryptoPP::ArraySink(byte_Validate, byte_Validate.size())));
// Length-constant comparison.
unsigned diff = _PBKDF2_BYTE_ ^ _PBKDF2_BYTE_;
for(unsigned i = 0; i < _PBKDF2_BYTE_; ++i)
{
diff |= byte_Derived[i] ^ byte_Validate[i];
}
h_Equal = diff == 0;
}
boost::chrono::steady_clock::duration duration = boost::chrono::steady_clock::now() - start;
h_ExecTime = static_cast<unsigned>(boost::chrono::duration_cast<boost::chrono::milliseconds>(duration).count());
}
开发者ID:maddinat0r,项目名称:samp-plugin-hash,代码行数:38,代码来源:pbkdf2.cpp
示例19: randomString
//Function generates a random alphanumeric string of length len
std::string randomString(const unsigned int len)
{
static const char alphanum[] =
"0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
CryptoPP::AutoSeededRandomPool prng;
std::string s = "";
//When adding each letter, generate a new word32,
//then compute it modulo alphanum's size - 1
for(unsigned int i = 0; i < len; ++i)
{
s += alphanum[prng.GenerateWord32() % (sizeof(alphanum) - 1)];
} //end for generate random string
/*std::string s = "";
for (int i = 0; i < len; ++i) {
s += alphanum[rand() % (sizeof(alphanum) - 1)];
}
*/
return s;
}
开发者ID:benjaminhkaiser,项目名称:SKB-Protocol,代码行数:25,代码来源:util.cpp
示例20: Send
void CUTPSocketListner::Send(const byte* Buff, size_t uSize, const struct sockaddr* sa, socklen_t sa_len, uint8 Type)
{
TKeyMap::iterator I = m_SendKeys.find((struct sockaddr*)sa);
if(I == m_SendKeys.end())
return;
I->second->LastActivity = GetCurTick();
ASSERT(I->second->PassKey);
if(uSize > 0xFFFF - 0x80)
{
ASSERT(0);
return;
}
bool SendKey = false;
int PadLen = 16;
if(Type == 1) // if its a UTP packet lets be a bit smart
{
ASSERT(uSize >= 4);
UUtpHdr UtpHdr;
UtpHdr.Bits = *((uint32*)Buff);
if(UtpHdr.Fields.type == 4) // ST_SYN
SendKey = true; // we always send the passked on y UTP Sync packet
if(UtpHdr.Fields.type == 0) // ST_DATA
PadLen = 0; // we dont needto padd data frames as tahy may already on thair own have a random size
}
else //if(!I->second->bAck) // if we are not talking UDT lets always send the key just to be sure
SendKey = true;
char Buffer[0xFFFF];
byte* pBuffer = (byte*)Buffer;
size_t uLength = 0;
CryptoPP::AutoSeededRandomPool rng;
uint32 Rand = 0;
rng.GenerateBlock((byte*)&Rand, sizeof(uint32));
UHdr Hdr;
Hdr.Fields.Type = Type;
Hdr.Fields.Reserved = 0;
Hdr.Fields.Discard = 0; // total drop ist (n+1)*256
if(uSize >= 10 * 1024)
Hdr.Fields.Discard = 3; // discard only 1024 key bytes in total for large packets
Hdr.Fields.HasKey = SendKey;
if(PadLen)
PadLen = (rand() % (PadLen + 1)) & 0x3F; // ensure 64 bytes are available for optional footer entries
Hdr.Fields.PadLen = PadLen;
//if(Hdr.Fields.Reserved != 0)
// Hdr.Fields.PadLen += 4;
memcpy(pBuffer + uLength, &Rand, sizeof(uint32)); uLength += 4;
memcpy(pBuffer + uLength, &Hdr.Bits, sizeof(uint32)); uLength += 4;
if(Hdr.Fields.HasKey) {
memcpy(pBuffer + uLength, &m_RecvKey, sizeof(uint64)); uLength += 8; }
memcpy(pBuffer + uLength, Buff, uSize); uLength += uSize;
//if(Hdr.Fields.Reserved != 0) {
// memcpy(pBuffer + uLength, NEO_MAGIC, 4); uLength += 4; }
if(PadLen > 0) {
rng.GenerateBlock(pBuffer + uLength, PadLen); uLength += PadLen; }
CryptoPP::Weak1::MD5 md5;
md5.Update((byte*)&Rand, sizeof(Rand));
md5.Update((byte*)&I->second->PassKey, sizeof(uint64));
byte Hash[16];
md5.Final(Hash);
//#ifdef _DEBUG
// LogLine(LOG_INFO | LOG_DEBUG, L"Send to %s PassKey %I64u -> %s",
// CSafeAddress(sa, sa_len, sa_len == sizeof(sockaddr_in) ? CSafeAddress::eUTP_IP4 : CSafeAddress::eUTP_IP6).ToString().c_str(),
// I->second->PassKey, ToHex(Hash, 16).c_str());
//#endif
CryptoPP::Weak::ARC4::Encryption RC4;
RC4.SetKey(Hash, 16);
RC4.DiscardBytes(256);
RC4.ProcessData(pBuffer + 4, pBuffer + 4, 4);
if(Hdr.Fields.Discard)
RC4.DiscardBytes(Hdr.Fields.Discard * 256);
RC4.ProcessData(pBuffer + 8, pBuffer + 8, uLength - 8);
sendto(m_Socket, Buffer, (int)uLength, 0, (struct sockaddr*)sa, sa_len);
}
开发者ID:0vermind,项目名称:NeoLoader,代码行数:89,代码来源:UTPSocketSession.cpp
注:本文中的cryptopp::AutoSeededRandomPool类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论