Botan 3.6.1
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> raw_public_key_bits() const override;
31
32 std::vector<uint8_t> public_key_bits() const override;
33
34 std::unique_ptr<Private_Key> generate_another(RandomNumberGenerator& rng) const final;
35
36 bool supports_operation(PublicKeyOperation op) const override { return (op == PublicKeyOperation::Signature); }
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 */
45 Ed25519_PublicKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits);
46
47 Ed25519_PublicKey(std::span<const uint8_t> pub) : Ed25519_PublicKey(pub.data(), pub.size()) {}
48
49 Ed25519_PublicKey(const uint8_t pub_key[], size_t len);
50
51 std::unique_ptr<PK_Ops::Verification> create_verification_op(std::string_view params,
52 std::string_view provider) const override;
53
54 std::unique_ptr<PK_Ops::Verification> create_x509_verification_op(const AlgorithmIdentifier& signature_algorithm,
55 std::string_view provider) const override;
56
57 protected:
58 Ed25519_PublicKey() = default;
59 std::vector<uint8_t> m_public;
60};
61
64
66 public virtual Private_Key {
67 public:
68 /**
69 * Construct a private key from the specified parameters.
70 * @param alg_id the X.509 algorithm identifier
71 * @param key_bits PKCS #8 structure
72 */
73 Ed25519_PrivateKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits);
74
75 /**
76 * Generate a private key.
77 * @param rng the RNG to use
78 */
80
81 /**
82 * Construct a private key from the specified parameters.
83 * @param secret_key the private key
84 */
85 explicit Ed25519_PrivateKey(const secure_vector<uint8_t>& secret_key);
86
87 BOTAN_DEPRECATED("Use raw_private_key_bits") const secure_vector<uint8_t>& get_private_key() const {
88 return m_private;
89 }
90
91 secure_vector<uint8_t> raw_private_key_bits() const override { return m_private; }
92
93 secure_vector<uint8_t> private_key_bits() const override;
94
95 std::unique_ptr<Public_Key> public_key() const override;
96
97 bool check_key(RandomNumberGenerator& rng, bool strong) const override;
98
99 std::unique_ptr<PK_Ops::Signature> create_signature_op(RandomNumberGenerator& rng,
100 std::string_view params,
101 std::string_view provider) const override;
102
103 private:
104 secure_vector<uint8_t> m_private;
105};
106
108
109void ed25519_gen_keypair(uint8_t pk[32], uint8_t sk[64], const uint8_t seed[32]);
110
111void ed25519_sign(uint8_t sig[64],
112 const uint8_t msg[],
113 size_t msg_len,
114 const uint8_t sk[64],
115 const uint8_t domain_sep[],
116 size_t domain_sep_len);
117
118bool ed25519_verify(const uint8_t msg[],
119 size_t msg_len,
120 const uint8_t sig[64],
121 const uint8_t pk[32],
122 const uint8_t domain_sep[],
123 size_t domain_sep_len);
124
125} // namespace Botan
126
127#endif
secure_vector< uint8_t > raw_private_key_bits() const override
Definition ed25519.h:91
std::vector< uint8_t > m_public
Definition ed25519.h:59
const std::vector< uint8_t > & get_public_key() const
Definition ed25519.h:38
std::string algo_name() const override
Definition ed25519.h:20
bool supports_operation(PublicKeyOperation op) const override
Definition ed25519.h:36
size_t key_length() const override
Definition ed25519.h:24
size_t estimated_strength() const override
Definition ed25519.h:22
Ed25519_PublicKey(std::span< const uint8_t > pub)
Definition ed25519.h:47
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