Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

curve25519.h
Go to the documentation of this file.
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_DLL Curve25519_PublicKey : public virtual Public_Key
16 {
17 public:
18 std::string algo_name() const override { return "Curve25519"; }
19
20 size_t estimated_strength() const override { return 128; }
21
22 size_t key_length() const override { return 255; }
23
24 bool check_key(RandomNumberGenerator& rng, bool strong) const override;
25
26 AlgorithmIdentifier algorithm_identifier() const override;
27
28 std::vector<uint8_t> public_key_bits() const override;
29
30 std::vector<uint8_t> public_value() const { return m_public; }
31
32 /**
33 * Create a Curve25519 Public Key.
34 * @param alg_id the X.509 algorithm identifier
35 * @param key_bits DER encoded public key bits
36 */
37 Curve25519_PublicKey(const AlgorithmIdentifier& alg_id,
38 const std::vector<uint8_t>& key_bits);
39
40 /**
41 * Create a Curve25519 Public Key.
42 * @param pub 32-byte raw public key
43 */
44 explicit Curve25519_PublicKey(const std::vector<uint8_t>& pub) : m_public(pub) {}
45
46 /**
47 * Create a Curve25519 Public Key.
48 * @param pub 32-byte raw public key
49 */
50 explicit Curve25519_PublicKey(const secure_vector<uint8_t>& pub) :
51 m_public(pub.begin(), pub.end()) {}
52
53 protected:
54 Curve25519_PublicKey() = default;
55 std::vector<uint8_t> m_public;
56 };
57
58 class BOTAN_DLL Curve25519_PrivateKey : public Curve25519_PublicKey,
59 public virtual Private_Key,
60 public virtual PK_Key_Agreement_Key
61 {
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 Curve25519_PrivateKey(const AlgorithmIdentifier& alg_id,
69 const secure_vector<uint8_t>& key_bits);
70
71 /**
72 * Generate a private key.
73 * @param rng the RNG to use
74 */
75 explicit Curve25519_PrivateKey(RandomNumberGenerator& rng);
76
77 /**
78 * Construct a private key from the specified parameters.
79 * @param secret_key DER encoded private key bits
80 */
81 explicit Curve25519_PrivateKey(const secure_vector<uint8_t>& secret_key);
82
83 std::vector<uint8_t> public_value() const override { return Curve25519_PublicKey::public_value(); }
84
85 secure_vector<uint8_t> agree(const uint8_t w[], size_t w_len) const;
86
87 const secure_vector<uint8_t>& get_x() const { return m_private; }
88
89 secure_vector<uint8_t> private_key_bits() const override;
90
91 bool check_key(RandomNumberGenerator& rng, bool strong) const override;
92
93 std::unique_ptr<PK_Ops::Key_Agreement>
94 create_key_agreement_op(RandomNumberGenerator& rng,
95 const std::string& params,
96 const std::string& provider) const override;
97
98 private:
99 secure_vector<uint8_t> m_private;
100 };
101
102 /*
103 * The types above are just wrappers for curve25519_donna, plus defining
104 * encodings for public and private keys.
105 */
106 void BOTAN_DLL curve25519_donna(uint8_t mypublic[32],
107 const uint8_t secret[32],
108 const uint8_t basepoint[32]);
109
110 /**
111 * Exponentiate by the x25519 base point
112 * @param mypublic output value
113 * @param secret random scalar
114 */
115 void BOTAN_DLL curve25519_basepoint(uint8_t mypublic[32],
116 const uint8_t secret[32]);
117
118 }
119
120 #endif
Botan::Curve25519_PublicKey::Curve25519_PublicKey
Curve25519_PublicKey(const secure_vector< uint8_t > &pub)
Definition: curve25519.h:50
Botan::Curve25519_PrivateKey::get_x
const secure_vector< uint8_t > & get_x() const
Definition: curve25519.h:87
Botan::Curve25519_PublicKey::algo_name
std::string algo_name() const override
Definition: curve25519.h:18
Botan::RandomNumberGenerator
Definition: rng.h:25
Botan::Private_Key
Definition: pk_keys.h:166
Botan::Curve25519_PublicKey::key_length
size_t key_length() const override
Definition: curve25519.h:22
Botan::Curve25519_PublicKey::estimated_strength
size_t estimated_strength() const override
Definition: curve25519.h:20
Botan::Curve25519_PublicKey::public_value
std::vector< uint8_t > public_value() const
Definition: curve25519.h:30
Botan::secure_vector
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:121
Botan::Curve25519_PublicKey
Definition: curve25519.h:15
Botan
Definition: alg_id.cpp:13
Botan::Curve25519_PublicKey::m_public
std::vector< uint8_t > m_public
Definition: curve25519.h:55
Botan::Public_Key
Definition: pk_keys.h:24
Botan::curve25519_basepoint
void curve25519_basepoint(uint8_t mypublic[32], const uint8_t secret[32])
Definition: curve25519.cpp:15
Botan::PK_Key_Agreement_Key
Definition: pk_keys.h:271
Botan::Curve25519_PublicKey::Curve25519_PublicKey
Curve25519_PublicKey(const std::vector< uint8_t > &pub)
Definition: curve25519.h:44
Botan::Curve25519_PrivateKey
Definition: curve25519.h:58
Botan::Curve25519_PrivateKey::public_value
std::vector< uint8_t > public_value() const override
Definition: curve25519.h:83
Botan::AlgorithmIdentifier
Definition: alg_id.h:20
Botan::curve25519_donna
void BOTAN_DLL curve25519_donna(uint8_t mypublic[32], const uint8_t secret[32], const uint8_t basepoint[32])