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
62455e49
Commit
62455e49
authored
Dec 26, 2017
by
yiwenshao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add comments for UDF
parent
c791641c
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
31 deletions
+38
-31
test_HOM.cc
debug/test_HOM.cc
+7
-3
edb.cc
udf/edb.cc
+31
-28
No files found.
debug/test_HOM.cc
View file @
62455e49
...
...
@@ -6,6 +6,7 @@
#include <crypto/paillier.hh>
#include <crypto/arc4.hh>
#include <NTL/ZZ.h>
#include <assert.h>
using
namespace
NTL
;
using
std
::
string
;
using
std
::
cout
;
...
...
@@ -26,12 +27,13 @@ static uint64_t cur_usec() {
}
/*
static void test_paillier_priv(){
static
void
test_paillier_priv
(){
Paillier_priv
*
sk
;
string
seed_key
=
"1234567678"
;
const
std
::
unique_ptr
<
streamrng
<
arc4
>>
prng
(
new
streamrng
<
arc4
>
(
seed_key
));
urandom
u
;
sk
=
new
Paillier_priv
(
Paillier_priv
::
keygen
(
prng
.
get
(),
1024
));
for
(
int
i
=
0
;
i
<
1024
;
i
++
){
ZZ
pt0
=
u
.
rand_zz_mod
(
to_ZZ
(
1
)
<<
20
);
ZZ
pt1
=
u
.
rand_zz_mod
(
to_ZZ
(
1
)
<<
20
);
...
...
@@ -45,7 +47,7 @@ static uint64_t cur_usec() {
cout
<<
"PASS"
<<
endl
;
}
}
*/
}
static
void
test_paillier_time
()
{
Paillier_priv
*
sk
;
...
...
@@ -53,9 +55,9 @@ static void test_paillier_time() {
const
std
::
unique_ptr
<
streamrng
<
arc4
>>
prng
(
new
streamrng
<
arc4
>
(
seed_key
));
urandom
u
;
sk
=
new
Paillier_priv
(
Paillier_priv
::
keygen
(
prng
.
get
(),
1024
));
ZZ
pt0
=
u
.
rand_zz_mod
(
to_ZZ
(
1
)
<<
20
);
cout
<<
"numOfTests: "
<<
numOfTest
<<
endl
;
ZZ
enc0
;
uint64_t
start
=
cur_usec
();
for
(
int
i
=
0
;
i
<
numOfTest
;
i
++
){
...
...
@@ -72,9 +74,11 @@ static void test_paillier_time() {
end
=
cur_usec
();
cout
<<
"decryption: "
<<
(
end
-
start
)
*
1.0
/
numOfTest
<<
endl
;
}
int
main
()
{
test_paillier_time
();
test_paillier_priv
();
return
0
;
}
udf/edb.cc
View file @
62455e49
...
...
@@ -399,12 +399,11 @@ cryptdb_searchSWP_init(UDF_INIT *const initid, UDF_ARGS *const args,
if
(
args
->
arg_count
!=
3
||
args
->
arg_type
[
0
]
!=
STRING_RESULT
||
args
->
arg_type
[
1
]
!=
STRING_RESULT
||
args
->
arg_type
[
2
]
!=
STRING_RESULT
)
{
strcpy
(
message
,
"Usage: cryptdb_searchSWP(string ciphertext,
string ciph, string wordKey)"
);
args
->
arg_type
[
2
]
!=
STRING_RESULT
)
{
strcpy
(
message
,
"Usage: cryptdb_searchSWP(string ciphertext,\
string ciph, string wordKey)"
);
return
1
;
}
Token
*
const
t
=
new
Token
();
uint64_t
ciphLen
;
...
...
@@ -442,11 +441,16 @@ cryptdb_searchSWP(UDF_INIT *const initid, UDF_ARGS *const args,
}
/**********************************************************************
*************************Begin UDF for SUM******************************
***********************************************************************
*/
struct
agg_state
{
ZZ
sum
;
ZZ
n2
;
ZZ
sum
;
/*the results of sum*/
ZZ
n2
;
/*n2 is the public key and for each group, n2 must be set*/
bool
n2_set
;
void
*
rbuf
;
void
*
rbuf
;
/*convert sum to void* and return*/
};
my_bool
...
...
@@ -455,8 +459,7 @@ cryptdb_agg_init(UDF_INIT *const initid, UDF_ARGS *const args,
{
if
(
args
->
arg_count
!=
2
||
args
->
arg_type
[
0
]
!=
STRING_RESULT
||
args
->
arg_type
[
1
]
!=
STRING_RESULT
)
{
args
->
arg_type
[
1
]
!=
STRING_RESULT
){
strcpy
(
message
,
"Usage: cryptdb_agg(string ciphertext, string pubkey)"
);
return
1
;
}
...
...
@@ -469,40 +472,35 @@ cryptdb_agg_init(UDF_INIT *const initid, UDF_ARGS *const args,
}
void
cryptdb_agg_deinit
(
UDF_INIT
*
const
initid
)
{
cryptdb_agg_deinit
(
UDF_INIT
*
const
initid
){
agg_state
*
const
as
=
reinterpret_cast
<
agg_state
*>
(
initid
->
ptr
);
free
(
as
->
rbuf
);
delete
as
;
}
/
/
When we want to add by zero for HOM values we can multiply our value
// by 1.
/
*
When we want to add by zero for HOM values we can multiply our value
by 1.*/
void
cryptdb_agg_clear
(
UDF_INIT
*
const
initid
,
char
*
const
is_null
,
char
*
const
error
)
{
cryptdb_agg_clear
(
UDF_INIT
*
const
initid
,
char
*
const
is_null
,
char
*
const
error
){
agg_state
*
const
as
=
reinterpret_cast
<
agg_state
*>
(
initid
->
ptr
);
as
->
sum
=
to_ZZ
(
1
);
as
->
n2_set
=
0
;
}
/
/args will be element to add, constant N2
/
*args will be element to add, constant N2*/
my_bool
cryptdb_agg_add
(
UDF_INIT
*
const
initid
,
UDF_ARGS
*
const
args
,
char
*
const
is_null
,
char
*
const
error
)
{
//cerr << "in agg_add \n";
char
*
const
is_null
,
char
*
const
error
){
agg_state
*
const
as
=
reinterpret_cast
<
agg_state
*>
(
initid
->
ptr
);
/*for each group, read and set n2*/
if
(
!
as
->
n2_set
)
{
//cerr << "n2 length is " << args->lengths[1] << "\n";
//cerr << "n2 first byte is " << (int)args->args[1][0] << "\n";
ZZFromBytes
(
as
->
n2
,
reinterpret_cast
<
const
uint8_t
*>
(
args
->
args
[
1
]),
args
->
lengths
[
1
]);
//cerr << "n2 is " << as->n2 << "\n";
as
->
n2_set
=
1
;
}
/*add current item e, which is converted from args->args[0]*/
ZZ
e
;
if
(
NULL
==
args
->
args
[
0
])
{
e
=
to_ZZ
(
1
);
...
...
@@ -510,17 +508,15 @@ cryptdb_agg_add(UDF_INIT *const initid, UDF_ARGS *const args,
ZZFromBytes
(
e
,
reinterpret_cast
<
const
uint8_t
*>
(
args
->
args
[
0
]),
args
->
lengths
[
0
]);
}
//cerr << "element to add " << e << "\n";
std
::
cerr
<<
"element to add "
<<
e
<<
"
\n
"
;
MulMod
(
as
->
sum
,
as
->
sum
,
e
,
as
->
n2
);
//
cerr << "sum so far " << as->sum << "\n";
std
::
cerr
<<
"sum so far "
<<
as
->
sum
<<
"
\n
"
;
return
true
;
}
char
*
cryptdb_agg
(
UDF_INIT
*
const
initid
,
UDF_ARGS
*
const
args
,
char
*
const
result
,
unsigned
long
*
const
length
,
char
*
const
is_null
,
char
*
const
error
)
{
unsigned
long
*
const
length
,
char
*
const
is_null
,
char
*
const
error
){
agg_state
*
const
as
=
reinterpret_cast
<
agg_state
*>
(
initid
->
ptr
);
BytesFromZZ
(
static_cast
<
uint8_t
*>
(
as
->
rbuf
),
as
->
sum
,
Paillier_len_bytes
);
...
...
@@ -528,6 +524,13 @@ cryptdb_agg(UDF_INIT *const initid, UDF_ARGS *const args, char *const result,
return
static_cast
<
char
*>
(
as
->
rbuf
);
}
/*
*****************************************************************************
*/
// for update with increment
// > UNUSED
...
...
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