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
f2b8271f
Unverified
Commit
f2b8271f
authored
Feb 15, 2020
by
kladko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SKALE-2167 Memory warnings
parent
5229616e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
917 additions
and
948 deletions
+917
-948
BLSCrypto.cpp
BLSCrypto.cpp
+9
-10
BLSCrypto.h
BLSCrypto.h
+2
-2
SGXWalletServer.cpp
SGXWalletServer.cpp
+8
-2
testw.cpp
testw.cpp
+898
-934
No files found.
BLSCrypto.cpp
View file @
f2b8271f
...
@@ -314,22 +314,21 @@ bool bls_sign(const char* _encryptedKeyHex, const char* _hashHex, size_t _t, siz
...
@@ -314,22 +314,21 @@ bool bls_sign(const char* _encryptedKeyHex, const char* _hashHex, size_t _t, siz
}
}
}
}
char
*
encryptBLSKeyShare2Hex
(
int
*
errStatus
,
char
*
err_string
,
const
char
*
_key
)
{
char
*
encryptBLSKeyShare2Hex
(
int
*
errStatus
,
char
*
err_string
,
const
char
*
_key
)
{
char
*
keyArray
=
(
char
*
)
calloc
(
BUF_LEN
,
1
);
auto
keyArray
=
make_shared
<
vector
<
char
>>
(
BUF_LEN
,
0
);
uint8_t
*
encryptedKey
=
(
uint8_t
*
)
calloc
(
BUF_LEN
,
1
);
auto
encryptedKey
=
make_shared
<
vector
<
uint8_t
>>
(
BUF_LEN
,
0
);
char
*
errMsg
=
(
char
*
)
calloc
(
BUF_LEN
,
1
);
auto
errMsg
=
make_shared
<
vector
<
char
>>
(
BUF_LEN
,
0
);
strncpy
((
char
*
)
keyArray
,
(
char
*
)
_key
,
BUF_LEN
);
strncpy
(
keyArray
->
data
(),
_key
,
BUF_LEN
);
*
errStatus
=
-
1
;
*
errStatus
=
-
1
;
unsigned
int
encryptedLen
=
0
;
unsigned
int
encryptedLen
=
0
;
//status = encrypt_key(eid, errStatus, errMsg, keyArray, encryptedKey, &encryptedLen);
//status = encrypt_key(eid, errStatus, errMsg, keyArray, encryptedKey, &encryptedLen);
status
=
encrypt_key_aes
(
eid
,
errStatus
,
errMsg
,
keyArray
,
encryptedKey
,
&
encryptedLen
);
status
=
encrypt_key_aes
(
eid
,
errStatus
,
errMsg
->
data
(),
keyArray
->
data
(),
encryptedKey
->
data
()
,
&
encryptedLen
);
if
(
DEBUG_PRINT
)
{
if
(
DEBUG_PRINT
)
{
spdlog
::
info
(
"errStatus is {}"
,
*
errStatus
);
spdlog
::
info
(
"errStatus is {}"
,
*
errStatus
);
spdlog
::
info
(
" errMsg is "
,
errMsg
);
spdlog
::
info
(
" errMsg is "
,
errMsg
->
data
()
);
}
}
if
(
status
!=
SGX_SUCCESS
)
{
if
(
status
!=
SGX_SUCCESS
)
{
...
@@ -339,13 +338,13 @@ char *encryptBLSKeyShare2Hex(int *errStatus, char *err_string, const char *_key)
...
@@ -339,13 +338,13 @@ char *encryptBLSKeyShare2Hex(int *errStatus, char *err_string, const char *_key)
}
}
if
(
*
errStatus
!=
0
)
{
if
(
*
errStatus
!=
0
)
{
throw
RPCException
(
-
666
,
errMsg
);
throw
RPCException
(
-
666
,
errMsg
->
data
()
);
}
}
char
*
result
=
(
char
*
)
calloc
(
2
*
BUF_LEN
,
1
);
char
*
result
=
(
char
*
)
calloc
(
2
*
BUF_LEN
,
1
);
carray2Hex
(
encryptedKey
,
encryptedLen
,
result
);
carray2Hex
(
encryptedKey
->
data
()
,
encryptedLen
,
result
);
return
result
;
return
result
;
}
}
...
...
BLSCrypto.h
View file @
f2b8271f
...
@@ -49,8 +49,8 @@ EXTERNC bool hex2carray2(const char * _hex, uint64_t *_bin_len,
...
@@ -49,8 +49,8 @@ EXTERNC bool hex2carray2(const char * _hex, uint64_t *_bin_len,
EXTERNC
char
*
encryptBLSKeyShare2Hex
(
int
*
errStatus
,
char
*
err_string
,
const
char
*
_key
);
char
*
encryptBLSKeyShare2Hex
(
int
*
errStatus
,
char
*
err_string
,
const
char
*
_key
);
EXTERNC
char
*
decryptBLSKeyShareFromHex
(
int
*
errStatus
,
char
*
errMsg
,
const
char
*
_encryptedKey
);
char
*
decryptBLSKeyShareFromHex
(
int
*
errStatus
,
char
*
errMsg
,
const
char
*
_encryptedKey
);
#endif //SGXWALLET_BLSCRYPTO_H
#endif //SGXWALLET_BLSCRYPTO_H
SGXWalletServer.cpp
View file @
f2b8271f
...
@@ -152,11 +152,13 @@ importBLSKeyShareImpl(const string &_keyShare, const string &_keyShareName, int
...
@@ -152,11 +152,13 @@ importBLSKeyShareImpl(const string &_keyShare, const string &_keyShareName, int
result
[
"errorMessage"
]
=
""
;
result
[
"errorMessage"
]
=
""
;
result
[
"encryptedKeyShare"
]
=
""
;
result
[
"encryptedKeyShare"
]
=
""
;
char
*
encryptedKeyShareHex
=
nullptr
;
try
{
try
{
// if ( !checkName(_keyShare, "BLS_KEY")){
// if ( !checkName(_keyShare, "BLS_KEY")){
// throw RPCException(INVALID_POLY_NAME, "Invalid BLSKey name");
// throw RPCException(INVALID_POLY_NAME, "Invalid BLSKey name");
// }
// }
char
*
encryptedKeyShareHex
=
encryptBLSKeyShare2Hex
(
&
errStatus
,
errMsg
,
_keyShare
.
c_str
());
encryptedKeyShareHex
=
encryptBLSKeyShare2Hex
(
&
errStatus
,
errMsg
,
_keyShare
.
c_str
());
if
(
encryptedKeyShareHex
==
nullptr
)
{
if
(
encryptedKeyShareHex
==
nullptr
)
{
throw
RPCException
(
UNKNOWN_ERROR
,
""
);
throw
RPCException
(
UNKNOWN_ERROR
,
""
);
...
@@ -166,7 +168,7 @@ importBLSKeyShareImpl(const string &_keyShare, const string &_keyShareName, int
...
@@ -166,7 +168,7 @@ importBLSKeyShareImpl(const string &_keyShare, const string &_keyShareName, int
throw
RPCException
(
errStatus
,
errMsg
);
throw
RPCException
(
errStatus
,
errMsg
);
}
}
result
[
"encryptedKeyShare"
]
=
encryptedKeyShareHex
;
result
[
"encryptedKeyShare"
]
=
string
(
encryptedKeyShareHex
)
;
writeKeyShare
(
_keyShareName
,
encryptedKeyShareHex
,
index
,
n
,
t
);
writeKeyShare
(
_keyShareName
,
encryptedKeyShareHex
,
index
,
n
,
t
);
...
@@ -175,6 +177,10 @@ importBLSKeyShareImpl(const string &_keyShare, const string &_keyShareName, int
...
@@ -175,6 +177,10 @@ importBLSKeyShareImpl(const string &_keyShare, const string &_keyShareName, int
result
[
"errorMessage"
]
=
_e
.
errString
;
result
[
"errorMessage"
]
=
_e
.
errString
;
}
}
if
(
encryptedKeyShareHex
!=
nullptr
)
{
free
(
encryptedKeyShareHex
);
}
return
result
;
return
result
;
}
}
...
...
testw.cpp
View file @
f2b8271f
...
@@ -34,19 +34,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
...
@@ -34,19 +34,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
*/
#include <libff/algebra/fields/fp.hpp>
#include <libff/algebra/fields/fp.hpp>
#include <dkg/dkg.h>
#include <dkg/dkg.h>
#include <jsonrpccpp/server/connectors/httpserver.h>
#include <jsonrpccpp/server/connectors/httpserver.h>
#include <libff/algebra/curves/alt_bn128/alt_bn128_pp.hpp>
#include <libff/algebra/curves/alt_bn128/alt_bn128_pp.hpp>
#include <libff/algebra/exponentiation/exponentiation.hpp>
#include <libff/algebra/exponentiation/exponentiation.hpp>
#include <libff/algebra/fields/fp.hpp>
#include <libff/algebra/fields/fp.hpp>
#include <dkg/dkg.h>
#include <dkg/dkg.h>
#include "sgxwallet_common.h"
#include "sgxwallet_common.h"
#include "create_enclave.h"
#include "create_enclave.h"
#include "secure_enclave_u.h"
#include "secure_enclave_u.h"
...
@@ -54,46 +46,36 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
...
@@ -54,46 +46,36 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <gmp.h>
#include <gmp.h>
#include <sgx_urts.h>
#include <sgx_urts.h>
#include <stdio.h>
#include <stdio.h>
#include "BLSCrypto.h"
#include "BLSCrypto.h"
#include "ServerInit.h"
#include "ServerInit.h"
#include "DKGCrypto.h"
#include "DKGCrypto.h"
#include "RPCException.h"
#include "RPCException.h"
#include "LevelDB.h"
#include "LevelDB.h"
#include "SGXWalletServer.hpp"
#include "SGXWalletServer.hpp"
#include <sgx_tcrypto.h>
#include <sgx_tcrypto.h>
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#include "catch.hpp"
#include "catch.hpp"
#include "stubclient.h"
#include "stubclient.h"
#include "BLSSigShare.h"
#include "BLSSigShare.h"
#include "BLSSigShareSet.h"
#include "BLSSigShareSet.h"
#include "BLSPublicKeyShare.h"
#include "BLSPublicKeyShare.h"
#include "BLSPublicKey.h"
#include "BLSPublicKey.h"
#include "SEKManager.h"
#include "SEKManager.h"
#include <thread>
#include <thread>
#include "common.h"
#include "common.h"
#include "stubclient.h"
#include <jsonrpccpp/client/connectors/httpclient.h>
default_random_engine
rand_gen
((
unsigned
int
)
time
(
0
));
default_random_engine
rand_gen
((
unsigned
int
)
time
(
0
));
string
stringFromFr
(
libff
::
alt_bn128_Fr
&
el
)
{
string
stringFromFr
(
libff
::
alt_bn128_Fr
&
el
)
{
mpz_t
t
;
mpz_t
t
;
mpz_init
(
t
);
mpz_init
(
t
);
el
.
as_bigint
().
to_mpz
(
t
);
el
.
as_bigint
().
to_mpz
(
t
);
char
arr
[
mpz_sizeinbase
(
t
,
10
)
+
2
];
char
arr
[
mpz_sizeinbase
(
t
,
10
)
+
2
];
char
*
tmp
=
mpz_get_str
(
arr
,
10
,
t
);
char
*
tmp
=
mpz_get_str
(
arr
,
10
,
t
);
mpz_clear
(
t
);
mpz_clear
(
t
);
...
@@ -115,25 +97,22 @@ int updated;
...
@@ -115,25 +97,22 @@ int updated;
#define TEST_BLS_KEY_NAME "SCHAIN:17:INDEX:5:KEY:1"
#define TEST_BLS_KEY_NAME "SCHAIN:17:INDEX:5:KEY:1"
void
reset_db
()
{
void
reset_db
()
{
//std::string db_name = SGXDATA_FOLDER + WALLETDB_NAME;
//string db_name = SGXDATA_FOLDER + WALLETDB_NAME;
REQUIRE
(
system
(
"rm -rf "
WALLETDB_NAME
)
==
0
);
REQUIRE
(
system
(
"rm -rf "
WALLETDB_NAME
)
==
0
);
}
}
char
*
encryptTestKey
()
{
char
*
encryptTestKey
()
{
const
char
*
key
=
TEST_BLS_KEY_SHARE
;
const
char
*
key
=
TEST_BLS_KEY_SHARE
;
int
errStatus
=
-
1
;
int
errStatus
=
-
1
;
vector
<
char
>
errMsg
(
BUF_LEN
,
0
);;
char
*
errMsg
=
(
char
*
)
calloc
(
BUF_LEN
,
1
);
char
*
encryptedKeyHex
=
encryptBLSKeyShare2Hex
(
&
errStatus
,
errMsg
.
data
(),
key
);
char
*
encryptedKeyHex
=
encryptBLSKeyShare2Hex
(
&
errStatus
,
errMsg
,
key
);
REQUIRE
(
encryptedKeyHex
!=
nullptr
);
REQUIRE
(
encryptedKeyHex
!=
nullptr
);
REQUIRE
(
errStatus
==
0
);
REQUIRE
(
errStatus
==
0
);
printf
(
"Encrypt key completed with status: %d %s
\n
"
,
errStatus
,
errMsg
);
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
);
...
@@ -142,504 +121,392 @@ char* encryptTestKey() {
...
@@ -142,504 +121,392 @@ char* encryptTestKey() {
TEST_CASE
(
"BLS key encrypt"
,
"[bls-key-encrypt]"
)
{
TEST_CASE
(
"BLS key encrypt"
,
"[bls-key-encrypt]"
)
{
DEBUG_PRINT
=
1
;
DEBUG_PRINT
=
1
;
is_sgx_https
=
0
;
is_sgx_https
=
0
;
init_all
(
false
,
false
,
init_SEK
);
init_all
(
false
,
false
,
init_SEK
);
char
*
key
=
encryptTestKey
();
char
*
key
=
encryptTestKey
();
REQUIRE
(
key
!=
nullptr
);
REQUIRE
(
key
!=
nullptr
);
/*free*/
(
key
);
}
}
TEST_CASE
(
"BLS key encrypt/decrypt"
,
"[bls-key-encrypt-decrypt]"
)
{
TEST_CASE
(
"BLS key encrypt/decrypt"
,
"[bls-key-encrypt-decrypt]"
)
{
{
{
DEBUG_PRINT
=
1
;
DEBUG_PRINT
=
1
;
is_sgx_https
=
0
;
is_sgx_https
=
0
;
init_all
(
false
,
false
,
init_SEK
);
init_all
(
false
,
false
,
init_SEK
);
//init_enclave();
//init_enclave();
int
errStatus
=
-
1
;
int
errStatus
=
-
1
;
char
*
errMsg
=
(
char
*
)
calloc
(
BUF_LEN
,
1
);
vector
<
char
>
errMsg
(
BUF_LEN
,
0
);
char
*
encryptedKey
=
encryptTestKey
();
char
*
encryptedKey
=
encryptTestKey
();
REQUIRE
(
encryptedKey
!=
nullptr
);
REQUIRE
(
encryptedKey
!=
nullptr
);
char
*
plaintextKey
=
decryptBLSKeyShareFromHex
(
&
errStatus
,
errMsg
.
data
(),
encryptedKey
);
char
*
plaintextKey
=
decryptBLSKeyShareFromHex
(
&
errStatus
,
errMsg
,
encryptedKey
);
free
(
encryptedKey
);
REQUIRE
(
errStatus
==
0
);
REQUIRE
(
errStatus
==
0
);
REQUIRE
(
strcmp
(
plaintextKey
,
TEST_BLS_KEY_SHARE
)
==
0
);
REQUIRE
(
strcmp
(
plaintextKey
,
TEST_BLS_KEY_SHARE
)
==
0
);
printf
(
"Decrypt key completed with status: %d %s
\n
"
,
errStatus
,
errMsg
);
printf
(
"Decrypt key completed with status: %d %s
\n
"
,
errStatus
,
errMsg
);
printf
(
"Decrypted key len %d
\n
"
,
(
int
)
strlen
(
plaintextKey
));
printf
(
"Decrypted key len %d
\n
"
,
(
int
)
strlen
(
plaintextKey
));
printf
(
"Decrypted key: %s
\n
"
,
plaintextKey
);
printf
(
"Decrypted key: %s
\n
"
,
plaintextKey
);
sgx_destroy_enclave
(
eid
);
sgx_destroy_enclave
(
eid
);
}
}
}
}
//TEST_CASE("BLS key import", "[bls-key-import]") {
// reset_db();
// init_all(false, false);
//
//
//
// auto result = importBLSKeyShareImpl(TEST_BLS_KEY_SHARE, TEST_BLS_KEY_NAME, 2, 2, 1);
//
// REQUIRE(result["status"] == 0);
//
// REQUIRE(result["encryptedKeyShare"] != "");
//
//
//TEST_CASE("BLS sign test", "[bls-sign]") {
//
// //init_all();
// init_enclave();
//
// char* encryptedKeyHex ="04000200000000000406ffffff02000000000000000000000b000000000000ff0000000000000000813f8390f6228a568e181a4dadb6508e3e66f5247175d65dbd0d8c7fbfa4df45000000f000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000008000000000000000000000000000000000dc044ae0cd79faaf41e8a7abb412790476738a98b5b6ce95fa1a32db5551b0a0d867305f4de558c64fee730a1f62394633c7d4ca65e3a40b7883e89c2801c61918b01c5de8624a52963df6f4de8581bcbdd2f9b69720d4cc764e03a04c7a99314bfdb5d2d55deda2ca40cd691f093fb2ecbae24cdacdd4d5de93189c6dfd6792d7b95bd5e330aec3538e7a85d15793"; //encryptTestKey();
//
// REQUIRE(encryptedKeyHex != nullptr);
//
//
// // const char *hexHash = "001122334455667788" "001122334455667788" "001122334455667788" "001122334455667788";
// const char *hexHash = "3F891FDA3704F0368DAB65FA81EBE616F4AA2A0854995DA4DC0B59D2CADBD64F";
//
// char* hexHashBuf = (char*) calloc(BUF_LEN, 1);
//
// strncpy(hexHashBuf, hexHash, BUF_LEN);
//
// char sig[BUF_LEN];
// auto result = sign(encryptedKeyHex, hexHashBuf, 2, 2, 1, sig);
//
// REQUIRE(result == true);
// printf("Signature is: %s \n", sig );
//
//}
//
//TEST_CASE("Server BLS sign test", "[bls-server-sign]") {
//
// reset_db();
//
// init_all(false, false);
//
//
// auto result = importBLSKeyShareImpl( TEST_BLS_KEY_SHARE, TEST_BLS_KEY_NAME, 2, 2, 1);
//
// REQUIRE(result["status"] == 0);
//
// REQUIRE(result["encryptedKeyShare"] != "");
//
// const char *hexHash = "001122334455667788" "001122334455667788" "001122334455667788" "001122334455667788";
//
// REQUIRE_NOTHROW(result = blsSignMessageHashImpl(TEST_BLS_KEY_NAME, hexHash,2,2,1));
//
// if (result["status"] != 0) {
// printf("Error message: %s", result["errorMessage"].asString().c_str());
// }
//
//
// REQUIRE(result["status"] == 0);
// REQUIRE(result["signatureShare"] != "");
//
// printf("Signature is: %s \n", result["signatureShare"].asString().c_str());
//
//}
//TEST_CASE("KeysDB test", "[keys-db]") {
TEST_CASE
(
"DKG gen test"
,
"[dkg-gen]"
)
{
//
//
//
// reset_db();
// init_all();
//
//
// string key = TEST_BLS_KEY_SHARE;
// string value = TEST_BLS_KEY_SHARE;
//
//
//
// REQUIRE_THROWS(readKeyShare(key));
//
//
// writeKeyShare(key, value, 1, 2, 1);
//
// REQUIRE(readKeyShare(key) != nullptr);
//
//
//// put your test here
//}
//init_all();
init_enclave
();
vector
<
uint8_t
>
encrypted_dkg_secret
(
DKG_MAX_SEALED_LEN
,
0
);
vector
<
char
>
errMsg
(
1024
,
0
);
int
err_status
=
0
;
uint32_t
enc_len
=
0
;
status
=
gen_dkg_secret
(
eid
,
&
err_status
,
errMsg
.
data
(),
encrypted_dkg_secret
.
data
(),
&
enc_len
,
32
);
REQUIRE
(
status
==
SGX_SUCCESS
);
printf
(
"gen_dkg_secret completed with status: %d %s
\n
"
,
err_status
,
errMsg
.
data
());
printf
(
"
\n
Length: %d
\n
"
,
enc_len
);
TEST_CASE
(
"DKG gen test"
,
"[dkg-gen]"
)
{
vector
<
char
>
secret
(
DKG_BUFER_LENGTH
,
0
);
//init_all();
vector
<
char
>
errMsg1
(
1024
,
0
);
init_enclave
();
uint8_t
*
encrypted_dkg_secret
=
(
uint8_t
*
)
calloc
(
DKG_MAX_SEALED_LEN
,
1
);
char
*
errMsg
=
(
char
*
)
calloc
(
1024
,
1
)
;
uint32_t
dec_len
;
int
err_status
=
0
;
status
=
decrypt_dkg_secret
(
eid
,
&
err_status
,
errMsg1
.
data
(),
encrypted_dkg_secret
.
data
(),
uint32_t
enc_len
=
0
;
(
uint8_t
*
)
secret
.
data
(),
&
dec_len
)
;
status
=
gen_dkg_secret
(
eid
,
&
err_status
,
errMsg
,
encrypted_dkg_secret
,
&
enc_len
,
32
);
REQUIRE
(
status
==
SGX_SUCCESS
);
REQUIRE
(
status
==
SGX_SUCCESS
);
printf
(
"gen_dkg_secret completed with status: %d %s
\n
"
,
err_status
,
errMsg
);
printf
(
"
\n
Length: %d
\n
"
,
enc_len
);
char
*
secret
=
(
char
*
)
calloc
(
DKG_BUFER_LENGTH
,
sizeof
(
char
));
printf
(
"
\n
decrypt_dkg_secret completed with status: %d %s
\n
"
,
err_status
,
errMsg1
.
data
());
printf
(
"decrypted secret %s
\n\n
"
,
secret
.
data
());
printf
(
"secret length %d
\n
"
,
strlen
(
secret
.
data
()));
printf
(
"decr length %d
\n
"
,
dec_len
);
char
*
errMsg1
=
(
char
*
)
calloc
(
1024
,
1
);
sgx_destroy_enclave
(
eid
);
}
uint32_t
dec_len
;
status
=
decrypt_dkg_secret
(
eid
,
&
err_status
,
errMsg1
,
encrypted_dkg_secret
,
(
uint8_t
*
)
secret
,
&
dec_len
);
REQUIRE
(
status
==
SGX_SUCCESS
);
printf
(
"
\n
decrypt_dkg_secret completed with status: %d %s
\n
"
,
err_status
,
errMsg1
);
vector
<
libff
::
alt_bn128_Fr
>
SplitStringToFr
(
const
char
*
koefs
,
const
char
symbol
)
{
printf
(
"decrypted secret %s
\n\n
"
,
secret
);
string
str
(
koefs
);
printf
(
"secret length %d
\n
"
,
strlen
(
secret
));
string
delim
;
printf
(
"decr length %d
\n
"
,
dec_len
);
delim
.
push_back
(
symbol
);
vector
<
libff
::
alt_bn128_Fr
>
tokens
;
size_t
prev
=
0
,
pos
=
0
;
do
{
pos
=
str
.
find
(
delim
,
prev
);
if
(
pos
==
string
::
npos
)
pos
=
str
.
length
();
string
token
=
str
.
substr
(
prev
,
pos
-
prev
);
if
(
!
token
.
empty
())
{
libff
::
alt_bn128_Fr
koef
(
token
.
c_str
());
tokens
.
push_back
(
koef
);
}
prev
=
pos
+
delim
.
length
();
}
while
(
pos
<
str
.
length
()
&&
prev
<
str
.
length
());
return
tokens
;
}
free
(
errMsg
);
vector
<
string
>
SplitStringTest
(
const
char
*
koefs
,
const
char
symbol
)
{
free
(
errMsg1
);
libff
::
init_alt_bn128_params
();
free
(
encrypted_dkg_secret
);
string
str
(
koefs
);
free
(
secret
);
string
delim
;
delim
.
push_back
(
symbol
);
vector
<
string
>
G2_strings
;
size_t
prev
=
0
,
pos
=
0
;
do
{
pos
=
str
.
find
(
delim
,
prev
);
if
(
pos
==
string
::
npos
)
pos
=
str
.
length
();
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
());
return
G2_strings
;
}
sgx_destroy_enclave
(
eid
);
libff
::
alt_bn128_G2
VectStringToG2
(
const
vector
<
string
>
&
G2_str_vect
)
{
libff
::
init_alt_bn128_params
();
libff
::
alt_bn128_G2
koef
=
libff
::
alt_bn128_G2
::
zero
();
koef
.
X
.
c0
=
libff
::
alt_bn128_Fq
(
G2_str_vect
.
at
(
0
).
c_str
());
koef
.
X
.
c1
=
libff
::
alt_bn128_Fq
(
G2_str_vect
.
at
(
1
).
c_str
());
koef
.
Y
.
c0
=
libff
::
alt_bn128_Fq
(
G2_str_vect
.
at
(
2
).
c_str
());
koef
.
Y
.
c1
=
libff
::
alt_bn128_Fq
(
G2_str_vect
.
at
(
3
).
c_str
());
koef
.
Z
.
c0
=
libff
::
alt_bn128_Fq
::
one
();
koef
.
Z
.
c1
=
libff
::
alt_bn128_Fq
::
zero
();
return
koef
;
}
}
vector
<
libff
::
alt_bn128_Fr
>
SplitStringToFr
(
const
char
*
koefs
,
const
char
symbol
){
TEST_CASE
(
"DKG public shares test"
,
"[dkg-pub_shares]"
)
{
string
str
(
koefs
);
string
delim
;
delim
.
push_back
(
symbol
);
vector
<
libff
::
alt_bn128_Fr
>
tokens
;
size_t
prev
=
0
,
pos
=
0
;
do
{
pos
=
str
.
find
(
delim
,
prev
);
if
(
pos
==
string
::
npos
)
pos
=
str
.
length
();
string
token
=
str
.
substr
(
prev
,
pos
-
prev
);
if
(
!
token
.
empty
())
{
libff
::
alt_bn128_Fr
koef
(
token
.
c_str
());
tokens
.
push_back
(
koef
);
}
prev
=
pos
+
delim
.
length
();
}
while
(
pos
<
str
.
length
()
&&
prev
<
str
.
length
());
return
tokens
;
//init_all();
}
libff
::
init_alt_bn128_params
();
init_enclave
();
vector
<
uint8_t
>
encrypted_dkg_secret
(
DKG_MAX_SEALED_LEN
,
0
);
vector
<
char
>
errMsg
(
1024
,
0
);
int
err_status
=
0
;
uint32_t
enc_len
=
0
;
unsigned
t
=
32
,
n
=
32
;
status
=
gen_dkg_secret
(
eid
,
&
err_status
,
errMsg
.
data
(),
encrypted_dkg_secret
.
data
(),
&
enc_len
,
n
);
REQUIRE
(
status
==
SGX_SUCCESS
);
//printf("gen_dkg_public completed with status: %d %s \n", err_status, errMsg);
vector
<
char
>
errMsg1
(
1024
,
0
);
vector
<
string
>
SplitStringTest
(
const
char
*
koefs
,
const
char
symbol
){
char
colon
=
':'
;
libff
::
init_alt_bn128_params
();
vector
<
char
>
public_shares
(
10000
,
0
);
string
str
(
koefs
);
string
delim
;
status
=
get_public_shares
(
eid
,
&
err_status
,
errMsg1
.
data
(),
delim
.
push_back
(
symbol
);
encrypted_dkg_secret
.
data
(),
enc_len
,
public_shares
.
data
(),
t
,
n
);
vector
<
string
>
G2_strings
;
REQUIRE
(
status
==
SGX_SUCCESS
);
size_t
prev
=
0
,
pos
=
0
;
printf
(
"
\n
get_public_shares status: %d error %s
\n\n
"
,
err_status
,
errMsg1
.
data
());
do
printf
(
" LEN: %d
\n
"
,
strlen
(
public_shares
.
data
()));
{
printf
(
" result: %s
\n
"
,
public_shares
.
data
());
pos
=
str
.
find
(
delim
,
prev
);
if
(
pos
==
string
::
npos
)
pos
=
str
.
length
();
vector
<
string
>
G2_strings
=
SplitString
(
public_shares
.
data
(),
','
);
string
token
=
str
.
substr
(
prev
,
pos
-
prev
);
vector
<
libff
::
alt_bn128_G2
>
pub_shares_G2
;
if
(
!
token
.
empty
())
{
for
(
int
i
=
0
;
i
<
G2_strings
.
size
();
i
++
)
{
string
koef
(
token
.
c_str
());
vector
<
string
>
koef_str
=
SplitString
(
G2_strings
.
at
(
i
).
c_str
(),
':'
);
G2_strings
.
push_back
(
koef
);
libff
::
alt_bn128_G2
el
=
VectStringToG2
(
koef_str
);
//cerr << "pub_share G2 " << i+1 << " : " << endl;
//el.print_coordinates();
pub_shares_G2
.
push_back
(
VectStringToG2
(
koef_str
));
}
}
prev
=
pos
+
delim
.
length
();
}
while
(
pos
<
str
.
length
()
&&
prev
<
str
.
length
());
return
G2_strings
;
vector
<
char
>
secret
(
DKG_MAX_SEALED_LEN
,
0
);
}
status
=
decrypt_dkg_secret
(
eid
,
&
err_status
,
errMsg1
.
data
(),
encrypted_dkg_secret
.
data
(),
(
uint8_t
*
)
secret
.
data
(),
&
enc_len
);
REQUIRE
(
status
==
SGX_SUCCESS
);
printf
(
"
\n
decrypt_dkg_secret completed with status: %d %s
\n
"
,
err_status
,
errMsg1
.
data
());
signatures
::
Dkg
dkg_obj
(
t
,
n
);
vector
<
libff
::
alt_bn128_Fr
>
poly
=
SplitStringToFr
(
secret
.
data
(),
colon
);
vector
<
libff
::
alt_bn128_G2
>
pub_shares_dkg
=
dkg_obj
.
VerificationVector
(
poly
);
printf
(
"calculated public shares (X.c0):
\n
"
);
for
(
uint32_t
i
=
0
;
i
<
pub_shares_dkg
.
size
();
i
++
)
{
libff
::
alt_bn128_G2
el
=
pub_shares_dkg
.
at
(
i
);
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
);
char
arr
[
mpz_sizeinbase
(
x_c0
,
10
)
+
2
];
char
*
share_str
=
mpz_get_str
(
arr
,
10
,
x_c0
);
printf
(
" %s
\n
"
,
share_str
);
mpz_clear
(
x_c0
);
}
libff
::
alt_bn128_G2
VectStringToG2
(
const
vector
<
string
>&
G2_str_vect
){
bool
res
=
(
pub_shares_G2
==
pub_shares_dkg
);
libff
::
init_alt_bn128_params
();
REQUIRE
(
res
==
true
);
libff
::
alt_bn128_G2
koef
=
libff
::
alt_bn128_G2
::
zero
();
koef
.
X
.
c0
=
libff
::
alt_bn128_Fq
(
G2_str_vect
.
at
(
0
).
c_str
());
koef
.
X
.
c1
=
libff
::
alt_bn128_Fq
(
G2_str_vect
.
at
(
1
).
c_str
());
koef
.
Y
.
c0
=
libff
::
alt_bn128_Fq
(
G2_str_vect
.
at
(
2
).
c_str
());
koef
.
Y
.
c1
=
libff
::
alt_bn128_Fq
(
G2_str_vect
.
at
(
3
).
c_str
());
koef
.
Z
.
c0
=
libff
::
alt_bn128_Fq
::
one
();
koef
.
Z
.
c1
=
libff
::
alt_bn128_Fq
::
zero
();
return
koef
;
}
TEST_CASE
(
"DKG public shares test"
,
"[dkg-pub_shares]"
)
{
sgx_destroy_enclave
(
eid
);
//init_all();
libff
::
init_alt_bn128_params
();
init_enclave
();
uint8_t
*
encrypted_dkg_secret
=
(
uint8_t
*
)
calloc
(
DKG_MAX_SEALED_LEN
,
1
);
char
*
errMsg
=
(
char
*
)
calloc
(
1024
,
1
);
int
err_status
=
0
;
uint32_t
enc_len
=
0
;
unsigned
t
=
32
,
n
=
32
;
status
=
gen_dkg_secret
(
eid
,
&
err_status
,
errMsg
,
encrypted_dkg_secret
,
&
enc_len
,
n
);
REQUIRE
(
status
==
SGX_SUCCESS
);
//printf("gen_dkg_public completed with status: %d %s \n", err_status, errMsg);
char
*
errMsg1
=
(
char
*
)
calloc
(
1024
,
1
);
char
colon
=
':'
;
char
*
public_shares
=
(
char
*
)
calloc
(
10000
,
1
);
status
=
get_public_shares
(
eid
,
&
err_status
,
errMsg1
,
encrypted_dkg_secret
,
enc_len
,
public_shares
,
t
,
n
);
REQUIRE
(
status
==
SGX_SUCCESS
);
printf
(
"
\n
get_public_shares status: %d error %s
\n\n
"
,
err_status
,
errMsg1
);
printf
(
" LEN: %d
\n
"
,
strlen
(
public_shares
));
printf
(
" result: %s
\n
"
,
public_shares
);
vector
<
string
>
G2_strings
=
SplitString
(
public_shares
,
','
);
vector
<
libff
::
alt_bn128_G2
>
pub_shares_G2
;
for
(
int
i
=
0
;
i
<
G2_strings
.
size
();
i
++
){
vector
<
string
>
koef_str
=
SplitString
(
G2_strings
.
at
(
i
).
c_str
(),
':'
);
libff
::
alt_bn128_G2
el
=
VectStringToG2
(
koef_str
);
//cerr << "pub_share G2 " << i+1 << " : " << endl;
//el.print_coordinates();
pub_shares_G2
.
push_back
(
VectStringToG2
(
koef_str
));
}
char
*
secret
=
(
char
*
)
calloc
(
DKG_MAX_SEALED_LEN
,
sizeof
(
char
));
status
=
decrypt_dkg_secret
(
eid
,
&
err_status
,
errMsg1
,
encrypted_dkg_secret
,
(
uint8_t
*
)
secret
,
&
enc_len
);
REQUIRE
(
status
==
SGX_SUCCESS
);
printf
(
"
\n
decrypt_dkg_secret completed with status: %d %s
\n
"
,
err_status
,
errMsg1
);
signatures
::
Dkg
dkg_obj
(
t
,
n
);
vector
<
libff
::
alt_bn128_Fr
>
poly
=
SplitStringToFr
((
char
*
)
secret
,
colon
);
vector
<
libff
::
alt_bn128_G2
>
pub_shares_dkg
=
dkg_obj
.
VerificationVector
(
poly
);
printf
(
"calculated public shares (X.c0):
\n
"
);
for
(
int
i
=
0
;
i
<
pub_shares_dkg
.
size
();
i
++
){
libff
::
alt_bn128_G2
el
=
pub_shares_dkg
.
at
(
i
);
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
);
char
arr
[
mpz_sizeinbase
(
x_c0
,
10
)
+
2
];
char
*
share_str
=
mpz_get_str
(
arr
,
10
,
x_c0
);
printf
(
" %s
\n
"
,
share_str
);
mpz_clear
(
x_c0
);
}
bool
res
=
(
pub_shares_G2
==
pub_shares_dkg
);
REQUIRE
(
res
==
true
);
free
(
errMsg
);
free
(
errMsg1
);
free
(
encrypted_dkg_secret
);
free
(
public_shares
);
sgx_destroy_enclave
(
eid
);
}
}
TEST_CASE
(
"DKG encrypted secret shares test"
,
"[dkg-encr_sshares]"
)
{
TEST_CASE
(
"DKG encrypted secret shares test"
,
"[dkg-encr_sshares]"
)
{
// init_all();
// init_all();
init_enclave
();
init_enclave
();
uint8_t
*
encrypted_key
=
(
uint8_t
*
)
calloc
(
BUF_LEN
,
1
);
char
*
errMsg
=
(
char
*
)
calloc
(
1024
,
1
);
vector
<
char
>
errMsg
(
1024
,
1
);
char
*
result
=
(
char
*
)
calloc
(
130
,
1
);
vector
<
char
>
result
(
130
,
1
);
int
err_status
=
0
;
int
err_status
=
0
;
uint32_t
enc_len
=
0
;
uint32_t
enc_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
);
REQUIRE
(
status
==
SGX_SUCCESS
);
cerr
<<
" poly generated"
<<
endl
;
uint8_t
*
encrypted_dkg_secret
=
(
uint8_t
*
)
calloc
(
DKG_MAX_SEALED_LEN
,
1
);
status
=
set_encrypted_dkg_poly
(
eid
,
&
err_status
,
errMsg
.
data
(),
encrypted_dkg_secret
.
data
());
REQUIRE
(
status
==
SGX_SUCCESS
);
cerr
<<
" poly set"
<<
endl
;
vector
<
uint8_t
>
encrPRDHKey
(
1024
,
0
);
status
=
gen_dkg_secret
(
eid
,
&
err_status
,
errMsg
,
encrypted_dkg_secret
,
&
enc_len
,
2
);
string
pub_keyB
=
"c0152c48bf640449236036075d65898fded1e242c00acb45519ad5f788ea7cbf9a5df1559e7fc87932eee5478b1b9023de19df654395574a690843988c3ff475"
;
REQUIRE
(
status
==
SGX_SUCCESS
);
cerr
<<
" poly generated"
<<
endl
;
status
=
set_encrypted_dkg_poly
(
eid
,
&
err_status
,
errMsg
,
encrypted_dkg_secret
);
vector
<
char
>
s_shareG2
(
320
,
0
);
REQUIRE
(
status
==
SGX_SUCCESS
);
status
=
get_encr_sshare
(
eid
,
&
err_status
,
errMsg
.
data
(),
encrPRDHKey
.
data
(),
&
enc_len
,
result
.
data
(),
s_shareG2
.
data
(),
cerr
<<
" poly set"
<<
endl
;
(
char
*
)
pub_keyB
.
data
(),
2
,
2
,
1
)
;
uint8_t
*
encr_pr_DHkey
=
(
uint8_t
*
)
calloc
(
1024
,
1
);
REQUIRE
(
status
==
SGX_SUCCESS
);
char
*
pub_key_x
=
(
char
*
)
calloc
(
1024
,
1
);
printf
(
" get_encr_sshare completed with status: %d %s
\n
"
,
err_status
,
errMsg
.
data
());
char
*
pub_key_y
=
(
char
*
)
calloc
(
1024
,
1
);
char
*
pub_keyB
=
"c0152c48bf640449236036075d65898fded1e242c00acb45519ad5f788ea7cbf9a5df1559e7fc87932eee5478b1b9023de19df654395574a690843988c3ff475"
;
cerr
<<
"secret share is "
<<
result
.
data
()
<<
endl
;
char
s_shareG2
[
320
];
status
=
get_encr_sshare
(
eid
,
&
err_status
,
errMsg
,
encr_pr_DHkey
,
&
enc_len
,
result
,
s_shareG2
,
pub_keyB
,
2
,
2
,
1
);
REQUIRE
(
status
==
SGX_SUCCESS
);
printf
(
" get_encr_sshare completed with status: %d %s
\n
"
,
err_status
,
errMsg
);
cerr
<<
"secret share is "
<<
result
<<
endl
;
sgx_destroy_enclave
(
eid
);
sgx_destroy_enclave
(
eid
);
}
}
TEST_CASE
(
"DKG verification test"
,
"[dkg-verify]"
)
{
TEST_CASE
(
"DKG verification test"
,
"[dkg-verify]"
)
{
// init_all();
init_enclave
();
uint8_t
*
encrypted_key
=
(
uint8_t
*
)
calloc
(
BUF_LEN
,
1
);
char
*
errMsg
=
(
char
*
)
calloc
(
1024
,
1
);
// init_all(
);
char
*
result
=
(
char
*
)
calloc
(
130
,
1
);
init_enclave
(
);
int
err_status
=
0
;
vector
<
char
>
errMsg
(
1024
,
0
)
;
uint32_t
enc_len
=
0
;
vector
<
char
>
result
(
130
,
0
)
;
int
err_status
=
0
;
uint32_t
enc_len
=
0
;
uint8_t
*
encrypted_dkg_secret
=
(
uint8_t
*
)
calloc
(
DKG_MAX_SEALED_LEN
,
1
);
vector
<
uint8_t
>
encrypted_dkg_secret
(
DKG_MAX_SEALED_LEN
,
1
);
status
=
gen_dkg_secret
(
eid
,
&
err_status
,
errMsg
.
data
(),
encrypted_dkg_secret
.
data
(),
&
enc_len
,
2
);
REQUIRE
(
status
==
SGX_SUCCESS
);
cerr
<<
" poly generated"
<<
endl
;
status
=
gen_dkg_secret
(
eid
,
&
err_status
,
errMsg
,
encrypted_dkg_secret
,
&
enc_len
,
2
);
status
=
set_encrypted_dkg_poly
(
eid
,
&
err_status
,
errMsg
.
data
(),
encrypted_dkg_secret
.
data
()
);
REQUIRE
(
status
==
SGX_SUCCESS
);
REQUIRE
(
status
==
SGX_SUCCESS
);
cerr
<<
" poly generated
"
<<
endl
;
cerr
<<
" poly set
"
<<
endl
;
status
=
set_encrypted_dkg_poly
(
eid
,
&
err_status
,
errMsg
,
encrypted_dkg_secret
);
vector
<
uint8_t
>
encrPrDHKey
(
1024
,
0
);
REQUIRE
(
status
==
SGX_SUCCESS
);
cerr
<<
" poly set"
<<
endl
;
uint8_t
*
encr_pr_DHkey
=
(
uint8_t
*
)
calloc
(
1024
,
1
);
string
pub_keyB
=
"c0152c48bf640449236036075d65898fded1e242c00acb45519ad5f788ea7cbf9a5df1559e7fc87932eee5478b1b9023de19df654395574a690843988c3ff475"
;
char
*
pub_key_x
=
(
char
*
)
calloc
(
1024
,
1
);
char
*
pub_key_y
=
(
char
*
)
calloc
(
1024
,
1
);
char
*
pub_keyB
=
"c0152c48bf640449236036075d65898fded1e242c00acb45519ad5f788ea7cbf9a5df1559e7fc87932eee5478b1b9023de19df654395574a690843988c3ff475"
;
vector
<
char
>
s_shareG2
(
320
,
0
)
;
char
s_shareG2
[
320
];
status
=
get_encr_sshare
(
eid
,
&
err_status
,
errMsg
.
data
(),
encrPrDHKey
.
data
(),
&
enc_len
,
result
.
data
(),
s_shareG2
.
data
(),
status
=
get_encr_sshare
(
eid
,
&
err_status
,
errMsg
,
encr_pr_DHkey
,
&
enc_len
,
result
,
s_shareG2
,
(
char
*
)
pub_keyB
.
data
(),
2
,
2
,
1
);
pub_keyB
,
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
);
cerr
<<
"secret share is "
<<
result
<<
endl
;
cerr
<<
"secret share is "
<<
result
.
data
()
<<
endl
;
sgx_destroy_enclave
(
eid
);
sgx_destroy_enclave
(
eid
);
}
}
TEST_CASE
(
"ECDSA keygen and signature test"
,
"[ecdsa_test]"
)
{
TEST_CASE
(
"ECDSA keygen and signature test"
,
"[ecdsa_test]"
)
{
init_enclave
();
init_enclave
();
char
*
errMsg
=
(
char
*
)
calloc
(
1024
,
1
);
vector
<
char
>
errMsg
(
1024
,
0
);
int
err_status
=
0
;
int
err_status
=
0
;
uint8_t
*
encr_pr_key
=
(
uint8_t
*
)
calloc
(
1024
,
1
);
vector
<
uint8_t
>
encr_pr_key
(
1024
,
0
);
vector
<
char
>
pub_key_x
(
1024
,
0
);
char
*
pub_key_x
=
(
char
*
)
calloc
(
1024
,
1
);
vector
<
char
>
pub_key_y
(
1024
,
0
);
char
*
pub_key_y
=
(
char
*
)
calloc
(
1024
,
1
);
uint32_t
enc_len
=
0
;
uint32_t
enc_len
=
0
;
//printf("before %p\n", pub_key_x);
//printf("before %p\n", pub_key_x);
status
=
generate_ecdsa_key
(
eid
,
&
err_status
,
errMsg
,
encr_pr_key
,
&
enc_len
,
pub_key_x
,
pub_key_y
);
status
=
generate_ecdsa_key
(
eid
,
&
err_status
,
errMsg
.
data
(),
encr_pr_key
.
data
(),
&
enc_len
,
pub_key_x
.
data
(),
printf
(
"
\n
errMsg %s
\n
"
,
errMsg
);
pub_key_y
.
data
());
REQUIRE
(
status
==
SGX_SUCCESS
);
printf
(
"
\n
errMsg %s
\n
"
,
errMsg
.
data
());
REQUIRE
(
status
==
SGX_SUCCESS
);
printf
(
"
\n
was pub_key_x %s:
\n
"
,
pub_key_x
);
printf
(
"
\n
was pub_key_y %s:
\n
"
,
pub_key_y
);
printf
(
"
\n
was pub_key_x %s:
\n
"
,
pub_key_x
.
data
());
/*printf("\nencr priv_key : \n");
printf
(
"
\n
was pub_key_y %s:
\n
"
,
pub_key_y
.
data
());
for ( int i = 0; i < 1024 ; i++)
/*printf("\nencr priv_key : \n");
printf("%u ", encr_pr_key[i]);*/
for ( int i = 0; i < 1024 ; i++)
printf("%u ", encr_pr_key[i]);*/
char
*
hex
=
"3F891FDA3704F0368DAB65FA81EBE616F4AA2A0854995DA4DC0B59D2CADBD64F"
;
// char* hex = "0x09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db";
string
hex
=
"3F891FDA3704F0368DAB65FA81EBE616F4AA2A0854995DA4DC0B59D2CADBD64F"
;
printf
(
"hash length %d "
,
strlen
(
hex
));
// char* hex = "0x09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db";
char
*
signature_r
=
(
char
*
)
calloc
(
1024
,
1
);
printf
(
"hash length %d "
,
hex
.
size
());
char
*
signature_s
=
(
char
*
)
calloc
(
1024
,
1
);
vector
<
char
>
signature_r
(
1024
,
0
);
uint8_t
signature_v
=
0
;
vector
<
char
>
signature_s
(
1024
,
0
);
uint8_t
signature_v
=
0
;
status
=
ecdsa_sign1
(
eid
,
&
err_status
,
errMsg
,
encr_pr_key
,
enc_len
,
(
unsigned
char
*
)
hex
,
signature_r
,
signature_s
,
&
signature_v
,
16
);
REQUIRE
(
status
==
SGX_SUCCESS
);
status
=
ecdsa_sign1
(
eid
,
&
err_status
,
errMsg
.
data
(),
encr_pr_key
.
data
(),
enc_len
,
(
unsigned
char
*
)
hex
.
data
(),
printf
(
"
\n
signature r : %s "
,
signature_r
);
signature_r
.
data
(),
printf
(
"
\n
signature s: %s "
,
signature_s
);
signature_s
.
data
(),
&
signature_v
,
16
);
printf
(
"
\n
signature v: %u "
,
signature_v
);
REQUIRE
(
status
==
SGX_SUCCESS
);
printf
(
"
\n
%s
\n
"
,
errMsg
);
printf
(
"
\n
signature r : %s "
,
signature_r
.
data
());
printf
(
"
\n
signature s: %s "
,
signature_s
.
data
());
free
(
errMsg
);
printf
(
"
\n
signature v: %u "
,
signature_v
);
sgx_destroy_enclave
(
eid
);
printf
(
"
\n
%s
\n
"
,
errMsg
.
data
());
printf
(
"the end of ecdsa test
\n
"
);
sgx_destroy_enclave
(
eid
);
printf
(
"the end of ecdsa test
\n
"
);
}
}
TEST_CASE
(
"Test test"
,
"[test_test]"
)
{
TEST_CASE
(
"Test test"
,
"[test_test]"
)
{
init_enclave
();
init_enclave
();
char
*
errMsg
=
(
char
*
)
calloc
(
1024
,
1
);
int
err_status
=
0
;
uint8_t
*
encr_pr_key
=
(
uint8_t
*
)
calloc
(
1024
,
1
);
char
*
pub_key_x
=
(
char
*
)
calloc
(
1024
,
1
);
vector
<
char
>
errMsg
(
1024
,
0
);
char
*
pub_key_y
=
(
char
*
)
calloc
(
1024
,
1
);
int
err_status
=
0
;
uint32_t
enc_len
=
0
;
vector
<
uint8_t
>
encr_pr_key
(
1024
,
0
);
vector
<
char
>
pub_key_x
(
1024
,
0
);
vector
<
char
>
pub_key_y
(
1024
,
0
);
uint32_t
enc_len
=
0
;
status
=
generate_ecdsa_key
(
eid
,
&
err_status
,
errMsg
,
encr_pr_key
,
&
enc_len
,
pub_key_x
,
pub_key_y
);
status
=
generate_ecdsa_key
(
eid
,
&
err_status
,
errMsg
.
data
(),
encr_pr_key
.
data
(),
&
enc_len
,
pub_key_x
.
data
(),
//printf("\nerrMsg %s\n", errMsg );
pub_key_y
.
data
());
REQUIRE
(
status
==
SGX_SUCCESS
);
//printf("\nerrMsg %s\n", errMsg );
REQUIRE
(
status
==
SGX_SUCCESS
);
//printf("\nwas pub_key_x %s: \n", pub_key_x);
//printf("\nwas pub_key_x %s: \n", pub_key_x);
//printf("\nwas pub_key_y %s: \n", pub_key_y);
//printf("\nwas pub_key_y %s: \n", pub_key_y);
//printf("\nencr priv_key %s: \n");
//printf("\nencr priv_key %s: \n");
//for ( int i = 0; i < 1024 ; i++)
//for ( int i = 0; i < 1024 ; i++)
// printf("%u ", encr_pr_key[i]);
// printf("%u ", encr_pr_key[i]);
//printf( "haha");
sgx_destroy_enclave
(
eid
);
//free(errMsg);
sgx_destroy_enclave
(
eid
);
}
}
TEST_CASE
(
"get public ECDSA key"
,
"[get_pub_ecdsa_key_test]"
)
{
TEST_CASE
(
"get public ECDSA key"
,
"[get_pub_ecdsa_key_test]"
)
{
//init_all();
//init_all();
init_enclave
();
init_enclave
();
char
*
errMsg
=
(
char
*
)
calloc
(
1024
,
1
);
int
err_status
=
0
;
int
err_status
=
0
;
vector
<
char
>
errMsg
(
1024
,
0
);
uint8_t
*
encr_pr_key
=
(
uint8_t
*
)
calloc
(
1024
,
1
);
vector
<
uint8_t
>
encr_pr_key
(
1024
,
0
);
vector
<
char
>
pub_key_x
(
1024
,
0
);
vector
<
char
>
pub_key_y
(
1024
,
0
);
uint32_t
enc_len
=
0
;
char
*
pub_key_x
=
(
char
*
)
calloc
(
1024
,
1
);
//printf("before %p\n", pub_key_x);
char
*
pub_key_y
=
(
char
*
)
calloc
(
1024
,
1
);
uint32_t
enc_len
=
0
;
//printf("before %p\n", pub_key_x);
status
=
generate_ecdsa_key
(
eid
,
&
err_status
,
errMsg
.
data
(),
encr_pr_key
.
data
(),
&
enc_len
,
pub_key_x
.
data
(),
pub_key_y
.
data
());
printf
(
"
\n
errMsg %s
\n
"
,
errMsg
.
data
());
REQUIRE
(
status
==
SGX_SUCCESS
);
status
=
generate_ecdsa_key
(
eid
,
&
err_status
,
errMsg
,
encr_pr_key
,
&
enc_len
,
pub_key_x
,
pub_key_y
);
printf
(
"
\n
was pub_key_x %s length %d:
\n
"
,
pub_key_x
.
data
(),
strlen
(
pub_key_x
.
data
()));
printf
(
"
\n
errMsg %s
\n
"
,
errMsg
);
printf
(
"
\n
was pub_key_y %s length %d:
\n
"
,
pub_key_y
.
data
(),
strlen
(
pub_key_y
.
data
()));
REQUIRE
(
status
==
SGX_SUCCESS
);
printf
(
"
\n
was pub_key_x %s length %d:
\n
"
,
pub_key_x
,
strlen
(
pub_key_x
));
/*printf("\nencr priv_key %s: \n");
printf
(
"
\n
was pub_key_y %s length %d:
\n
"
,
pub_key_y
,
strlen
(
pub_key_y
));
for ( int i = 0; i < 1024 ; i++)
printf("%u ", encr_pr_key[i]);*/
/*printf("\nencr priv_key %s: \n");
vector
<
char
>
got_pub_key_x
(
1024
,
0
);
for ( int i = 0; i < 1024 ; i++)
vector
<
char
>
got_pub_key_y
(
1024
,
0
);
printf("%u ", encr_pr_key[i]);*/
char
*
got_pub_key_x
=
(
char
*
)
calloc
(
1024
,
1
);
status
=
get_public_ecdsa_key
(
eid
,
&
err_status
,
errMsg
.
data
(),
encr_pr_key
.
data
(),
enc_len
,
got_pub_key_x
.
data
(),
char
*
got_pub_key_y
=
(
char
*
)
calloc
(
1024
,
1
);
got_pub_key_y
.
data
());
REQUIRE
(
status
==
SGX_SUCCESS
);
printf
(
"
\n
now pub_key_x %s:
\n
"
,
got_pub_key_x
.
data
());
printf
(
"
\n
now pub_key_y %s:
\n
"
,
got_pub_key_y
.
data
());
printf
(
"
\n
pr key %s
\n
"
,
errMsg
.
data
());
status
=
get_public_ecdsa_key
(
eid
,
&
err_status
,
errMsg
,
encr_pr_key
,
enc_len
,
got_pub_key_x
,
got_pub_key_y
);
REQUIRE
(
status
==
SGX_SUCCESS
);
printf
(
"
\n
now pub_key_x %s:
\n
"
,
got_pub_key_x
);
printf
(
"
\n
now pub_key_y %s:
\n
"
,
got_pub_key_y
);
printf
(
"
\n
pr key %s
\n
"
,
errMsg
);
free
(
errMsg
);
sgx_destroy_enclave
(
eid
);
sgx_destroy_enclave
(
eid
);
}
}
/*TEST_CASE( "verification test", "[verify]" ) {
/*TEST_CASE( "verification test", "[verify]" ) {
...
@@ -656,167 +523,169 @@ TEST_CASE("get public ECDSA key", "[get_pub_ecdsa_key_test]") {
...
@@ -656,167 +523,169 @@ TEST_CASE("get public ECDSA key", "[get_pub_ecdsa_key_test]") {
}*/
}*/
#include "stubclient.h"
#include <jsonrpccpp/client/connectors/httpclient.h>
using
namespace
jsonrpc
;
using
namespace
jsonrpc
;
using
namespace
std
;
using
namespace
std
;
string
ConvertDecToHex
(
string
dec
,
int
numBytes
=
32
){
string
ConvertDecToHex
(
string
dec
,
int
numBytes
=
32
)
{
mpz_t
num
;
mpz_t
num
;
mpz_init
(
num
);
mpz_init
(
num
);
mpz_set_str
(
num
,
dec
.
c_str
(),
10
);
mpz_set_str
(
num
,
dec
.
c_str
(),
10
);
char
tmp
[
mpz_sizeinbase
(
num
,
16
)
+
2
]
;
vector
<
char
>
tmp
(
mpz_sizeinbase
(
num
,
16
)
+
2
,
0
)
;
char
*
hex
=
mpz_get_str
(
tmp
,
16
,
num
);
char
*
hex
=
mpz_get_str
(
tmp
.
data
()
,
16
,
num
);
string
result
=
hex
;
string
result
=
hex
;
int
n_zeroes
=
numBytes
*
2
-
result
.
length
();
int
n_zeroes
=
numBytes
*
2
-
result
.
length
();
result
.
insert
(
0
,
n_zeroes
,
'0'
);
result
.
insert
(
0
,
n_zeroes
,
'0'
);
return
result
;
return
result
;
}
}
TEST_CASE
(
"BLS_DKG test"
,
"[bls_dkg]"
)
{
TEST_CASE
(
"BLS_DKG test"
,
"[bls_dkg]"
)
{
is_sgx_https
=
0
;
is_sgx_https
=
0
;
DEBUG_PRINT
=
1
;
DEBUG_PRINT
=
1
;
cerr
<<
"test started"
<<
endl
;
cerr
<<
"test started"
<<
endl
;
init_all
(
false
,
false
,
init_SEK
);
init_all
(
false
,
false
,
init_SEK
);
cerr
<<
"Server inited"
<<
endl
;
cerr
<<
"Server inited"
<<
endl
;
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
;
reset_db
();
reset_db
();
int
n
=
16
,
t
=
16
;
int
n
=
16
,
t
=
16
;
Json
::
Value
EthKeys
[
n
];
Json
::
Value
EthKeys
[
n
];
Json
::
Value
VerifVects
[
n
];
Json
::
Value
VerifVects
[
n
];
Json
::
Value
pubEthKeys
;
Json
::
Value
pubEthKeys
;
Json
::
Value
secretShares
[
n
];
Json
::
Value
secretShares
[
n
];
Json
::
Value
pubBLSKeys
[
n
];
Json
::
Value
pubBLSKeys
[
n
];
Json
::
Value
BLSSigShares
[
n
];
Json
::
Value
BLSSigShares
[
n
];
vector
<
string
>
pubShares
(
n
);
vector
<
string
>
pubShares
(
n
);
vector
<
string
>
poly_names
(
n
);
vector
<
string
>
poly_names
(
n
);
int
schain_id
=
rand_gen
();
int
schain_id
=
rand_gen
();
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
();
string
polyName
=
"POLY:SCHAIN_ID:"
+
to_string
(
schain_id
)
+
":NODE_ID:"
+
to_string
(
i
)
+
":DKG_ID:"
+
to_string
(
dkg_id
);
string
polyName
=
"POLY:SCHAIN_ID:"
+
to_string
(
schain_id
)
+
":NODE_ID:"
+
to_string
(
i
)
+
":DKG_ID:"
+
to_string
(
dkg_id
);
c
.
generateDKGPoly
(
polyName
,
t
);
poly_names
[
i
]
=
polyName
;
c
.
generateDKGPoly
(
polyName
,
t
);
VerifVects
[
i
]
=
c
.
getVerificationVector
(
polyName
,
t
,
n
);
poly_names
[
i
]
=
polyName
;
REQUIRE
(
VerifVects
[
i
][
"status"
]
==
0
);
VerifVects
[
i
]
=
c
.
getVerificationVector
(
polyName
,
t
,
n
);
cout
<<
"VV "
<<
i
<<
" "
<<
VerifVects
[
i
]
<<
endl
;
REQUIRE
(
VerifVects
[
i
][
"status"
]
==
0
);
pubEthKeys
.
append
(
EthKeys
[
i
][
"publicKey"
]);
cout
<<
"VV "
<<
i
<<
" "
<<
VerifVects
[
i
]
<<
endl
;
}
pubEthKeys
.
append
(
EthKeys
[
i
][
"publicKey"
]);
for
(
uint8_t
i
=
0
;
i
<
n
;
i
++
){
secretShares
[
i
]
=
c
.
getSecretShare
(
poly_names
[
i
],
pubEthKeys
,
t
,
n
);
cout
<<
secretShares
[
i
]
<<
std
::
endl
;
REQUIRE
(
secretShares
[
i
][
"status"
]
==
0
);
for
(
uint8_t
k
=
0
;
k
<
t
;
k
++
)
{
for
(
uint8_t
j
=
0
;
j
<
4
;
j
++
)
{
string
pubShare
=
VerifVects
[
i
][
"verificationVector"
][
k
][
j
].
asString
();
REQUIRE
(
pubShare
.
length
()
>
60
);
pubShares
[
i
]
+=
ConvertDecToHex
(
pubShare
);
}
}
}
for
(
uint8_t
i
=
0
;
i
<
n
;
i
++
)
{
secretShares
[
i
]
=
c
.
getSecretShare
(
poly_names
[
i
],
pubEthKeys
,
t
,
n
);
cout
<<
secretShares
[
i
]
<<
endl
;
REQUIRE
(
secretShares
[
i
][
"status"
]
==
0
);
for
(
uint8_t
k
=
0
;
k
<
t
;
k
++
)
{
for
(
uint8_t
j
=
0
;
j
<
4
;
j
++
)
{
string
pubShare
=
VerifVects
[
i
][
"verificationVector"
][
k
][
j
].
asString
();
REQUIRE
(
pubShare
.
length
()
>
60
);
pubShares
[
i
]
+=
ConvertDecToHex
(
pubShare
);
}
}
// cerr << "i is " << i << " pubShares[i] = " << pubShares[i] << endl;
// cerr << "i is " << i << " pubShares[i] = " << pubShares[i] << endl;
// cerr << "length is" << pubShares[i].length() << endl;
// cerr << "length is" << pubShares[i].length() << endl;
}
}
// Json::Value complaintResponse = c.complaintResponse(poly_names[1], 0);
// Json::Value complaintResponse = c.complaintResponse(poly_names[1], 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();
int
k
=
0
;
int
k
=
0
;
vector
<
string
>
secShares_vect
(
n
);
vector
<
string
>
secShares_vect
(
n
);
vector
<
string
>
pSharesBad
(
pubShares
);
for
(
int
i
=
0
;
i
<
n
;
i
++
)
for
(
int
j
=
0
;
j
<
n
;
j
++
){
// if ( i != j ){
cerr
<<
"secretShare length is "
<<
secretShares
[
i
][
"secretShare"
].
asString
().
length
()
<<
endl
;
string
secretShare
=
secretShares
[
i
][
"secretShare"
].
asString
().
substr
(
192
*
j
,
192
);
secShares_vect
[
i
]
+=
secretShares
[
j
][
"secretShare"
].
asString
().
substr
(
192
*
i
,
192
);
cerr
<<
"pubShare is "
<<
pubShares
[
i
]
<<
std
::
endl
;
bool
res
=
c
.
dkgVerification
(
pubShares
[
i
],
EthKeys
[
j
][
"keyName"
].
asString
(),
secretShare
,
t
,
n
,
j
)[
"result"
].
asBool
();
k
++
;
cerr
<<
"NOW K IS "
<<
k
<<
" i is "
<<
i
<<
" j is "
<<
j
<<
endl
;
REQUIRE
(
res
);
pSharesBad
[
i
][
0
]
=
'q'
;
Json
::
Value
wrongVerif
=
c
.
dkgVerification
(
pSharesBad
[
i
],
EthKeys
[
j
][
"keyName"
].
asString
(),
secretShare
,
t
,
n
,
j
);
res
=
wrongVerif
[
"result"
].
asBool
();
REQUIRE
(
!
res
);
cerr
<<
"wrong verification "
<<
wrongVerif
<<
endl
;
// }
}
BLSSigShareSet
sigShareSet
(
t
,
n
);
vector
<
string
>
pSharesBad
(
pubShares
);
string
hash
=
"09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db"
;
for
(
int
i
=
0
;
i
<
n
;
i
++
)
for
(
int
j
=
0
;
j
<
n
;
j
++
)
{
// if ( i != j ){
cerr
<<
"secretShare length is "
<<
secretShares
[
i
][
"secretShare"
].
asString
().
length
()
<<
endl
;
string
secretShare
=
secretShares
[
i
][
"secretShare"
].
asString
().
substr
(
192
*
j
,
192
);
secShares_vect
[
i
]
+=
secretShares
[
j
][
"secretShare"
].
asString
().
substr
(
192
*
i
,
192
);
cerr
<<
"pubShare is "
<<
pubShares
[
i
]
<<
endl
;
bool
res
=
c
.
dkgVerification
(
pubShares
[
i
],
EthKeys
[
j
][
"keyName"
].
asString
(),
secretShare
,
t
,
n
,
j
)[
"result"
].
asBool
();
k
++
;
cerr
<<
"NOW K IS "
<<
k
<<
" i is "
<<
i
<<
" j is "
<<
j
<<
endl
;
REQUIRE
(
res
);
auto
hash_arr
=
make_shared
<
array
<
uint8_t
,
32
>>
();
pSharesBad
[
i
][
0
]
=
'q'
;
uint64_t
binLen
;
Json
::
Value
wrongVerif
=
c
.
dkgVerification
(
pSharesBad
[
i
],
EthKeys
[
j
][
"keyName"
].
asString
(),
secretShare
,
t
,
if
(
!
hex2carray
(
hash
.
c_str
(),
&
binLen
,
hash_arr
->
data
())){
n
,
j
);
res
=
wrongVerif
[
"result"
].
asBool
();
REQUIRE
(
!
res
);
cerr
<<
"wrong verification "
<<
wrongVerif
<<
endl
;
// }
}
BLSSigShareSet
sigShareSet
(
t
,
n
);
string
hash
=
"09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db"
;
auto
hash_arr
=
make_shared
<
array
<
uint8_t
,
32
>>
();
uint64_t
binLen
;
if
(
!
hex2carray
(
hash
.
c_str
(),
&
binLen
,
hash_arr
->
data
()))
{
throw
RPCException
(
INVALID_HEX
,
"Invalid hash"
);
throw
RPCException
(
INVALID_HEX
,
"Invalid hash"
);
}
map
<
size_t
,
shared_ptr
<
BLSPublicKeyShare
>>
koefs_pkeys_map
;
for
(
int
i
=
0
;
i
<
t
;
i
++
){
string
endName
=
poly_names
[
i
].
substr
(
4
);
string
blsName
=
"BLS_KEY"
+
poly_names
[
i
].
substr
(
4
);
string
secretShare
=
secretShares
[
i
][
"secretShare"
].
asString
();
//cout << c.createBLSPrivateKey(blsName, EthKeys[i]["keyName"].asString(), poly_names[i], secretShare, t, n);
cout
<<
c
.
createBLSPrivateKey
(
blsName
,
EthKeys
[
i
][
"keyName"
].
asString
(),
poly_names
[
i
],
secShares_vect
[
i
],
t
,
n
);
pubBLSKeys
[
i
]
=
c
.
getBLSPublicKeyShare
(
blsName
);
cerr
<<
"BLS KEY SHARE NAME IS "
<<
blsName
<<
endl
;
//string hash = "09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db";
BLSSigShares
[
i
]
=
c
.
blsSignMessageHash
(
blsName
,
hash
,
t
,
n
,
i
+
1
);
cerr
<<
i
<<
" sig share is created "
<<
endl
;
shared_ptr
<
string
>
sig_share_ptr
=
make_shared
<
string
>
(
BLSSigShares
[
i
][
"signatureShare"
].
asString
());
BLSSigShare
sig
(
sig_share_ptr
,
i
+
1
,
t
,
n
);
sigShareSet
.
addSigShare
(
make_shared
<
BLSSigShare
>
(
sig
));
vector
<
string
>
pubKey_vect
;
for
(
uint8_t
j
=
0
;
j
<
4
;
j
++
){
pubKey_vect
.
push_back
(
pubBLSKeys
[
i
][
"blsPublicKeyShare"
][
j
].
asString
());
}
}
BLSPublicKeyShare
pubKey
(
make_shared
<
vector
<
string
>>
(
pubKey_vect
),
t
,
n
);
REQUIRE
(
pubKey
.
VerifySigWithHelper
(
hash_arr
,
make_shared
<
BLSSigShare
>
(
sig
)
,
t
,
n
));
koefs_pkeys_map
[
i
+
1
]
=
make_shared
<
BLSPublicKeyShare
>
(
pubKey
);
}
map
<
size_t
,
shared_ptr
<
BLSPublicKeyShare
>>
koefs_pkeys_map
;
for
(
int
i
=
0
;
i
<
t
;
i
++
)
{
string
endName
=
poly_names
[
i
].
substr
(
4
);
string
blsName
=
"BLS_KEY"
+
poly_names
[
i
].
substr
(
4
);
string
secretShare
=
secretShares
[
i
][
"secretShare"
].
asString
();
//cout << c.createBLSPrivateKey(blsName, EthKeys[i]["keyName"].asString(), poly_names[i], secretShare, t, n);
cout
<<
c
.
createBLSPrivateKey
(
blsName
,
EthKeys
[
i
][
"keyName"
].
asString
(),
poly_names
[
i
],
secShares_vect
[
i
],
t
,
n
);
pubBLSKeys
[
i
]
=
c
.
getBLSPublicKeyShare
(
blsName
);
cerr
<<
"BLS KEY SHARE NAME IS "
<<
blsName
<<
endl
;
//string hash = "09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db";
BLSSigShares
[
i
]
=
c
.
blsSignMessageHash
(
blsName
,
hash
,
t
,
n
,
i
+
1
);
cerr
<<
i
<<
" sig share is created "
<<
endl
;
shared_ptr
<
string
>
sig_share_ptr
=
make_shared
<
string
>
(
BLSSigShares
[
i
][
"signatureShare"
].
asString
());
BLSSigShare
sig
(
sig_share_ptr
,
i
+
1
,
t
,
n
);
sigShareSet
.
addSigShare
(
make_shared
<
BLSSigShare
>
(
sig
));
vector
<
string
>
pubKey_vect
;
for
(
uint8_t
j
=
0
;
j
<
4
;
j
++
)
{
pubKey_vect
.
push_back
(
pubBLSKeys
[
i
][
"blsPublicKeyShare"
][
j
].
asString
());
}
BLSPublicKeyShare
pubKey
(
make_shared
<
vector
<
string
>>
(
pubKey_vect
),
t
,
n
);
REQUIRE
(
pubKey
.
VerifySigWithHelper
(
hash_arr
,
make_shared
<
BLSSigShare
>
(
sig
),
t
,
n
));
koefs_pkeys_map
[
i
+
1
]
=
make_shared
<
BLSPublicKeyShare
>
(
pubKey
);
shared_ptr
<
BLSSignature
>
commonSig
=
sigShareSet
.
merge
();
}
BLSPublicKey
common_public
(
make_shared
<
map
<
size_t
,
shared_ptr
<
BLSPublicKeyShare
>>>
(
koefs_pkeys_map
),
t
,
n
);
REQUIRE
(
common_public
.
VerifySigWithHelper
(
hash_arr
,
commonSig
,
t
,
n
)
);
shared_ptr
<
BLSSignature
>
commonSig
=
sigShareSet
.
merge
();
BLSPublicKey
common_public
(
make_shared
<
map
<
size_t
,
shared_ptr
<
BLSPublicKeyShare
>>>
(
koefs_pkeys_map
),
t
,
n
);
REQUIRE
(
common_public
.
VerifySigWithHelper
(
hash_arr
,
commonSig
,
t
,
n
));
}
}
TEST_CASE
(
"API test"
,
"[api_test]"
)
{
TEST_CASE
(
"API test"
,
"[api_test]"
)
{
//DEBUG_PRINT = 1;
//DEBUG_PRINT = 1;
is_sgx_https
=
0
;
is_sgx_https
=
0
;
//cerr << __GNUC__ << endl;
//cerr << __GNUC__ << endl;
cerr
<<
"API test started"
<<
endl
;
cerr
<<
"API test started"
<<
endl
;
init_all
(
false
,
false
,
init_SEK
);
init_all
(
false
,
false
,
init_SEK
);
//HttpServer httpserver(1025);
//HttpServer httpserver(1025);
//SGXWalletServer s(httpserver,
//SGXWalletServer s(httpserver,
// JSONRPC_SERVER_V2); // hybrid server (json-rpc 1.0 & 2.0)
// JSONRPC_SERVER_V2); // hybrid server (json-rpc 1.0 & 2.0)
// s.StartListening();
// s.StartListening();
cerr
<<
"Server inited"
<<
endl
;
cerr
<<
"Server inited"
<<
endl
;
HttpClient
client
(
"http://localhost:1029"
);
HttpClient
client
(
"http://localhost:1029"
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
...
@@ -832,24 +701,25 @@ TEST_CASE("API test", "[api_test]") {
...
@@ -832,24 +701,25 @@ TEST_CASE("API test", "[api_test]") {
// levelDb->deleteKey(" DKG_DH_KEY_POLY:SCHAIN_ID:0:NODE_ID:" + to_string(i)+ ":DKG_ID:0_1");
// levelDb->deleteKey(" DKG_DH_KEY_POLY:SCHAIN_ID:0:NODE_ID:" + to_string(i)+ ":DKG_ID:0_1");
// }
// }
//cout << c.importBLSKeyShare("4160780231445160889237664391382223604184857153814275770598791864649971919844","BLS_KEY:SCHAIN_ID:2660016693368503500803087136248943520694587309641817:NODE_ID:33909:DKG_ID:3522960548719023733985054069487289468077787284706573", 4, 3,1);
//cout << c.importBLSKeyShare("4160780231445160889237664391382223604184857153814275770598791864649971919844","BLS_KEY:SCHAIN_ID:2660016693368503500803087136248943520694587309641817:NODE_ID:33909:DKG_ID:3522960548719023733985054069487289468077787284706573", 4, 3,1);
Json
::
Value
genKey
=
c
.
generateECDSAKey
();
Json
::
Value
genKey
=
c
.
generateECDSAKey
();
cout
<<
genKey
<<
endl
;
cout
<<
genKey
<<
endl
;
cout
<<
c
.
ecdsaSignMessageHash
(
16
,
genKey
[
"keyName"
].
asString
(),
"0x09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db"
);
cout
<<
c
.
ecdsaSignMessageHash
(
16
,
genKey
[
"keyName"
].
asString
(),
"0x09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db"
);
Json
::
Value
getPubKey
=
c
.
getPublicECDSAKey
(
genKey
[
"keyName"
].
asString
());
Json
::
Value
getPubKey
=
c
.
getPublicECDSAKey
(
genKey
[
"keyName"
].
asString
());
cout
<<
getPubKey
<<
endl
;
cout
<<
getPubKey
<<
endl
;
// cout << c.renameESDSAKey("NODE_1CHAIN_1","tmp_NEK:bcacde0d26c0ea2c7e649992e7f791e1fba2492f5b7ae63dadb799075167c7fc");
// cout << c.renameESDSAKey("NODE_1CHAIN_1","tmp_NEK:bcacde0d26c0ea2c7e649992e7f791e1fba2492f5b7ae63dadb799075167c7fc");
// cout<<c.getPublicECDSAKey("NEK:7ca98cf32fd1edba26ea685820719fd2201b068a10c1264d382abbde13802a0e");
// cout<<c.getPublicECDSAKey("NEK:7ca98cf32fd1edba26ea685820719fd2201b068a10c1264d382abbde13802a0e");
//cout << c.ecdsaSignMessageHash(16, "NEK:697fadfc597bdbfae9ffb7412b80939e848c9c2fec2657bb2122b6d0d4a0dca8","0x09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db" );
//cout << c.ecdsaSignMessageHash(16, "NEK:697fadfc597bdbfae9ffb7412b80939e848c9c2fec2657bb2122b6d0d4a0dca8","0x09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db" );
//cout << c.ecdsaSignMessageHash(16, "known_key1","0x09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db" );
//cout << c.ecdsaSignMessageHash(16, "known_key1","0x09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db" );
// cout << c.blsSignMessageHash(TEST_BLS_KEY_NAME, "0x09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db", 2,2,1 );
// cout << c.blsSignMessageHash(TEST_BLS_KEY_NAME, "0x09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db", 2,2,1 );
// cout << c.generateDKGPoly("pp2", 2);
// cout << c.generateDKGPoly("pp2", 2);
// cout << c.generateDKGPoly("POLY:SCHAIN_ID:1:NODE_ID:1:DKG_ID:1", 2);
// cout << c.generateDKGPoly("POLY:SCHAIN_ID:1:NODE_ID:1:DKG_ID:1", 2);
//cout << c.generateDKGPoly("POLY:SCHAIN_ID:14225439306783892379384764908040542049263455631509697460847850632966314337557:NODE_ID:1:DKG_ID:71951190446274221430521459675625214118086594348715", 1);
//cout << c.generateDKGPoly("POLY:SCHAIN_ID:14225439306783892379384764908040542049263455631509697460847850632966314337557:NODE_ID:1:DKG_ID:71951190446274221430521459675625214118086594348715", 1);
//cout << c.getVerificationVector("POLY:SCHAIN_ID:1:NODE_ID:1:DKG_ID:2", 2, 2);
//cout << c.getVerificationVector("POLY:SCHAIN_ID:1:NODE_ID:1:DKG_ID:2", 2, 2);
// cout << c.getVerificationVector("polyy", 5, 5);
// cout << c.getVerificationVector("polyy", 5, 5);
// cout << c.getSecretShare("p2",
// cout << c.getSecretShare("p2",
// "505f55a38f9c064da744f217d1cb993a17705e9839801958cda7c884e08ab4dad7fd8d22953d3ac7f0913de24fd67d7ed36741141b8a3da152d7ba954b0f14e232d69c361f0bc9e05f1cf8ef387122dc1d2f7cee7b6cda3537fc9427c02328b01f02fd94ec933134dc795a642864f8cb41ae263e11abaf992e21fcf9be732deb",
// "505f55a38f9c064da744f217d1cb993a17705e9839801958cda7c884e08ab4dad7fd8d22953d3ac7f0913de24fd67d7ed36741141b8a3da152d7ba954b0f14e232d69c361f0bc9e05f1cf8ef387122dc1d2f7cee7b6cda3537fc9427c02328b01f02fd94ec933134dc795a642864f8cb41ae263e11abaf992e21fcf9be732deb",
...
@@ -859,160 +729,161 @@ TEST_CASE("API test", "[api_test]") {
...
@@ -859,160 +729,161 @@ TEST_CASE("API test", "[api_test]") {
// "669aa790e1c5f5199af82ab0b6f1965c382d23a2ebdda581454adba3fd082a30edab62b545f78f1e402ceef7340a0364a7046633d6151fe7e657d8b8a6352378b3e6fdfe2633256ae1662fcd23466d02ead907b5d4366136341cea5e46f5a7bb67d897d6e35f619810238aa143c416f61c640ed214eb9c67a34c4a31b7d25e6e",
// "669aa790e1c5f5199af82ab0b6f1965c382d23a2ebdda581454adba3fd082a30edab62b545f78f1e402ceef7340a0364a7046633d6151fe7e657d8b8a6352378b3e6fdfe2633256ae1662fcd23466d02ead907b5d4366136341cea5e46f5a7bb67d897d6e35f619810238aa143c416f61c640ed214eb9c67a34c4a31b7d25e6e",
// 2,2);
// 2,2);
Json
::
Value
publicKeys
;
Json
::
Value
publicKeys
;
publicKeys
.
append
(
"505f55a38f9c064da744f217d1cb993a17705e9839801958cda7c884e08ab4dad7fd8d22953d3ac7f0913de24fd67d7ed36741141b8a3da152d7ba954b0f14e2"
);
publicKeys
.
append
(
publicKeys
.
append
(
"378b3e6fdfe2633256ae1662fcd23466d02ead907b5d4366136341cea5e46f5a7bb67d897d6e35f619810238aa143c416f61c640ed214eb9c67a34c4a31b7d25"
);
"505f55a38f9c064da744f217d1cb993a17705e9839801958cda7c884e08ab4dad7fd8d22953d3ac7f0913de24fd67d7ed36741141b8a3da152d7ba954b0f14e2"
);
// cout << c.getSecretShare("POLY:SCHAIN_ID:1:NODE_ID:1:DKG_ID:1", publicKeys, 2, 2);
publicKeys
.
append
(
// cout << c.generateDKGPoly("p3", 3);
"378b3e6fdfe2633256ae1662fcd23466d02ead907b5d4366136341cea5e46f5a7bb67d897d6e35f619810238aa143c416f61c640ed214eb9c67a34c4a31b7d25"
);
// cout << c.getSecretShare("p3",
// cout << c.getSecretShare("POLY:SCHAIN_ID:1:NODE_ID:1:DKG_ID:1", publicKeys, 2, 2);
// "669aa790e1c5f5199af82ab0b6f1965c382d23a2ebdda581454adba3fd082a30edab62b545f78f1e402ceef7340a0364a7046633d6151fe7e657d8b8a6352378b3e6fdfe2633256ae1662fcd23466d02ead907b5d4366136341cea5e46f5a7bb67d897d6e35f619810238aa143c416f61c640ed214eb9c67a34c4a31b7d25e6e9d43f1c88581f53af993da1654c9f91829c1fe5344c4452ef8d2d8675c6a051c19029f6e4f82b035fb3552058cf22c5bbafd9e6456d579634987281765d130b0",
// cout << c.generateDKGPoly("p3", 3);
// 3,3);
// cout << c.getSecretShare("p3",
// "669aa790e1c5f5199af82ab0b6f1965c382d23a2ebdda581454adba3fd082a30edab62b545f78f1e402ceef7340a0364a7046633d6151fe7e657d8b8a6352378b3e6fdfe2633256ae1662fcd23466d02ead907b5d4366136341cea5e46f5a7bb67d897d6e35f619810238aa143c416f61c640ed214eb9c67a34c4a31b7d25e6e9d43f1c88581f53af993da1654c9f91829c1fe5344c4452ef8d2d8675c6a051c19029f6e4f82b035fb3552058cf22c5bbafd9e6456d579634987281765d130b0",
// 3,3);
string
share_big0
=
"501e364a6ea516f4812b013bcc150cbb435a2c465c9fd525951264969d8441a986798fd3317c1c3e60f868bb26c4cff837d9185f4be6015d8326437cb5b69480495859cd5a385430ece51252acdc234d8dbde75708b600ac50b2974e813ee26bd87140d88647fcc44df7262bbba24328e8ce622cd627a15b508ffa0db9ae81e0e110fab42cfe40da66b524218ca3c8e5aa3363fbcadef748dc3523a7ffb95b8f5d8141a5163db9f69d1ab223494ed71487c9bb032a74c08a222d897a5e49a617"
;
string
share_big0
=
"501e364a6ea516f4812b013bcc150cbb435a2c465c9fd525951264969d8441a986798fd3317c1c3e60f868bb26c4cff837d9185f4be6015d8326437cb5b69480495859cd5a385430ece51252acdc234d8dbde75708b600ac50b2974e813ee26bd87140d88647fcc44df7262bbba24328e8ce622cd627a15b508ffa0db9ae81e0e110fab42cfe40da66b524218ca3c8e5aa3363fbcadef748dc3523a7ffb95b8f5d8141a5163db9f69d1ab223494ed71487c9bb032a74c08a222d897a5e49a617"
;
string
share_big
=
"03f749e2fcc28021895d757ec16d1636784446f5effcd3096b045136d8ab02657b32adc577f421330b81f5b7063df3b08a0621a897df2584b9046ca416e50ecc27e8c3277e981f7e650f8640289be128eecf0105f89a20e5ffb164744c45cf191d627ce9ab6c44e2ef96f230f2a4de742ea43b6f74b56849138026610b2d965605ececba527048a0f29f46334b1cec1d23df036248b24eccca99057d24764acee66c1a3f2f44771d0d237bf9d18c4177277e3ce3dc4e83686a2647fce1565ee0"
;
string
share_big
=
"03f749e2fcc28021895d757ec16d1636784446f5effcd3096b045136d8ab02657b32adc577f421330b81f5b7063df3b08a0621a897df2584b9046ca416e50ecc27e8c3277e981f7e650f8640289be128eecf0105f89a20e5ffb164744c45cf191d627ce9ab6c44e2ef96f230f2a4de742ea43b6f74b56849138026610b2d965605ececba527048a0f29f46334b1cec1d23df036248b24eccca99057d24764acee66c1a3f2f44771d0d237bf9d18c4177277e3ce3dc4e83686a2647fce1565ee0"
;
string
share
=
share_big
.
substr
(
0
,
192
);
string
share
=
share_big
.
substr
(
0
,
192
);
string
publicShares
=
"1fc8154abcbf0c2ebf559571d7b57a8995c0e293a73d4676a8f76051a0d0ace30e00a87c9f087254c9c860c3215c4f11e8f85a3e8fae19358f06a0cbddf3df1924b1347b9b58f5bcb20958a19bdbdd832181cfa9f9e9fd698f6a485051cb47b829d10f75b6e227a7d7366dd02825b5718072cd42c39f0352071808622b7db6421b1069f519527e49052a8da6e3720cbda9212fc656eef945f5e56a4159c3b9622d883400460a9eff07fe1873f9b1ec50f6cf70098b9da0b90625b176f12329fa2ecc65082c626dc702d9cfb23a06770d4a2c7867e269efe84e3709b11001fb380a32d609855d1d46bc60f21140c636618b8ff55ed06d7788b6f81b498f96d3f9"
;
string
publicShares
=
"1fc8154abcbf0c2ebf559571d7b57a8995c0e293a73d4676a8f76051a0d0ace30e00a87c9f087254c9c860c3215c4f11e8f85a3e8fae19358f06a0cbddf3df1924b1347b9b58f5bcb20958a19bdbdd832181cfa9f9e9fd698f6a485051cb47b829d10f75b6e227a7d7366dd02825b5718072cd42c39f0352071808622b7db6421b1069f519527e49052a8da6e3720cbda9212fc656eef945f5e56a4159c3b9622d883400460a9eff07fe1873f9b1ec50f6cf70098b9da0b90625b176f12329fa2ecc65082c626dc702d9cfb23a06770d4a2c7867e269efe84e3709b11001fb380a32d609855d1d46bc60f21140c636618b8ff55ed06d7788b6f81b498f96d3f9"
;
// cout << c.dkgVerification(publicShares, "test_key1", "37092c06c423b627c38ff86d1e66608bdc1496ef855b86e9f773441ac0b285d92aa466376a6008de4aab9858aa34848775282c4c3b56370bf25827321619c6e47701c8a32e3f4bb28f5a3b12a09800f318c550cedff6150e9a673ea56ece8b76", 2, 2, 0);
// cout << c.dkgVerification(publicShares, "test_key1", "37092c06c423b627c38ff86d1e66608bdc1496ef855b86e9f773441ac0b285d92aa466376a6008de4aab9858aa34848775282c4c3b56370bf25827321619c6e47701c8a32e3f4bb28f5a3b12a09800f318c550cedff6150e9a673ea56ece8b76", 2, 2, 0);
// cout << c.dkgVerification("oleh1", "key0", "37092c06c423b627c38ff86d1e66608bdc1496ef855b86e9f773441ac0b285d92aa466376a6008de4aab9858aa34848775282c4c3b56370bf25827321619c6e47701c8a32e3f4bb28f5a3b12a09800f318c550cedff6150e9a673ea56ece8b76", 2, 2, 0);
// cout << c.dkgVerification("oleh1", "key0", "37092c06c423b627c38ff86d1e66608bdc1496ef855b86e9f773441ac0b285d92aa466376a6008de4aab9858aa34848775282c4c3b56370bf25827321619c6e47701c8a32e3f4bb28f5a3b12a09800f318c550cedff6150e9a673ea56ece8b76", 2, 2, 0);
Json
::
Value
SecretShare
;
Json
::
Value
SecretShare
;
SecretShare
.
append
(
share_big0
);
SecretShare
.
append
(
share_big0
);
SecretShare
.
append
(
share_big
);
SecretShare
.
append
(
share_big
);
//cout << c.createBLSPrivateKey( "test_bls_key1","test_key1", "p2", share_big0, 2, 2 );
//cout << c.createBLSPrivateKey( "test_bls_key1","test_key1", "p2", share_big0, 2, 2 );
// string shares = "252122c309ed1f32faa897ede140c5b9c1bc07d5d9c94b7a22d4eeb13da7b7142aa466376a6008de4aab9858aa34848775282c4c3b56370bf25827321619c6e47701c8a32e3f4bb28f5a3b12a09800f318c550cedff6150e9a673ea56ece8b76df831dbef474cfc38be1c980130a8d273ff410fbf87deece9d7756a1b08ba9e954c1676cc7f2cac16e16cff0c877d8cf967381321fb4cc78e3638245a1dc85419766d281aff4935cc6eac25c9842032c8f7fae567c57622969599a72c42d2e1e";
// string shares = "252122c309ed1f32faa897ede140c5b9c1bc07d5d9c94b7a22d4eeb13da7b7142aa466376a6008de4aab9858aa34848775282c4c3b56370bf25827321619c6e47701c8a32e3f4bb28f5a3b12a09800f318c550cedff6150e9a673ea56ece8b76df831dbef474cfc38be1c980130a8d273ff410fbf87deece9d7756a1b08ba9e954c1676cc7f2cac16e16cff0c877d8cf967381321fb4cc78e3638245a1dc85419766d281aff4935cc6eac25c9842032c8f7fae567c57622969599a72c42d2e1e";
string
shares
=
"252122c309ed1f32faa897ede140c5b9c1bc07d5d9c94b7a22d4eeb13da7b7142aa466376a6008de4aab9858aa34848775282c4c3b56370bf25827321619c6e47701c8a32e3f4bb28f5a3b12a09800f318c550cedff6150e9a673ea56ece8b7637092c06c423b627c38ff86d1e66608bdc1496ef855b86e9f773441ac0b285d92aa466376a6008de4aab9858aa34848775282c4c3b56370bf25827321619c6e47701c8a32e3f4bb28f5a3b12a09800f318c550cedff6150e9a673ea56ece8b76"
;
string
shares
=
"252122c309ed1f32faa897ede140c5b9c1bc07d5d9c94b7a22d4eeb13da7b7142aa466376a6008de4aab9858aa34848775282c4c3b56370bf25827321619c6e47701c8a32e3f4bb28f5a3b12a09800f318c550cedff6150e9a673ea56ece8b7637092c06c423b627c38ff86d1e66608bdc1496ef855b86e9f773441ac0b285d92aa466376a6008de4aab9858aa34848775282c4c3b56370bf25827321619c6e47701c8a32e3f4bb28f5a3b12a09800f318c550cedff6150e9a673ea56ece8b76"
;
//cout << c.createBLSPrivateKey( "test_bls1","key0", "oleh1", shares, 2, 2 );
//cout << c.createBLSPrivateKey( "test_bls1","key0", "oleh1", shares, 2, 2 );
//cout << c.getBLSPublicKeyShare("test_bls_key0");
//cout << c.getBLSPublicKeyShare("test_bls_key0");
string
s_share
=
"13b871ad5025fed10a41388265b19886e78f449f758fe8642ade51440fcf850bb2083f87227d8fb53fdfb2854e2d0abec4f47e2197b821b564413af96124cd84a8700f8eb9ed03161888c9ef58d6e5896403de3608e634e23e92fba041aa283484427d0e6de20922216c65865cfe26edd2cf9cbfc3116d007710e8d82feafd9135c497bef0c800ca310ba6044763572681510dad5e043ebd87ffaa1a4cd45a899222207f3d05dec8110d132ad34c62d6a3b40bf8e9f40f875125c3035062d2ca"
;
string
s_share
=
"13b871ad5025fed10a41388265b19886e78f449f758fe8642ade51440fcf850bb2083f87227d8fb53fdfb2854e2d0abec4f47e2197b821b564413af96124cd84a8700f8eb9ed03161888c9ef58d6e5896403de3608e634e23e92fba041aa283484427d0e6de20922216c65865cfe26edd2cf9cbfc3116d007710e8d82feafd9135c497bef0c800ca310ba6044763572681510dad5e043ebd87ffaa1a4cd45a899222207f3d05dec8110d132ad34c62d6a3b40bf8e9f40f875125c3035062d2ca"
;
string
ethKeyName
=
"tmp_NEK:8abc8e8280fb060988b65da4b8cb00779a1e816ec42f8a40ae2daa520e484a01"
;
string
ethKeyName
=
"tmp_NEK:8abc8e8280fb060988b65da4b8cb00779a1e816ec42f8a40ae2daa520e484a01"
;
//cout << c.createBLSPrivateKey( "test_blskey", ethKeyName, "JCGMt", s_share, 2, 2 );
//cout << c.createBLSPrivateKey( "test_blskey", ethKeyName, "JCGMt", s_share, 2, 2 );
//cout << c.getBLSPublicKeyShare("test_blskey");
//cout << c.getBLSPublicKeyShare("test_blskey");
// cout << c.blsSignMessageHash("dOsRY","38433e5ce087dcc1be82fcc834eae83c256b3db87d34f84440d0b708daa0c6f7", 2, 2, 1);
// cout << c.blsSignMessageHash("dOsRY","38433e5ce087dcc1be82fcc834eae83c256b3db87d34f84440d0b708daa0c6f7", 2, 2, 1);
// cout << c.complaintResponse("POLY:SCHAIN_ID:1:NODE_ID:1:DKG_ID:1", 0);
// cout << c.complaintResponse("POLY:SCHAIN_ID:1:NODE_ID:1:DKG_ID:1", 0);
// cout << c.getBLSPublicKeyShare("BLS_KEY:SCHAIN_ID:1:NODE_ID:1:DKG_ID:0");
// cout << c.getBLSPublicKeyShare("BLS_KEY:SCHAIN_ID:1:NODE_ID:1:DKG_ID:0");
// cout << c.getPublicECDSAKey("NEK:91573248d6b0ebd5b1bd313ab35163361b423c0f9f01bad085d166650b8b2c1f");
// cout << c.getPublicECDSAKey("NEK:91573248d6b0ebd5b1bd313ab35163361b423c0f9f01bad085d166650b8b2c1f");
//cout << c.multG2("4160780231445160889237664391382223604184857153814275770598791864649971919844");
//cout << c.multG2("4160780231445160889237664391382223604184857153814275770598791864649971919844");
}
catch
(
JsonRpcException
&
e
)
{
}
catch
(
JsonRpcException
&
e
)
{
cerr
<<
e
.
what
()
<<
endl
;
cerr
<<
e
.
what
()
<<
endl
;
}
}
sgx_destroy_enclave
(
eid
);
sgx_destroy_enclave
(
eid
);
}
}
TEST_CASE
(
"getServerStatus test"
,
"[getServerStatus_test]"
)
{
TEST_CASE
(
"getServerStatus test"
,
"[getServerStatus_test]"
)
{
is_sgx_https
=
0
;
is_sgx_https
=
0
;
init_all
(
false
,
false
,
init_SEK
);
init_all
(
false
,
false
,
init_SEK
);
HttpClient
client
(
"http://localhost:1029"
);
HttpClient
client
(
"http://localhost:1029"
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
REQUIRE
(
c
.
getServerStatus
()[
"status"
]
==
0
);
REQUIRE
(
c
.
getServerStatus
()[
"status"
]
==
0
);
sgx_destroy_enclave
(
eid
);
sgx_destroy_enclave
(
eid
);
}
}
void
SendRPCRequest
()
{
void
SendRPCRequest
(){
cout
<<
"Hello from thread "
<<
this_thread
::
get_id
()
<<
endl
;
cout
<<
"Hello from thread "
<<
this_thread
::
get_id
()
<<
endl
;
HttpClient
client
(
"http://localhost:1029"
);
HttpClient
client
(
"http://localhost:1029"
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
reset_db
();
reset_db
();
int
n
=
16
,
t
=
16
;
int
n
=
16
,
t
=
16
;
Json
::
Value
EthKeys
[
n
];
Json
::
Value
EthKeys
[
n
];
Json
::
Value
VerifVects
[
n
];
Json
::
Value
VerifVects
[
n
];
Json
::
Value
pubEthKeys
;
Json
::
Value
pubEthKeys
;
Json
::
Value
secretShares
[
n
];
Json
::
Value
secretShares
[
n
];
Json
::
Value
pubBLSKeys
[
n
];
Json
::
Value
pubBLSKeys
[
n
];
Json
::
Value
BLSSigShares
[
n
];
Json
::
Value
BLSSigShares
[
n
];
vector
<
string
>
pubShares
(
n
);
vector
<
string
>
pubShares
(
n
);
vector
<
string
>
poly_names
(
n
);
vector
<
string
>
poly_names
(
n
);
int
schain_id
=
rand_gen
();
int
schain_id
=
rand_gen
();
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
();
string
polyName
=
"POLY:SCHAIN_ID:"
+
to_string
(
schain_id
)
+
":NODE_ID:"
+
to_string
(
i
)
+
":DKG_ID:"
+
to_string
(
dkg_id
);
string
polyName
=
c
.
generateDKGPoly
(
polyName
,
t
);
"POLY:SCHAIN_ID:"
+
to_string
(
schain_id
)
+
":NODE_ID:"
+
to_string
(
i
)
+
":DKG_ID:"
+
to_string
(
dkg_id
);
poly_names
[
i
]
=
polyName
;
c
.
generateDKGPoly
(
polyName
,
t
);
VerifVects
[
i
]
=
c
.
getVerificationVector
(
polyName
,
t
,
n
);
poly_names
[
i
]
=
polyName
;
REQUIRE
(
VerifVects
[
i
][
"status"
]
==
0
);
VerifVects
[
i
]
=
c
.
getVerificationVector
(
polyName
,
t
,
n
);
cout
<<
"VV "
<<
i
<<
" "
<<
VerifVects
[
i
]
<<
endl
;
REQUIRE
(
VerifVects
[
i
][
"status"
]
==
0
);
pubEthKeys
.
append
(
EthKeys
[
i
][
"publicKey"
]);
cout
<<
"VV "
<<
i
<<
" "
<<
VerifVects
[
i
]
<<
endl
;
}
pubEthKeys
.
append
(
EthKeys
[
i
][
"publicKey"
]);
for
(
uint8_t
i
=
0
;
i
<
n
;
i
++
){
secretShares
[
i
]
=
c
.
getSecretShare
(
poly_names
[
i
],
pubEthKeys
,
t
,
n
);
for
(
uint8_t
k
=
0
;
k
<
t
;
k
++
)
{
for
(
uint8_t
j
=
0
;
j
<
4
;
j
++
)
{
string
pubShare
=
VerifVects
[
i
][
"Verification Vector"
][
k
][
j
].
asString
();
pubShares
[
i
]
+=
ConvertDecToHex
(
pubShare
);
}
}
}
for
(
uint8_t
i
=
0
;
i
<
n
;
i
++
)
{
secretShares
[
i
]
=
c
.
getSecretShare
(
poly_names
[
i
],
pubEthKeys
,
t
,
n
);
for
(
uint8_t
k
=
0
;
k
<
t
;
k
++
)
{
for
(
uint8_t
j
=
0
;
j
<
4
;
j
++
)
{
string
pubShare
=
VerifVects
[
i
][
"Verification Vector"
][
k
][
j
].
asString
();
pubShares
[
i
]
+=
ConvertDecToHex
(
pubShare
);
}
}
// cerr << "i is " << i << " pubShares[i] = " << pubShares[i] << endl;
// cerr << "i is " << i << " pubShares[i] = " << pubShares[i] << endl;
// cerr << "length is" << pubShares[i].length() << endl;
// cerr << "length is" << pubShares[i].length() << endl;
}
int
k
=
0
;
vector
<
string
>
secShares_vect
(
n
);
for
(
int
i
=
0
;
i
<
n
;
i
++
)
for
(
int
j
=
0
;
j
<
n
;
j
++
){
// if ( i != j ){
cerr
<<
"SecretShare length is "
<<
secretShares
[
i
][
"secretShare"
].
asString
().
length
()
<<
endl
;
string
secretShare
=
secretShares
[
i
][
"secretShare"
].
asString
().
substr
(
192
*
j
,
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
);
cout
<<
verif
;
bool
res
=
verif
[
"result"
].
asBool
();
k
++
;
cerr
<<
"NOW K IS "
<<
k
<<
" i is "
<<
i
<<
" j is "
<<
j
<<
endl
;
// REQUIRE( res );
// }
}
}
int
k
=
0
;
BLSSigShareSet
sigShareSet
(
t
,
n
);
vector
<
string
>
secShares_vect
(
n
);
string
hash
=
"09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db"
;
auto
hash_arr
=
make_shared
<
array
<
uint8_t
,
32
>>
();
for
(
int
i
=
0
;
i
<
n
;
i
++
)
uint64_t
binLen
;
for
(
int
j
=
0
;
j
<
n
;
j
++
)
{
if
(
!
hex2carray
(
hash
.
c_str
(),
&
binLen
,
hash_arr
->
data
())){
// if ( i != j ){
throw
RPCException
(
INVALID_HEX
,
"Invalid hash"
);
cerr
<<
"SecretShare length is "
<<
secretShares
[
i
][
"secretShare"
].
asString
().
length
()
<<
endl
;
}
string
secretShare
=
secretShares
[
i
][
"secretShare"
].
asString
().
substr
(
192
*
j
,
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
);
cout
<<
verif
;
k
++
;
cerr
<<
"NOW K IS "
<<
k
<<
" i is "
<<
i
<<
" j is "
<<
j
<<
endl
;
// REQUIRE( res );
// }
}
map
<
size_t
,
shared_ptr
<
BLSPublicKeyShare
>>
koefs_pkeys_map
;
BLSSigShareSet
sigShareSet
(
t
,
n
);
for
(
int
i
=
0
;
i
<
t
;
i
++
){
string
endName
=
poly_names
[
i
].
substr
(
4
);
string
blsName
=
"BLS_KEY"
+
poly_names
[
i
].
substr
(
4
);
string
secretShare
=
secretShares
[
i
][
"secretShare"
].
asString
();
//cout << c.createBLSPrivateKey(blsName, EthKeys[i]["keyName"].asString(), poly_names[i], secretShare, t, n);
cout
<<
c
.
createBLSPrivateKey
(
blsName
,
EthKeys
[
i
][
"keyName"
].
asString
(),
poly_names
[
i
],
secShares_vect
[
i
],
t
,
n
);
pubBLSKeys
[
i
]
=
c
.
getBLSPublicKeyShare
(
blsName
);
cerr
<<
"BLS KEY SHARE NAME IS "
<<
blsName
<<
endl
;
string
hash
=
"09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db"
;
string
hash
=
"09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db"
;
BLSSigShares
[
i
]
=
c
.
blsSignMessageHash
(
blsName
,
hash
,
t
,
n
,
i
+
1
);
REQUIRE
(
BLSSigShares
[
i
][
"status"
]
==
0
);
auto
hash_arr
=
make_shared
<
array
<
uint8_t
,
32
>>
();
cerr
<<
i
<<
" sig share is created "
<<
endl
;
uint64_t
binLen
;
shared_ptr
<
string
>
sig_share_ptr
=
make_shared
<
string
>
(
BLSSigShares
[
i
][
"signatureShare"
].
asString
());
if
(
!
hex2carray
(
hash
.
c_str
(),
&
binLen
,
hash_arr
->
data
()))
{
BLSSigShare
sig
(
sig_share_ptr
,
i
+
1
,
t
,
n
);
throw
RPCException
(
INVALID_HEX
,
"Invalid hash"
);
sigShareSet
.
addSigShare
(
make_shared
<
BLSSigShare
>
(
sig
));
}
map
<
size_t
,
shared_ptr
<
BLSPublicKeyShare
>>
koefs_pkeys_map
;
for
(
int
i
=
0
;
i
<
t
;
i
++
)
{
string
endName
=
poly_names
[
i
].
substr
(
4
);
string
blsName
=
"BLS_KEY"
+
poly_names
[
i
].
substr
(
4
);
string
secretShare
=
secretShares
[
i
][
"secretShare"
].
asString
();
//cout << c.createBLSPrivateKey(blsName, EthKeys[i]["keyName"].asString(), poly_names[i], secretShare, t, n);
cout
<<
c
.
createBLSPrivateKey
(
blsName
,
EthKeys
[
i
][
"keyName"
].
asString
(),
poly_names
[
i
],
secShares_vect
[
i
],
t
,
n
);
pubBLSKeys
[
i
]
=
c
.
getBLSPublicKeyShare
(
blsName
);
cerr
<<
"BLS KEY SHARE NAME IS "
<<
blsName
<<
endl
;
string
hash
=
"09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db"
;
BLSSigShares
[
i
]
=
c
.
blsSignMessageHash
(
blsName
,
hash
,
t
,
n
,
i
+
1
);
REQUIRE
(
BLSSigShares
[
i
][
"status"
]
==
0
);
cerr
<<
i
<<
" sig share is created "
<<
endl
;
shared_ptr
<
string
>
sig_share_ptr
=
make_shared
<
string
>
(
BLSSigShares
[
i
][
"signatureShare"
].
asString
());
BLSSigShare
sig
(
sig_share_ptr
,
i
+
1
,
t
,
n
);
sigShareSet
.
addSigShare
(
make_shared
<
BLSSigShare
>
(
sig
));
// vector<string> pubKey_vect;
// vector<string> pubKey_vect;
// for ( uint8_t j = 0; j < 4; j++){
// for ( uint8_t j = 0; j < 4; j++){
...
@@ -1021,63 +892,64 @@ void SendRPCRequest(){
...
@@ -1021,63 +892,64 @@ void SendRPCRequest(){
// BLSPublicKeyShare pubKey(make_shared<vector<string>>(pubKey_vect), t, n);
// BLSPublicKeyShare pubKey(make_shared<vector<string>>(pubKey_vect), t, n);
// REQUIRE( pubKey.VerifySigWithHelper(hash_arr, make_shared<BLSSigShare>(sig) , t, n));
// REQUIRE( pubKey.VerifySigWithHelper(hash_arr, make_shared<BLSSigShare>(sig) , t, n));
//koefs_pkeys_map[i+1] = make_shared<BLSPublicKeyShare>(pubKey);
//koefs_pkeys_map[i+1] = make_shared<BLSPublicKeyShare>(pubKey);
}
}
shared_ptr
<
BLSSignature
>
commonSig
=
sigShareSet
.
merge
();
shared_ptr
<
BLSSignature
>
commonSig
=
sigShareSet
.
merge
();
// BLSPublicKey common_public(make_shared<map<size_t, shared_ptr<BLSPublicKeyShare>>>(koefs_pkeys_map), t, n);
// BLSPublicKey common_public(make_shared<map<size_t, shared_ptr<BLSPublicKeyShare>>>(koefs_pkeys_map), t, n);
// REQUIRE( common_public.VerifySigWithHelper(hash_arr, commonSig, t, n) );
// REQUIRE( common_public.VerifySigWithHelper(hash_arr, commonSig, t, n) );
}
}
TEST_CASE
(
"ManySimultaneousThreads"
,
"[many_threads_test]"
)
{
TEST_CASE
(
"ManySimultaneousThreads"
,
"[many_threads_test]"
)
{
is_sgx_https
=
0
;
is_sgx_https
=
0
;
DEBUG_PRINT
=
1
;
DEBUG_PRINT
=
1
;
is_aes
=
1
;
is_aes
=
1
;
init_all
(
false
,
false
,
init_SEK
);
init_all
(
false
,
false
,
init_SEK
);
vector
<
thread
>
threads
;
vector
<
thread
>
threads
;
int
num_threads
=
4
;
int
num_threads
=
4
;
for
(
int
i
=
0
;
i
<
num_threads
;
i
++
)
{
for
(
int
i
=
0
;
i
<
num_threads
;
i
++
)
{
threads
.
push_back
(
thread
(
SendRPCRequest
));
threads
.
push_back
(
thread
(
SendRPCRequest
));
}
}
for
(
auto
&
thread
:
threads
)
{
for
(
auto
&
thread
:
threads
)
{
thread
.
join
();
thread
.
join
();
}
}
sgx_destroy_enclave
(
eid
);
sgx_destroy_enclave
(
eid
);
}
}
TEST_CASE
(
"ecdsa API test"
,
"[ecdsa_api_test]"
)
{
TEST_CASE
(
"ecdsa API test"
,
"[ecdsa_api_test]"
)
{
DEBUG_PRINT
=
1
;
DEBUG_PRINT
=
1
;
is_sgx_https
=
0
;
is_sgx_https
=
0
;
is_aes
=
1
;
is_aes
=
1
;
cerr
<<
"ecdsa_api_test started"
<<
endl
;
cerr
<<
"ecdsa_api_test started"
<<
endl
;
init_all
(
false
,
false
,
init_SEK
);
init_all
(
false
,
false
,
init_SEK
);
cerr
<<
"Server inited"
<<
endl
;
cerr
<<
"Server inited"
<<
endl
;
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
;
REQUIRE
(
genKey
[
"status"
].
asInt
()
==
0
);
REQUIRE
(
genKey
[
"status"
].
asInt
()
==
0
);
Json
::
Value
getPubKey
=
c
.
getPublicECDSAKey
(
genKey
[
"keyName"
].
asString
());
Json
::
Value
getPubKey
=
c
.
getPublicECDSAKey
(
genKey
[
"keyName"
].
asString
());
cout
<<
getPubKey
<<
endl
;
cout
<<
getPubKey
<<
endl
;
REQUIRE
(
getPubKey
[
"status"
].
asInt
()
==
0
);
REQUIRE
(
getPubKey
[
"status"
].
asInt
()
==
0
);
REQUIRE
(
getPubKey
[
"publicKey"
].
asString
()
==
genKey
[
"publicKey"
].
asString
());
REQUIRE
(
getPubKey
[
"publicKey"
].
asString
()
==
genKey
[
"publicKey"
].
asString
());
Json
::
Value
ecdsaSign
=
c
.
ecdsaSignMessageHash
(
16
,
genKey
[
"keyName"
].
asString
(),
"0x09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db"
);
Json
::
Value
ecdsaSign
=
c
.
ecdsaSignMessageHash
(
16
,
genKey
[
"keyName"
].
asString
(),
cout
<<
ecdsaSign
<<
endl
;
"0x09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db"
);
REQUIRE
(
ecdsaSign
[
"status"
].
asInt
()
==
0
);
cout
<<
ecdsaSign
<<
endl
;
REQUIRE
(
ecdsaSign
[
"status"
].
asInt
()
==
0
);
...
@@ -1099,266 +971,270 @@ TEST_CASE("ecdsa API test", "[ecdsa_api_test]") {
...
@@ -1099,266 +971,270 @@ TEST_CASE("ecdsa API test", "[ecdsa_api_test]") {
// cout << ecdsaSignWrongHash << endl;
// cout << ecdsaSignWrongHash << endl;
// REQUIRE(ecdsaSignWrongHash["status"].asInt() != 0);
// REQUIRE(ecdsaSignWrongHash["status"].asInt() != 0);
sgx_destroy_enclave
(
eid
);
sgx_destroy_enclave
(
eid
);
}
}
TEST_CASE
(
"dkg API test"
,
"[dkg_api_test]"
)
{
TEST_CASE
(
"dkg API test"
,
"[dkg_api_test]"
)
{
DEBUG_PRINT
=
1
;
DEBUG_PRINT
=
1
;
is_sgx_https
=
0
;
is_sgx_https
=
0
;
cerr
<<
"dkg_api_test started"
<<
endl
;
init_all
(
false
,
false
,
init_SEK
);
cerr
<<
"Server inited"
<<
endl
;
HttpClient
client
(
"http://localhost:1029"
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
cerr
<<
"Client inited"
<<
endl
;
reset_db
();
string
polyName
=
"POLY:SCHAIN_ID:1:NODE_ID:1:DKG_ID:1"
;
cerr
<<
"dkg_api_test started"
<<
endl
;
Json
::
Value
genPoly
=
c
.
generateDKGPoly
(
polyName
,
2
);
init_all
(
false
,
false
,
init_SEK
);
Json
::
Value
publicKeys
;
cerr
<<
"Server inited"
<<
endl
;
publicKeys
.
append
(
"505f55a38f9c064da744f217d1cb993a17705e9839801958cda7c884e08ab4dad7fd8d22953d3ac7f0913de24fd67d7ed36741141b8a3da152d7ba954b0f14e2
"
);
HttpClient
client
(
"http://localhost:1029
"
);
publicKeys
.
append
(
"378b3e6fdfe2633256ae1662fcd23466d02ead907b5d4366136341cea5e46f5a7bb67d897d6e35f619810238aa143c416f61c640ed214eb9c67a34c4a31b7d25"
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
// wrongName
cerr
<<
"Client inited"
<<
endl
;
Json
::
Value
genPolyWrongName
=
c
.
generateDKGPoly
(
"poly"
,
2
);
REQUIRE
(
genPolyWrongName
[
"status"
].
asInt
()
!=
0
);
cout
<<
genPolyWrongName
<<
endl
;
Json
::
Value
verifVectWrongName
=
c
.
getVerificationVector
(
"poly"
,
2
,
2
);
REQUIRE
(
verifVectWrongName
[
"status"
].
asInt
()
!=
0
);
cout
<<
verifVectWrongName
<<
endl
;
Json
::
Value
secretSharesWrongName
=
c
.
getSecretShare
(
"poly"
,
publicKeys
,
2
,
2
);
reset_db
();
REQUIRE
(
secretSharesWrongName
[
"status"
].
asInt
()
!=
0
);
cout
<<
secretSharesWrongName
<<
endl
;
// wrong_t
string
polyName
=
"POLY:SCHAIN_ID:1:NODE_ID:1:DKG_ID:1"
;
Json
::
Value
genPolyWrong_t
=
c
.
generateDKGPoly
(
polyName
,
33
);
Json
::
Value
genPoly
=
c
.
generateDKGPoly
(
polyName
,
2
);
REQUIRE
(
genPolyWrong_t
[
"status"
].
asInt
()
!=
0
);
cout
<<
genPolyWrong_t
<<
endl
;
Json
::
Value
publicKeys
;
publicKeys
.
append
(
"505f55a38f9c064da744f217d1cb993a17705e9839801958cda7c884e08ab4dad7fd8d22953d3ac7f0913de24fd67d7ed36741141b8a3da152d7ba954b0f14e2"
);
publicKeys
.
append
(
"378b3e6fdfe2633256ae1662fcd23466d02ead907b5d4366136341cea5e46f5a7bb67d897d6e35f619810238aa143c416f61c640ed214eb9c67a34c4a31b7d25"
);
// wrongName
Json
::
Value
genPolyWrongName
=
c
.
generateDKGPoly
(
"poly"
,
2
);
REQUIRE
(
genPolyWrongName
[
"status"
].
asInt
()
!=
0
);
cout
<<
genPolyWrongName
<<
endl
;
Json
::
Value
verifVectWrongName
=
c
.
getVerificationVector
(
"poly"
,
2
,
2
);
REQUIRE
(
verifVectWrongName
[
"status"
].
asInt
()
!=
0
);
cout
<<
verifVectWrongName
<<
endl
;
Json
::
Value
secretSharesWrongName
=
c
.
getSecretShare
(
"poly"
,
publicKeys
,
2
,
2
);
REQUIRE
(
secretSharesWrongName
[
"status"
].
asInt
()
!=
0
);
cout
<<
secretSharesWrongName
<<
endl
;
// wrong_t
Json
::
Value
genPolyWrong_t
=
c
.
generateDKGPoly
(
polyName
,
33
);
REQUIRE
(
genPolyWrong_t
[
"status"
].
asInt
()
!=
0
);
cout
<<
genPolyWrong_t
<<
endl
;
Json
::
Value
verifVectWrong_t
=
c
.
getVerificationVector
(
polyName
,
1
,
2
);
REQUIRE
(
verifVectWrong_t
[
"status"
].
asInt
()
!=
0
);
cout
<<
verifVectWrong_t
<<
endl
;
Json
::
Value
secretSharesWrong_t
=
c
.
getSecretShare
(
polyName
,
publicKeys
,
3
,
3
);
REQUIRE
(
secretSharesWrong_t
[
"status"
].
asInt
()
!=
0
);
cout
<<
secretSharesWrong_t
<<
endl
;
// wrong_n
Json
::
Value
verifVectWrong_n
=
c
.
getVerificationVector
(
polyName
,
2
,
1
);
REQUIRE
(
verifVectWrong_n
[
"status"
].
asInt
()
!=
0
);
cout
<<
verifVectWrong_n
<<
endl
;
Json
::
Value
publicKeys1
;
publicKeys1
.
append
(
"505f55a38f9c064da744f217d1cb993a17705e9839801958cda7c884e08ab4dad7fd8d22953d3ac7f0913de24fd67d7ed36741141b8a3da152d7ba954b0f14e2"
);
Json
::
Value
secretSharesWrong_n
=
c
.
getSecretShare
(
polyName
,
publicKeys1
,
2
,
1
);
REQUIRE
(
secretSharesWrong_n
[
"status"
].
asInt
()
!=
0
);
cout
<<
secretSharesWrong_n
<<
endl
;
//wrong number of publicKeys
Json
::
Value
secretSharesWrongPkeys
=
c
.
getSecretShare
(
polyName
,
publicKeys
,
2
,
3
);
REQUIRE
(
secretSharesWrongPkeys
[
"status"
].
asInt
()
!=
0
);
cout
<<
secretSharesWrongPkeys
<<
endl
;
//wrong verif
Json
::
Value
Skeys
=
c
.
getSecretShare
(
polyName
,
publicKeys
,
2
,
2
);
Json
::
Value
verifVect
=
c
.
getVerificationVector
(
polyName
,
2
,
2
);
Json
::
Value
verificationWrongSkeys
=
c
.
dkgVerification
(
""
,
""
,
""
,
2
,
2
,
1
);
REQUIRE
(
verificationWrongSkeys
[
"status"
].
asInt
()
!=
0
);
cout
<<
verificationWrongSkeys
<<
endl
;
sgx_destroy_enclave
(
eid
);
}
TEST_CASE
(
"isPolyExists test"
,
"[is_poly_test]"
)
{
DEBUG_PRINT
=
1
;
is_sgx_https
=
0
;
Json
::
Value
verifVectWrong_t
=
c
.
getVerificationVector
(
polyName
,
1
,
2
);
cerr
<<
"is_poly_test started"
<<
endl
;
REQUIRE
(
verifVectWrong_t
[
"status"
].
asInt
()
!=
0
);
init_all
(
false
,
false
,
init_SEK
);
cout
<<
verifVectWrong_t
<<
endl
;
Json
::
Value
secretSharesWrong_t
=
c
.
getSecretShare
(
polyName
,
publicKeys
,
3
,
3
)
;
cerr
<<
"Server inited"
<<
endl
;
REQUIRE
(
secretSharesWrong_t
[
"status"
].
asInt
()
!=
0
);
HttpClient
client
(
"http://localhost:1029"
);
cout
<<
secretSharesWrong_t
<<
endl
;
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
)
;
// wrong_n
cerr
<<
"Client inited"
<<
endl
;
Json
::
Value
verifVectWrong_n
=
c
.
getVerificationVector
(
polyName
,
2
,
1
);
REQUIRE
(
verifVectWrong_n
[
"status"
].
asInt
()
!=
0
);
cout
<<
verifVectWrong_n
<<
endl
;
Json
::
Value
publicKeys1
;
reset_db
();
publicKeys1
.
append
(
"505f55a38f9c064da744f217d1cb993a17705e9839801958cda7c884e08ab4dad7fd8d22953d3ac7f0913de24fd67d7ed36741141b8a3da152d7ba954b0f14e2"
);
Json
::
Value
secretSharesWrong_n
=
c
.
getSecretShare
(
polyName
,
publicKeys1
,
2
,
1
);
REQUIRE
(
secretSharesWrong_n
[
"status"
].
asInt
()
!=
0
);
cout
<<
secretSharesWrong_n
<<
endl
;
//wrong number of publicKeys
string
polyName
=
"POLY:SCHAIN_ID:1:NODE_ID:1:DKG_ID:1"
;
Json
::
Value
secretSharesWrongPkeys
=
c
.
getSecretShare
(
polyName
,
publicKeys
,
2
,
3
);
Json
::
Value
genPoly
=
c
.
generateDKGPoly
(
polyName
,
2
);
REQUIRE
(
secretSharesWrongPkeys
[
"status"
].
asInt
()
!=
0
);
cout
<<
genPoly
<<
endl
;
cout
<<
secretSharesWrongPkeys
<<
endl
;
Json
::
Value
polyExists
=
c
.
isPolyExists
(
polyName
);
cout
<<
polyExists
<<
endl
;
REQUIRE
(
polyExists
[
"IsExist"
].
asBool
());
//wrong verif
Json
::
Value
polyDoesNotExist
=
c
.
isPolyExists
(
"Vasya"
);
Json
::
Value
Skeys
=
c
.
getSecretShare
(
polyName
,
publicKeys
,
2
,
2
);
cout
<<
polyDoesNotExist
<<
endl
;
Json
::
Value
verifVect
=
c
.
getVerificationVector
(
polyName
,
2
,
2
);
REQUIRE
(
!
polyDoesNotExist
[
"IsExist"
].
asBool
());
Json
::
Value
verificationWrongSkeys
=
c
.
dkgVerification
(
""
,
""
,
""
,
2
,
2
,
1
);
REQUIRE
(
verificationWrongSkeys
[
"status"
].
asInt
()
!=
0
);
cout
<<
verificationWrongSkeys
<<
endl
;
sgx_destroy_enclave
(
eid
);
}
}
TEST_CASE
(
"isPolyExists test"
,
"[is_poly_test]"
)
{
TEST_CASE
(
"AES_DKG test"
,
"[aes_dkg]"
)
{
DEBUG_PRINT
=
1
;
is_sgx_https
=
0
;
cerr
<<
"is_poly_test started"
<<
endl
;
init_all
(
false
,
false
,
init_SEK
);
cerr
<<
"Server inited"
<<
endl
;
HttpClient
client
(
"http://localhost:1029"
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
cerr
<<
"Client inited"
<<
endl
;
reset_db
();
string
polyName
=
"POLY:SCHAIN_ID:1:NODE_ID:1:DKG_ID:1"
;
is_sgx_https
=
0
;
Json
::
Value
genPoly
=
c
.
generateDKGPoly
(
polyName
,
2
);
DEBUG_PRINT
=
1
;
cout
<<
genPoly
<<
endl
;
is_aes
=
1
;
Json
::
Value
polyExists
=
c
.
isPolyExists
(
polyName
);
cout
<<
polyExists
<<
endl
;
REQUIRE
(
polyExists
[
"IsExist"
].
asBool
());
Json
::
Value
polyDoesNotExist
=
c
.
isPolyExists
(
"Vasya"
);
reset_db
();
cout
<<
polyDoesNotExist
<<
endl
;
REQUIRE
(
!
polyDoesNotExist
[
"IsExist"
].
asBool
());
}
cerr
<<
"test started"
<<
endl
;
init_all
(
false
,
false
,
init_SEK
);
cerr
<<
"Server inited"
<<
endl
;
HttpClient
client
(
"http://localhost:1029"
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
cerr
<<
"Client inited"
<<
endl
;
TEST_CASE
(
"AES_DKG test"
,
"[aes_dkg]"
)
{
int
n
=
2
,
t
=
2
;
Json
::
Value
EthKeys
[
n
];
Json
::
Value
VerifVects
[
n
];
Json
::
Value
pubEthKeys
;
Json
::
Value
secretShares
[
n
];
Json
::
Value
pubBLSKeys
[
n
];
Json
::
Value
BLSSigShares
[
n
];
vector
<
string
>
pubShares
(
n
);
vector
<
string
>
poly_names
(
n
);
int
schain_id
=
rand_gen
();
int
dkg_id
=
rand_gen
();
for
(
uint8_t
i
=
0
;
i
<
n
;
i
++
)
{
EthKeys
[
i
]
=
c
.
generateECDSAKey
();
cerr
<<
"after gen key"
<<
endl
;
string
polyName
=
"POLY:SCHAIN_ID:"
+
to_string
(
schain_id
)
+
":NODE_ID:"
+
to_string
(
i
)
+
":DKG_ID:"
+
to_string
(
dkg_id
);
REQUIRE
(
EthKeys
[
i
][
"status"
]
==
0
);
cout
<<
c
.
generateDKGPoly
(
polyName
,
t
);
poly_names
[
i
]
=
polyName
;
VerifVects
[
i
]
=
c
.
getVerificationVector
(
polyName
,
t
,
n
);
cout
<<
"VV "
<<
i
<<
" "
<<
VerifVects
[
i
]
<<
endl
;
pubEthKeys
.
append
(
EthKeys
[
i
][
"publicKey"
]);
}
is_sgx_https
=
0
;
for
(
uint8_t
i
=
0
;
i
<
n
;
i
++
)
{
DEBUG_PRINT
=
1
;
secretShares
[
i
]
=
c
.
getSecretShare
(
poly_names
[
i
],
pubEthKeys
,
t
,
n
);
is_aes
=
1
;
cout
<<
secretShares
[
i
]
<<
endl
;
REQUIRE
(
secretShares
[
i
][
"status"
]
==
0
);
reset_db
();
for
(
uint8_t
k
=
0
;
k
<
t
;
k
++
)
for
(
uint8_t
j
=
0
;
j
<
4
;
j
++
)
{
std
::
cerr
<<
"test started"
<<
std
::
endl
;
string
pubShare
=
VerifVects
[
i
][
"verificationVector"
][
k
][
j
].
asString
();
init_all
(
false
,
false
,
init_SEK
);
pubShares
[
i
]
+=
ConvertDecToHex
(
pubShare
);
cerr
<<
"Server inited"
<<
endl
;
}
HttpClient
client
(
"http://localhost:1029"
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
cerr
<<
"Client inited"
<<
endl
;
int
n
=
2
,
t
=
2
;
Json
::
Value
EthKeys
[
n
];
Json
::
Value
VerifVects
[
n
];
Json
::
Value
pubEthKeys
;
Json
::
Value
secretShares
[
n
];
Json
::
Value
pubBLSKeys
[
n
];
Json
::
Value
BLSSigShares
[
n
];
vector
<
string
>
pubShares
(
n
);
vector
<
string
>
poly_names
(
n
);
int
schain_id
=
rand_gen
();
int
dkg_id
=
rand_gen
();
for
(
uint8_t
i
=
0
;
i
<
n
;
i
++
){
EthKeys
[
i
]
=
c
.
generateECDSAKey
();
std
::
cerr
<<
"after gen key"
<<
std
::
endl
;
string
polyName
=
"POLY:SCHAIN_ID:"
+
to_string
(
schain_id
)
+
":NODE_ID:"
+
to_string
(
i
)
+
":DKG_ID:"
+
to_string
(
dkg_id
);
REQUIRE
(
EthKeys
[
i
][
"status"
]
==
0
);
cout
<<
c
.
generateDKGPoly
(
polyName
,
t
);
poly_names
[
i
]
=
polyName
;
VerifVects
[
i
]
=
c
.
getVerificationVector
(
polyName
,
t
,
n
);
cout
<<
"VV "
<<
i
<<
" "
<<
VerifVects
[
i
]
<<
std
::
endl
;
pubEthKeys
.
append
(
EthKeys
[
i
][
"publicKey"
]);
}
for
(
uint8_t
i
=
0
;
i
<
n
;
i
++
){
secretShares
[
i
]
=
c
.
getSecretShare
(
poly_names
[
i
],
pubEthKeys
,
t
,
n
);
cout
<<
secretShares
[
i
]
<<
std
::
endl
;
REQUIRE
(
secretShares
[
i
][
"status"
]
==
0
);
for
(
uint8_t
k
=
0
;
k
<
t
;
k
++
)
for
(
uint8_t
j
=
0
;
j
<
4
;
j
++
){
string
pubShare
=
VerifVects
[
i
][
"verificationVector"
][
k
][
j
].
asString
();
pubShares
[
i
]
+=
ConvertDecToHex
(
pubShare
);
}
// pSharesBad[i][0] = 'q';
// pSharesBad[i][0] = 'q';
// Json::Value wrongVerif = c.dkgVerification(pSharesBad[i], EthKeys[j]["keyName"].asString(), secretShare, t, n, j);
// Json::Value wrongVerif = c.dkgVerification(pSharesBad[i], EthKeys[j]["keyName"].asString(), secretShare, t, n, j);
// res = wrongVerif["result"].asBool();
// res = wrongVerif["result"].asBool();
// REQUIRE(!res);
// REQUIRE(!res);
// cerr << "wrong verification " << wrongVerif << endl;
// cerr << "wrong verification " << wrongVerif << endl;
// }
// }
}
int
k
=
0
;
vector
<
string
>
secShares_vect
(
n
);
for
(
int
i
=
0
;
i
<
n
;
i
++
)
for
(
int
j
=
0
;
j
<
n
;
j
++
){
// if ( i != j ){
cerr
<<
"SecretShare length is "
<<
secretShares
[
i
][
"secretShare"
].
asString
().
length
()
<<
endl
;
string
secretShare
=
secretShares
[
i
][
"secretShare"
].
asString
().
substr
(
192
*
j
,
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
);
cout
<<
verif
;
bool
res
=
verif
[
"result"
].
asBool
();
k
++
;
cerr
<<
"NOW K IS "
<<
k
<<
" i is "
<<
i
<<
" j is "
<<
j
<<
endl
;
REQUIRE
(
res
);
// }
}
}
int
k
=
0
;
vector
<
string
>
secShares_vect
(
n
);
for
(
int
i
=
0
;
i
<
n
;
i
++
)
for
(
int
j
=
0
;
j
<
n
;
j
++
)
{
// if ( i != j ){
cerr
<<
"SecretShare length is "
<<
secretShares
[
i
][
"secretShare"
].
asString
().
length
()
<<
endl
;
string
secretShare
=
secretShares
[
i
][
"secretShare"
].
asString
().
substr
(
192
*
j
,
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
);
cout
<<
verif
;
bool
res
=
verif
[
"result"
].
asBool
();
k
++
;
cerr
<<
"NOW K IS "
<<
k
<<
" i is "
<<
i
<<
" j is "
<<
j
<<
endl
;
REQUIRE
(
res
);
// }
}
Json
::
Value
complaintResponse
=
c
.
complaintResponse
(
poly_names
[
1
],
0
);
cout
<<
complaintResponse
<<
endl
;
REQUIRE
(
complaintResponse
[
"status"
]
==
0
);
cerr
<<
"share * G2 is "
<<
complaintResponse
[
"share*G2"
].
asString
();
cerr
<<
"DHKey is "
<<
complaintResponse
[
"dhKey"
].
asString
();
BLSSigShareSet
sigShareSet
(
t
,
n
);
Json
::
Value
complaintResponse
=
c
.
complaintResponse
(
poly_names
[
1
],
0
);
string
hash
=
"09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db"
;
cout
<<
complaintResponse
<<
endl
;
REQUIRE
(
complaintResponse
[
"status"
]
==
0
);
cerr
<<
"share * G2 is "
<<
complaintResponse
[
"share*G2"
].
asString
();
cerr
<<
"DHKey is "
<<
complaintResponse
[
"dhKey"
].
asString
();
BLSSigShareSet
sigShareSet
(
t
,
n
);
string
hash
=
"09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db"
;
auto
hash_arr
=
make_shared
<
array
<
uint8_t
,
32
>>
();
auto
hash_arr
=
make_shared
<
array
<
uint8_t
,
32
>>
();
uint64_t
binLen
;
uint64_t
binLen
;
if
(
!
hex2carray
(
hash
.
c_str
(),
&
binLen
,
hash_arr
->
data
()))
{
if
(
!
hex2carray
(
hash
.
c_str
(),
&
binLen
,
hash_arr
->
data
()))
{
throw
RPCException
(
INVALID_HEX
,
"Invalid hash"
);
throw
RPCException
(
INVALID_HEX
,
"Invalid hash"
);
}
}
map
<
size_t
,
shared_ptr
<
BLSPublicKeyShare
>>
koefs_pkeys_map
;
map
<
size_t
,
shared_ptr
<
BLSPublicKeyShare
>>
koefs_pkeys_map
;
for
(
int
i
=
0
;
i
<
t
;
i
++
)
{
string
endName
=
poly_names
[
i
].
substr
(
4
);
string
blsName
=
"BLS_KEY"
+
poly_names
[
i
].
substr
(
4
);
cout
<<
c
.
createBLSPrivateKey
(
blsName
,
EthKeys
[
i
][
"keyName"
].
asString
(),
poly_names
[
i
],
secShares_vect
[
i
],
t
,
n
);
pubBLSKeys
[
i
]
=
c
.
getBLSPublicKeyShare
(
blsName
);
cout
<<
pubBLSKeys
[
i
]
<<
endl
;
REQUIRE
(
pubBLSKeys
[
i
][
"status"
]
==
0
);
cerr
<<
"BLS KEY SHARE NAME IS"
<<
blsName
<<
endl
;
string
hash
=
"09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db"
;
BLSSigShares
[
i
]
=
c
.
blsSignMessageHash
(
blsName
,
hash
,
t
,
n
,
i
+
1
);
cout
<<
BLSSigShares
[
i
]
<<
endl
;
REQUIRE
(
BLSSigShares
[
i
][
"status"
]
==
0
);
cerr
<<
i
<<
" sig share is created "
<<
endl
;
shared_ptr
<
string
>
sig_share_ptr
=
make_shared
<
string
>
(
BLSSigShares
[
i
][
"signatureShare"
].
asString
());
BLSSigShare
sig
(
sig_share_ptr
,
i
+
1
,
t
,
n
);
sigShareSet
.
addSigShare
(
make_shared
<
BLSSigShare
>
(
sig
));
vector
<
string
>
pubKey_vect
;
for
(
uint8_t
j
=
0
;
j
<
4
;
j
++
)
{
pubKey_vect
.
push_back
(
pubBLSKeys
[
i
][
"blsPublicKeyShare"
][
j
].
asString
());
}
BLSPublicKeyShare
pubKey
(
make_shared
<
vector
<
string
>>
(
pubKey_vect
),
t
,
n
);
REQUIRE
(
pubKey
.
VerifySigWithHelper
(
hash_arr
,
make_shared
<
BLSSigShare
>
(
sig
),
t
,
n
));
koefs_pkeys_map
[
i
+
1
]
=
make_shared
<
BLSPublicKeyShare
>
(
pubKey
);
for
(
int
i
=
0
;
i
<
t
;
i
++
){
string
endName
=
poly_names
[
i
].
substr
(
4
);
string
blsName
=
"BLS_KEY"
+
poly_names
[
i
].
substr
(
4
);
cout
<<
c
.
createBLSPrivateKey
(
blsName
,
EthKeys
[
i
][
"keyName"
].
asString
(),
poly_names
[
i
],
secShares_vect
[
i
],
t
,
n
);
pubBLSKeys
[
i
]
=
c
.
getBLSPublicKeyShare
(
blsName
);
cout
<<
pubBLSKeys
[
i
]
<<
endl
;
REQUIRE
(
pubBLSKeys
[
i
][
"status"
]
==
0
);
cerr
<<
"BLS KEY SHARE NAME IS"
<<
blsName
<<
endl
;
string
hash
=
"09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db"
;
BLSSigShares
[
i
]
=
c
.
blsSignMessageHash
(
blsName
,
hash
,
t
,
n
,
i
+
1
);
cout
<<
BLSSigShares
[
i
]
<<
std
::
endl
;
REQUIRE
(
BLSSigShares
[
i
][
"status"
]
==
0
);
cerr
<<
i
<<
" sig share is created "
<<
endl
;
shared_ptr
<
string
>
sig_share_ptr
=
make_shared
<
string
>
(
BLSSigShares
[
i
][
"signatureShare"
].
asString
());
BLSSigShare
sig
(
sig_share_ptr
,
i
+
1
,
t
,
n
);
sigShareSet
.
addSigShare
(
make_shared
<
BLSSigShare
>
(
sig
));
vector
<
string
>
pubKey_vect
;
for
(
uint8_t
j
=
0
;
j
<
4
;
j
++
){
pubKey_vect
.
push_back
(
pubBLSKeys
[
i
][
"blsPublicKeyShare"
][
j
].
asString
());
}
}
BLSPublicKeyShare
pubKey
(
make_shared
<
vector
<
string
>>
(
pubKey_vect
),
t
,
n
);
REQUIRE
(
pubKey
.
VerifySigWithHelper
(
hash_arr
,
make_shared
<
BLSSigShare
>
(
sig
)
,
t
,
n
));
koefs_pkeys_map
[
i
+
1
]
=
make_shared
<
BLSPublicKeyShare
>
(
pubKey
);
}
shared_ptr
<
BLSSignature
>
commonSig
=
sigShareSet
.
merge
();
BLSPublicKey
common_public
(
make_shared
<
map
<
size_t
,
shared_ptr
<
BLSPublicKeyShare
>>>
(
koefs_pkeys_map
),
t
,
n
);
shared_ptr
<
BLSSignature
>
commonSig
=
sigShareSet
.
merge
();
REQUIRE
(
common_public
.
VerifySigWithHelper
(
hash_arr
,
commonSig
,
t
,
n
));
BLSPublicKey
common_public
(
make_shared
<
map
<
size_t
,
shared_ptr
<
BLSPublicKeyShare
>>>
(
koefs_pkeys_map
),
t
,
n
);
REQUIRE
(
common_public
.
VerifySigWithHelper
(
hash_arr
,
commonSig
,
t
,
n
)
);
sgx_destroy_enclave
(
eid
);
sgx_destroy_enclave
(
eid
);
}
}
TEST_CASE
(
"bls_sign_api test"
,
"[bls_sign]"
)
{
TEST_CASE
(
"bls_sign_api test"
,
"[bls_sign]"
)
{
is_sgx_https
=
0
;
is_sgx_https
=
0
;
DEBUG_PRINT
=
1
;
DEBUG_PRINT
=
1
;
is_aes
=
1
;
is_aes
=
1
;
std
::
cerr
<<
"test started"
<<
std
::
endl
;
init_all
(
false
,
false
,
init_SEK
);
cerr
<<
"Server inited"
<<
endl
;
HttpClient
client
(
"http://localhost:1029"
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
cerr
<<
"Client inited"
<<
endl
;
string
hash
=
"09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db"
;
string
blsName
=
"BLS_KEY:SCHAIN_ID:323669558:NODE_ID:1:DKG_ID:338183455"
;
int
n
=
4
,
t
=
4
;
Json
::
Value
pubBLSKey
=
c
.
getBLSPublicKeyShare
(
blsName
);
cerr
<<
"test started"
<<
endl
;
REQUIRE
(
pubBLSKey
[
"status"
]
==
0
);
init_all
(
false
,
false
,
init_SEK
);
cout
<<
pubBLSKey
<<
endl
;
cerr
<<
"Server inited"
<<
endl
;
HttpClient
client
(
"http://localhost:1029"
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
cerr
<<
"Client inited"
<<
endl
;
string
hash
=
"09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db"
;
string
blsName
=
"BLS_KEY:SCHAIN_ID:323669558:NODE_ID:1:DKG_ID:338183455"
;
int
n
=
4
,
t
=
4
;
Json
::
Value
pubBLSKey
=
c
.
getBLSPublicKeyShare
(
blsName
);
REQUIRE
(
pubBLSKey
[
"status"
]
==
0
);
cout
<<
pubBLSKey
<<
endl
;
Json
::
Value
sign
=
c
.
blsSignMessageHash
(
blsName
,
hash
,
t
,
n
,
1
);
Json
::
Value
sign
=
c
.
blsSignMessageHash
(
blsName
,
hash
,
t
,
n
,
1
);
cout
<<
sign
<<
endl
;
cout
<<
sign
<<
endl
;
REQUIRE
(
sign
[
"status"
]
==
0
);
REQUIRE
(
sign
[
"status"
]
==
0
);
// vector<string> pubKey_vect;
// vector<string> pubKey_vect;
// for ( uint8_t j = 0; j < 4; j++){
// for ( uint8_t j = 0; j < 4; j++){
...
@@ -1378,31 +1254,119 @@ TEST_CASE("AES encrypt/decrypt", "[AES-encrypt-decrypt]") {
...
@@ -1378,31 +1254,119 @@ TEST_CASE("AES encrypt/decrypt", "[AES-encrypt-decrypt]") {
init_all
(
false
,
false
,
init_SEK
);
init_all
(
false
,
false
,
init_SEK
);
//init_enclave();
//init_enclave();
int
errStatus
=
-
1
;
int
errStatus
=
-
1
;
char
*
errMsg
=
(
char
*
)
calloc
(
BUF_LEN
,
1
)
;
vector
<
char
>
errMsg
(
BUF_LEN
,
0
);
;
uint32_t
enc_len
;
uint32_t
enc_len
;
string
key
=
"123456789"
;
vector
<
uint8_t
>
encrypted_key
(
BUF_LEN
,
0
);
std
::
string
key
=
"123456789"
;
status
=
encrypt_key_aes
(
eid
,
&
errStatus
,
errMsg
.
data
(),
key
.
c_str
(),
encrypted_key
.
data
(),
&
enc_len
);
uint8_t
encrypted_key
[
BUF_LEN
];
memset
(
encrypted_key
,
0
,
BUF_LEN
);
status
=
encrypt_key_aes
(
eid
,
&
errStatus
,
errMsg
,
key
.
c_str
(),
encrypted_key
,
&
enc_len
);
REQUIRE
(
status
==
0
);
REQUIRE
(
status
==
0
);
std
::
cerr
<<
"key encrypted with status "
<<
status
<<
" err msg "
<<
errMsg
<<
std
::
endl
;
cerr
<<
"key encrypted with status "
<<
status
<<
" err msg "
<<
errMsg
.
data
()
<<
endl
;
char
decr_key
[
BUF_LEN
];
vector
<
char
>
decr_key
(
BUF_LEN
,
0
);
memset
(
decr_key
,
0
,
BUF_LEN
);
status
=
decrypt_key_aes
(
eid
,
&
errStatus
,
errMsg
.
data
(),
encrypted_key
.
data
(),
enc_len
,
decr_key
.
data
());
status
=
decrypt_key_aes
(
eid
,
&
errStatus
,
errMsg
,
encrypted_key
,
enc_len
,
decr_key
);
REQUIRE
(
status
==
0
);
REQUIRE
(
status
==
0
);
std
::
cerr
<<
"key encrypted with status "
<<
status
<<
" err msg "
<<
errMsg
<<
std
::
endl
;
cerr
<<
"key encrypted with status "
<<
status
<<
" err msg "
<<
errMsg
.
data
()
<<
endl
;
std
::
cerr
<<
"decrypted key is "
<<
decr_key
<<
std
::
endl
;
cerr
<<
"decrypted key is "
<<
decr_key
.
data
()
<<
endl
;
REQUIRE
(
key
.
compare
(
decr_key
)
==
0
);
REQUIRE
(
key
.
compare
(
decr_key
.
data
())
==
0
);
sgx_destroy_enclave
(
eid
);
sgx_destroy_enclave
(
eid
);
}
}
//TEST_CASE("BLS key import", "[bls-key-import]") {
// reset_db();
// init_all(false, false);
//
//
//
// auto result = importBLSKeyShareImpl(TEST_BLS_KEY_SHARE, TEST_BLS_KEY_NAME, 2, 2, 1);
//
// REQUIRE(result["status"] == 0);
//
// REQUIRE(result["encryptedKeyShare"] != "");
//
//
//TEST_CASE("BLS sign test", "[bls-sign]") {
//
// //init_all();
// init_enclave();
//
// char* encryptedKeyHex ="04000200000000000406ffffff02000000000000000000000b000000000000ff0000000000000000813f8390f6228a568e181a4dadb6508e3e66f5247175d65dbd0d8c7fbfa4df45000000f000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000008000000000000000000000000000000000dc044ae0cd79faaf41e8a7abb412790476738a98b5b6ce95fa1a32db5551b0a0d867305f4de558c64fee730a1f62394633c7d4ca65e3a40b7883e89c2801c61918b01c5de8624a52963df6f4de8581bcbdd2f9b69720d4cc764e03a04c7a99314bfdb5d2d55deda2ca40cd691f093fb2ecbae24cdacdd4d5de93189c6dfd6792d7b95bd5e330aec3538e7a85d15793"; //encryptTestKey();
//
// REQUIRE(encryptedKeyHex != nullptr);
//
//
// // const char *hexHash = "001122334455667788" "001122334455667788" "001122334455667788" "001122334455667788";
// const char *hexHash = "3F891FDA3704F0368DAB65FA81EBE616F4AA2A0854995DA4DC0B59D2CADBD64F";
//
// char* hexHashBuf = (char*) calloc(BUF_LEN, 1);
//
// strncpy(hexHashBuf, hexHash, BUF_LEN);
//
// char sig[BUF_LEN];
// auto result = sign(encryptedKeyHex, hexHashBuf, 2, 2, 1, sig);
//
// REQUIRE(result == true);
// printf("Signature is: %s \n", sig );
//
//}
//
//TEST_CASE("Server BLS sign test", "[bls-server-sign]") {
//
// reset_db();
//
// init_all(false, false);
//
//
// auto result = importBLSKeyShareImpl( TEST_BLS_KEY_SHARE, TEST_BLS_KEY_NAME, 2, 2, 1);
//
// REQUIRE(result["status"] == 0);
//
// REQUIRE(result["encryptedKeyShare"] != "");
//
// const char *hexHash = "001122334455667788" "001122334455667788" "001122334455667788" "001122334455667788";
//
// REQUIRE_NOTHROW(result = blsSignMessageHashImpl(TEST_BLS_KEY_NAME, hexHash,2,2,1));
//
// if (result["status"] != 0) {
// printf("Error message: %s", result["errorMessage"].asString().c_str());
// }
//
//
// REQUIRE(result["status"] == 0);
// REQUIRE(result["signatureShare"] != "");
//
// printf("Signature is: %s \n", result["signatureShare"].asString().c_str());
//
//}
//TEST_CASE("KeysDB test", "[keys-db]") {
//
//
//
// reset_db();
// init_all();
//
//
// string key = TEST_BLS_KEY_SHARE;
// string value = TEST_BLS_KEY_SHARE;
//
//
//
// REQUIRE_THROWS(readKeyShare(key));
//
//
// writeKeyShare(key, value, 1, 2, 1);
//
// REQUIRE(readKeyShare(key) != nullptr);
//
//
//// put your test here
//}
}
}
\ No newline at end of file
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