/src/botan/build/include/public/botan/x25519.h
Line | Count | Source |
1 | | /* |
2 | | * (C) 2014,2024 Jack Lloyd |
3 | | * |
4 | | * Botan is released under the Simplified BSD License (see license.txt) |
5 | | */ |
6 | | |
7 | | #ifndef BOTAN_X25519_H_ |
8 | | #define BOTAN_X25519_H_ |
9 | | |
10 | | #include <botan/pk_keys.h> |
11 | | |
12 | | namespace Botan { |
13 | | |
14 | | class BOTAN_PUBLIC_API(2, 0) X25519_PublicKey : public virtual Public_Key { |
15 | | public: |
16 | 8 | std::string algo_name() const override { return "X25519"; } |
17 | | |
18 | 0 | size_t estimated_strength() const override { return 128; } |
19 | | |
20 | 2 | size_t key_length() const override { return 255; } |
21 | | |
22 | | bool check_key(RandomNumberGenerator& rng, bool strong) const override; |
23 | | |
24 | | AlgorithmIdentifier algorithm_identifier() const override; |
25 | | |
26 | | std::vector<uint8_t> raw_public_key_bits() const override; |
27 | | |
28 | | std::vector<uint8_t> public_key_bits() const override; |
29 | | |
30 | 0 | BOTAN_DEPRECATED("Use raw_public_key_bits") std::vector<uint8_t> public_value() const { |
31 | 0 | return raw_public_key_bits(); |
32 | 0 | } |
33 | | |
34 | 0 | bool supports_operation(PublicKeyOperation op) const override { return (op == PublicKeyOperation::KeyAgreement); } |
35 | | |
36 | | std::unique_ptr<Private_Key> generate_another(RandomNumberGenerator& rng) const final; |
37 | | |
38 | | /** |
39 | | * Create a X25519 Public Key. |
40 | | * @param alg_id the X.509 algorithm identifier |
41 | | * @param key_bits DER encoded public key bits |
42 | | */ |
43 | | X25519_PublicKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits); |
44 | | |
45 | | /** |
46 | | * Create a X25519 Public Key. |
47 | | * @param pub 32-byte raw public key |
48 | | */ |
49 | | explicit X25519_PublicKey(std::span<const uint8_t> pub); |
50 | | |
51 | | protected: |
52 | 566 | X25519_PublicKey() = default; |
53 | | std::vector<uint8_t> m_public; // NOLINT(*non-private-member-variable*) |
54 | | }; |
55 | | |
56 | | BOTAN_DIAGNOSTIC_PUSH |
57 | | BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE |
58 | | |
59 | | class BOTAN_PUBLIC_API(2, 0) X25519_PrivateKey final : public X25519_PublicKey, |
60 | | public virtual Private_Key, |
61 | | public virtual PK_Key_Agreement_Key { |
62 | | public: |
63 | | /** |
64 | | * Construct a private key from the specified parameters. |
65 | | * @param alg_id the X.509 algorithm identifier |
66 | | * @param key_bits PKCS #8 structure |
67 | | */ |
68 | | X25519_PrivateKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits); |
69 | | |
70 | | /** |
71 | | * Generate a private key. |
72 | | * @param rng the RNG to use |
73 | | */ |
74 | | explicit X25519_PrivateKey(RandomNumberGenerator& rng); |
75 | | |
76 | | /** |
77 | | * Construct a private key from the specified parameters. |
78 | | * @param secret_key the private key |
79 | | */ |
80 | | explicit X25519_PrivateKey(std::span<const uint8_t> secret_key); |
81 | | |
82 | 0 | std::vector<uint8_t> public_value() const override { return raw_public_key_bits(); } |
83 | | |
84 | | secure_vector<uint8_t> agree(const uint8_t w[], size_t w_len) const; |
85 | | |
86 | 0 | secure_vector<uint8_t> raw_private_key_bits() const override { return m_private; } |
87 | | |
88 | 0 | BOTAN_DEPRECATED("Use raw_private_key_bits") const secure_vector<uint8_t>& get_x() const { return m_private; } |
89 | | |
90 | | secure_vector<uint8_t> private_key_bits() const override; |
91 | | |
92 | | std::unique_ptr<Public_Key> public_key() const override; |
93 | | |
94 | | bool check_key(RandomNumberGenerator& rng, bool strong) const override; |
95 | | |
96 | | std::unique_ptr<PK_Ops::Key_Agreement> create_key_agreement_op(RandomNumberGenerator& rng, |
97 | | std::string_view params, |
98 | | std::string_view provider) const override; |
99 | | |
100 | | private: |
101 | | secure_vector<uint8_t> m_private; |
102 | | }; |
103 | | |
104 | | BOTAN_DIAGNOSTIC_POP |
105 | | |
106 | | /* |
107 | | * The types above are just wrappers for curve25519_donna, plus defining |
108 | | * encodings for public and private keys. |
109 | | */ |
110 | | BOTAN_DEPRECATED_API("Use X25519_PrivateKey or Sodium::crypto_scalarmult_curve25519") |
111 | | void curve25519_donna(uint8_t mypublic[32], const uint8_t secret[32], const uint8_t basepoint[32]); |
112 | | |
113 | | /** |
114 | | * Exponentiate by the x25519 base point |
115 | | * @param mypublic output value |
116 | | * @param secret random scalar |
117 | | */ |
118 | | BOTAN_DEPRECATED_API("Use X25519_PrivateKey or Sodium::crypto_scalarmult_curve25519_base") |
119 | | void curve25519_basepoint(uint8_t mypublic[32], const uint8_t secret[32]); |
120 | | |
121 | | } // namespace Botan |
122 | | |
123 | | #endif |