Botan 3.14.1
Crypto and TLS for C&
ed25519_key.cpp
Go to the documentation of this file.
1/*
2* Ed25519
3* (C) 2017 Ribose Inc
4* 2025 Jack Lloyd
5*
6* Botan is released under the Simplified BSD License (see license.txt)
7*/
8
9#include <botan/ed25519.h>
10
11#include <botan/ber_dec.h>
12#include <botan/der_enc.h>
13#include <botan/hash.h>
14#include <botan/mem_ops.h>
15#include <botan/pk_options_readers.h>
16#include <botan/pubkey.h>
17#include <botan/rng.h>
18#include <botan/internal/ct_utils.h>
19#include <botan/internal/ed25519_internal.h>
20#include <botan/internal/pk_ops_impl.h>
21#include <botan/internal/pk_options_impl.h>
22#include <array>
23
24namespace Botan {
25
26class Ed25519_PublicKey_Data final {
27 public:
28 explicit Ed25519_PublicKey_Data(std::vector<uint8_t> key) : m_key(std::move(key)) {}
29
30 const std::vector<uint8_t>& key() const { return m_key; }
31
32 private:
33 std::vector<uint8_t> m_key;
34};
35
36class Ed25519_PrivateKey_Data final {
37 public:
38 explicit Ed25519_PrivateKey_Data(secure_vector<uint8_t> key) : m_key(std::move(key)) {}
39
40 const secure_vector<uint8_t>& key() const { return m_key; }
41
42 private:
44};
45
46const std::vector<uint8_t>& Ed25519_PublicKey::get_public_key() const {
47 return m_public->key();
48}
49
51 return m_private->key();
52}
53
55 return m_private->key();
56}
57
61
62bool Ed25519_PublicKey::check_key(RandomNumberGenerator& /*rng*/, bool /*strong*/) const {
63 // All possible checks are performed when the key is decoded
64 return true;
65}
66
67namespace {
68
69std::shared_ptr<const Ed25519_PublicKey_Data> load_ed25519_public_key(std::span<const uint8_t> key_bits) {
70 if(key_bits.size() != 32) {
71 throw Decoding_Error("Invalid size for Ed25519 public key");
72 }
73
74 // Rejects the identity, other points of small order, and points outside
75 // the prime order subgroup, so that no later check is needed
76 if(!ed25519_valid_public_key_point(key_bits.first<32>())) {
77 throw Decoding_Error("Invalid Ed25519 public key");
78 }
79
80 return std::make_shared<const Ed25519_PublicKey_Data>(std::vector<uint8_t>(key_bits.begin(), key_bits.end()));
81}
82
83} // namespace
84
85Ed25519_PublicKey::Ed25519_PublicKey(const uint8_t pub_key[], size_t pub_len) {
86 m_public = load_ed25519_public_key(std::span<const uint8_t>{pub_key, pub_len});
87}
88
89Ed25519_PublicKey::Ed25519_PublicKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits) {
90 // RFC 8410 Section 3: "the parameters MUST be absent".
91 if(!alg_id.parameters_are_empty()) {
92 throw Decoding_Error("Unexpected parameters for Ed25519 public key");
93 }
94
95 m_public = load_ed25519_public_key(key_bits);
96}
97
98std::vector<uint8_t> Ed25519_PublicKey::raw_public_key_bits() const {
99 return m_public->key();
100}
101
102std::vector<uint8_t> Ed25519_PublicKey::public_key_bits() const {
103 return raw_public_key_bits();
104}
105
106std::unique_ptr<Private_Key> Ed25519_PublicKey::generate_another(RandomNumberGenerator& rng) const {
107 return std::make_unique<Ed25519_PrivateKey>(rng);
108}
109
110namespace {
111
112// Given the 64-byte expanded private key (32-byte private seed followed by the
113// 32-byte public key) build the immutable public and private key data objects.
114void load_ed25519_keypair(secure_vector<uint8_t> expanded_key,
115 std::shared_ptr<const Ed25519_PublicKey_Data>& pk_out,
116 std::shared_ptr<const Ed25519_PrivateKey_Data>& sk_out) {
117 BOTAN_ASSERT_NOMSG(expanded_key.size() == 64);
118 pk_out = std::make_shared<const Ed25519_PublicKey_Data>(
119 std::vector<uint8_t>(expanded_key.begin() + 32, expanded_key.end()));
120 sk_out = std::make_shared<const Ed25519_PrivateKey_Data>(std::move(expanded_key));
121}
122
123/*
124* Return the secret scalar, derived by hashing the seed and clamping
125* (RFC 8032 5.1.5)
126*/
127Ed25519_Scalar ed25519_secret_scalar(HashFunction& sha512, std::span<const uint8_t> seed) {
128 std::array<uint8_t, 64> az{};
129 sha512.update(seed);
130 sha512.final(az);
131 az[0] &= 248;
132 az[31] &= 63;
133 az[31] |= 64;
134
135 const auto a = Ed25519_Scalar::from_bytes(std::span{az}.first<32>());
137 return a;
138}
139
140// Generate the 64-byte expanded private key from a 32-byte seed.
141secure_vector<uint8_t> ed25519_expand_seed(std::span<const uint8_t> seed) {
142 BOTAN_ASSERT_NOMSG(seed.size() == 32);
143
145 copy_mem(sk.data(), seed.data(), 32);
146 const auto sk_seed = std::span{sk}.first<32>();
147 CT::poison(sk_seed);
148
149 auto sha512 = HashFunction::create_or_throw("SHA-512");
150 const auto a = ed25519_secret_scalar(*sha512, sk_seed);
151
152 ed25519_basepoint_mul(std::span<uint8_t, 32>{sk.data() + 32, 32}, a);
153 CT::unpoison(sk);
154 return sk;
155}
156
157} // namespace
158
159Ed25519_PrivateKey::Ed25519_PrivateKey(std::span<const uint8_t> secret_key) {
160 if(secret_key.size() == 64) {
161 // Signing hashes the stored public key into the challenge, so a public
162 // key other than the one derived from the seed would leak the secret
163 // scalar. Regenerate it and reject any mismatch.
164 auto expanded = ed25519_expand_seed(secret_key.first(32));
165 if(!CT::is_equal(expanded.data() + 32, secret_key.data() + 32, 32).as_bool()) {
166 throw Decoding_Error("Ed25519 public key does not match the private key");
167 }
168 load_ed25519_keypair(std::move(expanded), m_public, m_private);
169 } else if(secret_key.size() == 32) {
170 load_ed25519_keypair(ed25519_expand_seed(secret_key), m_public, m_private);
171 } else {
172 throw Decoding_Error("Invalid size for Ed25519 private key");
173 }
174}
175
176//static
177Ed25519_PrivateKey Ed25519_PrivateKey::from_seed(std::span<const uint8_t> seed) {
178 if(seed.size() != 32) {
179 throw Decoding_Error("Ed25519 seed must be exactly 32 bytes long");
180 }
181 return Ed25519_PrivateKey(seed);
182}
183
184//static
185Ed25519_PrivateKey Ed25519_PrivateKey::from_bytes(std::span<const uint8_t> bytes) {
186 if(bytes.size() != 64) {
187 throw Decoding_Error("Ed25519 private key must be exactly 64 bytes long");
188 }
189 return Ed25519_PrivateKey(bytes);
190}
191
193 const secure_vector<uint8_t> seed = rng.random_vec(32);
194 load_ed25519_keypair(ed25519_expand_seed(seed), m_public, m_private);
195}
196
197Ed25519_PrivateKey::Ed25519_PrivateKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits) {
198 // RFC 8410 Section 3: "the parameters MUST be absent".
199 if(!alg_id.parameters_are_empty()) {
200 throw Decoding_Error("Unexpected parameters for Ed25519 private key");
201 }
202
205
206 if(bits.size() != 32) {
207 throw Decoding_Error("Invalid size for Ed25519 private key");
208 }
209 load_ed25519_keypair(ed25519_expand_seed(bits), m_public, m_private);
210}
211
212std::unique_ptr<Public_Key> Ed25519_PrivateKey::public_key() const {
213 return std::unique_ptr<Ed25519_PublicKey>(new Ed25519_PublicKey(m_public));
214}
215
217 const auto& priv = m_private->key();
218 const secure_vector<uint8_t> bits(priv.begin(), priv.begin() + 32);
220}
221
222bool Ed25519_PrivateKey::check_key(RandomNumberGenerator& /*rng*/, bool /*strong*/) const {
223 const auto& priv = m_private->key();
224 const auto regen = ed25519_expand_seed(std::span<const uint8_t>{priv.data(), 32});
225 // Variable time comparison is fine here
226 return std::vector<uint8_t>(regen.begin() + 32, regen.end()) == m_public->key();
227}
228
229namespace {
230
231/*
232* The dom2 prefix for Ed25519ph (RFC 8032 sections 2 and 5.1), with
233* phflag 1 and an empty context
234*/
235std::vector<uint8_t> ed25519ph_domain_sep() {
236 constexpr std::string_view prefix = "SigEd25519 no Ed25519 collisions";
237 std::vector<uint8_t> ds(prefix.begin(), prefix.end());
238 ds.push_back(0x01);
239 ds.push_back(0x00);
240 return ds;
241}
242
243/**
244* Ed25519 verification, following RFC 8032 5.1.7
245*
246* Subclasses determine the message that is verified and the domain
247* separator prepended to the hash inputs.
248*/
249class Ed25519_Verify_Operation_Base : public PK_Ops::Verification {
250 protected:
251 Ed25519_Verify_Operation_Base(std::shared_ptr<const Ed25519_PublicKey_Data> key,
252 std::vector<uint8_t> domain_sep) :
253 m_key(std::move(key)), m_domain_sep(std::move(domain_sep)) {
254 BOTAN_ASSERT_EQUAL(m_key->key().size(), 32, "Expected size");
255 }
256
257 bool verify_signature(std::span<const uint8_t> msg, std::span<const uint8_t, 64> sig) const {
258 const auto& pk = m_key->key();
259
260 // RFC 8032 adds the requirement that we verify that s < order in
261 // the signature; this did not exist in the original Ed25519 spec.
262 const auto s = Ed25519_Scalar::from_canonical_bytes(sig.last<32>());
263 if(!s) {
264 return false;
265 }
266
267 std::array<uint8_t, 64> hram{};
268 auto sha512 = HashFunction::create_or_throw("SHA-512");
269
270 sha512->update(m_domain_sep);
271 sha512->update(sig.data(), 32);
272 sha512->update(pk);
273 sha512->update(msg);
274 sha512->final(hram);
275
276 const auto h = Ed25519_Scalar::from_wide_bytes(hram);
277
278 return ed25519_check_signature(std::span<const uint8_t, 32>{pk.data(), 32}, h, sig.data(), *s);
279 }
280
281 private:
282 std::shared_ptr<const Ed25519_PublicKey_Data> m_key;
283 std::vector<uint8_t> m_domain_sep;
284};
285
286/**
287* Ed25519 verifying operation
288*/
289class Ed25519_Pure_Verify_Operation final : public Ed25519_Verify_Operation_Base {
290 public:
291 explicit Ed25519_Pure_Verify_Operation(std::shared_ptr<const Ed25519_PublicKey_Data> key,
292 std::vector<uint8_t> domain_sep = {}) :
293 Ed25519_Verify_Operation_Base(std::move(key), std::move(domain_sep)) {}
294
295 void update(std::span<const uint8_t> msg) override { m_msg.insert(m_msg.end(), msg.begin(), msg.end()); }
296
297 bool is_valid_signature(std::span<const uint8_t> sig) override {
298 if(sig.size() != 64) {
299 m_msg.clear();
300 return false;
301 }
302
303 const bool ok = verify_signature(m_msg, sig.first<64>());
304 m_msg.clear();
305 return ok;
306 }
307
308 std::string hash_function() const override { return "SHA-512"; }
309
310 private:
311 std::vector<uint8_t> m_msg;
312};
313
314/**
315* Ed25519 verifying operation with pre-hash
316*/
317class Ed25519_Hashed_Verify_Operation final : public Ed25519_Verify_Operation_Base {
318 public:
319 Ed25519_Hashed_Verify_Operation(std::shared_ptr<const Ed25519_PublicKey_Data> key,
320 std::string_view hash,
321 bool rfc8032) :
322 Ed25519_Verify_Operation_Base(std::move(key), rfc8032 ? ed25519ph_domain_sep() : std::vector<uint8_t>{}),
323 m_hash(HashFunction::create_or_throw(hash)) {}
324
325 void update(std::span<const uint8_t> msg) override { m_hash->update(msg); }
326
327 bool is_valid_signature(std::span<const uint8_t> sig) override {
328 std::vector<uint8_t> msg_hash(m_hash->output_length());
329 m_hash->final(msg_hash.data());
330
331 if(sig.size() != 64) {
332 return false;
333 }
334
335 return verify_signature(msg_hash, sig.first<64>());
336 }
337
338 std::string hash_function() const override { return m_hash->name(); }
339
340 private:
341 std::unique_ptr<HashFunction> m_hash;
342};
343
344/**
345* Ed25519 signing, following RFC 8032 5.1.6
346*
347* Subclasses determine the message that is signed and the domain
348* separator prepended to the hash inputs.
349*/
350class Ed25519_Sign_Operation_Base : public PK_Ops::Signature {
351 public:
352 size_t signature_length() const override { return 64; }
353
354 protected:
355 Ed25519_Sign_Operation_Base(std::shared_ptr<const Ed25519_PrivateKey_Data> key, std::vector<uint8_t> domain_sep) :
356 m_key(std::move(key)), m_domain_sep(std::move(domain_sep)) {
357 BOTAN_ASSERT_EQUAL(m_key->key().size(), 64, "Expected size");
358 }
359
360 std::vector<uint8_t> sign_message(std::span<const uint8_t> msg) const {
361 const auto& sk = m_key->key();
362 const auto seed = std::span{sk}.first<32>();
363 const auto scope = CT::scoped_poison(seed);
364
365 std::vector<uint8_t> sig_buf(64);
366 const std::span<uint8_t, 64> sig(sig_buf.data(), 64);
367
368 std::array<uint8_t, 64> hram{};
369
370 auto sha512 = HashFunction::create_or_throw("SHA-512");
371
372 sha512->update(sk.data(), 32);
373 std::array<uint8_t, 64> az{};
374 sha512->final(az);
375 az[0] &= 248;
376 az[31] &= 63;
377 az[31] |= 64;
378
379 const auto a = Ed25519_Scalar::from_bytes(std::span{az}.first<32>());
380
381 std::array<uint8_t, 64> nonce{};
382 sha512->update(m_domain_sep);
383 sha512->update(std::span{az}.last(32));
384 sha512->update(msg);
385 sha512->final(nonce);
386
387 const auto r = Ed25519_Scalar::from_wide_bytes(nonce);
388 ed25519_basepoint_mul(sig.first<32>(), r);
389
390 sha512->update(m_domain_sep);
391 sha512->update(sig.first(32));
392 sha512->update(sk.data() + 32, 32);
393 sha512->update(msg);
394 sha512->final(hram);
395
396 const auto h = Ed25519_Scalar::from_wide_bytes(hram);
397
398 const auto s = h * a + r;
399 s.serialize_to(sig.last<32>());
400
402 secure_scrub_memory(nonce);
403
404 CT::unpoison(sig_buf);
405 return sig_buf;
406 }
407
408 private:
409 std::shared_ptr<const Ed25519_PrivateKey_Data> m_key;
410 std::vector<uint8_t> m_domain_sep;
411};
412
413/**
414* Ed25519 signing operation ('pure' - signs message directly)
415*/
416class Ed25519_Pure_Sign_Operation final : public Ed25519_Sign_Operation_Base {
417 public:
418 explicit Ed25519_Pure_Sign_Operation(std::shared_ptr<const Ed25519_PrivateKey_Data> key,
419 std::vector<uint8_t> domain_sep = {}) :
420 Ed25519_Sign_Operation_Base(std::move(key), std::move(domain_sep)) {}
421
422 void update(std::span<const uint8_t> msg) override { m_msg.insert(m_msg.end(), msg.begin(), msg.end()); }
423
424 std::vector<uint8_t> sign(RandomNumberGenerator& /*rng*/) override {
425 auto sig = sign_message(m_msg);
426 m_msg.clear();
427 return sig;
428 }
429
430 AlgorithmIdentifier algorithm_identifier() const override;
431
432 std::string hash_function() const override { return "SHA-512"; }
433
434 private:
435 std::vector<uint8_t> m_msg;
436};
437
438AlgorithmIdentifier Ed25519_Pure_Sign_Operation::algorithm_identifier() const {
439 return AlgorithmIdentifier(OID::from_string("Ed25519"), AlgorithmIdentifier::USE_EMPTY_PARAM);
440}
441
442/**
443* Ed25519 signing operation with pre-hash
444*/
445class Ed25519_Hashed_Sign_Operation final : public Ed25519_Sign_Operation_Base {
446 public:
447 Ed25519_Hashed_Sign_Operation(std::shared_ptr<const Ed25519_PrivateKey_Data> key,
448 std::string_view hash,
449 bool rfc8032) :
450 Ed25519_Sign_Operation_Base(std::move(key), rfc8032 ? ed25519ph_domain_sep() : std::vector<uint8_t>{}),
451 m_hash(HashFunction::create_or_throw(hash)) {}
452
453 void update(std::span<const uint8_t> msg) override { m_hash->update(msg); }
454
455 std::vector<uint8_t> sign(RandomNumberGenerator& /*rng*/) override {
456 std::vector<uint8_t> msg_hash(m_hash->output_length());
457 m_hash->final(msg_hash.data());
458 return sign_message(msg_hash);
459 }
460
461 std::string hash_function() const override { return m_hash->name(); }
462
463 private:
464 std::unique_ptr<HashFunction> m_hash;
465};
466
467} // namespace
468
469std::unique_ptr<PK_Ops::Verification> Ed25519_PublicKey::_create_verification_op(
470 const PK_Signature_Options_Reader& options) const {
472
473 if(options.using_prehash()) {
474 if(options.prehash_function().has_value()) {
475 return std::make_unique<Ed25519_Hashed_Verify_Operation>(m_public, options.prehash_function().value(), false);
476 } else {
477 return std::make_unique<Ed25519_Hashed_Verify_Operation>(m_public, "SHA-512", true);
478 }
479 } else {
480 return std::make_unique<Ed25519_Pure_Verify_Operation>(m_public);
481 }
482}
483
484std::unique_ptr<PK_Ops::Verification> Ed25519_PublicKey::create_x509_verification_op(const AlgorithmIdentifier& alg_id,
485 std::string_view provider) const {
486 if(provider == "base" || provider.empty()) {
487 if(alg_id != this->algorithm_identifier()) {
488 throw Decoding_Error("Unexpected AlgorithmIdentifier for Ed25519 X509 signature");
489 }
490
491 return std::make_unique<Ed25519_Pure_Verify_Operation>(m_public);
492 }
493 throw Provider_Not_Found(algo_name(), provider);
494}
495
496std::unique_ptr<PK_Ops::Signature> Ed25519_PrivateKey::_create_signature_op(
497 RandomNumberGenerator& rng, const PK_Signature_Options_Reader& options) const {
498 BOTAN_UNUSED(rng);
499
501
503
504 if(options.using_prehash()) {
505 if(options.prehash_function().has_value()) {
506 return std::make_unique<Ed25519_Hashed_Sign_Operation>(m_private, options.prehash_function().value(), false);
507 } else {
508 return std::make_unique<Ed25519_Hashed_Sign_Operation>(m_private, "SHA-512", true);
509 }
510 } else {
511 return std::make_unique<Ed25519_Pure_Sign_Operation>(m_private);
512 }
513}
514
515/*
516* The deprecated ref10 style interface, now defined via the standard
517* interfaces. An empty domain separator is ordinary Ed25519; there is no
518* standard way to request an arbitrary domain separator, so that case
519* drives the operation directly.
520*/
521
522void ed25519_gen_keypair(uint8_t pk[32], uint8_t sk[64], const uint8_t seed[32]) {
523 const auto key = Ed25519_PrivateKey::from_seed(std::span<const uint8_t>{seed, 32});
524 const auto pub_bytes = key.raw_public_key_bits();
525 const auto priv_bytes = key.raw_private_key_bits();
526 copy_mem(pk, pub_bytes.data(), 32);
527 copy_mem(sk, priv_bytes.data(), 64);
528}
529
530void ed25519_sign(uint8_t sig[64],
531 const uint8_t msg[],
532 size_t msg_len,
533 const uint8_t sk[64],
534 const uint8_t domain_sep[],
535 size_t domain_sep_len) {
536 const auto key = Ed25519_PrivateKey::from_bytes(std::span<const uint8_t>{sk, 64});
537
538 Null_RNG null_rng;
539
540 std::vector<uint8_t> sig_vec;
541 if(domain_sep_len == 0) {
542 PK_Signer signer(key, null_rng, PK_Signature_Options());
543 signer.update(std::span<const uint8_t>{msg, msg_len});
544 sig_vec = signer.signature(null_rng);
545 } else {
546 Ed25519_Pure_Sign_Operation op(std::make_shared<Ed25519_PrivateKey_Data>(key.raw_private_key_bits()),
547 std::vector<uint8_t>(domain_sep, domain_sep + domain_sep_len));
548 op.update(std::span<const uint8_t>{msg, msg_len});
549 sig_vec = op.sign(null_rng);
550 }
551
552 copy_mem(sig, sig_vec.data(), 64);
553}
554
555bool ed25519_verify(const uint8_t msg[],
556 size_t msg_len,
557 const uint8_t sig[64],
558 const uint8_t pk[32],
559 const uint8_t domain_sep[],
560 size_t domain_sep_len) {
561 try {
562 const Ed25519_PublicKey key(std::span<const uint8_t>{pk, 32});
563
564 if(domain_sep_len == 0) {
565 PK_Verifier verifier(key, PK_Signature_Options());
566 verifier.update(std::span<const uint8_t>{msg, msg_len});
567 return verifier.check_signature(std::span<const uint8_t>{sig, 64});
568 } else {
569 Ed25519_Pure_Verify_Operation op(std::make_shared<Ed25519_PublicKey_Data>(key.raw_public_key_bits()),
570 std::vector<uint8_t>(domain_sep, domain_sep + domain_sep_len));
571 op.update(std::span<const uint8_t>{msg, msg_len});
572 return op.is_valid_signature(std::span<const uint8_t>{sig, 64});
573 }
574 } catch(Decoding_Error&) {
575 // An invalid public key cannot have signed anything
576 return false;
577 }
578}
579
580} // namespace Botan
#define BOTAN_UNUSED
Definition assert.h:151
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:82
#define BOTAN_ASSERT_EQUAL(expr1, expr2, assertion_made)
Definition assert.h:95
bool parameters_are_empty() const
Definition asn1_obj.h:715
virtual OID object_identifier() const
Definition pk_keys.cpp:24
static Limits DER()
Definition ber_dec.h:44
BER_Decoder & decode(bool &out)
Definition ber_dec.h:361
BER_Decoder & verify_end()
Definition ber_dec.cpp:471
secure_vector< uint8_t > get_contents()
Definition der_enc.cpp:161
DER_Encoder & encode(bool b)
Definition der_enc.cpp:313
Ed25519_PrivateKey(const AlgorithmIdentifier &alg_id, std::span< const uint8_t > key_bits)
const secure_vector< uint8_t > & get_private_key() const
static Ed25519_PrivateKey from_seed(std::span< const uint8_t > seed)
std::unique_ptr< Public_Key > public_key() const override
bool check_key(RandomNumberGenerator &rng, bool strong) const override
static Ed25519_PrivateKey from_bytes(std::span< const uint8_t > bytes)
secure_vector< uint8_t > raw_private_key_bits() const override
std::unique_ptr< PK_Ops::Signature > _create_signature_op(RandomNumberGenerator &rng, const PK_Signature_Options_Reader &option) const override
secure_vector< uint8_t > private_key_bits() const override
std::shared_ptr< const Ed25519_PublicKey_Data > m_public
Definition ed25519.h:73
std::unique_ptr< PK_Ops::Verification > create_x509_verification_op(const AlgorithmIdentifier &signature_algorithm, std::string_view provider) const override
const std::vector< uint8_t > & get_public_key() const
bool check_key(RandomNumberGenerator &rng, bool strong) const override
std::string algo_name() const override
Definition ed25519.h:24
friend class Ed25519_PrivateKey
Definition ed25519.h:76
std::unique_ptr< Private_Key > generate_another(RandomNumberGenerator &rng) const final
std::vector< uint8_t > public_key_bits() const override
std::unique_ptr< PK_Ops::Verification > _create_verification_op(const PK_Signature_Options_Reader &options) const override
AlgorithmIdentifier algorithm_identifier() const override
std::vector< uint8_t > raw_public_key_bits() const override
static Ed25519_Scalar from_wide_bytes(std::span< const uint8_t, 2 *BYTES > b)
static std::optional< Ed25519_Scalar > from_canonical_bytes(std::span< const uint8_t, BYTES > b)
static Ed25519_Scalar from_bytes(std::span< const uint8_t, BYTES > b)
static std::unique_ptr< HashFunction > create_or_throw(std::string_view algo_spec, std::string_view provider="")
Definition hash.cpp:311
const std::optional< std::string > & prehash_function() const
void update(uint8_t in)
Definition pubkey.h:241
std::vector< uint8_t > signature(RandomNumberGenerator &rng)
Definition pubkey.cpp:433
void update(uint8_t in)
Definition pubkey.h:378
bool check_signature(const uint8_t sig[], size_t length)
Definition pubkey.cpp:541
void random_vec(std::span< uint8_t > v)
Definition rng.h:254
constexpr auto scoped_poison(const Ts &... xs)
Definition ct_utils.h:222
constexpr CT::Mask< T > is_equal(const T x[], const T y[], size_t len)
Definition ct_utils.h:803
constexpr void unpoison(const T *p, size_t n)
Definition ct_utils.h:67
constexpr void poison(const T *p, size_t n)
Definition ct_utils.h:56
void ed25519_sign(uint8_t sig[64], const uint8_t msg[], size_t msg_len, const uint8_t sk[64], const uint8_t domain_sep[], size_t domain_sep_len)
bool ed25519_valid_public_key_point(std::span< const uint8_t, 32 > pk)
void acknowledge_always_deterministic(const PK_Signature_Options_Reader &options)
bool ed25519_check_signature(std::span< const uint8_t, 32 > pk, const Ed25519_Scalar &h, const uint8_t r[32], const Ed25519_Scalar &s)
constexpr void copy_mem(T *out, const T *in, size_t n)
Definition mem_ops.h:144
void secure_scrub_memory(void *ptr, size_t n)
Definition mem_utils.cpp:24
void require_software_provider(const OptionsT &options, std::string_view algo_name)
bool verify_signature(std::span< const uint8_t, ED448_LEN > pk, bool phflag, std::span< const uint8_t > context, std::span< const uint8_t > sig, std::span< const uint8_t > msg)
Verify a signature(RFC 8032 5.2.7).
void ed25519_gen_keypair(uint8_t pk[32], uint8_t sk[64], const uint8_t seed[32])
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:128
bool ed25519_verify(const uint8_t msg[], size_t msg_len, const uint8_t sig[64], const uint8_t pk[32], const uint8_t domain_sep[], size_t domain_sep_len)
void ed25519_basepoint_mul(std::span< uint8_t, 32 > out, const Ed25519_Scalar &scalar)
std::array< uint8_t, 2 *ED448_LEN > sign_message(std::span< const uint8_t, ED448_LEN > sk, std::span< const uint8_t, ED448_LEN > pk, bool pgflag, std::span< const uint8_t > context, std::span< const uint8_t > msg)
Sign a message using a keypair (RFC 8032 5.2.6).