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
6e432708
Unverified
Commit
6e432708
authored
Mar 23, 2020
by
kladko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SKALE-2341 Added tags for older commits
parent
c6be9d1b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
151 additions
and
184 deletions
+151
-184
DKGCrypto.cpp
DKGCrypto.cpp
+11
-11
SGXWalletServer.cpp
SGXWalletServer.cpp
+28
-60
testw.cpp
testw.cpp
+112
-113
No files found.
DKGCrypto.cpp
View file @
6e432708
...
@@ -213,8 +213,8 @@ string get_secret_shares(const string& polyName, const char* encryptedPolyHex, c
...
@@ -213,8 +213,8 @@ string get_secret_shares(const string& polyName, const char* encryptedPolyHex, c
//char *hexEncrKey = (char *) calloc(2 * BUF_LEN, 1);
//char *hexEncrKey = (char *) calloc(2 * BUF_LEN, 1);
for
(
int
i
=
0
;
i
<
n
;
i
++
){
for
(
int
i
=
0
;
i
<
n
;
i
++
){
uint8_t
encrypted
_s
key
[
BUF_LEN
];
uint8_t
encrypted
S
key
[
BUF_LEN
];
memset
(
encrypted
_s
key
,
0
,
BUF_LEN
);
memset
(
encrypted
S
key
,
0
,
BUF_LEN
);
uint32_t
dec_len
;
uint32_t
dec_len
;
char
cur_share
[
193
];
char
cur_share
[
193
];
...
@@ -231,11 +231,11 @@ string get_secret_shares(const string& polyName, const char* encryptedPolyHex, c
...
@@ -231,11 +231,11 @@ string get_secret_shares(const string& polyName, const char* encryptedPolyHex, c
}
}
if
(
!
encryptKeys
)
if
(
!
encryptKeys
)
get_encr_sshare
(
eid
,
&
err_status
,
errMsg1
,
encrypted_skey
,
&
dec_len
,
get_encr_sshare
(
eid
,
&
err_status
,
errMsg1
,
encryptedSkey
,
&
dec_len
,
cur_share
,
s_shareG2
,
pubKeyB
,
t
,
n
,
i
+
1
);
else
get_encr_sshare_aes
(
eid
,
&
err_status
,
errMsg1
,
encrypted_skey
,
&
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
){
if
(
err_status
!=
0
){
throw
RPCException
(
-
666
,
errMsg1
);
throw
RPCException
(
-
666
,
errMsg1
);
}
}
...
@@ -251,17 +251,17 @@ string get_secret_shares(const string& polyName, const char* encryptedPolyHex, c
...
@@ -251,17 +251,17 @@ string get_secret_shares(const string& polyName, const char* encryptedPolyHex, c
}
}
carray2Hex
(
encrypted
_s
key
,
dec_len
,
hexEncrKey
);
carray2Hex
(
encrypted
S
key
,
dec_len
,
hexEncrKey
);
string
DHKey_n
ame
=
"DKG_DH_KEY_"
+
polyName
+
"_"
+
to_string
(
i
)
+
":"
;
string
dhKeyN
ame
=
"DKG_DH_KEY_"
+
polyName
+
"_"
+
to_string
(
i
)
+
":"
;
cerr
<<
"hexEncr DH Key: "
<<
hexEncrKey
<<
endl
;
spdlog
::
debug
(
"hexEncr DH Key: { }"
,
hexEncrKey
)
;
SGXWalletServer
::
writeDataToDB
(
DHKey_n
ame
,
hexEncrKey
);
SGXWalletServer
::
writeDataToDB
(
dhKeyN
ame
,
hexEncrKey
);
string
shareG2_name
=
"shareG2_"
+
polyName
+
"_"
+
to_string
(
i
)
+
":"
;
string
shareG2_name
=
"shareG2_"
+
polyName
+
"_"
+
to_string
(
i
)
+
":"
;
if
(
printDebugInfo
)
{
if
(
printDebugInfo
)
{
spdlog
::
info
(
"name to write to db is {}"
,
DHKey_n
ame
);
spdlog
::
info
(
"name to write to db is {}"
,
dhKeyN
ame
);
spdlog
::
info
(
"name to write to db is {}"
,
shareG2_name
);
spdlog
::
info
(
"name to write to db is {}"
,
shareG2_name
);
spdlog
::
info
(
"s_shareG2: {}"
,
s_shareG2
);
spdlog
::
info
(
"s_shareG2: {}"
,
s_shareG2
);
}
}
...
...
SGXWalletServer.cpp
View file @
6e432708
...
@@ -81,15 +81,14 @@ int SGXWalletServer::initHttpsServer(bool _checkCerts) {
...
@@ -81,15 +81,14 @@ int SGXWalletServer::initHttpsServer(bool _checkCerts) {
string
keyCAPath
=
string
(
SGXDATA_FOLDER
)
+
"cert_data/rootCA.key"
;
string
keyCAPath
=
string
(
SGXDATA_FOLDER
)
+
"cert_data/rootCA.key"
;
if
(
access
(
rootCAPath
.
c_str
(),
F_OK
)
!=
0
||
access
(
keyCAPath
.
c_str
(),
F_OK
)
!=
0
)
{
if
(
access
(
rootCAPath
.
c_str
(),
F_OK
)
!=
0
||
access
(
keyCAPath
.
c_str
(),
F_OK
)
!=
0
)
{
spdlog
::
info
(
"YOU DO NOT HAVE ROOT CA CERTIFICATE"
);
spdlog
::
info
(
"NO ROOT CA CERTIFICATE YET. CREATING ..."
);
spdlog
::
info
(
"ROOT CA CERTIFICATE IS GOING TO BE CREATED"
);
string
genRootCACert
=
"cd cert && ./create_CA"
;
string
genRootCACert
=
"cd cert && ./create_CA"
;
if
(
system
(
genRootCACert
.
c_str
())
==
0
)
{
if
(
system
(
genRootCACert
.
c_str
())
==
0
)
{
spdlog
::
info
(
"ROOT CA CERTIFICATE IS SUCCESSFULLY GENERATED"
);
spdlog
::
info
(
"ROOT CA CERTIFICATE IS SUCCESSFULLY GENERATED"
);
}
else
{
}
else
{
spdlog
::
info
(
"ROOT CA CERTIFICATE GENERATION FAILED"
);
spdlog
::
error
(
"ROOT CA CERTIFICATE GENERATION FAILED"
);
exit
(
-
1
);
exit
(
-
1
);
}
}
}
}
...
@@ -116,7 +115,7 @@ int SGXWalletServer::initHttpsServer(bool _checkCerts) {
...
@@ -116,7 +115,7 @@ int SGXWalletServer::initHttpsServer(bool _checkCerts) {
JSONRPC_SERVER_V2
);
// hybrid server (json-rpc 1.0 & 2.0)
JSONRPC_SERVER_V2
);
// hybrid server (json-rpc 1.0 & 2.0)
if
(
!
s
->
StartListening
())
{
if
(
!
s
->
StartListening
())
{
spdlog
::
info
(
"SGX Server could not start listening"
);
spdlog
::
error
(
"SGX Server could not start listening"
);
exit
(
-
1
);
exit
(
-
1
);
}
else
{
}
else
{
spdlog
::
info
(
"SGX Server started on port {}"
,
BASE_PORT
);
spdlog
::
info
(
"SGX Server started on port {}"
,
BASE_PORT
);
...
@@ -131,7 +130,7 @@ int SGXWalletServer::initHttpServer() { //without ssl
...
@@ -131,7 +130,7 @@ int SGXWalletServer::initHttpServer() { //without ssl
s
=
new
SGXWalletServer
(
*
httpServer
,
s
=
new
SGXWalletServer
(
*
httpServer
,
JSONRPC_SERVER_V2
);
// hybrid server (json-rpc 1.0 & 2.0)
JSONRPC_SERVER_V2
);
// hybrid server (json-rpc 1.0 & 2.0)
if
(
!
s
->
StartListening
())
{
if
(
!
s
->
StartListening
())
{
spdlog
::
info
(
"Server could not start listening"
);
spdlog
::
error
(
"Server could not start listening"
);
exit
(
-
1
);
exit
(
-
1
);
}
}
return
0
;
return
0
;
...
@@ -266,11 +265,8 @@ Json::Value SGXWalletServer::generateECDSAKeyImpl() {
...
@@ -266,11 +265,8 @@ Json::Value SGXWalletServer::generateECDSAKeyImpl() {
string
keyName
=
"NEK:"
+
keys
.
at
(
2
);
string
keyName
=
"NEK:"
+
keys
.
at
(
2
);
if
(
printDebugInfo
)
{
spdlog
::
debug
(
"key name generated: {}"
,
keyName
);
spdlog
::
info
(
"write encr key {}"
,
keys
.
at
(
0
));
spdlog
::
debug
(
"write encr key {}"
,
keys
.
at
(
0
));
spdlog
::
info
(
"keyname length is {}"
,
keyName
.
length
());
spdlog
::
info
(
"key name generated: {}"
,
keyName
);
}
writeDataToDB
(
keyName
,
keys
.
at
(
0
));
writeDataToDB
(
keyName
,
keys
.
at
(
0
));
...
@@ -297,15 +293,15 @@ Json::Value SGXWalletServer::renameECDSAKeyImpl(const string &_keyName, const st
...
@@ -297,15 +293,15 @@ Json::Value SGXWalletServer::renameECDSAKeyImpl(const string &_keyName, const st
string
prefix
=
_tempKeyName
.
substr
(
0
,
8
);
string
prefix
=
_tempKeyName
.
substr
(
0
,
8
);
if
(
prefix
!=
"tmp_NEK:"
)
{
if
(
prefix
!=
"tmp_NEK:"
)
{
throw
RPCException
(
UNKNOWN_ERROR
,
"
wrong
temp key name"
);
throw
RPCException
(
UNKNOWN_ERROR
,
"
invalid
temp key name"
);
}
}
prefix
=
_keyName
.
substr
(
0
,
12
);
prefix
=
_keyName
.
substr
(
0
,
12
);
if
(
prefix
!=
"NEK_NODE_ID:"
)
{
if
(
prefix
!=
"NEK_NODE_ID:"
)
{
throw
RPCException
(
UNKNOWN_ERROR
,
"
wrong
key name"
);
throw
RPCException
(
UNKNOWN_ERROR
,
"
invalid
key name"
);
}
}
string
postfix
=
_keyName
.
substr
(
12
,
_keyName
.
length
());
string
postfix
=
_keyName
.
substr
(
12
,
_keyName
.
length
());
if
(
!
isStringDec
(
postfix
))
{
if
(
!
isStringDec
(
postfix
))
{
throw
RPCException
(
UNKNOWN_ERROR
,
"
wrong
key name"
);
throw
RPCException
(
UNKNOWN_ERROR
,
"
invalid
key name"
);
}
}
shared_ptr
<
string
>
key_ptr
=
readFromDb
(
_tempKeyName
);
shared_ptr
<
string
>
key_ptr
=
readFromDb
(
_tempKeyName
);
...
@@ -333,10 +329,6 @@ Json::Value SGXWalletServer::ecdsaSignMessageHashImpl(int _base, const string &_
...
@@ -333,10 +329,6 @@ Json::Value SGXWalletServer::ecdsaSignMessageHashImpl(int _base, const string &_
vector
<
string
>
sign_vect
(
3
);
vector
<
string
>
sign_vect
(
3
);
if
(
printDebugInfo
)
{
spdlog
::
info
(
"entered ecdsaSignMessageHashImpl {}"
,
_messageHash
,
"length {}"
,
_messageHash
.
length
());
}
try
{
try
{
string
cutHash
=
_messageHash
;
string
cutHash
=
_messageHash
;
...
@@ -347,10 +339,6 @@ Json::Value SGXWalletServer::ecdsaSignMessageHashImpl(int _base, const string &_
...
@@ -347,10 +339,6 @@ Json::Value SGXWalletServer::ecdsaSignMessageHashImpl(int _base, const string &_
cutHash
.
erase
(
cutHash
.
begin
(),
cutHash
.
begin
()
+
1
);
cutHash
.
erase
(
cutHash
.
begin
(),
cutHash
.
begin
()
+
1
);
}
}
if
(
printDebugInfo
)
{
spdlog
::
info
(
"Hash handled {}"
,
cutHash
);
}
if
(
!
checkECDSAKeyName
(
_keyName
))
{
if
(
!
checkECDSAKeyName
(
_keyName
))
{
throw
RPCException
(
INVALID_ECDSA_KEY_NAME
,
"Invalid ECDSA key name"
);
throw
RPCException
(
INVALID_ECDSA_KEY_NAME
,
"Invalid ECDSA key name"
);
}
}
...
@@ -368,9 +356,7 @@ Json::Value SGXWalletServer::ecdsaSignMessageHashImpl(int _base, const string &_
...
@@ -368,9 +356,7 @@ Json::Value SGXWalletServer::ecdsaSignMessageHashImpl(int _base, const string &_
throw
RPCException
(
INVALID_ECSDA_SIGNATURE
,
"Invalid ecdsa signature"
);
throw
RPCException
(
INVALID_ECSDA_SIGNATURE
,
"Invalid ecdsa signature"
);
}
}
if
(
printDebugInfo
)
{
spdlog
::
debug
(
"got signature_s {}"
,
sign_vect
.
at
(
2
));
spdlog
::
info
(
"got signature_s {}"
,
sign_vect
.
at
(
2
));
}
result
[
"signature_v"
]
=
sign_vect
.
at
(
0
);
result
[
"signature_v"
]
=
sign_vect
.
at
(
0
);
result
[
"signature_r"
]
=
sign_vect
.
at
(
1
);
result
[
"signature_r"
]
=
sign_vect
.
at
(
1
);
...
@@ -391,21 +377,18 @@ Json::Value SGXWalletServer::getPublicECDSAKeyImpl(const string &_keyName) {
...
@@ -391,21 +377,18 @@ Json::Value SGXWalletServer::getPublicECDSAKeyImpl(const string &_keyName) {
result
[
"errorMessage"
]
=
""
;
result
[
"errorMessage"
]
=
""
;
result
[
"publicKey"
]
=
""
;
result
[
"publicKey"
]
=
""
;
spdlog
::
info
(
"Calling method getPublicECDSAKey"
);
string
publicKey
;
string
Pkey
;
try
{
try
{
if
(
!
checkECDSAKeyName
(
_keyName
))
{
if
(
!
checkECDSAKeyName
(
_keyName
))
{
throw
RPCException
(
INVALID_ECDSA_KEY_NAME
,
"Invalid ECDSA key name"
);
throw
RPCException
(
INVALID_ECDSA_KEY_NAME
,
"Invalid ECDSA key name"
);
}
}
shared_ptr
<
string
>
key_ptr
=
readFromDb
(
_keyName
);
shared_ptr
<
string
>
keyStr
=
readFromDb
(
_keyName
);
Pkey
=
get_ecdsa_pubkey
(
key_ptr
->
c_str
());
publicKey
=
get_ecdsa_pubkey
(
keyStr
->
c_str
());
if
(
printDebugInfo
)
{
spdlog
::
debug
(
"PublicKey {}"
,
publicKey
);
spdlog
::
info
(
"PublicKey {}"
,
Pkey
);
spdlog
::
debug
(
"PublicKey length {}"
,
publicKey
.
length
());
spdlog
::
info
(
"PublicKey length {}"
,
Pkey
.
length
());
}
result
[
"publicKey"
]
=
publicKey
;
result
[
"publicKey"
]
=
Pkey
;
}
catch
(
RPCException
&
_e
)
{
}
catch
(
RPCException
&
_e
)
{
result
[
"status"
]
=
_e
.
status
;
result
[
"status"
]
=
_e
.
status
;
...
@@ -483,14 +466,13 @@ Json::Value SGXWalletServer::getVerificationVectorImpl(const string &_polyName,
...
@@ -483,14 +466,13 @@ Json::Value SGXWalletServer::getVerificationVectorImpl(const string &_polyName,
}
}
Json
::
Value
SGXWalletServer
::
getSecretShareImpl
(
const
string
&
_polyName
,
const
Json
::
Value
&
_publicKeys
,
int
_t
,
int
_n
)
{
Json
::
Value
SGXWalletServer
::
getSecretShareImpl
(
const
string
&
_polyName
,
const
Json
::
Value
&
_publicKeys
,
int
_t
,
int
_n
)
{
spdlog
::
info
(
"enter getSecretShareImpl"
);
Json
::
Value
result
;
Json
::
Value
result
;
result
[
"status"
]
=
0
;
result
[
"status"
]
=
0
;
result
[
"errorMessage"
]
=
""
;
result
[
"errorMessage"
]
=
""
;
try
{
try
{
if
(
_publicKeys
.
size
()
!=
(
uint64_t
)
_n
)
{
if
(
_publicKeys
.
size
()
!=
(
uint64_t
)
_n
)
{
throw
RPCException
(
INVALID_DKG_PARAMS
,
"
wrong
number of public keys"
);
throw
RPCException
(
INVALID_DKG_PARAMS
,
"
invalid
number of public keys"
);
}
}
if
(
!
checkName
(
_polyName
,
"POLY"
))
{
if
(
!
checkName
(
_polyName
,
"POLY"
))
{
throw
RPCException
(
INVALID_POLY_NAME
,
"Invalid polynomial name"
);
throw
RPCException
(
INVALID_POLY_NAME
,
"Invalid polynomial name"
);
...
@@ -527,8 +509,6 @@ Json::Value SGXWalletServer::getSecretShareImpl(const string &_polyName, const J
...
@@ -527,8 +509,6 @@ Json::Value SGXWalletServer::getSecretShareImpl(const string &_polyName, const J
Json
::
Value
SGXWalletServer
::
dkgVerificationImpl
(
const
string
&
_publicShares
,
const
string
&
_ethKeyName
,
Json
::
Value
SGXWalletServer
::
dkgVerificationImpl
(
const
string
&
_publicShares
,
const
string
&
_ethKeyName
,
const
string
&
_secretShare
,
int
_t
,
int
_n
,
int
_index
)
{
const
string
&
_secretShare
,
int
_t
,
int
_n
,
int
_index
)
{
spdlog
::
info
(
"enter dkgVerificationImpl"
);
Json
::
Value
result
;
Json
::
Value
result
;
result
[
"status"
]
=
0
;
result
[
"status"
]
=
0
;
result
[
"errorMessage"
]
=
""
;
result
[
"errorMessage"
]
=
""
;
...
@@ -568,7 +548,6 @@ Json::Value SGXWalletServer::dkgVerificationImpl(const string &_publicShares, co
...
@@ -568,7 +548,6 @@ Json::Value SGXWalletServer::dkgVerificationImpl(const string &_publicShares, co
Json
::
Value
SGXWalletServer
::
createBLSPrivateKeyImpl
(
const
string
&
_blsKeyName
,
const
string
&
_ethKeyName
,
const
string
&
_polyName
,
Json
::
Value
SGXWalletServer
::
createBLSPrivateKeyImpl
(
const
string
&
_blsKeyName
,
const
string
&
_ethKeyName
,
const
string
&
_polyName
,
const
string
&
_secretShare
,
int
_t
,
int
_n
)
{
const
string
&
_secretShare
,
int
_t
,
int
_n
)
{
spdlog
::
info
(
"createBLSPrivateKeyImpl entered"
);
Json
::
Value
result
;
Json
::
Value
result
;
result
[
"status"
]
=
0
;
result
[
"status"
]
=
0
;
...
@@ -577,8 +556,8 @@ Json::Value SGXWalletServer::createBLSPrivateKeyImpl(const string &_blsKeyName,
...
@@ -577,8 +556,8 @@ Json::Value SGXWalletServer::createBLSPrivateKeyImpl(const string &_blsKeyName,
try
{
try
{
if
(
_secretShare
.
length
()
!=
(
uint64_t
)
_n
*
192
)
{
if
(
_secretShare
.
length
()
!=
(
uint64_t
)
_n
*
192
)
{
spdlog
::
info
(
"wrong length of secret shares
- {}"
,
_secretShare
.
length
());
spdlog
::
error
(
"Invalid secret share length
- {}"
,
_secretShare
.
length
());
spdlog
::
info
(
"secret shares
- {}"
,
_secretShare
);
spdlog
::
error
(
"Secret share
- {}"
,
_secretShare
);
throw
RPCException
(
INVALID_SECRET_SHARES_LENGTH
,
"Invalid secret share length"
);
throw
RPCException
(
INVALID_SECRET_SHARES_LENGTH
,
"Invalid secret share length"
);
}
}
if
(
!
checkECDSAKeyName
(
_ethKeyName
))
{
if
(
!
checkECDSAKeyName
(
_ethKeyName
))
{
...
@@ -594,9 +573,8 @@ Json::Value SGXWalletServer::createBLSPrivateKeyImpl(const string &_blsKeyName,
...
@@ -594,9 +573,8 @@ Json::Value SGXWalletServer::createBLSPrivateKeyImpl(const string &_blsKeyName,
throw
RPCException
(
INVALID_DKG_PARAMS
,
"Invalid DKG parameters: n or t "
);
throw
RPCException
(
INVALID_DKG_PARAMS
,
"Invalid DKG parameters: n or t "
);
}
}
vector
<
string
>
sshares_vect
;
vector
<
string
>
sshares_vect
;
if
(
printDebugInfo
)
{
spdlog
::
info
(
"secret shares from json are - {}"
,
_secretShare
);
spdlog
::
debug
(
"secret shares from json are - {}"
,
_secretShare
);
}
shared_ptr
<
string
>
encryptedKeyHex_ptr
=
readFromDb
(
_ethKeyName
);
shared_ptr
<
string
>
encryptedKeyHex_ptr
=
readFromDb
(
_ethKeyName
);
...
@@ -635,12 +613,9 @@ Json::Value SGXWalletServer::getBLSPublicKeyShareImpl(const string &_blsKeyName)
...
@@ -635,12 +613,9 @@ Json::Value SGXWalletServer::getBLSPublicKeyShareImpl(const string &_blsKeyName)
throw
RPCException
(
INVALID_POLY_NAME
,
"Invalid BLSKey name"
);
throw
RPCException
(
INVALID_POLY_NAME
,
"Invalid BLSKey name"
);
}
}
shared_ptr
<
string
>
encryptedKeyHex_ptr
=
readFromDb
(
_blsKeyName
);
shared_ptr
<
string
>
encryptedKeyHex_ptr
=
readFromDb
(
_blsKeyName
);
if
(
printDebugInfo
)
{
spdlog
::
debug
(
"encr_bls_key_share is {}"
,
*
encryptedKeyHex_ptr
);
spdlog
::
info
(
"encr_bls_key_share is {}"
,
*
encryptedKeyHex_ptr
);
spdlog
::
debug
(
"length is {}"
,
encryptedKeyHex_ptr
->
length
());
spdlog
::
info
(
"length is {}"
,
encryptedKeyHex_ptr
->
length
());
//cerr << "encr_bls_key_share is " << *encryptedKeyHex_ptr << endl;
// cerr << "length is " << encryptedKeyHex_ptr->length() << endl;
}
vector
<
string
>
public_key_vect
=
GetBLSPubKey
(
encryptedKeyHex_ptr
->
c_str
());
vector
<
string
>
public_key_vect
=
GetBLSPubKey
(
encryptedKeyHex_ptr
->
c_str
());
for
(
uint8_t
i
=
0
;
i
<
4
;
i
++
)
{
for
(
uint8_t
i
=
0
;
i
<
4
;
i
++
)
{
result
[
"blsPublicKeyShare"
][
i
]
=
public_key_vect
.
at
(
i
);
result
[
"blsPublicKeyShare"
][
i
]
=
public_key_vect
.
at
(
i
);
...
@@ -688,7 +663,6 @@ Json::Value SGXWalletServer::multG2Impl(const string &_x) {
...
@@ -688,7 +663,6 @@ Json::Value SGXWalletServer::multG2Impl(const string &_x) {
result
[
"status"
]
=
0
;
result
[
"status"
]
=
0
;
result
[
"errorMessage"
]
=
""
;
result
[
"errorMessage"
]
=
""
;
try
{
try
{
spdlog
::
info
(
"multG2Impl try "
);
vector
<
string
>
xG2_vect
=
mult_G2
(
_x
);
vector
<
string
>
xG2_vect
=
mult_G2
(
_x
);
for
(
uint8_t
i
=
0
;
i
<
4
;
i
++
)
{
for
(
uint8_t
i
=
0
;
i
<
4
;
i
++
)
{
result
[
"x*G2"
][
i
]
=
xG2_vect
.
at
(
i
);
result
[
"x*G2"
][
i
]
=
xG2_vect
.
at
(
i
);
...
@@ -736,7 +710,6 @@ Json::Value SGXWalletServer::getServerStatusImpl() {
...
@@ -736,7 +710,6 @@ Json::Value SGXWalletServer::getServerStatusImpl() {
Json
::
Value
SGXWalletServer
::
generateDKGPoly
(
const
string
&
_polyName
,
int
_t
)
{
Json
::
Value
SGXWalletServer
::
generateDKGPoly
(
const
string
&
_polyName
,
int
_t
)
{
spdlog
::
info
(
"entered generateDKGPoly"
);
lock_guard
<
recursive_mutex
>
lock
(
m
);
lock_guard
<
recursive_mutex
>
lock
(
m
);
return
generateDKGPolyImpl
(
_polyName
,
_t
);
return
generateDKGPolyImpl
(
_polyName
,
_t
);
}
}
...
@@ -789,10 +762,7 @@ Json::Value SGXWalletServer::getPublicECDSAKey(const string &_keyName) {
...
@@ -789,10 +762,7 @@ Json::Value SGXWalletServer::getPublicECDSAKey(const string &_keyName) {
Json
::
Value
SGXWalletServer
::
ecdsaSignMessageHash
(
int
_base
,
const
string
&
_keyShareName
,
const
string
&
_messageHash
)
{
Json
::
Value
SGXWalletServer
::
ecdsaSignMessageHash
(
int
_base
,
const
string
&
_keyShareName
,
const
string
&
_messageHash
)
{
lock_guard
<
recursive_mutex
>
lock
(
m
);
lock_guard
<
recursive_mutex
>
lock
(
m
);
spdlog
::
info
(
"entered ecdsaSignMessageHash"
);
spdlog
::
debug
(
"MessageHash first {}"
,
_messageHash
);
if
(
printDebugInfo
)
{
spdlog
::
info
(
"MessageHash first {}"
,
_messageHash
);
}
return
ecdsaSignMessageHashImpl
(
_base
,
_keyShareName
,
_messageHash
);
return
ecdsaSignMessageHashImpl
(
_base
,
_keyShareName
,
_messageHash
);
}
}
...
@@ -890,12 +860,10 @@ void SGXWalletServer::writeDataToDB(const string &Name, const string &value) {
...
@@ -890,12 +860,10 @@ void SGXWalletServer::writeDataToDB(const string &Name, const string &value) {
if
(
LevelDB
::
getLevelDb
()
->
readString
(
Name
)
!=
nullptr
)
{
if
(
LevelDB
::
getLevelDb
()
->
readString
(
Name
)
!=
nullptr
)
{
spdlog
::
info
(
"name {}"
,
Name
,
" already exists"
);
spdlog
::
info
(
"name {}"
,
Name
,
" already exists"
);
throw
RPCException
(
KEY_SHARE_ALREADY_EXISTS
,
"
Data with this nam
e already exists"
);
throw
RPCException
(
KEY_SHARE_ALREADY_EXISTS
,
"
Key shar
e already exists"
);
}
}
LevelDB
::
getLevelDb
()
->
writeString
(
key
,
value
);
LevelDB
::
getLevelDb
()
->
writeString
(
key
,
value
);
if
(
printDebugInfo
)
{
spdlog
::
info
(
"{} "
,
Name
,
" is written to db "
);
}
}
}
testw.cpp
View file @
6e432708
...
@@ -113,9 +113,9 @@ char *encryptTestKey() {
...
@@ -113,9 +113,9 @@ char *encryptTestKey() {
REQUIRE
(
encryptedKeyHex
!=
nullptr
);
REQUIRE
(
encryptedKeyHex
!=
nullptr
);
REQUIRE
(
errStatus
==
0
);
REQUIRE
(
errStatus
==
0
);
printf
(
"Encrypt key completed with status: %d %s
\n
"
,
errStatus
,
errMsg
.
data
());
//
printf("Encrypt key completed with status: %d %s \n", errStatus, errMsg.data());
printf
(
"Encrypted key len %d
\n
"
,
(
int
)
strlen
(
encryptedKeyHex
));
//
printf("Encrypted key len %d\n", (int) strlen(encryptedKeyHex));
printf
(
"Encrypted key %s
\n
"
,
encryptedKeyHex
);
//
printf("Encrypted key %s \n", encryptedKeyHex);
return
encryptedKeyHex
;
return
encryptedKeyHex
;
}
}
...
@@ -123,7 +123,7 @@ char *encryptTestKey() {
...
@@ -123,7 +123,7 @@ char *encryptTestKey() {
TEST_CASE
(
"BLS key encrypt"
,
"[bls-key-encrypt]"
)
{
TEST_CASE
(
"BLS key encrypt"
,
"[bls-key-encrypt]"
)
{
resetDB
();
resetDB
();
setOptions
(
tru
e
,
false
,
true
);
setOptions
(
fals
e
,
false
,
true
);
initAll
(
false
,
true
);
initAll
(
false
,
true
);
auto
key
=
encryptTestKey
();
auto
key
=
encryptTestKey
();
REQUIRE
(
key
!=
nullptr
);
REQUIRE
(
key
!=
nullptr
);
...
@@ -134,7 +134,7 @@ TEST_CASE("BLS key encrypt", "[bls-key-encrypt]") {
...
@@ -134,7 +134,7 @@ TEST_CASE("BLS key encrypt", "[bls-key-encrypt]") {
/* Do later
/* Do later
TEST_CASE("BLS key encrypt/decrypt", "[bls-key-encrypt-decrypt]") {
TEST_CASE("BLS key encrypt/decrypt", "[bls-key-encrypt-decrypt]") {
resetDB();
resetDB();
setOptions(
tru
e, false, true);
setOptions(
fals
e, false, true);
initAll(false, true);
initAll(false, true);
//init_enclave();
//init_enclave();
...
@@ -172,24 +172,24 @@ void destroyEnclave() {
...
@@ -172,24 +172,24 @@ void destroyEnclave() {
TEST_CASE
(
"DKG gen test"
,
"[dkg-gen]"
)
{
TEST_CASE
(
"DKG gen test"
,
"[dkg-gen]"
)
{
resetDB
();
resetDB
();
setOptions
(
tru
e
,
false
,
true
);
setOptions
(
fals
e
,
false
,
true
);
initAll
(
false
,
true
);
initAll
(
false
,
true
);
vector
<
uint8_t
>
encrypted_dkg_secret
(
DKG_MAX_SEALED_LEN
,
0
);
vector
<
uint8_t
>
encrypted_dkg_secret
(
DKG_MAX_SEALED_LEN
,
0
);
vector
<
char
>
errMsg
(
1024
,
0
);
vector
<
char
>
errMsg
(
BUF_LEN
,
0
);
int
err_status
=
0
;
int
err_status
=
0
;
uint32_t
enc_len
=
0
;
uint32_t
enc_len
=
0
;
status
=
gen_dkg_secret
(
eid
,
&
err_status
,
errMsg
.
data
(),
encrypted_dkg_secret
.
data
(),
&
enc_len
,
32
);
status
=
gen_dkg_secret
(
eid
,
&
err_status
,
errMsg
.
data
(),
encrypted_dkg_secret
.
data
(),
&
enc_len
,
32
);
REQUIRE
(
status
==
SGX_SUCCESS
);
REQUIRE
(
status
==
SGX_SUCCESS
);
printf
(
"gen_dkg_secret completed with status: %d %s
\n
"
,
err_status
,
errMsg
.
data
());
//
printf("gen_dkg_secret completed with status: %d %s \n", err_status, errMsg.data());
printf
(
"
\n
Length: %d
\n
"
,
enc_len
);
//
printf("\n Length: %d \n", enc_len);
vector
<
char
>
secret
(
DKG_BUFER_LENGTH
,
0
);
vector
<
char
>
secret
(
DKG_BUFER_LENGTH
,
0
);
vector
<
char
>
errMsg1
(
1024
,
0
);
vector
<
char
>
errMsg1
(
BUF_LEN
,
0
);
uint32_t
dec_len
;
uint32_t
dec_len
;
status
=
decrypt_dkg_secret
(
eid
,
&
err_status
,
errMsg1
.
data
(),
encrypted_dkg_secret
.
data
(),
status
=
decrypt_dkg_secret
(
eid
,
&
err_status
,
errMsg1
.
data
(),
encrypted_dkg_secret
.
data
(),
...
@@ -197,10 +197,10 @@ TEST_CASE("DKG gen test", "[dkg-gen]") {
...
@@ -197,10 +197,10 @@ TEST_CASE("DKG gen test", "[dkg-gen]") {
REQUIRE
(
status
==
SGX_SUCCESS
);
REQUIRE
(
status
==
SGX_SUCCESS
);
printf
(
"
\n
decrypt_dkg_secret completed with status: %d %s
\n
"
,
err_status
,
errMsg1
.
data
());
//
printf("\ndecrypt_dkg_secret completed with status: %d %s \n", err_status, errMsg1.data());
printf
(
"decrypted secret %s
\n\n
"
,
secret
.
data
());
//
printf("decrypted secret %s \n\n", secret.data());
printf
(
"secret length %d
\n
"
,
(
int
)
strlen
(
secret
.
data
()));
//
printf("secret length %d \n", (int) strlen(secret.data()));
printf
(
"decr length %d
\n
"
,
dec_len
);
//
printf("decr length %d \n", dec_len);
sgx_destroy_enclave
(
eid
);
sgx_destroy_enclave
(
eid
);
}
}
...
@@ -261,14 +261,14 @@ libff::alt_bn128_G2 VectStringToG2(const vector<string> &G2_str_vect) {
...
@@ -261,14 +261,14 @@ libff::alt_bn128_G2 VectStringToG2(const vector<string> &G2_str_vect) {
TEST_CASE
(
"DKG public shares test"
,
"[dkg-pub_shares]"
)
{
TEST_CASE
(
"DKG public shares test"
,
"[dkg-pub_shares]"
)
{
resetDB
();
resetDB
();
setOptions
(
tru
e
,
false
,
true
);
setOptions
(
fals
e
,
false
,
true
);
initAll
(
false
,
true
);
initAll
(
false
,
true
);
libff
::
init_alt_bn128_params
();
libff
::
init_alt_bn128_params
();
vector
<
uint8_t
>
encrypted_dkg_secret
(
DKG_MAX_SEALED_LEN
,
0
);
vector
<
uint8_t
>
encrypted_dkg_secret
(
DKG_MAX_SEALED_LEN
,
0
);
vector
<
char
>
errMsg
(
1024
,
0
);
vector
<
char
>
errMsg
(
BUF_LEN
,
0
);
int
err_status
=
0
;
int
err_status
=
0
;
uint32_t
enc_len
=
0
;
uint32_t
enc_len
=
0
;
...
@@ -280,7 +280,7 @@ TEST_CASE("DKG public shares test", "[dkg-pub_shares]") {
...
@@ -280,7 +280,7 @@ TEST_CASE("DKG public shares test", "[dkg-pub_shares]") {
//printf("gen_dkg_public completed with status: %d %s \n", err_status, errMsg);
//printf("gen_dkg_public completed with status: %d %s \n", err_status, errMsg);
vector
<
char
>
errMsg1
(
1024
,
0
);
vector
<
char
>
errMsg1
(
BUF_LEN
,
0
);
char
colon
=
':'
;
char
colon
=
':'
;
vector
<
char
>
public_shares
(
10000
,
0
);
vector
<
char
>
public_shares
(
10000
,
0
);
...
@@ -288,9 +288,9 @@ TEST_CASE("DKG public shares test", "[dkg-pub_shares]") {
...
@@ -288,9 +288,9 @@ TEST_CASE("DKG public shares test", "[dkg-pub_shares]") {
status
=
get_public_shares
(
eid
,
&
err_status
,
errMsg1
.
data
(),
status
=
get_public_shares
(
eid
,
&
err_status
,
errMsg1
.
data
(),
encrypted_dkg_secret
.
data
(),
enc_len
,
public_shares
.
data
(),
t
,
n
);
encrypted_dkg_secret
.
data
(),
enc_len
,
public_shares
.
data
(),
t
,
n
);
REQUIRE
(
status
==
SGX_SUCCESS
);
REQUIRE
(
status
==
SGX_SUCCESS
);
printf
(
"
\n
get_public_shares status: %d error %s
\n\n
"
,
err_status
,
errMsg1
.
data
());
//
printf("\nget_public_shares status: %d error %s \n\n", err_status, errMsg1.data());
printf
(
" LEN: %d
\n
"
,
(
int
)
strlen
(
public_shares
.
data
()));
//
printf(" LEN: %d \n", (int) strlen(public_shares.data()));
printf
(
" result: %s
\n
"
,
public_shares
.
data
());
//
printf(" result: %s \n", public_shares.data());
vector
<
string
>
G2_strings
=
SplitString
(
public_shares
.
data
(),
','
);
vector
<
string
>
G2_strings
=
SplitString
(
public_shares
.
data
(),
','
);
vector
<
libff
::
alt_bn128_G2
>
pub_shares_G2
;
vector
<
libff
::
alt_bn128_G2
>
pub_shares_G2
;
...
@@ -307,13 +307,13 @@ TEST_CASE("DKG public shares test", "[dkg-pub_shares]") {
...
@@ -307,13 +307,13 @@ TEST_CASE("DKG public shares test", "[dkg-pub_shares]") {
status
=
decrypt_dkg_secret
(
eid
,
&
err_status
,
errMsg1
.
data
(),
encrypted_dkg_secret
.
data
(),
status
=
decrypt_dkg_secret
(
eid
,
&
err_status
,
errMsg1
.
data
(),
encrypted_dkg_secret
.
data
(),
(
uint8_t
*
)
secret
.
data
(),
&
enc_len
);
(
uint8_t
*
)
secret
.
data
(),
&
enc_len
);
REQUIRE
(
status
==
SGX_SUCCESS
);
REQUIRE
(
status
==
SGX_SUCCESS
);
printf
(
"
\n
decrypt_dkg_secret completed with status: %d %s
\n
"
,
err_status
,
errMsg1
.
data
());
//
printf("\ndecrypt_dkg_secret completed with status: %d %s \n", err_status, errMsg1.data());
signatures
::
Dkg
dkg_obj
(
t
,
n
);
signatures
::
Dkg
dkg_obj
(
t
,
n
);
vector
<
libff
::
alt_bn128_Fr
>
poly
=
SplitStringToFr
(
secret
.
data
(),
colon
);
vector
<
libff
::
alt_bn128_Fr
>
poly
=
SplitStringToFr
(
secret
.
data
(),
colon
);
vector
<
libff
::
alt_bn128_G2
>
pub_shares_dkg
=
dkg_obj
.
VerificationVector
(
poly
);
vector
<
libff
::
alt_bn128_G2
>
pub_shares_dkg
=
dkg_obj
.
VerificationVector
(
poly
);
printf
(
"calculated public shares (X.c0):
\n
"
);
//
printf("calculated public shares (X.c0): \n");
for
(
uint32_t
i
=
0
;
i
<
pub_shares_dkg
.
size
();
i
++
)
{
for
(
uint32_t
i
=
0
;
i
<
pub_shares_dkg
.
size
();
i
++
)
{
libff
::
alt_bn128_G2
el
=
pub_shares_dkg
.
at
(
i
);
libff
::
alt_bn128_G2
el
=
pub_shares_dkg
.
at
(
i
);
el
.
to_affine_coordinates
();
el
.
to_affine_coordinates
();
...
@@ -323,7 +323,7 @@ TEST_CASE("DKG public shares test", "[dkg-pub_shares]") {
...
@@ -323,7 +323,7 @@ TEST_CASE("DKG public shares test", "[dkg-pub_shares]") {
x_c0_el
.
as_bigint
().
to_mpz
(
x_c0
);
x_c0_el
.
as_bigint
().
to_mpz
(
x_c0
);
char
arr
[
mpz_sizeinbase
(
x_c0
,
10
)
+
2
];
char
arr
[
mpz_sizeinbase
(
x_c0
,
10
)
+
2
];
char
*
share_str
=
mpz_get_str
(
arr
,
10
,
x_c0
);
char
*
share_str
=
mpz_get_str
(
arr
,
10
,
x_c0
);
printf
(
" %s
\n
"
,
share_str
);
//
printf(" %s \n", share_str);
mpz_clear
(
x_c0
);
mpz_clear
(
x_c0
);
}
}
...
@@ -335,12 +335,12 @@ TEST_CASE("DKG public shares test", "[dkg-pub_shares]") {
...
@@ -335,12 +335,12 @@ TEST_CASE("DKG public shares test", "[dkg-pub_shares]") {
TEST_CASE
(
"DKG encrypted secret shares test"
,
"[dkg-encr_sshares]"
)
{
TEST_CASE
(
"DKG encrypted secret shares test"
,
"[dkg-encr_sshares]"
)
{
resetDB
();
resetDB
();
setOptions
(
tru
e
,
false
,
true
);
setOptions
(
fals
e
,
false
,
true
);
initAll
(
false
,
true
);
initAll
(
false
,
true
);
vector
<
char
>
errMsg
(
1024
,
0
);
vector
<
char
>
errMsg
(
BUF_LEN
,
0
);
vector
<
char
>
result
(
1300
,
0
);
vector
<
char
>
result
(
BUF_LEN
,
0
);
int
err_status
=
0
;
int
err_status
=
0
;
uint32_t
enc_len
=
0
;
uint32_t
enc_len
=
0
;
...
@@ -348,36 +348,36 @@ TEST_CASE("DKG encrypted secret shares test", "[dkg-encr_sshares]") {
...
@@ -348,36 +348,36 @@ TEST_CASE("DKG encrypted secret shares test", "[dkg-encr_sshares]") {
vector
<
uint8_t
>
encrypted_dkg_secret
(
DKG_MAX_SEALED_LEN
,
0
);
vector
<
uint8_t
>
encrypted_dkg_secret
(
DKG_MAX_SEALED_LEN
,
0
);
status
=
gen_dkg_secret
(
eid
,
&
err_status
,
errMsg
.
data
(),
encrypted_dkg_secret
.
data
(),
&
enc_len
,
2
);
status
=
gen_dkg_secret
(
eid
,
&
err_status
,
errMsg
.
data
(),
encrypted_dkg_secret
.
data
(),
&
enc_len
,
2
);
REQUIRE
(
status
==
SGX_SUCCESS
);
REQUIRE
(
status
==
SGX_SUCCESS
);
cerr
<<
" poly generated"
<<
endl
;
//
cerr << " poly generated" << endl;
status
=
set_encrypted_dkg_poly
(
eid
,
&
err_status
,
errMsg
.
data
(),
encrypted_dkg_secret
.
data
());
status
=
set_encrypted_dkg_poly
(
eid
,
&
err_status
,
errMsg
.
data
(),
encrypted_dkg_secret
.
data
());
REQUIRE
(
status
==
SGX_SUCCESS
);
REQUIRE
(
status
==
SGX_SUCCESS
);
cerr
<<
" poly set"
<<
endl
;
//
cerr << " poly set" << endl;
vector
<
uint8_t
>
encrPRDHKey
(
1024
,
0
);
vector
<
uint8_t
>
encrPRDHKey
(
BUF_LEN
,
0
);
string
pub_keyB
=
"c0152c48bf640449236036075d65898fded1e242c00acb45519ad5f788ea7cbf9a5df1559e7fc87932eee5478b1b9023de19df654395574a690843988c3ff475"
;
string
pub_keyB
=
"c0152c48bf640449236036075d65898fded1e242c00acb45519ad5f788ea7cbf9a5df1559e7fc87932eee5478b1b9023de19df654395574a690843988c3ff475"
;
vector
<
char
>
s_shareG2
(
320
,
0
);
vector
<
char
>
s_shareG2
(
BUF_LEN
,
0
);
status
=
get_encr_sshare
(
eid
,
&
err_status
,
errMsg
.
data
(),
encrPRDHKey
.
data
(),
&
enc_len
,
result
.
data
(),
status
=
get_encr_sshare
(
eid
,
&
err_status
,
errMsg
.
data
(),
encrPRDHKey
.
data
(),
&
enc_len
,
result
.
data
(),
s_shareG2
.
data
(),
s_shareG2
.
data
(),
(
char
*
)
pub_keyB
.
data
(),
2
,
2
,
1
);
(
char
*
)
pub_keyB
.
data
(),
2
,
2
,
1
);
REQUIRE
(
status
==
SGX_SUCCESS
);
REQUIRE
(
status
==
SGX_SUCCESS
);
cerr
<<
"secret share is "
<<
result
.
data
()
<<
endl
;
//
cerr << "secret share is " << result.data() << endl;
//sgx_destroy_enclave(eid);
//sgx_destroy_enclave(eid);
}
}
TEST_CASE
(
"DKG verification test"
,
"[dkg-verify]"
)
{
TEST_CASE
(
"DKG verification test"
,
"[dkg-verify]"
)
{
resetDB
();
resetDB
();
setOptions
(
tru
e
,
false
,
true
);
setOptions
(
fals
e
,
false
,
true
);
initAll
(
false
,
true
);
initAll
(
false
,
true
);
vector
<
char
>
errMsg
(
1024
,
0
);
vector
<
char
>
errMsg
(
BUF_LEN
,
0
);
vector
<
char
>
result
(
130
,
0
);
vector
<
char
>
result
(
BUF_LEN
,
0
);
int
err_status
=
0
;
int
err_status
=
0
;
uint32_t
enc_len
=
0
;
uint32_t
enc_len
=
0
;
...
@@ -386,25 +386,25 @@ TEST_CASE("DKG verification test", "[dkg-verify]") {
...
@@ -386,25 +386,25 @@ TEST_CASE("DKG verification test", "[dkg-verify]") {
status
=
gen_dkg_secret
(
eid
,
&
err_status
,
errMsg
.
data
(),
encrypted_dkg_secret
.
data
(),
&
enc_len
,
2
);
status
=
gen_dkg_secret
(
eid
,
&
err_status
,
errMsg
.
data
(),
encrypted_dkg_secret
.
data
(),
&
enc_len
,
2
);
REQUIRE
(
status
==
SGX_SUCCESS
);
REQUIRE
(
status
==
SGX_SUCCESS
);
cerr
<<
" poly generated"
<<
endl
;
//
cerr << " poly generated" << endl;
status
=
set_encrypted_dkg_poly
(
eid
,
&
err_status
,
errMsg
.
data
(),
encrypted_dkg_secret
.
data
());
status
=
set_encrypted_dkg_poly
(
eid
,
&
err_status
,
errMsg
.
data
(),
encrypted_dkg_secret
.
data
());
REQUIRE
(
status
==
SGX_SUCCESS
);
REQUIRE
(
status
==
SGX_SUCCESS
);
cerr
<<
" poly set"
<<
endl
;
//
cerr << " poly set" << endl;
vector
<
uint8_t
>
encrPrDHKey
(
1024
,
0
);
vector
<
uint8_t
>
encrPrDHKey
(
BUF_LEN
,
0
);
string
pub_keyB
=
"c0152c48bf640449236036075d65898fded1e242c00acb45519ad5f788ea7cbf9a5df1559e7fc87932eee5478b1b9023de19df654395574a690843988c3ff475"
;
string
pub_keyB
=
"c0152c48bf640449236036075d65898fded1e242c00acb45519ad5f788ea7cbf9a5df1559e7fc87932eee5478b1b9023de19df654395574a690843988c3ff475"
;
vector
<
char
>
s_shareG2
(
320
,
0
);
vector
<
char
>
s_shareG2
(
BUF_LEN
,
0
);
status
=
get_encr_sshare
(
eid
,
&
err_status
,
errMsg
.
data
(),
encrPrDHKey
.
data
(),
&
enc_len
,
result
.
data
(),
status
=
get_encr_sshare
(
eid
,
&
err_status
,
errMsg
.
data
(),
encrPrDHKey
.
data
(),
&
enc_len
,
result
.
data
(),
s_shareG2
.
data
(),
s_shareG2
.
data
(),
(
char
*
)
pub_keyB
.
data
(),
2
,
2
,
1
);
(
char
*
)
pub_keyB
.
data
(),
2
,
2
,
1
);
REQUIRE
(
status
==
SGX_SUCCESS
);
REQUIRE
(
status
==
SGX_SUCCESS
);
printf
(
" get_encr_sshare completed with status: %d %s
\n
"
,
err_status
,
errMsg
.
data
());
//
printf(" get_encr_sshare completed with status: %d %s \n", err_status, errMsg.data());
cerr
<<
"secret share is "
<<
result
.
data
()
<<
endl
;
//
cerr << "secret share is " << result.data() << endl;
sgx_destroy_enclave
(
eid
);
sgx_destroy_enclave
(
eid
);
...
@@ -413,15 +413,15 @@ TEST_CASE("DKG verification test", "[dkg-verify]") {
...
@@ -413,15 +413,15 @@ TEST_CASE("DKG verification test", "[dkg-verify]") {
TEST_CASE
(
"ECDSA keygen and signature test"
,
"[ecdsa_test]"
)
{
TEST_CASE
(
"ECDSA keygen and signature test"
,
"[ecdsa_test]"
)
{
resetDB
();
resetDB
();
setOptions
(
tru
e
,
false
,
true
);
setOptions
(
fals
e
,
false
,
true
);
initAll
(
false
,
true
);
initAll
(
false
,
true
);
vector
<
char
>
errMsg
(
1024
,
0
);
vector
<
char
>
errMsg
(
BUF_LEN
,
0
);
int
err_status
=
0
;
int
err_status
=
0
;
vector
<
uint8_t
>
encr_pr_key
(
1024
,
0
);
vector
<
uint8_t
>
encr_pr_key
(
BUF_LEN
,
0
);
vector
<
char
>
pub_key_x
(
1024
,
0
);
vector
<
char
>
pub_key_x
(
BUF_LEN
,
0
);
vector
<
char
>
pub_key_y
(
1024
,
0
);
vector
<
char
>
pub_key_y
(
BUF_LEN
,
0
);
uint32_t
enc_len
=
0
;
uint32_t
enc_len
=
0
;
...
@@ -429,42 +429,42 @@ TEST_CASE("ECDSA keygen and signature test", "[ecdsa_test]") {
...
@@ -429,42 +429,42 @@ TEST_CASE("ECDSA keygen and signature test", "[ecdsa_test]") {
status
=
generate_ecdsa_key
(
eid
,
&
err_status
,
errMsg
.
data
(),
encr_pr_key
.
data
(),
&
enc_len
,
pub_key_x
.
data
(),
status
=
generate_ecdsa_key
(
eid
,
&
err_status
,
errMsg
.
data
(),
encr_pr_key
.
data
(),
&
enc_len
,
pub_key_x
.
data
(),
pub_key_y
.
data
());
pub_key_y
.
data
());
printf
(
"
\n
errMsg %s
\n
"
,
errMsg
.
data
());
//
printf("\nerrMsg %s\n", errMsg.data());
REQUIRE
(
status
==
SGX_SUCCESS
);
REQUIRE
(
status
==
SGX_SUCCESS
);
printf
(
"
\n
was pub_key_x %s:
\n
"
,
pub_key_x
.
data
());
//
printf("\nwas pub_key_x %s: \n", pub_key_x.data());
printf
(
"
\n
was pub_key_y %s:
\n
"
,
pub_key_y
.
data
());
//
printf("\nwas pub_key_y %s: \n", pub_key_y.data());
string
hex
=
"3F891FDA3704F0368DAB65FA81EBE616F4AA2A0854995DA4DC0B59D2CADBD64F"
;
string
hex
=
"3F891FDA3704F0368DAB65FA81EBE616F4AA2A0854995DA4DC0B59D2CADBD64F"
;
printf
(
"hash length %d "
,
(
int
)
hex
.
size
());
//
printf("hash length %d ", (int) hex.size());
vector
<
char
>
signature_r
(
1024
,
0
);
vector
<
char
>
signature_r
(
BUF_LEN
,
0
);
vector
<
char
>
signature_s
(
1024
,
0
);
vector
<
char
>
signature_s
(
BUF_LEN
,
0
);
uint8_t
signature_v
=
0
;
uint8_t
signature_v
=
0
;
status
=
ecdsa_sign1
(
eid
,
&
err_status
,
errMsg
.
data
(),
encr_pr_key
.
data
(),
enc_len
,
(
unsigned
char
*
)
hex
.
data
(),
status
=
ecdsa_sign1
(
eid
,
&
err_status
,
errMsg
.
data
(),
encr_pr_key
.
data
(),
enc_len
,
(
unsigned
char
*
)
hex
.
data
(),
signature_r
.
data
(),
signature_r
.
data
(),
signature_s
.
data
(),
&
signature_v
,
16
);
signature_s
.
data
(),
&
signature_v
,
16
);
REQUIRE
(
status
==
SGX_SUCCESS
);
REQUIRE
(
status
==
SGX_SUCCESS
);
printf
(
"
\n
signature r : %s "
,
signature_r
.
data
());
//
printf("\nsignature r : %s ", signature_r.data());
printf
(
"
\n
signature s: %s "
,
signature_s
.
data
());
//
printf("\nsignature s: %s ", signature_s.data());
printf
(
"
\n
signature v: %u "
,
signature_v
);
//
printf("\nsignature v: %u ", signature_v);
printf
(
"
\n
%s
\n
"
,
errMsg
.
data
());
//
printf("\n %s \n", errMsg.data());
sgx_destroy_enclave
(
eid
);
sgx_destroy_enclave
(
eid
);
printf
(
"the end of ecdsa test
\n
"
);
//
printf("the end of ecdsa test\n");
}
}
TEST_CASE
(
"Test test"
,
"[test_test]"
)
{
TEST_CASE
(
"Test test"
,
"[test_test]"
)
{
resetDB
();
resetDB
();
setOptions
(
tru
e
,
false
,
true
);
setOptions
(
fals
e
,
false
,
true
);
initAll
(
false
,
true
);
initAll
(
false
,
true
);
vector
<
char
>
errMsg
(
1024
,
0
);
vector
<
char
>
errMsg
(
BUF_LEN
,
0
);
int
err_status
=
0
;
int
err_status
=
0
;
vector
<
uint8_t
>
encr_pr_key
(
1024
,
0
);
vector
<
uint8_t
>
encr_pr_key
(
BUF_LEN
,
0
);
vector
<
char
>
pub_key_x
(
1024
,
0
);
vector
<
char
>
pub_key_x
(
BUF_LEN
,
0
);
vector
<
char
>
pub_key_y
(
1024
,
0
);
vector
<
char
>
pub_key_y
(
BUF_LEN
,
0
);
uint32_t
enc_len
=
0
;
uint32_t
enc_len
=
0
;
status
=
generate_ecdsa_key
(
eid
,
&
err_status
,
errMsg
.
data
(),
encr_pr_key
.
data
(),
&
enc_len
,
pub_key_x
.
data
(),
status
=
generate_ecdsa_key
(
eid
,
&
err_status
,
errMsg
.
data
(),
encr_pr_key
.
data
(),
&
enc_len
,
pub_key_x
.
data
(),
...
@@ -479,38 +479,38 @@ TEST_CASE("Test test", "[test_test]") {
...
@@ -479,38 +479,38 @@ TEST_CASE("Test test", "[test_test]") {
TEST_CASE
(
"get public ECDSA key"
,
"[get_pub_ecdsa_key_test]"
)
{
TEST_CASE
(
"get public ECDSA key"
,
"[get_pub_ecdsa_key_test]"
)
{
resetDB
();
resetDB
();
setOptions
(
tru
e
,
false
,
true
);
setOptions
(
fals
e
,
false
,
true
);
initAll
(
false
,
true
);
initAll
(
false
,
true
);
int
err_status
=
0
;
int
err_status
=
0
;
vector
<
char
>
errMsg
(
1024
,
0
);
vector
<
char
>
errMsg
(
BUF_LEN
,
0
);
vector
<
uint8_t
>
encr_pr_key
(
1024
,
0
);
vector
<
uint8_t
>
encr_pr_key
(
BUF_LEN
,
0
);
vector
<
char
>
pub_key_x
(
1024
,
0
);
vector
<
char
>
pub_key_x
(
BUF_LEN
,
0
);
vector
<
char
>
pub_key_y
(
1024
,
0
);
vector
<
char
>
pub_key_y
(
BUF_LEN
,
0
);
uint32_t
enc_len
=
0
;
uint32_t
enc_len
=
0
;
status
=
generate_ecdsa_key
(
eid
,
&
err_status
,
errMsg
.
data
(),
encr_pr_key
.
data
(),
&
enc_len
,
pub_key_x
.
data
(),
status
=
generate_ecdsa_key
(
eid
,
&
err_status
,
errMsg
.
data
(),
encr_pr_key
.
data
(),
&
enc_len
,
pub_key_x
.
data
(),
pub_key_y
.
data
());
pub_key_y
.
data
());
printf
(
"
\n
errMsg %s
\n
"
,
errMsg
.
data
());
//
printf("\nerrMsg %s\n", errMsg.data());
REQUIRE
(
status
==
SGX_SUCCESS
);
REQUIRE
(
status
==
SGX_SUCCESS
);
printf
(
"
\n
was pub_key_x %s length %d:
\n
"
,
pub_key_x
.
data
(),
(
int
)
strlen
(
pub_key_x
.
data
()));
//
printf("\nwas pub_key_x %s length %d: \n", pub_key_x.data(), (int) strlen(pub_key_x.data()));
printf
(
"
\n
was pub_key_y %s length %d:
\n
"
,
pub_key_y
.
data
(),
(
int
)
strlen
(
pub_key_y
.
data
()));
//
printf("\nwas pub_key_y %s length %d: \n", pub_key_y.data(), (int) strlen(pub_key_y.data()));
/*printf("\nencr priv_key %s: \n");
/*printf("\nencr priv_key %s: \n");
for ( int i = 0; i <
1024
; i++)
for ( int i = 0; i <
BUF_LEN
; i++)
printf("%u ", encr_pr_key[i]);*/
printf("%u ", encr_pr_key[i]);*/
vector
<
char
>
got_pub_key_x
(
1024
,
0
);
vector
<
char
>
got_pub_key_x
(
BUF_LEN
,
0
);
vector
<
char
>
got_pub_key_y
(
1024
,
0
);
vector
<
char
>
got_pub_key_y
(
BUF_LEN
,
0
);
status
=
get_public_ecdsa_key
(
eid
,
&
err_status
,
errMsg
.
data
(),
encr_pr_key
.
data
(),
enc_len
,
got_pub_key_x
.
data
(),
status
=
get_public_ecdsa_key
(
eid
,
&
err_status
,
errMsg
.
data
(),
encr_pr_key
.
data
(),
enc_len
,
got_pub_key_x
.
data
(),
got_pub_key_y
.
data
());
got_pub_key_y
.
data
());
REQUIRE
(
status
==
SGX_SUCCESS
);
REQUIRE
(
status
==
SGX_SUCCESS
);
printf
(
"
\n
now pub_key_x %s:
\n
"
,
got_pub_key_x
.
data
());
//
printf("\nnow pub_key_x %s: \n", got_pub_key_x.data());
printf
(
"
\n
now pub_key_y %s:
\n
"
,
got_pub_key_y
.
data
());
//
printf("\nnow pub_key_y %s: \n", got_pub_key_y.data());
printf
(
"
\n
pr key %s
\n
"
,
errMsg
.
data
());
//
printf("\n pr key %s \n", errMsg.data());
sgx_destroy_enclave
(
eid
);
sgx_destroy_enclave
(
eid
);
...
@@ -554,12 +554,12 @@ string ConvertDecToHex(string dec, int numBytes = 32) {
...
@@ -554,12 +554,12 @@ string ConvertDecToHex(string dec, int numBytes = 32) {
TEST_CASE
(
"BLS_DKG test"
,
"[bls_dkg]"
)
{
TEST_CASE
(
"BLS_DKG test"
,
"[bls_dkg]"
)
{
resetDB
();
resetDB
();
setOptions
(
tru
e
,
false
,
true
);
setOptions
(
fals
e
,
false
,
true
);
initAll
(
false
,
true
);
initAll
(
false
,
true
);
HttpClient
client
(
"http://localhost:1029"
);
HttpClient
client
(
"http://localhost:1029"
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
cerr
<<
"Client inited"
<<
endl
;
//
cerr << "Client inited" << endl;
int
n
=
16
,
t
=
16
;
int
n
=
16
,
t
=
16
;
...
@@ -615,15 +615,15 @@ TEST_CASE("BLS_DKG test", "[bls_dkg]") {
...
@@ -615,15 +615,15 @@ TEST_CASE("BLS_DKG test", "[bls_dkg]") {
for
(
int
i
=
0
;
i
<
n
;
i
++
)
for
(
int
i
=
0
;
i
<
n
;
i
++
)
for
(
int
j
=
0
;
j
<
n
;
j
++
)
{
for
(
int
j
=
0
;
j
<
n
;
j
++
)
{
// if ( i != j ){
cerr
<<
"secretShare length is "
<<
secretShares
[
i
][
"secretShare"
].
asString
().
length
()
<<
endl
;
//
cerr << "secretShare length is " << secretShares[i]["secretShare"].asString().length() << endl;
string
secretShare
=
secretShares
[
i
][
"secretShare"
].
asString
().
substr
(
192
*
j
,
192
);
string
secretShare
=
secretShares
[
i
][
"secretShare"
].
asString
().
substr
(
192
*
j
,
192
);
secShares_vect
[
i
]
+=
secretShares
[
j
][
"secretShare"
].
asString
().
substr
(
192
*
i
,
192
);
secShares_vect
[
i
]
+=
secretShares
[
j
][
"secretShare"
].
asString
().
substr
(
192
*
i
,
192
);
cerr
<<
"pubShare is "
<<
pubShares
[
i
]
<<
endl
;
//
cerr << "pubShare is " << pubShares[i] << endl;
bool
res
=
c
.
dkgVerification
(
pubShares
[
i
],
EthKeys
[
j
][
"keyName"
].
asString
(),
secretShare
,
t
,
n
,
bool
res
=
c
.
dkgVerification
(
pubShares
[
i
],
EthKeys
[
j
][
"keyName"
].
asString
(),
secretShare
,
t
,
n
,
j
)[
"result"
].
asBool
();
j
)[
"result"
].
asBool
();
k
++
;
k
++
;
cerr
<<
"NOW K IS "
<<
k
<<
" i is "
<<
i
<<
" j is "
<<
j
<<
endl
;
//
cerr << "NOW K IS " << k << " i is " << i << " j is " << j << endl;
REQUIRE
(
res
);
REQUIRE
(
res
);
pSharesBad
[
i
][
0
]
=
'q'
;
pSharesBad
[
i
][
0
]
=
'q'
;
...
@@ -631,7 +631,7 @@ TEST_CASE("BLS_DKG test", "[bls_dkg]") {
...
@@ -631,7 +631,7 @@ TEST_CASE("BLS_DKG test", "[bls_dkg]") {
n
,
j
);
n
,
j
);
res
=
wrongVerif
[
"result"
].
asBool
();
res
=
wrongVerif
[
"result"
].
asBool
();
REQUIRE
(
!
res
);
REQUIRE
(
!
res
);
cerr
<<
"wrong verification "
<<
wrongVerif
<<
endl
;
//
cerr << "wrong verification " << wrongVerif << endl;
// }
// }
}
}
...
@@ -656,10 +656,10 @@ TEST_CASE("BLS_DKG test", "[bls_dkg]") {
...
@@ -656,10 +656,10 @@ TEST_CASE("BLS_DKG test", "[bls_dkg]") {
cout
<<
c
.
createBLSPrivateKey
(
blsName
,
EthKeys
[
i
][
"keyName"
].
asString
(),
poly_names
[
i
],
secShares_vect
[
i
],
t
,
cout
<<
c
.
createBLSPrivateKey
(
blsName
,
EthKeys
[
i
][
"keyName"
].
asString
(),
poly_names
[
i
],
secShares_vect
[
i
],
t
,
n
);
n
);
pubBLSKeys
[
i
]
=
c
.
getBLSPublicKeyShare
(
blsName
);
pubBLSKeys
[
i
]
=
c
.
getBLSPublicKeyShare
(
blsName
);
cerr
<<
"BLS KEY SHARE NAME IS "
<<
blsName
<<
endl
;
//
cerr << "BLS KEY SHARE NAME IS " << blsName << endl;
//string hash = "09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db";
//string hash = "09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db";
BLSSigShares
[
i
]
=
c
.
blsSignMessageHash
(
blsName
,
hash
,
t
,
n
,
i
+
1
);
BLSSigShares
[
i
]
=
c
.
blsSignMessageHash
(
blsName
,
hash
,
t
,
n
,
i
+
1
);
cerr
<<
i
<<
" sig share is created "
<<
endl
;
//
cerr << i << " sig share is created " << endl;
shared_ptr
<
string
>
sig_share_ptr
=
make_shared
<
string
>
(
BLSSigShares
[
i
][
"signatureShare"
].
asString
());
shared_ptr
<
string
>
sig_share_ptr
=
make_shared
<
string
>
(
BLSSigShares
[
i
][
"signatureShare"
].
asString
());
BLSSigShare
sig
(
sig_share_ptr
,
i
+
1
,
t
,
n
);
BLSSigShare
sig
(
sig_share_ptr
,
i
+
1
,
t
,
n
);
sigShareSet
.
addSigShare
(
make_shared
<
BLSSigShare
>
(
sig
));
sigShareSet
.
addSigShare
(
make_shared
<
BLSSigShare
>
(
sig
));
...
@@ -684,7 +684,7 @@ TEST_CASE("BLS_DKG test", "[bls_dkg]") {
...
@@ -684,7 +684,7 @@ TEST_CASE("BLS_DKG test", "[bls_dkg]") {
}
}
TEST_CASE
(
"API test"
,
"[api_test]"
)
{
TEST_CASE
(
"API test"
,
"[api_test]"
)
{
setOptions
(
tru
e
,
false
,
true
);
setOptions
(
fals
e
,
false
,
true
);
initAll
(
false
,
true
);
initAll
(
false
,
true
);
//HttpServer httpserver(1025);
//HttpServer httpserver(1025);
...
@@ -695,7 +695,7 @@ TEST_CASE("API test", "[api_test]") {
...
@@ -695,7 +695,7 @@ TEST_CASE("API test", "[api_test]") {
HttpClient
client
(
"http://localhost:1029"
);
HttpClient
client
(
"http://localhost:1029"
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
cerr
<<
"Client inited"
<<
endl
;
//
cerr << "Client inited" << endl;
try
{
try
{
// for ( uint8_t i = 0; i < 2; i++) {
// for ( uint8_t i = 0; i < 2; i++) {
...
@@ -789,7 +789,7 @@ TEST_CASE("API test", "[api_test]") {
...
@@ -789,7 +789,7 @@ TEST_CASE("API test", "[api_test]") {
TEST_CASE
(
"getServerStatus test"
,
"[getServerStatus_test]"
)
{
TEST_CASE
(
"getServerStatus test"
,
"[getServerStatus_test]"
)
{
resetDB
();
resetDB
();
setOptions
(
tru
e
,
false
,
true
);
setOptions
(
fals
e
,
false
,
true
);
initAll
(
false
,
true
);
initAll
(
false
,
true
);
HttpClient
client
(
"http://localhost:1029"
);
HttpClient
client
(
"http://localhost:1029"
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
...
@@ -848,13 +848,13 @@ void SendRPCRequest() {
...
@@ -848,13 +848,13 @@ void SendRPCRequest() {
for
(
int
i
=
0
;
i
<
n
;
i
++
)
for
(
int
i
=
0
;
i
<
n
;
i
++
)
for
(
int
j
=
0
;
j
<
n
;
j
++
)
{
for
(
int
j
=
0
;
j
<
n
;
j
++
)
{
// if ( i != j ){
// if ( i != j ){
cerr
<<
"SecretShare length is "
<<
secretShares
[
i
][
"secretShare"
].
asString
().
length
()
<<
endl
;
//
cerr << "SecretShare length is " << secretShares[i]["secretShare"].asString().length() << endl;
string
secretShare
=
secretShares
[
i
][
"secretShare"
].
asString
().
substr
(
192
*
j
,
192
);
string
secretShare
=
secretShares
[
i
][
"secretShare"
].
asString
().
substr
(
192
*
j
,
192
);
secShares_vect
[
i
]
+=
secretShares
[
j
][
"secretShare"
].
asString
().
substr
(
192
*
i
,
192
);
secShares_vect
[
i
]
+=
secretShares
[
j
][
"secretShare"
].
asString
().
substr
(
192
*
i
,
192
);
Json
::
Value
verif
=
c
.
dkgVerification
(
pubShares
[
i
],
EthKeys
[
j
][
"keyName"
].
asString
(),
secretShare
,
t
,
n
,
j
);
Json
::
Value
verif
=
c
.
dkgVerification
(
pubShares
[
i
],
EthKeys
[
j
][
"keyName"
].
asString
(),
secretShare
,
t
,
n
,
j
);
cout
<<
verif
;
cout
<<
verif
;
k
++
;
k
++
;
cerr
<<
"NOW K IS "
<<
k
<<
" i is "
<<
i
<<
" j is "
<<
j
<<
endl
;
//
cerr << "NOW K IS " << k << " i is " << i << " j is " << j << endl;
// REQUIRE( res );
// REQUIRE( res );
// }
// }
}
}
...
@@ -881,11 +881,11 @@ void SendRPCRequest() {
...
@@ -881,11 +881,11 @@ void SendRPCRequest() {
cout
<<
c
.
createBLSPrivateKey
(
blsName
,
EthKeys
[
i
][
"keyName"
].
asString
(),
poly_names
[
i
],
secShares_vect
[
i
],
t
,
cout
<<
c
.
createBLSPrivateKey
(
blsName
,
EthKeys
[
i
][
"keyName"
].
asString
(),
poly_names
[
i
],
secShares_vect
[
i
],
t
,
n
);
n
);
pubBLSKeys
[
i
]
=
c
.
getBLSPublicKeyShare
(
blsName
);
pubBLSKeys
[
i
]
=
c
.
getBLSPublicKeyShare
(
blsName
);
cerr
<<
"BLS KEY SHARE NAME IS "
<<
blsName
<<
endl
;
//
cerr << "BLS KEY SHARE NAME IS " << blsName << endl;
string
hash
=
"09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db"
;
string
hash
=
"09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db"
;
BLSSigShares
[
i
]
=
c
.
blsSignMessageHash
(
blsName
,
hash
,
t
,
n
,
i
+
1
);
BLSSigShares
[
i
]
=
c
.
blsSignMessageHash
(
blsName
,
hash
,
t
,
n
,
i
+
1
);
REQUIRE
(
BLSSigShares
[
i
][
"status"
]
==
0
);
REQUIRE
(
BLSSigShares
[
i
][
"status"
]
==
0
);
cerr
<<
i
<<
" sig share is created "
<<
endl
;
//
cerr << i << " sig share is created " << endl;
shared_ptr
<
string
>
sig_share_ptr
=
make_shared
<
string
>
(
BLSSigShares
[
i
][
"signatureShare"
].
asString
());
shared_ptr
<
string
>
sig_share_ptr
=
make_shared
<
string
>
(
BLSSigShares
[
i
][
"signatureShare"
].
asString
());
BLSSigShare
sig
(
sig_share_ptr
,
i
+
1
,
t
,
n
);
BLSSigShare
sig
(
sig_share_ptr
,
i
+
1
,
t
,
n
);
sigShareSet
.
addSigShare
(
make_shared
<
BLSSigShare
>
(
sig
));
sigShareSet
.
addSigShare
(
make_shared
<
BLSSigShare
>
(
sig
));
...
@@ -910,7 +910,7 @@ void SendRPCRequest() {
...
@@ -910,7 +910,7 @@ void SendRPCRequest() {
TEST_CASE
(
"ManySimultaneousThreads"
,
"[many_threads_test]"
)
{
TEST_CASE
(
"ManySimultaneousThreads"
,
"[many_threads_test]"
)
{
resetDB
();
resetDB
();
setOptions
(
tru
e
,
false
,
true
);
setOptions
(
fals
e
,
false
,
true
);
initAll
(
false
,
true
);
initAll
(
false
,
true
);
...
@@ -929,14 +929,14 @@ TEST_CASE("ManySimultaneousThreads", "[many_threads_test]") {
...
@@ -929,14 +929,14 @@ TEST_CASE("ManySimultaneousThreads", "[many_threads_test]") {
TEST_CASE
(
"ecdsa API test"
,
"[ecdsa_api_test]"
)
{
TEST_CASE
(
"ecdsa API test"
,
"[ecdsa_api_test]"
)
{
resetDB
();
resetDB
();
setOptions
(
tru
e
,
false
,
true
);
setOptions
(
fals
e
,
false
,
true
);
initAll
(
false
,
true
);
initAll
(
false
,
true
);
HttpClient
client
(
"http://localhost:1029"
);
HttpClient
client
(
"http://localhost:1029"
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
cerr
<<
"Client inited"
<<
endl
;
//
cerr << "Client inited" << endl;
Json
::
Value
genKey
=
c
.
generateECDSAKey
();
Json
::
Value
genKey
=
c
.
generateECDSAKey
();
cout
<<
genKey
<<
endl
;
cout
<<
genKey
<<
endl
;
...
@@ -977,7 +977,7 @@ TEST_CASE("ecdsa API test", "[ecdsa_api_test]") {
...
@@ -977,7 +977,7 @@ TEST_CASE("ecdsa API test", "[ecdsa_api_test]") {
TEST_CASE
(
"dkg API test"
,
"[dkg_api_test]"
)
{
TEST_CASE
(
"dkg API test"
,
"[dkg_api_test]"
)
{
resetDB
();
resetDB
();
setOptions
(
tru
e
,
false
,
true
);
setOptions
(
fals
e
,
false
,
true
);
initAll
(
false
,
true
);
initAll
(
false
,
true
);
...
@@ -1049,14 +1049,14 @@ TEST_CASE("dkg API test", "[dkg_api_test]") {
...
@@ -1049,14 +1049,14 @@ TEST_CASE("dkg API test", "[dkg_api_test]") {
TEST_CASE
(
"isPolyExists test"
,
"[is_poly_test]"
)
{
TEST_CASE
(
"isPolyExists test"
,
"[is_poly_test]"
)
{
resetDB
();
resetDB
();
setOptions
(
tru
e
,
false
,
true
);
setOptions
(
fals
e
,
false
,
true
);
initAll
(
false
,
true
);
initAll
(
false
,
true
);
HttpClient
client
(
"http://localhost:1029"
);
HttpClient
client
(
"http://localhost:1029"
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
cerr
<<
"Client inited"
<<
endl
;
//
cerr << "Client inited" << endl;
string
polyName
=
"POLY:SCHAIN_ID:1:NODE_ID:1:DKG_ID:1"
;
string
polyName
=
"POLY:SCHAIN_ID:1:NODE_ID:1:DKG_ID:1"
;
Json
::
Value
genPoly
=
c
.
generateDKGPoly
(
polyName
,
2
);
Json
::
Value
genPoly
=
c
.
generateDKGPoly
(
polyName
,
2
);
...
@@ -1075,13 +1075,13 @@ TEST_CASE("isPolyExists test", "[is_poly_test]") {
...
@@ -1075,13 +1075,13 @@ TEST_CASE("isPolyExists test", "[is_poly_test]") {
TEST_CASE
(
"AES_DKG test"
,
"[aes_dkg]"
)
{
TEST_CASE
(
"AES_DKG test"
,
"[aes_dkg]"
)
{
resetDB
();
resetDB
();
setOptions
(
tru
e
,
false
,
true
);
setOptions
(
fals
e
,
false
,
true
);
cerr
<<
"test started"
<<
endl
;
//
cerr << "test started" << endl;
initAll
(
false
,
true
);
initAll
(
false
,
true
);
HttpClient
client
(
"http://localhost:1029"
);
HttpClient
client
(
"http://localhost:1029"
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
cerr
<<
"Client inited"
<<
endl
;
//
cerr << "Client inited" << endl;
int
n
=
2
,
t
=
2
;
int
n
=
2
,
t
=
2
;
Json
::
Value
EthKeys
[
n
];
Json
::
Value
EthKeys
[
n
];
...
@@ -1097,7 +1097,6 @@ TEST_CASE("AES_DKG test", "[aes_dkg]") {
...
@@ -1097,7 +1097,6 @@ TEST_CASE("AES_DKG test", "[aes_dkg]") {
int
dkg_id
=
rand_gen
();
int
dkg_id
=
rand_gen
();
for
(
uint8_t
i
=
0
;
i
<
n
;
i
++
)
{
for
(
uint8_t
i
=
0
;
i
<
n
;
i
++
)
{
EthKeys
[
i
]
=
c
.
generateECDSAKey
();
EthKeys
[
i
]
=
c
.
generateECDSAKey
();
cerr
<<
"after gen key"
<<
endl
;
string
polyName
=
string
polyName
=
"POLY:SCHAIN_ID:"
+
to_string
(
schain_id
)
+
":NODE_ID:"
+
to_string
(
i
)
+
":DKG_ID:"
+
to_string
(
dkg_id
);
"POLY:SCHAIN_ID:"
+
to_string
(
schain_id
)
+
":NODE_ID:"
+
to_string
(
i
)
+
":DKG_ID:"
+
to_string
(
dkg_id
);
REQUIRE
(
EthKeys
[
i
][
"status"
]
==
0
);
REQUIRE
(
EthKeys
[
i
][
"status"
]
==
0
);
...
@@ -1132,14 +1131,14 @@ TEST_CASE("AES_DKG test", "[aes_dkg]") {
...
@@ -1132,14 +1131,14 @@ TEST_CASE("AES_DKG test", "[aes_dkg]") {
for
(
int
i
=
0
;
i
<
n
;
i
++
)
for
(
int
i
=
0
;
i
<
n
;
i
++
)
for
(
int
j
=
0
;
j
<
n
;
j
++
)
{
for
(
int
j
=
0
;
j
<
n
;
j
++
)
{
// if ( i != j ){
// if ( i != j ){
cerr
<<
"SecretShare length is "
<<
secretShares
[
i
][
"secretShare"
].
asString
().
length
()
<<
endl
;
//
cerr << "SecretShare length is " << secretShares[i]["secretShare"].asString().length() << endl;
string
secretShare
=
secretShares
[
i
][
"secretShare"
].
asString
().
substr
(
192
*
j
,
192
);
string
secretShare
=
secretShares
[
i
][
"secretShare"
].
asString
().
substr
(
192
*
j
,
192
);
secShares_vect
[
i
]
+=
secretShares
[
j
][
"secretShare"
].
asString
().
substr
(
192
*
i
,
192
);
secShares_vect
[
i
]
+=
secretShares
[
j
][
"secretShare"
].
asString
().
substr
(
192
*
i
,
192
);
Json
::
Value
verif
=
c
.
dkgVerification
(
pubShares
[
i
],
EthKeys
[
j
][
"keyName"
].
asString
(),
secretShare
,
t
,
n
,
j
);
Json
::
Value
verif
=
c
.
dkgVerification
(
pubShares
[
i
],
EthKeys
[
j
][
"keyName"
].
asString
(),
secretShare
,
t
,
n
,
j
);
cout
<<
verif
;
cout
<<
verif
;
bool
res
=
verif
[
"result"
].
asBool
();
bool
res
=
verif
[
"result"
].
asBool
();
k
++
;
k
++
;
cerr
<<
"NOW K IS "
<<
k
<<
" i is "
<<
i
<<
" j is "
<<
j
<<
endl
;
//
cerr << "NOW K IS " << k << " i is " << i << " j is " << j << endl;
REQUIRE
(
res
);
REQUIRE
(
res
);
// }
// }
}
}
...
@@ -1148,8 +1147,8 @@ TEST_CASE("AES_DKG test", "[aes_dkg]") {
...
@@ -1148,8 +1147,8 @@ TEST_CASE("AES_DKG test", "[aes_dkg]") {
Json
::
Value
complaintResponse
=
c
.
complaintResponse
(
poly_names
[
1
],
0
);
Json
::
Value
complaintResponse
=
c
.
complaintResponse
(
poly_names
[
1
],
0
);
cout
<<
complaintResponse
<<
endl
;
cout
<<
complaintResponse
<<
endl
;
REQUIRE
(
complaintResponse
[
"status"
]
==
0
);
REQUIRE
(
complaintResponse
[
"status"
]
==
0
);
cerr
<<
"share * G2 is "
<<
complaintResponse
[
"share*G2"
].
asString
();
//
cerr << "share * G2 is " << complaintResponse["share*G2"].asString();
cerr
<<
"DHKey is "
<<
complaintResponse
[
"dhKey"
].
asString
();
//
cerr << "DHKey is " << complaintResponse["dhKey"].asString();
BLSSigShareSet
sigShareSet
(
t
,
n
);
BLSSigShareSet
sigShareSet
(
t
,
n
);
...
@@ -1172,12 +1171,12 @@ TEST_CASE("AES_DKG test", "[aes_dkg]") {
...
@@ -1172,12 +1171,12 @@ TEST_CASE("AES_DKG test", "[aes_dkg]") {
pubBLSKeys
[
i
]
=
c
.
getBLSPublicKeyShare
(
blsName
);
pubBLSKeys
[
i
]
=
c
.
getBLSPublicKeyShare
(
blsName
);
cout
<<
pubBLSKeys
[
i
]
<<
endl
;
cout
<<
pubBLSKeys
[
i
]
<<
endl
;
REQUIRE
(
pubBLSKeys
[
i
][
"status"
]
==
0
);
REQUIRE
(
pubBLSKeys
[
i
][
"status"
]
==
0
);
cerr
<<
"BLS KEY SHARE NAME IS"
<<
blsName
<<
endl
;
//
cerr << "BLS KEY SHARE NAME IS" << blsName << endl;
string
hash
=
"09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db"
;
string
hash
=
"09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db"
;
BLSSigShares
[
i
]
=
c
.
blsSignMessageHash
(
blsName
,
hash
,
t
,
n
,
i
+
1
);
BLSSigShares
[
i
]
=
c
.
blsSignMessageHash
(
blsName
,
hash
,
t
,
n
,
i
+
1
);
cout
<<
BLSSigShares
[
i
]
<<
endl
;
cout
<<
BLSSigShares
[
i
]
<<
endl
;
REQUIRE
(
BLSSigShares
[
i
][
"status"
]
==
0
);
REQUIRE
(
BLSSigShares
[
i
][
"status"
]
==
0
);
cerr
<<
i
<<
" sig share is created "
<<
endl
;
//
cerr << i << " sig share is created " << endl;
shared_ptr
<
string
>
sig_share_ptr
=
make_shared
<
string
>
(
BLSSigShares
[
i
][
"signatureShare"
].
asString
());
shared_ptr
<
string
>
sig_share_ptr
=
make_shared
<
string
>
(
BLSSigShares
[
i
][
"signatureShare"
].
asString
());
BLSSigShare
sig
(
sig_share_ptr
,
i
+
1
,
t
,
n
);
BLSSigShare
sig
(
sig_share_ptr
,
i
+
1
,
t
,
n
);
sigShareSet
.
addSigShare
(
make_shared
<
BLSSigShare
>
(
sig
));
sigShareSet
.
addSigShare
(
make_shared
<
BLSSigShare
>
(
sig
));
...
@@ -1202,12 +1201,12 @@ TEST_CASE("AES_DKG test", "[aes_dkg]") {
...
@@ -1202,12 +1201,12 @@ TEST_CASE("AES_DKG test", "[aes_dkg]") {
TEST_CASE
(
"bls_sign_api test"
,
"[bls_sign]"
)
{
TEST_CASE
(
"bls_sign_api test"
,
"[bls_sign]"
)
{
resetDB
();
resetDB
();
setOptions
(
tru
e
,
false
,
true
);
setOptions
(
fals
e
,
false
,
true
);
initAll
(
false
,
true
);
initAll
(
false
,
true
);
HttpClient
client
(
"http://localhost:1029"
);
HttpClient
client
(
"http://localhost:1029"
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
cerr
<<
"Client inited"
<<
endl
;
//
cerr << "Client inited" << endl;
string
hash
=
"09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db"
;
string
hash
=
"09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db"
;
string
blsName
=
"BLS_KEY:SCHAIN_ID:323669558:NODE_ID:1:DKG_ID:338183455"
;
string
blsName
=
"BLS_KEY:SCHAIN_ID:323669558:NODE_ID:1:DKG_ID:338183455"
;
int
n
=
4
,
t
=
4
;
int
n
=
4
,
t
=
4
;
...
@@ -1234,7 +1233,7 @@ TEST_CASE("bls_sign_api test", "[bls_sign]") {
...
@@ -1234,7 +1233,7 @@ TEST_CASE("bls_sign_api test", "[bls_sign]") {
TEST_CASE
(
"AES encrypt/decrypt"
,
"[AES-encrypt-decrypt]"
)
{
TEST_CASE
(
"AES encrypt/decrypt"
,
"[AES-encrypt-decrypt]"
)
{
resetDB
();
resetDB
();
setOptions
(
tru
e
,
false
,
true
);
setOptions
(
fals
e
,
false
,
true
);
initAll
(
false
,
true
);
initAll
(
false
,
true
);
...
@@ -1247,14 +1246,14 @@ TEST_CASE("AES encrypt/decrypt", "[AES-encrypt-decrypt]") {
...
@@ -1247,14 +1246,14 @@ TEST_CASE("AES encrypt/decrypt", "[AES-encrypt-decrypt]") {
status
=
encrypt_key_aes
(
eid
,
&
errStatus
,
errMsg
.
data
(),
key
.
c_str
(),
encrypted_key
.
data
(),
&
enc_len
);
status
=
encrypt_key_aes
(
eid
,
&
errStatus
,
errMsg
.
data
(),
key
.
c_str
(),
encrypted_key
.
data
(),
&
enc_len
);
REQUIRE
(
status
==
0
);
REQUIRE
(
status
==
0
);
cerr
<<
"key encrypted with status "
<<
status
<<
" err msg "
<<
errMsg
.
data
()
<<
endl
;
//
cerr << "key encrypted with status " << status << " err msg " << errMsg.data() << endl;
vector
<
char
>
decr_key
(
BUF_LEN
,
0
);
vector
<
char
>
decr_key
(
BUF_LEN
,
0
);
status
=
decrypt_key_aes
(
eid
,
&
errStatus
,
errMsg
.
data
(),
encrypted_key
.
data
(),
enc_len
,
decr_key
.
data
());
status
=
decrypt_key_aes
(
eid
,
&
errStatus
,
errMsg
.
data
(),
encrypted_key
.
data
(),
enc_len
,
decr_key
.
data
());
REQUIRE
(
status
==
0
);
REQUIRE
(
status
==
0
);
cerr
<<
"key encrypted with status "
<<
status
<<
" err msg "
<<
errMsg
.
data
()
<<
endl
;
//
cerr << "key encrypted with status " << status << " err msg " << errMsg.data() << endl;
cerr
<<
"decrypted key is "
<<
decr_key
.
data
()
<<
endl
;
//
cerr << "decrypted key is " << decr_key.data() << endl;
REQUIRE
(
key
.
compare
(
decr_key
.
data
())
==
0
);
REQUIRE
(
key
.
compare
(
decr_key
.
data
())
==
0
);
sgx_destroy_enclave
(
eid
);
sgx_destroy_enclave
(
eid
);
...
...
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