diff options
author | subtly <subtly@users.noreply.github.com> | 2014-10-23 11:04:25 +0800 |
---|---|---|
committer | subtly <subtly@users.noreply.github.com> | 2014-10-23 11:04:25 +0800 |
commit | 4dcfbd05c6218e8cd38a36eacdc09b0dabf5e9f0 (patch) | |
tree | d86417f663ba0a5c91ce0cc1b403f62508260632 /crypto.cpp | |
parent | 19e169694c7ae60acc8eb923fe71c4a971dc32fd (diff) | |
download | dexon-solidity-4dcfbd05c6218e8cd38a36eacdc09b0dabf5e9f0.tar dexon-solidity-4dcfbd05c6218e8cd38a36eacdc09b0dabf5e9f0.tar.gz dexon-solidity-4dcfbd05c6218e8cd38a36eacdc09b0dabf5e9f0.tar.bz2 dexon-solidity-4dcfbd05c6218e8cd38a36eacdc09b0dabf5e9f0.tar.lz dexon-solidity-4dcfbd05c6218e8cd38a36eacdc09b0dabf5e9f0.tar.xz dexon-solidity-4dcfbd05c6218e8cd38a36eacdc09b0dabf5e9f0.tar.zst dexon-solidity-4dcfbd05c6218e8cd38a36eacdc09b0dabf5e9f0.zip |
cryptopp_vs_secp256k1
Diffstat (limited to 'crypto.cpp')
-rw-r--r-- | crypto.cpp | 33 |
1 files changed, 32 insertions, 1 deletions
@@ -37,6 +37,37 @@ using namespace CryptoPP; BOOST_AUTO_TEST_SUITE(devcrypto) +BOOST_AUTO_TEST_CASE(cryptopp_vs_secp256k1) +{ + ECIES<ECP>::Decryptor d(pp::PRNG(), pp::secp256k1()); + ECIES<ECP>::Encryptor e(d.GetKey()); + + Secret s; + pp::SecretFromDL_PrivateKey_EC(d.GetKey(), s); + + Public p; + pp::PublicFromDL_PublicKey_EC(e.GetKey(), p); + + assert(dev::toAddress(s) == right160(dev::sha3(p.ref()))); + + Secret previous = s; + for (auto i = 0; i < 30; i++) + { + ECIES<ECP>::Decryptor d(pp::PRNG(), pp::secp256k1()); + ECIES<ECP>::Encryptor e(d.GetKey()); + + Secret s; + pp::SecretFromDL_PrivateKey_EC(d.GetKey(), s); + assert(s!=previous); + + Public p; + pp::PublicFromDL_PublicKey_EC(e.GetKey(), p); + + /// wow, this worked. the first time. + assert(dev::toAddress(s) == right160(dev::sha3(p.ref()))); + } +} + BOOST_AUTO_TEST_CASE(cryptopp_private_secret_import) { ECKeyPair k = ECKeyPair::create(); @@ -50,7 +81,7 @@ BOOST_AUTO_TEST_CASE(cryptopp_public_export_import) ECIES<ECP>::Encryptor e(d.GetKey()); Public p; - pp::exportDL_PublicKey_EC(e.GetKey(), p); + pp::PublicFromDL_PublicKey_EC(e.GetKey(), p); DL_PublicKey_EC<ECP> pub; pub.Initialize(pp::secp256k1(), pp::PointFromPublic(p)); |