1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
/*
* Curve25519
* (C) 2014 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
#ifndef BOTAN_CURVE_25519_H__
#define BOTAN_CURVE_25519_H__
#include <botan/pk_keys.h>
namespace Botan {
class BOTAN_DLL Curve25519_PublicKey : public virtual Public_Key
{
public:
std::string algo_name() const override { return "Curve25519"; }
size_t estimated_strength() const override { return 128; }
size_t max_input_bits() const override { return 256; }
bool check_key(RandomNumberGenerator& rng, bool strong) const override;
AlgorithmIdentifier algorithm_identifier() const override;
std::vector<byte> x509_subject_public_key() const override;
std::vector<byte> public_value() const { return unlock(m_public); }
/**
* Create a Curve25519 Public Key.
* @param alg_id the X.509 algorithm identifier
* @param key_bits X.509 subject public key info structure
*/
Curve25519_PublicKey(const AlgorithmIdentifier& alg_id,
const secure_vector<byte>& key_bits);
/**
* Create a Curve25519 Public Key.
* @param pub DER encoded public key bits
*/
explicit Curve25519_PublicKey(const secure_vector<byte>& pub) : m_public(pub) {}
protected:
Curve25519_PublicKey() {}
secure_vector<byte> m_public;
};
class BOTAN_DLL Curve25519_PrivateKey : public Curve25519_PublicKey,
public virtual Private_Key,
public virtual PK_Key_Agreement_Key
{
public:
/**
* Construct a private key from the specified parameters.
* @param alg_id the X.509 algorithm identifier
* @param key_bits PKCS #8 structure
* @param rng the RNG to use
*/
Curve25519_PrivateKey(const AlgorithmIdentifier& alg_id,
const secure_vector<byte>& key_bits,
RandomNumberGenerator& rng);
/**
* Generate a private key.
* @param rng the RNG to use
*/
explicit Curve25519_PrivateKey(RandomNumberGenerator& rng);
/**
* Construct a private key from the specified parameters.
* @param secret_key DER encoded private key bits
*/
explicit Curve25519_PrivateKey(const secure_vector<byte>& secret_key);
std::vector<byte> public_value() const override { return Curve25519_PublicKey::public_value(); }
secure_vector<byte> agree(const byte w[], size_t w_len) const;
const secure_vector<byte>& get_x() const { return m_private; }
secure_vector<byte> pkcs8_private_key() const override;
bool check_key(RandomNumberGenerator& rng, bool strong) const override;
std::unique_ptr<PK_Ops::Key_Agreement>
create_key_agreement_op(RandomNumberGenerator& rng,
const std::string& params,
const std::string& provider) const override;
private:
secure_vector<byte> m_private;
};
/*
* The types above are just wrappers for curve25519_donna, plus defining
* encodings for public and private keys.
*/
int BOTAN_DLL curve25519_donna(uint8_t mypublic[32],
const uint8_t secret[32],
const uint8_t basepoint[32]);
}
#endif
|