Commit c4e206fe authored by yiwenshao's avatar yiwenshao

able to verify encryption and decryption layers

parent 9ed387b1
...@@ -3,10 +3,11 @@ ...@@ -3,10 +3,11 @@
#oAGG: HOM #oAGG: HOM
#oASHE: ASHE #oASHE: ASHE
[onions for num] [onions for num]
oDET: DETJOIN DET RND oDET: DETJOIN DET
oOPE: OPEFOREIGN OPE RND oOPE: OPE
oAGG: HOM oAGG: HOM
#oASHE: ASHE oASHE: ASHE
[end] [end]
##################################################################################### #####################################################################################
...@@ -15,5 +16,6 @@ oAGG: HOM ...@@ -15,5 +16,6 @@ oAGG: HOM
#oOPE: OPEFOREIGN OPE RND #oOPE: OPEFOREIGN OPE RND
[onions for str] [onions for str]
oDET: DETJOIN DET RND oDET: DETJOIN DET RND
oOPE: OPEFOREIGN OPE RND oOPE: OPE
oSWP: SEARCH oSWP: SEARCH
[end]
...@@ -84,17 +84,42 @@ decrypt_item_layers_raw(const Item &i, uint64_t IV, std::vector<std::unique_ptr< ...@@ -84,17 +84,42 @@ decrypt_item_layers_raw(const Item &i, uint64_t IV, std::vector<std::unique_ptr<
return out_i; return out_i;
} }
static
Item *
getItemInt(std::string input) {
return new (current_thd->mem_root)
Item_int(static_cast<ulonglong>(valFromStr(input)));
}
int static
main() { Item *
init(); getItemString(std::string input) {
create_embedded_thd(0); 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; Create_field *f = new Create_field;
f->sql_type = MYSQL_TYPE_LONG; f->sql_type = MYSQL_TYPE_LONG;
f->flags |= UNSIGNED_FLAG;
return f;
}
static
void test1(){
// create_embedded_thd(0);
Create_field *f = new Create_field;
f->sql_type = MYSQL_TYPE_LONG;
f->flags |= UNSIGNED_FLAG;//Or we will have error range.
std::unique_ptr<EncLayer> el(EncLayerFactory::encLayer(oDET,SECLEVEL::RND,*f,"HEHE")); std::unique_ptr<EncLayer> el(EncLayerFactory::encLayer(oDET,SECLEVEL::RND,*f,"HEHE"));
auto levels = CURRENT_NUM_LAYOUT[oDET]; auto levels = CURRENT_NUM_LAYOUT[oDET];
std::vector<std::unique_ptr<EncLayer> > layers; std::vector<std::unique_ptr<EncLayer> > layers;
const Create_field * newcf = f; const Create_field * newcf = f;
...@@ -107,15 +132,108 @@ main() { ...@@ -107,15 +132,108 @@ main() {
newcf = el->newCreateField(oldcf); newcf = el->newCreateField(oldcf);
layers.push_back(std::move(el)); layers.push_back(std::move(el));
} }
Item * in = NULL; Item * instr = getItemString("abc");
encrypt_item_layers_raw(*in,0,layers); (void)instr;
decrypt_item_layers_raw(*in,0,layers); Item * inint = getItemInt("123");
Item * intenc = encrypt_item_layers_raw(*inint,0,layers);
Item * intdec = decrypt_item_layers_raw(*intenc,0,layers);
(void)intdec;
(void)el; (void)el;
(void)f; (void)f;
//Then we should encrypt and decrypt.
}
static
std::vector<std::unique_ptr<EncLayer> >
getOnionLayerStr(onion o,SECLEVEL l,int length){
std::vector<std::unique_ptr<EncLayer> > res;
Create_field* f = getStringField(length);
const std::string key = "plainkey";
std::unique_ptr<EncLayer> el(EncLayerFactory::encLayer(o,l,*f,key));
res.push_back(std::move(el));//std::move should be used. or we will have complier error.
return std::move(res);
}
static
std::vector<std::unique_ptr<EncLayer> >
getOnionLayerInt(onion o,SECLEVEL l) {
std::vector<std::unique_ptr<EncLayer> > res;
Create_field* f = getUnsignedIntField();
const std::string key = "plainkey";
std::unique_ptr<EncLayer> el(EncLayerFactory::encLayer(o,l,*f,key));
res.push_back(std::move(el));
return std::move(res);
}
static
void test2() {
// create_embedded_thd(0);
Create_field *f = new Create_field;
//simulate the str mode
f->sql_type = MYSQL_TYPE_VARCHAR;
f->length = 20;
std::unique_ptr<EncLayer> el(EncLayerFactory::encLayer(oDET,SECLEVEL::RND,*f,"HEHE"));
auto levels = CURRENT_STR_LAYOUT[oDET];
std::vector<std::unique_ptr<EncLayer> > layers;
const Create_field * newcf = f;
onion o = oDET;
for (auto l: levels) {
const std::string key = "plainkey";
std::unique_ptr<EncLayer>
el(EncLayerFactory::encLayer(o, l, *newcf, key));
const Create_field &oldcf = *newcf;
newcf = el->newCreateField(oldcf);
layers.push_back(std::move(el));
}
Item * instr = getItemString("abc");
//(void)instr;
//Item * inint = getItemInt("123");
Item * strenc = encrypt_item_layers_raw(*instr,0,layers);
Item * strdec = decrypt_item_layers_raw(*strenc,0,layers);
(void)strdec;
(void)el;
(void)f;
//Then we should encrypt and decrypt. //Then we should encrypt and decrypt.
}
static
void verifyLayerStr() {
auto layers = getOnionLayerStr(oDET,SECLEVEL::RND,20);
Item* input = getItemString("hehe");
Item* enc = encrypt_item_layers_raw(*input,0,layers);
Item* dec = decrypt_item_layers_raw(*enc,0,layers);
(void)dec;
(void)(dec->name);
}
static
void verifyLayerInt() {
auto layers = getOnionLayerInt(oDET,SECLEVEL::RND);
Item* input = getItemInt("123");
Item* enc = encrypt_item_layers_raw(*input,0,layers);
Item* dec = decrypt_item_layers_raw(*enc,0,layers);
(void)dec;
(void)(((Item_int*)dec)->value);
}
int
main() {
init();
create_embedded_thd(0);
test1();
test2();
getOnionLayerStr(oDET,SECLEVEL::RND,20);
getOnionLayerInt(oDET,SECLEVEL::RND);
verifyLayerStr();
verifyLayerInt();
return 0; return 0;
} }
......
[mysql-proxy] [mysql-proxy]
plugins = proxy plugins = proxy
event-threads = 4 event-threads = 4
proxy-address = 192.168.1.9:3399 proxy-address = 127.0.0.1:3399
proxy-backen-addresses = 127.0.0.1:3306 proxy-backen-addresses = 127.0.0.1:3306
...@@ -3,5 +3,5 @@ name="all.sql" ...@@ -3,5 +3,5 @@ name="all.sql"
if [ $# = 1 ];then if [ $# = 1 ];then
name=$1 name=$1
fi fi
mysqldump -uroot -h127.0.0.1 -P3306 --no-create-info --compact tpcc1000 > $name mysqldump -uroot -hlocalhost -P3306 --no-create-info --compact micro_db > $name
...@@ -18,3 +18,4 @@ function generate_insert_int(){ ...@@ -18,3 +18,4 @@ function generate_insert_int(){
h="INSERT INTO str_table VALUES " h="INSERT INTO str_table VALUES "
generate_insert_int "$h" 3 100 generate_insert_int "$h" 3 100
INSERT INTO int_table VALUES (30569),(20714),(32184),(219),(769),(23230),(12826),(951),(15940),(10370),(13504),(31031),(20070),(18364),(12901),(23721),(9104),(7061),(8484),(4617),(12972),(32749),(30288),(19558),(1609),(17415),(17857),(19113),(22409),(8231),(4591),(7658),(5483),(17668),(23917),(31495),(21785),(4344),(18119),(21307),(1337),(10395),(9305),(8301),(2051),(11210),(31071),(2640),(17143),(2631),(3705),(32231),(27056),(22263),(11398),(19217),(7343),(25756),(5625),(20342),(31769),(6839),(4509),(6708),(3091),(31866),(26183),(4234),(9746),(8639),(17798),(12934),(22402),(21783),(31087),(3106),(24391),(31216),(22373),(25093),(29764),(18173),(17477),(26976),(16001),(14660),(20130),(15043),(31096),(4484),(8336),(28135),(2222),(4342),(16962),(14320),(9895),(22998),(7717),(22127);
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