aboutsummaryrefslogtreecommitdiffstats
path: root/src/pk_core.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-05-24 18:25:00 +0000
committerlloyd <[email protected]>2008-05-24 18:25:00 +0000
commitb7563677f13adb8dfa5813ef91ed79364b2d984d (patch)
treecf7fabb3eb43bc49333be726c15ecac1a7f9a1a7 /src/pk_core.cpp
parenta6a9110d02925e111cff2dc1143a09a3b7680f0b (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/pk_core.cpp')
-rw-r--r--src/pk_core.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/pk_core.cpp b/src/pk_core.cpp
index 42abe7196..4c76716f2 100644
--- a/src/pk_core.cpp
+++ b/src/pk_core.cpp
@@ -8,6 +8,7 @@
#include <botan/engine.h>
#include <botan/config.h>
#include <botan/parsing.h>
+#include <botan/libstate.h>
#include <algorithm>
namespace Botan {
@@ -29,7 +30,8 @@ IF_Core::IF_Core(const BigInt& e, const BigInt& n, const BigInt& d,
if(d != 0)
{
- BigInt k = random_integer(std::min(n.bits()-1, BLINDING_BITS));
+ BigInt k = random_integer(global_state().prng_reference(),
+ std::min(n.bits()-1, BLINDING_BITS));
if(k != 0)
blinder = Blinder(power_mod(k, e, n), inverse_mod(k, n), n);
}
@@ -180,7 +182,8 @@ 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 = random_integer(std::min(p.bits()-1, BLINDING_BITS));
+ BigInt k = random_integer(global_state().prng_reference(),
+ std::min(p.bits()-1, BLINDING_BITS));
if(k != 0)
blinder = Blinder(k, power_mod(k, x, p), p);
}
@@ -242,7 +245,8 @@ DH_Core::DH_Core(const DL_Group& group, const BigInt& x)
op = Engine_Core::dh_op(group, x);
const BigInt& p = group.get_p();
- BigInt k = random_integer(std::min(p.bits()-1, BLINDING_BITS));
+ BigInt k = random_integer(global_state().prng_reference(),
+ std::min(p.bits()-1, BLINDING_BITS));
if(k != 0)
blinder = Blinder(k, power_mod(inverse_mod(k, p), x, p), p);
}