From 0e78e6805315e8cba8d2e153b5919bb135e5ec54 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Sat, 7 Apr 2012 05:15:56 -0700 Subject: [PATCH] Improve unit test. --- src/ECIES.cpp | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/ECIES.cpp b/src/ECIES.cpp index 2e4e7e881..c3ba79481 100644 --- a/src/ECIES.cpp +++ b/src/ECIES.cpp @@ -258,19 +258,25 @@ std::vector CKey::decryptECIES(CKey& otherKey, const std::vector< bool checkECIES(void) { 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++) { + 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 std::vector message(4096); int msglen=i%3000; + if(RAND_bytes(static_cast(&message.front()), msglen) != 1) throw std::runtime_error("insufficient entropy"); message.resize(msglen); @@ -281,7 +287,11 @@ bool checkECIES(void) // decrypt message with recipient's private key and sender's public key std::vector 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; } return true;