mardi 31 mars 2015

Botan 1.10.9 SecureVector to std::vector bad_alloc

I have this strange error in botan 1.10.9. When I want to store the private key bytes vector and the publics key byte vector i get an std::bad_alloc error. Could it be that is not possible to initialize a std::vector from the SecureVector from botan?



Botan::LibraryInitializer init;

Botan::AutoSeeded_RNG rng;
rng.reseed(10096);

Botan::RSA_PrivateKey rsaPrivate(rng, 1024);

std::vector<unsigned char> privateArray(rsaPrivate.pkcs8_private_key().begin(), rsaPrivate.pkcs8_private_key().end());
std::vector<unsigned char> publicArray(rsaPrivate.x509_subject_public_key().begin(), rsaPrivate.x509_subject_public_key().end());


If i encode the keys, then the operation works fine:



Botan::SecureVector<Botan::byte> publicBytes = std::move(Botan::X509::BER_encode(rsaPrivate));
Botan::SecureVector<Botan::byte> privateBytes = std::move(Botan::PKCS8::BER_encode(rsaPrivate, rng, info.passphrase()));

std::vector<unsigned char> publicArray(publicBytes.begin(), publicBytes.end());
std::vector<unsigned char> privateArray(privateBytes.begin(), privateBytes.end());


Any ideas why this could be happening? The weird thing is that if i remove one of the vectors initialization, soooooometimes it works but most of the time i get the crash.


Aucun commentaire:

Enregistrer un commentaire