Botan  1.11.11
ecdsa.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 * Distributed under the terms of the Botan license
8 */
9 
10 #ifndef BOTAN_ECDSA_KEY_H__
11 #define BOTAN_ECDSA_KEY_H__
12 
13 #include <botan/ecc_key.h>
14 #include <botan/reducer.h>
15 #include <botan/pk_ops.h>
16 
17 namespace Botan {
18 
19 /**
20 * This class represents ECDSA Public Keys.
21 */
22 class BOTAN_DLL ECDSA_PublicKey : public virtual EC_PublicKey
23  {
24  public:
25 
26  /**
27  * Construct a public key from a given public point.
28  * @param dom_par the domain parameters associated with this key
29  * @param public_point the public point defining this key
30  */
31  ECDSA_PublicKey(const EC_Group& dom_par,
32  const PointGFp& public_point) :
33  EC_PublicKey(dom_par, public_point) {}
34 
36  const secure_vector<byte>& key_bits) :
37  EC_PublicKey(alg_id, key_bits) {}
38 
39  /**
40  * Get this keys algorithm name.
41  * @result this keys algorithm name ("ECDSA")
42  */
43  std::string algo_name() const { return "ECDSA"; }
44 
45  /**
46  * Get the maximum number of bits allowed to be fed to this key.
47  * This is the bitlength of the order of the base point.
48  * @result the maximum number of input bits
49  */
50  size_t max_input_bits() const { return domain().get_order().bits(); }
51 
52  size_t message_parts() const { return 2; }
53 
54  size_t message_part_size() const
55  { return domain().get_order().bytes(); }
56 
57  protected:
59  };
60 
61 /**
62 * This class represents ECDSA Private Keys
63 */
64 class BOTAN_DLL ECDSA_PrivateKey : public ECDSA_PublicKey,
65  public EC_PrivateKey
66  {
67  public:
68 
69  /**
70  * Load a private key
71  * @param alg_id the X.509 algorithm identifier
72  * @param key_bits PKCS #8 structure
73  */
75  const secure_vector<byte>& key_bits) :
76  EC_PrivateKey(alg_id, key_bits) {}
77 
78  /**
79  * Generate a new private key
80  * @param rng a random number generator
81  * @param domain parameters to used for this key
82  * @param x the private key (if zero, generate a ney random key)
83  */
85  const EC_Group& domain,
86  const BigInt& x = 0) :
87  EC_PrivateKey(rng, domain, x) {}
88 
89  bool check_key(RandomNumberGenerator& rng, bool) const;
90  };
91 
92 /**
93 * ECDSA signature operation
94 */
96  {
97  public:
99  const std::string& hash);
100 
101  secure_vector<byte> sign(const byte msg[], size_t msg_len,
102  RandomNumberGenerator& rng);
103 
104  size_t message_parts() const { return 2; }
105  size_t message_part_size() const { return order.bytes(); }
106  size_t max_input_bits() const { return order.bits(); }
107 
108  private:
109  const PointGFp& base_point;
110  const BigInt& order;
111  const BigInt& x;
112  Modular_Reducer mod_order;
113  std::string m_hash;
114  };
115 
116 /**
117 * ECDSA verification operation
118 */
120  {
121  public:
123 
124  size_t message_parts() const { return 2; }
125  size_t message_part_size() const { return order.bytes(); }
126  size_t max_input_bits() const { return order.bits(); }
127 
128  bool with_recovery() const { return false; }
129 
130  bool verify(const byte msg[], size_t msg_len,
131  const byte sig[], size_t sig_len);
132  private:
133  const PointGFp& base_point;
134  const PointGFp& public_point;
135  const BigInt& order;
136  };
137 
138 }
139 
140 #endif
ECDSA_PublicKey(const AlgorithmIdentifier &alg_id, const secure_vector< byte > &key_bits)
Definition: ecdsa.h:35
size_t message_parts() const
Definition: ecdsa.h:104
size_t message_part_size() const
Definition: ecdsa.h:54
size_t max_input_bits() const
Definition: ecdsa.h:106
size_t message_part_size() const
Definition: ecdsa.h:105
size_t message_part_size() const
Definition: ecdsa.h:125
size_t max_input_bits() const
Definition: ecdsa.h:50
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:92
uint8_t byte
Definition: types.h:30
Definition: buf_comp.h:15
size_t message_parts() const
Definition: ecdsa.h:124
std::string algo_name() const
Definition: ecdsa.h:43
ECDSA_PrivateKey(const AlgorithmIdentifier &alg_id, const secure_vector< byte > &key_bits)
Definition: ecdsa.h:74
size_t message_parts() const
Definition: ecdsa.h:52
ECDSA_PublicKey(const EC_Group &dom_par, const PointGFp &public_point)
Definition: ecdsa.h:31
ECDSA_PrivateKey(RandomNumberGenerator &rng, const EC_Group &domain, const BigInt &x=0)
Definition: ecdsa.h:84
size_t max_input_bits() const
Definition: ecdsa.h:126