Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
sgxwallet
Project
Project
Details
Activity
Releases
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
董子豪
sgxwallet
Commits
ade77718
Unverified
Commit
ade77718
authored
Jun 24, 2020
by
Oleh Nikolaiev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SKALE-2794 refactor code
parent
da0c0687
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
63 additions
and
74 deletions
+63
-74
DKGCrypto.cpp
DKGCrypto.cpp
+1
-1
SEKManager.cpp
SEKManager.cpp
+44
-21
DKGUtils.cpp
secure_enclave/DKGUtils.cpp
+14
-20
EnclaveCommon.cpp
secure_enclave/EnclaveCommon.cpp
+3
-11
testw.cpp
testw.cpp
+1
-21
No files found.
DKGCrypto.cpp
View file @
ade77718
...
@@ -242,7 +242,7 @@ verifyShares(const char *publicShares, const char *encr_sshare, const char *encr
...
@@ -242,7 +242,7 @@ verifyShares(const char *publicShares, const char *encr_sshare, const char *encr
trustedDkgVerifyAES
(
eid
,
&
errStatus
,
errMsg
,
pshares
,
encr_sshare
,
encr_key
,
decKeyLen
,
t
,
ind
,
&
result
);
trustedDkgVerifyAES
(
eid
,
&
errStatus
,
errMsg
,
pshares
,
encr_sshare
,
encr_key
,
decKeyLen
,
t
,
ind
,
&
result
);
if
(
errStatus
!=
0
)
{
if
(
errStatus
!=
0
)
{
throw
SGXException
(
-
666
,
errMsg
1
.
data
()
);
throw
SGXException
(
-
666
,
errMsg
);
}
}
if
(
result
==
2
)
{
if
(
result
==
2
)
{
...
...
SEKManager.cpp
View file @
ade77718
...
@@ -43,7 +43,7 @@ bool case_insensitive_match(string s1, string s2) {
...
@@ -43,7 +43,7 @@ bool case_insensitive_match(string s1, string s2) {
return
s1
.
compare
(
s2
);
return
s1
.
compare
(
s2
);
}
}
void
create_test_key
(){
void
create_test_key
()
{
int
errStatus
=
0
;
int
errStatus
=
0
;
vector
<
char
>
errMsg
(
1024
,
0
);
vector
<
char
>
errMsg
(
1024
,
0
);
uint32_t
enc_len
;
uint32_t
enc_len
;
...
@@ -54,30 +54,34 @@ void create_test_key(){
...
@@ -54,30 +54,34 @@ void create_test_key(){
std
::
string
key
=
TEST_VALUE
;
std
::
string
key
=
TEST_VALUE
;
status
=
trustedEncryptKeyAES
(
eid
,
&
errStatus
,
errMsg
.
data
(),
key
.
c_str
(),
encrypted_key
,
&
enc_len
);
status
=
trustedEncryptKeyAES
(
eid
,
&
errStatus
,
errMsg
.
data
(),
key
.
c_str
(),
encrypted_key
,
&
enc_len
);
if
(
status
!=
0
)
{
if
(
status
!=
SGX_SUCCESS
)
{
std
::
cerr
<<
"encrypt test key failed with status "
<<
status
<<
std
::
endl
;
std
::
cerr
<<
"encrypt test key failed with status "
<<
status
<<
std
::
endl
;
throw
SGXException
(
status
,
errMsg
.
data
())
;
throw
SGXException
(
status
,
errMsg
.
data
())
;
}
}
if
(
errStatus
!=
0
)
{
std
::
cerr
<<
"encrypt test key failed with status "
<<
errStatus
<<
std
::
endl
;
throw
SGXException
(
errStatus
,
errMsg
.
data
())
;
}
vector
<
char
>
hexEncrKey
(
2
*
enc_len
+
1
,
0
);
vector
<
char
>
hexEncrKey
(
2
*
enc_len
+
1
,
0
);
carray2Hex
(
encrypted_key
,
enc_len
,
hexEncrKey
.
data
());
carray2Hex
(
encrypted_key
,
enc_len
,
hexEncrKey
.
data
());
uint64_t
test_len
;
uint64_t
test_len
;
vector
<
uint8_t
>
test_encr_key
(
1024
,
0
);
vector
<
uint8_t
>
test_encr_key
(
1024
,
0
);
if
(
!
hex2carray
(
hexEncrKey
.
data
(),
&
test_len
,
test_encr_key
.
data
())){
if
(
!
hex2carray
(
hexEncrKey
.
data
(),
&
test_len
,
test_encr_key
.
data
()))
{
std
::
cerr
<<
"wrong encrypted test key"
<<
std
::
endl
;
std
::
cerr
<<
"wrong encrypted test key"
<<
std
::
endl
;
}
}
LevelDB
::
getLevelDb
()
->
writeDataUnique
(
"TEST_KEY"
,
hexEncrKey
.
data
());
LevelDB
::
getLevelDb
()
->
writeDataUnique
(
"TEST_KEY"
,
hexEncrKey
.
data
());
}
}
bool
check_SEK
(
std
::
string
SEK
)
{
bool
check_SEK
(
const
std
::
string
&
SEK
)
{
std
::
shared_ptr
<
std
::
string
>
test_key_ptr
=
LevelDB
::
getLevelDb
()
->
readString
(
"TEST_KEY"
);
std
::
shared_ptr
<
std
::
string
>
test_key_ptr
=
LevelDB
::
getLevelDb
()
->
readString
(
"TEST_KEY"
);
vector
<
uint8_t
>
encr_test_key
(
BUF_LEN
,
0
);
vector
<
uint8_t
>
encr_test_key
(
BUF_LEN
,
0
);
uint64_t
len
;
uint64_t
len
;
if
(
!
hex2carray
(
test_key_ptr
->
c_str
(),
&
len
,
encr_test_key
.
data
()))
{
if
(
!
hex2carray
(
test_key_ptr
->
c_str
(),
&
len
,
encr_test_key
.
data
()))
{
spdlog
::
error
(
"wrong test key"
);
spdlog
::
error
(
"wrong test key"
);
exit
(
-
1
);
exit
(
-
1
);
}
}
...
@@ -91,20 +95,25 @@ bool check_SEK(std::string SEK){
...
@@ -91,20 +95,25 @@ bool check_SEK(std::string SEK){
uint32_t
l
=
len
;
uint32_t
l
=
len
;
status
=
trustedSetSEK_backup
(
eid
,
&
err_status
,
errMsg
.
data
(),
encr_SEK
.
data
(),
&
l
,
SEK
.
c_str
()
);
status
=
trustedSetSEK_backup
(
eid
,
&
err_status
,
errMsg
.
data
(),
encr_SEK
.
data
(),
&
l
,
SEK
.
c_str
()
);
if
(
status
!=
SGX_SUCCESS
){
if
(
status
!=
SGX_SUCCESS
)
{
cerr
<<
"RPCException thrown with status "
<<
status
<<
endl
;
cerr
<<
"RPCException thrown with status "
<<
status
<<
endl
;
throw
SGXException
(
status
,
errMsg
.
data
());
throw
SGXException
(
status
,
errMsg
.
data
());
}
}
if
(
err_status
!=
0
)
{
cerr
<<
"RPCException thrown with status "
<<
err_status
<<
endl
;
throw
SGXException
(
err_status
,
errMsg
.
data
());
}
status
=
trustedDecryptKeyAES
(
eid
,
&
err_status
,
errMsg
.
data
(),
encr_test_key
.
data
(),
len
,
decr_key
.
data
());
status
=
trustedDecryptKeyAES
(
eid
,
&
err_status
,
errMsg
.
data
(),
encr_test_key
.
data
(),
len
,
decr_key
.
data
());
if
(
status
!=
SGX_SUCCESS
||
err_status
!=
0
){
if
(
status
!=
SGX_SUCCESS
||
err_status
!=
0
)
{
spdlog
::
error
(
"failed to decrypt test key"
);
spdlog
::
error
(
"failed to decrypt test key"
);
spdlog
::
error
(
errMsg
.
data
());
spdlog
::
error
(
errMsg
.
data
());
exit
(
-
1
);
exit
(
-
1
);
}
}
std
::
string
test_key
=
TEST_VALUE
;
std
::
string
test_key
=
TEST_VALUE
;
if
(
test_key
.
compare
(
decr_key
.
data
())
!=
0
){
if
(
test_key
.
compare
(
decr_key
.
data
())
!=
0
)
{
std
::
cerr
<<
"decrypted key is "
<<
decr_key
.
data
()
<<
std
::
endl
;
std
::
cerr
<<
"decrypted key is "
<<
decr_key
.
data
()
<<
std
::
endl
;
spdlog
::
error
(
"Invalid SEK"
);
spdlog
::
error
(
"Invalid SEK"
);
return
false
;
return
false
;
...
@@ -112,7 +121,7 @@ bool check_SEK(std::string SEK){
...
@@ -112,7 +121,7 @@ bool check_SEK(std::string SEK){
return
true
;
return
true
;
}
}
void
gen_SEK
(){
void
gen_SEK
()
{
vector
<
char
>
errMsg
(
1024
,
0
);
vector
<
char
>
errMsg
(
1024
,
0
);
int
err_status
=
0
;
int
err_status
=
0
;
vector
<
uint8_t
>
encr_SEK
(
1024
,
0
);
vector
<
uint8_t
>
encr_SEK
(
1024
,
0
);
...
@@ -122,10 +131,14 @@ void gen_SEK(){
...
@@ -122,10 +131,14 @@ void gen_SEK(){
memset
(
SEK
,
0
,
65
);
memset
(
SEK
,
0
,
65
);
status
=
trustedGenerateSEK
(
eid
,
&
err_status
,
errMsg
.
data
(),
encr_SEK
.
data
(),
&
enc_len
,
SEK
);
status
=
trustedGenerateSEK
(
eid
,
&
err_status
,
errMsg
.
data
(),
encr_SEK
.
data
(),
&
enc_len
,
SEK
);
if
(
status
!=
SGX_SUCCESS
||
err_status
!=
0
)
{
if
(
status
!=
SGX_SUCCESS
)
{
throw
SGXException
(
status
,
errMsg
.
data
())
;
throw
SGXException
(
status
,
errMsg
.
data
())
;
}
}
if
(
err_status
!=
0
)
{
throw
SGXException
(
err_status
,
errMsg
.
data
())
;
}
vector
<
char
>
hexEncrKey
(
2
*
enc_len
+
1
,
0
);
vector
<
char
>
hexEncrKey
(
2
*
enc_len
+
1
,
0
);
carray2Hex
(
encr_SEK
.
data
(),
enc_len
,
hexEncrKey
.
data
());
carray2Hex
(
encr_SEK
.
data
(),
enc_len
,
hexEncrKey
.
data
());
...
@@ -140,7 +153,7 @@ void gen_SEK(){
...
@@ -140,7 +153,7 @@ void gen_SEK(){
std
::
cout
<<
" DO YOU CONFIRM THAT YOU COPIED THE KEY? (if you confirm type - I confirm)"
std
::
cout
<<
" DO YOU CONFIRM THAT YOU COPIED THE KEY? (if you confirm type - I confirm)"
<<
std
::
endl
;
<<
std
::
endl
;
std
::
getline
(
std
::
cin
,
buffer
);
std
::
getline
(
std
::
cin
,
buffer
);
}
while
(
case_insensitive_match
(
confirm_str
,
buffer
));
//(strcmp(confirm_str.c_str(), buffer.c_str()) != 0);
}
while
(
case_insensitive_match
(
confirm_str
,
buffer
));
}
}
LevelDB
::
getLevelDb
()
->
writeDataUnique
(
"SEK"
,
hexEncrKey
.
data
());
LevelDB
::
getLevelDb
()
->
writeDataUnique
(
"SEK"
,
hexEncrKey
.
data
());
...
@@ -148,7 +161,7 @@ void gen_SEK(){
...
@@ -148,7 +161,7 @@ void gen_SEK(){
create_test_key
();
create_test_key
();
}
}
void
trustedSetSEK
(
std
::
shared_ptr
<
std
::
string
>
hex_encr_SEK
){
void
trustedSetSEK
(
std
::
shared_ptr
<
std
::
string
>
hex_encr_SEK
)
{
vector
<
char
>
errMsg
(
1024
,
0
);
vector
<
char
>
errMsg
(
1024
,
0
);
int
err_status
=
0
;
int
err_status
=
0
;
...
@@ -157,25 +170,30 @@ void trustedSetSEK(std::shared_ptr<std::string> hex_encr_SEK){
...
@@ -157,25 +170,30 @@ void trustedSetSEK(std::shared_ptr<std::string> hex_encr_SEK){
uint64_t
len
;
uint64_t
len
;
if
(
!
hex2carray
(
hex_encr_SEK
->
c_str
(),
&
len
,
encr_SEK
)){
if
(
!
hex2carray
(
hex_encr_SEK
->
c_str
(),
&
len
,
encr_SEK
))
{
throw
SGXException
(
INVALID_HEX
,
"Invalid encrypted SEK Hex"
);
throw
SGXException
(
INVALID_HEX
,
"Invalid encrypted SEK Hex"
);
}
}
status
=
trustedSetSEK
(
eid
,
&
err_status
,
errMsg
.
data
(),
encr_SEK
,
len
);
status
=
trustedSetSEK
(
eid
,
&
err_status
,
errMsg
.
data
(),
encr_SEK
,
len
);
if
(
status
!=
SGX_SUCCESS
||
err_status
!=
0
)
{
if
(
status
!=
SGX_SUCCESS
)
{
cerr
<<
"RPCException thrown"
<<
endl
;
cerr
<<
"RPCException thrown"
<<
endl
;
throw
SGXException
(
status
,
errMsg
.
data
())
;
throw
SGXException
(
status
,
errMsg
.
data
())
;
}
}
if
(
err_status
!=
0
)
{
cerr
<<
"RPCException thrown"
<<
endl
;
throw
SGXException
(
err_status
,
errMsg
.
data
())
;
}
}
}
void
enter_SEK
(){
void
enter_SEK
()
{
vector
<
char
>
errMsg
(
1024
,
0
);
vector
<
char
>
errMsg
(
1024
,
0
);
int
err_status
=
0
;
int
err_status
=
0
;
vector
<
uint8_t
>
encr_SEK
(
BUF_LEN
,
0
);
vector
<
uint8_t
>
encr_SEK
(
BUF_LEN
,
0
);
uint32_t
enc_len
;
uint32_t
enc_len
;
std
::
shared_ptr
<
std
::
string
>
test_key_ptr
=
LevelDB
::
getLevelDb
()
->
readString
(
"TEST_KEY"
);
std
::
shared_ptr
<
std
::
string
>
test_key_ptr
=
LevelDB
::
getLevelDb
()
->
readString
(
"TEST_KEY"
);
if
(
test_key_ptr
==
nullptr
){
if
(
test_key_ptr
==
nullptr
)
{
spdlog
::
error
(
"empty db"
);
spdlog
::
error
(
"empty db"
);
exit
(
-
1
);
exit
(
-
1
);
}
}
...
@@ -183,18 +201,23 @@ void enter_SEK(){
...
@@ -183,18 +201,23 @@ void enter_SEK(){
std
::
string
SEK
;
std
::
string
SEK
;
std
::
cout
<<
"ENTER BACKUP KEY"
<<
std
::
endl
;
std
::
cout
<<
"ENTER BACKUP KEY"
<<
std
::
endl
;
std
::
cin
>>
SEK
;
std
::
cin
>>
SEK
;
while
(
!
checkHex
(
SEK
,
16
)
||
!
check_SEK
(
SEK
)){
while
(
!
checkHex
(
SEK
,
16
)
||
!
check_SEK
(
SEK
))
{
std
::
cout
<<
"KEY IS INVALID.TRY ONCE MORE"
<<
std
::
endl
;
std
::
cout
<<
"KEY IS INVALID.TRY ONCE MORE"
<<
std
::
endl
;
SEK
=
""
;
SEK
=
""
;
std
::
cin
>>
SEK
;
std
::
cin
>>
SEK
;
}
}
status
=
trustedSetSEK_backup
(
eid
,
&
err_status
,
errMsg
.
data
(),
encr_SEK
.
data
(),
&
enc_len
,
SEK
.
c_str
());
status
=
trustedSetSEK_backup
(
eid
,
&
err_status
,
errMsg
.
data
(),
encr_SEK
.
data
(),
&
enc_len
,
SEK
.
c_str
());
if
(
status
!=
SGX_SUCCESS
){
if
(
status
!=
SGX_SUCCESS
)
{
cerr
<<
"RPCException thrown with status "
<<
status
<<
endl
;
cerr
<<
"RPCException thrown with status "
<<
status
<<
endl
;
throw
SGXException
(
status
,
errMsg
.
data
());
throw
SGXException
(
status
,
errMsg
.
data
());
}
}
if
(
err_status
!=
0
)
{
cerr
<<
"RPCException thrown"
<<
endl
;
throw
SGXException
(
err_status
,
errMsg
.
data
())
;
}
vector
<
char
>
hexEncrKey
(
2
*
enc_len
+
1
,
0
);
vector
<
char
>
hexEncrKey
(
2
*
enc_len
+
1
,
0
);
carray2Hex
(
encr_SEK
.
data
(),
enc_len
,
hexEncrKey
.
data
());
carray2Hex
(
encr_SEK
.
data
(),
enc_len
,
hexEncrKey
.
data
());
...
@@ -203,7 +226,7 @@ void enter_SEK(){
...
@@ -203,7 +226,7 @@ void enter_SEK(){
LevelDB
::
getLevelDb
()
->
writeDataUnique
(
"SEK"
,
hexEncrKey
.
data
());
LevelDB
::
getLevelDb
()
->
writeDataUnique
(
"SEK"
,
hexEncrKey
.
data
());
}
}
void
initSEK
(){
void
initSEK
()
{
std
::
shared_ptr
<
std
::
string
>
encr_SEK_ptr
=
LevelDB
::
getLevelDb
()
->
readString
(
"SEK"
);
std
::
shared_ptr
<
std
::
string
>
encr_SEK_ptr
=
LevelDB
::
getLevelDb
()
->
readString
(
"SEK"
);
if
(
encryptKeys
)
{
if
(
encryptKeys
)
{
enter_SEK
();
enter_SEK
();
...
...
secure_enclave/DKGUtils.cpp
View file @
ade77718
...
@@ -42,8 +42,7 @@
...
@@ -42,8 +42,7 @@
using
namespace
std
;
using
namespace
std
;
string
stringFromFr
(
libff
::
alt_bn128_Fr
&
_el
)
{
string
stringFromFr
(
const
libff
::
alt_bn128_Fr
&
_el
)
{
mpz_t
t
;
mpz_t
t
;
mpz_init
(
t
);
mpz_init
(
t
);
...
@@ -57,8 +56,7 @@ string stringFromFr(libff::alt_bn128_Fr& _el) {
...
@@ -57,8 +56,7 @@ string stringFromFr(libff::alt_bn128_Fr& _el) {
return
string
(
tmp
);
return
string
(
tmp
);
}
}
template
<
class
T
>
template
<
class
T
>
string
ConvertToString
(
const
T
&
field_elem
,
int
base
=
10
)
{
string
ConvertToString
(
T
field_elem
,
int
base
=
10
)
{
mpz_t
t
;
mpz_t
t
;
mpz_init
(
t
);
mpz_init
(
t
);
...
@@ -74,7 +72,7 @@ string ConvertToString(T field_elem, int base = 10) {
...
@@ -74,7 +72,7 @@ string ConvertToString(T field_elem, int base = 10) {
return
output
;
return
output
;
}
}
string
ConvertG2ToString
(
const
libff
::
alt_bn128_G2
&
elem
,
int
base
=
10
,
string
delim
=
":"
){
string
ConvertG2ToString
(
const
libff
::
alt_bn128_G2
&
elem
,
int
base
=
10
,
string
delim
=
":"
)
{
string
result
;
string
result
;
result
+=
ConvertToString
(
elem
.
X
.
c0
);
result
+=
ConvertToString
(
elem
.
X
.
c0
);
result
+=
delim
;
result
+=
delim
;
...
@@ -87,7 +85,7 @@ string ConvertG2ToString(const libff::alt_bn128_G2 & elem, int base = 10, string
...
@@ -87,7 +85,7 @@ string ConvertG2ToString(const libff::alt_bn128_G2 & elem, int base = 10, string
return
result
;
return
result
;
}
}
vector
<
libff
::
alt_bn128_Fr
>
SplitStringToFr
(
const
char
*
coeffs
,
const
char
symbol
){
vector
<
libff
::
alt_bn128_Fr
>
SplitStringToFr
(
const
char
*
coeffs
,
const
char
symbol
)
{
string
str
(
coeffs
);
string
str
(
coeffs
);
string
delim
;
string
delim
;
delim
.
push_back
(
symbol
);
delim
.
push_back
(
symbol
);
...
@@ -109,7 +107,7 @@ vector<libff::alt_bn128_Fr> SplitStringToFr(const char* coeffs, const char symbo
...
@@ -109,7 +107,7 @@ vector<libff::alt_bn128_Fr> SplitStringToFr(const char* coeffs, const char symbo
return
tokens
;
return
tokens
;
}
}
int
gen_dkg_poly
(
char
*
secret
,
unsigned
_t
){
int
gen_dkg_poly
(
char
*
secret
,
unsigned
_t
)
{
libff
::
init_alt_bn128_params
();
libff
::
init_alt_bn128_params
();
string
result
;
string
result
;
for
(
size_t
i
=
0
;
i
<
_t
;
++
i
)
{
for
(
size_t
i
=
0
;
i
<
_t
;
++
i
)
{
...
@@ -151,7 +149,7 @@ void calc_secret_shares(const char* decrypted_coeffs, char * secret_shares,
...
@@ -151,7 +149,7 @@ void calc_secret_shares(const char* decrypted_coeffs, char * secret_shares,
for
(
size_t
i
=
0
;
i
<
_n
;
++
i
)
{
for
(
size_t
i
=
0
;
i
<
_n
;
++
i
)
{
libff
::
alt_bn128_Fr
secret_share
=
PolynomialValue
(
poly
,
libff
::
alt_bn128_Fr
(
i
+
1
),
_t
);
libff
::
alt_bn128_Fr
secret_share
=
PolynomialValue
(
poly
,
libff
::
alt_bn128_Fr
(
i
+
1
),
_t
);
result
+=
ConvertToString
(
secret_share
);
//stringFromFr(secret_share);
result
+=
ConvertToString
(
secret_share
);
result
+=
":"
;
result
+=
":"
;
}
}
strncpy
(
secret_shares
,
result
.
c_str
(),
result
.
length
()
+
1
);
strncpy
(
secret_shares
,
result
.
c_str
(),
result
.
length
()
+
1
);
...
@@ -162,7 +160,7 @@ int calc_secret_share(const char* decrypted_coeffs, char * s_share,
...
@@ -162,7 +160,7 @@ int calc_secret_share(const char* decrypted_coeffs, char * s_share,
libff
::
init_alt_bn128_params
();
libff
::
init_alt_bn128_params
();
char
symbol
=
':'
;
char
symbol
=
':'
;
vector
<
libff
::
alt_bn128_Fr
>
poly
=
SplitStringToFr
(
decrypted_coeffs
,
symbol
);
vector
<
libff
::
alt_bn128_Fr
>
poly
=
SplitStringToFr
(
decrypted_coeffs
,
symbol
);
if
(
poly
.
size
()
!=
_t
){
if
(
poly
.
size
()
!=
_t
)
{
return
1
;
return
1
;
}
}
...
@@ -190,7 +188,7 @@ void calc_secret_shareG2_old(const char* decrypted_coeffs, char * s_shareG2,
...
@@ -190,7 +188,7 @@ void calc_secret_shareG2_old(const char* decrypted_coeffs, char * s_shareG2,
strncpy
(
s_shareG2
,
secret_shareG2_str
.
c_str
(),
secret_shareG2_str
.
length
()
+
1
);
strncpy
(
s_shareG2
,
secret_shareG2_str
.
c_str
(),
secret_shareG2_str
.
length
()
+
1
);
}
}
int
calc_secret_shareG2
(
const
char
*
s_share
,
char
*
s_shareG2
){
int
calc_secret_shareG2
(
const
char
*
s_share
,
char
*
s_shareG2
)
{
libff
::
init_alt_bn128_params
();
libff
::
init_alt_bn128_params
();
mpz_t
share
;
mpz_t
share
;
...
@@ -225,7 +223,7 @@ int calc_public_shares(const char* decrypted_coeffs, char * public_shares,
...
@@ -225,7 +223,7 @@ int calc_public_shares(const char* decrypted_coeffs, char * public_shares,
string
result
;
string
result
;
char
symbol
=
':'
;
char
symbol
=
':'
;
vector
<
libff
::
alt_bn128_Fr
>
poly
=
SplitStringToFr
(
decrypted_coeffs
,
symbol
);
vector
<
libff
::
alt_bn128_Fr
>
poly
=
SplitStringToFr
(
decrypted_coeffs
,
symbol
);
if
(
poly
.
size
()
!=
_t
){
if
(
poly
.
size
()
!=
_t
)
{
return
1
;
return
1
;
}
}
for
(
size_t
i
=
0
;
i
<
_t
;
++
i
)
{
for
(
size_t
i
=
0
;
i
<
_t
;
++
i
)
{
...
@@ -255,7 +253,7 @@ string ConvertHexToDec(string hex_str){
...
@@ -255,7 +253,7 @@ string ConvertHexToDec(string hex_str){
return
result
;
return
result
;
}
}
int
Verification
(
char
*
public_shares
,
mpz_t
decr_secret_share
,
int
_t
,
int
ind
)
{
int
Verification
(
char
*
public_shares
,
mpz_t
decr_secret_share
,
int
_t
,
int
ind
)
{
string
pub_shares_str
=
public_shares
;
string
pub_shares_str
=
public_shares
;
libff
::
init_alt_bn128_params
();
libff
::
init_alt_bn128_params
();
...
@@ -307,7 +305,7 @@ int Verification ( char * public_shares, mpz_t decr_secret_share, int _t, int in
...
@@ -307,7 +305,7 @@ int Verification ( char * public_shares, mpz_t decr_secret_share, int _t, int in
return
(
val
==
sshare
*
libff
::
alt_bn128_G2
::
one
());
return
(
val
==
sshare
*
libff
::
alt_bn128_G2
::
one
());
}
}
int
calc_bls_public_key
(
char
*
skey_hex
,
char
*
pub_key
){
int
calc_bls_public_key
(
char
*
skey_hex
,
char
*
pub_key
)
{
libff
::
init_alt_bn128_params
();
libff
::
init_alt_bn128_params
();
mpz_t
skey
;
mpz_t
skey
;
...
@@ -333,7 +331,3 @@ int calc_bls_public_key(char* skey_hex, char* pub_key){
...
@@ -333,7 +331,3 @@ int calc_bls_public_key(char* skey_hex, char* pub_key){
return
0
;
return
0
;
}
}
secure_enclave/EnclaveCommon.cpp
View file @
ade77718
...
@@ -36,7 +36,6 @@
...
@@ -36,7 +36,6 @@
using
namespace
std
;
using
namespace
std
;
string
*
stringFromKey
(
libff
::
alt_bn128_Fr
*
_key
)
{
string
*
stringFromKey
(
libff
::
alt_bn128_Fr
*
_key
)
{
mpz_t
t
;
mpz_t
t
;
mpz_init
(
t
);
mpz_init
(
t
);
...
@@ -79,7 +78,6 @@ string *stringFromG1(libff::alt_bn128_G1 *_g1) {
...
@@ -79,7 +78,6 @@ string *stringFromG1(libff::alt_bn128_G1 *_g1) {
return
sG1
;
return
sG1
;
}
}
libff
::
alt_bn128_Fr
*
keyFromString
(
const
char
*
_keyStringHex
)
{
libff
::
alt_bn128_Fr
*
keyFromString
(
const
char
*
_keyStringHex
)
{
mpz_t
skey
;
mpz_t
skey
;
mpz_init
(
skey
);
mpz_init
(
skey
);
...
@@ -92,7 +90,6 @@ libff::alt_bn128_Fr *keyFromString(const char *_keyStringHex) {
...
@@ -92,7 +90,6 @@ libff::alt_bn128_Fr *keyFromString(const char *_keyStringHex) {
return
new
libff
::
alt_bn128_Fr
(
skey_dec
);
return
new
libff
::
alt_bn128_Fr
(
skey_dec
);
}
}
int
inited
=
0
;
int
inited
=
0
;
void
enclave_init
()
{
void
enclave_init
()
{
...
@@ -116,10 +113,9 @@ bool enclave_sign(const char *_keyString, const char *_hashXString, const char *
...
@@ -116,10 +113,9 @@ bool enclave_sign(const char *_keyString, const char *_hashXString, const char *
libff
::
alt_bn128_Fq
hashY
(
_hashYString
);
libff
::
alt_bn128_Fq
hashY
(
_hashYString
);
libff
::
alt_bn128_Fq
hashZ
=
1
;
libff
::
alt_bn128_Fq
hashZ
=
1
;
libff
::
alt_bn128_G1
hash
(
hashX
,
hashY
,
hashZ
);
libff
::
alt_bn128_G1
hash
(
hashX
,
hashY
,
hashZ
);
libff
::
alt_bn128_G1
sign
=
key
->
as_bigint
()
*
hash
;
// sign
libff
::
alt_bn128_G1
sign
=
key
->
as_bigint
()
*
hash
;
sign
.
to_affine_coordinates
();
sign
.
to_affine_coordinates
();
...
@@ -135,7 +131,6 @@ bool enclave_sign(const char *_keyString, const char *_hashXString, const char *
...
@@ -135,7 +131,6 @@ bool enclave_sign(const char *_keyString, const char *_hashXString, const char *
}
}
void
carray2Hex
(
const
unsigned
char
*
d
,
int
_len
,
char
*
_hexArray
)
{
void
carray2Hex
(
const
unsigned
char
*
d
,
int
_len
,
char
*
_hexArray
)
{
char
hexval
[
16
]
=
{
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
char
hexval
[
16
]
=
{
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
,
'a'
,
'b'
,
'c'
,
'd'
,
'e'
,
'f'
};
'8'
,
'9'
,
'a'
,
'b'
,
'c'
,
'd'
,
'e'
,
'f'
};
...
@@ -145,7 +140,6 @@ void carray2Hex(const unsigned char *d, int _len, char* _hexArray) {
...
@@ -145,7 +140,6 @@ void carray2Hex(const unsigned char *d, int _len, char* _hexArray) {
}
}
_hexArray
[
_len
*
2
]
=
0
;
_hexArray
[
_len
*
2
]
=
0
;
}
}
int
char2int
(
char
_input
)
{
int
char2int
(
char
_input
)
{
...
@@ -160,7 +154,7 @@ int char2int(char _input) {
...
@@ -160,7 +154,7 @@ int char2int(char _input) {
bool
hex2carray2
(
const
char
*
_hex
,
uint64_t
*
_bin_len
,
bool
hex2carray2
(
const
char
*
_hex
,
uint64_t
*
_bin_len
,
uint8_t
*
_bin
,
const
int
_max_length
)
{
uint8_t
*
_bin
,
const
int
_max_length
)
{
int
len
=
strnlen
(
_hex
,
_max_length
);
//2 * BUF_LEN);
int
len
=
strnlen
(
_hex
,
_max_length
);
if
(
len
==
0
&&
len
%
2
==
1
)
if
(
len
==
0
&&
len
%
2
==
1
)
return
false
;
return
false
;
...
@@ -204,13 +198,11 @@ bool hex2carray(const char * _hex, uint64_t *_bin_len,
...
@@ -204,13 +198,11 @@ bool hex2carray(const char * _hex, uint64_t *_bin_len,
return
true
;
return
true
;
}
}
enum
log_level
{
L_TRACE
=
0
,
L_DEBUG
=
1
,
L_INFO
=
2
,
L_WARNING
=
3
,
L_ERROR
=
4
};
enum
log_level
{
L_TRACE
=
0
,
L_DEBUG
=
1
,
L_INFO
=
2
,
L_WARNING
=
3
,
L_ERROR
=
4
};
uint32_t
globalLogLevel_
=
2
;
uint32_t
globalLogLevel_
=
2
;
void
logMsg
(
log_level
_level
,
const
char
*
_msg
)
{
void
logMsg
(
log_level
_level
,
const
char
*
_msg
)
{
if
(
_level
<
globalLogLevel_
)
if
(
_level
<
globalLogLevel_
)
return
;
return
;
...
...
testw.cpp
View file @
ade77718
...
@@ -56,7 +56,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
...
@@ -56,7 +56,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "LevelDB.h"
#include "LevelDB.h"
#include "SGXWalletServer.hpp"
#include "SGXWalletServer.hpp"
#define CATCH_CONFIG_MAIN
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#include "catch.hpp"
...
@@ -75,11 +74,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
...
@@ -75,11 +74,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "TestUtils.h"
#include "TestUtils.h"
#include "testw.h"
#include "testw.h"
using
namespace
jsonrpc
;
using
namespace
jsonrpc
;
using
namespace
std
;
using
namespace
std
;
class
TestFixture
{
class
TestFixture
{
public
:
public
:
TestFixture
()
{
TestFixture
()
{
...
@@ -277,14 +274,12 @@ string genECDSAKeyAPI(StubClient &_c) {
...
@@ -277,14 +274,12 @@ string genECDSAKeyAPI(StubClient &_c) {
return
keyName
;
return
keyName
;
}
}
TEST_CASE_METHOD
(
TestFixture
,
"ECDSA key gen API"
,
"[ecdsa-key-gen-api]"
)
{
TEST_CASE_METHOD
(
TestFixture
,
"ECDSA key gen API"
,
"[ecdsa-key-gen-api]"
)
{
HttpClient
client
(
RPC_ENDPOINT
);
HttpClient
client
(
RPC_ENDPOINT
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
for
(
int
i
=
0
;
i
<=
20
;
i
++
)
{
for
(
int
i
=
0
;
i
<=
20
;
i
++
)
{
try
{
try
{
auto
keyName
=
genECDSAKeyAPI
(
c
);
auto
keyName
=
genECDSAKeyAPI
(
c
);
Json
::
Value
sig
=
c
.
ecdsaSignMessageHash
(
16
,
keyName
,
SAMPLE_HASH
);
Json
::
Value
sig
=
c
.
ecdsaSignMessageHash
(
16
,
keyName
,
SAMPLE_HASH
);
...
@@ -299,7 +294,6 @@ TEST_CASE_METHOD(TestFixture, "ECDSA key gen API", "[ecdsa-key-gen-api]") {
...
@@ -299,7 +294,6 @@ TEST_CASE_METHOD(TestFixture, "ECDSA key gen API", "[ecdsa-key-gen-api]") {
for
(
int
i
=
0
;
i
<=
20
;
i
++
)
{
for
(
int
i
=
0
;
i
<=
20
;
i
++
)
{
try
{
try
{
auto
keyName
=
genECDSAKeyAPI
(
c
);
auto
keyName
=
genECDSAKeyAPI
(
c
);
Json
::
Value
sig
=
c
.
ecdsaSignMessageHash
(
10
,
keyName
,
SAMPLE_HASH
);
Json
::
Value
sig
=
c
.
ecdsaSignMessageHash
(
10
,
keyName
,
SAMPLE_HASH
);
...
@@ -406,12 +400,6 @@ TEST_CASE_METHOD(TestFixture, "DKG public shares test", "[dkg-pub-shares]") {
...
@@ -406,12 +400,6 @@ TEST_CASE_METHOD(TestFixture, "DKG public shares test", "[dkg-pub-shares]") {
for
(
uint32_t
i
=
0
;
i
<
pubSharesDkg
.
size
();
i
++
)
{
for
(
uint32_t
i
=
0
;
i
<
pubSharesDkg
.
size
();
i
++
)
{
libff
::
alt_bn128_G2
el
=
pubSharesDkg
.
at
(
i
);
libff
::
alt_bn128_G2
el
=
pubSharesDkg
.
at
(
i
);
el
.
to_affine_coordinates
();
el
.
to_affine_coordinates
();
libff
::
alt_bn128_Fq
x_c0_el
=
el
.
X
.
c0
;
mpz_t
x_c0
;
mpz_init
(
x_c0
);
x_c0_el
.
as_bigint
().
to_mpz
(
x_c0
);
mpz_clear
(
x_c0
);
}
}
REQUIRE
(
pubSharesG2
==
pubSharesDkg
);
REQUIRE
(
pubSharesG2
==
pubSharesDkg
);
}
}
...
@@ -461,12 +449,6 @@ TEST_CASE_METHOD(TestFixture, "DKG AES public shares test", "[dkg-aes-pub-shares
...
@@ -461,12 +449,6 @@ TEST_CASE_METHOD(TestFixture, "DKG AES public shares test", "[dkg-aes-pub-shares
for
(
uint32_t
i
=
0
;
i
<
pubSharesDkg
.
size
();
i
++
)
{
for
(
uint32_t
i
=
0
;
i
<
pubSharesDkg
.
size
();
i
++
)
{
libff
::
alt_bn128_G2
el
=
pubSharesDkg
.
at
(
i
);
libff
::
alt_bn128_G2
el
=
pubSharesDkg
.
at
(
i
);
el
.
to_affine_coordinates
();
el
.
to_affine_coordinates
();
libff
::
alt_bn128_Fq
x_c0_el
=
el
.
X
.
c0
;
mpz_t
x_c0
;
mpz_init
(
x_c0
);
x_c0_el
.
as_bigint
().
to_mpz
(
x_c0
);
mpz_clear
(
x_c0
);
}
}
REQUIRE
(
pubSharesG2
==
pubSharesDkg
);
REQUIRE
(
pubSharesG2
==
pubSharesDkg
);
}
}
...
@@ -483,7 +465,6 @@ TEST_CASE_METHOD(TestFixture, "DKG encrypted secret shares test", "[dkg-encr-ssh
...
@@ -483,7 +465,6 @@ TEST_CASE_METHOD(TestFixture, "DKG encrypted secret shares test", "[dkg-encr-ssh
REQUIRE
(
status
==
SGX_SUCCESS
);
REQUIRE
(
status
==
SGX_SUCCESS
);
REQUIRE
(
errStatus
==
SGX_SUCCESS
);
REQUIRE
(
errStatus
==
SGX_SUCCESS
);
status
=
trustedSetEncryptedDkgPoly
(
eid
,
&
errStatus
,
errMsg
.
data
(),
encryptedDKGSecret
.
data
());
status
=
trustedSetEncryptedDkgPoly
(
eid
,
&
errStatus
,
errMsg
.
data
(),
encryptedDKGSecret
.
data
());
REQUIRE
(
status
==
SGX_SUCCESS
);
REQUIRE
(
status
==
SGX_SUCCESS
);
REQUIRE
(
errStatus
==
SGX_SUCCESS
);
REQUIRE
(
errStatus
==
SGX_SUCCESS
);
...
@@ -568,12 +549,10 @@ TEST_CASE_METHOD(TestFixture, "DKG_BLS test", "[dkg-bls]") {
...
@@ -568,12 +549,10 @@ TEST_CASE_METHOD(TestFixture, "DKG_BLS test", "[dkg-bls]") {
REQUIRE
(
blsKeyNames
.
size
()
==
4
);
REQUIRE
(
blsKeyNames
.
size
()
==
4
);
schainID
=
TestUtils
::
randGen
();
schainID
=
TestUtils
::
randGen
();
dkgID
=
TestUtils
::
randGen
();
dkgID
=
TestUtils
::
randGen
();
TestUtils
::
doDKG
(
c
,
16
,
5
,
ecdsaKeyNames
,
blsKeyNames
,
schainID
,
dkgID
);
TestUtils
::
doDKG
(
c
,
16
,
5
,
ecdsaKeyNames
,
blsKeyNames
,
schainID
,
dkgID
);
}
}
...
@@ -616,6 +595,7 @@ TEST_CASE_METHOD(TestFixture, "DKG API test", "[dkg-api]") {
...
@@ -616,6 +595,7 @@ TEST_CASE_METHOD(TestFixture, "DKG API test", "[dkg-api]") {
string
polyName
=
SAMPLE_POLY_NAME
;
string
polyName
=
SAMPLE_POLY_NAME
;
Json
::
Value
genPoly
=
c
.
generateDKGPoly
(
polyName
,
2
);
Json
::
Value
genPoly
=
c
.
generateDKGPoly
(
polyName
,
2
);
REQUIRE
(
genPoly
[
"status"
].
asInt
()
==
0
);
Json
::
Value
publicKeys
;
Json
::
Value
publicKeys
;
publicKeys
.
append
(
SAMPLE_DKG_PUB_KEY_1
);
publicKeys
.
append
(
SAMPLE_DKG_PUB_KEY_1
);
...
...
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