diff options
author | Gav Wood <i@gavwood.com> | 2014-01-05 05:37:34 +0800 |
---|---|---|
committer | Gav Wood <i@gavwood.com> | 2014-01-05 05:37:34 +0800 |
commit | e5d733fbb4de2aa8d13d288da4ec468a9b145aaa (patch) | |
tree | 5cacb0d43b9cc48d48a090091ef97811f56eb605 /main.cpp | |
parent | 978affbb19197ab018368131ecfc16dfa04f9e26 (diff) | |
download | dexon-solidity-e5d733fbb4de2aa8d13d288da4ec468a9b145aaa.tar dexon-solidity-e5d733fbb4de2aa8d13d288da4ec468a9b145aaa.tar.gz dexon-solidity-e5d733fbb4de2aa8d13d288da4ec468a9b145aaa.tar.bz2 dexon-solidity-e5d733fbb4de2aa8d13d288da4ec468a9b145aaa.tar.lz dexon-solidity-e5d733fbb4de2aa8d13d288da4ec468a9b145aaa.tar.xz dexon-solidity-e5d733fbb4de2aa8d13d288da4ec468a9b145aaa.tar.zst dexon-solidity-e5d733fbb4de2aa8d13d288da4ec468a9b145aaa.zip |
crypto prototyping.
Diffstat (limited to 'main.cpp')
-rw-r--r-- | main.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
@@ -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; |