aboutsummaryrefslogtreecommitdiffstats
path: root/src/nr.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/nr.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/nr.cpp')
-rw-r--r--src/nr.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/nr.cpp b/src/nr.cpp
index 80abbf508..0f911daac 100644
--- a/src/nr.cpp
+++ b/src/nr.cpp
@@ -6,6 +6,7 @@
#include <botan/nr.h>
#include <botan/numthry.h>
#include <botan/keypair.h>
+#include <botan/libstate.h>
namespace Botan {
@@ -55,10 +56,11 @@ u32bit NR_PublicKey::message_part_size() const
/*************************************************
* Create a NR private key *
*************************************************/
-NR_PrivateKey::NR_PrivateKey(const DL_Group& grp)
+NR_PrivateKey::NR_PrivateKey(const DL_Group& grp,
+ RandomNumberGenerator& rng)
{
group = grp;
- x = random_integer(2, group_q() - 1);
+ x = random_integer(rng, 2, group_q() - 1);
PKCS8_load_hook(true);
}
@@ -100,7 +102,7 @@ SecureVector<byte> NR_PrivateKey::sign(const byte in[], u32bit length) const
BigInt k;
do
- k.randomize(q.bits());
+ k.randomize(global_state().prng_reference(), q.bits());
while(k >= q);
return core.sign(in, length, k);