mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-03-07 06:09:42 +00:00
Add eddsa from ref10 implementation (with some modifications).
This commit is contained in:
44
core/crypto/EdDSA25519.cpp
Normal file
44
core/crypto/EdDSA25519.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#include "EdDSA25519.h"
|
||||
#include "ed25519/ed25519_ref10.h"
|
||||
#include <cstring>
|
||||
|
||||
namespace i2p {
|
||||
namespace crypto {
|
||||
|
||||
|
||||
EDDSA25519Verifier::EDDSA25519Verifier(const uint8_t* signingKey)
|
||||
{
|
||||
|
||||
std::memcpy(m_PublicKey, signingKey, EDDSA25519_PUBLIC_KEY_LENGTH);
|
||||
}
|
||||
|
||||
bool EDDSA25519Verifier::Verify(const uint8_t* buf, size_t len, const uint8_t* signature) const
|
||||
{
|
||||
return ed25519_ref10_open(signature, buf, len, m_PublicKey) > 0;
|
||||
}
|
||||
|
||||
size_t EDDSA25519Verifier::GetPublicKeyLen() const
|
||||
{
|
||||
return EDDSA25519_PUBLIC_KEY_LENGTH;
|
||||
}
|
||||
|
||||
|
||||
size_t EDDSA25519Verifier::GetSignatureLen() const
|
||||
{
|
||||
return EDDSA25519_SIGNATURE_LENGTH;
|
||||
}
|
||||
|
||||
|
||||
EDDSA25519Signer::EDDSA25519Signer(const uint8_t* signingPrivateKey)
|
||||
{
|
||||
std::memcpy(m_PrivateKey, signingPrivateKey, EDDSA25519_PRIVATE_KEY_LENGTH);
|
||||
ed25519_ref10_pubkey(m_PublicKey, m_PrivateKey);
|
||||
}
|
||||
|
||||
void EDDSA25519Signer::Sign(CryptoPP::RandomNumberGenerator& rnd, const uint8_t* buf, int len, uint8_t* signature) const
|
||||
{
|
||||
ed25519_ref10_sign(signature, buf, len, m_PrivateKey, m_PublicKey);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user