Botan 2.13.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

ed25519.h
Go to the documentation of this file.
1 /*
2 * Ed25519
3 * (C) 2017 Ribose Inc
4 *
5 * Based on the public domain code from SUPERCOP ref10 by
6 * Peter Schwabe, Daniel J. Bernstein, Niels Duif, Tanja Lange, Bo-Yin Yang
7 *
8 * Botan is released under the Simplified BSD License (see license.txt)
9 */
10
11 #ifndef BOTAN_ED25519_H_
12 #define BOTAN_ED25519_H_
13
14 #include <botan/pk_keys.h>
15
16 namespace Botan {
17
18 class BOTAN_PUBLIC_API(2,2) Ed25519_PublicKey : public virtual Public_Key
19 {
20 public:
21 std::string algo_name() const override { return "Ed25519"; }
22
23 size_t estimated_strength() const override { return 128; }
24
25 size_t key_length() const override { return 255; }
26
27 bool check_key(RandomNumberGenerator& rng, bool strong) const override;
28
29 AlgorithmIdentifier algorithm_identifier() const override;
30
31 std::vector<uint8_t> public_key_bits() const override;
32
33 /**
34 * Create a Ed25519 Public Key.
35 * @param alg_id the X.509 algorithm identifier
36 * @param key_bits DER encoded public key bits
37 */
38 Ed25519_PublicKey(const AlgorithmIdentifier& alg_id,
39 const std::vector<uint8_t>& key_bits);
40
41 template<typename Alloc>
42 Ed25519_PublicKey(const std::vector<uint8_t, Alloc>& pub) :
43 Ed25519_PublicKey(pub.data(), pub.size()) {}
44
45 Ed25519_PublicKey(const uint8_t pub_key[], size_t len);
46
47 std::unique_ptr<PK_Ops::Verification>
48 create_verification_op(const std::string& params,
49 const std::string& provider) const override;
50
51 const std::vector<uint8_t>& get_public_key() const { return m_public; }
52
53 protected:
54 Ed25519_PublicKey() = default;
55 std::vector<uint8_t> m_public;
56 };
57
58 class BOTAN_PUBLIC_API(2,2) Ed25519_PrivateKey final : public Ed25519_PublicKey,
59 public virtual Private_Key
60 {
61 public:
62 /**
63 * Construct a private key from the specified parameters.
64 * @param alg_id the X.509 algorithm identifier
65 * @param key_bits PKCS #8 structure
66 */
67 Ed25519_PrivateKey(const AlgorithmIdentifier& alg_id,
68 const secure_vector<uint8_t>& key_bits);
69
70 /**
71 * Generate a private key.
72 * @param rng the RNG to use
73 */
74 explicit Ed25519_PrivateKey(RandomNumberGenerator& rng);
75
76 /**
77 * Construct a private key from the specified parameters.
78 * @param secret_key the private key
79 */
80 explicit Ed25519_PrivateKey(const secure_vector<uint8_t>& secret_key);
81
82 const secure_vector<uint8_t>& get_private_key() const { return m_private; }
83
84 secure_vector<uint8_t> private_key_bits() const override;
85
86 bool check_key(RandomNumberGenerator& rng, bool strong) const override;
87
88 std::unique_ptr<PK_Ops::Signature>
89 create_signature_op(RandomNumberGenerator& rng,
90 const std::string& params,
91 const std::string& provider) const override;
92
93 private:
94 secure_vector<uint8_t> m_private;
95 };
96
97 void ed25519_gen_keypair(uint8_t pk[32], uint8_t sk[64], const uint8_t seed[32]);
98
99 void ed25519_sign(uint8_t sig[64],
100 const uint8_t msg[],
101 size_t msg_len,
102 const uint8_t sk[64],
103 const uint8_t domain_sep[], size_t domain_sep_len);
104
105 bool ed25519_verify(const uint8_t msg[],
106 size_t msg_len,
107 const uint8_t sig[64],
108 const uint8_t pk[32],
109 const uint8_t domain_sep[], size_t domain_sep_len);
110
111 }
112
113 #endif
Botan::ed25519_gen_keypair
void ed25519_gen_keypair(uint8_t *pk, uint8_t *sk, const uint8_t seed[32])
Definition: ed25519.cpp:18
Botan::Ed25519_PublicKey::m_public
std::vector< uint8_t > m_public
Definition: ed25519.h:55
Botan::Ed25519_PublicKey::algo_name
std::string algo_name() const override
Definition: ed25519.h:21
Botan::Ed25519_PublicKey
Definition: ed25519.h:18
Botan::RandomNumberGenerator
Definition: rng.h:24
Botan::Ed25519_PublicKey::estimated_strength
size_t estimated_strength() const override
Definition: ed25519.h:23
Botan::Private_Key
Definition: pk_keys.h:181
m_public
std::shared_ptr< const RSA_Public_Data > m_public
Definition: rsa.cpp:453
final
int(* final)(unsigned char *, CTX *)
Definition: commoncrypto_hash.cpp:28
Botan::Ed25519_PublicKey::Ed25519_PublicKey
Ed25519_PublicKey(const std::vector< uint8_t, Alloc > &pub)
Definition: ed25519.h:42
BOTAN_PUBLIC_API
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
Botan::Ed25519_PublicKey::key_length
size_t key_length() const override
Definition: ed25519.h:25
Botan::secure_vector
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:65
m_private
std::shared_ptr< const RSA_Private_Data > m_private
Definition: rsa.cpp:454
Botan::Ed25519_PrivateKey
Definition: ed25519.h:58
Botan
Definition: alg_id.cpp:13
Botan::Public_Key
Definition: pk_keys.h:29
Botan::AlgorithmIdentifier
Definition: alg_id.h:21
Botan::ed25519_verify
bool ed25519_verify(const uint8_t *m, size_t mlen, const uint8_t sig[64], const uint8_t *pk, const uint8_t domain_sep[], size_t domain_sep_len)
Definition: ed25519.cpp:71
Botan::Ed25519_PrivateKey::get_private_key
const secure_vector< uint8_t > & get_private_key() const
Definition: ed25519.h:82
Botan::Ed25519_PublicKey::get_public_key
const std::vector< uint8_t > & get_public_key() const
Definition: ed25519.h:51
Botan::ed25519_sign
void ed25519_sign(uint8_t sig[64], const uint8_t m[], size_t mlen, const uint8_t sk[64], const uint8_t domain_sep[], size_t domain_sep_len)
Definition: ed25519.cpp:36