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
a4559a97
Commit
a4559a97
authored
Mar 13, 2018
by
yiwenshao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add new decrypt_sum function to ASHE
parent
2bcb7b4f
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
30 additions
and
38 deletions
+30
-38
CURRENT.conf
conf/CURRENT.conf
+1
-1
CryptoHandlers.cc
main/CryptoHandlers.cc
+9
-3
CryptoHandlers.hh
main/CryptoHandlers.hh
+4
-5
dbobject.hh
main/dbobject.hh
+3
-3
rewrite_main.cc
main/rewrite_main.cc
+8
-10
schema.cc
main/schema.cc
+5
-11
schema.hh
main/schema.hh
+0
-5
No files found.
conf/CURRENT.conf
View file @
a4559a97
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
#oAGG: HOM
#oAGG: HOM
#oASHE: ASHE
#oASHE: ASHE
[
onions
for
num
]
[
onions
for
num
]
oDET
:
DET
oDET
:
DET
JOIN
DET
RND
oOPE
:
OPE
oOPE
:
OPE
oAGG
:
HOM
oAGG
:
HOM
#oASHE: ASHE
#oASHE: ASHE
...
...
main/CryptoHandlers.cc
View file @
a4559a97
...
@@ -1657,20 +1657,26 @@ ASHE::encrypt(const Item &ptext, uint64_t IV) const{
...
@@ -1657,20 +1657,26 @@ ASHE::encrypt(const Item &ptext, uint64_t IV) const{
}
}
Item
*
Item
*
ASHE
::
decrypt
(
const
Item
&
ctext
,
uint64_t
IV
)
const
ASHE
::
decrypt
(
const
Item
&
ctext
,
uint64_t
IV
)
const
{
{
long
long
ct
=
const_cast
<
Item
&>
(
ctext
).
val_uint
();
long
long
ct
=
const_cast
<
Item
&>
(
ctext
).
val_uint
();
auto
res
=
ashe
.
decrypt
(
ct
,
IV
);
auto
res
=
ashe
.
decrypt
(
ct
,
IV
);
return
new
(
current_thd
->
mem_root
)
return
new
(
current_thd
->
mem_root
)
Item_int
(
static_cast
<
ulonglong
>
(
res
));
Item_int
(
static_cast
<
ulonglong
>
(
res
));
}
}
Item
*
ASHE
::
decrypt_sum
(
const
Item
&
ctext
)
{
const
std
::
string
plainstr
=
ItemToString
(
ctext
);
std
::
cout
<<
"ctext: "
<<
plainstr
<<
std
::
endl
;
return
MySQLFieldTypeToItem
(
MYSQL_TYPE_STRING
,
plainstr
);
}
Item
*
Item
*
ASHE
::
sumUDA
(
Item
*
const
expr
)
const
ASHE
::
sumUDA
(
Item
*
const
expr
)
const
{
{
List
<
Item
>
l
;
List
<
Item
>
l
;
l
.
push_back
(
expr
);
l
.
push_back
(
expr
);
// l.push_back(ZZToItemStr(sk->hompubkey()));
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 @
a4559a97
...
@@ -182,10 +182,8 @@ private:
...
@@ -182,10 +182,8 @@ private:
class
ASHE
:
public
EncLayer
{
class
ASHE
:
public
EncLayer
{
public
:
public
:
ASHE
(
const
Create_field
&
cf
,
const
std
::
string
&
seed_key
)
:
seed_key
(
seed_key
),
ashe
(
1
){
ASHE
(
const
Create_field
&
cf
,
const
std
::
string
&
seed_key
)
:
seed_key
(
seed_key
),
ashe
(
1
){}
}
// serialize and deserialize
// serialize and deserialize
std
::
string
doSerialize
()
const
{
return
seed_key
;}
std
::
string
doSerialize
()
const
{
return
seed_key
;}
ASHE
(
unsigned
int
id
,
const
std
::
string
&
serial
);
ASHE
(
unsigned
int
id
,
const
std
::
string
&
serial
);
...
@@ -199,8 +197,9 @@ public:
...
@@ -199,8 +197,9 @@ public:
//TODO needs multi encrypt and decrypt
//TODO needs multi encrypt and decrypt
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
*
sumUDA
(
Item
*
const
expr
)
const
;
Item
*
sumUDA
(
Item
*
const
expr
)
const
;
protected
:
protected
:
std
::
string
const
seed_key
;
std
::
string
const
seed_key
;
mutable
RAW_ASHE
ashe
;
mutable
RAW_ASHE
ashe
;
...
...
main/dbobject.hh
View file @
a4559a97
...
@@ -166,10 +166,10 @@ public:
...
@@ -166,10 +166,10 @@ public:
// FIXME: Use rtti.
// FIXME: Use rtti.
virtual
std
::
string
typeName
()
const
=
0
;
virtual
std
::
string
typeName
()
const
=
0
;
/*
*/
/*
fetch children from embedded db
*/
virtual
std
::
vector
<
DBMeta
*>
virtual
std
::
vector
<
DBMeta
*>
fetchChildren
(
const
std
::
unique_ptr
<
Connect
>
&
e_conn
)
=
0
;
fetchChildren
(
const
std
::
unique_ptr
<
Connect
>
&
e_conn
)
=
0
;
/*
*/
/*
apply function to each child
*/
virtual
bool
virtual
bool
applyToChildren
(
std
::
function
<
bool
(
const
DBMeta
&
)
>
)
const
=
0
;
applyToChildren
(
std
::
function
<
bool
(
const
DBMeta
&
)
>
)
const
=
0
;
/*traverse the map to get the key for the conresponding child(reference MappedDBMeta)*/
/*traverse the map to get the key for the conresponding child(reference MappedDBMeta)*/
...
@@ -226,7 +226,7 @@ public:
...
@@ -226,7 +226,7 @@ public:
virtual
~
MappedDBMeta
()
{}
virtual
~
MappedDBMeta
()
{}
virtual
bool
addChild
(
KeyType
key
,
std
::
unique_ptr
<
ChildType
>
meta
);
virtual
bool
addChild
(
KeyType
key
,
std
::
unique_ptr
<
ChildType
>
meta
);
virtual
bool
childExists
(
const
KeyType
&
key
)
const
;
virtual
bool
childExists
(
const
KeyType
&
key
)
const
;
virtual
ChildType
*
getChild
(
const
KeyType
&
key
)
const
;
virtual
ChildType
*
getChild
(
const
KeyType
&
key
)
const
;
/*the return type is different from that of DBMeta, what are the consequences?*/
/*the return type is different from that of DBMeta, what are the consequences?*/
...
...
main/rewrite_main.cc
View file @
a4559a97
...
@@ -1395,11 +1395,13 @@ std::string ReturnMeta::stringify() {
...
@@ -1395,11 +1395,13 @@ std::string ReturnMeta::stringify() {
}
}
//有了准备好的合适的meta以后, 对于ResType类型进来的加密数据, 可以解密变成明文的resType
/*Transform encrypted ResType into plaintext ResType
*ReturnMeta contains metadata form layers of decryption
*
*/
ResType
ResType
Rewriter
::
decryptResults
(
const
ResType
&
dbres
,
const
ReturnMeta
&
rmeta
)
Rewriter
::
decryptResults
(
const
ResType
&
dbres
,
const
ReturnMeta
&
rmeta
)
{
{
//这个success是构造的时候写入的.
assert
(
dbres
.
success
());
assert
(
dbres
.
success
());
const
unsigned
int
rows
=
dbres
.
rows
.
size
();
const
unsigned
int
rows
=
dbres
.
rows
.
size
();
...
@@ -1410,20 +1412,17 @@ Rewriter::decryptResults(const ResType &dbres, const ReturnMeta &rmeta)
...
@@ -1410,20 +1412,17 @@ Rewriter::decryptResults(const ResType &dbres, const ReturnMeta &rmeta)
for
(
auto
it
=
dbres
.
names
.
begin
();
for
(
auto
it
=
dbres
.
names
.
begin
();
it
!=
dbres
.
names
.
end
();
it
++
)
{
it
!=
dbres
.
names
.
end
();
it
++
)
{
//返回的匿名的名字, 一列下标从0开始.
const
unsigned
int
index
=
it
-
dbres
.
names
.
begin
();
const
unsigned
int
index
=
it
-
dbres
.
names
.
begin
();
//
根据下标获得rfmeta
//
use index to get either salt or metadata for encrypted field.
const
ReturnField
&
rf
=
rmeta
.
rfmeta
.
at
(
index
);
const
ReturnField
&
rf
=
rmeta
.
rfmeta
.
at
(
index
);
if
(
!
rf
.
getIsSalt
())
{
if
(
!
rf
.
getIsSalt
())
{
//need to return this field
//plaintext column name
//存的时候, 不是salt, 已经存储了明文的名字.
dec_names
.
push_back
(
rf
.
fieldCalled
());
dec_names
.
push_back
(
rf
.
fieldCalled
());
}
}
}
}
const
unsigned
int
real_cols
=
dec_names
.
size
();
const
unsigned
int
real_cols
=
dec_names
.
size
();
//为每个数据行初始化指针空间
std
::
vector
<
std
::
vector
<
Item
*>
>
dec_rows
(
rows
);
std
::
vector
<
std
::
vector
<
Item
*>
>
dec_rows
(
rows
);
for
(
unsigned
int
i
=
0
;
i
<
rows
;
i
++
)
{
for
(
unsigned
int
i
=
0
;
i
<
rows
;
i
++
)
{
dec_rows
[
i
]
=
std
::
vector
<
Item
*>
(
real_cols
);
dec_rows
[
i
]
=
std
::
vector
<
Item
*>
(
real_cols
);
...
@@ -1435,7 +1434,6 @@ Rewriter::decryptResults(const ResType &dbres, const ReturnMeta &rmeta)
...
@@ -1435,7 +1434,6 @@ Rewriter::decryptResults(const ResType &dbres, const ReturnMeta &rmeta)
if
(
rf
.
getIsSalt
())
{
if
(
rf
.
getIsSalt
())
{
continue
;
continue
;
}
}
//获得key, 存在fieldMeta中
FieldMeta
*
const
fm
=
rf
.
getOLK
().
key
;
FieldMeta
*
const
fm
=
rf
.
getOLK
().
key
;
for
(
unsigned
int
r
=
0
;
r
<
rows
;
r
++
)
{
for
(
unsigned
int
r
=
0
;
r
<
rows
;
r
++
)
{
...
@@ -1445,14 +1443,14 @@ Rewriter::decryptResults(const ResType &dbres, const ReturnMeta &rmeta)
...
@@ -1445,14 +1443,14 @@ Rewriter::decryptResults(const ResType &dbres, const ReturnMeta &rmeta)
}
else
{
}
else
{
uint64_t
salt
=
0
;
uint64_t
salt
=
0
;
const
int
salt_pos
=
rf
.
getSaltPosition
();
const
int
salt_pos
=
rf
.
getSaltPosition
();
//
如果存在salt, 则读取远端的salt值, 转化以后用于解密
.
//
use salt_pos to read the salt from remote results
.
if
(
salt_pos
>=
0
)
{
if
(
salt_pos
>=
0
)
{
Item_int
*
const
salt_item
=
Item_int
*
const
salt_item
=
static_cast
<
Item_int
*>
(
dbres
.
rows
[
r
][
salt_pos
]);
static_cast
<
Item_int
*>
(
dbres
.
rows
[
r
][
salt_pos
]);
assert_s
(
!
salt_item
->
null_value
,
"salt item is null"
);
assert_s
(
!
salt_item
->
null_value
,
"salt item is null"
);
salt
=
salt_item
->
value
;
salt
=
salt_item
->
value
;
}
}
//
层次化的解密
.
//
layers of decryption
.
dec_rows
[
r
][
col_index
]
=
dec_rows
[
r
][
col_index
]
=
decrypt_item_layers
(
*
dbres
.
rows
[
r
][
c
],
decrypt_item_layers
(
*
dbres
.
rows
[
r
][
c
],
fm
,
rf
.
getOLK
().
o
,
salt
);
fm
,
rf
.
getOLK
().
o
,
salt
);
...
...
main/schema.cc
View file @
a4559a97
...
@@ -13,8 +13,6 @@
...
@@ -13,8 +13,6 @@
#include <main/macro_util.hh>
#include <main/macro_util.hh>
#include "util/onions.hh"
#include "util/onions.hh"
//对于schemaInfo而言, 先获得自己的id, 作为parent, 可以查找底下的databasemeta的serial,key以及id
//然后通过lambda表达式,先把databasemeta加入到schemainfo的map中, 然后返回这写个databasemeta供后续使用.
/*
/*
*for example, we have schemaInfo, then in this function, it first fetch it's own id, and use it as parent
*for example, we have schemaInfo, then in this function, it first fetch it's own id, and use it as parent
...
@@ -368,8 +366,6 @@ std::string FieldMeta::stringify() const
...
@@ -368,8 +366,6 @@ std::string FieldMeta::stringify() const
return
res
;
return
res
;
}
}
//这里FieldMeta的getChildren是pair,OnionMetaKey,OnionMeta, 其中
//onionMeta有根据Uniq排序输出为vector
std
::
vector
<
std
::
pair
<
const
OnionMetaKey
*
,
OnionMeta
*>>
std
::
vector
<
std
::
pair
<
const
OnionMetaKey
*
,
OnionMeta
*>>
FieldMeta
::
orderedOnionMetas
()
const
FieldMeta
::
orderedOnionMetas
()
const
{
{
...
@@ -489,11 +485,10 @@ bool FieldMeta::hasOnion(onion o) const
...
@@ -489,11 +485,10 @@ bool FieldMeta::hasOnion(onion o) const
}
}
std
::
unique_ptr
<
TableMeta
>
std
::
unique_ptr
<
TableMeta
>
TableMeta
::
deserialize
(
unsigned
int
id
,
const
std
::
string
&
serial
)
TableMeta
::
deserialize
(
unsigned
int
id
,
const
std
::
string
&
serial
)
{
{
assert
(
id
!=
0
);
assert
(
id
!=
0
);
const
auto
vec
=
unserialize_string
(
serial
);
const
auto
vec
=
unserialize_string
(
serial
);
//
table 的解序列化有5个项目.
//
five items to be deserialized
assert
(
5
==
vec
.
size
());
assert
(
5
==
vec
.
size
());
const
std
::
string
anon_table_name
=
vec
[
0
];
const
std
::
string
anon_table_name
=
vec
[
0
];
...
@@ -507,10 +502,9 @@ TableMeta::deserialize(unsigned int id, const std::string &serial)
...
@@ -507,10 +502,9 @@ TableMeta::deserialize(unsigned int id, const std::string &serial)
salt_name
,
counter
));
salt_name
,
counter
));
}
}
//table有5个要素需要进行编码, 匿名的名字, sensitive的bool,salt的bool,salt的名字, 以及counter
//five items to be serialized
//为什么tableMeta和FieldMeta需要继承UniqueCounter
std
::
string
std
::
string
TableMeta
::
serialize
(
const
DBObject
&
parent
)
const
TableMeta
::
serialize
(
const
DBObject
&
parent
)
const
{
{
const
std
::
string
&
serial
=
const
std
::
string
&
serial
=
serialize_string
(
getAnonTableName
())
+
serialize_string
(
getAnonTableName
())
+
serialize_string
(
bool_to_string
(
hasSensitive
))
+
serialize_string
(
bool_to_string
(
hasSensitive
))
+
...
...
main/schema.hh
View file @
a4559a97
...
@@ -162,8 +162,6 @@ private:
...
@@ -162,8 +162,6 @@ private:
const
Create_field
&
cf
);
const
Create_field
&
cf
);
uint64_t
&
getCounter_
()
{
return
counter
;}
uint64_t
&
getCounter_
()
{
return
counter
;}
};
};
//salt只是一个IV, 为什么还需要随机的名字: 因为field 需要有名字, 不然没法查询.
class
TableMeta
:
public
MappedDBMeta
<
FieldMeta
,
IdentityMetaKey
>
,
class
TableMeta
:
public
MappedDBMeta
<
FieldMeta
,
IdentityMetaKey
>
,
public
UniqueCounter
{
public
UniqueCounter
{
public
:
public
:
...
@@ -178,7 +176,6 @@ public:
...
@@ -178,7 +176,6 @@ public:
// Restore.
// Restore.
static
std
::
unique_ptr
<
TableMeta
>
static
std
::
unique_ptr
<
TableMeta
>
deserialize
(
unsigned
int
id
,
const
std
::
string
&
serial
);
deserialize
(
unsigned
int
id
,
const
std
::
string
&
serial
);
TableMeta
(
unsigned
int
id
,
const
std
::
string
&
anon_table_name
,
TableMeta
(
unsigned
int
id
,
const
std
::
string
&
anon_table_name
,
bool
has_sensitive
,
bool
has_salt
,
bool
has_sensitive
,
bool
has_salt
,
const
std
::
string
&
salt_name
,
unsigned
int
counter
)
const
std
::
string
&
salt_name
,
unsigned
int
counter
)
...
@@ -186,9 +183,7 @@ public:
...
@@ -186,9 +183,7 @@ public:
has_salt
(
has_salt
),
salt_name
(
salt_name
),
has_salt
(
has_salt
),
salt_name
(
salt_name
),
anon_table_name
(
anon_table_name
),
counter
(
counter
)
{
anon_table_name
(
anon_table_name
),
counter
(
counter
)
{
}
}
~
TableMeta
()
{;}
~
TableMeta
()
{;}
std
::
string
serialize
(
const
DBObject
&
parent
)
const
;
std
::
string
serialize
(
const
DBObject
&
parent
)
const
;
std
::
string
getAnonTableName
()
const
;
std
::
string
getAnonTableName
()
const
;
std
::
vector
<
FieldMeta
*>
orderedFieldMetas
()
const
;
std
::
vector
<
FieldMeta
*>
orderedFieldMetas
()
const
;
...
...
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