From 5f5bca7632cee1d810bdc086ca7391fc06c7d892 Mon Sep 17 00:00:00 2001 From: subtly Date: Fri, 13 Feb 2015 02:48:33 -0500 Subject: [PATCH] initiator handshake crypto-test --- crypto.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/crypto.cpp b/crypto.cpp index 291893f59..b63bdf596 100644 --- a/crypto.cpp +++ b/crypto.cpp @@ -316,6 +316,43 @@ BOOST_AUTO_TEST_CASE(ecdhe) BOOST_REQUIRE_EQUAL(sremote, slocal); } +BOOST_AUTO_TEST_CASE(handshakeNew) +{ + // authInitiator -> E(remote-pubk, S(ecdhe-random, ecdh-shared-secret^nonce) || H(ecdhe-random-pubk) || pubk || nonce || 0x0) + // authRecipient -> E(remote-pubk, ecdhe-random-pubk || nonce || 0x0) + + Secret nodeAsecret(sha3("privacy")); + KeyPair nodeA(nodeAsecret); + + Secret nodeBsecret(sha3("privacy++")); + KeyPair nodeB(nodeBsecret); + + // Initiator is Alice (nodeA) + ECDHE eA; + bytes nAbytes(fromHex("0xAAAA")); + h256 nonceA(sha3(nAbytes)); + + bytes auth(Signature::size + h256::size + Public::size + h256::size + 1); + { + bytesConstRef sig(&auth[0], Signature::size); + bytesConstRef hepubk(&auth[Signature::size], h256::size); + bytesConstRef pubk(&auth[Signature::size + h256::size], Public::size); + bytesConstRef nonce(&auth[Signature::size + h256::size + Public::size], h256::size); + + Secret ss; + s_secp256k1.agree(nodeA.sec(), nodeB.pub(), ss); + sign(eA.seckey(), ss ^ nonceA).ref().copyTo(sig); + sha3(eA.pubkey().ref(), hepubk); + nodeA.pub().ref().copyTo(pubk); + nonceA.ref().copyTo(nonce); + auth[auth.size() - 1] = 0x0; + } + + cnote << "initAuth:" << toHex(auth); + +// bytes ack(h256::size * 2 + 1); +} + BOOST_AUTO_TEST_CASE(ecdhe_aes128_ctr_sha3mac) { // New connections require new ECDH keypairs