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