diff options
author | lloyd <[email protected]> | 2010-03-01 22:53:42 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-03-01 22:53:42 +0000 |
commit | b789c87b7c96dbdb00839996c9603a3f0921b25b (patch) | |
tree | 63b10b4ea832d624908006e936e3fc5ba8311625 /src/pubkey/ec_dompar/ec_dompar.h | |
parent | 6646a0577a337fa054aea1153dc39af419a6b1b4 (diff) |
Clean up EC_Domain_Params
Diffstat (limited to 'src/pubkey/ec_dompar/ec_dompar.h')
-rw-r--r-- | src/pubkey/ec_dompar/ec_dompar.h | 81 |
1 files changed, 44 insertions, 37 deletions
diff --git a/src/pubkey/ec_dompar/ec_dompar.h b/src/pubkey/ec_dompar/ec_dompar.h index f5f573ba9..cc55aa4df 100644 --- a/src/pubkey/ec_dompar/ec_dompar.h +++ b/src/pubkey/ec_dompar/ec_dompar.h @@ -2,7 +2,7 @@ * ECC Domain Parameters * * (C) 2007 Falko Strenzke, FlexSecure GmbH -* 2008 Jack Lloyd +* 2008-2010 Jack Lloyd * * Distributed under the terms of the Botan license */ @@ -22,10 +22,15 @@ namespace Botan { /** * This class represents elliptic curce domain parameters */ +enum EC_Domain_Params_Encoding { + EC_DOMPAR_ENC_EXPLICIT = 0, + EC_DOMPAR_ENC_IMPLICITCA = 1, + EC_DOMPAR_ENC_OID = 2 +}; + class BOTAN_DLL EC_Domain_Params { public: - /** * Construct Domain paramers from specified parameters * @param curve elliptic curve @@ -36,78 +41,80 @@ class BOTAN_DLL EC_Domain_Params EC_Domain_Params(const CurveGFp& curve, const PointGFp& base_point, const BigInt& order, - const BigInt& cofactor); + const BigInt& cofactor) : + curve(curve), + base_point(base_point), + order(order), + cofactor(cofactor), + oid("") + {} + + /** + * Decode a BER encoded ECC domain parameter set + * @param ber_encoding the bytes of the BER encoding + */ + EC_Domain_Params(const MemoryRegion<byte>& ber_encoding); + + /** + * Create the DER encoding of this domain + * @param form of encoding to use + * @returns bytes encododed as DER + */ + SecureVector<byte> DER_encode(EC_Domain_Params_Encoding form) const; /** * Return domain parameter curve * @result domain parameter curve */ - const CurveGFp& get_curve() const - { - return m_curve; - } + const CurveGFp& get_curve() const { return curve; } /** * Return domain parameter curve * @result domain parameter curve */ - const PointGFp& get_base_point() const - { - return m_base_point; - } + const PointGFp& get_base_point() const { return base_point; } /** * Return the order of the base point * @result order of the base point */ - const BigInt& get_order() const - { - return m_order; - } + const BigInt& get_order() const { return order; } /** * Return the cofactor * @result the cofactor */ - const BigInt& get_cofactor() const - { - return m_cofactor; - } + const BigInt& get_cofactor() const { return cofactor; } /** * Return the OID of these domain parameters * @result the OID */ - std::string get_oid() const { return m_oid; } + std::string get_oid() const { return oid; } + + bool operator==(const EC_Domain_Params& other) const + { + return ((get_curve() == other.get_curve()) && + (get_base_point() == other.get_base_point()) && + (get_order() == other.get_order()) && + (get_cofactor() == other.get_cofactor())); + } private: friend EC_Domain_Params get_EC_Dom_Pars_by_oid(std::string oid); - CurveGFp m_curve; - PointGFp m_base_point; - BigInt m_order; - BigInt m_cofactor; - std::string m_oid; + CurveGFp curve; + PointGFp base_point; + BigInt order, cofactor; + std::string oid; }; -bool BOTAN_DLL operator==(EC_Domain_Params const& lhs, - EC_Domain_Params const& rhs); - inline bool operator!=(const EC_Domain_Params& lhs, const EC_Domain_Params& rhs) { return !(lhs == rhs); } -enum EC_dompar_enc { ENC_EXPLICIT = 0, ENC_IMPLICITCA = 1, ENC_OID = 2 }; - -SecureVector<byte> -BOTAN_DLL encode_der_ec_dompar(EC_Domain_Params const& dom_pars, - EC_dompar_enc enc_type); - -EC_Domain_Params -BOTAN_DLL decode_ber_ec_dompar(SecureVector<byte> const& encoded); - /** * Factory function, the only way to obtain EC domain parameters with * an OID. The demanded OID has to be registered in the InSiTo |