Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
Practical-Cryptdb
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Zhaozhen
Practical-Cryptdb
Commits
14aa33e4
Commit
14aa33e4
authored
Jan 11, 2018
by
yiwenshao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rename ASHE to RAW_ASHE and add ASHE in main/rewrite_main.cc:buildTypeTextTranslator
parent
dd228f42
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
37 additions
and
34 deletions
+37
-34
ASHE.cc
crypto/ASHE.cc
+15
-15
ASHE.hh
crypto/ASHE.hh
+4
-4
test_ASHE.cc
debug/test_ASHE.cc
+4
-4
CryptoHandlers.cc
main/CryptoHandlers.cc
+2
-0
rewrite_main.cc
main/rewrite_main.cc
+4
-4
onions.cc
util/onions.cc
+8
-7
No files found.
crypto/ASHE.cc
View file @
14aa33e4
#include "crypto/ASHE.hh"
#include <iostream>
const
unsigned
int
ASHE
::
ASHE_MAX
=
0xffffffff
;
const
std
::
string
ASHE
::
key
(
"11223344"
);
blowfish
ASHE
::
bf
(
ASHE
::
key
);
const
unsigned
int
RAW_ASHE
::
RAW_
ASHE_MAX
=
0xffffffff
;
const
std
::
string
RAW_
ASHE
::
key
(
"11223344"
);
blowfish
RAW_ASHE
::
bf
(
RAW_
ASHE
::
key
);
ASHE
::
ASHE
(
int
i
)
:
IV
(
i
){
RAW_ASHE
::
RAW_
ASHE
(
int
i
)
:
IV
(
i
){
}
std
::
pair
<
long
,
uint64_t
>
ASHE
::
encrypt
(
unsigned
int
plaintext
){
uint64_t
i
=
Fi
(
IV
)
%
ASHE_MAX
,
i_1
=
Fi_1
(
IV
)
%
ASHE_MAX
;
std
::
pair
<
long
,
uint64_t
>
RAW_
ASHE
::
encrypt
(
unsigned
int
plaintext
){
uint64_t
i
=
Fi
(
IV
)
%
RAW_ASHE_MAX
,
i_1
=
Fi_1
(
IV
)
%
RAW_
ASHE_MAX
;
long
res
=
(
long
)
i_1
-
(
long
)
i
;
ciphertext
=
((
long
)
plaintext
+
res
)
%
ASHE_MAX
;
ciphertext
=
((
long
)
plaintext
+
res
)
%
RAW_
ASHE_MAX
;
return
std
::
make_pair
(
ciphertext
,
IV
);
}
unsigned
int
ASHE
::
decrypt
(
long
ciphertext
){
uint64_t
i
=
Fi
(
IV
)
%
ASHE_MAX
,
i_1
=
Fi_1
(
IV
)
%
ASHE_MAX
;
unsigned
int
RAW_
ASHE
::
decrypt
(
long
ciphertext
){
uint64_t
i
=
Fi
(
IV
)
%
RAW_ASHE_MAX
,
i_1
=
Fi_1
(
IV
)
%
RAW_
ASHE_MAX
;
long
res
=
(
long
)
i
-
(
long
)
i_1
;
return
(
ciphertext
+
res
)
%
ASHE_MAX
;
return
(
ciphertext
+
res
)
%
RAW_
ASHE_MAX
;
}
std
::
pair
<
long
,
std
::
vector
<
uint64_t
>>
ASHE
::
sum
(
std
::
vector
<
ASHE
>
input
){
std
::
pair
<
long
,
std
::
vector
<
uint64_t
>>
RAW_ASHE
::
sum
(
std
::
vector
<
RAW_
ASHE
>
input
){
long
res
=
0
;
std
::
vector
<
uint64_t
>
ivs
;
for
(
auto
&
item
:
input
){
long
cph
=
item
.
get_ciphertext
();
res
+=
cph
;
res
%=
ASHE_MAX
;
res
%=
RAW_
ASHE_MAX
;
ivs
.
push_back
(
item
.
get_IV
());
}
return
std
::
make_pair
(
res
,
ivs
);
}
uint64_t
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
;
for
(
auto
item
:
input
.
second
){
uint64_t
i
=
Fi
(
item
)
%
ASHE_MAX
,
i_1
=
Fi_1
(
item
)
%
ASHE_MAX
;
uint64_t
i
=
Fi
(
item
)
%
RAW_ASHE_MAX
,
i_1
=
Fi_1
(
item
)
%
RAW_
ASHE_MAX
;
long
target
=
(
long
)
i
-
(
long
)
i_1
;
res
+=
target
;
res
%=
ASHE_MAX
;
res
%=
RAW_
ASHE_MAX
;
}
return
res
;
}
...
...
crypto/ASHE.hh
View file @
14aa33e4
...
...
@@ -3,14 +3,14 @@
#include <string>
#include "crypto/blowfish.hh"
class
ASHE
{
static
const
unsigned
int
ASHE_MAX
;
/*n*/
class
RAW_
ASHE
{
static
const
unsigned
int
RAW_
ASHE_MAX
;
/*n*/
static
const
std
::
string
key
;
static
blowfish
bf
;
uint64_t
IV
;
long
ciphertext
;
public
:
ASHE
(
int
iv
);
RAW_
ASHE
(
int
iv
);
long
get_ciphertext
(){
return
ciphertext
;}
...
...
@@ -21,6 +21,6 @@ public:
static
uint64_t
Fi
(
uint64_t
IV
){
return
bf
.
encrypt
(
IV
)
%
100000
;}
static
uint64_t
Fi_1
(
uint64_t
IV
){
return
bf
.
encrypt
(
IV
-
1
)
%
100000
;}
static
std
::
pair
<
long
,
std
::
vector
<
uint64_t
>>
sum
(
std
::
vector
<
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
>>
);
};
debug/test_ASHE.cc
View file @
14aa33e4
...
...
@@ -6,12 +6,12 @@ int main(){
const
int
num_of_tests
=
100
;
unsigned
int
seed
=
1u
;
std
::
vector
<
unsigned
int
>
plain
;
std
::
vector
<
ASHE
>
ass
;
std
::
vector
<
RAW_
ASHE
>
ass
;
for
(
int
i
=
0
;
i
<
num_of_tests
;
i
++
){
plain
.
push_back
(
seed
);
uint64_t
IV
=
randomValue
();
if
(
IV
==
0
)
IV
=
1
;
ass
.
push_back
(
ASHE
(
IV
));
ass
.
push_back
(
RAW_
ASHE
(
IV
));
ass
.
back
().
encrypt
(
seed
);
unsigned
int
res
=
ass
.
back
().
decrypt
(
ass
.
back
().
get_ciphertext
());
if
(
res
==
seed
)
std
::
cout
<<
"pass"
<<
std
::
endl
;
...
...
@@ -19,8 +19,8 @@ int main(){
seed
++
;
}
std
::
pair
<
long
,
std
::
vector
<
uint64_t
>>
enc_sum
=
ASHE
::
sum
(
ass
);
long
res
=
ASHE
::
decrypt_sum
(
enc_sum
);
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
;
return
0
;
}
...
...
main/CryptoHandlers.cc
View file @
14aa33e4
...
...
@@ -211,6 +211,7 @@ EncLayerFactory::encLayer(onion o, SECLEVEL sl, const Create_field &cf,
case
SECLEVEL
:
:
OPE
:
{
return
OPEFactory
::
create
(
cf
,
key
);}
case
SECLEVEL
:
:
OPEFOREIGN
:
{
return
OPEFOREIGNFactory
::
create
(
cf
,
key
);}
case
SECLEVEL
:
:
HOM
:
{
return
HOMFactory
::
create
(
cf
,
key
);}
case
SECLEVEL
:
:
ASHE
:
{
return
std
::
unique_ptr
<
EncLayer
>
(
new
ASHE
(
cf
,
key
));}
case
SECLEVEL
:
:
SEARCH
:
{
return
std
::
unique_ptr
<
EncLayer
>
(
new
Search
(
cf
,
key
));
}
...
...
@@ -247,6 +248,7 @@ EncLayerFactory::deserializeLayer(unsigned int id,
case
SECLEVEL
:
:
HOM
:
return
std
::
unique_ptr
<
EncLayer
>
(
new
HOM
(
id
,
serial
));
case
SECLEVEL
:
:
ASHE
:
return
std
::
unique_ptr
<
EncLayer
>
(
new
ASHE
(
id
,
serial
));
case
SECLEVEL
:
:
SEARCH
:
return
std
::
unique_ptr
<
EncLayer
>
(
new
Search
(
id
,
serial
));
...
...
main/rewrite_main.cc
View file @
14aa33e4
...
...
@@ -642,22 +642,22 @@ static bool
buildTypeTextTranslator
(){
// Onions.
const
std
::
vector
<
std
::
string
>
onion_strings
{
"oINVALID"
,
"oPLAIN"
,
"oEq"
,
"oOrder"
,
"oADD"
,
"oSWP"
"oINVALID"
,
"oPLAIN"
,
"oEq"
,
"oOrder"
,
"oADD"
,
"oSWP"
,
"oASHE"
};
const
std
::
vector
<
onion
>
onions
{
oINVALID
,
oPLAIN
,
oDET
,
oOPE
,
oAGG
,
oSWP
oINVALID
,
oPLAIN
,
oDET
,
oOPE
,
oAGG
,
oSWP
,
oASHE
};
RETURN_FALSE_IF_FALSE
(
onion_strings
.
size
()
==
onions
.
size
());
translatorHelper
<
onion
>
(
onion_strings
,
onions
);
// SecLevels.
const
std
::
vector
<
std
::
string
>
seclevel_strings
{
"RND"
,
"DET"
,
"DETJOIN"
,
"OPEFOREIGN"
,
"OPE"
,
"HOM"
,
"SEARCH"
,
"PLAINVAL"
,
"INVALID"
"INVALID"
,
"ASHE"
};
const
std
::
vector
<
SECLEVEL
>
seclevels
{
SECLEVEL
::
RND
,
SECLEVEL
::
DET
,
SECLEVEL
::
DETJOIN
,
SECLEVEL
::
OPEFOREIGN
,
SECLEVEL
::
OPE
,
SECLEVEL
::
HOM
,
SECLEVEL
::
SEARCH
,
SECLEVEL
::
PLAINVAL
,
SECLEVEL
::
INVALID
SECLEVEL
::
INVALID
,
SECLEVEL
::
ASHE
};
RETURN_FALSE_IF_FALSE
(
seclevel_strings
.
size
()
==
seclevels
.
size
());
translatorHelper
(
seclevel_strings
,
seclevels
);
...
...
util/onions.cc
View file @
14aa33e4
...
...
@@ -10,16 +10,17 @@ onionlayout PLAIN_ONION_LAYOUT = {
/***************************ofthen used*******************************************************/
onionlayout
NUM_ONION_LAYOUT
=
{
{
oDET
,
std
::
vector
<
SECLEVEL
>
({
SECLEVEL
::
DETJOIN
,
SECLEVEL
::
DET
,
SECLEVEL
::
RND
})},
{
oOPE
,
std
::
vector
<
SECLEVEL
>
({
SECLEVEL
::
OPEFOREIGN
,
SECLEVEL
::
OPE
,
SECLEVEL
::
RND
})},
{
oAGG
,
std
::
vector
<
SECLEVEL
>
({
SECLEVEL
::
HOM
})}
// {oDET, std::vector<SECLEVEL>({SECLEVEL::DETJOIN, SECLEVEL::DET,
// SECLEVEL::RND})},
// {oOPE, std::vector<SECLEVEL>({SECLEVEL::OPEFOREIGN,SECLEVEL::OPE, SECLEVEL::RND})},
// {oAGG, std::vector<SECLEVEL>({SECLEVEL::HOM})}
{
oASHE
,
std
::
vector
<
SECLEVEL
>
({
SECLEVEL
::
ASHE
})}
};
onionlayout
STR_ONION_LAYOUT
=
{
{
oDET
,
std
::
vector
<
SECLEVEL
>
({
SECLEVEL
::
DETJOIN
,
SECLEVEL
::
DET
,
SECLEVEL
::
RND
})},
{
oOPE
,
std
::
vector
<
SECLEVEL
>
({
SECLEVEL
::
OPEFOREIGN
,
SECLEVEL
::
OPE
,
SECLEVEL
::
RND
})},
//
{oDET, std::vector<SECLEVEL>({SECLEVEL::DETJOIN, SECLEVEL::DET,
//
SECLEVEL::RND})},
//
{oOPE, std::vector<SECLEVEL>({SECLEVEL::OPEFOREIGN, SECLEVEL::OPE, SECLEVEL::RND})},
{
oSWP
,
std
::
vector
<
SECLEVEL
>
({
SECLEVEL
::
SEARCH
})}
// {oSWP, std::vector<SECLEVEL>({SECLEVEL::PLAINVAL, SECLEVEL::DET,
// SECLEVEL::RND})}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment