import/export cryptopp keys. begin to separate operations and public/secret.

This commit is contained in:
subtly 2014-10-23 02:40:02 +02:00
parent 9308d04a4c
commit 6513d43129

View File

@ -28,7 +28,6 @@
#include <libethereum/Transaction.h> #include <libethereum/Transaction.h>
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
#include <libdevcrypto/EC.h> #include <libdevcrypto/EC.h>
//#include <libdevcrypto/ECIES.h>
#include "TestHelperCrypto.h" #include "TestHelperCrypto.h"
using namespace std; using namespace std;
@ -38,22 +37,32 @@ using namespace CryptoPP;
BOOST_AUTO_TEST_SUITE(devcrypto) BOOST_AUTO_TEST_SUITE(devcrypto)
BOOST_AUTO_TEST_CASE(cryptopp_private_secret_import)
{
ECKeyPair k = ECKeyPair::create();
Integer e = k.m_decryptor.AccessKey().GetPrivateExponent();
assert(pp::ExponentFromSecret(k.secret()) == e);
}
BOOST_AUTO_TEST_CASE(cryptopp_public_export_import) BOOST_AUTO_TEST_CASE(cryptopp_public_export_import)
{ {
ECIES<ECP>::Decryptor d(pp::PRNG(), pp::secp256k1()); ECIES<ECP>::Decryptor d(pp::PRNG(), pp::secp256k1());
ECIES<ECP>::Encryptor e(d.GetKey()); ECIES<ECP>::Encryptor e(d.GetKey());
Public p = pp::exportPublicKey(e.GetKey()); Public p;
pp::exportDL_PublicKey_EC(e.GetKey(), p);
Integer x(&p[0], 32); Integer x(&p[0], 32);
Integer y(&p[32], 32); Integer y(&p[32], 32);
DL_PublicKey_EC<ECP> pub; DL_PublicKey_EC<ECP> pub;
pub.Initialize(pp::secp256k1(), ECP::Point(x,y)); pub.Initialize(pp::secp256k1(), ECP::Point(x,y));
assert(pub == e.GetKey()); assert(pub == e.GetKey());
DL_PublicKey_EC<ECP> pub2;
pub.Initialize(pp::secp256k1(), ECP::Point(x,y));
} }
BOOST_AUTO_TEST_CASE(eckeypair_encrypt) BOOST_AUTO_TEST_CASE(ecies_eckeypair)
{ {
ECKeyPair k = ECKeyPair::create(); ECKeyPair k = ECKeyPair::create();
string message("Now is the time for all good persons to come to the aide of humanity."); string message("Now is the time for all good persons to come to the aide of humanity.");
@ -63,31 +72,15 @@ BOOST_AUTO_TEST_CASE(eckeypair_encrypt)
k.encrypt(b); k.encrypt(b);
assert(b != asBytes(original)); assert(b != asBytes(original));
bytes p = k.decrypt(&b); Secret s = k.secret();
assert(p == asBytes(original)); decrypt(s, b);
assert(b == asBytes(original));
encrypt(p, k.publicKey()); // Fix Me!
assert(p != asBytes(original)); // encrypt(k.publicKey(), b);
// assert(b != asBytes(original));
// todo: test decrypt w/Secret // bytes plain = k.decrypt(&b);
} // assert(plain == asBytes(original));
BOOST_AUTO_TEST_CASE(ecies)
{
// ECKeyPair k = ECKeyPair::create();
//
// string message("Now is the time for all good persons to come to the aide of humanity.");
// bytes b = bytesRef(message).toBytes();
// ECIESEncryptor(&k).encrypt(b);
//
// bytesConstRef br(&b);
// bytes plain = ECIESDecryptor(&k).decrypt(br);
//
// // ideally, decryptor will go a step further, accept a bytesRef and zero input.
// assert(plain != b);
//
// // plaintext is same as output
// assert(plain == bytesConstRef(message).toBytes());
} }
BOOST_AUTO_TEST_CASE(ecdhe_aes128_ctr_sha3mac) BOOST_AUTO_TEST_CASE(ecdhe_aes128_ctr_sha3mac)