Commit ce655543 authored by yiwenshao's avatar yiwenshao

add test_enclayers

parent 30cbd3f8
......@@ -100,6 +100,10 @@ mtl/test_main_exe/%:$(OBJDIR)/test_main/%.o
@mkdir -p $(@D)
$(CXX) -g -o $@ $^ $(CXXFLAGS) $(LDFLAGS) -L/$(MYBUILD)/libmysqld -lmysqld -laio -lz -ldl -lm -lcrypt -lpthread -lcryptdb -ledbcrypto -ledbutil -ledbparser -lntl -lcrypto
mtl/test_enclayers_exe/%:$(OBJDIR)/test_enclayers/%.o $(OBJDIR)/libwrapper.so
@mkdir -p $(@D)
$(CXX) -g -o $@ $< $(CXXFLAGS) $(LDFLAGS) -L/$(MYBUILD)/libmysqld -lmysqld -laio -lz -ldl -lm -lcrypt -lpthread -lwrapper -lcryptdb -ledbcrypto -ledbutil -ledbparser -lntl -lcrypto
mtl/test_redisbio_exe/%:$(OBJDIR)/test_redisbio/%.o $(OBJDIR)/libredisbio.so
@mkdir -p $(@D)
$(CXX) -g -o $@ $< $(CXXFLAGS) $(LDFLAGS) -lredisbio
......@@ -124,6 +128,7 @@ include test_wrapper/Makefrag
include test_util/Makefrag
include test_parser/Makefrag
include test_main/Makefrag
include test_enclayers/Makefrag
include wrapper/Makefrag
include test_parser_helper/Makefrag
include redisbio/Makefrag
......
#pragma once
#include <algorithm>
#include <string>
#include <util/util.hh>
#include <crypto/prng.hh>
......@@ -449,3 +450,14 @@ private:
std::list<std::string> *
tokenize(const std::string &text);
std::string
decrypt_AES_CBC(const std::string &ctext, const AES_KEY * deckey, std::string salt, bool dounpad);
std::string
encrypt_AES_CBC(const std::string &ptext, const AES_KEY * enckey, std::string salt, bool dopad);
std::string
encrypt_AES_CMC(const std::string &ptext, const AES_KEY * enckey, bool dopad);
std::string
decrypt_AES_CMC(const std::string &ctext, const AES_KEY * deckey, bool dopad);
OBJDIRS += test_enclayers
##note that xx=*.cc will not expand. wildcard *.cc will include files from other directories.
##%.o will include testall
TESTALL_OBJS := $(patsubst %.cc,$(OBJDIR)/%.o,$(wildcard test_enclayers/*.cc))
TESTALL_EXES := $(patsubst test_enclayers/%.cc,mtl/test_enclayers_exe/%,$(wildcard test_enclayers/*.cc))
all: $(TESTALL_OBJS) $(TESTALL_EXES)
#include "parser/sql_utils.hh"
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <map>
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include "main/CryptoHandlers.hh"
#include "wrapper/reuse.hh"
#include "wrapper/common.hh"
#include "wrapper/insert_lib.hh"
#include "util/constants.hh"
#include "util/timer.hh"
#include "util/log.hh"
#include "util/onions.hh"
using std::cout;
using std::cin;
using std::endl;
using std::vector;
using std::string;
using std::to_string;
static std::string embeddedDir="/t/cryt/shadow";
static std::map<std::string, WrapperState*> clients;
//This connection mimics the behaviour of MySQL-Proxy
Connect *globalConn;
/*for each field, convert the format to FieldMeta_Wrapper*/
static void init(){
std::string client="192.168.1.1:1234";
//one Wrapper per user.
clients[client] = new WrapperState();
//Connect phase
ConnectionInfo ci("localhost", "root", "letmein",3306);
const std::string master_key = "113341234";
char *buffer;
if((buffer = getcwd(NULL, 0)) == NULL){
perror("getcwd error");
}
embeddedDir = std::string(buffer)+"/shadow";
SharedProxyState *shared_ps =
new SharedProxyState(ci, embeddedDir , master_key,
determineSecurityRating());
assert(0 == mysql_thread_init());
//we init embedded database here.
clients[client]->ps = std::unique_ptr<ProxyState>(new ProxyState(*shared_ps));
clients[client]->ps->safeCreateEmbeddedTHD();
//Connect end!!
globalConn = new Connect(ci.server, ci.user, ci.passwd, ci.port);
}
static
Item *
getItemString(std::string input) {
return MySQLFieldTypeToItem(MYSQL_TYPE_STRING, input);
}
/*
static
Item *
getItemInt(std::string input) {
return new (current_thd->mem_root)
Item_int(static_cast<ulonglong>(valFromStr(input)));
}
static
Item *
getItemString(std::string input) {
return MySQLFieldTypeToItem(MYSQL_TYPE_STRING, input);
}
static
Create_field* getStringField(int length) {
Create_field *f = new Create_field;
f->sql_type = MYSQL_TYPE_VARCHAR;
f->length = length;
return f;
}
static
Create_field* getUnsignedIntField(){
Create_field *f = new Create_field;
f->sql_type = MYSQL_TYPE_LONG;
f->flags |= UNSIGNED_FLAG;
return f;
}
*/
static
void control(DET_str* ds, Item* plain, int num_of_tests,int length) {
Item* enc = NULL;
Item* dec = NULL;
std::cout<<"length: "<<length<<std::endl;
std::cout<<"num_of_tests: "<<num_of_tests<<std::endl;
timer t;
for(int i=0;i<num_of_tests;i++) {
enc = ds->encrypt(*plain,0u);
}
std::cout<<"ENC_DET_STR_IN_us: "<<t.lap()*1.0/num_of_tests<<std::endl;
for(int i=0;i<num_of_tests;i++) {
dec = ds->decrypt(*enc,0u);
}
std::cout<<"DEC_DET_STR_IN_us: "<<t.lap()*1.0/num_of_tests<<std::endl;
std::cout<<"enclen: "<<enc->str_value.length()<<std::endl;
std::cout<<"declen: "<<dec->str_value.length() <<std::endl;
}
int
main(int argc,char**argv) {
init();
create_embedded_thd(0);
std::string key = "key";
Create_field *cf = NULL;
DET_str* ds = new DET_str(*cf, key);
int num_of_tests = 10000;
int length = 16;
if(argc==3){
num_of_tests = std::stoi(std::string(argv[1]));
length = std::stoi(std::string(argv[2]));
}else{
std::cout<<"num_of_tests:length"<<std::endl;
return 0;
}
for(int i=1;i<=100;i++) {
std::string input = ggetpRandomName(length*i);
Item* plain = getItemString(input) ;
control(ds, plain, num_of_tests, length*i) ;
}
return 0;
}
//main/schema.cc:83 is use to create layers of encryption
#include "main/CryptoHandlers.hh"
static void
test_aes_cmc(int num_of_tests,int len) {
std::string key(16,'a');
AES_KEY * ak = get_AES_dec_key(key);
std::string plain(len,'a');
std::string enc,dec;
for(int i=0;i<num_of_tests;i++){
enc = encrypt_AES_CMC(plain,ak,true);
}
for(int i=0;i<num_of_tests;i++){
dec = decrypt_AES_CMC(enc,ak,true);
}
}
static void
test_aes_cbc(int num_of_tests,int len) {
}
int
main() {
test_aes_cmc(10,10);
test_aes_cbc(10,10);
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