Commit 5bf37a6b authored by yiwenshao's avatar yiwenshao

add tests

parent e4697269
#include <string>
#include <map>
#include <iostream>
#include <memory>
#include <crypto/padding.hh>
#include <crypto/prng.hh>
#include <crypto/BasicCrypto.hh>
#include <crypto/blowfish.hh>
#include <crypto/arc4.hh>
#include <crypto/ASHE.hh>
#include <util/util.hh>
#include <NTL/ZZ.h>
#include "util/timer.hh"
int
main(int argc,char**argv){
RAW_ASHE ashe(1);
int num_of_tests = 10000;
if(argc==2){
num_of_tests = std::stoi(std::string(argv[1]));
}else{
std::cout<<"num_of_tests"<<std::endl;
return 0;
}
unsigned int pt = 1u;
timer t;
std::pair<long,uint64_t> res;
for(int i=0;i<num_of_tests;i++) {
res = ashe.encrypt(pt,0);
}
std::cout<<"enc_ashe_in_us: "<<t.lap()*1.0/num_of_tests<<std::endl;
for(int i=0;i<num_of_tests;i++) {
ashe.decrypt(res.first,0);
}
std::cout<<"dec_ashe_in_us: "<<t.lap()*1.0/num_of_tests<<std::endl;
return 0;
}
#include <string>
#include <map>
#include <iostream>
#include <memory>
#include <crypto/padding.hh>
#include <crypto/prng.hh>
#include <crypto/BasicCrypto.hh>
#include <crypto/blowfish.hh>
#include <crypto/arc4.hh>
#include <util/util.hh>
#include <NTL/ZZ.h>
#include "util/timer.hh"
int
main(int argc,char**argv){
blowfish bf("key");
int num_of_tests = 10000;
if(argc==2){
num_of_tests = std::stoi(std::string(argv[1]));
}else{
std::cout<<"num_of_tests"<<std::endl;
return 0;
}
uint64_t plain = 111u;
uint64_t cipher;
timer t;
for(int i=0;i<num_of_tests;i++) {
cipher = bf.encrypt(plain);
}
std::cout<<"enc_blowfish_in_us: "<<t.lap()*1.0/num_of_tests<<std::endl;
for(int i=0;i<num_of_tests;i++) {
bf.decrypt(cipher);
}
std::cout<<"dec_blowfish_in_us: "<<t.lap()*1.0/num_of_tests<<std::endl;
return 0;
}
int
main() {
return 0;
}
......@@ -12,34 +12,41 @@
#include <crypto/ope.hh>
#include <util/util.hh>
#include <NTL/ZZ.h>
#include "util/timer.hh"
using namespace NTL;
static std::string prng_expand(const std::string &seed_key, uint key_bytes){
streamrng<arc4> prng(seed_key);
return prng.rand_string(key_bytes);
}
static
void test_OPEint() {
int
main(int argc,char**argv){
int num_of_tests = 10000;
if(argc==2){
num_of_tests = std::stoi(std::string(argv[1]));
}else{
std::cout<<"num_of_tests"<<std::endl;
return 0;
}
std::string key = "12345798797";
std::string rawkey = prng_expand(key, 16);
const size_t plain_size = 4;
const size_t ciph_size = 8;
OPE ope(rawkey,8*plain_size,8*ciph_size);
uint64_t plaintext = 123456789;
NTL::ZZ enc,dec;
uint64_t enc64,dec64;
uint64_t enc64;
timer t;
for(int i=0;i<num_of_tests;i++) {
enc = ope.encrypt(ZZFromUint64(plaintext));
}
std::cout<<"enc_ope_int_in_us: "<<t.lap()*1.0/num_of_tests<<std::endl;
enc64 = uint64FromZZ(enc);
for(int i=0;i<num_of_tests;i++) {
dec = ope.decrypt(ZZFromUint64(enc64));
dec64 = uint64FromZZ(dec);
std::cout<<"enc: "<<enc<<"dec: "<<dec<<std::endl;
std::cout<<"enc64: "<<enc64<<"dec64:"<<dec64<<std::endl;
}
int
main(){
test_OPEint();
}
std::cout<<"dec_ope_int_in_us: "<<t.lap()*1.0/num_of_tests<<std::endl;
return 0;
}
#include <string>
#include <map>
#include <iostream>
#include <memory>
#include <iomanip>
#include <crypto/padding.hh>
#include <crypto/prng.hh>
#include <crypto/BasicCrypto.hh>
#include <crypto/blowfish.hh>
#include <crypto/arc4.hh>
#include <crypto/cbc.hh>
#include <crypto/ope.hh>
#include <util/util.hh>
#include <NTL/ZZ.h>
#include "util/timer.hh"
using namespace NTL;
static std::string prng_expand(const std::string &seed_key, uint key_bytes){
streamrng<arc4> prng(seed_key);
return prng.rand_string(key_bytes);
}
int
main(int argc,char**argv){
int num_of_tests = 10000;
if(argc==2){
num_of_tests = std::stoi(std::string(argv[1]));
}else{
std::cout<<"num_of_tests"<<std::endl;
return 0;
}
std::string key = "12345798797";
std::string rawkey = prng_expand(key, 16);
const size_t plain_size = 4;
const size_t ciph_size = 8;
OPE ope(rawkey,8*plain_size,8*ciph_size);
std::string ps = "1234567890";
timer t;
for(int i=0;i<num_of_tests;i++) {
uint32_t pv = 0;
for (uint i = 0; i < plain_size; i++) {
pv = pv * 256 + static_cast<int>(ps[i]);
}
ope.encrypt(to_ZZ(pv));
}
std::cout<<"enc_ope_str_in_us: "<<t.lap()*1.0/num_of_tests<<std::endl;
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment