aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGav Wood <i@gavwood.com>2014-01-05 05:37:34 +0800
committerGav Wood <i@gavwood.com>2014-01-05 05:37:34 +0800
commite5d733fbb4de2aa8d13d288da4ec468a9b145aaa (patch)
tree5cacb0d43b9cc48d48a090091ef97811f56eb605
parent978affbb19197ab018368131ecfc16dfa04f9e26 (diff)
downloaddexon-solidity-e5d733fbb4de2aa8d13d288da4ec468a9b145aaa.tar.gz
dexon-solidity-e5d733fbb4de2aa8d13d288da4ec468a9b145aaa.tar.zst
dexon-solidity-e5d733fbb4de2aa8d13d288da4ec468a9b145aaa.zip
crypto prototyping.
-rw-r--r--CMakeLists.txt2
-rw-r--r--main.cpp48
2 files changed, 50 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e383ba2d..2bafaea3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -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)
diff --git a/main.cpp b/main.cpp
index e78f3ce0..00681436 100644
--- a/main.cpp
+++ b/main.cpp
@@ -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;