本文整理汇总了C++中botan::SecureVector::size方法的典型用法代码示例。如果您正苦于以下问题:C++ SecureVector::size方法的具体用法?C++ SecureVector::size怎么用?C++ SecureVector::size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类botan::SecureVector
的用法示例。
在下文中一共展示了SecureVector::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: signFinal
bool BotanDSA::signFinal(ByteString& signature)
{
if (!AsymmetricAlgorithm::signFinal(signature))
{
return false;
}
// Perform the signature operation
Botan::SecureVector<Botan::byte> signResult;
try
{
BotanRNG* rng = (BotanRNG*)BotanCryptoFactory::i()->getRNG();
signResult = signer->signature(*rng->getRNG());
}
catch (...)
{
ERROR_MSG("Could not sign the data");
delete signer;
signer = NULL;
return false;
}
// Return the result
signature.resize(signResult.size());
memcpy(&signature[0], signResult.begin(), signResult.size());
delete signer;
signer = NULL;
return true;
}
示例2: ExtractFromWad
EpadResult ExtractFromWad(RandomInStream &in, OutStream &out, std::string &key_file)
{
WadMetadata metadata;
auto result = ExtractWadMetadata(in, in.GetCount(), metadata);
in.Seek(metadata.payload_offset);
if(result != EpadResult::Success)
return result;
Botan::SecureVector<byte> buffer;
buffer.resize(metadata.payload_size != 0 ? metadata.payload_size : in.GetCount());
in.Read(buffer.data(), buffer.size());
out.Write(buffer.data(), buffer.size());
key_file.clear();
if(metadata.key_file_offset != kInvalid)
{
key_file.resize(metadata.key_file_size);
in.Seek(metadata.key_file_offset);
in.Read(reinterpret_cast<byte *>(&*key_file.begin()), metadata.key_file_size);
}
return EpadResult::Success;
}
示例3:
// Encode into PKCS#8 DER
ByteString BotanDSAPrivateKey::PKCS8Encode()
{
ByteString der;
createBotanKey();
if (dsa == NULL) return der;
const Botan::SecureVector<Botan::byte> ber = Botan::PKCS8::BER_encode(*dsa);
der.resize(ber.size());
memcpy(&der[0], ber.begin(), ber.size());
return der;
}
示例4: if
bool ne7ssh_crypt::negotiatedKex (Botan::SecureVector<Botan::byte> &kexAlgo)
{
if (!memcmp (kexAlgo.begin(), "diffie-hellman-group1-sha1", kexAlgo.size()))
{
kexMethod = DH_GROUP1_SHA1;
return true;
}
else if (!memcmp (kexAlgo.begin(), "diffie-hellman-group14-sha1", kexAlgo.size()))
{
kexMethod = DH_GROUP14_SHA1;
return true;
}
ne7ssh::errors()->push (session->getSshChannel(), "KEX algorithm: '%B' not defined.", &kexAlgo);
return false;
}
示例5: htonl
void ne7ssh_string::addVectorField(const Botan::SecureVector<Botan::byte> &vector)
{
uint32 nLen = htonl(vector.size());
_buffer += SecureVector<Botan::byte>((Botan::byte*)&nLen, sizeof(uint32));
_buffer += vector;
}
示例6: signFinal
bool BotanGOST::signFinal(ByteString& signature)
{
if (!AsymmetricAlgorithm::signFinal(signature))
{
return false;
}
// Perform the signature operation
#if BOTAN_VERSION_MINOR == 11
std::vector<Botan::byte> signResult;
#else
Botan::SecureVector<Botan::byte> signResult;
#endif
try
{
BotanRNG* rng = (BotanRNG*)BotanCryptoFactory::i()->getRNG();
signResult = signer->signature(*rng->getRNG());
}
catch (...)
{
ERROR_MSG("Could not sign the data");
delete signer;
signer = NULL;
return false;
}
// Return the result
signature.resize(signResult.size());
#if BOTAN_VERSION_MINOR == 11
memcpy(&signature[0], signResult.data(), signResult.size());
#else
memcpy(&signature[0], signResult.begin(), signResult.size());
#endif
delete signer;
signer = NULL;
return true;
}
示例7:
bool ne7ssh_crypt::decryptPacket (Botan::SecureVector<Botan::byte> &decrypted, Botan::SecureVector<Botan::byte> &packet, uint32 len)
{
uint32 pLen = packet.size();
if (len % decryptBlock) len = len + (len % decryptBlock);
if (len > pLen) len = pLen;
decrypt->process_msg (packet.begin(), len);
decrypted = decrypt->read_all (decrypt->message_count() - 1);
return true;
}
示例8: oid
// Encode into PKCS#8 DER
ByteString BotanECDHPrivateKey::PKCS8Encode()
{
ByteString der;
createBotanKey();
if (eckey == NULL) return der;
const size_t PKCS8_VERSION = 0;
// No OID for ECDH
const Botan::OID oid("1.2.840.10045.2.1");
// Force EC_DOMPAR_ENC_OID
const Botan::MemoryVector<Botan::byte> parameters = eckey->domain().DER_encode(Botan::EC_DOMPAR_ENC_OID);
const Botan::AlgorithmIdentifier alg_id(oid, parameters);
const Botan::SecureVector<Botan::byte> ber =
Botan::DER_Encoder()
.start_cons(Botan::SEQUENCE)
.encode(PKCS8_VERSION)
.encode(alg_id)
.encode(eckey->pkcs8_private_key(), Botan::OCTET_STRING)
.end_cons()
.get_contents();
der.resize(ber.size());
memcpy(&der[0], ber.begin(), ber.size());
return der;
}
示例9: digestPIN
char* digestPIN(CK_UTF8CHAR_PTR pPin, CK_ULONG ulPinLen) {
// We do not use any salt
Botan::Pipe *digestPIN = new Botan::Pipe(new Botan::Hash_Filter(new Botan::SHA_256), new Botan::Hex_Encoder);
digestPIN->start_msg();
digestPIN->write((Botan::byte*)pPin, (Botan::u32bit)ulPinLen);
digestPIN->write((Botan::byte*)pPin, (Botan::u32bit)ulPinLen);
digestPIN->write((Botan::byte*)pPin, (Botan::u32bit)ulPinLen);
digestPIN->end_msg();
// Get the digested PIN
Botan::SecureVector<Botan::byte> pinVector = digestPIN->read_all();
int size = pinVector.size();
char *tmpPIN = (char *)malloc(size + 1);
if(tmpPIN != NULL_PTR) {
tmpPIN[size] = '\0';
memcpy(tmpPIN, pinVector.begin(), size);
}
delete digestPIN;
return tmpPIN;
}
示例10: encrypt
// Encryption functions
bool BotanRSA::encrypt(PublicKey* publicKey, const ByteString& data, ByteString& encryptedData, const std::string padding)
{
// Check if the public key is the right type
if (!publicKey->isOfType(BotanRSAPublicKey::type))
{
ERROR_MSG("Invalid key type supplied");
return false;
}
std::string lowerPadding;
lowerPadding.resize(padding.size());
std::transform(padding.begin(), padding.end(), lowerPadding.begin(), tolower);
std::string eme;
if (!lowerPadding.compare("rsa-pkcs"))
{
eme = "PKCS1v15";
}
else if (!lowerPadding.compare("rsa-pkcs-oaep"))
{
eme = "EME1(SHA-160)";
}
else if (!lowerPadding.compare("rsa-raw"))
{
eme = "Raw";
}
else
{
ERROR_MSG("Invalid padding mechanism supplied (%s)", padding.c_str());
return false;
}
BotanRSAPublicKey* pk = (BotanRSAPublicKey*) publicKey;
Botan::RSA_PublicKey* botanKey = pk->getBotanKey();
if (!botanKey)
{
ERROR_MSG("Could not get the Botan public key");
return false;
}
Botan::PK_Encryptor_EME* encryptor = NULL;
try
{
encryptor = new Botan::PK_Encryptor_EME(*botanKey, eme);
}
catch (...)
{
ERROR_MSG("Could not create the encryptor token");
return false;
}
// Perform the encryption operation
Botan::SecureVector<Botan::byte> encResult;
try
{
BotanRNG* rng = (BotanRNG*)BotanCryptoFactory::i()->getRNG();
encResult = encryptor->encrypt(data.const_byte_str(), data.size(), *rng->getRNG());
}
catch (...)
{
ERROR_MSG("Could not encrypt the data");
delete encryptor;
return false;
}
// Return the result
encryptedData.resize(encResult.size());
memcpy(&encryptedData[0], encResult.begin(), encResult.size());
delete encryptor;
return true;
}
示例11: failed_test
bool failed_test(const std::string& algo,
std::vector<std::string> params,
bool is_extension, bool exp_pass,
std::string& last_missing,
Botan::RandomNumberGenerator& rng)
{
#if !EXTRA_TESTS
if(!exp_pass) return true;
#endif
std::map<std::string, std::string> vars;
vars["input"] = params[0];
vars["output"] = params[1];
if(params.size() > 2)
vars["key"] = params[2];
if(params.size() > 3)
vars["iv"] = params[3];
std::map<std::string, bool> results =
algorithm_kat(algo, vars, global_state().algorithm_factory());
if(results.size())
{
for(std::map<std::string, bool>::const_iterator i = results.begin();
i != results.end(); ++i)
{
if(i->second == false)
{
std::cout << algo << " test with provider "
<< i->first << " failed\n";
return true;
}
}
return false; // OK
}
const std::string in = params[0];
const std::string expected = params[1];
params.erase(params.begin());
params.erase(params.begin());
if(in.size() % 2 == 1)
{
std::cout << "Can't have an odd sized hex string!" << std::endl;
return true;
}
Botan::Pipe pipe;
try {
Botan::Filter* test = lookup(algo, params);
if(test == 0 && is_extension) return !exp_pass;
if(test == 0)
{
if(algo != last_missing)
{
std::cout << "WARNING: \"" + algo + "\" is not a known "
<< "algorithm name." << std::endl;
last_missing = algo;
}
return 0;
}
pipe.reset();
pipe.append(test);
pipe.append(new Botan::Hex_Encoder);
Botan::SecureVector<byte> data = Botan::hex_decode(in);
const byte* data_ptr = &data[0];
// this can help catch errors with buffering, etc
size_t len = data.size();
pipe.start_msg();
while(len)
{
u32bit how_much = random_word(rng, len);
pipe.write(data_ptr, how_much);
data_ptr += how_much;
len -= how_much;
}
pipe.end_msg();
}
catch(Botan::Algorithm_Not_Found& e)
{
std::cout << "Algorithm not found: " << e.what() << std::endl;
return false;
}
catch(Botan::Exception& e)
{
if(exp_pass || DEBUG)
std::cout << "Exception caught: " << e.what() << std::endl;
return true;
}
catch(std::exception& e)
{
if(exp_pass || DEBUG)
//.........这里部分代码省略.........
示例12: sign
// Signing functions
bool BotanDSA::sign(PrivateKey* privateKey, const ByteString& dataToSign,
ByteString& signature, const std::string mechanism)
{
std::string lowerMechanism;
lowerMechanism.resize(mechanism.size());
std::transform(mechanism.begin(), mechanism.end(), lowerMechanism.begin(), tolower);
std::string emsa;
if (!lowerMechanism.compare("dsa"))
{
emsa = "Raw";
}
else
{
// Call default implementation
return AsymmetricAlgorithm::sign(privateKey, dataToSign, signature, mechanism);
}
// Check if the private key is the right type
if (!privateKey->isOfType(BotanDSAPrivateKey::type))
{
ERROR_MSG("Invalid key type supplied");
return false;
}
BotanDSAPrivateKey* pk = (BotanDSAPrivateKey*) privateKey;
Botan::DSA_PrivateKey* botanKey = pk->getBotanKey();
if (!botanKey)
{
ERROR_MSG("Could not get the Botan private key");
return false;
}
try
{
signer = new Botan::PK_Signer(*botanKey, emsa);
// Should we add DISABLE_FAULT_PROTECTION? Makes this operation faster.
}
catch (...)
{
ERROR_MSG("Could not create the signer token");
return false;
}
// Perform the signature operation
Botan::SecureVector<Botan::byte> signResult;
try
{
BotanRNG* rng = (BotanRNG*)BotanCryptoFactory::i()->getRNG();
signResult = signer->sign_message(dataToSign.const_byte_str(), dataToSign.size(), *rng->getRNG());
}
catch (...)
{
ERROR_MSG("Could not sign the data");
delete signer;
signer = NULL;
return false;
}
// Return the result
signature.resize(signResult.size());
memcpy(&signature[0], signResult.begin(), signResult.size());
delete signer;
signer = NULL;
return true;
}
示例13: decrypt
// Decryption functions
bool BotanRSA::decrypt(PrivateKey* privateKey, const ByteString& encryptedData, ByteString& data, const std::string padding)
{
// Check if the private key is the right type
if (!privateKey->isOfType(BotanRSAPrivateKey::type))
{
ERROR_MSG("Invalid key type supplied");
return false;
}
std::string lowerPadding;
lowerPadding.resize(padding.size());
std::transform(padding.begin(), padding.end(), lowerPadding.begin(), tolower);
std::string eme;
if (!lowerPadding.compare("rsa-pkcs"))
{
eme = "PKCS1v15";
}
else if (!lowerPadding.compare("rsa-pkcs-oaep"))
{
eme = "EME1(SHA-160)";
}
else if (!lowerPadding.compare("rsa-raw"))
{
eme = "Raw";
}
else
{
ERROR_MSG("Invalid padding mechanism supplied (%s)", padding.c_str());
return false;
}
BotanRSAPrivateKey* pk = (BotanRSAPrivateKey*) privateKey;
Botan::RSA_PrivateKey* botanKey = pk->getBotanKey();
if (!botanKey)
{
ERROR_MSG("Could not get the Botan private key");
return false;
}
Botan::PK_Decryptor_EME* decryptor = NULL;
try
{
decryptor = new Botan::PK_Decryptor_EME(*botanKey, eme);
}
catch (...)
{
ERROR_MSG("Could not create the decryptor token");
return false;
}
// Perform the decryption operation
Botan::SecureVector<Botan::byte> decResult;
try
{
decResult = decryptor->decrypt(encryptedData.const_byte_str(), encryptedData.size());
}
catch (...)
{
ERROR_MSG("Could not decrypt the data");
delete decryptor;
return false;
}
// Return the result
if (!eme.compare("Raw"))
{
// We compensate that Botan removes leading zeros
int modSize = pk->getN().size();
int decSize = decResult.size();
data.resize(modSize);
memcpy(&data[0] + modSize - decSize, decResult.begin(), decSize);
}
else
{
data.resize(decResult.size());
memcpy(&data[0], decResult.begin(), decResult.size());
}
delete decryptor;
return true;
}
示例14: sign
// Signing functions
bool BotanRSA::sign(PrivateKey* privateKey, const ByteString& dataToSign,
ByteString& signature, const AsymMech::Type mechanism,
const void* param /* = NULL */, const size_t paramLen /* = 0 */)
{
std::string emsa = "";
switch (mechanism)
{
case AsymMech::RSA:
emsa = "Raw";
break;
case AsymMech::RSA_PKCS:
emsa = "EMSA3(Raw)";
break;
default:
// Call default implementation
return AsymmetricAlgorithm::sign(privateKey, dataToSign, signature, mechanism, param, paramLen);
}
// Check if the private key is the right type
if (!privateKey->isOfType(BotanRSAPrivateKey::type))
{
ERROR_MSG("Invalid key type supplied");
return false;
}
BotanRSAPrivateKey* pk = (BotanRSAPrivateKey*) privateKey;
Botan::RSA_PrivateKey* botanKey = pk->getBotanKey();
if (!botanKey)
{
ERROR_MSG("Could not get the Botan private key");
return false;
}
try
{
signer = new Botan::PK_Signer(*botanKey, emsa);
// Should we add DISABLE_FAULT_PROTECTION? Makes this operation faster.
}
catch (...)
{
ERROR_MSG("Could not create the signer token");
return false;
}
// Perform the signature operation
#if BOTAN_VERSION_MINOR == 11
std::vector<Botan::byte> signResult;
#else
Botan::SecureVector<Botan::byte> signResult;
#endif
try
{
BotanRNG* rng = (BotanRNG*)BotanCryptoFactory::i()->getRNG();
signResult = signer->sign_message(dataToSign.const_byte_str(), dataToSign.size(), *rng->getRNG());
}
catch (std::exception& e)
{
ERROR_MSG("Could not sign the data: %s", e.what());
delete signer;
signer = NULL;
return false;
}
// Return the result
signature.resize(signResult.size());
#if BOTAN_VERSION_MINOR == 11
memcpy(&signature[0], signResult.data(), signResult.size());
#else
memcpy(&signature[0], signResult.begin(), signResult.size());
#endif
delete signer;
signer = NULL;
return true;
}
示例15:
ne7ssh_string::ne7ssh_string(Botan::SecureVector<Botan::byte>& var, uint32 position)
: _currentPart(0),
_buffer(SecureVector<Botan::byte>((var.begin() + position), (var.size() - position)))
{
}