mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
commit before narrowing down import-public key issue w/cryptopp
This commit is contained in:
parent
4dcfbd05c6
commit
9604a5a4d9
58
crypto.cpp
58
crypto.cpp
@ -63,16 +63,24 @@ BOOST_AUTO_TEST_CASE(cryptopp_vs_secp256k1)
|
|||||||
Public p;
|
Public p;
|
||||||
pp::PublicFromDL_PublicKey_EC(e.GetKey(), p);
|
pp::PublicFromDL_PublicKey_EC(e.GetKey(), p);
|
||||||
|
|
||||||
/// wow, this worked. the first time.
|
|
||||||
assert(dev::toAddress(s) == right160(dev::sha3(p.ref())));
|
assert(dev::toAddress(s) == right160(dev::sha3(p.ref())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(cryptopp_private_secret_import)
|
BOOST_AUTO_TEST_CASE(cryptopp_is_bad)
|
||||||
{
|
{
|
||||||
ECKeyPair k = ECKeyPair::create();
|
SecretKeyRef k;
|
||||||
Integer e = k.m_decryptor.AccessKey().GetPrivateExponent();
|
Secret s = k.sec();
|
||||||
assert(pp::ExponentFromSecret(k.secret()) == e);
|
|
||||||
|
/// Convert secret to exponent used by pp
|
||||||
|
Integer e = pp::ExponentFromSecret(k.sec());
|
||||||
|
|
||||||
|
ECIES<ECP>::Decryptor d;
|
||||||
|
// k.AccessGroupParameters().Initialize(ASN1::secp256r1());
|
||||||
|
// k.SetPrivateExponent(_e);
|
||||||
|
|
||||||
|
pp::SecretFromDL_PrivateKey_EC(d.GetKey(), s);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(cryptopp_public_export_import)
|
BOOST_AUTO_TEST_CASE(cryptopp_public_export_import)
|
||||||
@ -80,34 +88,54 @@ 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());
|
||||||
|
|
||||||
|
Secret s;
|
||||||
|
pp::SecretFromDL_PrivateKey_EC(d.GetKey(), s);
|
||||||
Public p;
|
Public p;
|
||||||
pp::PublicFromDL_PublicKey_EC(e.GetKey(), p);
|
pp::PublicFromDL_PublicKey_EC(e.GetKey(), p);
|
||||||
|
Address addr = right160(dev::sha3(p.ref()));
|
||||||
|
assert(toAddress(s) == addr);
|
||||||
|
|
||||||
|
KeyPair l(s);
|
||||||
|
assert(l.address() == addr);
|
||||||
|
|
||||||
DL_PublicKey_EC<ECP> pub;
|
DL_PublicKey_EC<ECP> pub;
|
||||||
pub.Initialize(pp::secp256k1(), pp::PointFromPublic(p));
|
pub.Initialize(pp::secp256k1(), pp::PointFromPublic(p));
|
||||||
assert(pub.GetPublicElement() == e.GetKey().GetPublicElement());
|
assert(pub.GetPublicElement() == e.GetKey().GetPublicElement());
|
||||||
|
|
||||||
|
|
||||||
|
////
|
||||||
|
SecretKeyRef k;
|
||||||
|
Public p2;
|
||||||
|
pp::PublicFromExponent(pp::ExponentFromSecret(k.sec()), p2);
|
||||||
|
assert(k.pub() == p2);
|
||||||
|
|
||||||
|
// Fix me:
|
||||||
|
Address a = k.address();
|
||||||
|
Address a2 = toAddress(k.sec());
|
||||||
|
assert(a2 == a);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(ecies_eckeypair)
|
BOOST_AUTO_TEST_CASE(ecies_eckeypair)
|
||||||
{
|
{
|
||||||
ECKeyPair k = ECKeyPair::create();
|
KeyPair l = KeyPair::create();
|
||||||
|
SecretKeyRef k(l.sec());
|
||||||
|
|
||||||
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.");
|
||||||
string original = message;
|
string original = message;
|
||||||
|
|
||||||
bytes b = asBytes(message);
|
bytes b = asBytes(message);
|
||||||
k.encrypt(b);
|
encrypt(k.pub(), b);
|
||||||
assert(b != asBytes(original));
|
assert(b != asBytes(original));
|
||||||
|
|
||||||
Secret s = k.secret();
|
decrypt(k.sec(), b);
|
||||||
decrypt(s, b);
|
|
||||||
assert(b == asBytes(original));
|
assert(b == asBytes(original));
|
||||||
|
|
||||||
// Fix Me!
|
// // Fix Me!
|
||||||
// encrypt(k.publicKey(), b);
|
//// encrypt(k.publicKey(), b);
|
||||||
k.encrypt(b);
|
// k.encrypt(b);
|
||||||
assert(b != asBytes(original));
|
// assert(b != asBytes(original));
|
||||||
k.decrypt(b);
|
// k.decrypt(b);
|
||||||
assert(b == asBytes(original));
|
// assert(b == asBytes(original));
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(ecdhe_aes128_ctr_sha3mac)
|
BOOST_AUTO_TEST_CASE(ecdhe_aes128_ctr_sha3mac)
|
||||||
|
Loading…
Reference in New Issue
Block a user