diff options
author | lloyd <[email protected]> | 2006-09-06 19:48:09 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2006-09-06 19:48:09 +0000 |
commit | e00227828d80f9c9a17ef236586211faa01e4193 (patch) | |
tree | 2573533839150184038b18d7789eaef1ee5dd904 /src | |
parent | 7f176fd2259fcb395ca03751f19790eac15bd9ce (diff) |
Split PK_Key into Public_Key and Private_Key; these new classes merge in
the interfaces previously included in X509_PublicKey and PKCS8_PrivateKey.
Diffstat (limited to 'src')
-rw-r--r-- | src/dh.cpp | 21 | ||||
-rw-r--r-- | src/dsa.cpp | 13 | ||||
-rw-r--r-- | src/elgamal.cpp | 13 | ||||
-rw-r--r-- | src/if_algo.cpp | 9 | ||||
-rw-r--r-- | src/nr.cpp | 13 | ||||
-rw-r--r-- | src/pk_keys.cpp | 8 | ||||
-rw-r--r-- | src/rsa.cpp | 4 | ||||
-rw-r--r-- | src/rw.cpp | 4 | ||||
-rw-r--r-- | src/x509_key.cpp | 27 | ||||
-rw-r--r-- | src/x509find.cpp | 22 |
10 files changed, 53 insertions, 81 deletions
diff --git a/src/dh.cpp b/src/dh.cpp index cdcd17e50..23242e5f6 100644 --- a/src/dh.cpp +++ b/src/dh.cpp @@ -24,7 +24,15 @@ DH_PublicKey::DH_PublicKey(const DL_Group& grp, const BigInt& y1) *************************************************/ void DH_PublicKey::X509_load_hook() { - check_loaded_public(); + load_check(); + } + +/************************************************* +* Return the maximum input size in bits * +*************************************************/ +u32bit DH_PublicKey::max_input_bits() const + { + return group_p().bits(); } /************************************************* @@ -45,8 +53,7 @@ DH_PrivateKey::DH_PrivateKey(const DL_Group& grp) const BigInt& p = group_p(); x = random_integer(2 * dl_work_factor(p.bits())); - PKCS8_load_hook(); - check_generated_private(); + PKCS8_load_hook(true); } /************************************************* @@ -60,17 +67,21 @@ DH_PrivateKey::DH_PrivateKey(const DL_Group& grp, const BigInt& x1, x = x1; PKCS8_load_hook(); - check_loaded_private(); } /************************************************* * Algorithm Specific PKCS #8 Initialization Code * *************************************************/ -void DH_PrivateKey::PKCS8_load_hook() +void DH_PrivateKey::PKCS8_load_hook(bool generated) { if(y == 0) y = power_mod(group_g(), x, group_p()); core = DH_Core(group, x); + + if(generated) + gen_check(); + else + load_check(); } /************************************************* diff --git a/src/dsa.cpp b/src/dsa.cpp index d3fc9107a..f5f7d1765 100644 --- a/src/dsa.cpp +++ b/src/dsa.cpp @@ -25,7 +25,7 @@ DSA_PublicKey::DSA_PublicKey(const DL_Group& grp, const BigInt& y1) void DSA_PublicKey::X509_load_hook() { core = DSA_Core(group, y); - check_loaded_public(); + load_check(); } /************************************************* @@ -61,8 +61,7 @@ DSA_PrivateKey::DSA_PrivateKey(const DL_Group& grp) group = grp; x = random_integer(2, group_q() - 1); - PKCS8_load_hook(); - check_generated_private(); + PKCS8_load_hook(true); } /************************************************* @@ -76,17 +75,21 @@ DSA_PrivateKey::DSA_PrivateKey(const DL_Group& grp, const BigInt& x1, x = x1; PKCS8_load_hook(); - check_loaded_private(); } /************************************************* * Algorithm Specific PKCS #8 Initialization Code * *************************************************/ -void DSA_PrivateKey::PKCS8_load_hook() +void DSA_PrivateKey::PKCS8_load_hook(bool generated) { if(y == 0) y = power_mod(group_g(), x, group_p()); core = DSA_Core(group, y, x); + + if(generated) + gen_check(); + else + load_check(); } /************************************************* diff --git a/src/elgamal.cpp b/src/elgamal.cpp index 152aeb4dc..7be0a576b 100644 --- a/src/elgamal.cpp +++ b/src/elgamal.cpp @@ -26,7 +26,7 @@ ElGamal_PublicKey::ElGamal_PublicKey(const DL_Group& grp, const BigInt& y1) void ElGamal_PublicKey::X509_load_hook() { core = ELG_Core(group, y); - check_loaded_public(); + load_check(); } /************************************************* @@ -56,8 +56,7 @@ ElGamal_PrivateKey::ElGamal_PrivateKey(const DL_Group& grp) x = random_integer(2 * dl_work_factor(group_p().bits())); - PKCS8_load_hook(); - check_generated_private(); + PKCS8_load_hook(true); } /************************************************* @@ -71,17 +70,21 @@ ElGamal_PrivateKey::ElGamal_PrivateKey(const DL_Group& grp, const BigInt& x1, x = x1; PKCS8_load_hook(); - check_loaded_private(); } /************************************************* * Algorithm Specific PKCS #8 Initialization Code * *************************************************/ -void ElGamal_PrivateKey::PKCS8_load_hook() +void ElGamal_PrivateKey::PKCS8_load_hook(bool generated) { if(y == 0) y = power_mod(group_g(), x, group_p()); core = ELG_Core(group, y, x); + + if(generated) + gen_check(); + else + load_check(); } /************************************************* diff --git a/src/if_algo.cpp b/src/if_algo.cpp index 97d0d0510..afa428fde 100644 --- a/src/if_algo.cpp +++ b/src/if_algo.cpp @@ -159,13 +159,13 @@ PKCS8_Decoder* IF_Scheme_PrivateKey::pkcs8_decoder() void IF_Scheme_PublicKey::X509_load_hook() { core = IF_Core(e, n); - check_loaded_public(); + load_check(); } /************************************************* * Algorithm Specific PKCS #8 Initialization Code * *************************************************/ -void IF_Scheme_PrivateKey::PKCS8_load_hook() +void IF_Scheme_PrivateKey::PKCS8_load_hook(bool generated) { if(n == 0) n = p * q; if(d1 == 0) d1 = d % (p - 1); @@ -173,6 +173,11 @@ void IF_Scheme_PrivateKey::PKCS8_load_hook() if(c == 0) c = inverse_mod(q, p); core = IF_Core(e, n, d, p, q, d1, d2, c); + + if(generated) + gen_check(); + else + load_check(); } /************************************************* diff --git a/src/nr.cpp b/src/nr.cpp index d6e436015..f8fe065df 100644 --- a/src/nr.cpp +++ b/src/nr.cpp @@ -25,7 +25,7 @@ NR_PublicKey::NR_PublicKey(const DL_Group& grp, const BigInt& y1) void NR_PublicKey::X509_load_hook() { core = NR_Core(group, y); - check_loaded_public(); + load_check(); } /************************************************* @@ -60,8 +60,7 @@ NR_PrivateKey::NR_PrivateKey(const DL_Group& grp) group = grp; x = random_integer(2, group_q() - 1); - PKCS8_load_hook(); - check_generated_private(); + PKCS8_load_hook(true); } /************************************************* @@ -75,17 +74,21 @@ NR_PrivateKey::NR_PrivateKey(const DL_Group& grp, const BigInt& x1, x = x1; PKCS8_load_hook(); - check_loaded_private(); } /************************************************* * Algorithm Specific PKCS #8 Initialization Code * *************************************************/ -void NR_PrivateKey::PKCS8_load_hook() +void NR_PrivateKey::PKCS8_load_hook(bool generated) { if(y == 0) y = power_mod(group_g(), x, group_p()); core = NR_Core(group, y, x); + + if(generated) + gen_check(); + else + load_check(); } /************************************************* diff --git a/src/pk_keys.cpp b/src/pk_keys.cpp index 4a175e17c..478ee5d37 100644 --- a/src/pk_keys.cpp +++ b/src/pk_keys.cpp @@ -27,7 +27,7 @@ bool key_check_level(const std::string& type) /************************************************* * Default OID access * *************************************************/ -OID PK_Key::get_oid() const +OID Public_Key::get_oid() const { try { return OIDS::lookup(algo_name()); @@ -41,7 +41,7 @@ OID PK_Key::get_oid() const /************************************************* * Run checks on a loaded public key * *************************************************/ -void PK_Key::check_loaded_public() const +void Public_Key::load_check() const { if(!check_key(key_check_level("public"))) throw Invalid_Argument(algo_name() + ": Invalid public key"); @@ -50,7 +50,7 @@ void PK_Key::check_loaded_public() const /************************************************* * Run checks on a loaded private key * *************************************************/ -void PK_Key::check_loaded_private() const +void Private_Key::load_check() const { if(!check_key(key_check_level("private"))) throw Invalid_Argument(algo_name() + ": Invalid private key"); @@ -59,7 +59,7 @@ void PK_Key::check_loaded_private() const /************************************************* * Run checks on a generated private key * *************************************************/ -void PK_Key::check_generated_private() const +void Private_Key::gen_check() const { if(!check_key(key_check_level("private_gen"))) throw Self_Test_Failure(algo_name() + " private key generation failed"); diff --git a/src/rsa.cpp b/src/rsa.cpp index c11733aa3..1176b3a68 100644 --- a/src/rsa.cpp +++ b/src/rsa.cpp @@ -64,8 +64,7 @@ RSA_PrivateKey::RSA_PrivateKey(u32bit bits, u32bit exp) q = random_prime(bits - p.bits(), e); d = inverse_mod(e, lcm(p - 1, q - 1)); - PKCS8_load_hook(); - check_generated_private(); + PKCS8_load_hook(true); if(n.bits() != bits) throw Self_Test_Failure(algo_name() + " private key generation failed"); @@ -88,7 +87,6 @@ RSA_PrivateKey::RSA_PrivateKey(const BigInt& prime1, const BigInt& prime2, d = inverse_mod(e, lcm(p - 1, q - 1)); PKCS8_load_hook(); - check_loaded_private(); } /************************************************* diff --git a/src/rw.cpp b/src/rw.cpp index 9ab43cde9..714929edd 100644 --- a/src/rw.cpp +++ b/src/rw.cpp @@ -65,8 +65,7 @@ RW_PrivateKey::RW_PrivateKey(u32bit bits, u32bit exp) q = random_prime(bits - p.bits(), e / 2, ((p % 8 == 3) ? 7 : 3), 8); d = inverse_mod(e, lcm(p - 1, q - 1) >> 1); - PKCS8_load_hook(); - check_generated_private(); + PKCS8_load_hook(true); if(n.bits() != bits) throw Self_Test_Failure(algo_name() + " private key generation failed"); @@ -89,7 +88,6 @@ RW_PrivateKey::RW_PrivateKey(const BigInt& prime1, const BigInt& prime2, d = inverse_mod(e, lcm(p - 1, q - 1) >> 1); PKCS8_load_hook(); - check_loaded_private(); } /************************************************* diff --git a/src/x509_key.cpp b/src/x509_key.cpp index 2825cf836..332297e78 100644 --- a/src/x509_key.cpp +++ b/src/x509_key.cpp @@ -15,33 +15,6 @@ namespace Botan { -/************************************************* -* Compute the key id * -*************************************************/ -u64bit X509_PublicKey::key_id() const - { - std::auto_ptr<X509_Encoder> encoder(x509_encoder()); - if(!encoder.get()) - throw Internal_Error("X509_PublicKey:key_id: No encoder found"); - - Pipe pipe(new Hash_Filter("SHA-1", 8)); - pipe.start_msg(); - pipe.write(algo_name()); - pipe.write(encoder->alg_id().parameters); - pipe.write(encoder->key_bits()); - pipe.end_msg(); - - SecureVector<byte> output = pipe.read_all(); - - if(output.size() != 8) - throw Internal_Error("X509_PublicKey::key_id: Incorrect output size"); - - u64bit id = 0; - for(u32bit j = 0; j != 8; ++j) - id = (id << 8) | output[j]; - return id; - } - namespace X509 { /************************************************* diff --git a/src/x509find.cpp b/src/x509find.cpp index 7a9d370a1..9a6f75fe4 100644 --- a/src/x509find.cpp +++ b/src/x509find.cpp @@ -101,28 +101,6 @@ std::vector<X509_Certificate> by_dns(const X509_Store& store, } /************************************************* -* Search for a certificate by key id * -*************************************************/ -std::vector<X509_Certificate> by_keyid(const X509_Store& store, u64bit key_id) - { - class KeyID_Match : public X509_Store::Search_Func - { - public: - bool match(const X509_Certificate& cert) const - { - std::auto_ptr<X509_PublicKey> key(cert.subject_public_key()); - return (key->key_id() == key_id); - } - KeyID_Match(u64bit id) : key_id(id) {} - private: - u64bit key_id; - }; - - KeyID_Match search_params(key_id); - return store.get_certs(search_params); - } - -/************************************************* * Search for a certificate by issuer/serial * *************************************************/ std::vector<X509_Certificate> by_iands(const X509_Store& store, |