2014-08-21 19:15:04 +04:00
|
|
|
#ifndef SIGNATURE_H__
|
|
|
|
#define SIGNATURE_H__
|
|
|
|
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <cryptopp/dsa.h>
|
2014-08-21 22:26:15 +04:00
|
|
|
#include <cryptopp/asn.h>
|
|
|
|
#include <cryptopp/oids.h>
|
|
|
|
#include <cryptopp/eccrypto.h>
|
2014-08-21 19:15:04 +04:00
|
|
|
#include "CryptoConst.h"
|
|
|
|
|
|
|
|
namespace i2p
|
|
|
|
{
|
|
|
|
namespace crypto
|
|
|
|
{
|
|
|
|
class Verifier
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
virtual ~Verifier () {};
|
|
|
|
virtual bool Verify (const uint8_t * buf, size_t len, const uint8_t * signature) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class DSAVerifier: public Verifier
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
DSAVerifier (const uint8_t * signingKey)
|
|
|
|
{
|
|
|
|
m_PublicKey.Initialize (dsap, dsaq, dsag, CryptoPP::Integer (signingKey, 128));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Verify (const uint8_t * buf, size_t len, const uint8_t * signature)
|
|
|
|
{
|
|
|
|
CryptoPP::DSA::Verifier verifier (m_PublicKey);
|
|
|
|
return verifier.VerifyMessage (buf, len, signature, 40);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
CryptoPP::DSA::PublicKey m_PublicKey;
|
2014-08-21 22:26:15 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
class ECDSAP256Verifier: public Verifier
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
ECDSAP256Verifier (const uint8_t * signingKey)
|
|
|
|
{
|
|
|
|
m_PublicKey.Initialize (CryptoPP::ASN1::secp256r1(),
|
|
|
|
CryptoPP::ECP::Point (CryptoPP::Integer (signingKey, 32),
|
|
|
|
CryptoPP::Integer (signingKey + 32, 32)));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Verify (const uint8_t * buf, size_t len, const uint8_t * signature)
|
|
|
|
{
|
|
|
|
CryptoPP::ECDSA<CryptoPP::ECP, CryptoPP::SHA256>::Verifier verifier (m_PublicKey);
|
|
|
|
return verifier.VerifyMessage (buf, len, signature, 64);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
CryptoPP::ECDSA<CryptoPP::ECP, CryptoPP::SHA256>::PublicKey m_PublicKey;
|
|
|
|
};
|
2014-08-21 19:15:04 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|