From fa4aaf1f50fffc3af1f1bc576c3e9de9e8cca02b Mon Sep 17 00:00:00 2001 From: orignal Date: Fri, 22 Aug 2014 16:28:25 -0400 Subject: [PATCH] signers --- Signature.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) 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; + }; } }