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
a7eb58f6
Commit
a7eb58f6
authored
Mar 14, 2018
by
yiwenshao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
=====new feature added===== Able to run ASHE
parent
a4559a97
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
71 additions
and
11 deletions
+71
-11
CURRENT.conf
conf/CURRENT.conf
+2
-2
test_ASHE.cc
debug/test_ASHE.cc
+18
-0
CryptoHandlers.cc
main/CryptoHandlers.cc
+37
-4
CryptoHandlers.hh
main/CryptoHandlers.hh
+1
-1
rewrite_main.cc
main/rewrite_main.cc
+4
-0
rewrite_sum.cc
main/rewrite_sum.cc
+6
-1
edb.cc
udf/edb.cc
+3
-3
No files found.
conf/CURRENT.conf
View file @
a7eb58f6
...
@@ -5,8 +5,8 @@
...
@@ -5,8 +5,8 @@
[
onions
for
num
]
[
onions
for
num
]
oDET
:
DETJOIN
DET
RND
oDET
:
DETJOIN
DET
RND
oOPE
:
OPE
oOPE
:
OPE
oAGG
:
HOM
#
oAGG: HOM
#
oASHE: ASHE
oASHE
:
ASHE
[
end
]
[
end
]
...
...
debug/test_ASHE.cc
View file @
a7eb58f6
...
@@ -75,11 +75,29 @@ void test4() {
...
@@ -75,11 +75,29 @@ void test4() {
std
::
cout
<<
ashe1
.
decrypt_sum
(
encsum
)
<<
std
::
endl
;
std
::
cout
<<
ashe1
.
decrypt_sum
(
encsum
)
<<
std
::
endl
;
}
}
static
void
test5
(){
RAW_ASHE
ashe1
(
1
);
std
::
pair
<
long
,
std
::
vector
<
uint64_t
>>
enc1
=
{
-
997019180l
,{
15834153223274321377UL
}};
std
::
pair
<
long
,
std
::
vector
<
uint64_t
>>
enc2
=
{
873317538l
,{
4670737221960292774UL
}};
auto
encsum
=
ashe1
.
sum
(
enc1
,
enc2
);
encsum
=
ashe1
.
sum
(
encsum
,{
-
2374120261L
,{
11932286636268610472UL
}});
encsum
=
ashe1
.
sum
(
encsum
,{
3912122192L
,{
3375502011127705401UL
}});
encsum
=
ashe1
.
sum
(
encsum
,{
-
329683860
,{
1422696692650720651
}});
UNUSED
(
encsum
);
auto
res
=
RAW_ASHE
::
decrypt_sum
(
encsum
);
std
::
cout
<<
res
<<
std
::
endl
;
}
int
main
(){
int
main
(){
UNUSED
(
test1
);
UNUSED
(
test1
);
UNUSED
(
test2
);
UNUSED
(
test2
);
test3
();
test3
();
test4
();
test4
();
test5
();
return
0
;
return
0
;
}
}
main/CryptoHandlers.cc
View file @
a7eb58f6
...
@@ -13,6 +13,7 @@
...
@@ -13,6 +13,7 @@
#include <cmath>
#include <cmath>
#include <memory>
#include <memory>
#include <istream>
#define LEXSTRING(cstr) { (char*) cstr, sizeof(cstr) }
#define LEXSTRING(cstr) { (char*) cstr, sizeof(cstr) }
#define BITS_PER_BYTE 8
#define BITS_PER_BYTE 8
...
@@ -1664,19 +1665,51 @@ ASHE::decrypt(const Item &ctext, uint64_t IV) const {
...
@@ -1664,19 +1665,51 @@ ASHE::decrypt(const Item &ctext, uint64_t IV) const {
Item_int
(
static_cast
<
ulonglong
>
(
res
));
Item_int
(
static_cast
<
ulonglong
>
(
res
));
}
}
static
std
::
vector
<
std
::
string
>
split_string
(
std
::
string
s
)
{
std
::
vector
<
std
::
string
>
res
;
int
index
=
0
;
int
next
;
while
((
next
=
s
.
find
(
' '
,
index
))
!=-
1
){
res
.
push_back
(
s
.
substr
(
index
,
next
-
index
));
index
=
next
+
1
;
}
res
.
push_back
(
s
.
substr
(
index
));
return
res
;
}
Item
*
Item
*
ASHE
::
decrypt_sum
(
const
Item
&
ctext
)
{
ASHE
::
decrypt_sum
(
const
Item
&
ctext
)
{
const
std
::
string
plainstr
=
ItemToString
(
ctext
);
std
::
string
plainstr
=
ItemToString
(
ctext
);
std
::
cout
<<
"ctext: "
<<
plainstr
<<
std
::
endl
;
while
(
!
(
plainstr
.
back
()
>=
'0'
&&
plainstr
.
back
()
<=
'9'
))
{
return
MySQLFieldTypeToItem
(
MYSQL_TYPE_STRING
,
plainstr
);
plainstr
.
pop_back
();
}
assert
(
plainstr
.
back
()
!=
' '
);
std
::
vector
<
std
::
string
>
sum_ivs_vec
=
split_string
(
plainstr
);
long
cipher
=
std
::
stol
(
sum_ivs_vec
[
0
]);
std
::
vector
<
uint64_t
>
vec
;
for
(
unsigned
int
i
=
1
;
i
<
sum_ivs_vec
.
size
();
i
++
)
{
uint64_t
value
;
std
::
istringstream
iss
(
sum_ivs_vec
[
i
]);
iss
>>
value
;
vec
.
push_back
(
value
);
}
std
::
pair
<
long
,
std
::
vector
<
uint64_t
>>
in
=
std
::
make_pair
(
cipher
,
vec
);
uint64_t
res
=
RAW_ASHE
::
decrypt_sum
(
in
);
// return MySQLFieldTypeToItem(MYSQL_TYPE_STRING, plainstr);
std
::
string
str
=
std
::
to_string
(
res
);
return
new
(
current_thd
->
mem_root
)
Item_int
(
static_cast
<
ulonglong
>
(
valFromStr
(
str
)));
}
}
Item
*
Item
*
ASHE
::
sumUDA
(
Item
*
const
expr
)
const
ASHE
::
sumUDA
(
Item
*
const
expr
,
Item
*
const
saltname
)
const
{
{
List
<
Item
>
l
;
List
<
Item
>
l
;
l
.
push_back
(
expr
);
l
.
push_back
(
expr
);
l
.
push_back
(
saltname
);
return
new
(
current_thd
->
mem_root
)
Item_func_udf_str
(
&
u_sumashe_a
,
l
);
return
new
(
current_thd
->
mem_root
)
Item_func_udf_str
(
&
u_sumashe_a
,
l
);
}
}
...
...
main/CryptoHandlers.hh
View file @
a7eb58f6
...
@@ -198,7 +198,7 @@ public:
...
@@ -198,7 +198,7 @@ public:
Item
*
encrypt
(
const
Item
&
p
,
uint64_t
IV
)
const
;
Item
*
encrypt
(
const
Item
&
p
,
uint64_t
IV
)
const
;
Item
*
decrypt
(
const
Item
&
c
,
uint64_t
IV
)
const
;
Item
*
decrypt
(
const
Item
&
c
,
uint64_t
IV
)
const
;
Item
*
decrypt_sum
(
const
Item
&
ctext
);
Item
*
decrypt_sum
(
const
Item
&
ctext
);
Item
*
sumUDA
(
Item
*
const
expr
)
const
;
Item
*
sumUDA
(
Item
*
const
expr
,
Item
*
const
saltname
)
const
;
protected
:
protected
:
std
::
string
const
seed_key
;
std
::
string
const
seed_key
;
...
...
main/rewrite_main.cc
View file @
a7eb58f6
...
@@ -919,6 +919,10 @@ decrypt_item_layers(const Item &i, const FieldMeta *const fm, onion o,
...
@@ -919,6 +919,10 @@ decrypt_item_layers(const Item &i, const FieldMeta *const fm, onion o,
//onionmeta的使用方法很简单, getlayers, 然后层层使用.
//onionmeta的使用方法很简单, getlayers, 然后层层使用.
const
auto
&
enc_layers
=
om
->
getLayers
();
const
auto
&
enc_layers
=
om
->
getLayers
();
for
(
auto
it
=
enc_layers
.
rbegin
();
it
!=
enc_layers
.
rend
();
++
it
)
{
for
(
auto
it
=
enc_layers
.
rbegin
();
it
!=
enc_layers
.
rend
();
++
it
)
{
if
(
o
==
oASHE
)
{
out_i
=
((
ASHE
&
)(
*
it
)).
decrypt_sum
(
*
dec
);
break
;
}
out_i
=
(
*
it
)
->
decrypt
(
*
dec
,
IV
);
out_i
=
(
*
it
)
->
decrypt
(
*
dec
,
IV
);
assert
(
out_i
);
assert
(
out_i
);
dec
=
out_i
;
dec
=
out_i
;
...
...
main/rewrite_sum.cc
View file @
a7eb58f6
...
@@ -206,8 +206,13 @@ class CItemSum : public CItemSubtypeST<Item_sum_sum, SFT> {
...
@@ -206,8 +206,13 @@ class CItemSum : public CItemSubtypeST<Item_sum_sum, SFT> {
EncLayer
const
&
el
=
a
.
getBackEncLayer
(
*
om
);
EncLayer
const
&
el
=
a
.
getBackEncLayer
(
*
om
);
TEST_UnexpectedSecurityLevel
(
oASHE
,
SECLEVEL
::
ASHE
,
TEST_UnexpectedSecurityLevel
(
oASHE
,
SECLEVEL
::
ASHE
,
el
.
level
());
el
.
level
());
return
static_cast
<
const
ASHE
&>
(
el
).
sumUDA
(
new_child
);
const
Item_field
*
old_child
=
(
Item_field
const
*
)(
RiboldMYSQL
::
get_arg
(
i
,
0
)
);
const
std
::
string
table_name
=
old_child
->
table_name
;
const
std
::
string
anno_table_name
=
a
.
getTableMeta
(
a
.
getDatabaseName
(),
table_name
).
getAnonTableName
();
Item_field
*
const
salt_field
=
make_item_field
(
*
old_child
,
anno_table_name
,
constr
.
key
->
getSaltName
());
return
static_cast
<
const
ASHE
&>
(
el
).
sumUDA
(
new_child
,
salt_field
);
}
else
{
}
else
{
TEST_UnexpectedSecurityLevel
(
constr
.
o
,
SECLEVEL
::
PLAINVAL
,
TEST_UnexpectedSecurityLevel
(
constr
.
o
,
SECLEVEL
::
PLAINVAL
,
constr
.
l
);
constr
.
l
);
...
...
udf/edb.cc
View file @
a7eb58f6
...
@@ -582,7 +582,7 @@ my_bool cryptdb_asheagg_add(UDF_INIT *const initid, UDF_ARGS *const args,
...
@@ -582,7 +582,7 @@ my_bool cryptdb_asheagg_add(UDF_INIT *const initid, UDF_ARGS *const args,
};
};
std
::
pair
<
long
,
std
::
vector
<
uint64_t
>>
next
=
{
std
::
pair
<
long
,
std
::
vector
<
uint64_t
>>
next
=
{
*
((
long
*
)
args
->
args
[
0
]),
*
((
long
*
)
args
->
args
[
0
]),
{
1
},
{
*
((
uint64_t
*
)
args
->
args
[
1
])
},
};
};
already
=
RAW_ASHE
::
sum
(
already
,
next
);
already
=
RAW_ASHE
::
sum
(
already
,
next
);
((
ashesumdata
*
)(
initid
->
ptr
))
->
cipher
=
already
.
first
;
((
ashesumdata
*
)(
initid
->
ptr
))
->
cipher
=
already
.
first
;
...
@@ -597,13 +597,13 @@ char* cryptdb_asheagg(UDF_INIT *const initid, UDF_ARGS *const args,
...
@@ -597,13 +597,13 @@ char* cryptdb_asheagg(UDF_INIT *const initid, UDF_ARGS *const args,
char
*
const
is_null
,
char
*
const
error
)
{
char
*
const
is_null
,
char
*
const
error
)
{
std
::
string
s
;
std
::
string
s
;
ashesumdata
*
data
=
(
ashesumdata
*
)(
initid
->
ptr
);
ashesumdata
*
data
=
(
ashesumdata
*
)(
initid
->
ptr
);
s
+=
std
::
to_string
(
data
->
cipher
)
+=
std
::
string
(
"
<=cipher ivs=>
"
);
s
+=
std
::
to_string
(
data
->
cipher
)
+=
std
::
string
(
"
"
);
for
(
auto
item
:
data
->
IVs
)
{
for
(
auto
item
:
data
->
IVs
)
{
(
void
)
item
;
(
void
)
item
;
s
+=
std
::
to_string
(
item
)
+=
std
::
string
(
" "
);
s
+=
std
::
to_string
(
item
)
+=
std
::
string
(
" "
);
}
}
s
+=
std
::
string
(
"iv size:"
)
+=
std
::
to_string
(
data
->
IVs
.
size
());
//
s+=std::string("iv size:")+=std::to_string(data->IVs.size());
unsigned
int
len
=
s
.
size
();
unsigned
int
len
=
s
.
size
();
*
length
=
len
+
1
;
*
length
=
len
+
1
;
...
...
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