Botan
1.11.4
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
src
pubkey
ecdsa
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
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
:
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
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
*/
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
secure_vector<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
Generated on Wed May 1 2013 08:42:16 for Botan by
1.8.3.1