Trouble verifying ECDSA signature

18 views
Skip to first unread message

honkon...@gmail.com

unread,
Mar 26, 2018, 1:29:45 PM3/26/18
to Crypto++ Users
Hello
I'm having trouble verifying an ECDSA signature following instructions in the wiki, the following program prints FAIL and I cannot figure out why:

#include <cryptopp/eccrypto.h>
#include <cryptopp/oids.h>
#include <cryptopp/osrng.h>
#include <iostream>
using namespace std;
using namespace CryptoPP;
int main() {
    AutoSeededRandomPool prng;
    ECDSA<ECP, SHA256>::PrivateKey private_key;
    ECDSA<ECP, SHA256>::PublicKey public_key;
    private_key.Initialize( prng, ASN1::secp160r1() );
    private_key.MakePublicKey(public_key);
    ECDSA<ECP, SHA256>::Signer signer(private_key);
    ECDSA<ECP, SHA256>::Verifier verifier(public_key);
    signer.AccessKey().Initialize(prng, ASN1::secp160r1());
    string signature(signer.MaxSignatureLength(), 0);
    string message = "asdf";
    auto signature_length = signer.SignMessage(
        prng, (const byte*)message.data(),
        message.size(), (byte*)signature.data());
    signature.resize(signature_length);
    bool verified = verifier.VerifyMessage(
        (const byte*)message.data(), message.size(),
        (const byte*)signature.data(), signature.size());
    if (verified)
        cout << "PASS" << endl;
    else
        cout << "FAIL" << endl;
}

Isn't this how it's supposed to work? Thanks!
Ilja

Mouse

unread,
Mar 26, 2018, 4:53:00 PM3/26/18
to honkon...@gmail.com, Crypto++ Users
This is what you want:

    ECDSA<ECP, SHA256>::Verifier verifier(public_key);
    //signer.AccessKey().Initialize(prng, ASN1::secp160r1());
    string signature(signer.MaxSignatureLength(), 0);

--
You received this message because you are subscribed to "Crypto++ Users". More information about Crypto++ and this group is available at http://www.cryptopp.com and http://groups.google.com/forum/#!forum/cryptopp-users.
---
You received this message because you are subscribed to the Google Groups "Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cryptopp-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Regards,
Mouse

honkon...@gmail.com

unread,
Mar 27, 2018, 6:34:26 AM3/27/18
to Crypto++ Users
This is what you want:

    ECDSA<ECP, SHA256>::Verifier verifier(public_key);
    //signer.AccessKey().Initialize(prng, ASN1::secp160r1());
    string signature(signer.MaxSignatureLength(), 0);

Oh that was simple, thanks!
Reply all
Reply to author
Forward
0 new messages