Botan 3.0.0
Crypto and TLS for C&
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
16namespace Botan {
17
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 bool supports_operation(PublicKeyOperation op) const override
34 {
35 return (op == PublicKeyOperation::Signature);
36 }
37
38 const std::vector<uint8_t>& get_public_key() const { return m_public; }
39
40 /**
41 * Create a Ed25519 Public Key.
42 * @param alg_id the X.509 algorithm identifier
43 * @param key_bits DER encoded public key bits
44 */
46 std::span<const uint8_t> key_bits);
47
48 template<typename Alloc>
49 Ed25519_PublicKey(const std::vector<uint8_t, Alloc>& pub) :
50 Ed25519_PublicKey(pub.data(), pub.size()) {}
51
52 Ed25519_PublicKey(const uint8_t pub_key[], size_t len);
53
54 std::unique_ptr<PK_Ops::Verification>
55 create_verification_op(std::string_view params,
56 std::string_view provider) const override;
57
58 std::unique_ptr<PK_Ops::Verification>
59 create_x509_verification_op(const AlgorithmIdentifier& signature_algorithm,
60 std::string_view provider) const override;
61 protected:
62 Ed25519_PublicKey() = default;
63 std::vector<uint8_t> m_public;
64 };
65
68
70 public virtual Private_Key
71 {
72 public:
73 /**
74 * Construct a private key from the specified parameters.
75 * @param alg_id the X.509 algorithm identifier
76 * @param key_bits PKCS #8 structure
77 */
79 std::span<const uint8_t> key_bits);
80
81 /**
82 * Generate a private key.
83 * @param rng the RNG to use
84 */
86
87 /**
88 * Construct a private key from the specified parameters.
89 * @param secret_key the private key
90 */
91 explicit Ed25519_PrivateKey(const secure_vector<uint8_t>& secret_key);
92
93 BOTAN_DEPRECATED("Use raw_private_key_bits")
94 const secure_vector<uint8_t>& get_private_key() const { return m_private; }
95
96 secure_vector<uint8_t> raw_private_key_bits() const override { return m_private; }
97
98 secure_vector<uint8_t> private_key_bits() const override;
99
100 std::unique_ptr<Public_Key> public_key() const override;
101
102 bool check_key(RandomNumberGenerator& rng, bool strong) const override;
103
104 std::unique_ptr<PK_Ops::Signature>
105 create_signature_op(RandomNumberGenerator& rng,
106 std::string_view params,
107 std::string_view provider) const override;
108
109 private:
110 secure_vector<uint8_t> m_private;
111 };
112
114
115void ed25519_gen_keypair(uint8_t pk[32], uint8_t sk[64], const uint8_t seed[32]);
116
117void ed25519_sign(uint8_t sig[64],
118 const uint8_t msg[],
119 size_t msg_len,
120 const uint8_t sk[64],
121 const uint8_t domain_sep[], size_t domain_sep_len);
122
123bool ed25519_verify(const uint8_t msg[],
124 size_t msg_len,
125 const uint8_t sig[64],
126 const uint8_t pk[32],
127 const uint8_t domain_sep[], size_t domain_sep_len);
128
129}
130
131#endif
secure_vector< uint8_t > raw_private_key_bits() const override
Definition: ed25519.h:96
std::vector< uint8_t > m_public
Definition: ed25519.h:63
Ed25519_PublicKey(const std::vector< uint8_t, Alloc > &pub)
Definition: ed25519.h:49
const std::vector< uint8_t > & get_public_key() const
Definition: ed25519.h:38
std::string algo_name() const override
Definition: ed25519.h:21
bool supports_operation(PublicKeyOperation op) const override
Definition: ed25519.h:33
size_t key_length() const override
Definition: ed25519.h:25
size_t estimated_strength() const override
Definition: ed25519.h:23
int(* final)(unsigned char *, CTX *)
#define BOTAN_DIAGNOSTIC_POP
Definition: compiler.h:204
#define BOTAN_DIAGNOSTIC_PUSH
Definition: compiler.h:201
#define BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE
Definition: compiler.h:203
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
Definition: alg_id.cpp:12
PublicKeyOperation
Definition: pk_keys.h:43
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
void ed25519_gen_keypair(uint8_t *pk, uint8_t *sk, const uint8_t seed[32])
Definition: ed25519.cpp:18
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
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:64