aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-06-20 11:24:33 +0000
committerlloyd <[email protected]>2008-06-20 11:24:33 +0000
commit79c7591a0946bb20fd50de136970cc0b1454430a (patch)
tree4efe62dfcd3f786970cf24062d06061275aead86 /src
parent850af952f95a3115e509ebd0aa6689a1d2e9c810 (diff)
Convert pkcs8_decoder() and x509_decoder() to take a RandomNumberGenerator&
reference, along with PKCS8::load_key get_pbe no longer calls new_params() on the newly instantiated instance, which is not backwards compatible (you have to either call new_params yourself, or explicitly set the iteration count, salt, etc)
Diffstat (limited to 'src')
-rw-r--r--src/dl_algo.cpp11
-rw-r--r--src/get_pbe.cpp3
-rw-r--r--src/if_algo.cpp8
-rw-r--r--src/pkcs8.cpp32
-rw-r--r--src/x509_key.cpp5
5 files changed, 35 insertions, 24 deletions
diff --git a/src/dl_algo.cpp b/src/dl_algo.cpp
index 726ee2f0d..7fc364389 100644
--- a/src/dl_algo.cpp
+++ b/src/dl_algo.cpp
@@ -43,7 +43,7 @@ X509_Encoder* DL_Scheme_PublicKey::x509_encoder() const
/*************************************************
* Return the X.509 public key decoder *
*************************************************/
-X509_Decoder* DL_Scheme_PublicKey::x509_decoder()
+X509_Decoder* DL_Scheme_PublicKey::x509_decoder(RandomNumberGenerator& rng)
{
class DL_Scheme_Decoder : public X509_Decoder
{
@@ -68,7 +68,7 @@ X509_Decoder* DL_Scheme_PublicKey::x509_decoder()
RandomNumberGenerator& rng;
};
- return new DL_Scheme_Decoder(this, global_state().prng_reference());
+ return new DL_Scheme_Decoder(this, rng);
}
/*************************************************
@@ -103,7 +103,7 @@ PKCS8_Encoder* DL_Scheme_PrivateKey::pkcs8_encoder() const
/*************************************************
* Return the PKCS #8 private key decoder *
*************************************************/
-PKCS8_Decoder* DL_Scheme_PrivateKey::pkcs8_decoder()
+PKCS8_Decoder* DL_Scheme_PrivateKey::pkcs8_decoder(RandomNumberGenerator& rng)
{
class DL_Scheme_Decoder : public PKCS8_Decoder
{
@@ -120,15 +120,14 @@ PKCS8_Decoder* DL_Scheme_PrivateKey::pkcs8_decoder()
key->PKCS8_load_hook(rng);
}
- DL_Scheme_Decoder(DL_Scheme_PrivateKey* k,
- RandomNumberGenerator& r) :
+ DL_Scheme_Decoder(DL_Scheme_PrivateKey* k, RandomNumberGenerator& r) :
key(k), rng(r) {}
private:
DL_Scheme_PrivateKey* key;
RandomNumberGenerator& rng;
};
- return new DL_Scheme_Decoder(this, global_state().prng_reference());
+ return new DL_Scheme_Decoder(this, rng);
}
/*************************************************
diff --git a/src/get_pbe.cpp b/src/get_pbe.cpp
index 75aaf2f6b..aef7756fb 100644
--- a/src/get_pbe.cpp
+++ b/src/get_pbe.cpp
@@ -7,7 +7,6 @@
#include <botan/lookup.h>
#include <botan/pbe_pkcs.h>
#include <botan/parsing.h>
-#include <botan/libstate.h>
namespace Botan {
@@ -36,8 +35,6 @@ PBE* get_pbe(const std::string& pbe_name)
if(!pbe_obj)
throw Algorithm_Not_Found(pbe_name);
- pbe_obj->new_params(global_state().prng_reference());
-
return pbe_obj;
}
diff --git a/src/if_algo.cpp b/src/if_algo.cpp
index 2bd508c86..e2178e5f1 100644
--- a/src/if_algo.cpp
+++ b/src/if_algo.cpp
@@ -46,7 +46,7 @@ X509_Encoder* IF_Scheme_PublicKey::x509_encoder() const
/*************************************************
* Return the X.509 public key decoder *
*************************************************/
-X509_Decoder* IF_Scheme_PublicKey::x509_decoder()
+X509_Decoder* IF_Scheme_PublicKey::x509_decoder(RandomNumberGenerator& rng)
{
class IF_Scheme_Decoder : public X509_Decoder
{
@@ -72,7 +72,7 @@ X509_Decoder* IF_Scheme_PublicKey::x509_decoder()
RandomNumberGenerator& rng;
};
- return new IF_Scheme_Decoder(this, global_state().prng_reference());
+ return new IF_Scheme_Decoder(this, rng);
}
/*************************************************
@@ -117,7 +117,7 @@ PKCS8_Encoder* IF_Scheme_PrivateKey::pkcs8_encoder() const
/*************************************************
* Return the PKCS #8 public key decoder *
*************************************************/
-PKCS8_Decoder* IF_Scheme_PrivateKey::pkcs8_decoder()
+PKCS8_Decoder* IF_Scheme_PrivateKey::pkcs8_decoder(RandomNumberGenerator& rng)
{
class IF_Scheme_Decoder : public PKCS8_Decoder
{
@@ -154,7 +154,7 @@ PKCS8_Decoder* IF_Scheme_PrivateKey::pkcs8_decoder()
RandomNumberGenerator& rng;
};
- return new IF_Scheme_Decoder(this, global_state().prng_reference());
+ return new IF_Scheme_Decoder(this, rng);
}
/*************************************************
diff --git a/src/pkcs8.cpp b/src/pkcs8.cpp
index b3366acd2..330437894 100644
--- a/src/pkcs8.cpp
+++ b/src/pkcs8.cpp
@@ -12,6 +12,7 @@
#include <botan/oids.h>
#include <botan/pem.h>
#include <botan/pbe.h>
+#include <botan/libstate.h>
#include <memory>
namespace Botan {
@@ -173,6 +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->set_key(pass);
Pipe key_encrytor(pbe);
@@ -223,7 +225,9 @@ std::string PEM_encode(const Private_Key& key, const std::string& pass,
/*************************************************
* Extract a private key and return it *
*************************************************/
-Private_Key* load_key(DataSource& source, const User_Interface& ui)
+Private_Key* load_key(DataSource& source,
+ RandomNumberGenerator& rng,
+ const User_Interface& ui)
{
AlgorithmIdentifier alg_id;
SecureVector<byte> pkcs8_key = PKCS8_decode(source, ui, alg_id);
@@ -239,7 +243,8 @@ Private_Key* load_key(DataSource& source, const User_Interface& ui)
throw PKCS8_Exception("Unknown PK algorithm/OID: " + alg_name + ", " +
alg_id.oid.as_string());
- std::auto_ptr<PKCS8_Decoder> decoder(key->pkcs8_decoder());
+ std::auto_ptr<PKCS8_Decoder> decoder(key->pkcs8_decoder(rng));
+
if(!decoder.get())
throw Decoding_Error("Key does not support PKCS #8 decoding");
@@ -252,32 +257,39 @@ Private_Key* load_key(DataSource& source, const User_Interface& ui)
/*************************************************
* Extract a private key and return it *
*************************************************/
-Private_Key* load_key(const std::string& fsname, const User_Interface& ui)
+Private_Key* load_key(const std::string& fsname,
+ RandomNumberGenerator& rng,
+ const User_Interface& ui)
{
DataSource_Stream source(fsname, true);
- return PKCS8::load_key(source, ui);
+ return PKCS8::load_key(source, rng, ui);
}
/*************************************************
* Extract a private key and return it *
*************************************************/
-Private_Key* load_key(DataSource& source, const std::string& pass)
+Private_Key* load_key(DataSource& source,
+ RandomNumberGenerator& rng,
+ const std::string& pass)
{
- return PKCS8::load_key(source, User_Interface(pass));
+ return PKCS8::load_key(source, rng, User_Interface(pass));
}
/*************************************************
* Extract a private key and return it *
*************************************************/
-Private_Key* load_key(const std::string& fsname, const std::string& pass)
+Private_Key* load_key(const std::string& fsname,
+ RandomNumberGenerator& rng,
+ const std::string& pass)
{
- return PKCS8::load_key(fsname, User_Interface(pass));
+ return PKCS8::load_key(fsname, rng, User_Interface(pass));
}
/*************************************************
* Make a copy of this private key *
*************************************************/
-Private_Key* copy_key(const Private_Key& key)
+Private_Key* copy_key(const Private_Key& key,
+ RandomNumberGenerator& rng)
{
Pipe bits;
@@ -286,7 +298,7 @@ Private_Key* copy_key(const Private_Key& key)
bits.end_msg();
DataSource_Memory source(bits.read_all());
- return PKCS8::load_key(source);
+ return PKCS8::load_key(source, rng);
}
}
diff --git a/src/x509_key.cpp b/src/x509_key.cpp
index 09044d492..f327aac16 100644
--- a/src/x509_key.cpp
+++ b/src/x509_key.cpp
@@ -11,6 +11,7 @@
#include <botan/pk_algs.h>
#include <botan/oids.h>
#include <botan/pem.h>
+#include <botan/libstate.h>
#include <memory>
namespace Botan {
@@ -97,7 +98,9 @@ Public_Key* load_key(DataSource& source)
throw Decoding_Error("Unknown PK algorithm/OID: " + alg_name + ", " +
alg_id.oid.as_string());
- std::auto_ptr<X509_Decoder> decoder(key_obj->x509_decoder());
+ std::auto_ptr<X509_Decoder> decoder(
+ key_obj->x509_decoder(global_state().prng_reference()));
+
if(!decoder.get())
throw Decoding_Error("Key does not support X.509 decoding");