diff --git a/Signature.h b/Signature.h index 594c12ed..ca859d67 100644 --- a/Signature.h +++ b/Signature.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include "CryptoConst.h" @@ -22,6 +23,14 @@ namespace crypto virtual size_t GetSignatureLen () const = 0; }; + class Singer + { + public: + + virtual ~Singer () {}; + virtual void Sign (CryptoPP::RandomNumberGenerator& rnd, const uint8_t * buf, int len, uint8_t * signature) = 0; + }; + class DSAVerifier: public Verifier { public: @@ -45,6 +54,26 @@ namespace crypto CryptoPP::DSA::PublicKey m_PublicKey; }; + class DSASinger: public Singer + { + public: + + DSASinger (const uint8_t * signingPrivateKey) + { + m_PrivateKey.Initialize (dsap, dsaq, dsag, CryptoPP::Integer (signingPrivateKey, 20)); + } + + void Sign (CryptoPP::RandomNumberGenerator& rnd, const uint8_t * buf, int len, uint8_t * signature) + { + CryptoPP::DSA::Signer signer (m_PrivateKey); + signer.SignMessage (rnd, buf, len, signature); + } + + private: + + CryptoPP::DSA::PrivateKey m_PrivateKey; + }; + class ECDSAP256Verifier: public Verifier { public: @@ -69,6 +98,26 @@ namespace crypto CryptoPP::ECDSA::PublicKey m_PublicKey; }; + + class ECDSAP256Singer: public Singer + { + public: + + ECDSAP256Singer (const uint8_t * signingPrivateKey) + { + m_PrivateKey.Initialize (CryptoPP::ASN1::secp256r1(), CryptoPP::Integer (signingPrivateKey, 32)); + } + + void Sign (CryptoPP::RandomNumberGenerator& rnd, const uint8_t * buf, int len, uint8_t * signature) + { + CryptoPP::ECDSA::Signer signer (m_PrivateKey); + signer.SignMessage (rnd, buf, len, signature); + } + + private: + + CryptoPP::ECDSA::PrivateKey m_PrivateKey; + }; } }