crypto prototyping.

This commit is contained in:
Gav Wood 2014-01-04 21:37:34 +00:00
parent 978affbb19
commit e5d733fbb4
2 changed files with 50 additions and 0 deletions

View File

@ -8,4 +8,6 @@ link_directories(../../secp256k1)
add_executable(testeth ${SRC_LIST})
target_link_libraries(testeth secp256k1)
target_link_libraries(testeth ethereum)
target_link_libraries(testeth gmp)

View File

@ -20,7 +20,55 @@ std::string randomWord()
int main()
{
secp256k1_start();
bytes pubkey(65);
int pubkeylen = 65;
{
cout << "SEC: " << asHex(sha256("123", false)) << endl;
int ret = secp256k1_ecdsa_pubkey_create(pubkey.data(), &pubkeylen, (byte const*)sha256("123", false).data(), 1);
pubkey.resize(pubkeylen);
cout << "PUB: " << ret << " " << pubkeylen << " " << asHex(pubkey) << endl;
}
bytes tx = fromUserHex("88005401010101010101010101010101010101010101011f0de0b6b3a76400001ce8d4a5100080181c373130a009ba1f10285d4e659568bfcfec85067855c5a3c150100815dad4ef98fd37cf0593828c89db94bd6c64e210a32ef8956eaa81ea9307194996a3b879441f5d");
cout << "TX: " << RLP(tx) << endl;
Transaction t(tx);
std::string sig64 = toBigEndianString(t.vrs.r) + toBigEndianString(t.vrs.s);
cout << "SIG: " << sig64.size() << " " << asHex(sig64) << " " << t.vrs.v << endl;
auto msg = t.rlp(false);
cout << "TX w/o SIG: " << RLP(msg) << endl;
cout << "RLP(TX w/o SIG): " << asHex(t.rlpString(false)) << endl;
std::string hmsg = sha256(t.rlpString(false), false);
cout << "SHA256(RLP(TX w/o SIG)): 0x" << asHex(hmsg) << endl;
{
bytes sig(64);
u256 nonce = 0;
int v = 0;
int ret = secp256k1_ecdsa_sign_compact((byte const*)hmsg.data(), hmsg.size(), sig.data(), (byte const*)sha256("123", false).data(), (byte const*)&nonce, &v);
cout << "MYSIG: " << dec << ret << " " << sig.size() << " " << asHex(sig) << " " << v << endl;
ret = secp256k1_ecdsa_recover_compact((byte const*)hmsg.data(), hmsg.size(), (byte const*)sig.data(), pubkey.data(), &pubkeylen, 1, (int)t.vrs.v);
pubkey.resize(pubkeylen);
cout << "MYREC: " << dec << ret << " " << pubkeylen << " " << asHex(pubkey) << endl;
}
{
pubkey.resize(65);
int ret = secp256k1_ecdsa_recover_compact((byte const*)hmsg.data(), hmsg.size(), (byte const*)sig64.data(), pubkey.data(), &pubkeylen, 1, (int)t.vrs.v);
pubkey.resize(pubkeylen);
cout << "REC: " << dec << ret << " " << pubkeylen << " " << asHex(pubkey) << endl;
cout << hex << sha256(pubkey) << endl;
pubkey.resize(65);
ret = secp256k1_ecdsa_recover_compact((byte const*)hmsg.data(), hmsg.size(), (byte const*)sig64.data(), pubkey.data(), &pubkeylen, 0, (int)t.vrs.v);
pubkey.resize(pubkeylen);
cout << "REC+: " << dec << ret << " " << pubkeylen << " " << asHex(pubkey) << endl;
cout << hex << sha256(pubkey) << endl;
}
{
Trie t;