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
a2fdbcb7
Unverified
Commit
a2fdbcb7
authored
Mar 24, 2020
by
kladko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SKALE-2341 Added tags for older commits
parent
4e26af8b
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
392 additions
and
439 deletions
+392
-439
BLSCrypto.cpp
BLSCrypto.cpp
+139
-142
DKGCrypto.cpp
DKGCrypto.cpp
+241
-273
ECDSACrypto.cpp
ECDSACrypto.cpp
+3
-9
LevelDB.cpp
LevelDB.cpp
+8
-11
SEKManager.cpp
SEKManager.cpp
+0
-2
ServerInit.cpp
ServerInit.cpp
+1
-2
No files found.
BLSCrypto.cpp
View file @
a2fdbcb7
...
...
@@ -55,7 +55,7 @@
#include "common.h"
std
::
string
*
FqToString
(
libff
::
alt_bn128_Fq
*
_fq
)
{
std
::
string
*
FqToString
(
libff
::
alt_bn128_Fq
*
_fq
)
{
mpz_t
t
;
mpz_init
(
t
);
...
...
@@ -81,8 +81,7 @@ int char2int(char _input) {
}
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'
,
'8'
,
'9'
,
'a'
,
'b'
,
'c'
,
'd'
,
'e'
,
'f'
};
...
...
@@ -97,8 +96,8 @@ void carray2Hex(const unsigned char *d, int _len, char* _hexArray) {
}
bool
hex2carray
(
const
char
*
_hex
,
uint64_t
*
_bin_len
,
uint8_t
*
_bin
)
{
bool
hex2carray
(
const
char
*
_hex
,
uint64_t
*
_bin_len
,
uint8_t
*
_bin
)
{
int
len
=
strnlen
(
_hex
,
2
*
BUF_LEN
);
...
...
@@ -109,8 +108,8 @@ bool hex2carray(const char * _hex, uint64_t *_bin_len,
*
_bin_len
=
len
/
2
;
for
(
int
i
=
0
;
i
<
len
/
2
;
i
++
)
{
int
high
=
char2int
((
char
)
_hex
[
i
*
2
]);
int
low
=
char2int
((
char
)
_hex
[
i
*
2
+
1
]);
int
high
=
char2int
((
char
)
_hex
[
i
*
2
]);
int
low
=
char2int
((
char
)
_hex
[
i
*
2
+
1
]);
if
(
high
<
0
||
low
<
0
)
{
return
false
;
...
...
@@ -123,8 +122,8 @@ bool hex2carray(const char * _hex, uint64_t *_bin_len,
}
bool
hex2carray2
(
const
char
*
_hex
,
uint64_t
*
_bin_len
,
uint8_t
*
_bin
,
const
int
_max_length
)
{
bool
hex2carray2
(
const
char
*
_hex
,
uint64_t
*
_bin_len
,
uint8_t
*
_bin
,
const
int
_max_length
)
{
int
len
=
strnlen
(
_hex
,
_max_length
);
//2 * BUF_LEN);
...
...
@@ -135,8 +134,8 @@ bool hex2carray2(const char * _hex, uint64_t *_bin_len,
*
_bin_len
=
len
/
2
;
for
(
int
i
=
0
;
i
<
len
/
2
;
i
++
)
{
int
high
=
char2int
((
char
)
_hex
[
i
*
2
]);
int
low
=
char2int
((
char
)
_hex
[
i
*
2
+
1
]);
int
high
=
char2int
((
char
)
_hex
[
i
*
2
]);
int
low
=
char2int
((
char
)
_hex
[
i
*
2
+
1
]);
if
(
high
<
0
||
low
<
0
)
{
return
false
;
...
...
@@ -149,8 +148,8 @@ bool hex2carray2(const char * _hex, uint64_t *_bin_len,
}
bool
sign
(
const
char
*
_encryptedKeyHex
,
const
char
*
_hashHex
,
size_t
_t
,
size_t
_n
,
size_t
_signerIndex
,
char
*
_sig
)
{
bool
sign
(
const
char
*
_encryptedKeyHex
,
const
char
*
_hashHex
,
size_t
_t
,
size_t
_n
,
size_t
_signerIndex
,
char
*
_sig
)
{
//cerr << "ENTER SIGN" << endl;
...
...
@@ -160,7 +159,7 @@ bool sign(const char* _encryptedKeyHex, const char* _hashHex, size_t _t, size_t
uint64_t
binLen
;
if
(
!
hex2carray
(
_hashHex
,
&
binLen
,
hash
->
data
()))
{
if
(
!
hex2carray
(
_hashHex
,
&
binLen
,
hash
->
data
()))
{
throw
RPCException
(
INVALID_HEX
,
"Invalid hash"
);
}
// assert(binLen == hash->size());
...
...
@@ -190,8 +189,8 @@ bool sign(const char* _encryptedKeyHex, const char* _hashHex, size_t _t, size_t
return
true
;
}
bool
sign_aes
(
const
char
*
_encryptedKeyHex
,
const
char
*
_hashHex
,
size_t
_t
,
size_t
_n
,
size_t
_signerIndex
,
char
*
_sig
)
{
bool
sign_aes
(
const
char
*
_encryptedKeyHex
,
const
char
*
_hashHex
,
size_t
_t
,
size_t
_n
,
size_t
_signerIndex
,
char
*
_sig
)
{
//cerr << "ENTER SIGN" << endl;
...
...
@@ -201,7 +200,7 @@ bool sign_aes(const char* _encryptedKeyHex, const char* _hashHex, size_t _t, siz
uint64_t
binLen
;
if
(
!
hex2carray
(
_hashHex
,
&
binLen
,
hash
->
data
()))
{
if
(
!
hex2carray
(
_hashHex
,
&
binLen
,
hash
->
data
()))
{
throw
RPCException
(
INVALID_HEX
,
"Invalid hash"
);
}
// assert(binLen == hash->size());
...
...
@@ -227,14 +226,14 @@ bool sign_aes(const char* _encryptedKeyHex, const char* _hashHex, size_t _t, siz
int
errStatus
=
0
;
string
*
xStr
=
FqToString
(
&
(
hash_with_hint
.
first
.
X
));
string
*
xStr
=
FqToString
(
&
(
hash_with_hint
.
first
.
X
));
if
(
xStr
==
nullptr
)
{
std
::
cerr
<<
"Null xStr"
<<
std
::
endl
;
BOOST_THROW_EXCEPTION
(
runtime_error
(
"Null xStr"
));
}
string
*
yStr
=
FqToString
(
&
(
hash_with_hint
.
first
.
Y
));
string
*
yStr
=
FqToString
(
&
(
hash_with_hint
.
first
.
Y
));
if
(
yStr
==
nullptr
)
{
std
::
cerr
<<
"Null yStr"
<<
std
::
endl
;
...
...
@@ -247,7 +246,7 @@ bool sign_aes(const char* _encryptedKeyHex, const char* _hashHex, size_t _t, siz
char
xStrArg
[
BUF_LEN
];
char
yStrArg
[
BUF_LEN
];
char
signature
[
BUF_LEN
];
char
signature
[
BUF_LEN
];
memset
(
xStrArg
,
0
,
BUF_LEN
);
memset
(
yStrArg
,
0
,
BUF_LEN
);
...
...
@@ -273,7 +272,7 @@ bool sign_aes(const char* _encryptedKeyHex, const char* _hashHex, size_t _t, siz
if
(
status
!=
SGX_SUCCESS
)
{
cerr
<<
"SGX enclave call to bls_sign_message failed:"
<<
status
<<
std
::
endl
;
cerr
<<
"SGX enclave call to bls_sign_message failed:"
<<
status
<<
std
::
endl
;
BOOST_THROW_EXCEPTION
(
runtime_error
(
"SGX enclave call to bls_sign_message failed"
));
}
...
...
@@ -303,18 +302,17 @@ bool sign_aes(const char* _encryptedKeyHex, const char* _hashHex, size_t _t, siz
return
true
;
}
bool
bls_sign
(
const
char
*
_encryptedKeyHex
,
const
char
*
_hashHex
,
size_t
_t
,
size_t
_n
,
size_t
_signerIndex
,
char
*
_sig
)
{
bool
bls_sign
(
const
char
*
_encryptedKeyHex
,
const
char
*
_hashHex
,
size_t
_t
,
size_t
_n
,
size_t
_signerIndex
,
char
*
_sig
)
{
if
(
!
encryptKeys
)
{
if
(
!
encryptKeys
)
{
return
sign
(
_encryptedKeyHex
,
_hashHex
,
_t
,
_n
,
_signerIndex
,
_sig
);
}
else
{
}
else
{
return
sign_aes
(
_encryptedKeyHex
,
_hashHex
,
_t
,
_n
,
_signerIndex
,
_sig
);
}
}
char
*
encryptBLSKeyShare2Hex
(
int
*
errStatus
,
char
*
err_string
,
const
char
*
_key
)
{
char
*
encryptBLSKeyShare2Hex
(
int
*
errStatus
,
char
*
err_string
,
const
char
*
_key
)
{
auto
keyArray
=
make_shared
<
vector
<
char
>>
(
BUF_LEN
,
0
);
auto
encryptedKey
=
make_shared
<
vector
<
uint8_t
>>
(
BUF_LEN
,
0
);
auto
errMsg
=
make_shared
<
vector
<
char
>>
(
BUF_LEN
,
0
);
...
...
@@ -326,10 +324,9 @@ char* encryptBLSKeyShare2Hex(int *errStatus, char *err_string, const char *_key)
//status = encrypt_key(eid, errStatus, errMsg, keyArray, encryptedKey, &encryptedLen);
status
=
encrypt_key_aes
(
eid
,
errStatus
,
errMsg
->
data
(),
keyArray
->
data
(),
encryptedKey
->
data
(),
&
encryptedLen
);
if
(
printDebugInfo
)
{
spdlog
::
debug
(
"errStatus is {}"
,
*
errStatus
);
spdlog
::
debug
(
" errMsg is "
,
errMsg
->
data
()
);
}
spdlog
::
debug
(
"errStatus is {}"
,
*
errStatus
);
spdlog
::
debug
(
" errMsg is "
,
errMsg
->
data
());
if
(
status
!=
SGX_SUCCESS
)
{
...
...
DKGCrypto.cpp
View file @
a2fdbcb7
...
...
@@ -36,24 +36,22 @@
#include "spdlog/spdlog.h"
#include "common.h"
vector
<
string
>
SplitString
(
const
char
*
koefs
,
const
char
symbol
)
{
vector
<
string
>
SplitString
(
const
char
*
koefs
,
const
char
symbol
)
{
string
str
(
koefs
);
string
delim
;
delim
.
push_back
(
symbol
);
vector
<
string
>
G2_strings
;
size_t
prev
=
0
,
pos
=
0
;
do
{
do
{
pos
=
str
.
find
(
delim
,
prev
);
if
(
pos
==
string
::
npos
)
pos
=
str
.
length
();
string
token
=
str
.
substr
(
prev
,
pos
-
prev
);
string
token
=
str
.
substr
(
prev
,
pos
-
prev
);
if
(
!
token
.
empty
())
{
string
koef
(
token
.
c_str
());
G2_strings
.
push_back
(
koef
);
}
prev
=
pos
+
delim
.
length
();
}
while
(
pos
<
str
.
length
()
&&
prev
<
str
.
length
());
}
while
(
pos
<
str
.
length
()
&&
prev
<
str
.
length
());
return
G2_strings
;
}
...
...
@@ -65,9 +63,9 @@ string ConvertToString(T field_elem, int base = 10) {
field_elem
.
as_bigint
().
to_mpz
(
t
);
char
arr
[
mpz_sizeinbase
(
t
,
base
)
+
2
];
char
arr
[
mpz_sizeinbase
(
t
,
base
)
+
2
];
char
*
tmp
=
mpz_get_str
(
arr
,
base
,
t
);
char
*
tmp
=
mpz_get_str
(
arr
,
base
,
t
);
mpz_clear
(
t
);
string
output
=
tmp
;
...
...
@@ -75,7 +73,7 @@ string ConvertToString(T field_elem, int base = 10) {
return
output
;
}
string
gen_dkg_poly
(
int
_t
)
{
string
gen_dkg_poly
(
int
_t
)
{
vector
<
char
>
errMsg
(
1024
,
0
);
int
err_status
=
0
;
...
...
@@ -84,27 +82,25 @@ string gen_dkg_poly( int _t){
uint32_t
enc_len
=
0
;
if
(
!
encryptKeys
)
status
=
gen_dkg_secret
(
eid
,
&
err_status
,
errMsg
.
data
(),
encrypted_dkg_secret
.
data
(),
&
enc_len
,
_t
);
status
=
gen_dkg_secret
(
eid
,
&
err_status
,
errMsg
.
data
(),
encrypted_dkg_secret
.
data
(),
&
enc_len
,
_t
);
else
status
=
gen_dkg_secret_aes
(
eid
,
&
err_status
,
errMsg
.
data
(),
encrypted_dkg_secret
.
data
(),
&
enc_len
,
_t
);
if
(
err_status
!=
0
)
{
throw
RPCException
(
-
666
,
errMsg
.
data
()
)
;
status
=
gen_dkg_secret_aes
(
eid
,
&
err_status
,
errMsg
.
data
(),
encrypted_dkg_secret
.
data
(),
&
enc_len
,
_t
);
if
(
err_status
!=
0
)
{
throw
RPCException
(
-
666
,
errMsg
.
data
()
)
;
}
if
(
printDebugInfo
)
{
spdlog
::
debug
(
"gen_dkg_secret, status {}"
,
err_status
,
" err msg "
,
errMsg
.
data
());
spdlog
::
debug
(
"in DKGCrypto encr len is {}"
,
enc_len
);
}
uint64_t
length
=
DKG_MAX_SEALED_LEN
;
if
(
encryptKeys
){
if
(
encryptKeys
)
{
length
=
enc_len
;
}
//vector<char> hexEncrPoly(DKG_MAX_SEALED_LEN * 2 + 1, 0);//(4*BUF_LEN, 1);
vector
<
char
>
hexEncrPoly
(
2
*
length
+
1
,
0
);
assert
(
encrypted_dkg_secret
.
size
()
>=
length
);
assert
(
encrypted_dkg_secret
.
size
()
>=
length
);
//carray2Hex(encrypted_dkg_secret.data(), DKG_MAX_SEALED_LEN, hexEncrPoly.data());
carray2Hex
(
encrypted_dkg_secret
.
data
(),
length
,
hexEncrPoly
.
data
());
string
result
(
hexEncrPoly
.
data
());
...
...
@@ -112,39 +108,34 @@ string gen_dkg_poly( int _t){
return
result
;
}
vector
<
vector
<
string
>>
get_verif_vect
(
const
char
*
encryptedPolyHex
,
int
t
,
int
n
)
{
vector
<
vector
<
string
>>
get_verif_vect
(
const
char
*
encryptedPolyHex
,
int
t
,
int
n
)
{
char
*
errMsg1
=
(
char
*
)
calloc
(
1024
,
1
);
char
*
errMsg1
=
(
char
*
)
calloc
(
1024
,
1
);
//char errMsg1[BUF_LEN];
int
err_status
=
0
;
if
(
printDebugInfo
)
{
// cerr << "got encr poly " << encryptedPolyHex << endl;
spdlog
::
debug
(
"got encr poly size {}"
,
char_traits
<
char
>::
length
(
encryptedPolyHex
));
}
char
*
public_shares
=
(
char
*
)
calloc
(
10000
,
1
);
char
*
public_shares
=
(
char
*
)
calloc
(
10000
,
1
);
memset
(
public_shares
,
0
,
10000
);
// char public_shares[10000];
uint64_t
enc_len
=
0
;
uint8_t
*
encr_dkg_poly
=
(
uint8_t
*
)
calloc
(
DKG_MAX_SEALED_LEN
*
2
,
1
);
uint8_t
*
encr_dkg_poly
=
(
uint8_t
*
)
calloc
(
DKG_MAX_SEALED_LEN
*
2
,
1
);
memset
(
encr_dkg_poly
,
0
,
DKG_MAX_SEALED_LEN
*
2
);
//uint8_t encr_dkg_poly[DKG_MAX_SEALED_LEN];
if
(
!
hex2carray2
(
encryptedPolyHex
,
&
enc_len
,
encr_dkg_poly
,
6100
))
{
if
(
!
hex2carray2
(
encryptedPolyHex
,
&
enc_len
,
encr_dkg_poly
,
6100
))
{
throw
RPCException
(
INVALID_HEX
,
"Invalid encryptedPolyHex"
);
}
if
(
printDebugInfo
)
{
//cerr << "hex_encr_poly is " << encryptedPolyHex << std::endl;
spdlog
::
debug
(
"hex_encr_poly length is {}"
,
strlen
(
encryptedPolyHex
));
spdlog
::
debug
(
"enc len {}"
,
enc_len
);
// cerr << "encr raw poly: " << endl;
// for ( int i = 0 ; i < 3050; i++)
// printf(" %d ", encr_dkg_poly[i] );
}
uint32_t
len
=
0
;
...
...
@@ -154,25 +145,21 @@ vector <vector<string>> get_verif_vect(const char* encryptedPolyHex, int t, int
status
=
get_public_shares_aes
(
eid
,
&
err_status
,
errMsg1
,
encr_dkg_poly
,
enc_len
,
public_shares
,
t
,
n
);
}
if
(
err_status
!=
0
)
{
throw
RPCException
(
-
666
,
errMsg1
);
if
(
err_status
!=
0
)
{
throw
RPCException
(
-
666
,
errMsg1
);
}
if
(
printDebugInfo
)
{
spdlog
::
debug
(
"err msg is {}"
,
errMsg1
);
spdlog
::
debug
(
"public_shares:"
);
spdlog
::
debug
(
"{}"
,
public_shares
);
// cerr << "public_shares:" << endl;
// cerr << public_shares << endl;
spdlog
::
debug
(
"{}"
,
public_shares
);;
spdlog
::
debug
(
"get_public_shares status: {}"
,
err_status
);
//printf("\nget_public_shares status: %d error %s \n\n", err_status, errMsg1);
}
vector
<
string
>
G2_strings
=
SplitString
(
public_shares
,
','
);
vector
<
vector
<
string
>>
pub_shares_vect
;
for
(
uint64_t
i
=
0
;
i
<
G2_strings
.
size
();
i
++
)
{
vector
<
string
>
koef_str
=
SplitString
(
G2_strings
.
at
(
i
).
c_str
(),
':'
);
vector
<
string
>
G2_strings
=
SplitString
(
public_shares
,
','
);
vector
<
vector
<
string
>>
pub_shares_vect
;
for
(
uint64_t
i
=
0
;
i
<
G2_strings
.
size
();
i
++
)
{
vector
<
string
>
koef_str
=
SplitString
(
G2_strings
.
at
(
i
).
c_str
(),
':'
);
pub_shares_vect
.
push_back
(
koef_str
);
}
...
...
@@ -183,7 +170,8 @@ vector <vector<string>> get_verif_vect(const char* encryptedPolyHex, int t, int
return
pub_shares_vect
;
}
string
get_secret_shares
(
const
string
&
polyName
,
const
char
*
encryptedPolyHex
,
const
vector
<
string
>&
publicKeys
,
int
t
,
int
n
){
string
get_secret_shares
(
const
string
&
polyName
,
const
char
*
encryptedPolyHex
,
const
vector
<
string
>
&
publicKeys
,
int
t
,
int
n
)
{
//char* errMsg1 = (char*) calloc(1024,1);
char
errMsg1
[
BUF_LEN
];
int
err_status
=
0
;
...
...
@@ -194,7 +182,7 @@ string get_secret_shares(const string& polyName, const char* encryptedPolyHex, c
// uint8_t* encr_dkg_poly = (uint8_t*) calloc(DKG_MAX_SEALED_LEN, 1);
uint8_t
encr_dkg_poly
[
DKG_MAX_SEALED_LEN
];
memset
(
encr_dkg_poly
,
0
,
DKG_MAX_SEALED_LEN
);
if
(
!
hex2carray2
(
encryptedPolyHex
,
&
enc_len
,
encr_dkg_poly
,
6100
))
{
if
(
!
hex2carray2
(
encryptedPolyHex
,
&
enc_len
,
encr_dkg_poly
,
6100
))
{
throw
RPCException
(
INVALID_HEX
,
"Invalid encryptedPolyHex"
);
}
...
...
@@ -205,14 +193,14 @@ string get_secret_shares(const string& polyName, const char* encryptedPolyHex, c
else
status
=
set_encrypted_dkg_poly_aes
(
eid
,
&
err_status
,
errMsg1
,
encr_dkg_poly
,
&
enc_len
);
if
(
status
!=
SGX_SUCCESS
||
err_status
!=
0
)
{
throw
RPCException
(
-
666
,
errMsg1
);
if
(
status
!=
SGX_SUCCESS
||
err_status
!=
0
)
{
throw
RPCException
(
-
666
,
errMsg1
);
}
string
result
;
//char *hexEncrKey = (char *) calloc(2 * BUF_LEN, 1);
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
uint8_t
encryptedSkey
[
BUF_LEN
];
memset
(
encryptedSkey
,
0
,
BUF_LEN
);
uint32_t
dec_len
;
...
...
@@ -226,53 +214,41 @@ string get_secret_shares(const string& polyName, const char* encryptedPolyHex, c
char
pubKeyB
[
129
];
strncpy
(
pubKeyB
,
pub_keyB
.
c_str
(),
128
);
pubKeyB
[
128
]
=
0
;
if
(
printDebugInfo
)
{
spdlog
::
debug
(
"pubKeyB is {}"
,
pub_keyB
);
}
if
(
!
encryptKeys
)
get_encr_sshare
(
eid
,
&
err_status
,
errMsg1
,
encryptedSkey
,
&
dec_len
,
cur_share
,
s_shareG2
,
pubKeyB
,
t
,
n
,
i
+
1
);
cur_share
,
s_shareG2
,
pubKeyB
,
t
,
n
,
i
+
1
);
else
get_encr_sshare_aes
(
eid
,
&
err_status
,
errMsg1
,
encryptedSkey
,
&
dec_len
,
cur_share
,
s_shareG2
,
pubKeyB
,
t
,
n
,
i
+
1
);
if
(
err_status
!=
0
)
{
cur_share
,
s_shareG2
,
pubKeyB
,
t
,
n
,
i
+
1
);
if
(
err_status
!=
0
)
{
throw
RPCException
(
-
666
,
errMsg1
);
}
if
(
printDebugInfo
)
{
spdlog
::
debug
(
"cur_share is {}"
,
cur_share
);
}
result
+=
cur_share
;
//uint32_t enc_len = BUF_LEN;
if
(
printDebugInfo
)
{
spdlog
::
debug
(
"dec len is {}"
,
dec_len
);
}
carray2Hex
(
encryptedSkey
,
dec_len
,
hexEncrKey
);
string
dhKeyName
=
"DKG_DH_KEY_"
+
polyName
+
"_"
+
to_string
(
i
)
+
":"
;
spdlog
::
debug
(
"hexEncr DH Key: { }"
,
hexEncrKey
);
spdlog
::
debug
(
"hexEncr DH Key: { }"
,
hexEncrKey
);
SGXWalletServer
::
writeDataToDB
(
dhKeyName
,
hexEncrKey
);
string
shareG2_name
=
"shareG2_"
+
polyName
+
"_"
+
to_string
(
i
)
+
":"
;
if
(
printDebugInfo
)
{
spdlog
::
debug
(
"name to write to db is {}"
,
dhKeyName
);
spdlog
::
debug
(
"name to write to db is {}"
,
shareG2_name
);
spdlog
::
debug
(
"s_shareG2: {}"
,
s_shareG2
);
}
SGXWalletServer
::
writeDataToDB
(
shareG2_name
,
s_shareG2
);
if
(
printDebugInfo
)
{
spdlog
::
debug
(
"errMsg: {}"
,
errMsg1
);
// cerr << "iteration " << i <<" result length is " << result.length() << endl ;
// cerr << "iteration " << i <<" share length is " << strlen(cur_share) << endl;
// cerr << "iteration " << i <<" share is " << cur_share << endl;
}
}
//result += '\0';
...
...
@@ -283,28 +259,28 @@ string get_secret_shares(const string& polyName, const char* encryptedPolyHex, c
return
result
;
}
bool
VerifyShares
(
const
char
*
publicShares
,
const
char
*
encr_sshare
,
const
char
*
encryptedKeyHex
,
int
t
,
int
n
,
int
ind
){
bool
VerifyShares
(
const
char
*
publicShares
,
const
char
*
encr_sshare
,
const
char
*
encryptedKeyHex
,
int
t
,
int
n
,
int
ind
)
{
//char* errMsg1 = (char*) calloc(1024,1);
char
errMsg1
[
BUF_LEN
];
int
err_status
=
0
;
uint64_t
dec_key_len
;
uint64_t
dec_key_len
;
uint8_t
encr_key
[
BUF_LEN
];
memset
(
encr_key
,
0
,
BUF_LEN
);
if
(
!
hex2carray
(
encryptedKeyHex
,
&
dec_key_len
,
encr_key
)){
if
(
!
hex2carray
(
encryptedKeyHex
,
&
dec_key_len
,
encr_key
))
{
throw
RPCException
(
INVALID_HEX
,
"Invalid encryptedPolyHex"
);
}
int
result
;
if
(
printDebugInfo
)
{
cerr
<<
"encryptedKeyHex "
<<
encryptedKeyHex
<<
endl
;
cerr
<<
"dec_key_len "
<<
dec_key_len
<<
endl
;
cerr
<<
"encr_sshare length is "
<<
strlen
(
encr_sshare
)
<<
endl
;
//cerr << "public shares " << publicShares << endl;
spdlog
::
debug
(
"publicShares length is {}"
,
char_traits
<
char
>::
length
(
publicShares
));
}
char
pshares
[
8193
];
memset
(
pshares
,
0
,
8193
);
strncpy
(
pshares
,
publicShares
,
strlen
(
publicShares
)
);
strncpy
(
pshares
,
publicShares
,
strlen
(
publicShares
));
if
(
!
encryptKeys
)
...
...
@@ -312,34 +288,32 @@ bool VerifyShares(const char* publicShares, const char* encr_sshare, const char
else
dkg_verification_aes
(
eid
,
&
err_status
,
errMsg1
,
pshares
,
encr_sshare
,
encr_key
,
dec_key_len
,
t
,
ind
,
&
result
);
if
(
result
==
2
){
if
(
result
==
2
)
{
throw
RPCException
(
INVALID_HEX
,
"Invalid public shares"
);
}
if
(
printDebugInfo
)
{
spdlog
::
debug
(
"errMsg1: {}"
,
errMsg1
);
spdlog
::
debug
(
"result is: {}"
,
result
);
}
//free(errMsg1);
return
result
;
}
bool
CreateBLSShare
(
const
string
&
blsKeyName
,
const
char
*
s_shares
,
const
char
*
encryptedKeyHex
)
{
if
(
printDebugInfo
)
{
bool
CreateBLSShare
(
const
string
&
blsKeyName
,
const
char
*
s_shares
,
const
char
*
encryptedKeyHex
)
{
spdlog
::
debug
(
"ENTER CreateBLSShare"
);
}
// char* errMsg1 = (char*) calloc(1024,1);
char
errMsg1
[
BUF_LEN
];
int
err_status
=
0
;
uint64_t
dec_key_len
;
uint64_t
dec_key_len
;
uint8_t
encr_bls_key
[
BUF_LEN
];
memset
(
encr_bls_key
,
0
,
BUF_LEN
);
uint8_t
encr_key
[
BUF_LEN
];
memset
(
encr_key
,
0
,
BUF_LEN
);
if
(
!
hex2carray
(
encryptedKeyHex
,
&
dec_key_len
,
encr_key
))
{
if
(
!
hex2carray
(
encryptedKeyHex
,
&
dec_key_len
,
encr_key
))
{
throw
RPCException
(
INVALID_HEX
,
"Invalid encryptedKeyHex"
);
}
...
...
@@ -351,13 +325,12 @@ bool CreateBLSShare( const string& blsKeyName, const char * s_shares, const char
else
create_bls_key_aes
(
eid
,
&
err_status
,
errMsg1
,
s_shares
,
encr_key
,
dec_key_len
,
encr_bls_key
,
&
enc_bls_len
);
//cerr << "AFTER create_bls_key IN ENCLAVE er msg is " << errMsg1 << endl;
if
(
err_status
!=
0
)
{
if
(
err_status
!=
0
)
{
//spdlog::info("ERROR IN ENCLAVE with status {}", err_status);
spdlog
::
error
(
errMsg1
);
spdlog
::
error
(
"status {}"
,
err_status
);
throw
RPCException
(
ERROR_IN_ENCLAVE
,
"Create BLS private key failed in enclave"
);
}
else
{
}
else
{
//char *hexBLSKey = (char *) calloc(2 * BUF_LEN, 1);
char
hexBLSKey
[
2
*
BUF_LEN
];
...
...
@@ -366,89 +339,84 @@ bool CreateBLSShare( const string& blsKeyName, const char * s_shares, const char
carray2Hex
(
encr_bls_key
,
enc_bls_len
,
hexBLSKey
);
// cerr << "BEFORE WRITE BLS KEY TO DB" << endl;
SGXWalletServer
::
writeDataToDB
(
blsKeyName
,
hexBLSKey
);
if
(
printDebugInfo
)
{
spdlog
::
debug
(
"hexBLSKey length is {}"
,
char_traits
<
char
>::
length
(
hexBLSKey
));
spdlog
::
debug
(
"bls key {}"
,
blsKeyName
,
" is "
,
hexBLSKey
);
}
spdlog
::
debug
(
"bls key {}"
,
blsKeyName
,
" is "
,
hexBLSKey
);
//free(hexBLSKey);
return
true
;
}
}
vector
<
string
>
GetBLSPubKey
(
const
char
*
encryptedKeyHex
)
{
vector
<
string
>
GetBLSPubKey
(
const
char
*
encryptedKeyHex
)
{
//char* errMsg1 = (char*) calloc(1024,1);
char
errMsg1
[
BUF_LEN
];
int
err_status
=
0
;
uint64_t
dec_key_len
;
uint64_t
dec_key_len
;
uint8_t
encr_key
[
BUF_LEN
];
if
(
!
hex2carray
(
encryptedKeyHex
,
&
dec_key_len
,
encr_key
)){
if
(
!
hex2carray
(
encryptedKeyHex
,
&
dec_key_len
,
encr_key
))
{
throw
RPCException
(
INVALID_HEX
,
"Invalid encryptedKeyHex"
);
}
char
pub_key
[
320
];
if
(
printDebugInfo
)
{
spdlog
::
debug
(
"dec_key_len is {}"
,
dec_key_len
);
}
if
(
!
encryptKeys
)
get_bls_pub_key
(
eid
,
&
err_status
,
errMsg1
,
encr_key
,
dec_key_len
,
pub_key
);
else
get_bls_pub_key_aes
(
eid
,
&
err_status
,
errMsg1
,
encr_key
,
dec_key_len
,
pub_key
);
if
(
err_status
!=
0
)
{
if
(
err_status
!=
0
)
{
std
::
cerr
<<
errMsg1
<<
" status is "
<<
err_status
<<
std
::
endl
;
throw
RPCException
(
ERROR_IN_ENCLAVE
,
"Failed to get BLS public key in enclave"
);
}
vector
<
string
>
pub_key_vect
=
SplitString
(
pub_key
,
':'
);
if
(
printDebugInfo
)
{
spdlog
::
debug
(
"errMsg1 is {}"
,
errMsg1
);
spdlog
::
debug
(
"pub key is "
);
for
(
int
i
=
0
;
i
<
4
;
i
++
)
spdlog
::
debug
(
"{}"
,
pub_key_vect
.
at
(
i
));
}
return
pub_key_vect
;
}
string
decrypt_DHKey
(
const
string
&
polyName
,
int
ind
)
{
string
decrypt_DHKey
(
const
string
&
polyName
,
int
ind
)
{
vector
<
char
>
errMsg1
(
1024
,
0
);
vector
<
char
>
errMsg1
(
1024
,
0
);
int
err_status
=
0
;
string
DH_key_name
=
polyName
+
"_"
+
to_string
(
ind
)
+
":"
;
shared_ptr
<
string
>
hexEncrKey_ptr
=
SGXWalletServer
::
readFromDb
(
DH_key_name
,
"DKG_DH_KEY_"
);
if
(
printDebugInfo
)
{
spdlog
::
debug
(
"encr DH key is {}"
,
*
hexEncrKey_ptr
);
}
vector
<
char
>
hexEncrKey
(
2
*
BUF_LEN
,
0
);
uint64_t
DH_enc_len
=
0
;
uint8_t
encrypted_DHkey
[
BUF_LEN
];
if
(
!
hex2carray
(
hexEncrKey_ptr
->
c_str
(),
&
DH_enc_len
,
encrypted_DHkey
))
{
if
(
!
hex2carray
(
hexEncrKey_ptr
->
c_str
(),
&
DH_enc_len
,
encrypted_DHkey
))
{
throw
RPCException
(
INVALID_HEX
,
"Invalid hexEncrKey"
);
}
if
(
printDebugInfo
)
{
spdlog
::
debug
(
"encr DH key length is {}"
,
DH_enc_len
);
spdlog
::
debug
(
"hex encr DH key length is {}"
,
hexEncrKey_ptr
->
length
());
}
char
DHKey
[
ECDSA_SKEY_LEN
];
if
(
!
encryptKeys
)
if
(
!
encryptKeys
)
decrypt_key
(
eid
,
&
err_status
,
errMsg1
.
data
(),
encrypted_DHkey
,
DH_enc_len
,
DHKey
);
else
decrypt_key_aes
(
eid
,
&
err_status
,
errMsg1
.
data
(),
encrypted_DHkey
,
DH_enc_len
,
DHKey
);
if
(
err_status
!=
0
)
{
if
(
err_status
!=
0
)
{
throw
RPCException
(
/*ERROR_IN_ENCLAVE*/
err_status
,
"decrypt key failed in enclave"
);
}
return
DHKey
;
}
vector
<
string
>
mult_G2
(
const
string
&
x
)
{
vector
<
string
>
mult_G2
(
const
string
&
x
)
{
vector
<
string
>
result
(
4
);
libff
::
init_alt_bn128_params
();
libff
::
alt_bn128_Fr
el
(
x
.
c_str
());
...
...
ECDSACrypto.cpp
View file @
a2fdbcb7
...
...
@@ -61,13 +61,10 @@ std::vector<std::string> genECDSAKey() {
throw
RPCException
(
status
,
errMsg
);
}
std
::
vector
<
std
::
string
>
keys
(
3
);
if
(
printDebugInfo
)
{
std
::
cerr
<<
"account key is "
<<
errMsg
<<
std
::
endl
;
std
::
cerr
<<
"enc_len is "
<<
enc_len
<<
std
::
endl
;
// std::cerr << "enc_key is " << std::endl;
// for(int i = 0 ; i < 1024; i++)
// std::cerr << (int)encr_pr_key[i] << " " ;
}
char
*
hexEncrKey
=
(
char
*
)
calloc
(
BUF_LEN
*
2
,
1
);
carray2Hex
(
encr_pr_key
,
enc_len
,
hexEncrKey
);
keys
.
at
(
0
)
=
hexEncrKey
;
...
...
@@ -77,10 +74,8 @@ std::vector<std::string> genECDSAKey() {
unsigned
long
seed
=
randGen
();
if
(
printDebugInfo
)
{
spdlog
::
debug
(
"seed is {}"
,
seed
);
std
::
cerr
<<
"strlen is "
<<
strlen
(
hexEncrKey
)
<<
std
::
endl
;
}
gmp_randstate_t
state
;
gmp_randinit_default
(
state
);
...
...
@@ -133,13 +128,12 @@ std::string getECDSAPubKey(const char *_encryptedKeyHex) {
}
string
pubKey
=
string
(
pubKeyX
.
data
())
+
string
(
pubKeyY
.
data
());
//concatPubKeyWith0x(pub_key_x, pub_key_y);//
if
(
printDebugInfo
)
{
spdlog
::
debug
(
"enc_len is {}"
,
enc_len
);
spdlog
::
debug
(
"pubkey is {}"
,
pubKey
);
spdlog
::
debug
(
"pubkey length is {}"
,
pubKey
.
length
());
spdlog
::
debug
(
"err str is {}"
,
errMsg
.
data
());
spdlog
::
debug
(
"err status is {}"
,
err_status
);
}
return
pubKey
;
}
...
...
LevelDB.cpp
View file @
a2fdbcb7
...
...
@@ -62,10 +62,10 @@ std::shared_ptr<string> LevelDB::readString(const string &_key) {
auto
status
=
db
->
Get
(
readOptions
,
_key
,
&*
result
);
if
(
printDebugInfo
)
{
spdlog
::
debug
(
"key to read from db: {}"
,
_key
);
//std::cerr << "key to read from db: " << _key << std::endl;
}
throwExceptionOnError
(
status
);
...
...
@@ -83,10 +83,10 @@ void LevelDB::writeString(const string &_key, const string &_value) {
throwExceptionOnError
(
status
);
if
(
printDebugInfo
)
{
spdlog
::
debug
(
"written key: {}"
,
_key
);
// std::cerr << "written key " << _key << std::endl;
}
}
...
...
@@ -100,10 +100,9 @@ void LevelDB::deleteDHDKGKey (const string &_key) {
throwExceptionOnError
(
status
);
if
(
printDebugInfo
)
{
spdlog
::
debug
(
"key deleted: {}"
,
full_key
);
//std::cerr << "key deleted " << full_key << std::endl;
}
}
void
LevelDB
::
deleteTempNEK
(
const
string
&
_key
){
...
...
@@ -130,10 +129,9 @@ void LevelDB::deleteKey(const string &_key){
throwExceptionOnError
(
status
);
if
(
printDebugInfo
)
{
spdlog
::
debug
(
"key deleted: {}"
,
_key
);
// std::cerr << "key deleted " << _key << std::endl;
}
}
...
...
@@ -219,10 +217,9 @@ void LevelDB::writeDataUnique(const string & Name, const string &value) {
}
writeString
(
key
,
value
);
if
(
printDebugInfo
)
{
spdlog
::
debug
(
"{}"
,
Name
,
" is written to db"
);
//std::cerr << Name << " is written to db " << std::endl;
}
}
...
...
SEKManager.cpp
View file @
a2fdbcb7
...
...
@@ -231,8 +231,6 @@ void init_SEK(){
gen_SEK
();
}
else
{
if
(
printDebugInfo
)
spdlog
::
info
(
"going to set SEK from db"
);
set_SEK
(
encr_SEK_ptr
);
}
}
...
...
ServerInit.cpp
View file @
a2fdbcb7
...
...
@@ -77,9 +77,8 @@ void initEnclave() {
}
#endif
if
(
printDebugInfo
)
{
spdlog
::
debug
(
"SGX_DEBUG_FLAG = {}"
,
SGX_DEBUG_FLAG
);
}
status
=
sgx_create_enclave_search
(
ENCLAVE_NAME
,
SGX_DEBUG_FLAG
,
&
token
,
&
updated
,
&
eid
,
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