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 /include | |
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 'include')
-rw-r--r-- | include/bigint.h | 4 | ||||
-rw-r--r-- | include/dh.h | 2 | ||||
-rw-r--r-- | include/dl_group.h | 14 | ||||
-rw-r--r-- | include/dsa.h | 2 | ||||
-rw-r--r-- | include/elgamal.h | 2 | ||||
-rw-r--r-- | include/libstate.h | 2 | ||||
-rw-r--r-- | include/nr.h | 2 | ||||
-rw-r--r-- | include/numthry.h | 27 | ||||
-rw-r--r-- | include/rsa.h | 2 | ||||
-rw-r--r-- | include/rw.h | 2 |
10 files changed, 37 insertions, 22 deletions
diff --git a/include/bigint.h b/include/bigint.h index 36abbb388..5c4a9c997 100644 --- a/include/bigint.h +++ b/include/bigint.h @@ -20,7 +20,7 @@ class BOTAN_DLL BigInt public: enum Base { Octal = 8, Decimal = 10, Hexadecimal = 16, Binary = 256 }; enum Sign { Negative = 0, Positive = 1 }; - enum NumberType { Random, Power2 }; + enum NumberType { Power2 }; struct DivideByZero : public Exception { DivideByZero() : Exception("BigInt divide by zero") {} }; @@ -82,7 +82,7 @@ class BOTAN_DLL BigInt word operator[](u32bit) const; void clear() { reg.clear(); } - void randomize(u32bit = 0); + void randomize(RandomNumberGenerator& rng, u32bit n); void binary_encode(byte[]) const; void binary_decode(const byte[], u32bit); diff --git a/include/dh.h b/include/dh.h index c2ee8bd7d..3c55ef8d4 100644 --- a/include/dh.h +++ b/include/dh.h @@ -45,7 +45,7 @@ class BOTAN_DLL DH_PrivateKey : public DH_PublicKey, MemoryVector<byte> public_value() const; DH_PrivateKey() {} - DH_PrivateKey(const DL_Group&); + DH_PrivateKey(const DL_Group&, RandomNumberGenerator&); DH_PrivateKey(const DL_Group&, const BigInt&, const BigInt& = 0); private: void PKCS8_load_hook(bool = false); diff --git a/include/dl_group.h b/include/dl_group.h index 9fb242070..010a949ff 100644 --- a/include/dl_group.h +++ b/include/dl_group.h @@ -1,6 +1,6 @@ /************************************************* * Discrete Logarithm Group Header File * -* (C) 1999-2007 Jack Lloyd * +* (C) 1999-2008 Jack Lloyd * *************************************************/ #ifndef BOTAN_DL_PARAM_H__ @@ -24,7 +24,7 @@ class BOTAN_DLL DL_Group enum Format { ANSI_X9_42, ANSI_X9_57, PKCS_3 }; enum PrimeType { Strong, Prime_Subgroup, DSA_Kosherizer }; - bool verify_group(bool) const; + bool verify_group(RandomNumberGenerator& rng, bool) const; std::string PEM_encode(Format) const; SecureVector<byte> DER_encode(Format) const; @@ -33,14 +33,18 @@ class BOTAN_DLL DL_Group DL_Group(); DL_Group(const std::string&); - DL_Group(PrimeType, u32bit, u32bit = 0); + DL_Group(RandomNumberGenerator& rng, PrimeType, u32bit, u32bit = 0); DL_Group(const MemoryRegion<byte>&, u32bit = 1024, u32bit = 0); DL_Group(const BigInt&, const BigInt&); DL_Group(const BigInt&, const BigInt&, const BigInt&); private: static BigInt make_dsa_generator(const BigInt&, const BigInt&); - static SecureVector<byte> generate_dsa_primes(BigInt&, BigInt&, - u32bit, u32bit); + + static SecureVector<byte> + generate_dsa_primes(RandomNumberGenerator& rng, + BigInt& p, BigInt& q, + u32bit pbits, u32bit qbits); + static bool generate_dsa_primes(BigInt&, BigInt&, u32bit, u32bit, const MemoryRegion<byte>&); diff --git a/include/dsa.h b/include/dsa.h index 1bb501d27..21941cd29 100644 --- a/include/dsa.h +++ b/include/dsa.h @@ -48,7 +48,7 @@ class BOTAN_DLL DSA_PrivateKey : public DSA_PublicKey, bool check_key(bool) const; DSA_PrivateKey() {} - DSA_PrivateKey(const DL_Group&); + DSA_PrivateKey(const DL_Group&, RandomNumberGenerator& rng); DSA_PrivateKey(const DL_Group&, const BigInt&, const BigInt& = 0); private: void PKCS8_load_hook(bool = false); diff --git a/include/elgamal.h b/include/elgamal.h index 3f39d22a7..9a8135d38 100644 --- a/include/elgamal.h +++ b/include/elgamal.h @@ -46,7 +46,7 @@ class BOTAN_DLL ElGamal_PrivateKey : public ElGamal_PublicKey, bool check_key(bool) const; ElGamal_PrivateKey() {} - ElGamal_PrivateKey(const DL_Group&); + ElGamal_PrivateKey(const DL_Group&, RandomNumberGenerator&); ElGamal_PrivateKey(const DL_Group&, const BigInt&, const BigInt& = 0); private: void PKCS8_load_hook(bool = false); diff --git a/include/libstate.h b/include/libstate.h index 77a6ce05b..e38acd90a 100644 --- a/include/libstate.h +++ b/include/libstate.h @@ -54,6 +54,8 @@ class BOTAN_DLL Library_State void add_entropy(EntropySource&, bool); u32bit seed_prng(bool, u32bit); + RandomNumberGenerator& prng_reference() { return (*rng); } + class Config& config() const; class Mutex* get_mutex() const; diff --git a/include/nr.h b/include/nr.h index ef46db0b0..0225af057 100644 --- a/include/nr.h +++ b/include/nr.h @@ -48,7 +48,7 @@ class BOTAN_DLL NR_PrivateKey : public NR_PublicKey, bool check_key(bool) const; NR_PrivateKey() {} - NR_PrivateKey(const DL_Group&); + NR_PrivateKey(const DL_Group&, RandomNumberGenerator& rng); NR_PrivateKey(const DL_Group&, const BigInt&, const BigInt& = 0); private: void PKCS8_load_hook(bool = false); diff --git a/include/numthry.h b/include/numthry.h index 44d56601a..6ca06be10 100644 --- a/include/numthry.h +++ b/include/numthry.h @@ -6,6 +6,7 @@ #ifndef BOTAN_NUMBTHRY_H__ #define BOTAN_NUMBTHRY_H__ +#include <botan/base.h> #include <botan/bigint.h> #include <botan/reducer.h> #include <botan/pow_mod.h> @@ -42,23 +43,31 @@ u32bit BOTAN_DLL low_zero_bits(const BigInt&); /************************************************* * Primality Testing * *************************************************/ -bool BOTAN_DLL check_prime(const BigInt&); -bool BOTAN_DLL is_prime(const BigInt&); -bool BOTAN_DLL verify_prime(const BigInt&); +bool BOTAN_DLL check_prime(const BigInt&, RandomNumberGenerator&); +bool BOTAN_DLL is_prime(const BigInt&, RandomNumberGenerator&); +bool BOTAN_DLL verify_prime(const BigInt&, RandomNumberGenerator&); s32bit BOTAN_DLL simple_primality_tests(const BigInt&); -bool BOTAN_DLL passes_mr_tests(const BigInt&, u32bit = 1); -bool BOTAN_DLL run_primality_tests(const BigInt&, u32bit = 1); + +bool BOTAN_DLL passes_mr_tests(RandomNumberGenerator&, + const BigInt&, u32bit = 1); + +bool BOTAN_DLL run_primality_tests(RandomNumberGenerator&, + const BigInt&, u32bit = 1); /************************************************* * Random Number Generation * *************************************************/ -BigInt BOTAN_DLL random_integer(u32bit); -BigInt BOTAN_DLL random_integer(const BigInt&, const BigInt&); -BigInt BOTAN_DLL random_prime(u32bit, const BigInt& = 1, +BigInt BOTAN_DLL random_integer(RandomNumberGenerator&, u32bit); +BigInt BOTAN_DLL random_integer(RandomNumberGenerator&, + const BigInt&, const BigInt&); + +BigInt BOTAN_DLL random_prime(RandomNumberGenerator&, + u32bit n, const BigInt& = 1, u32bit = 1, u32bit = 2); -BigInt BOTAN_DLL random_safe_prime(u32bit); +BigInt BOTAN_DLL random_safe_prime(RandomNumberGenerator&, + u32bit); /************************************************* * Prime Numbers * diff --git a/include/rsa.h b/include/rsa.h index 415bc2af6..54ac50fad 100644 --- a/include/rsa.h +++ b/include/rsa.h @@ -46,7 +46,7 @@ class BOTAN_DLL RSA_PrivateKey : public RSA_PublicKey, RSA_PrivateKey() {} RSA_PrivateKey(const BigInt&, const BigInt&, const BigInt&, const BigInt& = 0, const BigInt& = 0); - RSA_PrivateKey(u32bit, u32bit = 65537); + RSA_PrivateKey(u32bit, RandomNumberGenerator&, u32bit = 65537); private: BigInt private_op(const byte[], u32bit) const; }; diff --git a/include/rw.h b/include/rw.h index 896e29545..6ccc2b10d 100644 --- a/include/rw.h +++ b/include/rw.h @@ -42,7 +42,7 @@ class BOTAN_DLL RW_PrivateKey : public RW_PublicKey, RW_PrivateKey() {} RW_PrivateKey(const BigInt&, const BigInt&, const BigInt&, const BigInt& = 0, const BigInt& = 0); - RW_PrivateKey(u32bit, u32bit = 2); + RW_PrivateKey(u32bit, RandomNumberGenerator& rng, u32bit = 2); }; } |