Botan 3.11.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*/
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 parameter of the signature
52 * @param s the s parameter 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
66 bool supports_operation(PublicKeyOperation op) const override { return (op == PublicKeyOperation::Signature); }
67
68 std::unique_ptr<Private_Key> generate_another(RandomNumberGenerator& rng) const override;
69
70 uint8_t recovery_param(const std::vector<uint8_t>& msg, const BigInt& r, const BigInt& s) const;
71
72 std::unique_ptr<PK_Ops::Verification> create_verification_op(std::string_view params,
73 std::string_view provider) const override;
74
75 std::unique_ptr<PK_Ops::Verification> create_x509_verification_op(const AlgorithmIdentifier& signature_algorithm,
76 std::string_view provider) const override;
77
78 protected:
79 ECDSA_PublicKey() = default;
80};
81
82/**
83* This class represents ECDSA Private Keys
84*/
85
88
90 public EC_PrivateKey {
91 public:
92 /**
93 * Load a private key
94 * @param alg_id the X.509 algorithm identifier
95 * @param key_bits ECPrivateKey bits
96 */
97 ECDSA_PrivateKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits) :
98 EC_PrivateKey(alg_id, key_bits) {}
99
100 /**
101 * Create a private key from a given secret @p x
102 * @param group curve parameters to bu used for this key
103 * @param x the private key
104 */
105 ECDSA_PrivateKey(const EC_Group& group, const EC_Scalar& x) : EC_PrivateKey(group, x) {}
106
107 /**
108 * Create a new private key
109 * @param rng a random number generator
110 * @param group parameters to used for this key
111 */
113
114 /**
115 * Create a private key.
116 * @param rng a random number generator
117 * @param group parameters to used for this key
118 * @param x the private key (if zero, generate a new random key)
119 */
120 BOTAN_DEPRECATED("Use one of the other constructors")
122 EC_PrivateKey(rng, group, x) {}
123
124 bool check_key(RandomNumberGenerator& rng, bool strong) const override;
125
126 std::unique_ptr<Public_Key> public_key() const override;
127
128 std::unique_ptr<PK_Ops::Signature> create_signature_op(RandomNumberGenerator& rng,
129 std::string_view params,
130 std::string_view provider) const override;
131};
132
134
135} // namespace Botan
136
137#endif
#define BOTAN_DIAGNOSTIC_POP
Definition api.h:122
#define BOTAN_DIAGNOSTIC_PUSH
Definition api.h:119
#define BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE
Definition api.h:121
#define BOTAN_PUBLIC_API(maj, min)
Definition api.h:21
#define BOTAN_DEPRECATED(msg)
Definition api.h:73
ECDSA_PrivateKey(const AlgorithmIdentifier &alg_id, std::span< const uint8_t > key_bits)
Definition ecdsa.h:97
ECDSA_PrivateKey(RandomNumberGenerator &rng, const EC_Group &group)
Definition ecdsa.h:112
ECDSA_PrivateKey(const EC_Group &group, const EC_Scalar &x)
Definition ecdsa.h:105
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:66
EC_PrivateKey(const EC_PrivateKey &other)=default
EC_PublicKey(const EC_PublicKey &other)=default
PublicKeyOperation
Definition pk_keys.h:46