diff options
-rw-r--r-- | checks/x509.cpp | 11 | ||||
-rw-r--r-- | include/pkcs8.h | 17 | ||||
-rw-r--r-- | src/pkcs8.cpp | 14 |
3 files changed, 26 insertions, 16 deletions
diff --git a/checks/x509.cpp b/checks/x509.cpp index d1aebe059..48cbd8384 100644 --- a/checks/x509.cpp +++ b/checks/x509.cpp @@ -47,13 +47,14 @@ u64bit key_id(const Public_Key* key) u32bit check_against_copy(const Private_Key& orig) { - Private_Key* copy_priv = PKCS8::copy_key(orig, global_state().prng_reference()); + RandomNumberGenerator& rng = global_state().prng_reference(); + + Private_Key* copy_priv = PKCS8::copy_key(orig, rng); Public_Key* copy_pub = X509::copy_key(orig); - const std::string passphrase= "I need work! -Mr. T"; // Me too... - DataSource_Memory enc_source(PKCS8::PEM_encode(orig, passphrase)); - Private_Key* copy_priv_enc = PKCS8::load_key(enc_source, - global_state().prng_reference(), + const std::string passphrase= "I need work! -Mr. T"; + DataSource_Memory enc_source(PKCS8::PEM_encode(orig, rng, passphrase)); + Private_Key* copy_priv_enc = PKCS8::load_key(enc_source, rng, passphrase); u64bit orig_id = key_id(&orig); diff --git a/include/pkcs8.h b/include/pkcs8.h index 7ee0dd864..383b1604a 100644 --- a/include/pkcs8.h +++ b/include/pkcs8.h @@ -49,12 +49,19 @@ namespace PKCS8 { * PKCS #8 Private Key Encoding/Decoding * *************************************************/ BOTAN_DLL void encode(const Private_Key&, Pipe&, X509_Encoding = PEM); -BOTAN_DLL void encrypt_key(const Private_Key&, Pipe&, const std::string&, - const std::string& = "", X509_Encoding = PEM); - BOTAN_DLL std::string PEM_encode(const Private_Key&); -BOTAN_DLL std::string PEM_encode(const Private_Key&, const std::string&, - const std::string& = ""); + +BOTAN_DLL void encrypt_key(const Private_Key&, + Pipe&, + RandomNumberGenerator&, + const std::string&, + const std::string& = "", + X509_Encoding = PEM); + +BOTAN_DLL std::string PEM_encode(const Private_Key&, + RandomNumberGenerator&, + const std::string&, + const std::string& = ""); BOTAN_DLL Private_Key* load_key(DataSource&, RandomNumberGenerator&, const User_Interface&); diff --git a/src/pkcs8.cpp b/src/pkcs8.cpp index 330437894..fe5041a62 100644 --- a/src/pkcs8.cpp +++ b/src/pkcs8.cpp @@ -12,7 +12,6 @@ #include <botan/oids.h> #include <botan/pem.h> #include <botan/pbe.h> -#include <botan/libstate.h> #include <memory> namespace Botan { @@ -35,7 +34,6 @@ SecureVector<byte> PKCS8_extract(DataSource& source, .decode(key_data, OCTET_STRING) .verify_end(); - return key_data; } @@ -162,7 +160,9 @@ void encode(const Private_Key& key, Pipe& pipe, X509_Encoding encoding) /************************************************* * Encode and encrypt a PKCS #8 private key * *************************************************/ -void encrypt_key(const Private_Key& key, Pipe& pipe, +void encrypt_key(const Private_Key& key, + Pipe& pipe, + RandomNumberGenerator& rng, const std::string& pass, const std::string& pbe_algo, X509_Encoding encoding) { @@ -174,7 +174,7 @@ void encrypt_key(const Private_Key& key, Pipe& pipe, raw_key.end_msg(); PBE* pbe = get_pbe(((pbe_algo != "") ? pbe_algo : DEFAULT_PBE)); - pbe->new_params(global_state().prng_reference()); + pbe->new_params(rng); pbe->set_key(pass); Pipe key_encrytor(pbe); @@ -209,7 +209,9 @@ std::string PEM_encode(const Private_Key& key) /************************************************* * Encrypt and PEM encode a PKCS #8 private key * *************************************************/ -std::string PEM_encode(const Private_Key& key, const std::string& pass, +std::string PEM_encode(const Private_Key& key, + RandomNumberGenerator& rng, + const std::string& pass, const std::string& pbe_algo) { if(pass == "") @@ -217,7 +219,7 @@ std::string PEM_encode(const Private_Key& key, const std::string& pass, Pipe pem; pem.start_msg(); - encrypt_key(key, pem, pass, pbe_algo, PEM); + encrypt_key(key, pem, rng, pass, pbe_algo, PEM); pem.end_msg(); return pem.read_all_as_string(); } |