Debian Codegraph @

src/lib/pubkey/curve448/x448/x448.h

raw
1 /*
2 * X448
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 #ifndef BOTAN_X448_H_
9 #define BOTAN_X448_H_
10
11 #include <botan/pk_keys.h>
12
13 #include <array>
14
15 namespace Botan {
16 /**
17 * @brief A public key for the X448 key agreement scheme according to RFC 7748.
18 */
19 class BOTAN_PUBLIC_API(3, 4) X448_PublicKey : public virtual Public_Key {
20 public:
21 /**
22 * Create a X448 Public Key.
23 * @param alg_id the X.509 algorithm identifier
24 * @param key_bits DER encoded public key bits
25 */
26 X448_PublicKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits);
27
28 /**
29 * Create a X448 Public Key.
30 * @param pub 56-byte raw public key
31 */
32 explicit X448_PublicKey(std::span<const uint8_t> pub);
33
34 std::string algo_name() const override { return "X448"; }
35
36 size_t estimated_strength() const override { return 224; }
37
38 size_t key_length() const override { return 448; }
39
40 bool check_key(RandomNumberGenerator& rng, bool strong) const override;
41
42 AlgorithmIdentifier algorithm_identifier() const override;
43
44 BOTAN_DEPRECATED("Use raw_public_key_bits") std::vector<uint8_t> public_value() const {
45 return raw_public_key_bits();
46 }
47
48 std::vector<uint8_t> raw_public_key_bits() const override;
49
50 std::vector<uint8_t> public_key_bits() const override;
51
52 bool supports_operation(PublicKeyOperation op) const override { return (op == PublicKeyOperation::KeyAgreement); }
53
54 std::unique_ptr<Private_Key> generate_another(RandomNumberGenerator& rng) const final;
55
56 protected:
57 X448_PublicKey() = default;
58 std::array<uint8_t, 56> m_public{}; // NOLINT(*non-private-member-variable*)
59 };
60
61 BOTAN_DIAGNOSTIC_PUSH
62 BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE
63
64 /**
65 * @brief A private key for the X448 key agreement scheme according to RFC 7748.
66 */
67 class BOTAN_PUBLIC_API(3, 4) X448_PrivateKey final : public X448_PublicKey,
68 public virtual Private_Key,
69 public virtual PK_Key_Agreement_Key {
70 public:
71 /**
72 * Construct a private key from the specified parameters.
73 * @param alg_id the X.509 algorithm identifier
74 * @param key_bits PKCS #8 structure
75 */
76 X448_PrivateKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits);
77
78 /**
79 * Generate a private key.
80 * @param rng the RNG to use
81 */
82 explicit X448_PrivateKey(RandomNumberGenerator& rng);
83
84 /**
85 * Construct a private key from the specified parameters.
86 * @param secret_key the private key
87 */
88 explicit X448_PrivateKey(std::span<const uint8_t> secret_key);
89
90 std::vector<uint8_t> public_value() const override { return raw_public_key_bits(); }
91
92 secure_vector<uint8_t> raw_private_key_bits() const override { return {m_private.begin(), m_private.end()}; }
93
94 secure_vector<uint8_t> private_key_bits() const override;
95
96 std::unique_ptr<Public_Key> public_key() const override;
97
98 bool check_key(RandomNumberGenerator& rng, bool strong) const override;
99
100 std::unique_ptr<PK_Ops::Key_Agreement> create_key_agreement_op(RandomNumberGenerator& rng,
101 std::string_view params,
102 std::string_view provider) const override;
103
104 private:
105 secure_vector<uint8_t> m_private;
106 };
107
108 BOTAN_DIAGNOSTIC_POP
109
110 } // namespace Botan
111
112 #endif