Botan 1.10.17
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
17namespace Botan {
18
19/**
20* This class represents ECDSA Public Keys.
21*/
22class 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 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:
59 };
60
61/**
62* This class represents ECDSA Private Keys
63*/
64class 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 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 */
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
100 SecureVector<byte> sign(const byte msg[], size_t msg_len,
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*/
118 {
119 public:
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
ECDSA_PrivateKey(const AlgorithmIdentifier &alg_id, const MemoryRegion< byte > &key_bits)
Definition ecdsa.h:74
ECDSA_PrivateKey(RandomNumberGenerator &rng, const EC_Group &domain, const BigInt &x=0)
Definition ecdsa.h:84
ECDSA_PublicKey(const EC_Group &dom_par, const PointGFp &public_point)
Definition ecdsa.h:31
size_t max_input_bits() const
Definition ecdsa.h:50
ECDSA_PublicKey(const AlgorithmIdentifier &alg_id, const MemoryRegion< byte > &key_bits)
Definition ecdsa.h:35
size_t message_part_size() const
Definition ecdsa.h:54
std::string algo_name() const
Definition ecdsa.h:43
size_t message_parts() const
Definition ecdsa.h:52
SecureVector< byte > sign(const byte msg[], size_t msg_len, RandomNumberGenerator &rng)
Definition ecdsa.cpp:36
size_t message_parts() const
Definition ecdsa.h:103
size_t max_input_bits() const
Definition ecdsa.h:105
size_t message_part_size() const
Definition ecdsa.h:104
ECDSA_Signature_Operation(const ECDSA_PrivateKey &ecdsa)
Definition ecdsa.cpp:27
ECDSA_Verification_Operation(const ECDSA_PublicKey &ecdsa)
Definition ecdsa.cpp:65
EC_PrivateKey(RandomNumberGenerator &rng, const EC_Group &domain, const BigInt &private_key)
Definition ecc_key.cpp:81
const EC_Group & domain() const
Definition ecc_key.h:60
EC_PublicKey(const EC_Group &dom_par, const PointGFp &pub_point)
Definition ecc_key.cpp:21
const PointGFp & public_point() const
Definition ecc_key.h:45