/src/Botan-3.4.0/build/include/public/botan/ed25519.h
Line | Count | Source (jump to first uncovered line) |
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 | | public: |
20 | 0 | std::string algo_name() const override { return "Ed25519"; } |
21 | | |
22 | 0 | size_t estimated_strength() const override { return 128; } |
23 | | |
24 | 0 | 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 | 0 | bool supports_operation(PublicKeyOperation op) const override { return (op == PublicKeyOperation::Signature); } |
35 | | |
36 | 60.2k | 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 | 60.2k | 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 | 0 | Ed25519_PublicKey() = default; |
58 | | std::vector<uint8_t> m_public; |
59 | | }; |
60 | | |
61 | | BOTAN_DIAGNOSTIC_PUSH |
62 | | BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE |
63 | | |
64 | | class BOTAN_PUBLIC_API(2, 2) Ed25519_PrivateKey final : public Ed25519_PublicKey, |
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 | | */ |
78 | | explicit Ed25519_PrivateKey(RandomNumberGenerator& rng); |
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 | 0 | const secure_vector<uint8_t>& get_private_key() const { return m_private; } |
89 | | |
90 | 0 | 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 | | |
106 | | BOTAN_DIAGNOSTIC_POP |
107 | | |
108 | | void ed25519_gen_keypair(uint8_t pk[32], uint8_t sk[64], const uint8_t seed[32]); |
109 | | |
110 | | void 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 | | |
117 | | bool 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 |