Botan  2.11.0
Crypto and TLS for C++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 * Botan is released under the Simplified BSD License (see license.txt)
8 */
9 
10 #ifndef BOTAN_ECDSA_KEY_H_
11 #define BOTAN_ECDSA_KEY_H_
12 
13 #include <botan/ecc_key.h>
14 
15 namespace Botan {
16 
17 /**
18 * This class represents ECDSA Public Keys.
19 */
20 class BOTAN_PUBLIC_API(2,0) ECDSA_PublicKey : public virtual EC_PublicKey
21  {
22  public:
23 
24  /**
25  * Create a public key from a given public point.
26  * @param dom_par the domain parameters associated with this key
27  * @param public_point the public point defining this key
28  */
29  ECDSA_PublicKey(const EC_Group& dom_par,
30  const PointGFp& public_point) :
31  EC_PublicKey(dom_par, public_point) {}
32 
33  /**
34  * Load a public key.
35  * @param alg_id the X.509 algorithm identifier
36  * @param key_bits DER encoded public key bits
37  */
39  const std::vector<uint8_t>& key_bits) :
40  EC_PublicKey(alg_id, key_bits) {}
41 
42  /**
43  * Recover a public key from a signature/msg pair
44  * See SEC section 4.6.1
45  * @param group the elliptic curve group
46  * @param msg the message
47  * @param r the r paramter of the signature
48  * @param s the s paramter of the signature
49  * @param v the recovery ID
50  */
51  ECDSA_PublicKey(const EC_Group& group,
52  const std::vector<uint8_t>& msg,
53  const BigInt& r,
54  const BigInt& s,
55  uint8_t v);
56 
57  /**
58  * Get this keys algorithm name.
59  * @result this keys algorithm name ("ECDSA")
60  */
61  std::string algo_name() const override { return "ECDSA"; }
62 
63  size_t message_parts() const override { return 2; }
64 
65  size_t message_part_size() const override
66  { return domain().get_order().bytes(); }
67 
68  uint8_t recovery_param(const std::vector<uint8_t>& msg,
69  const BigInt& r,
70  const BigInt& s) const;
71 
72  std::unique_ptr<PK_Ops::Verification>
73  create_verification_op(const std::string& params,
74  const std::string& provider) const override;
75  protected:
76  ECDSA_PublicKey() = default;
77  };
78 
79 /**
80 * This class represents ECDSA Private Keys
81 */
83  public EC_PrivateKey
84  {
85  public:
86 
87  /**
88  * Load a private key
89  * @param alg_id the X.509 algorithm identifier
90  * @param key_bits ECPrivateKey bits
91  */
93  const secure_vector<uint8_t>& key_bits) :
94  EC_PrivateKey(alg_id, key_bits) {}
95 
96  /**
97  * Create a private key.
98  * @param rng a random number generator
99  * @param domain parameters to used for this key
100  * @param x the private key (if zero, generate a new random key)
101  */
103  const EC_Group& domain,
104  const BigInt& x = 0) :
105  EC_PrivateKey(rng, domain, x) {}
106 
107  bool check_key(RandomNumberGenerator& rng, bool) const override;
108 
109  std::unique_ptr<PK_Ops::Signature>
110  create_signature_op(RandomNumberGenerator& rng,
111  const std::string& params,
112  const std::string& provider) const override;
113  };
114 
115 }
116 
117 #endif
size_t message_parts() const override
Definition: ecdsa.h:63
int(* final)(unsigned char *, CTX *)
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
size_t message_part_size() const override
Definition: ecdsa.h:65
Definition: alg_id.cpp:13
ECDSA_PrivateKey(const AlgorithmIdentifier &alg_id, const secure_vector< uint8_t > &key_bits)
Definition: ecdsa.h:92
std::string algo_name() const override
Definition: ecdsa.h:61
ECDSA_PublicKey(const EC_Group &dom_par, const PointGFp &public_point)
Definition: ecdsa.h:29
ECDSA_PrivateKey(RandomNumberGenerator &rng, const EC_Group &domain, const BigInt &x=0)
Definition: ecdsa.h:102
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:65
ECDSA_PublicKey(const AlgorithmIdentifier &alg_id, const std::vector< uint8_t > &key_bits)
Definition: ecdsa.h:38