diff options
author | lloyd <[email protected]> | 2008-06-20 10:38:08 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-06-20 10:38:08 +0000 |
commit | 4331395edf8e68b46e61fc00ddb5518fef8b36b5 (patch) | |
tree | 9307d278abe6065720359df390faef327a9a3d4f /src | |
parent | 3b28d92a8a90f27f3da55db7afb47ea23e02cfc4 (diff) |
Pass a RandomNumberGenerator& to the PK_Core constructors and the various
public key object loading hooks.
Diffstat (limited to 'src')
-rw-r--r-- | src/dh.cpp | 19 | ||||
-rw-r--r-- | src/dl_algo.cpp | 5 | ||||
-rw-r--r-- | src/dsa.cpp | 17 | ||||
-rw-r--r-- | src/elgamal.cpp | 21 | ||||
-rw-r--r-- | src/nr.cpp | 17 | ||||
-rw-r--r-- | src/pk_core.cpp | 13 |
6 files changed, 48 insertions, 44 deletions
diff --git a/src/dh.cpp b/src/dh.cpp index cf83590d0..8367a3bce 100644 --- a/src/dh.cpp +++ b/src/dh.cpp @@ -17,15 +17,15 @@ DH_PublicKey::DH_PublicKey(const DL_Group& grp, const BigInt& y1) { group = grp; y = y1; - X509_load_hook(); + X509_load_hook(global_state().prng_reference()); } /************************************************* * Algorithm Specific X.509 Initialization Code * *************************************************/ -void DH_PublicKey::X509_load_hook() +void DH_PublicKey::X509_load_hook(RandomNumberGenerator& rng) { - load_check(global_state().prng_reference()); + load_check(rng); } /************************************************* @@ -55,7 +55,7 @@ DH_PrivateKey::DH_PrivateKey(const DL_Group& grp, const BigInt& p = group_p(); x.randomize(rng, 2 * dl_work_factor(p.bits())); - PKCS8_load_hook(true); + PKCS8_load_hook(rng, true); } /************************************************* @@ -68,22 +68,23 @@ DH_PrivateKey::DH_PrivateKey(const DL_Group& grp, const BigInt& x1, y = y1; x = x1; - PKCS8_load_hook(); + PKCS8_load_hook(global_state().prng_reference()); } /************************************************* * Algorithm Specific PKCS #8 Initialization Code * *************************************************/ -void DH_PrivateKey::PKCS8_load_hook(bool generated) +void DH_PrivateKey::PKCS8_load_hook(RandomNumberGenerator& rng, + bool generated) { if(y == 0) y = power_mod(group_g(), x, group_p()); - core = DH_Core(group, x); + core = DH_Core(rng, group, x); if(generated) - gen_check(global_state().prng_reference()); + gen_check(rng); else - load_check(global_state().prng_reference()); + load_check(rng); } /************************************************* diff --git a/src/dl_algo.cpp b/src/dl_algo.cpp index e1de143a0..ade50e28d 100644 --- a/src/dl_algo.cpp +++ b/src/dl_algo.cpp @@ -7,6 +7,7 @@ #include <botan/numthry.h> #include <botan/der_enc.h> #include <botan/ber_dec.h> +#include <botan/libstate.h> namespace Botan { @@ -56,7 +57,7 @@ X509_Decoder* DL_Scheme_PublicKey::x509_decoder() void key_bits(const MemoryRegion<byte>& bits) { BER_Decoder(bits).decode(key->y); - key->X509_load_hook(); + key->X509_load_hook(global_state().prng_reference()); } DL_Scheme_Decoder(DL_Scheme_PublicKey* k) : key(k) {} @@ -113,7 +114,7 @@ PKCS8_Decoder* DL_Scheme_PrivateKey::pkcs8_decoder() void key_bits(const MemoryRegion<byte>& bits) { BER_Decoder(bits).decode(key->x); - key->PKCS8_load_hook(); + key->PKCS8_load_hook(global_state().prng_reference()); } DL_Scheme_Decoder(DL_Scheme_PrivateKey* k) : key(k) {} diff --git a/src/dsa.cpp b/src/dsa.cpp index 4438ce4d5..e53ba0766 100644 --- a/src/dsa.cpp +++ b/src/dsa.cpp @@ -17,16 +17,16 @@ DSA_PublicKey::DSA_PublicKey(const DL_Group& grp, const BigInt& y1) { group = grp; y = y1; - X509_load_hook(); + X509_load_hook(global_state().prng_reference()); } /************************************************* * Algorithm Specific X.509 Initialization Code * *************************************************/ -void DSA_PublicKey::X509_load_hook() +void DSA_PublicKey::X509_load_hook(RandomNumberGenerator& rng) { core = DSA_Core(group, y); - load_check(global_state().prng_reference()); + load_check(rng); } /************************************************* @@ -63,7 +63,7 @@ DSA_PrivateKey::DSA_PrivateKey(const DL_Group& grp, group = grp; x = random_integer(rng, 2, group_q() - 1); - PKCS8_load_hook(true); + PKCS8_load_hook(rng, true); } /************************************************* @@ -76,22 +76,23 @@ DSA_PrivateKey::DSA_PrivateKey(const DL_Group& grp, const BigInt& x1, y = y1; x = x1; - PKCS8_load_hook(); + PKCS8_load_hook(global_state().prng_reference()); } /************************************************* * Algorithm Specific PKCS #8 Initialization Code * *************************************************/ -void DSA_PrivateKey::PKCS8_load_hook(bool generated) +void DSA_PrivateKey::PKCS8_load_hook(RandomNumberGenerator& rng, + bool generated) { if(y == 0) y = power_mod(group_g(), x, group_p()); core = DSA_Core(group, y, x); if(generated) - gen_check(global_state().prng_reference()); + gen_check(rng); else - load_check(global_state().prng_reference()); + load_check(rng); } /************************************************* diff --git a/src/elgamal.cpp b/src/elgamal.cpp index 02257af03..fc5100d99 100644 --- a/src/elgamal.cpp +++ b/src/elgamal.cpp @@ -18,16 +18,16 @@ ElGamal_PublicKey::ElGamal_PublicKey(const DL_Group& grp, const BigInt& y1) { group = grp; y = y1; - X509_load_hook(); + X509_load_hook(global_state().prng_reference()); } /************************************************* * Algorithm Specific X.509 Initialization Code * *************************************************/ -void ElGamal_PublicKey::X509_load_hook() +void ElGamal_PublicKey::X509_load_hook(RandomNumberGenerator& rng) { - core = ELG_Core(group, y); - load_check(global_state().prng_reference()); + core = ELG_Core(rng, group, y); + load_check(rng); } /************************************************* @@ -58,7 +58,7 @@ ElGamal_PrivateKey::ElGamal_PrivateKey(const DL_Group& grp, group = grp; x.randomize(rng, 2 * dl_work_factor(group_p().bits())); - PKCS8_load_hook(true); + PKCS8_load_hook(rng, true); } /************************************************* @@ -71,22 +71,23 @@ ElGamal_PrivateKey::ElGamal_PrivateKey(const DL_Group& grp, const BigInt& x1, y = y1; x = x1; - PKCS8_load_hook(); + PKCS8_load_hook(global_state().prng_reference()); } /************************************************* * Algorithm Specific PKCS #8 Initialization Code * *************************************************/ -void ElGamal_PrivateKey::PKCS8_load_hook(bool generated) +void ElGamal_PrivateKey::PKCS8_load_hook(RandomNumberGenerator& rng, + bool generated) { if(y == 0) y = power_mod(group_g(), x, group_p()); - core = ELG_Core(group, y, x); + core = ELG_Core(rng, group, y, x); if(generated) - gen_check(global_state().prng_reference()); + gen_check(rng); else - load_check(global_state().prng_reference()); + load_check(rng); } /************************************************* diff --git a/src/nr.cpp b/src/nr.cpp index 5b7c28f72..d8e200d9f 100644 --- a/src/nr.cpp +++ b/src/nr.cpp @@ -17,16 +17,16 @@ NR_PublicKey::NR_PublicKey(const DL_Group& grp, const BigInt& y1) { group = grp; y = y1; - X509_load_hook(); + X509_load_hook(global_state().prng_reference()); } /************************************************* * Algorithm Specific X.509 Initialization Code * *************************************************/ -void NR_PublicKey::X509_load_hook() +void NR_PublicKey::X509_load_hook(RandomNumberGenerator& rng) { core = NR_Core(group, y); - load_check(global_state().prng_reference()); + load_check(rng); } /************************************************* @@ -62,7 +62,7 @@ NR_PrivateKey::NR_PrivateKey(const DL_Group& grp, group = grp; x = random_integer(rng, 2, group_q() - 1); - PKCS8_load_hook(true); + PKCS8_load_hook(rng, true); } /************************************************* @@ -75,22 +75,23 @@ NR_PrivateKey::NR_PrivateKey(const DL_Group& grp, const BigInt& x1, y = y1; x = x1; - PKCS8_load_hook(); + PKCS8_load_hook(global_state().prng_reference()); } /************************************************* * Algorithm Specific PKCS #8 Initialization Code * *************************************************/ -void NR_PrivateKey::PKCS8_load_hook(bool generated) +void NR_PrivateKey::PKCS8_load_hook(RandomNumberGenerator& rng, + bool generated) { if(y == 0) y = power_mod(group_g(), x, group_p()); core = NR_Core(group, y, x); if(generated) - gen_check(global_state().prng_reference()); + gen_check(rng); else - load_check(global_state().prng_reference()); + load_check(rng); } /************************************************* diff --git a/src/pk_core.cpp b/src/pk_core.cpp index daee59273..788190477 100644 --- a/src/pk_core.cpp +++ b/src/pk_core.cpp @@ -8,7 +8,6 @@ #include <botan/engine.h> #include <botan/config.h> #include <botan/parsing.h> -#include <botan/libstate.h> #include <algorithm> namespace Botan { @@ -173,7 +172,8 @@ SecureVector<byte> NR_Core::sign(const byte in[], u32bit length, /************************************************* * ELG_Core Constructor * *************************************************/ -ELG_Core::ELG_Core(const DL_Group& group, const BigInt& y, const BigInt& x) +ELG_Core::ELG_Core(RandomNumberGenerator& rng, + const DL_Group& group, const BigInt& y, const BigInt& x) { op = Engine_Core::elg_op(group, y, x); @@ -183,8 +183,7 @@ ELG_Core::ELG_Core(const DL_Group& group, const BigInt& y, const BigInt& x) const BigInt& p = group.get_p(); p_bytes = p.bytes(); - BigInt k(global_state().prng_reference(), - std::min(p.bits()-1, BLINDING_BITS)); + BigInt k(rng, std::min(p.bits()-1, BLINDING_BITS)); if(k != 0) blinder = Blinder(k, power_mod(k, x, p), p); @@ -242,14 +241,14 @@ SecureVector<byte> ELG_Core::decrypt(const byte in[], u32bit length) const /************************************************* * DH_Core Constructor * *************************************************/ -DH_Core::DH_Core(const DL_Group& group, const BigInt& x) +DH_Core::DH_Core(RandomNumberGenerator& rng, + const DL_Group& group, const BigInt& x) { op = Engine_Core::dh_op(group, x); const BigInt& p = group.get_p(); - BigInt k(global_state().prng_reference(), - std::min(p.bits()-1, BLINDING_BITS)); + BigInt k(rng, std::min(p.bits()-1, BLINDING_BITS)); if(k != 0) blinder = Blinder(k, power_mod(inverse_mod(k, p), x, p), p); |