aboutsummaryrefslogtreecommitdiffstats
path: root/src/pubkey
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-03-04 17:44:07 +0000
committerlloyd <[email protected]>2010-03-04 17:44:07 +0000
commit19853ce387c62b220b90019674251b334b823823 (patch)
tree5137d8be0eb07a3d56e1740add1b8aad33d4f904 /src/pubkey
parent788e524d35d01d90c56c825dbf63a96c3c42a32c (diff)
Remove IF_Scheme_PrivateKey::PKCS8_load_hook
Diffstat (limited to 'src/pubkey')
-rw-r--r--src/pubkey/if_algo/if_algo.cpp26
-rw-r--r--src/pubkey/if_algo/if_algo.h4
-rw-r--r--src/pubkey/rsa/rsa.cpp13
-rw-r--r--src/pubkey/rsa/rsa.h5
-rw-r--r--src/pubkey/rw/rw.cpp12
-rw-r--r--src/pubkey/rw/rw.h5
6 files changed, 30 insertions, 35 deletions
diff --git a/src/pubkey/if_algo/if_algo.cpp b/src/pubkey/if_algo/if_algo.cpp
index 62f83ff00..f793789cf 100644
--- a/src/pubkey/if_algo/if_algo.cpp
+++ b/src/pubkey/if_algo/if_algo.cpp
@@ -56,7 +56,8 @@ MemoryVector<byte> IF_Scheme_PrivateKey::pkcs8_private_key() const
.get_contents();
}
-IF_Scheme_PrivateKey::IF_Scheme_PrivateKey(const AlgorithmIdentifier&,
+IF_Scheme_PrivateKey::IF_Scheme_PrivateKey(RandomNumberGenerator& rng,
+ const AlgorithmIdentifier&,
const MemoryRegion<byte>& key_bits)
{
u32bit version;
@@ -76,6 +77,10 @@ IF_Scheme_PrivateKey::IF_Scheme_PrivateKey(const AlgorithmIdentifier&,
if(version != 0)
throw Decoding_Error("Unknown PKCS #1 key format version");
+
+ core = IF_Core(rng, e, n, d, p, q, d1, d2, c);
+
+ load_check(rng);
}
IF_Scheme_PrivateKey::IF_Scheme_PrivateKey(RandomNumberGenerator& rng,
@@ -111,25 +116,6 @@ IF_Scheme_PrivateKey::IF_Scheme_PrivateKey(RandomNumberGenerator& rng,
}
/*
-* Algorithm Specific PKCS #8 Initialization Code
-*/
-void IF_Scheme_PrivateKey::PKCS8_load_hook(RandomNumberGenerator& rng,
- bool generated)
- {
- if(n == 0) n = p * q;
- if(d1 == 0) d1 = d % (p - 1);
- if(d2 == 0) d2 = d % (q - 1);
- if(c == 0) c = inverse_mod(q, p);
-
- core = IF_Core(rng, e, n, d, p, q, d1, d2, c);
-
- if(generated)
- gen_check(rng);
- else
- load_check(rng);
- }
-
-/*
* Check IF Scheme Public Parameters
*/
bool IF_Scheme_PublicKey::check_key(RandomNumberGenerator&, bool) const
diff --git a/src/pubkey/if_algo/if_algo.h b/src/pubkey/if_algo/if_algo.h
index 01e370854..cbcdb9c5c 100644
--- a/src/pubkey/if_algo/if_algo.h
+++ b/src/pubkey/if_algo/if_algo.h
@@ -68,7 +68,8 @@ class BOTAN_DLL IF_Scheme_PrivateKey : public virtual IF_Scheme_PublicKey,
const BigInt& exp, const BigInt& d_exp,
const BigInt& mod);
- IF_Scheme_PrivateKey(const AlgorithmIdentifier& alg_id,
+ IF_Scheme_PrivateKey(RandomNumberGenerator& rng,
+ const AlgorithmIdentifier& alg_id,
const MemoryRegion<byte>& key_bits);
bool check_key(RandomNumberGenerator& rng, bool) const;
@@ -96,7 +97,6 @@ class BOTAN_DLL IF_Scheme_PrivateKey : public virtual IF_Scheme_PublicKey,
protected:
IF_Scheme_PrivateKey() {}
- void PKCS8_load_hook(RandomNumberGenerator&, bool = false);
BigInt d, p, q, d1, d2, c;
};
diff --git a/src/pubkey/rsa/rsa.cpp b/src/pubkey/rsa/rsa.cpp
index c606e5c53..b181cb9cc 100644
--- a/src/pubkey/rsa/rsa.cpp
+++ b/src/pubkey/rsa/rsa.cpp
@@ -57,12 +57,19 @@ RSA_PrivateKey::RSA_PrivateKey(RandomNumberGenerator& rng,
e = exp;
p = random_prime(rng, (bits + 1) / 2, e);
q = random_prime(rng, bits - p.bits(), e);
- d = inverse_mod(e, lcm(p - 1, q - 1));
-
- PKCS8_load_hook(rng, true);
+ n = p * q;
if(n.bits() != bits)
throw Self_Test_Failure(algo_name() + " private key generation failed");
+
+ d = inverse_mod(e, lcm(p - 1, q - 1));
+ d1 = d % (p - 1);
+ d2 = d % (q - 1);
+ c = inverse_mod(q, p);
+
+ core = IF_Core(rng, e, n, d, p, q, d1, d2, c);
+
+ gen_check(rng);
}
/*
diff --git a/src/pubkey/rsa/rsa.h b/src/pubkey/rsa/rsa.h
index ce79e2440..0d5a4ad2e 100644
--- a/src/pubkey/rsa/rsa.h
+++ b/src/pubkey/rsa/rsa.h
@@ -69,10 +69,7 @@ class BOTAN_DLL RSA_PrivateKey : public RSA_PublicKey,
RSA_PrivateKey(const AlgorithmIdentifier& alg_id,
const MemoryRegion<byte>& key_bits,
RandomNumberGenerator& rng) :
- IF_Scheme_PrivateKey(alg_id, key_bits)
- {
- PKCS8_load_hook(rng);
- }
+ IF_Scheme_PrivateKey(rng, alg_id, key_bits) {}
/**
* Construct a private key from the specified parameters.
diff --git a/src/pubkey/rw/rw.cpp b/src/pubkey/rw/rw.cpp
index 259e53a26..72fa29afa 100644
--- a/src/pubkey/rw/rw.cpp
+++ b/src/pubkey/rw/rw.cpp
@@ -57,12 +57,20 @@ RW_PrivateKey::RW_PrivateKey(RandomNumberGenerator& rng,
e = exp;
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(rng, true);
+ n = p * q;
if(n.bits() != bits)
throw Self_Test_Failure(algo_name() + " private key generation failed");
+
+ d = inverse_mod(e, lcm(p - 1, q - 1) >> 1);
+ d1 = d % (p - 1);
+ d2 = d % (q - 1);
+ c = inverse_mod(q, p);
+
+ core = IF_Core(rng, e, n, d, p, q, d1, d2, c);
+
+ gen_check(rng);
}
/*
diff --git a/src/pubkey/rw/rw.h b/src/pubkey/rw/rw.h
index d2411d630..efdca04e7 100644
--- a/src/pubkey/rw/rw.h
+++ b/src/pubkey/rw/rw.h
@@ -57,10 +57,7 @@ class BOTAN_DLL RW_PrivateKey : public RW_PublicKey,
RW_PrivateKey(const AlgorithmIdentifier& alg_id,
const MemoryRegion<byte>& key_bits,
RandomNumberGenerator& rng) :
- IF_Scheme_PrivateKey(alg_id, key_bits)
- {
- PKCS8_load_hook(rng);
- }
+ IF_Scheme_PrivateKey(rng, alg_id, key_bits) {}
RW_PrivateKey(RandomNumberGenerator& rng,
const BigInt& p, const BigInt& q,