Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

ecc_key.h
Go to the documentation of this file.
1 /*
2 * ECDSA
3 * (C) 2007 Falko Strenzke, FlexSecure GmbH
4 * Manuel Hartl, FlexSecure GmbH
5 * (C) 2008-2010 Jack Lloyd
6 *
7 * Botan is released under the Simplified BSD License (see license.txt)
8 */
9
10 #ifndef BOTAN_ECC_PUBLIC_KEY_BASE_H__
11 #define BOTAN_ECC_PUBLIC_KEY_BASE_H__
12
13 #include <botan/ec_group.h>
14 #include <botan/pk_keys.h>
15 #include <botan/x509_key.h>
16
17 namespace Botan {
18
19 /**
20 * This class represents abstract ECC public keys. When encoding a key
21 * via an encoder that can be accessed via the corresponding member
22 * functions, the key will decide upon its internally stored encoding
23 * information whether to encode itself with or without domain
24 * parameters, or using the domain parameter oid. Furthermore, a public
25 * key without domain parameters can be decoded. In that case, it
26 * cannot be used for verification until its domain parameters are set
27 * by calling the corresponding member function.
28 */
29 class BOTAN_DLL EC_PublicKey : public virtual Public_Key
30 {
31 public:
32 /**
33 * Create a public key.
34 * @param dom_par EC domain parameters
35 * @param pub_point public point on the curve
36 */
37 EC_PublicKey(const EC_Group& dom_par,
38 const PointGFp& pub_point);
39
40 /**
41 * Load a public key.
42 * @param alg_id the X.509 algorithm identifier
43 * @param key_bits DER encoded public key bits
44 */
45 EC_PublicKey(const AlgorithmIdentifier& alg_id,
46 const std::vector<uint8_t>& key_bits);
47
48 EC_PublicKey(const EC_PublicKey& other) = default;
49 EC_PublicKey& operator=(const EC_PublicKey& other) = default;
50 virtual ~EC_PublicKey() = default;
51
52 /**
53 * Get the public point of this key.
54 * @throw Invalid_State is thrown if the
55 * domain parameters of this point are not set
56 * @result the public point of this key
57 */
58 const PointGFp& public_point() const { return m_public_key; }
59
60 AlgorithmIdentifier algorithm_identifier() const override;
61
62 std::vector<uint8_t> public_key_bits() const override;
63
64 bool check_key(RandomNumberGenerator& rng,
65 bool strong) const override;
66
67 /**
68 * Get the domain parameters of this key.
69 * @throw Invalid_State is thrown if the
70 * domain parameters of this point are not set
71 * @result the domain parameters of this key
72 */
73 const EC_Group& domain() const { return m_domain_params; }
74
75 /**
76 * Set the domain parameter encoding to be used when encoding this key.
77 * @param enc the encoding to use
78 */
79 void set_parameter_encoding(EC_Group_Encoding enc);
80
81 /**
82 * Return the DER encoding of this keys domain in whatever format
83 * is preset for this particular key
84 */
85 std::vector<uint8_t> DER_domain() const
86 { return domain().DER_encode(domain_format()); }
87
88 /**
89 * Get the domain parameter encoding to be used when encoding this key.
90 * @result the encoding to use
91 */
92 EC_Group_Encoding domain_format() const
93 { return m_domain_encoding; }
94
95 size_t key_length() const override;
96 size_t estimated_strength() const override;
97
98 protected:
99 EC_PublicKey() : m_domain_params{}, m_public_key{}, m_domain_encoding(EC_DOMPAR_ENC_EXPLICIT)
100 {}
101
102 EC_Group m_domain_params;
103 PointGFp m_public_key;
104 EC_Group_Encoding m_domain_encoding;
105 };
106
107 /**
108 * This abstract class represents ECC private keys
109 */
110 class BOTAN_DLL EC_PrivateKey : public virtual EC_PublicKey,
111 public virtual Private_Key
112 {
113 public:
114 /*
115 * If x=0, creates a new private key in the domain
116 * using the given rng. If with_modular_inverse is set,
117 * the public key will be calculated by multiplying
118 * the base point with the modular inverse of
119 * x (as in ECGDSA and ECKCDSA), otherwise by
120 * multiplying directly with x (as in ECDSA).
121 */
122 EC_PrivateKey(RandomNumberGenerator& rng,
123 const EC_Group& domain,
124 const BigInt& x,
125 bool with_modular_inverse=false);
126
127 /*
128 * Creates a new private key object from the
129 * ECPrivateKey structure given in key_bits.
130 * If with_modular_inverse is set,
131 * the public key will be calculated by multiplying
132 * the base point with the modular inverse of
133 * x (as in ECGDSA and ECKCDSA), otherwise by
134 * multiplying directly with x (as in ECDSA).
135 */
136 EC_PrivateKey(const AlgorithmIdentifier& alg_id,
137 const secure_vector<uint8_t>& key_bits,
138 bool with_modular_inverse=false);
139
140 secure_vector<uint8_t> private_key_bits() const override;
141
142 /**
143 * Get the private key value of this key object.
144 * @result the private key value of this key object
145 */
146 const BigInt& private_value() const;
147
148 EC_PrivateKey(const EC_PrivateKey& other) = default;
149 EC_PrivateKey& operator=(const EC_PrivateKey& other) = default;
150 ~EC_PrivateKey() = default;
151 protected:
152 EC_PrivateKey() = default;
153
154 BigInt m_private_key;
155 };
156
157 }
158
159 #endif
Botan::EC_PrivateKey::m_private_key
BigInt m_private_key
Definition: ecc_key.h:154
Botan::BigInt
Definition: bigint.h:23
Botan::EC_DOMPAR_ENC_EXPLICIT
Definition: ec_group.h:23
Botan::EC_PublicKey::domain
const EC_Group & domain() const
Definition: ecc_key.h:73
Botan::PointGFp
Definition: point_gfp.h:41
Botan::RandomNumberGenerator
Definition: rng.h:25
Botan::Private_Key
Definition: pk_keys.h:166
Botan::EC_PublicKey::m_public_key
PointGFp m_public_key
Definition: ecc_key.h:103
Botan::EC_PublicKey
Definition: ecc_key.h:29
Botan::EC_PrivateKey
Definition: ecc_key.h:110
Botan::EC_PublicKey::public_point
const PointGFp & public_point() const
Definition: ecc_key.h:58
Botan::secure_vector
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:121
Botan::EC_PublicKey::DER_domain
std::vector< uint8_t > DER_domain() const
Definition: ecc_key.h:85
Botan
Definition: alg_id.cpp:13
Botan::EC_Group
Definition: ec_group.h:31
Botan::Public_Key
Definition: pk_keys.h:24
Botan::EC_PublicKey::EC_PublicKey
EC_PublicKey()
Definition: ecc_key.h:99
Botan::EC_Group_Encoding
EC_Group_Encoding
Definition: ec_group.h:22
Botan::AlgorithmIdentifier
Definition: alg_id.h:20
Botan::EC_PublicKey::m_domain_params
EC_Group m_domain_params
Definition: ecc_key.h:102
Botan::EC_PublicKey::domain_format
EC_Group_Encoding domain_format() const
Definition: ecc_key.h:92
Botan::EC_PublicKey::m_domain_encoding
EC_Group_Encoding m_domain_encoding
Definition: ecc_key.h:104