mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Improve unit test.
This commit is contained in:
@@ -258,19 +258,25 @@ std::vector<unsigned char> CKey::decryptECIES(CKey& otherKey, const std::vector<
|
|||||||
bool checkECIES(void)
|
bool checkECIES(void)
|
||||||
{
|
{
|
||||||
CKey senderPriv, recipientPriv, senderPub, recipientPub;
|
CKey senderPriv, recipientPriv, senderPub, recipientPub;
|
||||||
senderPriv.MakeNewKey();
|
|
||||||
recipientPriv.MakeNewKey();
|
|
||||||
|
|
||||||
if(!senderPub.SetPubKey(senderPriv.GetPubKey()))
|
|
||||||
throw std::runtime_error("key error");
|
|
||||||
if(!recipientPub.SetPubKey(recipientPriv.GetPubKey()))
|
|
||||||
throw std::runtime_error("key error");
|
|
||||||
|
|
||||||
for(int i=0; i<30000; i++)
|
for(int i=0; i<30000; i++)
|
||||||
{
|
{
|
||||||
|
if((i%100)==0)
|
||||||
|
{ // generate new keys every 100 times
|
||||||
|
// std::cerr << "new keys" << std::endl;
|
||||||
|
senderPriv.MakeNewKey();
|
||||||
|
recipientPriv.MakeNewKey();
|
||||||
|
|
||||||
|
if(!senderPub.SetPubKey(senderPriv.GetPubKey()))
|
||||||
|
throw std::runtime_error("key error");
|
||||||
|
if(!recipientPub.SetPubKey(recipientPriv.GetPubKey()))
|
||||||
|
throw std::runtime_error("key error");
|
||||||
|
}
|
||||||
|
|
||||||
// generate message
|
// generate message
|
||||||
std::vector<unsigned char> message(4096);
|
std::vector<unsigned char> message(4096);
|
||||||
int msglen=i%3000;
|
int msglen=i%3000;
|
||||||
|
|
||||||
if(RAND_bytes(static_cast<unsigned char *>(&message.front()), msglen) != 1)
|
if(RAND_bytes(static_cast<unsigned char *>(&message.front()), msglen) != 1)
|
||||||
throw std::runtime_error("insufficient entropy");
|
throw std::runtime_error("insufficient entropy");
|
||||||
message.resize(msglen);
|
message.resize(msglen);
|
||||||
@@ -281,7 +287,11 @@ bool checkECIES(void)
|
|||||||
// decrypt message with recipient's private key and sender's public key
|
// decrypt message with recipient's private key and sender's public key
|
||||||
std::vector<unsigned char> decrypt=recipientPriv.decryptECIES(senderPub, ciphertext);
|
std::vector<unsigned char> decrypt=recipientPriv.decryptECIES(senderPub, ciphertext);
|
||||||
|
|
||||||
if(decrypt != message) return false;
|
if(decrypt != message)
|
||||||
|
{
|
||||||
|
assert(false);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
// std::cerr << "Msg(" << msglen << ") ok " << ciphertext.size() << std::endl;
|
// std::cerr << "Msg(" << msglen << ") ok " << ciphertext.size() << std::endl;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user