/src/botan/build/include/public/botan/ed448.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Ed448 Signature Algorithm (RFC 8032) |
3 | | * (C) 2024 Jack Lloyd |
4 | | * 2024 Fabian Albert - Rohde & Schwarz Cybersecurity |
5 | | * |
6 | | * Botan is released under the Simplified BSD License (see license.txt) |
7 | | */ |
8 | | |
9 | | #ifndef BOTAN_ED448_H_ |
10 | | #define BOTAN_ED448_H_ |
11 | | |
12 | | #include <botan/pk_keys.h> |
13 | | |
14 | | #include <array> |
15 | | |
16 | | namespace Botan { |
17 | | |
18 | | /** |
19 | | * @brief A public key for Ed448/Ed448ph according to RFC 8032. |
20 | | * |
21 | | * By default, Ed448 without prehash is used (recommended). To use |
22 | | * Ed448ph, "Ed448ph" or a custom hash function identifier is passed |
23 | | * as a parameter to the create_verification_op method. |
24 | | * |
25 | | * Note that contexts (i.e. Ed448ctx) are not supported by this interface. |
26 | | */ |
27 | | class BOTAN_PUBLIC_API(3, 4) Ed448_PublicKey : public virtual Public_Key { |
28 | | public: |
29 | 0 | std::string algo_name() const override { return "Ed448"; } |
30 | | |
31 | 0 | size_t estimated_strength() const override { return 224; } |
32 | | |
33 | 0 | size_t key_length() const override { return 448; } |
34 | | |
35 | | bool check_key(RandomNumberGenerator& rng, bool strong) const override; |
36 | | |
37 | | AlgorithmIdentifier algorithm_identifier() const override; |
38 | | |
39 | | std::vector<uint8_t> raw_public_key_bits() const override; |
40 | | |
41 | | std::vector<uint8_t> public_key_bits() const override; |
42 | | |
43 | | std::unique_ptr<Private_Key> generate_another(RandomNumberGenerator& rng) const final; |
44 | | |
45 | 0 | bool supports_operation(PublicKeyOperation op) const override { return (op == PublicKeyOperation::Signature); } |
46 | | |
47 | | /** |
48 | | * Create a Ed448 Public Key. |
49 | | * @param alg_id the X.509 algorithm identifier |
50 | | * @param key_bits DER encoded public key bits |
51 | | */ |
52 | | Ed448_PublicKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits); |
53 | | |
54 | | /** |
55 | | * Create a Ed448 Public Key from bytes (57 Bytes). |
56 | | */ |
57 | | Ed448_PublicKey(std::span<const uint8_t> key_bits); |
58 | | |
59 | | std::unique_ptr<PK_Ops::Verification> create_verification_op(std::string_view params, |
60 | | std::string_view provider) const override; |
61 | | |
62 | | std::unique_ptr<PK_Ops::Verification> create_x509_verification_op(const AlgorithmIdentifier& signature_algorithm, |
63 | | std::string_view provider) const override; |
64 | | |
65 | | protected: |
66 | 186 | Ed448_PublicKey() = default; |
67 | | std::array<uint8_t, 57> m_public; |
68 | | }; |
69 | | |
70 | | BOTAN_DIAGNOSTIC_PUSH |
71 | | BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE |
72 | | |
73 | | /** |
74 | | * @brief A private key for Ed448/Ed448ph according to RFC 8032. |
75 | | * |
76 | | * By default, Ed448 without prehash is used (recommended). To use |
77 | | * Ed448ph, "Ed448ph" or a custom hash function identifier is passed |
78 | | * as a parameter to the create_verification_op method. |
79 | | * |
80 | | * Note that contexts (i.e. Ed448ctx) are not supported by this interface. |
81 | | */ |
82 | | class BOTAN_PUBLIC_API(3, 4) Ed448_PrivateKey final : public Ed448_PublicKey, |
83 | | public virtual Private_Key { |
84 | | public: |
85 | | /** |
86 | | * Construct a private key from the specified parameters. |
87 | | * |
88 | | * @param alg_id the X.509 algorithm identifier |
89 | | * @param key_bits PKCS #8 structure |
90 | | */ |
91 | | Ed448_PrivateKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits); |
92 | | |
93 | | /** |
94 | | * Construct a private key from bytes. |
95 | | * |
96 | | * @param key_bits private key bytes (57 Bytes) |
97 | | */ |
98 | | Ed448_PrivateKey(std::span<const uint8_t> key_bits); |
99 | | |
100 | | /** |
101 | | * Generate a new private key. |
102 | | * |
103 | | * @param rng the RNG to use |
104 | | */ |
105 | | explicit Ed448_PrivateKey(RandomNumberGenerator& rng); |
106 | | |
107 | 0 | secure_vector<uint8_t> raw_private_key_bits() const override { return {m_private.begin(), m_private.end()}; } |
108 | | |
109 | | secure_vector<uint8_t> private_key_bits() const override; |
110 | | |
111 | | std::unique_ptr<Public_Key> public_key() const override; |
112 | | |
113 | | bool check_key(RandomNumberGenerator& rng, bool strong) const override; |
114 | | |
115 | | std::unique_ptr<PK_Ops::Signature> create_signature_op(RandomNumberGenerator& rng, |
116 | | std::string_view params, |
117 | | std::string_view provider) const override; |
118 | | |
119 | | private: |
120 | | secure_vector<uint8_t> m_private; |
121 | | }; |
122 | | |
123 | | BOTAN_DIAGNOSTIC_POP |
124 | | |
125 | | } // namespace Botan |
126 | | |
127 | | #endif |