diff options
author | lloyd <[email protected]> | 2008-06-20 19:03:45 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-06-20 19:03:45 +0000 |
commit | 7dde81851bfb6cef78c3480acc2f1c1dedb1f126 (patch) | |
tree | 06f35288c9c08b9f77468c664dbf8a65aaaf2647 /src | |
parent | 770a9850f1a7c6c65b0316503b99798a6ff910dd (diff) |
Similiar combining transform for the ElGamal, DSA, and NR private key
constructors.
Diffstat (limited to 'src')
-rw-r--r-- | src/dsa.cpp | 31 | ||||
-rw-r--r-- | src/elgamal.cpp | 28 | ||||
-rw-r--r-- | src/nr.cpp | 28 |
3 files changed, 34 insertions, 53 deletions
diff --git a/src/dsa.cpp b/src/dsa.cpp index e53ba0766..8ca2f7db5 100644 --- a/src/dsa.cpp +++ b/src/dsa.cpp @@ -57,26 +57,20 @@ u32bit DSA_PublicKey::message_part_size() const /************************************************* * Create a DSA private key * *************************************************/ -DSA_PrivateKey::DSA_PrivateKey(const DL_Group& grp, - RandomNumberGenerator& rng) +DSA_PrivateKey::DSA_PrivateKey(RandomNumberGenerator& rng, + const DL_Group& grp, + const BigInt& x_arg) { group = grp; - x = random_integer(rng, 2, group_q() - 1); + x = x_arg; - PKCS8_load_hook(rng, true); - } - -/************************************************* -* DSA_PrivateKey Constructor * -*************************************************/ -DSA_PrivateKey::DSA_PrivateKey(const DL_Group& grp, const BigInt& x1, - const BigInt& y1) - { - group = grp; - y = y1; - x = x1; - - PKCS8_load_hook(global_state().prng_reference()); + if(x == 0) + { + x = random_integer(rng, 2, group_q() - 1); + PKCS8_load_hook(rng, true); + } + else + PKCS8_load_hook(rng, false); } /************************************************* @@ -85,8 +79,7 @@ DSA_PrivateKey::DSA_PrivateKey(const DL_Group& grp, const BigInt& x1, void DSA_PrivateKey::PKCS8_load_hook(RandomNumberGenerator& rng, bool generated) { - if(y == 0) - y = power_mod(group_g(), x, group_p()); + y = power_mod(group_g(), x, group_p()); core = DSA_Core(group, y, x); if(generated) diff --git a/src/elgamal.cpp b/src/elgamal.cpp index fc5100d99..d97a365e7 100644 --- a/src/elgamal.cpp +++ b/src/elgamal.cpp @@ -52,26 +52,20 @@ u32bit ElGamal_PublicKey::max_input_bits() const /************************************************* * ElGamal_PrivateKey Constructor * *************************************************/ -ElGamal_PrivateKey::ElGamal_PrivateKey(const DL_Group& grp, - RandomNumberGenerator& rng) +ElGamal_PrivateKey::ElGamal_PrivateKey(RandomNumberGenerator& rng, + const DL_Group& grp, + const BigInt& x_arg) { group = grp; - x.randomize(rng, 2 * dl_work_factor(group_p().bits())); + x = x_arg; - PKCS8_load_hook(rng, true); - } - -/************************************************* -* ElGamal_PrivateKey Constructor * -*************************************************/ -ElGamal_PrivateKey::ElGamal_PrivateKey(const DL_Group& grp, const BigInt& x1, - const BigInt& y1) - { - group = grp; - y = y1; - x = x1; - - PKCS8_load_hook(global_state().prng_reference()); + if(x == 0) + { + x.randomize(rng, 2 * dl_work_factor(group_p().bits())); + PKCS8_load_hook(rng, true); + } + else + PKCS8_load_hook(rng, false); } /************************************************* diff --git a/src/nr.cpp b/src/nr.cpp index d8e200d9f..de46abd80 100644 --- a/src/nr.cpp +++ b/src/nr.cpp @@ -56,26 +56,20 @@ u32bit NR_PublicKey::message_part_size() const /************************************************* * Create a NR private key * *************************************************/ -NR_PrivateKey::NR_PrivateKey(const DL_Group& grp, - RandomNumberGenerator& rng) +NR_PrivateKey::NR_PrivateKey(RandomNumberGenerator& rng, + const DL_Group& grp, + const BigInt& x_arg) { group = grp; - x = random_integer(rng, 2, group_q() - 1); + x = x_arg; - PKCS8_load_hook(rng, true); - } - -/************************************************* -* NR_PrivateKey Constructor * -*************************************************/ -NR_PrivateKey::NR_PrivateKey(const DL_Group& grp, const BigInt& x1, - const BigInt& y1) - { - group = grp; - y = y1; - x = x1; - - PKCS8_load_hook(global_state().prng_reference()); + if(x == 0) + { + x = random_integer(rng, 2, group_q() - 1); + PKCS8_load_hook(rng, true); + } + else + PKCS8_load_hook(rng, false); } /************************************************* |