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/rw.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/rw.cpp')
-rw-r--r-- | src/rw.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/rw.cpp b/src/rw.cpp index 758a95a04..425ab83b3 100644 --- a/src/rw.cpp +++ b/src/rw.cpp @@ -52,17 +52,19 @@ SecureVector<byte> RW_PublicKey::verify(const byte in[], u32bit len) const /************************************************* * Create a Rabin-Williams private key * *************************************************/ -RW_PrivateKey::RW_PrivateKey(u32bit bits, u32bit exp) +RW_PrivateKey::RW_PrivateKey(u32bit bits, + RandomNumberGenerator& rng, + u32bit exp) { - if(bits < 512) + if(bits < 1024) throw Invalid_Argument(algo_name() + ": Can't make a key that is only " + to_string(bits) + " bits long"); if(exp < 2 || exp % 2 == 1) throw Invalid_Argument(algo_name() + ": Invalid encryption exponent"); e = exp; - p = random_prime((bits + 1) / 2, e / 2, 3, 4); - q = random_prime(bits - p.bits(), e / 2, ((p % 8 == 3) ? 7 : 3), 8); + p = random_prime(rng, (bits + 1) / 2, e / 2, 3, 4); + q = random_prime(rng, bits - p.bits(), e / 2, ((p % 8 == 3) ? 7 : 3), 8); d = inverse_mod(e, lcm(p - 1, q - 1) >> 1); PKCS8_load_hook(true); |