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
559f8a45
Commit
559f8a45
authored
Jan 12, 2018
by
yiwenshao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
try to modify ASHE layer
parent
c7ca6705
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
129 deletions
+37
-129
ASHE.hh
crypto/ASHE.hh
+3
-0
CryptoHandlers.cc
main/CryptoHandlers.cc
+33
-116
CryptoHandlers.hh
main/CryptoHandlers.hh
+1
-13
No files found.
crypto/ASHE.hh
View file @
559f8a45
...
@@ -24,3 +24,6 @@ public:
...
@@ -24,3 +24,6 @@ public:
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
>>
);
};
};
main/CryptoHandlers.cc
View file @
559f8a45
...
@@ -163,13 +163,13 @@ public:
...
@@ -163,13 +163,13 @@ public:
};
};
class
ASHEFactory
:
public
LayerFactory
{
//
class ASHEFactory : public LayerFactory {
public
:
//
public:
static
std
::
unique_ptr
<
EncLayer
>
//
static std::unique_ptr<EncLayer>
create
(
const
Create_field
&
cf
,
const
std
::
string
&
key
);
//
create(const Create_field &cf, const std::string &key);
static
std
::
unique_ptr
<
EncLayer
>
//
static std::unique_ptr<EncLayer>
deserialize
(
unsigned
int
id
,
const
SerialLayer
&
serial
);
//
deserialize(unsigned int id, const SerialLayer &serial);
};
//
};
/*===================== SERIALIZE Helpers =============================*/
/*===================== SERIALIZE Helpers =============================*/
...
@@ -1450,25 +1450,25 @@ HOMFactory::deserialize(unsigned int id, const SerialLayer &serial) {
...
@@ -1450,25 +1450,25 @@ HOMFactory::deserialize(unsigned int id, const SerialLayer &serial) {
*/
*/
std
::
unique_ptr
<
EncLayer
>
//
std::unique_ptr<EncLayer>
ASHEFactory
::
create
(
const
Create_field
&
cf
,
const
std
::
string
&
key
)
//
ASHEFactory::create(const Create_field &cf, const std::string &key)
{
//
{
if
(
cf
.
sql_type
==
MYSQL_TYPE_DECIMAL
//
if (cf.sql_type == MYSQL_TYPE_DECIMAL
||
cf
.
sql_type
==
MYSQL_TYPE_NEWDECIMAL
)
{
//
|| cf.sql_type == MYSQL_TYPE_NEWDECIMAL) {
FAIL_TextMessageError
(
"decimal support is broken"
);
//
FAIL_TextMessageError("decimal support is broken");
}
//
}
//
return
std
::
unique_ptr
<
EncLayer
>
(
new
ASHE
(
cf
,
key
));
//
return std::unique_ptr<EncLayer>(new ASHE(cf, key));
}
//
}
//
std
::
unique_ptr
<
EncLayer
>
//
std::unique_ptr<EncLayer>
ASHEFactory
::
deserialize
(
unsigned
int
id
,
const
SerialLayer
&
serial
)
{
//
ASHEFactory::deserialize(unsigned int id, const SerialLayer &serial) {
if
(
serial
.
name
==
"ASHE_dec"
)
{
//
if (serial.name == "ASHE_dec") {
FAIL_TextMessageError
(
"decimal support broken"
);
//
FAIL_TextMessageError("decimal support broken");
}
//
}
return
std
::
unique_ptr
<
EncLayer
>
(
new
ASHE
(
id
,
serial
.
layer_info
));
//
return std::unique_ptr<EncLayer>(new ASHE(id, serial.layer_info));
}
//
}
//
/****************************************************************************
/****************************************************************************
...
@@ -1815,114 +1815,31 @@ const std::vector<udf_func*> udf_list = {
...
@@ -1815,114 +1815,31 @@ const std::vector<udf_func*> udf_list = {
/************************************************ASHE********************************************/
/************************************************ASHE********************************************/
ASHE
::
ASHE
(
const
Create_field
&
f
,
const
std
::
string
&
seed_key
)
ASHE
::
ASHE
(
const
Create_field
&
f
,
const
std
::
string
&
seed_key
)
:
seed_key
(
seed_key
)
,
sk
(
NULL
),
waiting
(
true
)
:
seed_key
(
seed_key
)
{}
{}
ASHE
::
ASHE
(
unsigned
int
id
,
const
std
::
string
&
serial
)
ASHE
::
ASHE
(
unsigned
int
id
,
const
std
::
string
&
serial
){}
:
EncLayer
(
id
),
seed_key
(
serial
),
sk
(
NULL
),
waiting
(
true
)
{}
Create_field
*
Create_field
*
ASHE
::
newCreateField
(
const
Create_field
&
cf
,
ASHE
::
newCreateField
(
const
Create_field
&
cf
,
const
std
::
string
&
anonname
)
const
{
const
std
::
string
&
anonname
)
const
{
return
arrayCreateFieldHelper
(
cf
,
2
*
nbits
/
BITS_PER_BYTE
,
return
NULL
;
MYSQL_TYPE_VARCHAR
,
anonname
,
&
my_charset_bin
);
}
//if first, use seed key to generate
void
ASHE
::
unwait
()
const
{
const
std
::
unique_ptr
<
streamrng
<
arc4
>>
prng
(
new
streamrng
<
arc4
>
(
seed_key
));
sk
=
new
Paillier_priv
(
Paillier_priv
::
keygen
(
prng
.
get
(),
nbits
));
waiting
=
false
;
}
}
//if first, use seed key to generate
Item
*
Item
*
ASHE
::
encrypt
(
const
Item
&
ptext
,
uint64_t
IV
)
const
{
ASHE
::
encrypt
(
const
Item
&
ptext
,
uint64_t
IV
)
const
{
if
(
true
==
waiting
)
{
return
NULL
;
this
->
unwait
();
}
const
ZZ
enc
=
sk
->
encrypt
(
ItemIntToZZ
(
ptext
));
return
ZZToItemStr
(
enc
);
}
}
Item
*
Item
*
ASHE
::
decrypt
(
const
Item
&
ctext
,
uint64_t
IV
)
const
ASHE
::
decrypt
(
const
Item
&
ctext
,
uint64_t
IV
)
const
{
{
if
(
true
==
waiting
)
{
return
NULL
;
this
->
unwait
();
}
const
ZZ
enc
=
ItemStrToZZ
(
ctext
);
const
ZZ
dec
=
sk
->
decrypt
(
enc
);
LOG
(
encl
)
<<
"ASHE ciph "
<<
enc
<<
"---->"
<<
dec
;
TEST_Text
(
NumBytes
(
dec
)
<=
8
,
"Summation produced an integer larger than 64 bits"
);
return
ZZToItemInt
(
dec
);
}
//static udf_func u_sum_a = {
// LEXSTRING("cryptdb_agg"),
// STRING_RESULT,
// UDFTYPE_AGGREGATE,
// NULL,
// NULL,
// NULL,
// NULL,
// NULL,
// NULL,
// NULL,
// 0L,
//};
//
//static udf_func u_sum_f = {
// LEXSTRING("cryptdb_func_add_set"),
// STRING_RESULT,
// UDFTYPE_FUNCTION,
// NULL,
// NULL,
// NULL,
// NULL,
// NULL,
// NULL,
// NULL,
// 0L,
//};
//
Item
*
ASHE
::
sumUDA
(
Item
*
const
expr
)
const
{
if
(
true
==
waiting
)
{
this
->
unwait
();
}
List
<
Item
>
l
;
l
.
push_back
(
expr
);
l
.
push_back
(
ZZToItemStr
(
sk
->
hompubkey
()));
return
new
(
current_thd
->
mem_root
)
Item_func_udf_str
(
&
u_sum_a
,
l
);
}
Item
*
ASHE
::
sumUDF
(
Item
*
const
i1
,
Item
*
const
i2
)
const
{
if
(
true
==
waiting
)
{
this
->
unwait
();
}
List
<
Item
>
l
;
l
.
push_back
(
i1
);
l
.
push_back
(
i2
);
l
.
push_back
(
ZZToItemStr
(
sk
->
hompubkey
()));
return
new
(
current_thd
->
mem_root
)
Item_func_udf_str
(
&
u_sum_f
,
l
);
}
}
ASHE
::~
ASHE
()
{
ASHE
::~
ASHE
()
{
delete
sk
;
}
}
...
...
main/CryptoHandlers.hh
View file @
559f8a45
...
@@ -131,26 +131,14 @@ public:
...
@@ -131,26 +131,14 @@ public:
Create_field
*
newCreateField
(
const
Create_field
&
cf
,
Create_field
*
newCreateField
(
const
Create_field
&
cf
,
const
std
::
string
&
anonname
=
""
)
const
std
::
string
&
anonname
=
""
)
const
;
const
;
//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
;
//expr is the expression (e.g. a field) over which to sum
Item
*
sumUDA
(
Item
*
const
expr
)
const
;
Item
*
sumUDF
(
Item
*
const
i1
,
Item
*
const
i2
)
const
;
protected
:
protected
:
std
::
string
const
seed_key
;
std
::
string
const
seed_key
;
static
const
uint
nbits
=
1024
;
mutable
Paillier_priv
*
sk
;
private
:
void
unwait
()
const
;
mutable
bool
waiting
;
};
};
class
Search
:
public
EncLayer
{
class
Search
:
public
EncLayer
{
public
:
public
:
Search
(
const
Create_field
&
cf
,
const
std
::
string
&
seed_key
);
Search
(
const
Create_field
&
cf
,
const
std
::
string
&
seed_key
);
...
...
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