diff options
author | lloyd <[email protected]> | 2008-05-24 18:25:00 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-05-24 18:25:00 +0000 |
commit | b7563677f13adb8dfa5813ef91ed79364b2d984d (patch) | |
tree | cf7fabb3eb43bc49333be726c15ecac1a7f9a1a7 /src/dl_group.cpp | |
parent | a6a9110d02925e111cff2dc1143a09a3b7680f0b (diff) |
Previously random_integer and friends used the global PRNG object to get
random bits. Now they take a reference to a RandomNumberGenerator object.
This was applied several times out, so now the constructors to private
key objects also take a RandomNumberGenerator& argument. This is also true
for a number of randomized algorithms (Miller-Rabin, for instance).
You can get a reference to the global PRNG with
global_state().prng_reference()
This is a provisional thing: and warning: it is not thread safe! If this
is a problem instead keep per-thread PRNGs and pass them were needed.
Diffstat (limited to 'src/dl_group.cpp')
-rw-r--r-- | src/dl_group.cpp | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/dl_group.cpp b/src/dl_group.cpp index b356b707d..d0b27be0c 100644 --- a/src/dl_group.cpp +++ b/src/dl_group.cpp @@ -1,9 +1,10 @@ /************************************************* * Discrete Logarithm Parameters Source File * -* (C) 1999-2007 Jack Lloyd * +* (C) 1999-2008 Jack Lloyd * *************************************************/ #include <botan/dl_group.h> +#include <botan/libstate.h> #include <botan/config.h> #include <botan/parsing.h> #include <botan/numthry.h> @@ -40,7 +41,8 @@ DL_Group::DL_Group(const std::string& type) /************************************************* * DL_Group Constructor * *************************************************/ -DL_Group::DL_Group(PrimeType type, u32bit pbits, u32bit qbits) +DL_Group::DL_Group(RandomNumberGenerator& rng, + PrimeType type, u32bit pbits, u32bit qbits) { if(pbits < 512) throw Invalid_Argument("DL_Group: prime size " + to_string(pbits) + @@ -48,7 +50,7 @@ DL_Group::DL_Group(PrimeType type, u32bit pbits, u32bit qbits) if(type == Strong) { - p = random_safe_prime(pbits); + p = random_safe_prime(rng, pbits); q = (p - 1) / 2; g = 2; } @@ -59,18 +61,18 @@ DL_Group::DL_Group(PrimeType type, u32bit pbits, u32bit qbits) if(!qbits) qbits = 2 * dl_work_factor(pbits); - q = random_prime(qbits); + q = random_prime(rng, qbits); BigInt X; - while(p.bits() != pbits || !is_prime(p)) + while(p.bits() != pbits || !is_prime(p, rng)) { - X = random_integer(pbits); + X = random_integer(rng, pbits); p = X - (X % (2*q) - 1); } } else { qbits = qbits ? qbits : ((pbits == 1024) ? 160 : 256); - generate_dsa_primes(p, q, pbits, qbits); + generate_dsa_primes(rng, p, q, pbits, qbits); } g = make_dsa_generator(p, q); @@ -125,7 +127,7 @@ void DL_Group::initialize(const BigInt& p1, const BigInt& q1, const BigInt& g1) g = g1; q = q1; - if(q == 0 && check_prime((p - 1) / 2)) + if(q == 0 && check_prime((p - 1) / 2, global_state().prng_reference())) q = (p - 1) / 2; initialized = true; @@ -143,7 +145,8 @@ void DL_Group::init_check() const /************************************************* * Verify the parameters * *************************************************/ -bool DL_Group::verify_group(bool strong) const +bool DL_Group::verify_group(RandomNumberGenerator& rng, + bool strong) const { init_check(); @@ -155,9 +158,9 @@ bool DL_Group::verify_group(bool strong) const if(!strong) return true; - if(!check_prime(p)) + if(!check_prime(p, rng)) return false; - if((q > 0) && !check_prime(q)) + if((q > 0) && !check_prime(q, rng)) return false; return true; } |