Botan 3.14.1
Crypto and TLS for C&
ed448.h
Go to the documentation of this file.
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 <memory>
15#include <vector>
16
17namespace Botan {
18
19class Ed448_PublicKey_Data;
20class Ed448_PrivateKey_Data;
21
22/**
23 * @brief A public key for Ed448/Ed448ph according to RFC 8032.
24 *
25 * By default, Ed448 without prehash is used (recommended). To use
26 * Ed448ph, "Ed448ph" or a custom hash function identifier is passed
27 * as a parameter to the _create_verification_op method.
28 *
29 * Note that contexts (i.e. Ed448ctx) are not supported by this interface.
30 */
31class BOTAN_PUBLIC_API(3, 4) Ed448_PublicKey : public virtual Public_Key {
32 public:
33 std::string algo_name() const override { return "Ed448"; }
34
35 size_t estimated_strength() const override { return 224; }
36
37 size_t key_length() const override { return 448; }
38
39 bool check_key(RandomNumberGenerator& rng, bool strong) const override;
40
41 AlgorithmIdentifier algorithm_identifier() const override;
42
43 std::vector<uint8_t> raw_public_key_bits() const override;
44
45 std::vector<uint8_t> public_key_bits() const override;
46
47 std::unique_ptr<Private_Key> generate_another(RandomNumberGenerator& rng) const final;
48
49 bool supports_operation(PublicKeyOperation op) const override { return (op == PublicKeyOperation::Signature); }
50
51 /**
52 * Create a Ed448 Public Key.
53 * @param alg_id the X.509 algorithm identifier
54 * @param key_bits DER encoded public key bits
55 *
56 * Throws Decoding_Error if the key is invalid; see the raw constructor
57 */
58 Ed448_PublicKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits);
59
60 /**
61 * Create a Ed448 Public Key from bytes (57 Bytes).
62 *
63 * Throws Decoding_Error if the encoding is invalid, or if the point is
64 * the identity, has small order, or lies outside the prime order
65 * subgroup. No further checks are needed once the key is constructed.
66 */
67 BOTAN_FUTURE_EXPLICIT Ed448_PublicKey(std::span<const uint8_t> key_bits);
68
69 std::unique_ptr<PK_Ops::Verification> _create_verification_op(
70 const PK_Signature_Options_Reader& options) const override;
71
72 std::unique_ptr<PK_Ops::Verification> create_x509_verification_op(const AlgorithmIdentifier& signature_algorithm,
73 std::string_view provider) const override;
74
75 protected:
76 Ed448_PublicKey() = default;
77 std::shared_ptr<const Ed448_PublicKey_Data> m_public; // NOLINT(*non-private-member-variable*)
78
79 private:
80 friend class Ed448_PrivateKey;
81
82 // Shares already validated key data, so the private key's public_key()
83 // need not repeat the checks performed when decoding
84 explicit Ed448_PublicKey(std::shared_ptr<const Ed448_PublicKey_Data> key) : m_public(std::move(key)) {}
85};
86
89
90/**
91 * @brief A private key for Ed448/Ed448ph according to RFC 8032.
92 *
93 * By default, Ed448 without prehash is used (recommended). To use
94 * Ed448ph, "Ed448ph" or a custom hash function identifier is passed
95 * as a parameter to the _create_verification_op method.
96 *
97 * Note that contexts (i.e. Ed448ctx) are not supported by this interface.
98 */
100 public virtual Private_Key {
101 public:
102 /**
103 * Construct a private key from the specified parameters.
104 *
105 * @param alg_id the X.509 algorithm identifier
106 * @param key_bits PKCS #8 structure
107 */
108 Ed448_PrivateKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits);
109
110 /**
111 * Construct a private key from bytes.
112 *
113 * @param key_bits private key bytes (57 Bytes)
114 */
115 BOTAN_FUTURE_EXPLICIT Ed448_PrivateKey(std::span<const uint8_t> key_bits);
116
117 /**
118 * Generate a new private key.
119 *
120 * @param rng the RNG to use
121 */
123
125
127
128 std::unique_ptr<Public_Key> public_key() const override;
129
130 bool check_key(RandomNumberGenerator& rng, bool strong) const override;
131
132 std::unique_ptr<PK_Ops::Signature> _create_signature_op(
133 RandomNumberGenerator& rng, const PK_Signature_Options_Reader& options) const override;
134
135 private:
136 std::shared_ptr<const Ed448_PrivateKey_Data> m_private;
137};
138
140
141} // namespace Botan
142
143#endif
#define BOTAN_DIAGNOSTIC_POP
Definition api.h:128
#define BOTAN_DIAGNOSTIC_PUSH
Definition api.h:125
#define BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE
Definition api.h:127
#define BOTAN_PUBLIC_API(maj, min)
Definition api.h:21
#define BOTAN_FUTURE_EXPLICIT
Definition api.h:52
Ed448_PrivateKey(const AlgorithmIdentifier &alg_id, std::span< const uint8_t > key_bits)
Definition ed448.cpp:94
std::unique_ptr< PK_Ops::Signature > _create_signature_op(RandomNumberGenerator &rng, const PK_Signature_Options_Reader &options) const override
Definition ed448.cpp:300
bool check_key(RandomNumberGenerator &rng, bool strong) const override
Definition ed448.cpp:138
secure_vector< uint8_t > raw_private_key_bits() const override
Definition ed448.cpp:45
secure_vector< uint8_t > private_key_bits() const override
Definition ed448.cpp:132
std::unique_ptr< Public_Key > public_key() const override
Definition ed448.cpp:128
A public key for Ed448/Ed448ph according to RFC 8032.
Definition ed448.h:31
std::string algo_name() const override
Definition ed448.h:33
bool supports_operation(PublicKeyOperation op) const override
Definition ed448.h:49
std::shared_ptr< const Ed448_PublicKey_Data > m_public
Definition ed448.h:77
Ed448_PublicKey(const AlgorithmIdentifier &alg_id, std::span< const uint8_t > key_bits)
Definition ed448.cpp:59
friend class Ed448_PrivateKey
Definition ed448.h:80
size_t key_length() const override
Definition ed448.h:37
size_t estimated_strength() const override
Definition ed448.h:35
PublicKeyOperation
Definition pk_keys.h:50
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:128