Commit 197d7a54 authored by yiwenshao's avatar yiwenshao

ashe enc/dec pass tests

parent a2ba4dc8
...@@ -16,8 +16,10 @@ std::pair<long,uint64_t> RAW_ASHE::encrypt(unsigned int plaintext){ ...@@ -16,8 +16,10 @@ std::pair<long,uint64_t> RAW_ASHE::encrypt(unsigned int plaintext){
std::pair<long,uint64_t> RAW_ASHE::encrypt(unsigned int plaintext,uint64_t inIV){ std::pair<long,uint64_t> RAW_ASHE::encrypt(unsigned int plaintext,uint64_t inIV){
uint64_t i = Fi(inIV)%RAW_ASHE_MAX, i_1=Fi_1(inIV)%RAW_ASHE_MAX; uint64_t i = Fi(inIV)%RAW_ASHE_MAX, i_1=Fi_1(inIV)%RAW_ASHE_MAX;
long res = (long)i_1 - (long)i; long offset = (long)i_1 - (long)i;
ciphertext = ((long)plaintext + res)%RAW_ASHE_MAX; ciphertext = ((long)plaintext + offset);
// std::cout<<"plain:offset:cipher"<<std::endl;
// std::cout<<plaintext<<":"<<offset<<":"<<ciphertext<<std::endl;
return std::make_pair(ciphertext,inIV); return std::make_pair(ciphertext,inIV);
} }
...@@ -32,8 +34,11 @@ unsigned int RAW_ASHE::decrypt(long ciphertext){ ...@@ -32,8 +34,11 @@ unsigned int RAW_ASHE::decrypt(long ciphertext){
unsigned int RAW_ASHE::decrypt(long ciphertext,uint64_t inIV){ unsigned int RAW_ASHE::decrypt(long ciphertext,uint64_t inIV){
uint64_t i = Fi(inIV)%RAW_ASHE_MAX, i_1=Fi_1(inIV)%RAW_ASHE_MAX; uint64_t i = Fi(inIV)%RAW_ASHE_MAX, i_1=Fi_1(inIV)%RAW_ASHE_MAX;
long res = (long)i - (long)i_1; long offset = (long)i - (long)i_1;
return (ciphertext + res)%RAW_ASHE_MAX; unsigned int res = (ciphertext + offset);
// std::cout<<"cipher:offset:plain"<<std::endl;
// std::cout<<ciphertext<<":"<<offset<<":"<<res<<std::endl;
return res;
} }
......
...@@ -14,17 +14,15 @@ public: ...@@ -14,17 +14,15 @@ public:
long get_ciphertext(){return ciphertext;} long get_ciphertext(){return ciphertext;}
std::pair<long,uint64_t> encrypt(unsigned int plaintext); std::pair<long,uint64_t> encrypt(unsigned int plaintext);
std::pair<long,uint64_t> encrypt(unsigned int plaintext,uint64_t inIv); std::pair<long,uint64_t> encrypt(unsigned int plaintext,uint64_t inIv);
unsigned int decrypt(long ciphertext); unsigned int decrypt(long ciphertext);
unsigned int decrypt(long ciphertext,uint64_t inIv); unsigned int decrypt(long ciphertext,uint64_t inIv);
uint64_t get_IV(){return IV;}; uint64_t get_IV(){return IV;};
static uint64_t Fi(uint64_t IV){return bf.encrypt(IV)%RAW_ASHE_MAX;} static uint64_t Fi(uint64_t IV) {return bf.encrypt(IV)%RAW_ASHE_MAX;}
static uint64_t Fi_1(uint64_t IV){return bf.encrypt(IV-1)%RAW_ASHE_MAX;} static uint64_t Fi_1(uint64_t IV) {return bf.encrypt(IV-1)%RAW_ASHE_MAX;}
static std::pair<long,std::vector<uint64_t>> sum(std::vector<RAW_ASHE>); static std::pair<long,std::vector<uint64_t>> sum(std::vector<RAW_ASHE>);
static uint64_t decrypt_sum(std::pair<long,std::vector<uint64_t>>); static uint64_t decrypt_sum(std::pair<long,std::vector<uint64_t>>);
}; };
......
#include "main/big_proxy.hh"
#include "util/constants.hh"
#include "util/util.hh"
using std::string;
int
main(int argc,char ** argv) {
big_proxy b("tdb","127.0.0.1","root","letmein",3306);
//std::string query;
//std::getline(std::cin,query);
std::string filename = std::string(cryptdb_dir)+"/"+"sql";
std::cout<<filename<<std::endl;
UNUSED(b);
// while(query != "quit"){
// b.go(query);
// std::getline(std::cin,query);
// }
return 0;
}
...@@ -2,12 +2,13 @@ ...@@ -2,12 +2,13 @@
#include <iostream> #include <iostream>
#include "crypto/ASHE.hh" #include "crypto/ASHE.hh"
#include "util/util.cc" #include "util/util.cc"
int main(){ static
const int num_of_tests = 32768; void test1() {
unsigned int seed = 1u; const unsigned int num_of_tests = 0xffffffff;
unsigned int seed = 4294967294u;
std::vector<unsigned int> plain; std::vector<unsigned int> plain;
std::vector<RAW_ASHE> ass; std::vector<RAW_ASHE> ass;
for(int i=0;i<num_of_tests;i++){ for(unsigned int i=0u;i<num_of_tests;i++){
plain.push_back(seed); plain.push_back(seed);
uint64_t IV = randomValue(); uint64_t IV = randomValue();
if(IV==0) IV=1; if(IV==0) IV=1;
...@@ -15,13 +16,43 @@ int main(){ ...@@ -15,13 +16,43 @@ int main(){
ass.back().encrypt(seed,IV); ass.back().encrypt(seed,IV);
unsigned int res = ass.back().decrypt(ass.back().get_ciphertext(),IV); unsigned int res = ass.back().decrypt(ass.back().get_ciphertext(),IV);
if(res==seed) ; if(res==seed) ;
else std::cout<<"not pass!!!!!!!!!!!!!!!!!!!!!!!!!!!!"<<std::endl; else{
std::cout<<"not pass!!!!!!!!!!!!!!!!!!!!!!!!!!!!"<<seed<<std::endl;
// return 0;
}
seed++; seed++;
} }
// std::pair<long,std::vector<uint64_t>> enc_sum = RAW_ASHE::sum(ass);
// long res = RAW_ASHE::decrypt_sum(enc_sum);
// std::cout<<enc_sum.first<<"::"<<res<<std::endl;
}
std::pair<long,std::vector<uint64_t>> enc_sum = RAW_ASHE::sum(ass); static
long res = RAW_ASHE::decrypt_sum(enc_sum); void test2(){
std::cout<<enc_sum.first<<"::"<<res<<std::endl; const unsigned int num_of_tests = 0xffffffff;
unsigned int seed = 0u;
for(unsigned int i=0u;i<num_of_tests;i++){
uint64_t IV = randomValue();
if(IV==0) IV=1;
RAW_ASHE ashe(IV);
auto enc = ashe.encrypt(seed,IV);
assert(enc.first == ashe.get_ciphertext());
assert(enc.second == IV);
unsigned int res = ashe.decrypt(enc.first,enc.second);
if(res==seed) ;
else{
std::cout<<"not pass!!!!!!!!!!!!!!!!!!!!!!!!!!!!"<<seed<<std::endl;
}
seed++;
}
}
int main(){
UNUSED(test1);
test2();
return 0; return 0;
} }
...@@ -38,6 +38,8 @@ ...@@ -38,6 +38,8 @@
#define RFIF RETURN_FALSE_IF_FALSE #define RFIF RETURN_FALSE_IF_FALSE
#define UNUSED(x) (void)(x)
// ==== CONSTANTS ============== // // ==== CONSTANTS ============== //
#define SVAL2(s) #s #define SVAL2(s) #s
......
File mode changed from 100644 to 100755
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