Botan 3.11.0
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
52 std::unique_ptr<Private_Key> generate_another(RandomNumberGenerator& rng) const final;
53
54 bool supports_operation(PublicKeyOperation op) const override { return (op == PublicKeyOperation::Signature); }
55
56 std::unique_ptr<PK_Ops::Verification> create_verification_op(std::string_view params,
57 std::string_view provider) const override;
58
59 std::unique_ptr<PK_Ops::Verification> create_x509_verification_op(const AlgorithmIdentifier& signature_algorithm,
60 std::string_view provider) const override;
61
62 protected:
63 ECGDSA_PublicKey() = default;
64};
65
66/**
67* This class represents ECGDSA private keys.
68*/
69
72
74 public EC_PrivateKey {
75 public:
76 /**
77 * Load a private key.
78 * @param alg_id the X.509 algorithm identifier
79 * @param key_bits ECPrivateKey bits
80 */
81 ECGDSA_PrivateKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits) :
82 EC_PrivateKey(alg_id, key_bits, true) {}
83
84 /**
85 * Create a private key from a given secret @p x
86 * @param group curve parameters to bu used for this key
87 * @param x the private key
88 */
89 ECGDSA_PrivateKey(const EC_Group& group, const EC_Scalar& x) : EC_PrivateKey(group, x, true) {}
90
91 /**
92 * Create a new private key
93 * @param rng a random number generator
94 * @param group parameters to used for this key
95 */
96 ECGDSA_PrivateKey(RandomNumberGenerator& rng, const EC_Group& group) : EC_PrivateKey(rng, group, true) {}
97
98 /**
99 * Generate a new private key.
100 * @param rng a random number generator
101 * @param group parameters to used for this key
102 * @param x the private key (if zero, generate a new random key)
103 */
104 BOTAN_DEPRECATED("Use one of the other constructors")
106 EC_PrivateKey(rng, group, x, true) {}
107
108 std::unique_ptr<Public_Key> public_key() const override;
109
110 bool check_key(RandomNumberGenerator& rng, bool strong) const override;
111
112 std::unique_ptr<PK_Ops::Signature> create_signature_op(RandomNumberGenerator& rng,
113 std::string_view params,
114 std::string_view provider) const override;
115};
116
118
119} // namespace Botan
120
121#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
ECGDSA_PrivateKey(const EC_Group &group, const EC_Scalar &x)
Definition ecgdsa.h:89
ECGDSA_PrivateKey(const AlgorithmIdentifier &alg_id, std::span< const uint8_t > key_bits)
Definition ecgdsa.h:81
ECGDSA_PrivateKey(RandomNumberGenerator &rng, const EC_Group &group)
Definition ecgdsa.h:96
bool supports_operation(PublicKeyOperation op) const override
Definition ecgdsa.h:54
std::string algo_name() const override
Definition ecgdsa.h:48
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
EC_PrivateKey(const EC_PrivateKey &other)=default
EC_PublicKey(const EC_PublicKey &other)=default
PublicKeyOperation
Definition pk_keys.h:46