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