diff options
author | lloyd <[email protected]> | 2008-05-24 19:49:14 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-05-24 19:49:14 +0000 |
commit | 8283202b8bfd5fe088f87a91a3158bef0072311f (patch) | |
tree | c7e7c773a9658e1d4cb7cd03d94ffa10f443ec9a | |
parent | 440a5d6bd0de20027d8c094abdd1390ee23eae6f (diff) |
Don't use the global PRNG in implementations of PBE::new_params
-rw-r--r-- | include/pbe.h | 4 | ||||
-rw-r--r-- | include/pbe_pkcs.h | 6 | ||||
-rw-r--r-- | src/get_pbe.cpp | 3 | ||||
-rw-r--r-- | src/pbes1.cpp | 5 | ||||
-rw-r--r-- | src/pbes2.cpp | 9 |
5 files changed, 16 insertions, 11 deletions
diff --git a/include/pbe.h b/include/pbe.h index 323f37ce4..35d6d774d 100644 --- a/include/pbe.h +++ b/include/pbe.h @@ -19,9 +19,11 @@ class BOTAN_DLL PBE : public Filter { public: virtual void set_key(const std::string&) = 0; - virtual void new_params() = 0; + virtual void new_params(RandomNumberGenerator& rng) = 0; + virtual MemoryVector<byte> encode_params() const = 0; virtual void decode_params(DataSource&) = 0; + virtual OID get_oid() const = 0; }; diff --git a/include/pbe_pkcs.h b/include/pbe_pkcs.h index a01f70e66..82f797b7b 100644 --- a/include/pbe_pkcs.h +++ b/include/pbe_pkcs.h @@ -24,10 +24,11 @@ class BOTAN_DLL PBE_PKCS5v15 : public PBE PBE_PKCS5v15(const std::string&, const std::string&, Cipher_Dir); private: void set_key(const std::string&); - void new_params(); + void new_params(RandomNumberGenerator& rng); MemoryVector<byte> encode_params() const; void decode_params(DataSource&); OID get_oid() const; + void flush_pipe(bool); const Cipher_Dir direction; const std::string digest, cipher; @@ -49,10 +50,11 @@ class BOTAN_DLL PBE_PKCS5v20 : public PBE PBE_PKCS5v20(const std::string&, const std::string&); private: void set_key(const std::string&); - void new_params(); + void new_params(RandomNumberGenerator& rng); MemoryVector<byte> encode_params() const; void decode_params(DataSource&); OID get_oid() const; + void flush_pipe(bool); bool known_cipher(const std::string&) const; diff --git a/src/get_pbe.cpp b/src/get_pbe.cpp index 406cbb2bb..75aaf2f6b 100644 --- a/src/get_pbe.cpp +++ b/src/get_pbe.cpp @@ -7,6 +7,7 @@ #include <botan/lookup.h> #include <botan/pbe_pkcs.h> #include <botan/parsing.h> +#include <botan/libstate.h> namespace Botan { @@ -35,7 +36,7 @@ PBE* get_pbe(const std::string& pbe_name) if(!pbe_obj) throw Algorithm_Not_Found(pbe_name); - pbe_obj->new_params(); + pbe_obj->new_params(global_state().prng_reference()); return pbe_obj; } diff --git a/src/pbes1.cpp b/src/pbes1.cpp index 8e548f6b4..3126209b4 100644 --- a/src/pbes1.cpp +++ b/src/pbes1.cpp @@ -8,7 +8,6 @@ #include <botan/ber_dec.h> #include <botan/parsing.h> #include <botan/lookup.h> -#include <botan/libstate.h> #include <algorithm> #include <memory> @@ -82,11 +81,11 @@ void PBE_PKCS5v15::set_key(const std::string& passphrase) /************************************************* * Create a new set of PBES1 parameters * *************************************************/ -void PBE_PKCS5v15::new_params() +void PBE_PKCS5v15::new_params(RandomNumberGenerator& rng) { iterations = 2048; salt.create(8); - global_state().randomize(salt, salt.size()); + rng.randomize(salt, salt.size()); } /************************************************* diff --git a/src/pbes2.cpp b/src/pbes2.cpp index ea51597a3..62913abac 100644 --- a/src/pbes2.cpp +++ b/src/pbes2.cpp @@ -8,7 +8,6 @@ #include <botan/ber_dec.h> #include <botan/parsing.h> #include <botan/lookup.h> -#include <botan/libstate.h> #include <botan/asn1_obj.h> #include <botan/oids.h> #include <algorithm> @@ -81,14 +80,16 @@ void PBE_PKCS5v20::set_key(const std::string& passphrase) /************************************************* * Create a new set of PBES2 parameters * *************************************************/ -void PBE_PKCS5v20::new_params() +void PBE_PKCS5v20::new_params(RandomNumberGenerator& rng) { iterations = 2048; key_length = max_keylength_of(cipher_algo); + salt.create(8); + rng.randomize(salt, salt.size()); + iv.create(block_size_of(cipher_algo)); - global_state().randomize(salt, salt.size()); - global_state().randomize(iv, iv.size()); + rng.randomize(iv, iv.size()); } /************************************************* |