From 770a9850f1a7c6c65b0316503b99798a6ff910dd Mon Sep 17 00:00:00 2001 From: lloyd Date: Fri, 20 Jun 2008 11:39:33 +0000 Subject: Consolidate the two DH_PrivateKey constructors into a single one taking a RNG reference, a group, and an (optional) private key. The public key is now always rederived from the private. --- src/dh.cpp | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/dh.cpp b/src/dh.cpp index 8367a3bce..159eb0629 100644 --- a/src/dh.cpp +++ b/src/dh.cpp @@ -47,28 +47,21 @@ MemoryVector DH_PublicKey::public_value() const /************************************************* * Create a DH private key * *************************************************/ -DH_PrivateKey::DH_PrivateKey(const DL_Group& grp, - RandomNumberGenerator& rng) +DH_PrivateKey::DH_PrivateKey(RandomNumberGenerator& rng, + const DL_Group& grp, + const BigInt& x_arg) { group = grp; - - const BigInt& p = group_p(); - x.randomize(rng, 2 * dl_work_factor(p.bits())); - - PKCS8_load_hook(rng, true); - } - -/************************************************* -* DH_PrivateKey Constructor * -*************************************************/ -DH_PrivateKey::DH_PrivateKey(const DL_Group& grp, const BigInt& x1, - const BigInt& y1) - { - group = grp; - y = y1; - x = x1; - - PKCS8_load_hook(global_state().prng_reference()); + x = x_arg; + + if(x == 0) + { + const BigInt& p = group_p(); + x.randomize(rng, 2 * dl_work_factor(p.bits())); + PKCS8_load_hook(rng, true); + } + else + PKCS8_load_hook(rng, false); } /************************************************* -- cgit v1.2.3