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