Botan: src/pubkey/ecdsa/ecdsa.h Source File

Botan 1.10.16

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
35 ECDSA_PublicKey(const AlgorithmIdentifier& alg_id,
36 const MemoryRegion<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:
58 ECDSA_PublicKey() {}
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 */
74 ECDSA_PrivateKey(const AlgorithmIdentifier& alg_id,
75 const MemoryRegion<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 */
84 ECDSA_PrivateKey(RandomNumberGenerator& rng,
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 */
95 class BOTAN_DLL ECDSA_Signature_Operation : public PK_Ops::Signature
96 {
97 public:
98 ECDSA_Signature_Operation(const ECDSA_PrivateKey& ecdsa);
99
100 SecureVector<byte> sign(const byte msg[], size_t msg_len,
101 RandomNumberGenerator& rng);
102
103 size_t message_parts() const { return 2; }
104 size_t message_part_size() const { return order.bytes(); }
105 size_t max_input_bits() const { return order.bits(); }
106
107 private:
108 const PointGFp& base_point;
109 const BigInt& order;
110 const BigInt& x;
111 Modular_Reducer mod_order;
112 };
113
114 /**
115 * ECDSA verification operation
116 */
117 class BOTAN_DLL ECDSA_Verification_Operation : public PK_Ops::Verification
118 {
119 public:
120 ECDSA_Verification_Operation(const ECDSA_PublicKey& ecdsa);
121
122 size_t message_parts() const { return 2; }
123 size_t message_part_size() const { return order.bytes(); }
124 size_t max_input_bits() const { return order.bits(); }
125
126 bool with_recovery() const { return false; }
127
128 bool verify(const byte msg[], size_t msg_len,
129 const byte sig[], size_t sig_len);
130 private:
131 const PointGFp& base_point;
132 const PointGFp& public_point;
133 const BigInt& order;
134 };
135
136 }
137
138 #endif
Botan::ECDSA_Signature_Operation::max_input_bits
size_t max_input_bits() const
Definition: ecdsa.h:105
Botan::BigInt
Definition: bigint.h:22
Botan::PointGFp
Definition: point_gfp.h:41
Botan::RandomNumberGenerator
Definition: rng.h:20
Botan::ECDSA_PublicKey::max_input_bits
size_t max_input_bits() const
Definition: ecdsa.h:50
Botan::ECDSA_PublicKey::ECDSA_PublicKey
ECDSA_PublicKey()
Definition: ecdsa.h:58
Botan::ECDSA_PrivateKey::ECDSA_PrivateKey
ECDSA_PrivateKey(const AlgorithmIdentifier &alg_id, const MemoryRegion< byte > &key_bits)
Definition: ecdsa.h:74
Botan::PK_Ops::Signature
Definition: pk_ops.h:49
Botan::EC_PublicKey
Definition: ecc_key.h:30
Botan::ECDSA_Signature_Operation::message_parts
size_t message_parts() const
Definition: ecdsa.h:103
Botan::EC_PrivateKey
Definition: ecc_key.h:92
Botan::byte
unsigned char byte
Definition: types.h:22
Botan::ECDSA_Verification_Operation::with_recovery
bool with_recovery() const
Definition: ecdsa.h:126
Botan::ECDSA_Signature_Operation
Definition: ecdsa.h:95
Botan::ECDSA_PublicKey::message_part_size
size_t message_part_size() const
Definition: ecdsa.h:54
Botan::ECDSA_Signature_Operation::message_part_size
size_t message_part_size() const
Definition: ecdsa.h:104
Botan::ECDSA_PublicKey
Definition: ecdsa.h:22
Botan::ECDSA_PublicKey::ECDSA_PublicKey
ECDSA_PublicKey(const AlgorithmIdentifier &alg_id, const MemoryRegion< byte > &key_bits)
Definition: ecdsa.h:35
Botan::MemoryRegion< byte >
Botan
Definition: algo_base.h:14
Botan::EC_Group
Definition: ec_group.h:31
Botan::ECDSA_Verification_Operation::message_part_size
size_t message_part_size() const
Definition: ecdsa.h:123
Botan::ECDSA_PublicKey::message_parts
size_t message_parts() const
Definition: ecdsa.h:52
Botan::ECDSA_Verification_Operation::max_input_bits
size_t max_input_bits() const
Definition: ecdsa.h:124
Botan::AlgorithmIdentifier
Definition: alg_id.h:20
Botan::ECDSA_Verification_Operation::message_parts
size_t message_parts() const
Definition: ecdsa.h:122
Botan::ECDSA_PrivateKey
Definition: ecdsa.h:64
Botan::ECDSA_PublicKey::ECDSA_PublicKey
ECDSA_PublicKey(const EC_Group &dom_par, const PointGFp &public_point)
Definition: ecdsa.h:31
Botan::SecureVector< byte >
Botan::ECDSA_PrivateKey::ECDSA_PrivateKey
ECDSA_PrivateKey(RandomNumberGenerator &rng, const EC_Group &domain, const BigInt &x=0)
Definition: ecdsa.h:84
Botan::ECDSA_Verification_Operation
Definition: ecdsa.h:117
Botan::ECDSA_PublicKey::algo_name
std::string algo_name() const
Definition: ecdsa.h:43
Botan::Modular_Reducer
Definition: reducer.h:18
Botan::PK_Ops::Verification
Definition: pk_ops.h:85