Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use sha256(data) instead of plain data in secp256k1 tests #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions deps/CoinCore/tests/secp256k1/src/secp256k1_rfc6979_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ int main(int argc, char* argv[])
cout << "Using data " << data.getHex() << endl;
cout << "Data hash: " << sha256(data).getHex() << endl;

uchar_vector k = secp256k1_rfc6979_k(key, data);
uchar_vector k = secp256k1_rfc6979_k(key, sha256(data));
cout << "k = " << k.getHex() << endl;

cout << "Signing..." << endl;
uchar_vector sig = secp256k1_sign_rfc6979(key, data);
uchar_vector sig = secp256k1_sign_rfc6979(key, sha256(data));
cout << "Signature: " << sig.getHex() << endl;
cout << "Valid: " << (secp256k1_verify(key, data, sig) ? "TRUE" : "FALSE") << endl << endl;
cout << "Valid: " << (secp256k1_verify(key, sha256(data), sig) ? "TRUE" : "FALSE") << endl << endl;
}
catch (const exception& e)
{
Expand Down
9 changes: 5 additions & 4 deletions deps/CoinCore/tests/secp256k1/src/secp256k1_test.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <CoinCore/secp256k1_openssl.h>
#include <CoinCore/hash.h>
#include <stdutils/uchar_vector.h>

#include <iostream>
Expand Down Expand Up @@ -35,12 +36,12 @@ int main(int argc, char* argv[])
cout << "Public key: " << pubkey.getHex() << endl;

cout << endl << "Signing data..." << flush;
uchar_vector sig = secp256k1_sign(key, data);
uchar_vector sig = secp256k1_sign(key, sha256(data));
cout << "done." << endl;
cout << "Signature: " << sig.getHex() << endl;

cout << endl << "Verifying signature (should be valid)..." << flush;
if (secp256k1_verify(key, data, sig, SIGNATURE_FLAGS)) { cout << "valid." << endl; }
if (secp256k1_verify(key, sha256(data), sig, SIGNATURE_FLAGS)) { cout << "valid." << endl; }
else { cout << "invalid. TEST FAILED" << endl; }

cout << endl << "Creating public key object..." << flush;
Expand All @@ -64,7 +65,7 @@ int main(int argc, char* argv[])
cout << "Public key: " << pubkey.getHex() << endl;

cout << endl << "Verifying signature (should be valid)..." << flush;
if (secp256k1_verify(key2, data, sig, SIGNATURE_FLAGS)) { cout << "valid." << endl; }
if (secp256k1_verify(key2, sha256(data), sig, SIGNATURE_FLAGS)) { cout << "valid." << endl; }
else { cout << "invalid. TEST FAILED" << endl; }

cout << endl << "Creating new key..." << flush;
Expand All @@ -78,7 +79,7 @@ int main(int argc, char* argv[])
cout << "Public key: " << pubkey.getHex() << endl;

cout << endl << "Verifying old signature with new key (should be invalid)..." << flush;
if (secp256k1_verify(key, data, sig, SIGNATURE_FLAGS)) { cout << "valid. TEST FAILED" << endl; }
if (secp256k1_verify(key, sha256(data), sig, SIGNATURE_FLAGS)) { cout << "valid. TEST FAILED" << endl; }
else { cout << "invalid." << endl; }
}
catch (const exception& e)
Expand Down