Commit 5c8b0818 authored by yiwenshao's avatar yiwenshao

test basic ashe sum

parent 397608d0
...@@ -54,6 +54,18 @@ std::pair<long,std::vector<uint64_t>> RAW_ASHE::sum(std::vector<RAW_ASHE> input) ...@@ -54,6 +54,18 @@ std::pair<long,std::vector<uint64_t>> RAW_ASHE::sum(std::vector<RAW_ASHE> input)
return std::make_pair(res,ivs); return std::make_pair(res,ivs);
} }
std::pair<long,std::vector<uint64_t>>
RAW_ASHE::sum(std::pair<long,std::vector<uint64_t>> left,
std::pair<long,std::vector<uint64_t>> right) {
std::vector<uint64_t> vecsum;
for(auto item:left.second) vecsum.push_back(item);
for(auto item:right.second) vecsum.push_back(item);
return std::make_pair((left.first+right.first)%RAW_ASHE_MAX,vecsum);
}
uint64_t RAW_ASHE::decrypt_sum(std::pair<long,std::vector<uint64_t>> input){ uint64_t RAW_ASHE::decrypt_sum(std::pair<long,std::vector<uint64_t>> input){
long res = input.first; long res = input.first;
for(auto item:input.second){ for(auto item:input.second){
......
...@@ -23,6 +23,9 @@ public: ...@@ -23,6 +23,9 @@ public:
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::pair<long,std::vector<uint64_t>> left,
std::pair<long,std::vector<uint64_t>> right);
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>>);
}; };
......
...@@ -43,11 +43,36 @@ void test2(){ ...@@ -43,11 +43,36 @@ void test2(){
} }
} }
static
void test3() {
std::vector<uint64_t> ivs;
std::vector<long> cipher;
for(unsigned int i=1;i<=10;i++) {
uint64_t IV = randomValue();
if(IV==0) IV=1;
RAW_ASHE ashe(IV);
//cipher.push_back(ashe.encrypt(i,IV));
}
}
static
void test4() {
RAW_ASHE ashe1(1);
RAW_ASHE ashe2(2);
auto enc1 = ashe1.encrypt(1,1);
auto enc2 = ashe2.encrypt(2,2);
std::pair<long,std::vector<uint64_t>> enc1t = {enc1.first,{enc1.second}};
std::pair<long,std::vector<uint64_t>> enc2t = {enc2.first,{enc2.second}};
auto encsum = ashe1.sum(enc1t,enc2t);
std::cout<<ashe1.decrypt_sum(encsum)<<std::endl;
}
int main(){ int main(){
UNUSED(test1); UNUSED(test1);
test2(); UNUSED(test2);
test3();
test4();
return 0; 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