Botan 3.7.1
Crypto and TLS for C&
eckcdsa.h
Go to the documentation of this file.
1/*
2* ECKCDSA (ISO/IEC 14888-3:2018)
3* (C) 2016 René Korthaus, Sirrix AG
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#ifndef BOTAN_ECKCDSA_KEY_H_
9#define BOTAN_ECKCDSA_KEY_H_
10
11#include <botan/ecc_key.h>
12
13namespace Botan {
14
15/**
16* This class represents ECKCDSA public keys.
17*/
18class BOTAN_PUBLIC_API(2, 0) ECKCDSA_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 ECKCDSA_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 ECKCDSA_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 ECKCDSA_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 */
47 std::string algo_name() const override { return "ECKCDSA"; }
48
49 std::optional<size_t> _signature_element_size_for_DER_encoding() const override {
50 return domain().get_order_bytes();
51 }
52
53 std::unique_ptr<Private_Key> generate_another(RandomNumberGenerator& rng) const final;
54
55 bool supports_operation(PublicKeyOperation op) const override { return (op == PublicKeyOperation::Signature); }
56
57 std::unique_ptr<PK_Ops::Verification> create_verification_op(std::string_view params,
58 std::string_view provider) const override;
59
60 std::unique_ptr<PK_Ops::Verification> create_x509_verification_op(const AlgorithmIdentifier& signature_algorithm,
61 std::string_view provider) const override;
62
63 protected:
64 ECKCDSA_PublicKey() = default;
65};
66
67/**
68* This class represents ECKCDSA private keys.
69*/
70
73
75 public EC_PrivateKey {
76 public:
77 /**
78 * Load a private key.
79 * @param alg_id the X.509 algorithm identifier
80 * @param key_bits ECPrivateKey bits
81 */
82 ECKCDSA_PrivateKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits) :
83 EC_PrivateKey(alg_id, key_bits, true) {}
84
85 /**
86 * Create a private key from a given secret @p x
87 * @param group curve parameters to bu used for this key
88 * @param x the private key
89 */
90 ECKCDSA_PrivateKey(EC_Group group, EC_Scalar x) : EC_PrivateKey(std::move(group), std::move(x), true) {}
91
92 /**
93 * Create a new private key
94 * @param rng a random number generator
95 * @param group parameters to used for this key
96 */
97 ECKCDSA_PrivateKey(RandomNumberGenerator& rng, EC_Group group) : EC_PrivateKey(rng, std::move(group), true) {}
98
99 /**
100 * Create a private key.
101 * @param rng a random number generator
102 * @param group parameters to used for this key
103 * @param x the private key (if zero, generate a new random key)
104 */
105 BOTAN_DEPRECATED("Use one of the other constructors")
107 EC_PrivateKey(rng, group, x, true) {}
108
109 bool check_key(RandomNumberGenerator& rng, bool) const override;
110
111 std::unique_ptr<Public_Key> public_key() const override;
112
113 std::unique_ptr<PK_Ops::Signature> create_signature_op(RandomNumberGenerator& rng,
114 std::string_view params,
115 std::string_view provider) const override;
116};
117
119
120} // namespace Botan
121
122#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
ECKCDSA_PrivateKey(EC_Group group, EC_Scalar x)
Definition eckcdsa.h:90
ECKCDSA_PrivateKey(const AlgorithmIdentifier &alg_id, std::span< const uint8_t > key_bits)
Definition eckcdsa.h:82
ECKCDSA_PrivateKey(RandomNumberGenerator &rng, EC_Group group)
Definition eckcdsa.h:97
bool supports_operation(PublicKeyOperation op) const override
Definition eckcdsa.h:55
std::string algo_name() const override
Definition eckcdsa.h:47
ECKCDSA_PublicKey(const EC_Group &group, const EC_AffinePoint &public_key)
Definition eckcdsa.h:25
ECKCDSA_PublicKey(const AlgorithmIdentifier &alg_id, std::span< const uint8_t > key_bits)
Definition eckcdsa.h:41
std::optional< size_t > _signature_element_size_for_DER_encoding() const override
Definition eckcdsa.h:49
int(* final)(unsigned char *, CTX *)
PublicKeyOperation
Definition pk_keys.h:45