Botan 3.4.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 dom_par the domain parameters associated with this key
25 * @param public_point the public point defining this key
26 */
27 ECDSA_PublicKey(const EC_Group& dom_par, const EC_Point& public_point) : EC_PublicKey(dom_par, public_point) {}
28
29 /**
30 * Load a public key.
31 * @param alg_id the X.509 algorithm identifier
32 * @param key_bits DER encoded public key bits
33 */
34 ECDSA_PublicKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits) :
35 EC_PublicKey(alg_id, key_bits) {}
36
37 /**
38 * Recover a public key from a signature/msg pair
39 * See SEC section 4.6.1
40 * @param group the elliptic curve group
41 * @param msg the message
42 * @param r the r paramter of the signature
43 * @param s the s paramter of the signature
44 * @param v the recovery ID
45 */
47 const EC_Group& group, const std::vector<uint8_t>& msg, const BigInt& r, const BigInt& s, uint8_t v);
48
49 /**
50 * Get this keys algorithm name.
51 * @result this keys algorithm name ("ECDSA")
52 */
53 std::string algo_name() const override { return "ECDSA"; }
54
55 size_t message_parts() const override { return 2; }
56
57 size_t message_part_size() const override { return domain().get_order().bytes(); }
58
59 bool supports_operation(PublicKeyOperation op) const override { return (op == PublicKeyOperation::Signature); }
60
61 std::unique_ptr<Private_Key> generate_another(RandomNumberGenerator& rng) const override;
62
63 uint8_t recovery_param(const std::vector<uint8_t>& msg, const BigInt& r, const BigInt& s) const;
64
65 std::unique_ptr<PK_Ops::Verification> create_verification_op(std::string_view params,
66 std::string_view provider) const override;
67
68 std::unique_ptr<PK_Ops::Verification> create_x509_verification_op(const AlgorithmIdentifier& signature_algorithm,
69 std::string_view provider) const override;
70
71 protected:
72 ECDSA_PublicKey() = default;
73};
74
75/**
76* This class represents ECDSA Private Keys
77*/
78
81
83 public EC_PrivateKey {
84 public:
85 /**
86 * Load a private key
87 * @param alg_id the X.509 algorithm identifier
88 * @param key_bits ECPrivateKey bits
89 */
90 ECDSA_PrivateKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits) :
91 EC_PrivateKey(alg_id, key_bits) {}
92
93 /**
94 * Create a private key.
95 * @param rng a random number generator
96 * @param domain parameters to used for this key
97 * @param x the private key (if zero, generate a new random key)
98 */
99 ECDSA_PrivateKey(RandomNumberGenerator& rng, const EC_Group& domain, const BigInt& x = BigInt::zero()) :
100 EC_PrivateKey(rng, domain, x) {}
101
102 bool check_key(RandomNumberGenerator& rng, bool) const override;
103
104 std::unique_ptr<Public_Key> public_key() const override;
105
106 std::unique_ptr<PK_Ops::Signature> create_signature_op(RandomNumberGenerator& rng,
107 std::string_view params,
108 std::string_view provider) const override;
109};
110
112
113} // namespace Botan
114
115#endif
ECDSA_PrivateKey(const AlgorithmIdentifier &alg_id, std::span< const uint8_t > key_bits)
Definition ecdsa.h:90
ECDSA_PrivateKey(RandomNumberGenerator &rng, const EC_Group &domain, const BigInt &x=BigInt::zero())
Definition ecdsa.h:99
std::string algo_name() const override
Definition ecdsa.h:53
size_t message_part_size() const override
Definition ecdsa.h:57
ECDSA_PublicKey(const AlgorithmIdentifier &alg_id, std::span< const uint8_t > key_bits)
Definition ecdsa.h:34
size_t message_parts() const override
Definition ecdsa.h:55
bool supports_operation(PublicKeyOperation op) const override
Definition ecdsa.h:59
ECDSA_PublicKey(const EC_Group &dom_par, const EC_Point &public_point)
Definition ecdsa.h:27
int(* final)(unsigned char *, CTX *)
#define BOTAN_DIAGNOSTIC_POP
Definition compiler.h:191
#define BOTAN_DIAGNOSTIC_PUSH
Definition compiler.h:188
#define BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE
Definition compiler.h:190
#define BOTAN_PUBLIC_API(maj, min)
Definition compiler.h:31
PublicKeyOperation
Definition pk_keys.h:45