diff options
author | lloyd <[email protected]> | 2008-05-24 18:28:57 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-05-24 18:28:57 +0000 |
commit | ebc67ae27481549a152858f24fff4a7a82ad4e51 (patch) | |
tree | 9b8f0e18725ebdee90c5e5e54f2aadcf56bd93af | |
parent | b7563677f13adb8dfa5813ef91ed79364b2d984d (diff) |
Avoid using global rng in DL_Group::generate_dsa_primes
-rw-r--r-- | include/dl_group.h | 8 | ||||
-rw-r--r-- | src/dl_group.cpp | 5 | ||||
-rw-r--r-- | src/dsa_gen.cpp | 11 |
3 files changed, 14 insertions, 10 deletions
diff --git a/include/dl_group.h b/include/dl_group.h index 010a949ff..74a11b5d5 100644 --- a/include/dl_group.h +++ b/include/dl_group.h @@ -33,8 +33,11 @@ class BOTAN_DLL DL_Group DL_Group(); DL_Group(const std::string&); + DL_Group(RandomNumberGenerator& rng, PrimeType, u32bit, u32bit = 0); - DL_Group(const MemoryRegion<byte>&, u32bit = 1024, u32bit = 0); + DL_Group(RandomNumberGenerator& rng, const MemoryRegion<byte>&, + u32bit = 1024, u32bit = 0); + DL_Group(const BigInt&, const BigInt&); DL_Group(const BigInt&, const BigInt&, const BigInt&); private: @@ -45,7 +48,8 @@ class BOTAN_DLL DL_Group BigInt& p, BigInt& q, u32bit pbits, u32bit qbits); - static bool generate_dsa_primes(BigInt&, BigInt&, u32bit, u32bit, + static bool generate_dsa_primes(RandomNumberGenerator&, + BigInt&, BigInt&, u32bit, u32bit, const MemoryRegion<byte>&); void init_check() const; diff --git a/src/dl_group.cpp b/src/dl_group.cpp index d0b27be0c..7ec591b15 100644 --- a/src/dl_group.cpp +++ b/src/dl_group.cpp @@ -84,9 +84,10 @@ DL_Group::DL_Group(RandomNumberGenerator& rng, /************************************************* * DL_Group Constructor * *************************************************/ -DL_Group::DL_Group(const MemoryRegion<byte>& seed, u32bit pbits, u32bit qbits) +DL_Group::DL_Group(RandomNumberGenerator& rng, + const MemoryRegion<byte>& seed, u32bit pbits, u32bit qbits) { - if(!generate_dsa_primes(p, q, pbits, qbits, seed)) + if(!generate_dsa_primes(rng, p, q, pbits, qbits, seed)) throw Invalid_Argument("DL_Group: The seed/counter given does not " "generate a DSA group"); diff --git a/src/dsa_gen.cpp b/src/dsa_gen.cpp index 0e4f5301f..d0b60f73c 100644 --- a/src/dsa_gen.cpp +++ b/src/dsa_gen.cpp @@ -7,7 +7,6 @@ #include <botan/numthry.h> #include <botan/lookup.h> #include <botan/parsing.h> -#include <botan/libstate.h> #include <algorithm> #include <memory> @@ -34,7 +33,8 @@ bool fips186_3_valid_size(u32bit pbits, u32bit qbits) /************************************************* * Attempt DSA prime generation with given seed * *************************************************/ -bool DL_Group::generate_dsa_primes(BigInt& p, BigInt& q, +bool DL_Group::generate_dsa_primes(RandomNumberGenerator& rng, + BigInt& p, BigInt& q, u32bit pbits, u32bit qbits, const MemoryRegion<byte>& seed_c) { @@ -80,7 +80,7 @@ bool DL_Group::generate_dsa_primes(BigInt& p, BigInt& q, q.set_bit(qbits-1); q.set_bit(0); - if(!is_prime(q, global_state().prng_reference())) + if(!is_prime(q, rng)) return false; const u32bit n = (pbits-1) / (HASH_SIZE * 8), @@ -104,8 +104,7 @@ bool DL_Group::generate_dsa_primes(BigInt& p, BigInt& q, p = X - (X % (2*q) - 1); - if(p.bits() == pbits && - is_prime(p, global_state().prng_reference())) + if(p.bits() == pbits && is_prime(p, rng)) return true; } return false; @@ -124,7 +123,7 @@ SecureVector<byte> DL_Group::generate_dsa_primes(RandomNumberGenerator& rng, { rng.randomize(seed, seed.size()); - if(generate_dsa_primes(p, q, pbits, qbits, seed)) + if(generate_dsa_primes(rng, p, q, pbits, qbits, seed)) return seed; } } |