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
41b04d2d
Commit
41b04d2d
authored
Jan 08, 2018
by
yiwenshao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
limited version of ASHE that is able to decrypt and sum
parent
d70378b3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
30 deletions
+36
-30
ASHE.cc
crypto/ASHE.cc
+17
-12
ASHE.hh
crypto/ASHE.hh
+8
-7
test_ASHE.cc
debug/test_ASHE.cc
+11
-11
No files found.
crypto/ASHE.cc
View file @
41b04d2d
#include"crypto/ASHE.hh"
#include "crypto/ASHE.hh"
const
unsigned
long
ASHE
::
ASHE_MAX
=
0xffffffffffffffff
;
#include <iostream>
const
unsigned
int
ASHE
::
ASHE_MAX
=
0xffffffff
;
const
std
::
string
ASHE
::
key
(
"11223344"
);
const
std
::
string
ASHE
::
key
(
"11223344"
);
blowfish
ASHE
::
bf
(
ASHE
::
key
);
blowfish
ASHE
::
bf
(
ASHE
::
key
);
ASHE
::
ASHE
(
int
i
)
:
IV
(
i
){
ASHE
::
ASHE
(
int
i
)
:
IV
(
i
){
}
}
std
::
pair
<
long
,
uint64_t
>
ASHE
::
encrypt
(
unsigned
long
plaintext
){
std
::
pair
<
long
,
uint64_t
>
ASHE
::
encrypt
(
unsigned
int
plaintext
){
ciphertext
=
(
plaintext
-
Fi
(
IV
)
+
Fi_1
(
IV
))
%
ASHE_MAX
;
uint64_t
i
=
Fi
(
IV
)
%
ASHE_MAX
,
i_1
=
Fi_1
(
IV
)
%
ASHE_MAX
;
long
res
=
(
long
)
i_1
-
(
long
)
i
;
ciphertext
=
((
long
)
plaintext
+
res
)
%
ASHE_MAX
;
return
std
::
make_pair
(
ciphertext
,
IV
);
return
std
::
make_pair
(
ciphertext
,
IV
);
}
}
unsigned
long
ASHE
::
decrypt
(
long
ciphertext
){
unsigned
int
ASHE
::
decrypt
(
long
ciphertext
){
return
(
ciphertext
+
Fi
(
IV
)
-
Fi_1
(
IV
))
%
ASHE_MAX
;
uint64_t
i
=
Fi
(
IV
)
%
ASHE_MAX
,
i_1
=
Fi_1
(
IV
)
%
ASHE_MAX
;
long
res
=
(
long
)
i
-
(
long
)
i_1
;
return
(
ciphertext
+
res
)
%
ASHE_MAX
;
}
}
std
::
pair
<
long
,
std
::
vector
<
uint64_t
>>
ASHE
::
sum
(
std
::
vector
<
ASHE
>
input
){
std
::
pair
<
long
,
std
::
vector
<
uint64_t
>>
ASHE
::
sum
(
std
::
vector
<
ASHE
>
input
){
long
res
=
0
;
long
res
=
0
;
std
::
vector
<
uint64_t
>
ivs
;
std
::
vector
<
uint64_t
>
ivs
;
for
(
auto
&
item
:
input
){
for
(
auto
&
item
:
input
){
res
+=
item
.
get_ciphertext
();
long
cph
=
item
.
get_ciphertext
();
res
+=
cph
;
res
%=
ASHE_MAX
;
res
%=
ASHE_MAX
;
ivs
.
push_back
(
item
.
get_IV
());
ivs
.
push_back
(
item
.
get_IV
());
}
}
...
@@ -30,9 +33,11 @@ std::pair<long,std::vector<uint64_t>> ASHE::sum(std::vector<ASHE> input){
...
@@ -30,9 +33,11 @@ std::pair<long,std::vector<uint64_t>> ASHE::sum(std::vector<ASHE> input){
}
}
uint64_t
ASHE
::
decrypt_sum
(
std
::
pair
<
long
,
std
::
vector
<
uint64_t
>>
input
){
uint64_t
ASHE
::
decrypt_sum
(
std
::
pair
<
long
,
std
::
vector
<
uint64_t
>>
input
){
uint64_t
res
=
input
.
first
;
long
res
=
input
.
first
;
for
(
auto
item
:
input
.
second
){
for
(
auto
item
:
input
.
second
){
res
+=
(
Fi
(
item
)
-
Fi_1
(
item
));
uint64_t
i
=
Fi
(
item
)
%
ASHE_MAX
,
i_1
=
Fi_1
(
item
)
%
ASHE_MAX
;
long
target
=
(
long
)
i
-
(
long
)
i_1
;
res
+=
target
;
res
%=
ASHE_MAX
;
res
%=
ASHE_MAX
;
}
}
return
res
;
return
res
;
...
...
crypto/ASHE.hh
View file @
41b04d2d
...
@@ -4,22 +4,23 @@
...
@@ -4,22 +4,23 @@
#include "crypto/blowfish.hh"
#include "crypto/blowfish.hh"
class
ASHE
{
class
ASHE
{
static
const
unsigned
long
ASHE_MAX
;
static
const
unsigned
int
ASHE_MAX
;
/*n*/
static
const
std
::
string
key
;
static
const
std
::
string
key
;
static
blowfish
bf
;
static
blowfish
bf
;
uint64_t
IV
;
uint64_t
IV
;
long
ciphertext
;
long
ciphertext
;
public
:
public
:
ASHE
(
int
iv
);
static
uint64_t
Fi
(
uint64_t
IV
){
return
bf
.
encrypt
(
IV
);}
static
uint64_t
Fi_1
(
uint64_t
IV
){
return
bf
.
encrypt
(
IV
-
1
);}
long
get_ciphertext
(){
return
ciphertext
;}
long
get_ciphertext
(){
return
ciphertext
;}
ASHE
(
int
iv
);
std
::
pair
<
long
,
uint64_t
>
encrypt
(
unsigned
long
plaintext
);
std
::
pair
<
long
,
uint64_t
>
encrypt
(
unsigned
int
plaintext
);
unsigned
int
decrypt
(
long
ciphertext
);
uint64_t
get_IV
(){
return
IV
;};
uint64_t
get_IV
(){
return
IV
;};
unsigned
long
decrypt
(
long
ciphertext
);
static
uint64_t
Fi
(
uint64_t
IV
){
return
bf
.
encrypt
(
IV
)
%
100000
;}
static
uint64_t
Fi_1
(
uint64_t
IV
){
return
bf
.
encrypt
(
IV
-
1
)
%
100000
;}
static
std
::
pair
<
long
,
std
::
vector
<
uint64_t
>>
sum
(
std
::
vector
<
ASHE
>
);
static
std
::
pair
<
long
,
std
::
vector
<
uint64_t
>>
sum
(
std
::
vector
<
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
>>
);
};
};
debug/test_ASHE.cc
View file @
41b04d2d
...
@@ -2,25 +2,25 @@
...
@@ -2,25 +2,25 @@
#include <iostream>
#include <iostream>
#include "crypto/ASHE.hh"
#include "crypto/ASHE.hh"
#include "util/util.cc"
#include "util/util.cc"
int
main
(){
int
main
(){
std
::
vector
<
unsigned
long
long
>
plain
{
1u
,
2u
,
3u
//,4u,5u,6u,7u,8u,9u,10u
const
int
num_of_tests
=
100
;
};
unsigned
int
seed
=
1u
;
std
::
vector
<
unsigned
int
>
plain
;
std
::
vector
<
ASHE
>
ass
;
std
::
vector
<
ASHE
>
ass
;
for
(
auto
item
:
plain
){
for
(
int
i
=
0
;
i
<
num_of_tests
;
i
++
){
plain
.
push_back
(
seed
);
uint64_t
IV
=
randomValue
();
uint64_t
IV
=
randomValue
();
if
(
IV
==
0
)
IV
=
1
;
if
(
IV
==
0
)
IV
=
1
;
ass
.
push_back
(
ASHE
(
IV
));
ass
.
push_back
(
ASHE
(
IV
));
ass
.
back
().
encrypt
(
item
);
ass
.
back
().
encrypt
(
seed
);
}
unsigned
int
res
=
ass
.
back
().
decrypt
(
ass
.
back
().
get_ciphertext
());
if
(
res
==
seed
)
std
::
cout
<<
"pass"
<<
std
::
endl
;
for
(
auto
&
item
:
ass
){
else
std
::
cout
<<
"not pass!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
<<
std
::
endl
;
s
td
::
cout
<<
item
.
get_ciphertext
()
<<
"::"
<<
item
.
decrypt
(
item
.
get_ciphertext
())
<<
std
::
endl
;
s
eed
++
;
}
}
std
::
pair
<
long
,
std
::
vector
<
uint64_t
>>
enc_sum
=
ASHE
::
sum
(
ass
);
std
::
pair
<
long
,
std
::
vector
<
uint64_t
>>
enc_sum
=
ASHE
::
sum
(
ass
);
long
res
=
ASHE
::
decrypt_sum
(
enc_sum
);
uint64_t
res
=
ASHE
::
decrypt_sum
(
enc_sum
);
std
::
cout
<<
enc_sum
.
first
<<
"::"
<<
res
<<
std
::
endl
;
std
::
cout
<<
enc_sum
.
first
<<
"::"
<<
res
<<
std
::
endl
;
return
0
;
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