Botan 3.7.1
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*/
20class BOTAN_PUBLIC_API(2, 0) ECDSA_PublicKey : public virtual EC_PublicKey {
21 public:
22 /**
23 * Create a public key from a given public point.
24 * @param group the domain parameters associated with this key
25 * @param public_key the public point defining this key
26 */
27 ECDSA_PublicKey(const EC_Group& group, const EC_AffinePoint& public_key) : EC_PublicKey(group, public_key) {}
28
29#if defined(BOTAN_HAS_LEGACY_EC_POINT)
30 /**
31 * Create a public key from a given public point.
32 * @param group the domain parameters associated with this key
33 * @param public_point the public point defining this key
34 */
35 ECDSA_PublicKey(const EC_Group& group, const EC_Point& public_point) : EC_PublicKey(group, public_point) {}
36#endif
37
38 /**
39 * Load a public key.
40 * @param alg_id the X.509 algorithm identifier
41 * @param key_bits DER encoded public key bits
42 */
43 ECDSA_PublicKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits) :
44 EC_PublicKey(alg_id, key_bits) {}
45
46 /**
47 * Recover a public key from a signature/msg pair
48 * See SEC section 4.6.1
49 * @param group the elliptic curve group
50 * @param msg the message
51 * @param r the r paramter of the signature
52 * @param s the s paramter of the signature
53 * @param v the recovery ID
54 */
56 const EC_Group& group, const std::vector<uint8_t>& msg, const BigInt& r, const BigInt& s, uint8_t v);
57
58 /**
59 * Get this keys algorithm name.
60 * @result this keys algorithm name ("ECDSA")
61 */
62 std::string algo_name() const override { return "ECDSA"; }
63
64 std::optional<size_t> _signature_element_size_for_DER_encoding() const override {
65 return domain().get_order_bytes();
66 }
67
68 bool supports_operation(PublicKeyOperation op) const override { return (op == PublicKeyOperation::Signature); }
69
70 std::unique_ptr<Private_Key> generate_another(RandomNumberGenerator& rng) const override;
71
72 uint8_t recovery_param(const std::vector<uint8_t>& msg, const BigInt& r, const BigInt& s) const;
73
74 std::unique_ptr<PK_Ops::Verification> create_verification_op(std::string_view params,
75 std::string_view provider) const override;
76
77 std::unique_ptr<PK_Ops::Verification> create_x509_verification_op(const AlgorithmIdentifier& signature_algorithm,
78 std::string_view provider) const override;
79
80 protected:
81 ECDSA_PublicKey() = default;
82};
83
84/**
85* This class represents ECDSA Private Keys
86*/
87
90
92 public EC_PrivateKey {
93 public:
94 /**
95 * Load a private key
96 * @param alg_id the X.509 algorithm identifier
97 * @param key_bits ECPrivateKey bits
98 */
99 ECDSA_PrivateKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits) :
100 EC_PrivateKey(alg_id, key_bits) {}
101
102 /**
103 * Create a private key from a given secret @p x
104 * @param group curve parameters to bu used for this key
105 * @param x the private key
106 */
107 ECDSA_PrivateKey(EC_Group group, EC_Scalar x) : EC_PrivateKey(std::move(group), std::move(x)) {}
108
109 /**
110 * Create a new private key
111 * @param rng a random number generator
112 * @param group parameters to used for this key
113 */
114 ECDSA_PrivateKey(RandomNumberGenerator& rng, EC_Group group) : EC_PrivateKey(rng, std::move(group)) {}
115
116 /**
117 * Create a private key.
118 * @param rng a random number generator
119 * @param group parameters to used for this key
120 * @param x the private key (if zero, generate a new random key)
121 */
122 BOTAN_DEPRECATED("Use one of the other constructors")
124 EC_PrivateKey(rng, group, x) {}
125
126 bool check_key(RandomNumberGenerator& rng, bool) const override;
127
128 std::unique_ptr<Public_Key> public_key() const override;
129
130 std::unique_ptr<PK_Ops::Signature> create_signature_op(RandomNumberGenerator& rng,
131 std::string_view params,
132 std::string_view provider) const override;
133};
134
136
137} // namespace Botan
138
139#endif
#define BOTAN_DIAGNOSTIC_POP
Definition api.h:108
#define BOTAN_DIAGNOSTIC_PUSH
Definition api.h:105
#define BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE
Definition api.h:107
#define BOTAN_PUBLIC_API(maj, min)
Definition api.h:19
#define BOTAN_DEPRECATED(msg)
Definition api.h:59
ECDSA_PrivateKey(const AlgorithmIdentifier &alg_id, std::span< const uint8_t > key_bits)
Definition ecdsa.h:99
ECDSA_PrivateKey(RandomNumberGenerator &rng, EC_Group group)
Definition ecdsa.h:114
ECDSA_PrivateKey(EC_Group group, EC_Scalar x)
Definition ecdsa.h:107
ECDSA_PublicKey(const EC_Group &group, const EC_AffinePoint &public_key)
Definition ecdsa.h:27
std::string algo_name() const override
Definition ecdsa.h:62
ECDSA_PublicKey(const AlgorithmIdentifier &alg_id, std::span< const uint8_t > key_bits)
Definition ecdsa.h:43
bool supports_operation(PublicKeyOperation op) const override
Definition ecdsa.h:68
std::optional< size_t > _signature_element_size_for_DER_encoding() const override
Definition ecdsa.h:64
int(* final)(unsigned char *, CTX *)
PublicKeyOperation
Definition pk_keys.h:45