Botan 2.19.5 Crypto and TLS for C&

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