diff options
author | René Korthaus <[email protected]> | 2016-12-04 22:06:32 +0100 |
---|---|---|
committer | René Korthaus <[email protected]> | 2016-12-05 10:28:38 +0100 |
commit | 8690e4e616367c12412fb56bc1826be203a4614b (patch) | |
tree | dace4204f21931d458ceeadf351428f01792f215 /src/lib/pubkey | |
parent | 61c4932f27c060a691ddc04fb75d227a1e8365dd (diff) |
Add Public_Key::subject_public_key()
Adds new Public_Key::subject_public_key() that returns
a X.509 SubjectPublicKey structure. Renames the current
Public_Key::x509_subject_public_key() to public_key_bits().
BER_encode() just invokes subject_public_key().
Diffstat (limited to 'src/lib/pubkey')
-rw-r--r-- | src/lib/pubkey/curve25519/curve25519.cpp | 2 | ||||
-rw-r--r-- | src/lib/pubkey/curve25519/curve25519.h | 2 | ||||
-rw-r--r-- | src/lib/pubkey/dl_algo/dl_algo.cpp | 2 | ||||
-rw-r--r-- | src/lib/pubkey/dl_algo/dl_algo.h | 2 | ||||
-rw-r--r-- | src/lib/pubkey/ecc_key/ecc_key.cpp | 2 | ||||
-rw-r--r-- | src/lib/pubkey/ecc_key/ecc_key.h | 2 | ||||
-rw-r--r-- | src/lib/pubkey/gost_3410/gost_3410.cpp | 2 | ||||
-rw-r--r-- | src/lib/pubkey/gost_3410/gost_3410.h | 2 | ||||
-rw-r--r-- | src/lib/pubkey/mce/mceliece.h | 2 | ||||
-rw-r--r-- | src/lib/pubkey/mce/mceliece_key.cpp | 2 | ||||
-rw-r--r-- | src/lib/pubkey/pk_keys.cpp | 10 | ||||
-rw-r--r-- | src/lib/pubkey/pk_keys.h | 7 | ||||
-rw-r--r-- | src/lib/pubkey/rsa/rsa.cpp | 2 | ||||
-rw-r--r-- | src/lib/pubkey/rsa/rsa.h | 2 | ||||
-rw-r--r-- | src/lib/pubkey/x509_key.cpp | 10 | ||||
-rw-r--r-- | src/lib/pubkey/xmss/xmss_publickey.h | 9 | ||||
-rw-r--r-- | src/lib/pubkey/xmss/xmss_wots_addressed_publickey.h | 4 | ||||
-rw-r--r-- | src/lib/pubkey/xmss/xmss_wots_publickey.h | 4 |
18 files changed, 39 insertions, 29 deletions
diff --git a/src/lib/pubkey/curve25519/curve25519.cpp b/src/lib/pubkey/curve25519/curve25519.cpp index dd97e1f1d..8c2628934 100644 --- a/src/lib/pubkey/curve25519/curve25519.cpp +++ b/src/lib/pubkey/curve25519/curve25519.cpp @@ -58,7 +58,7 @@ Curve25519_PublicKey::Curve25519_PublicKey(const AlgorithmIdentifier&, size_check(m_public.size(), "public key"); } -std::vector<byte> Curve25519_PublicKey::x509_subject_public_key() const +std::vector<byte> Curve25519_PublicKey::public_key_bits() const { return DER_Encoder() .start_cons(SEQUENCE) diff --git a/src/lib/pubkey/curve25519/curve25519.h b/src/lib/pubkey/curve25519/curve25519.h index 40d9d81da..f48bb117d 100644 --- a/src/lib/pubkey/curve25519/curve25519.h +++ b/src/lib/pubkey/curve25519/curve25519.h @@ -25,7 +25,7 @@ class BOTAN_DLL Curve25519_PublicKey : public virtual Public_Key AlgorithmIdentifier algorithm_identifier() const override; - std::vector<byte> x509_subject_public_key() const override; + std::vector<byte> public_key_bits() const override; std::vector<byte> public_value() const { return m_public; } diff --git a/src/lib/pubkey/dl_algo/dl_algo.cpp b/src/lib/pubkey/dl_algo/dl_algo.cpp index f5c6ddabb..8457a61ac 100644 --- a/src/lib/pubkey/dl_algo/dl_algo.cpp +++ b/src/lib/pubkey/dl_algo/dl_algo.cpp @@ -29,7 +29,7 @@ AlgorithmIdentifier DL_Scheme_PublicKey::algorithm_identifier() const m_group.DER_encode(group_format())); } -std::vector<byte> DL_Scheme_PublicKey::x509_subject_public_key() const +std::vector<byte> DL_Scheme_PublicKey::public_key_bits() const { return DER_Encoder().encode(m_y).get_contents_unlocked(); } diff --git a/src/lib/pubkey/dl_algo/dl_algo.h b/src/lib/pubkey/dl_algo/dl_algo.h index 7e90bc3b7..c24c921a8 100644 --- a/src/lib/pubkey/dl_algo/dl_algo.h +++ b/src/lib/pubkey/dl_algo/dl_algo.h @@ -23,7 +23,7 @@ class BOTAN_DLL DL_Scheme_PublicKey : public virtual Public_Key AlgorithmIdentifier algorithm_identifier() const override; - std::vector<byte> x509_subject_public_key() const override; + std::vector<byte> public_key_bits() const override; /** * Get the DL domain parameters of this key. diff --git a/src/lib/pubkey/ecc_key/ecc_key.cpp b/src/lib/pubkey/ecc_key/ecc_key.cpp index ea2bb48e9..95427c487 100644 --- a/src/lib/pubkey/ecc_key/ecc_key.cpp +++ b/src/lib/pubkey/ecc_key/ecc_key.cpp @@ -55,7 +55,7 @@ AlgorithmIdentifier EC_PublicKey::algorithm_identifier() const return AlgorithmIdentifier(get_oid(), DER_domain()); } -std::vector<byte> EC_PublicKey::x509_subject_public_key() const +std::vector<byte> EC_PublicKey::public_key_bits() const { return unlock(EC2OSP(public_point(), PointGFp::COMPRESSED)); } diff --git a/src/lib/pubkey/ecc_key/ecc_key.h b/src/lib/pubkey/ecc_key/ecc_key.h index 375c8e85c..e6e5a3029 100644 --- a/src/lib/pubkey/ecc_key/ecc_key.h +++ b/src/lib/pubkey/ecc_key/ecc_key.h @@ -55,7 +55,7 @@ class BOTAN_DLL EC_PublicKey : public virtual Public_Key AlgorithmIdentifier algorithm_identifier() const override; - std::vector<byte> x509_subject_public_key() const override; + std::vector<byte> public_key_bits() const override; bool check_key(RandomNumberGenerator& rng, bool strong) const override; diff --git a/src/lib/pubkey/gost_3410/gost_3410.cpp b/src/lib/pubkey/gost_3410/gost_3410.cpp index ed01450c8..d10ad0575 100644 --- a/src/lib/pubkey/gost_3410/gost_3410.cpp +++ b/src/lib/pubkey/gost_3410/gost_3410.cpp @@ -15,7 +15,7 @@ namespace Botan { -std::vector<byte> GOST_3410_PublicKey::x509_subject_public_key() const +std::vector<byte> GOST_3410_PublicKey::public_key_bits() const { const BigInt x = public_point().get_affine_x(); const BigInt y = public_point().get_affine_y(); diff --git a/src/lib/pubkey/gost_3410/gost_3410.h b/src/lib/pubkey/gost_3410/gost_3410.h index c844e0fab..a80b41fc7 100644 --- a/src/lib/pubkey/gost_3410/gost_3410.h +++ b/src/lib/pubkey/gost_3410/gost_3410.h @@ -46,7 +46,7 @@ class BOTAN_DLL GOST_3410_PublicKey : public virtual EC_PublicKey AlgorithmIdentifier algorithm_identifier() const override; - std::vector<byte> x509_subject_public_key() const override; + std::vector<byte> public_key_bits() const override; size_t message_parts() const override { return 2; } diff --git a/src/lib/pubkey/mce/mceliece.h b/src/lib/pubkey/mce/mceliece.h index 2c4f38c33..884f40083 100644 --- a/src/lib/pubkey/mce/mceliece.h +++ b/src/lib/pubkey/mce/mceliece.h @@ -40,7 +40,7 @@ class BOTAN_DLL McEliece_PublicKey : public virtual Public_Key size_t key_length() const override; size_t estimated_strength() const override; - std::vector<byte> x509_subject_public_key() const override; + std::vector<byte> public_key_bits() const override; bool check_key(RandomNumberGenerator&, bool) const override { return true; } diff --git a/src/lib/pubkey/mce/mceliece_key.cpp b/src/lib/pubkey/mce/mceliece_key.cpp index 93ce41fb2..502665820 100644 --- a/src/lib/pubkey/mce/mceliece_key.cpp +++ b/src/lib/pubkey/mce/mceliece_key.cpp @@ -69,7 +69,7 @@ AlgorithmIdentifier McEliece_PublicKey::algorithm_identifier() const return AlgorithmIdentifier(get_oid(), std::vector<byte>()); } -std::vector<byte> McEliece_PublicKey::x509_subject_public_key() const +std::vector<byte> McEliece_PublicKey::public_key_bits() const { return DER_Encoder() .start_cons(SEQUENCE) diff --git a/src/lib/pubkey/pk_keys.cpp b/src/lib/pubkey/pk_keys.cpp index 3b843cea3..d21ff484a 100644 --- a/src/lib/pubkey/pk_keys.cpp +++ b/src/lib/pubkey/pk_keys.cpp @@ -14,6 +14,16 @@ namespace Botan { +std::vector<byte> Public_Key::subject_public_key() const + { + return DER_Encoder() + .start_cons(SEQUENCE) + .encode(algorithm_identifier()) + .encode(public_key_bits(), BIT_STRING) + .end_cons() + .get_contents_unlocked(); + } + /* * Default OID access */ diff --git a/src/lib/pubkey/pk_keys.h b/src/lib/pubkey/pk_keys.h index 613fbb7dd..6a5f4fc64 100644 --- a/src/lib/pubkey/pk_keys.h +++ b/src/lib/pubkey/pk_keys.h @@ -74,9 +74,14 @@ class BOTAN_DLL Public_Key virtual AlgorithmIdentifier algorithm_identifier() const = 0; /** + * @return BER encoded public key bits + */ + virtual std::vector<byte> public_key_bits() const = 0; + + /** * @return X.509 subject key encoding for this key object */ - virtual std::vector<byte> x509_subject_public_key() const = 0; + std::vector<byte> subject_public_key() const; // Internal or non-public declarations follow diff --git a/src/lib/pubkey/rsa/rsa.cpp b/src/lib/pubkey/rsa/rsa.cpp index 4302aa88a..039627806 100644 --- a/src/lib/pubkey/rsa/rsa.cpp +++ b/src/lib/pubkey/rsa/rsa.cpp @@ -41,7 +41,7 @@ AlgorithmIdentifier RSA_PublicKey::algorithm_identifier() const AlgorithmIdentifier::USE_NULL_PARAM); } -std::vector<byte> RSA_PublicKey::x509_subject_public_key() const +std::vector<byte> RSA_PublicKey::public_key_bits() const { return DER_Encoder() .start_cons(SEQUENCE) diff --git a/src/lib/pubkey/rsa/rsa.h b/src/lib/pubkey/rsa/rsa.h index f576a5f07..83b43a9ad 100644 --- a/src/lib/pubkey/rsa/rsa.h +++ b/src/lib/pubkey/rsa/rsa.h @@ -41,7 +41,7 @@ class BOTAN_DLL RSA_PublicKey : public virtual Public_Key AlgorithmIdentifier algorithm_identifier() const override; - std::vector<byte> x509_subject_public_key() const override; + std::vector<byte> public_key_bits() const override; /** * @return public modulus diff --git a/src/lib/pubkey/x509_key.cpp b/src/lib/pubkey/x509_key.cpp index f4cfe805e..f1db29bc4 100644 --- a/src/lib/pubkey/x509_key.cpp +++ b/src/lib/pubkey/x509_key.cpp @@ -18,12 +18,8 @@ namespace X509 { std::vector<byte> BER_encode(const Public_Key& key) { - return DER_Encoder() - .start_cons(SEQUENCE) - .encode(key.algorithm_identifier()) - .encode(key.x509_subject_public_key(), BIT_STRING) - .end_cons() - .get_contents_unlocked(); + // keeping it around for compat + return key.subject_public_key(); } /* @@ -31,7 +27,7 @@ std::vector<byte> BER_encode(const Public_Key& key) */ std::string PEM_encode(const Public_Key& key) { - return PEM_Code::encode(X509::BER_encode(key), + return PEM_Code::encode(key.subject_public_key(), "PUBLIC KEY"); } diff --git a/src/lib/pubkey/xmss/xmss_publickey.h b/src/lib/pubkey/xmss/xmss_publickey.h index b8aa8d920..23c8032c2 100644 --- a/src/lib/pubkey/xmss/xmss_publickey.h +++ b/src/lib/pubkey/xmss/xmss_publickey.h @@ -216,13 +216,12 @@ class BOTAN_DLL XMSS_PublicKey : public virtual Public_Key } /** - * Currently x509 is not suppoerted for XMSS. x509_subject_public_key() - * returns a raw byte sequence as defined in [1]. This method acts as - * alias for raw_public_key(). + * Returns a raw byte sequence as defined in [1]. + * This method acts as an alias for raw_public_key(). * - * @return raw non x509 compliant public key. + * @return raw public key bits. **/ - virtual std::vector<byte> x509_subject_public_key() const override + virtual std::vector<byte> public_key_bits() const override { return raw_public_key(); } diff --git a/src/lib/pubkey/xmss/xmss_wots_addressed_publickey.h b/src/lib/pubkey/xmss/xmss_wots_addressed_publickey.h index a07b0b803..74e686f9f 100644 --- a/src/lib/pubkey/xmss/xmss_wots_addressed_publickey.h +++ b/src/lib/pubkey/xmss/xmss_wots_addressed_publickey.h @@ -82,9 +82,9 @@ class XMSS_WOTS_Addressed_PublicKey : public virtual Public_Key return m_pub_key.estimated_strength(); } - virtual std::vector<byte> x509_subject_public_key() const override + virtual std::vector<byte> public_key_bits() const override { - return m_pub_key.x509_subject_public_key(); + return m_pub_key.public_key_bits(); } protected: diff --git a/src/lib/pubkey/xmss/xmss_wots_publickey.h b/src/lib/pubkey/xmss/xmss_wots_publickey.h index afb0ac847..4f414de27 100644 --- a/src/lib/pubkey/xmss/xmss_wots_publickey.h +++ b/src/lib/pubkey/xmss/xmss_wots_publickey.h @@ -261,9 +261,9 @@ class BOTAN_DLL XMSS_WOTS_PublicKey : virtual public Public_Key return m_wots_params.estimated_strength(); } - virtual std::vector<byte> x509_subject_public_key() const override + virtual std::vector<byte> public_key_bits() const override { - throw Not_Implemented("No x509 key format defined for XMSS-WOTS."); + throw Not_Implemented("No key format defined for XMSS-WOTS"); } bool operator==(const XMSS_WOTS_PublicKey& key) |