From ea0f46dfcab59938fc863ca8d01552392c3c5a34 Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Sat, 10 Mar 2018 09:46:52 -0500 Subject: Default to encoding ECC public keys as uncompressed. GH #1480 --- src/lib/pubkey/ecc_key/ecc_key.cpp | 13 ++++++++++++- src/lib/pubkey/ecc_key/ecc_key.h | 14 ++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) (limited to 'src/lib') diff --git a/src/lib/pubkey/ecc_key/ecc_key.cpp b/src/lib/pubkey/ecc_key/ecc_key.cpp index 4b591ff56..07122964e 100644 --- a/src/lib/pubkey/ecc_key/ecc_key.cpp +++ b/src/lib/pubkey/ecc_key/ecc_key.cpp @@ -68,7 +68,18 @@ AlgorithmIdentifier EC_PublicKey::algorithm_identifier() const std::vector EC_PublicKey::public_key_bits() const { - return unlock(EC2OSP(public_point(), PointGFp::COMPRESSED)); + //return public_point().encode(point_format()); + return unlock(EC2OSP(public_point(), point_format())); + } + +void EC_PublicKey::set_point_encoding(PointGFp::Compression_Type enc) + { + if(enc != PointGFp::COMPRESSED && + enc != PointGFp::UNCOMPRESSED && + enc != PointGFp::HYBRID) + throw Invalid_Argument("Invalid point encoding for EC_PublicKey"); + + m_point_encoding = enc; } void EC_PublicKey::set_parameter_encoding(EC_Group_Encoding form) diff --git a/src/lib/pubkey/ecc_key/ecc_key.h b/src/lib/pubkey/ecc_key/ecc_key.h index 427be56ef..4e4e623b2 100644 --- a/src/lib/pubkey/ecc_key/ecc_key.h +++ b/src/lib/pubkey/ecc_key/ecc_key.h @@ -77,6 +77,12 @@ class BOTAN_PUBLIC_API(2,0) EC_PublicKey : public virtual Public_Key */ void set_parameter_encoding(EC_Group_Encoding enc); + /** + * Set the point encoding method to be used when encoding this key. + * @param enc the encoding to use + */ + void set_point_encoding(PointGFp::Compression_Type enc); + /** * Return the DER encoding of this keys domain in whatever format * is preset for this particular key @@ -91,6 +97,13 @@ class BOTAN_PUBLIC_API(2,0) EC_PublicKey : public virtual Public_Key EC_Group_Encoding domain_format() const { return m_domain_encoding; } + /** + * Get the point encoding method to be used when encoding this key. + * @result the encoding to use + */ + PointGFp::Compression_Type point_format() const + { return m_point_encoding; } + size_t key_length() const override; size_t estimated_strength() const override; @@ -101,6 +114,7 @@ class BOTAN_PUBLIC_API(2,0) EC_PublicKey : public virtual Public_Key EC_Group m_domain_params; PointGFp m_public_key; EC_Group_Encoding m_domain_encoding; + PointGFp::Compression_Type m_point_encoding = PointGFp::UNCOMPRESSED; }; /** -- cgit v1.2.3