I made a Signer/Checker mechanisms with ECDSA using Crypto++.
The problem is when I want to check signature it doesn't work with Verify function.
Can you propose me a more manual way to verify signature?
I made a Signer/Checker mechanisms with ECDSA using Crypto++.
The problem is when I want to check signature it doesn't work with Verify function.
Can you propose me a more manual way to verify signature?
How to verify ECDSA signature with Crypto++ without the verify function?
I'm not sure how you would verify code without a verify function. I'm probably not understanding the question.
Just in case, here's how Crypto++ implements its verification code.
First, ECDSA
is a DL_Algorithm_ECDSA
(from eccrypto.h
):
//! ECDSA algorithm
template <class EC>
class DL_Algorithm_ECDSA : public DL_Algorithm_GDSA<typename EC::Point>
{
public:
static const char * CRYPTOPP_API StaticAlgorithmName() {return "ECDSA";}
};
...
template <class EC, class H>
struct ECDSA :
public DL_SS<DL_Keys_ECDSA<EC>, DL_Algorithm_ECDSA<EC>,
DL_SignatureMessageEncodingMethod_DSA, H>
{
};
Next, here's verify function from DL_Algorithm_GDSA
in gfcrypt.h
:
bool Verify(const DL_GroupParameters<T> ¶ms, const DL_PublicKey<T> &publicKey,
const Integer &e, const Integer &r, const Integer &s) const
{
const Integer &q = params.GetSubgroupOrder();
if (r>=q || r<1 || s>=q || s<1)
return false;
Integer w = s.InverseMod(q);
Integer u1 = (e * w) % q;
Integer u2 = (r * w) % q;
return r == params.ConvertElementToInteger(
publicKey.CascadeExponentiateBaseAndPublicElement(u1, u2)) % q;
}
The code below uses VerifyMessage
, and its part of PK_Verifier
declared in cryptolib.h
:
virtual bool VerifyMessage(const byte *message, size_t messageLen,
const byte *signature, size_t signatureLength) const;
PK_Verifier
is the 'master' base class that objects like ECDSA
, NR
, and RSASS
use to expose the consistent interface.
Objects like ECDSA
, NR
, and RSASS
connect to PK_Verifier
via the DL_SS
:
template <class EC, class H>
struct ECDSA :
public DL_SS<DL_Keys_ECDSA<EC>, DL_Algorithm_ECDSA<EC>, DL_SignatureMessageEncodingMethod_DSA, H>
{
};
Finally, here's how DL_SS
relates to PK_Verifier
(from pubkey.h
):
//! Discrete Log Based Signature Scheme
template <class KEYS, class SA, class MEM, class H, class ALG_INFO = DL_SS<KEYS, SA, MEM, H, int> >
class DL_SS : public KEYS
{
typedef DL_SignatureSchemeOptions<ALG_INFO, KEYS, SA, MEM, H> SchemeOptions;
...
//! implements PK_Signer interface
typedef PK_FinalTemplate<DL_SignerImpl<SchemeOptions> > Signer;
//! implements PK_Verifier interface
typedef PK_FinalTemplate<DL_VerifierImpl<SchemeOptions> > Verifier;
};
The problem is when I want to check signature it doesn't work with Verify function.
There's lots of code available on the Crypto++ wiki. For ECDSA, see Elliptic Curve Digital Signature Algorithm. Below is a signing a verification sample taken from the wiki.
Sign
AutoSeededRandomPool prng;
ECDSA<ECP, SHA1>::PrivateKey privateKey;
privateKey.Load(...);
privateKey.Validate(prng, 3);
ECDSA<ECP, SHA1>::Signer signer(privateKey);
string message = "Do or do not. There is no try.";
// Determine maximum size, allocate a string with the maximum size
size_t siglen = signer.MaxSignatureLength();
string signature(siglen, 0x00);
// Sign, and trim signature to actual size
siglen = signer.SignMessage( prng, message.data(), message.size(), signature.data() );
signature.resize(siglen);
Verify
AutoSeededRandomPool prng;
ECDSA<ECP, SHA1>::PublicKey publicKey;
publicKey.Load(...);
publicKey.Validate(prng, 3);
ECDSA<ECP, SHA1>::Verifier verifier(publicKey);
bool result = verifier.VerifyMessage( message.data(), message.size(), signature.data(), signature.size() );
if(result)
cout << "Verified signature on message" << endl;
else
cerr << "Failed to verify signature on message" << endl;