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
5bf37a6b
Commit
5bf37a6b
authored
May 05, 2018
by
yiwenshao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add tests
parent
e4697269
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
149 additions
and
21 deletions
+149
-21
test_ashe.cc
test_crypto/test_ashe.cc
+43
-0
test_blowfish.cc
test_crypto/test_blowfish.cc
+36
-0
test_ope.cc
test_crypto/test_ope.cc
+0
-5
test_ope_int.cc
test_crypto/test_ope_int.cc
+23
-16
test_ope_str.cc
test_crypto/test_ope_str.cc
+47
-0
No files found.
test_crypto/test_ashe.cc
0 → 100644
View file @
5bf37a6b
#include <string>
#include <map>
#include <iostream>
#include <memory>
#include <crypto/padding.hh>
#include <crypto/prng.hh>
#include <crypto/BasicCrypto.hh>
#include <crypto/blowfish.hh>
#include <crypto/arc4.hh>
#include <crypto/ASHE.hh>
#include <util/util.hh>
#include <NTL/ZZ.h>
#include "util/timer.hh"
int
main
(
int
argc
,
char
**
argv
){
RAW_ASHE
ashe
(
1
);
int
num_of_tests
=
10000
;
if
(
argc
==
2
){
num_of_tests
=
std
::
stoi
(
std
::
string
(
argv
[
1
]));
}
else
{
std
::
cout
<<
"num_of_tests"
<<
std
::
endl
;
return
0
;
}
unsigned
int
pt
=
1u
;
timer
t
;
std
::
pair
<
long
,
uint64_t
>
res
;
for
(
int
i
=
0
;
i
<
num_of_tests
;
i
++
)
{
res
=
ashe
.
encrypt
(
pt
,
0
);
}
std
::
cout
<<
"enc_ashe_in_us: "
<<
t
.
lap
()
*
1.0
/
num_of_tests
<<
std
::
endl
;
for
(
int
i
=
0
;
i
<
num_of_tests
;
i
++
)
{
ashe
.
decrypt
(
res
.
first
,
0
);
}
std
::
cout
<<
"dec_ashe_in_us: "
<<
t
.
lap
()
*
1.0
/
num_of_tests
<<
std
::
endl
;
return
0
;
}
test_crypto/test_blowfish.cc
0 → 100644
View file @
5bf37a6b
#include <string>
#include <map>
#include <iostream>
#include <memory>
#include <crypto/padding.hh>
#include <crypto/prng.hh>
#include <crypto/BasicCrypto.hh>
#include <crypto/blowfish.hh>
#include <crypto/arc4.hh>
#include <util/util.hh>
#include <NTL/ZZ.h>
#include "util/timer.hh"
int
main
(
int
argc
,
char
**
argv
){
blowfish
bf
(
"key"
);
int
num_of_tests
=
10000
;
if
(
argc
==
2
){
num_of_tests
=
std
::
stoi
(
std
::
string
(
argv
[
1
]));
}
else
{
std
::
cout
<<
"num_of_tests"
<<
std
::
endl
;
return
0
;
}
uint64_t
plain
=
111u
;
uint64_t
cipher
;
timer
t
;
for
(
int
i
=
0
;
i
<
num_of_tests
;
i
++
)
{
cipher
=
bf
.
encrypt
(
plain
);
}
std
::
cout
<<
"enc_blowfish_in_us: "
<<
t
.
lap
()
*
1.0
/
num_of_tests
<<
std
::
endl
;
for
(
int
i
=
0
;
i
<
num_of_tests
;
i
++
)
{
bf
.
decrypt
(
cipher
);
}
std
::
cout
<<
"dec_blowfish_in_us: "
<<
t
.
lap
()
*
1.0
/
num_of_tests
<<
std
::
endl
;
return
0
;
}
test_crypto/test_ope.cc
deleted
100644 → 0
View file @
e4697269
int
main
()
{
return
0
;
}
test_crypto/test_ope_int.cc
View file @
5bf37a6b
...
...
@@ -12,34 +12,41 @@
#include <crypto/ope.hh>
#include <util/util.hh>
#include <NTL/ZZ.h>
#include "util/timer.hh"
using
namespace
NTL
;
static
std
::
string
prng_expand
(
const
std
::
string
&
seed_key
,
uint
key_bytes
){
streamrng
<
arc4
>
prng
(
seed_key
);
return
prng
.
rand_string
(
key_bytes
);
}
static
void
test_OPEint
()
{
int
main
(
int
argc
,
char
**
argv
){
int
num_of_tests
=
10000
;
if
(
argc
==
2
){
num_of_tests
=
std
::
stoi
(
std
::
string
(
argv
[
1
]));
}
else
{
std
::
cout
<<
"num_of_tests"
<<
std
::
endl
;
return
0
;
}
std
::
string
key
=
"12345798797"
;
std
::
string
rawkey
=
prng_expand
(
key
,
16
);
const
size_t
plain_size
=
4
;
const
size_t
ciph_size
=
8
;
OPE
ope
(
rawkey
,
8
*
plain_size
,
8
*
ciph_size
);
uint64_t
plaintext
=
123456789
;
NTL
::
ZZ
enc
,
dec
;
uint64_t
enc64
,
dec64
;
enc
=
ope
.
encrypt
(
ZZFromUint64
(
plaintext
));
enc64
=
uint64FromZZ
(
enc
);
dec
=
ope
.
decrypt
(
ZZFromUint64
(
enc64
));
dec64
=
uint64FromZZ
(
dec
);
std
::
cout
<<
"enc: "
<<
enc
<<
"dec: "
<<
dec
<<
std
::
endl
;
std
::
cout
<<
"enc64: "
<<
enc64
<<
"dec64:"
<<
dec64
<<
std
::
endl
;
}
uint64_t
enc64
;
int
main
(){
test_OPEint
();
return
0
;
timer
t
;
for
(
int
i
=
0
;
i
<
num_of_tests
;
i
++
)
{
enc
=
ope
.
encrypt
(
ZZFromUint64
(
plaintext
));
}
std
::
cout
<<
"enc_ope_int_in_us: "
<<
t
.
lap
()
*
1.0
/
num_of_tests
<<
std
::
endl
;
enc64
=
uint64FromZZ
(
enc
);
for
(
int
i
=
0
;
i
<
num_of_tests
;
i
++
)
{
dec
=
ope
.
decrypt
(
ZZFromUint64
(
enc64
));
}
std
::
cout
<<
"dec_ope_int_in_us: "
<<
t
.
lap
()
*
1.0
/
num_of_tests
<<
std
::
endl
;
return
0
;
}
test_crypto/test_ope_str.cc
0 → 100644
View file @
5bf37a6b
#include <string>
#include <map>
#include <iostream>
#include <memory>
#include <iomanip>
#include <crypto/padding.hh>
#include <crypto/prng.hh>
#include <crypto/BasicCrypto.hh>
#include <crypto/blowfish.hh>
#include <crypto/arc4.hh>
#include <crypto/cbc.hh>
#include <crypto/ope.hh>
#include <util/util.hh>
#include <NTL/ZZ.h>
#include "util/timer.hh"
using
namespace
NTL
;
static
std
::
string
prng_expand
(
const
std
::
string
&
seed_key
,
uint
key_bytes
){
streamrng
<
arc4
>
prng
(
seed_key
);
return
prng
.
rand_string
(
key_bytes
);
}
int
main
(
int
argc
,
char
**
argv
){
int
num_of_tests
=
10000
;
if
(
argc
==
2
){
num_of_tests
=
std
::
stoi
(
std
::
string
(
argv
[
1
]));
}
else
{
std
::
cout
<<
"num_of_tests"
<<
std
::
endl
;
return
0
;
}
std
::
string
key
=
"12345798797"
;
std
::
string
rawkey
=
prng_expand
(
key
,
16
);
const
size_t
plain_size
=
4
;
const
size_t
ciph_size
=
8
;
OPE
ope
(
rawkey
,
8
*
plain_size
,
8
*
ciph_size
);
std
::
string
ps
=
"1234567890"
;
timer
t
;
for
(
int
i
=
0
;
i
<
num_of_tests
;
i
++
)
{
uint32_t
pv
=
0
;
for
(
uint
i
=
0
;
i
<
plain_size
;
i
++
)
{
pv
=
pv
*
256
+
static_cast
<
int
>
(
ps
[
i
]);
}
ope
.
encrypt
(
to_ZZ
(
pv
));
}
std
::
cout
<<
"enc_ope_str_in_us: "
<<
t
.
lap
()
*
1.0
/
num_of_tests
<<
std
::
endl
;
return
0
;
}
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