本文整理汇总了C++中cryptopp::AutoSeededRandomPool::GenerateBlock方法的典型用法代码示例。如果您正苦于以下问题:C++ AutoSeededRandomPool::GenerateBlock方法的具体用法?C++ AutoSeededRandomPool::GenerateBlock怎么用?C++ AutoSeededRandomPool::GenerateBlock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cryptopp::AutoSeededRandomPool
的用法示例。
在下文中一共展示了AutoSeededRandomPool::GenerateBlock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例2: 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);
}
示例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));
}
示例4: 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);
}
示例5: 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();
}
示例6: GenerateRandom
SecureBinaryData SecureBinaryData::GenerateRandom(uint32_t numBytes)
{
static CryptoPP::AutoSeededRandomPool prng;
SecureBinaryData randData(numBytes);
prng.GenerateBlock(randData.getPtr(), numBytes);
return randData;
}
示例7: 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;
}
}
示例8: 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;
}
示例9:
uint64_t
generateWord64()
{
static CryptoPP::AutoSeededRandomPool rng;
uint64_t random;
rng.GenerateBlock(reinterpret_cast<unsigned char*>(&random), 8);
return random;
}
示例10: 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;
}
示例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
示例12: 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;
}
}
示例13: encrypt
QByteArray encrypt(QByteArray in) {
byte iv[CryptoPP::AES::BLOCKSIZE];
rnd.GenerateBlock(iv, CryptoPP::AES::BLOCKSIZE);
QByteArray out = QByteArray((char*)iv, CryptoPP::AES::BLOCKSIZE);
int inputSize = in.size();
string cipher;
CBC_Mode<AES>::Encryption aes(keyByte(), keySize(), iv);
ArraySource((byte *)in.data(), inputSize, true, new StreamTransformationFilter(aes, new StringSink(cipher)));
QByteArray encryptedBytes = QByteArray(cipher.c_str(), cipher.size());
out.append(encryptedBytes);
return out;
}
示例14: 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);
}
}
示例15: 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;
}