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/elgamal.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/elgamal.cpp')
-rw-r--r-- | src/elgamal.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/elgamal.cpp b/src/elgamal.cpp index 65fd22180..bcb8a6cc0 100644 --- a/src/elgamal.cpp +++ b/src/elgamal.cpp @@ -7,6 +7,7 @@ #include <botan/numthry.h> #include <botan/keypair.h> #include <botan/util.h> +#include <botan/libstate.h> namespace Botan { @@ -35,7 +36,10 @@ void ElGamal_PublicKey::X509_load_hook() SecureVector<byte> ElGamal_PublicKey::encrypt(const byte in[], u32bit length) const { - BigInt k = random_integer(2 * dl_work_factor(group_p().bits())); + BigInt k = random_integer( + global_state().prng_reference(), + 2 * dl_work_factor(group_p().bits())); + return core.encrypt(in, length, k); } @@ -50,11 +54,12 @@ u32bit ElGamal_PublicKey::max_input_bits() const /************************************************* * ElGamal_PrivateKey Constructor * *************************************************/ -ElGamal_PrivateKey::ElGamal_PrivateKey(const DL_Group& grp) +ElGamal_PrivateKey::ElGamal_PrivateKey(const DL_Group& grp, + RandomNumberGenerator& rng) { group = grp; - x = random_integer(2 * dl_work_factor(group_p().bits())); + x = random_integer(rng, 2 * dl_work_factor(group_p().bits())); PKCS8_load_hook(true); } |