/src/botan/build/include/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 | | { |
20 | | public: |
21 | 163 | std::string algo_name() const override { return "Ed25519"; } |
22 | | |
23 | 0 | size_t estimated_strength() const override { return 128; } |
24 | | |
25 | 0 | 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 | 70 | const std::vector<uint8_t>& get_public_key() const { return m_public; } |
52 | | |
53 | | protected: |
54 | 7 | 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 | 0 | 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 |