Botan  1.11.15
src/lib/pubkey/ecc_key/ecc_key.h
Go to the documentation of this file.
00001 /*
00002 * ECDSA
00003 * (C) 2007 Falko Strenzke, FlexSecure GmbH
00004 *          Manuel Hartl, FlexSecure GmbH
00005 * (C) 2008-2010 Jack Lloyd
00006 *
00007 * Botan is released under the Simplified BSD License (see license.txt)
00008 */
00009 
00010 #ifndef BOTAN_ECC_PUBLIC_KEY_BASE_H__
00011 #define BOTAN_ECC_PUBLIC_KEY_BASE_H__
00012 
00013 #include <botan/ec_group.h>
00014 #include <botan/pk_keys.h>
00015 #include <botan/x509_key.h>
00016 #include <botan/pkcs8.h>
00017 
00018 namespace Botan {
00019 
00020 /**
00021 * This class represents abstract ECC public keys. When encoding a key
00022 * via an encoder that can be accessed via the corresponding member
00023 * functions, the key will decide upon its internally stored encoding
00024 * information whether to encode itself with or without domain
00025 * parameters, or using the domain parameter oid. Furthermore, a public
00026 * key without domain parameters can be decoded. In that case, it
00027 * cannot be used for verification until its domain parameters are set
00028 * by calling the corresponding member function.
00029 */
00030 class BOTAN_DLL EC_PublicKey : public virtual Public_Key
00031    {
00032    public:
00033       EC_PublicKey(const EC_Group& dom_par,
00034                    const PointGFp& pub_point);
00035 
00036       EC_PublicKey(const AlgorithmIdentifier& alg_id,
00037                    const secure_vector<byte>& key_bits);
00038 
00039       /**
00040       * Get the public point of this key.
00041       * @throw Invalid_State is thrown if the
00042       * domain parameters of this point are not set
00043       * @result the public point of this key
00044       */
00045       const PointGFp& public_point() const { return public_key; }
00046 
00047       AlgorithmIdentifier algorithm_identifier() const;
00048 
00049       std::vector<byte> x509_subject_public_key() const;
00050 
00051       bool check_key(RandomNumberGenerator& rng,
00052                      bool strong) const;
00053 
00054       /**
00055       * Get the domain parameters of this key.
00056       * @throw Invalid_State is thrown if the
00057       * domain parameters of this point are not set
00058       * @result the domain parameters of this key
00059       */
00060       const EC_Group& domain() const { return domain_params; }
00061 
00062       /**
00063       * Set the domain parameter encoding to be used when encoding this key.
00064       * @param enc the encoding to use
00065       */
00066       void set_parameter_encoding(EC_Group_Encoding enc);
00067 
00068       /**
00069       * Return the DER encoding of this keys domain in whatever format
00070       * is preset for this particular key
00071       */
00072       std::vector<byte> DER_domain() const
00073          { return domain().DER_encode(domain_format()); }
00074 
00075       /**
00076       * Get the domain parameter encoding to be used when encoding this key.
00077       * @result the encoding to use
00078       */
00079       EC_Group_Encoding domain_format() const
00080          { return domain_encoding; }
00081 
00082       size_t estimated_strength() const override;
00083 
00084    protected:
00085       EC_PublicKey() : domain_encoding(EC_DOMPAR_ENC_EXPLICIT) {}
00086 
00087       EC_Group domain_params;
00088       PointGFp public_key;
00089       EC_Group_Encoding domain_encoding;
00090    };
00091 
00092 /**
00093 * This abstract class represents ECC private keys
00094 */
00095 class BOTAN_DLL EC_PrivateKey : public virtual EC_PublicKey,
00096                                 public virtual Private_Key
00097    {
00098    public:
00099      EC_PrivateKey(RandomNumberGenerator& rng,
00100                    const EC_Group& domain,
00101                    const BigInt& private_key);
00102 
00103       EC_PrivateKey(const AlgorithmIdentifier& alg_id,
00104                     const secure_vector<byte>& key_bits);
00105 
00106       secure_vector<byte> pkcs8_private_key() const;
00107 
00108       /**
00109       * Get the private key value of this key object.
00110       * @result the private key value of this key object
00111       */
00112       const BigInt& private_value() const;
00113    protected:
00114       EC_PrivateKey() {}
00115 
00116       BigInt private_key;
00117    };
00118 
00119 }
00120 
00121 #endif