ECDSA not producing proper pairs

28 views
Skip to first unread message

Connor Huffine

unread,
May 19, 2013, 2:18:48 AM5/19/13
to cryptop...@googlegroups.com
    For some reason, my code is not giving me proper pairs; it gives me a private key that doesn't correspond to the public key I'm generating. Everything is in hex.
Example:
private key: e6d9f1845ccf7effe2e0a4d79a4adf59ab421e71127d16ff00c12b4a20d22d8d
x: ac43191cb357b72cbbcc26688ffefa9f5a1524ea5a19512bde902a3a823ca7ca
y: 21d409304f6bbc829e04793718929b0115e7daae6e6d4bc11a7fe405783a942e
compressed: 03ac43191cb357b72cbbcc26688ffefa9f5a1524ea5a19512bde902a3a823ca7ca

Brick o' code:

    AutoSeededRandomPool prng;
    ECDSA<ECP, SHA256>::PrivateKey privateKey;
    ECDSA<ECP, SHA256>::PublicKey publicKey;
    privateKey.Initialize( prng, CryptoPP::ASN1::secp256r1());

    bool result = privateKey.Validate( prng, 3 );
    cout << "valid: " << result << endl << endl;

    const Integer& x1 = privateKey.GetPrivateExponent();
    cout << "priv:  " << std::hex << x1 << endl;

    privateKey.MakePublicKey(publicKey);

    result = publicKey.Validate( prng, 3 );
    cout << "valid: " << result << endl << endl;

    Integer qx = publicKey.GetPublicElement().x;
    Integer qy = publicKey.GetPublicElement().y;

    cout << "pub x: " << std::hex << qx << endl;
    cout << "pub y: " << std::hex << qy << endl;

What've I done wrong?

Connor Huffine

unread,
May 20, 2013, 1:46:06 AM5/20/13
to cryptop...@googlegroups.com
Never mind, I'm an idiot. I was using the wrong curve. secp256r1 instead of secp256k1.
Reply all
Reply to author
Forward
0 new messages