11 #include <schnorrkel/schnorrkel.h> 17 case E::VERIFICATION_FAILED:
18 return "Internal error during ed25519 signature verification";
20 return "Internal error during ed25519 signing";
22 return "Unknown error in ed25519 provider";
28 : generator_{std::move(generator)},
40 const Ed25519Seed &seed)
const {
41 std::array<uint8_t, ED25519_KEYPAIR_LENGTH> kp_bytes{};
42 ed25519_keypair_from_seed(kp_bytes.data(), seed.data());
45 kp_bytes.begin(), ED25519_SECRET_KEY_LENGTH, kp.secret_key.begin());
46 std::copy_n(kp_bytes.begin() + ED25519_SECRET_KEY_LENGTH,
47 ED25519_PUBLIC_KEY_LENGTH,
48 kp.public_key.begin());
53 const Ed25519Keypair &keypair, gsl::span<const uint8_t> message)
const {
55 std::array<uint8_t, ED25519_KEYPAIR_LENGTH> keypair_bytes;
58 keypair_bytes.begin());
61 keypair_bytes.begin() + ED25519_SECRET_KEY_LENGTH);
62 auto res = ed25519_sign(
63 sig.data(), keypair_bytes.data(), message.data(), message.size_bytes());
64 if (res != ED25519_RESULT_OK) {
65 logger_->error(
"Error during ed25519 sign; error code: {}", res);
71 const Ed25519Signature &signature,
72 gsl::span<const uint8_t> message,
73 const Ed25519PublicKey &public_key)
const {
74 auto res = ed25519_verify(signature.data(),
77 message.size_bytes());
78 if (res == ED25519_RESULT_OK) {
81 if (res == ED25519_RESULT_VERIFICATION_FAILED) {
84 logger_->error(
"Error verifying a signature; error code: {}", res);
Ed25519PrivateKey secret_key
outcome::result< bool > verify(const Ed25519Signature &signature, gsl::span< const uint8_t > message, const Ed25519PublicKey &public_key) const override
OUTCOME_CPP_DEFINE_CATEGORY(kagome::crypto, Ed25519ProviderImpl::Error, e)
std::shared_ptr< CSPRNG > generator_
Ed25519PublicKey public_key
Ed25519KeypairAndSeed generateKeypair() const override
Ed25519ProviderImpl(std::shared_ptr< CSPRNG > generator)
Logger createLogger(const std::string &tag)
outcome::result< Ed25519Signature > sign(const Ed25519Keypair &keypair, gsl::span< const uint8_t > message) const override