Botan 3.0.0
Crypto and TLS for C&
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
15namespace Botan {
16
17/**
18* This class represents ECDSA Public Keys.
19*/
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 EC_Point& 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 std::span<const 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 bool supports_operation(PublicKeyOperation op) const override
69 {
70 return (op == PublicKeyOperation::Signature);
71 }
72
73 uint8_t recovery_param(const std::vector<uint8_t>& msg,
74 const BigInt& r,
75 const BigInt& s) const;
76
77 std::unique_ptr<PK_Ops::Verification>
78 create_verification_op(std::string_view params,
79 std::string_view provider) const override;
80
81 std::unique_ptr<PK_Ops::Verification>
82 create_x509_verification_op(const AlgorithmIdentifier& signature_algorithm,
83 std::string_view provider) const override;
84 protected:
85 ECDSA_PublicKey() = default;
86 };
87
88/**
89* This class represents ECDSA Private Keys
90*/
91
94
96 public EC_PrivateKey
97 {
98 public:
99
100 /**
101 * Load a private key
102 * @param alg_id the X.509 algorithm identifier
103 * @param key_bits ECPrivateKey bits
104 */
106 std::span<const uint8_t> key_bits) :
107 EC_PrivateKey(alg_id, key_bits) {}
108
109 /**
110 * Create a private key.
111 * @param rng a random number generator
112 * @param domain parameters to used for this key
113 * @param x the private key (if zero, generate a new random key)
114 */
116 const EC_Group& domain,
117 const BigInt& x = BigInt::zero()) :
118 EC_PrivateKey(rng, domain, x) {}
119
120 bool check_key(RandomNumberGenerator& rng, bool) const override;
121
122 std::unique_ptr<Public_Key> public_key() const override;
123
124 std::unique_ptr<PK_Ops::Signature>
125 create_signature_op(RandomNumberGenerator& rng,
126 std::string_view params,
127 std::string_view provider) const override;
128 };
129
131
132}
133
134#endif
ECDSA_PrivateKey(const AlgorithmIdentifier &alg_id, std::span< const uint8_t > key_bits)
Definition: ecdsa.h:105
ECDSA_PrivateKey(RandomNumberGenerator &rng, const EC_Group &domain, const BigInt &x=BigInt::zero())
Definition: ecdsa.h:115
std::string algo_name() const override
Definition: ecdsa.h:61
size_t message_part_size() const override
Definition: ecdsa.h:65
ECDSA_PublicKey(const AlgorithmIdentifier &alg_id, std::span< const uint8_t > key_bits)
Definition: ecdsa.h:38
size_t message_parts() const override
Definition: ecdsa.h:63
bool supports_operation(PublicKeyOperation op) const override
Definition: ecdsa.h:68
ECDSA_PublicKey(const EC_Group &dom_par, const EC_Point &public_point)
Definition: ecdsa.h:29
int(* final)(unsigned char *, CTX *)
#define BOTAN_DIAGNOSTIC_POP
Definition: compiler.h:204
#define BOTAN_DIAGNOSTIC_PUSH
Definition: compiler.h:201
#define BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE
Definition: compiler.h:203
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
Definition: alg_id.cpp:12
PublicKeyOperation
Definition: pk_keys.h:43