Botan 3.7.1
Crypto and TLS for C&
ecgdsa.h
Go to the documentation of this file.
1/*
2* ECGDSA (BSI-TR-03111, version 2.0)
3* (C) 2016 René Korthaus
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#ifndef BOTAN_ECGDSA_KEY_H_
9#define BOTAN_ECGDSA_KEY_H_
10
11#include <botan/ecc_key.h>
12
13namespace Botan {
14
15/**
16* This class represents ECGDSA public keys.
17*/
18class BOTAN_PUBLIC_API(2, 0) ECGDSA_PublicKey : public virtual EC_PublicKey {
19 public:
20 /**
21 * Construct a public key from a given public point.
22 * @param group the domain parameters associated with this key
23 * @param public_key the public point defining this key
24 */
25 ECGDSA_PublicKey(const EC_Group& group, const EC_AffinePoint& public_key) : EC_PublicKey(group, public_key) {}
26
27#if defined(BOTAN_HAS_LEGACY_EC_POINT)
28 /**
29 * Construct a public key from a given public point.
30 * @param group the domain parameters associated with this key
31 * @param public_point the public point defining this key
32 */
33 ECGDSA_PublicKey(const EC_Group& group, const EC_Point& public_point) : EC_PublicKey(group, public_point) {}
34#endif
35
36 /**
37 * Load a public key.
38 * @param alg_id the X.509 algorithm identifier
39 * @param key_bits DER encoded public key bits
40 */
41 ECGDSA_PublicKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits) :
42 EC_PublicKey(alg_id, key_bits) {}
43
44 /**
45 * Get this keys algorithm name.
46 * @result this keys algorithm name ("ECGDSA")
47 */
48 std::string algo_name() const override { return "ECGDSA"; }
49
50 std::optional<size_t> _signature_element_size_for_DER_encoding() const override {
51 return domain().get_order_bytes();
52 }
53
54 std::unique_ptr<Private_Key> generate_another(RandomNumberGenerator& rng) const final;
55
56 bool supports_operation(PublicKeyOperation op) const override { return (op == PublicKeyOperation::Signature); }
57
58 std::unique_ptr<PK_Ops::Verification> create_verification_op(std::string_view params,
59 std::string_view provider) const override;
60
61 std::unique_ptr<PK_Ops::Verification> create_x509_verification_op(const AlgorithmIdentifier& signature_algorithm,
62 std::string_view provider) const override;
63
64 protected:
65 ECGDSA_PublicKey() = default;
66};
67
68/**
69* This class represents ECGDSA private keys.
70*/
71
74
76 public EC_PrivateKey {
77 public:
78 /**
79 * Load a private key.
80 * @param alg_id the X.509 algorithm identifier
81 * @param key_bits ECPrivateKey bits
82 */
83 ECGDSA_PrivateKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits) :
84 EC_PrivateKey(alg_id, key_bits, true) {}
85
86 /**
87 * Create a private key from a given secret @p x
88 * @param group curve parameters to bu used for this key
89 * @param x the private key
90 */
91 ECGDSA_PrivateKey(EC_Group group, EC_Scalar x) : EC_PrivateKey(std::move(group), std::move(x), true) {}
92
93 /**
94 * Create a new private key
95 * @param rng a random number generator
96 * @param group parameters to used for this key
97 */
98 ECGDSA_PrivateKey(RandomNumberGenerator& rng, EC_Group group) : EC_PrivateKey(rng, std::move(group), true) {}
99
100 /**
101 * Generate a new private key.
102 * @param rng a random number generator
103 * @param group parameters to used for this key
104 * @param x the private key (if zero, generate a new random key)
105 */
106 BOTAN_DEPRECATED("Use one of the other constructors")
108 EC_PrivateKey(rng, group, x, true) {}
109
110 std::unique_ptr<Public_Key> public_key() const override;
111
112 bool check_key(RandomNumberGenerator& rng, bool) const override;
113
114 std::unique_ptr<PK_Ops::Signature> create_signature_op(RandomNumberGenerator& rng,
115 std::string_view params,
116 std::string_view provider) const override;
117};
118
120
121} // namespace Botan
122
123#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
ECGDSA_PrivateKey(RandomNumberGenerator &rng, EC_Group group)
Definition ecgdsa.h:98
ECGDSA_PrivateKey(const AlgorithmIdentifier &alg_id, std::span< const uint8_t > key_bits)
Definition ecgdsa.h:83
ECGDSA_PrivateKey(EC_Group group, EC_Scalar x)
Definition ecgdsa.h:91
bool supports_operation(PublicKeyOperation op) const override
Definition ecgdsa.h:56
std::string algo_name() const override
Definition ecgdsa.h:48
std::optional< size_t > _signature_element_size_for_DER_encoding() const override
Definition ecgdsa.h:50
ECGDSA_PublicKey(const EC_Group &group, const EC_AffinePoint &public_key)
Definition ecgdsa.h:25
ECGDSA_PublicKey(const AlgorithmIdentifier &alg_id, std::span< const uint8_t > key_bits)
Definition ecgdsa.h:41
int(* final)(unsigned char *, CTX *)
PublicKeyOperation
Definition pk_keys.h:45