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
Show 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
}
}
char
*
encryptBLSKeyShare2Hex
(
int
*
errStatus
,
char
*
err_string
,
const
char
*
_key
)
{
char
*
keyArray
=
(
char
*
)
calloc
(
BUF_LEN
,
1
);
uint8_t
*
encryptedKey
=
(
uint8_t
*
)
calloc
(
BUF_LEN
,
1
);
char
*
errMsg
=
(
char
*
)
calloc
(
BUF_LEN
,
1
);
strncpy
((
char
*
)
keyArray
,
(
char
*
)
_key
,
BUF_LEN
);
char
*
encryptBLSKeyShare2Hex
(
int
*
errStatus
,
char
*
err_string
,
const
char
*
_key
)
{
auto
keyArray
=
make_shared
<
vector
<
char
>>
(
BUF_LEN
,
0
);
auto
encryptedKey
=
make_shared
<
vector
<
uint8_t
>>
(
BUF_LEN
,
0
);
auto
errMsg
=
make_shared
<
vector
<
char
>>
(
BUF_LEN
,
0
);
strncpy
(
keyArray
->
data
(),
_key
,
BUF_LEN
);
*
errStatus
=
-
1
;
unsigned
int
encryptedLen
=
0
;
//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
)
{
spdlog
::
info
(
"errStatus is {}"
,
*
errStatus
);
spdlog
::
info
(
" errMsg is "
,
errMsg
);
spdlog
::
info
(
" errMsg is "
,
errMsg
->
data
()
);
}
if
(
status
!=
SGX_SUCCESS
)
{
...
...
@@ -339,13 +338,13 @@ char *encryptBLSKeyShare2Hex(int *errStatus, char *err_string, const char *_key)
}
if
(
*
errStatus
!=
0
)
{
throw
RPCException
(
-
666
,
errMsg
);
throw
RPCException
(
-
666
,
errMsg
->
data
()
);
}
char
*
result
=
(
char
*
)
calloc
(
2
*
BUF_LEN
,
1
);
carray2Hex
(
encryptedKey
,
encryptedLen
,
result
);
carray2Hex
(
encryptedKey
->
data
()
,
encryptedLen
,
result
);
return
result
;
}
...
...
BLSCrypto.h
View file @
f2b8271f
...
...
@@ -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
SGXWalletServer.cpp
View file @
f2b8271f
...
...
@@ -152,11 +152,13 @@ importBLSKeyShareImpl(const string &_keyShare, const string &_keyShareName, int
result
[
"errorMessage"
]
=
""
;
result
[
"encryptedKeyShare"
]
=
""
;
char
*
encryptedKeyShareHex
=
nullptr
;
try
{
// if ( !checkName(_keyShare, "BLS_KEY")){
// 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
)
{
throw
RPCException
(
UNKNOWN_ERROR
,
""
);
...
...
@@ -166,7 +168,7 @@ importBLSKeyShareImpl(const string &_keyShare, const string &_keyShareName, int
throw
RPCException
(
errStatus
,
errMsg
);
}
result
[
"encryptedKeyShare"
]
=
encryptedKeyShareHex
;
result
[
"encryptedKeyShare"
]
=
string
(
encryptedKeyShareHex
)
;
writeKeyShare
(
_keyShareName
,
encryptedKeyShareHex
,
index
,
n
,
t
);
...
...
@@ -175,6 +177,10 @@ importBLSKeyShareImpl(const string &_keyShare, const string &_keyShareName, int
result
[
"errorMessage"
]
=
_e
.
errString
;
}
if
(
encryptedKeyShareHex
!=
nullptr
)
{
free
(
encryptedKeyShareHex
);
}
return
result
;
}
...
...
testw.cpp
View file @
f2b8271f
...
...
@@ -34,19 +34,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <libff/algebra/fields/fp.hpp>
#include <dkg/dkg.h>
#include <jsonrpccpp/server/connectors/httpserver.h>
#include <libff/algebra/curves/alt_bn128/alt_bn128_pp.hpp>
#include <libff/algebra/exponentiation/exponentiation.hpp>
#include <libff/algebra/fields/fp.hpp>
#include <dkg/dkg.h>
#include "sgxwallet_common.h"
#include "create_enclave.h"
#include "secure_enclave_u.h"
...
...
@@ -54,46 +46,36 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <gmp.h>
#include <sgx_urts.h>
#include <stdio.h>
#include "BLSCrypto.h"
#include "ServerInit.h"
#include "DKGCrypto.h"
#include "RPCException.h"
#include "LevelDB.h"
#include "SGXWalletServer.hpp"
#include <sgx_tcrypto.h>
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#include "catch.hpp"
#include "stubclient.h"
#include "BLSSigShare.h"
#include "BLSSigShareSet.h"
#include "BLSPublicKeyShare.h"
#include "BLSPublicKey.h"
#include "SEKManager.h"
#include <thread>
#include "common.h"
#include "stubclient.h"
#include <jsonrpccpp/client/connectors/httpclient.h>
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_init
(
t
);
el
.
as_bigint
().
to_mpz
(
t
);
char
arr
[
mpz_sizeinbase
(
t
,
10
)
+
2
];
char
*
tmp
=
mpz_get_str
(
arr
,
10
,
t
);
mpz_clear
(
t
);
...
...
@@ -115,25 +97,22 @@ int updated;
#define TEST_BLS_KEY_NAME "SCHAIN:17:INDEX:5:KEY:1"
void
reset_db
()
{
//std::string db_name = SGXDATA_FOLDER + WALLETDB_NAME;
REQUIRE
(
system
(
"rm -rf "
WALLETDB_NAME
)
==
0
);
//string db_name = SGXDATA_FOLDER + WALLETDB_NAME;
REQUIRE
(
system
(
"rm -rf "
WALLETDB_NAME
)
==
0
);
}
char
*
encryptTestKey
()
{
char
*
encryptTestKey
()
{
const
char
*
key
=
TEST_BLS_KEY_SHARE
;
int
errStatus
=
-
1
;
char
*
errMsg
=
(
char
*
)
calloc
(
BUF_LEN
,
1
);
char
*
encryptedKeyHex
=
encryptBLSKeyShare2Hex
(
&
errStatus
,
errMsg
,
key
);
vector
<
char
>
errMsg
(
BUF_LEN
,
0
);;
char
*
encryptedKeyHex
=
encryptBLSKeyShare2Hex
(
&
errStatus
,
errMsg
.
data
(),
key
);
REQUIRE
(
encryptedKeyHex
!=
nullptr
);
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 %s
\n
"
,
encryptedKeyHex
);
...
...
@@ -142,13 +121,12 @@ char* encryptTestKey() {
TEST_CASE
(
"BLS key encrypt"
,
"[bls-key-encrypt]"
)
{
DEBUG_PRINT
=
1
;
is_sgx_https
=
0
;
init_all
(
false
,
false
,
init_SEK
);
char
*
key
=
encryptTestKey
();
char
*
key
=
encryptTestKey
();
REQUIRE
(
key
!=
nullptr
);
/*free*/
(
key
);
}
...
...
@@ -162,17 +140,16 @@ TEST_CASE("BLS key encrypt/decrypt", "[bls-key-encrypt-decrypt]") {
//init_enclave();
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
);
char
*
plaintextKey
=
decryptBLSKeyShareFromHex
(
&
errStatus
,
errMsg
.
data
(),
encryptedKey
);
char
*
plaintextKey
=
decryptBLSKeyShareFromHex
(
&
errStatus
,
errMsg
,
encryptedKey
);
free
(
encryptedKey
);
REQUIRE
(
errStatus
==
0
);
REQUIRE
(
strcmp
(
plaintextKey
,
TEST_BLS_KEY_SHARE
)
==
0
);
printf
(
"Decrypt key completed with status: %d %s
\n
"
,
errStatus
,
errMsg
);
...
...
@@ -181,186 +158,85 @@ TEST_CASE("BLS key encrypt/decrypt", "[bls-key-encrypt-decrypt]") {
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
//}
TEST_CASE
(
"DKG gen test"
,
"[dkg-gen]"
)
{
TEST_CASE
(
"DKG gen test"
,
"[dkg-gen]"
)
{
//init_all();
init_enclave
();
uint8_t
*
encrypted_dkg_secret
=
(
uint8_t
*
)
calloc
(
DKG_MAX_SEALED_LEN
,
1
);
vector
<
uint8_t
>
encrypted_dkg_secret
(
DKG_MAX_SEALED_LEN
,
0
);
vector
<
char
>
errMsg
(
1024
,
0
);
char
*
errMsg
=
(
char
*
)
calloc
(
1024
,
1
);
int
err_status
=
0
;
uint32_t
enc_len
=
0
;
status
=
gen_dkg_secret
(
eid
,
&
err_status
,
errMsg
,
encrypted_dkg_secret
,
&
enc_len
,
32
);
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
);
printf
(
"gen_dkg_secret completed with status: %d %s
\n
"
,
err_status
,
errMsg
.
data
()
);
printf
(
"
\n
Length: %d
\n
"
,
enc_len
);
char
*
secret
=
(
char
*
)
calloc
(
DKG_BUFER_LENGTH
,
sizeof
(
char
)
);
vector
<
char
>
secret
(
DKG_BUFER_LENGTH
,
0
);
char
*
errMsg1
=
(
char
*
)
calloc
(
1024
,
1
);
vector
<
char
>
errMsg1
(
1024
,
0
);
uint32_t
dec_len
;
status
=
decrypt_dkg_secret
(
eid
,
&
err_status
,
errMsg1
,
encrypted_dkg_secret
,
(
uint8_t
*
)
secret
,
&
dec_len
);
REQUIRE
(
status
==
SGX_SUCCESS
);
status
=
decrypt_dkg_secret
(
eid
,
&
err_status
,
errMsg1
.
data
(),
encrypted_dkg_secret
.
data
(),
(
uint8_t
*
)
secret
.
data
(),
&
dec_len
);
printf
(
"
\n
decrypt_dkg_secret completed with status: %d %s
\n
"
,
err_status
,
errMsg1
);
printf
(
"decrypted secret %s
\n\n
"
,
secret
);
printf
(
"secret length %d
\n
"
,
strlen
(
secret
));
printf
(
"decr length %d
\n
"
,
dec_len
);
REQUIRE
(
status
==
SGX_SUCCESS
);
free
(
errMsg
);
free
(
errMsg1
);
free
(
encrypted_dkg_secret
);
free
(
secret
);
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
);
sgx_destroy_enclave
(
eid
);
}
vector
<
libff
::
alt_bn128_Fr
>
SplitStringToFr
(
const
char
*
koefs
,
const
char
symbol
)
{
vector
<
libff
::
alt_bn128_Fr
>
SplitStringToFr
(
const
char
*
koefs
,
const
char
symbol
)
{
string
str
(
koefs
);
string
delim
;
delim
.
push_back
(
symbol
);
vector
<
libff
::
alt_bn128_Fr
>
tokens
;
size_t
prev
=
0
,
pos
=
0
;
do
{
do
{
pos
=
str
.
find
(
delim
,
prev
);
if
(
pos
==
string
::
npos
)
pos
=
str
.
length
();
string
token
=
str
.
substr
(
prev
,
pos
-
prev
);
string
token
=
str
.
substr
(
prev
,
pos
-
prev
);
if
(
!
token
.
empty
())
{
libff
::
alt_bn128_Fr
koef
(
token
.
c_str
());
tokens
.
push_back
(
koef
);
}
prev
=
pos
+
delim
.
length
();
}
while
(
pos
<
str
.
length
()
&&
prev
<
str
.
length
());
}
while
(
pos
<
str
.
length
()
&&
prev
<
str
.
length
());
return
tokens
;
}
vector
<
string
>
SplitStringTest
(
const
char
*
koefs
,
const
char
symbol
)
{
vector
<
string
>
SplitStringTest
(
const
char
*
koefs
,
const
char
symbol
)
{
libff
::
init_alt_bn128_params
();
string
str
(
koefs
);
string
delim
;
delim
.
push_back
(
symbol
);
vector
<
string
>
G2_strings
;
size_t
prev
=
0
,
pos
=
0
;
do
{
do
{
pos
=
str
.
find
(
delim
,
prev
);
if
(
pos
==
string
::
npos
)
pos
=
str
.
length
();
string
token
=
str
.
substr
(
prev
,
pos
-
prev
);
string
token
=
str
.
substr
(
prev
,
pos
-
prev
);
if
(
!
token
.
empty
())
{
string
koef
(
token
.
c_str
());
G2_strings
.
push_back
(
koef
);
}
prev
=
pos
+
delim
.
length
();
}
while
(
pos
<
str
.
length
()
&&
prev
<
str
.
length
());
}
while
(
pos
<
str
.
length
()
&&
prev
<
str
.
length
());
return
G2_strings
;
}
libff
::
alt_bn128_G2
VectStringToG2
(
const
vector
<
string
>
&
G2_str_vect
)
{
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
());
...
...
@@ -373,155 +249,146 @@ libff::alt_bn128_G2 VectStringToG2(const vector<string>& G2_str_vect){
return
koef
;
}
TEST_CASE
(
"DKG public shares test"
,
"[dkg-pub_shares]"
)
{
TEST_CASE
(
"DKG public shares test"
,
"[dkg-pub_shares]"
)
{
//init_all();
libff
::
init_alt_bn128_params
();
init_enclave
();
uint8_t
*
encrypted_dkg_secret
=
(
uint8_t
*
)
calloc
(
DKG_MAX_SEALED_LEN
,
1
);
vector
<
uint8_t
>
encrypted_dkg_secret
(
DKG_MAX_SEALED_LEN
,
0
);
vector
<
char
>
errMsg
(
1024
,
0
);
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
);
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);
char
*
errMsg1
=
(
char
*
)
calloc
(
1024
,
1
);
vector
<
char
>
errMsg1
(
1024
,
0
);
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
);
vector
<
char
>
public_shares
(
10000
,
0
);
status
=
get_public_shares
(
eid
,
&
err_status
,
errMsg1
.
data
(),
encrypted_dkg_secret
.
data
(),
enc_len
,
public_shares
.
data
(),
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
(),
':'
);
printf
(
"
\n
get_public_shares status: %d error %s
\n\n
"
,
err_status
,
errMsg1
.
data
()
);
printf
(
" LEN: %d
\n
"
,
strlen
(
public_shares
.
data
()
));
printf
(
" result: %s
\n
"
,
public_shares
.
data
()
);
vector
<
string
>
G2_strings
=
SplitString
(
public_shares
.
data
()
,
','
);
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
);
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
);
printf
(
"
\n
decrypt_dkg_secret completed with status: %d %s
\n
"
,
err_status
,
errMsg1
.
data
()
);
signatures
::
Dkg
dkg_obj
(
t
,
n
);
signatures
::
Dkg
dkg_obj
(
t
,
n
);
vector
<
libff
::
alt_bn128_Fr
>
poly
=
SplitStringToFr
((
char
*
)
secret
,
colon
);
vector
<
libff
::
alt_bn128_G2
>
pub_shares_dkg
=
dkg_obj
.
VerificationVector
(
poly
);
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
(
int
i
=
0
;
i
<
pub_shares_dkg
.
size
();
i
++
)
{
for
(
uint32_t
i
=
0
;
i
<
pub_shares_dkg
.
size
();
i
++
)
{
libff
::
alt_bn128_G2
el
=
pub_shares_dkg
.
at
(
i
);
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
);
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
);
REQUIRE
(
res
==
true
);
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_enclave
();
uint8_t
*
encrypted_key
=
(
uint8_t
*
)
calloc
(
BUF_LEN
,
1
);
char
*
errMsg
=
(
char
*
)
calloc
(
1024
,
1
);
char
*
result
=
(
char
*
)
calloc
(
130
,
1
);
vector
<
char
>
errMsg
(
1024
,
1
);
vector
<
char
>
result
(
130
,
1
);
int
err_status
=
0
;
uint32_t
enc_len
=
0
;
uint8_t
*
encrypted_dkg_secret
=
(
uint8_t
*
)
calloc
(
DKG_MAX_SEALED_LEN
,
1
);
status
=
gen_dkg_secret
(
eid
,
&
err_status
,
errMsg
,
encrypted_dkg_secret
,
&
enc_len
,
2
);
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
;
status
=
set_encrypted_dkg_poly
(
eid
,
&
err_status
,
errMsg
,
encrypted_dkg_secret
);
status
=
set_encrypted_dkg_poly
(
eid
,
&
err_status
,
errMsg
.
data
(),
encrypted_dkg_secret
.
data
()
);
REQUIRE
(
status
==
SGX_SUCCESS
);
cerr
<<
" poly set"
<<
endl
;
uint8_t
*
encr_pr_DHkey
=
(
uint8_t
*
)
calloc
(
1024
,
1
);
char
*
pub_key_x
=
(
char
*
)
calloc
(
1024
,
1
);
char
*
pub_key_y
=
(
char
*
)
calloc
(
1024
,
1
);
vector
<
uint8_t
>
encrPRDHKey
(
1024
,
0
);
string
pub_keyB
=
"c0152c48bf640449236036075d65898fded1e242c00acb45519ad5f788ea7cbf9a5df1559e7fc87932eee5478b1b9023de19df654395574a690843988c3ff475"
;
vector
<
char
>
s_shareG2
(
320
,
0
);
status
=
get_encr_sshare
(
eid
,
&
err_status
,
errMsg
.
data
(),
encrPRDHKey
.
data
(),
&
enc_len
,
result
.
data
(),
s_shareG2
.
data
(),
(
char
*
)
pub_keyB
.
data
(),
2
,
2
,
1
);
char
*
pub_keyB
=
"c0152c48bf640449236036075d65898fded1e242c00acb45519ad5f788ea7cbf9a5df1559e7fc87932eee5478b1b9023de19df654395574a690843988c3ff475"
;
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
);
printf
(
" get_encr_sshare completed with status: %d %s
\n
"
,
err_status
,
errMsg
.
data
()
);
cerr
<<
"secret share is "
<<
result
<<
endl
;
cerr
<<
"secret share is "
<<
result
.
data
()
<<
endl
;
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
);
char
*
result
=
(
char
*
)
calloc
(
130
,
1
);
vector
<
char
>
errMsg
(
1024
,
0
);
vector
<
char
>
result
(
130
,
0
);
int
err_status
=
0
;
uint32_t
enc_len
=
0
;
vector
<
uint8_t
>
encrypted_dkg_secret
(
DKG_MAX_SEALED_LEN
,
1
);
uint8_t
*
encrypted_dkg_secret
=
(
uint8_t
*
)
calloc
(
DKG_MAX_SEALED_LEN
,
1
);
status
=
gen_dkg_secret
(
eid
,
&
err_status
,
errMsg
,
encrypted_dkg_secret
,
&
enc_len
,
2
);
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
=
set_encrypted_dkg_poly
(
eid
,
&
err_status
,
errMsg
,
encrypted_dkg_secret
);
status
=
set_encrypted_dkg_poly
(
eid
,
&
err_status
,
errMsg
.
data
(),
encrypted_dkg_secret
.
data
()
);
REQUIRE
(
status
==
SGX_SUCCESS
);
cerr
<<
" poly set"
<<
endl
;
uint8_t
*
encr_pr_DHkey
=
(
uint8_t
*
)
calloc
(
1024
,
1
);
char
*
pub_key_x
=
(
char
*
)
calloc
(
1024
,
1
);
char
*
pub_key_y
=
(
char
*
)
calloc
(
1024
,
1
);
vector
<
uint8_t
>
encrPrDHKey
(
1024
,
0
);
char
*
pub_keyB
=
"c0152c48bf640449236036075d65898fded1e242c00acb45519ad5f788ea7cbf9a5df1559e7fc87932eee5478b1b9023de19df654395574a690843988c3ff475"
;
string
pub_keyB
=
"c0152c48bf640449236036075d65898fded1e242c00acb45519ad5f788ea7cbf9a5df1559e7fc87932eee5478b1b9023de19df654395574a690843988c3ff475"
;
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
);
vector
<
char
>
s_shareG2
(
320
,
0
);
status
=
get_encr_sshare
(
eid
,
&
err_status
,
errMsg
.
data
(),
encrPrDHKey
.
data
(),
&
enc_len
,
result
.
data
(),
s_shareG2
.
data
(),
(
char
*
)
pub_keyB
.
data
(),
2
,
2
,
1
);
REQUIRE
(
status
==
SGX_SUCCESS
);
printf
(
" get_encr_sshare completed with status: %d %s
\n
"
,
err_status
,
errMsg
);
printf
(
" get_encr_sshare completed with status: %d %s
\n
"
,
err_status
,
errMsg
.
data
()
);
cerr
<<
"secret share is "
<<
result
<<
endl
;
cerr
<<
"secret share is "
<<
result
.
data
()
<<
endl
;
sgx_destroy_enclave
(
eid
);
...
...
@@ -532,41 +399,43 @@ TEST_CASE("ECDSA keygen and signature test", "[ecdsa_test]") {
init_enclave
();
char
*
errMsg
=
(
char
*
)
calloc
(
1024
,
1
);
vector
<
char
>
errMsg
(
1024
,
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
);
vector
<
char
>
pub_key_y
(
1024
,
0
);
char
*
pub_key_x
=
(
char
*
)
calloc
(
1024
,
1
);
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
,
encr_pr_key
,
&
enc_len
,
pub_key_x
,
pub_key_y
);
printf
(
"
\n
errMsg %s
\n
"
,
errMsg
);
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
);
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
(
"
\n
was pub_key_y %s:
\n
"
,
pub_key_y
.
data
()
);
/*printf("\nencr priv_key : \n");
for ( int i = 0; i < 1024 ; i++)
printf("%u ", encr_pr_key[i]);*/
char
*
hex
=
"3F891FDA3704F0368DAB65FA81EBE616F4AA2A0854995DA4DC0B59D2CADBD64F"
;
string
hex
=
"3F891FDA3704F0368DAB65FA81EBE616F4AA2A0854995DA4DC0B59D2CADBD64F"
;
// char* hex = "0x09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db";
printf
(
"hash length %d "
,
strlen
(
hex
));
char
*
signature_r
=
(
char
*
)
calloc
(
1024
,
1
);
char
*
signature_s
=
(
char
*
)
calloc
(
1024
,
1
);
printf
(
"hash length %d "
,
hex
.
size
(
));
vector
<
char
>
signature_r
(
1024
,
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
);
status
=
ecdsa_sign1
(
eid
,
&
err_status
,
errMsg
.
data
(),
encr_pr_key
.
data
(),
enc_len
,
(
unsigned
char
*
)
hex
.
data
(),
signature_r
.
data
(),
signature_s
.
data
(),
&
signature_v
,
16
);
REQUIRE
(
status
==
SGX_SUCCESS
);
printf
(
"
\n
signature r : %s "
,
signature_r
);
printf
(
"
\n
signature s: %s "
,
signature_s
);
printf
(
"
\n
signature r : %s "
,
signature_r
.
data
()
);
printf
(
"
\n
signature s: %s "
,
signature_s
.
data
()
);
printf
(
"
\n
signature v: %u "
,
signature_v
);
printf
(
"
\n
%s
\n
"
,
errMsg
);
printf
(
"
\n
%s
\n
"
,
errMsg
.
data
()
);
free
(
errMsg
);
sgx_destroy_enclave
(
eid
);
printf
(
"the end of ecdsa test
\n
"
);
}
...
...
@@ -575,15 +444,15 @@ TEST_CASE("Test test", "[test_test]") {
init_enclave
();
char
*
errMsg
=
(
char
*
)
calloc
(
1024
,
1
);
vector
<
char
>
errMsg
(
1024
,
0
);
int
err_status
=
0
;
uint8_t
*
encr_pr_key
=
(
uint8_t
*
)
calloc
(
1024
,
1
);
char
*
pub_key_x
=
(
char
*
)
calloc
(
1024
,
1
);
char
*
pub_key_y
=
(
char
*
)
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
;
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
(),
pub_key_y
.
data
());
//printf("\nerrMsg %s\n", errMsg );
REQUIRE
(
status
==
SGX_SUCCESS
);
...
...
@@ -595,9 +464,6 @@ TEST_CASE("Test test", "[test_test]") {
//for ( int i = 0; i < 1024 ; i++)
// printf("%u ", encr_pr_key[i]);
//printf( "haha");
//free(errMsg);
sgx_destroy_enclave
(
eid
);
...
...
@@ -608,37 +474,38 @@ TEST_CASE("get public ECDSA key", "[get_pub_ecdsa_key_test]") {
//init_all();
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
);
char
*
pub_key_y
=
(
char
*
)
calloc
(
1024
,
1
);
vector
<
char
>
errMsg
(
1024
,
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
;
//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
);
printf
(
"
\n
errMsg %s
\n
"
,
errMsg
);
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
);
printf
(
"
\n
was pub_key_x %s length %d:
\n
"
,
pub_key_x
,
strlen
(
pub_key_x
));
printf
(
"
\n
was pub_key_y %s length %d:
\n
"
,
pub_key_y
,
strlen
(
pub_key_y
));
printf
(
"
\n
was pub_key_x %s length %d:
\n
"
,
pub_key_x
.
data
(),
strlen
(
pub_key_x
.
data
()
));
printf
(
"
\n
was pub_key_y %s length %d:
\n
"
,
pub_key_y
.
data
(),
strlen
(
pub_key_y
.
data
()
));
/*printf("\nencr priv_key %s: \n");
for ( int i = 0; i < 1024 ; i++)
printf("%u ", encr_pr_key[i]);*/
char
*
got_pub_key_x
=
(
char
*
)
calloc
(
1024
,
1
);
char
*
got_pub_key_y
=
(
char
*
)
calloc
(
1024
,
1
);
vector
<
char
>
got_pub_key_x
(
1024
,
0
);
vector
<
char
>
got_pub_key_y
(
1024
,
0
);
status
=
get_public_ecdsa_key
(
eid
,
&
err_status
,
errMsg
,
encr_pr_key
,
enc_len
,
got_pub_key_x
,
got_pub_key_y
);
status
=
get_public_ecdsa_key
(
eid
,
&
err_status
,
errMsg
.
data
(),
encr_pr_key
.
data
(),
enc_len
,
got_pub_key_x
.
data
(),
got_pub_key_y
.
data
());
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
);
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
());
free
(
errMsg
);
sgx_destroy_enclave
(
eid
);
}
...
...
@@ -656,19 +523,18 @@ 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
std
;
string
ConvertDecToHex
(
string
dec
,
int
numBytes
=
32
){
string
ConvertDecToHex
(
string
dec
,
int
numBytes
=
32
)
{
mpz_t
num
;
mpz_init
(
num
);
mpz_set_str
(
num
,
dec
.
c_str
(),
10
);
char
tmp
[
mpz_sizeinbase
(
num
,
16
)
+
2
]
;
char
*
hex
=
mpz_get_str
(
tmp
,
16
,
num
);
vector
<
char
>
tmp
(
mpz_sizeinbase
(
num
,
16
)
+
2
,
0
)
;
char
*
hex
=
mpz_get_str
(
tmp
.
data
()
,
16
,
num
);
string
result
=
hex
;
int
n_zeroes
=
numBytes
*
2
-
result
.
length
();
...
...
@@ -681,7 +547,7 @@ string ConvertDecToHex(string dec, int numBytes = 32){
TEST_CASE
(
"BLS_DKG test"
,
"[bls_dkg]"
)
{
is_sgx_https
=
0
;
DEBUG_PRINT
=
1
;
cerr
<<
"test started"
<<
endl
;
cerr
<<
"test started"
<<
endl
;
init_all
(
false
,
false
,
init_SEK
);
cerr
<<
"Server inited"
<<
endl
;
HttpClient
client
(
"http://localhost:1029"
);
...
...
@@ -703,9 +569,10 @@ TEST_CASE("BLS_DKG test", "[bls_dkg]") {
int
schain_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
();
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
;
...
...
@@ -716,14 +583,14 @@ TEST_CASE("BLS_DKG test", "[bls_dkg]") {
}
for
(
uint8_t
i
=
0
;
i
<
n
;
i
++
)
{
for
(
uint8_t
i
=
0
;
i
<
n
;
i
++
)
{
secretShares
[
i
]
=
c
.
getSecretShare
(
poly_names
[
i
],
pubEthKeys
,
t
,
n
);
cout
<<
secretShares
[
i
]
<<
std
::
endl
;
cout
<<
secretShares
[
i
]
<<
endl
;
REQUIRE
(
secretShares
[
i
][
"status"
]
==
0
);
for
(
uint8_t
k
=
0
;
k
<
t
;
k
++
)
{
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
);
REQUIRE
(
pubShare
.
length
()
>
60
);
pubShares
[
i
]
+=
ConvertDecToHex
(
pubShare
);
}
}
...
...
@@ -737,24 +604,26 @@ TEST_CASE("BLS_DKG test", "[bls_dkg]") {
int
k
=
0
;
vector
<
string
>
secShares_vect
(
n
);
vector
<
string
>
secShares_vect
(
n
);
vector
<
string
>
pSharesBad
(
pubShares
);
vector
<
string
>
pSharesBad
(
pubShares
);
for
(
int
i
=
0
;
i
<
n
;
i
++
)
for
(
int
j
=
0
;
j
<
n
;
j
++
)
{
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
();
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
);
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
();
REQUIRE
(
!
res
);
cerr
<<
"wrong verification "
<<
wrongVerif
<<
endl
;
...
...
@@ -767,19 +636,20 @@ TEST_CASE("BLS_DKG test", "[bls_dkg]") {
auto
hash_arr
=
make_shared
<
array
<
uint8_t
,
32
>>
();
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"
);
}
map
<
size_t
,
shared_ptr
<
BLSPublicKeyShare
>>
koefs_pkeys_map
;
for
(
int
i
=
0
;
i
<
t
;
i
++
)
{
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
);
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";
...
...
@@ -790,20 +660,19 @@ TEST_CASE("BLS_DKG test", "[bls_dkg]") {
sigShareSet
.
addSigShare
(
make_shared
<
BLSSigShare
>
(
sig
));
vector
<
string
>
pubKey_vect
;
for
(
uint8_t
j
=
0
;
j
<
4
;
j
++
)
{
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
));
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
();
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
));
}
...
...
@@ -836,7 +705,8 @@ TEST_CASE("API test", "[api_test]") {
Json
::
Value
genKey
=
c
.
generateECDSAKey
();
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
());
cout
<<
getPubKey
<<
endl
;
// cout << c.renameESDSAKey("NODE_1CHAIN_1","tmp_NEK:bcacde0d26c0ea2c7e649992e7f791e1fba2492f5b7ae63dadb799075167c7fc");
...
...
@@ -860,8 +730,10 @@ TEST_CASE("API test", "[api_test]") {
// 2,2);
Json
::
Value
publicKeys
;
publicKeys
.
append
(
"505f55a38f9c064da744f217d1cb993a17705e9839801958cda7c884e08ab4dad7fd8d22953d3ac7f0913de24fd67d7ed36741141b8a3da152d7ba954b0f14e2"
);
publicKeys
.
append
(
"378b3e6fdfe2633256ae1662fcd23466d02ead907b5d4366136341cea5e46f5a7bb67d897d6e35f619810238aa143c416f61c640ed214eb9c67a34c4a31b7d25"
);
publicKeys
.
append
(
"505f55a38f9c064da744f217d1cb993a17705e9839801958cda7c884e08ab4dad7fd8d22953d3ac7f0913de24fd67d7ed36741141b8a3da152d7ba954b0f14e2"
);
publicKeys
.
append
(
"378b3e6fdfe2633256ae1662fcd23466d02ead907b5d4366136341cea5e46f5a7bb67d897d6e35f619810238aa143c416f61c640ed214eb9c67a34c4a31b7d25"
);
// cout << c.getSecretShare("POLY:SCHAIN_ID:1:NODE_ID:1:DKG_ID:1", publicKeys, 2, 2);
// cout << c.generateDKGPoly("p3", 3);
// cout << c.getSecretShare("p3",
...
...
@@ -912,7 +784,7 @@ TEST_CASE("API test", "[api_test]") {
TEST_CASE
(
"getServerStatus test"
,
"[getServerStatus_test]"
)
{
is_sgx_https
=
0
;
init_all
(
false
,
false
,
init_SEK
);
init_all
(
false
,
false
,
init_SEK
);
HttpClient
client
(
"http://localhost:1029"
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
REQUIRE
(
c
.
getServerStatus
()[
"status"
]
==
0
);
...
...
@@ -920,8 +792,7 @@ TEST_CASE("getServerStatus test", "[getServerStatus_test]") {
}
void
SendRPCRequest
(){
void
SendRPCRequest
()
{
cout
<<
"Hello from thread "
<<
this_thread
::
get_id
()
<<
endl
;
HttpClient
client
(
"http://localhost:1029"
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
...
...
@@ -940,20 +811,21 @@ void SendRPCRequest(){
int
schain_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
();
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
;
VerifVects
[
i
]
=
c
.
getVerificationVector
(
polyName
,
t
,
n
);
REQUIRE
(
VerifVects
[
i
][
"status"
]
==
0
);
REQUIRE
(
VerifVects
[
i
][
"status"
]
==
0
);
cout
<<
"VV "
<<
i
<<
" "
<<
VerifVects
[
i
]
<<
endl
;
pubEthKeys
.
append
(
EthKeys
[
i
][
"publicKey"
]);
}
for
(
uint8_t
i
=
0
;
i
<
n
;
i
++
)
{
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
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
);
...
...
@@ -966,17 +838,16 @@ void SendRPCRequest(){
int
k
=
0
;
vector
<
string
>
secShares_vect
(
n
);
vector
<
string
>
secShares_vect
(
n
);
for
(
int
i
=
0
;
i
<
n
;
i
++
)
for
(
int
j
=
0
;
j
<
n
;
j
++
)
{
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
);
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 );
...
...
@@ -984,26 +855,26 @@ void SendRPCRequest(){
}
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
()))
{
if
(
!
hex2carray
(
hash
.
c_str
(),
&
binLen
,
hash_arr
->
data
()))
{
throw
RPCException
(
INVALID_HEX
,
"Invalid hash"
);
}
map
<
size_t
,
shared_ptr
<
BLSPublicKeyShare
>>
koefs_pkeys_map
;
for
(
int
i
=
0
;
i
<
t
;
i
++
)
{
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
);
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"
;
...
...
@@ -1030,22 +901,22 @@ void SendRPCRequest(){
// REQUIRE( common_public.VerifySigWithHelper(hash_arr, commonSig, t, n) );
}
}
TEST_CASE
(
"ManySimultaneousThreads"
,
"[many_threads_test]"
)
{
is_sgx_https
=
0
;
DEBUG_PRINT
=
1
;
is_aes
=
1
;
init_all
(
false
,
false
,
init_SEK
);
init_all
(
false
,
false
,
init_SEK
);
vector
<
thread
>
threads
;
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
));
}
for
(
auto
&
thread
:
threads
)
{
for
(
auto
&
thread
:
threads
)
{
thread
.
join
();
}
...
...
@@ -1075,7 +946,8 @@ TEST_CASE("ecdsa API test", "[ecdsa_api_test]") {
REQUIRE
(
getPubKey
[
"status"
].
asInt
()
==
0
);
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
(),
"0x09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db"
);
cout
<<
ecdsaSign
<<
endl
;
REQUIRE
(
ecdsaSign
[
"status"
].
asInt
()
==
0
);
...
...
@@ -1121,8 +993,10 @@ TEST_CASE("dkg API test", "[dkg_api_test]") {
Json
::
Value
genPoly
=
c
.
generateDKGPoly
(
polyName
,
2
);
Json
::
Value
publicKeys
;
publicKeys
.
append
(
"505f55a38f9c064da744f217d1cb993a17705e9839801958cda7c884e08ab4dad7fd8d22953d3ac7f0913de24fd67d7ed36741141b8a3da152d7ba954b0f14e2"
);
publicKeys
.
append
(
"378b3e6fdfe2633256ae1662fcd23466d02ead907b5d4366136341cea5e46f5a7bb67d897d6e35f619810238aa143c416f61c640ed214eb9c67a34c4a31b7d25"
);
publicKeys
.
append
(
"505f55a38f9c064da744f217d1cb993a17705e9839801958cda7c884e08ab4dad7fd8d22953d3ac7f0913de24fd67d7ed36741141b8a3da152d7ba954b0f14e2"
);
publicKeys
.
append
(
"378b3e6fdfe2633256ae1662fcd23466d02ead907b5d4366136341cea5e46f5a7bb67d897d6e35f619810238aa143c416f61c640ed214eb9c67a34c4a31b7d25"
);
// wrongName
Json
::
Value
genPolyWrongName
=
c
.
generateDKGPoly
(
"poly"
,
2
);
...
...
@@ -1156,7 +1030,8 @@ TEST_CASE("dkg API test", "[dkg_api_test]") {
cout
<<
verifVectWrong_n
<<
endl
;
Json
::
Value
publicKeys1
;
publicKeys1
.
append
(
"505f55a38f9c064da744f217d1cb993a17705e9839801958cda7c884e08ab4dad7fd8d22953d3ac7f0913de24fd67d7ed36741141b8a3da152d7ba954b0f14e2"
);
publicKeys1
.
append
(
"505f55a38f9c064da744f217d1cb993a17705e9839801958cda7c884e08ab4dad7fd8d22953d3ac7f0913de24fd67d7ed36741141b8a3da152d7ba954b0f14e2"
);
Json
::
Value
secretSharesWrong_n
=
c
.
getSecretShare
(
polyName
,
publicKeys1
,
2
,
1
);
REQUIRE
(
secretSharesWrong_n
[
"status"
].
asInt
()
!=
0
);
cout
<<
secretSharesWrong_n
<<
endl
;
...
...
@@ -1169,7 +1044,7 @@ TEST_CASE("dkg API test", "[dkg_api_test]") {
//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
);
Json
::
Value
verificationWrongSkeys
=
c
.
dkgVerification
(
""
,
""
,
""
,
2
,
2
,
1
);
REQUIRE
(
verificationWrongSkeys
[
"status"
].
asInt
()
!=
0
);
cout
<<
verificationWrongSkeys
<<
endl
;
...
...
@@ -1212,7 +1087,7 @@ TEST_CASE("AES_DKG test", "[aes_dkg]") {
reset_db
();
std
::
cerr
<<
"test started"
<<
std
::
endl
;
cerr
<<
"test started"
<<
endl
;
init_all
(
false
,
false
,
init_SEK
);
cerr
<<
"Server inited"
<<
endl
;
HttpClient
client
(
"http://localhost:1029"
);
...
...
@@ -1231,24 +1106,25 @@ TEST_CASE("AES_DKG test", "[aes_dkg]") {
int
schain_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
();
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
);
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
]
<<
std
::
endl
;
cout
<<
"VV "
<<
i
<<
" "
<<
VerifVects
[
i
]
<<
endl
;
pubEthKeys
.
append
(
EthKeys
[
i
][
"publicKey"
]);
}
for
(
uint8_t
i
=
0
;
i
<
n
;
i
++
)
{
for
(
uint8_t
i
=
0
;
i
<
n
;
i
++
)
{
secretShares
[
i
]
=
c
.
getSecretShare
(
poly_names
[
i
],
pubEthKeys
,
t
,
n
);
cout
<<
secretShares
[
i
]
<<
std
::
endl
;
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
++
)
{
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
);
}
...
...
@@ -1262,20 +1138,20 @@ TEST_CASE("AES_DKG test", "[aes_dkg]") {
}
int
k
=
0
;
vector
<
string
>
secShares_vect
(
n
);
vector
<
string
>
secShares_vect
(
n
);
for
(
int
i
=
0
;
i
<
n
;
i
++
)
for
(
int
j
=
0
;
j
<
n
;
j
++
)
{
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
);
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
);
REQUIRE
(
res
);
// }
}
...
...
@@ -1292,44 +1168,45 @@ TEST_CASE("AES_DKG test", "[aes_dkg]") {
auto
hash_arr
=
make_shared
<
array
<
uint8_t
,
32
>>
();
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"
);
}
map
<
size_t
,
shared_ptr
<
BLSPublicKeyShare
>>
koefs_pkeys_map
;
for
(
int
i
=
0
;
i
<
t
;
i
++
)
{
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
);
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
);
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
++
)
{
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
));
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
();
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
)
);
sgx_destroy_enclave
(
eid
);
}
...
...
@@ -1340,7 +1217,7 @@ TEST_CASE("bls_sign_api test", "[bls_sign]") {
DEBUG_PRINT
=
1
;
is_aes
=
1
;
std
::
cerr
<<
"test started"
<<
std
::
endl
;
cerr
<<
"test started"
<<
endl
;
init_all
(
false
,
false
,
init_SEK
);
cerr
<<
"Server inited"
<<
endl
;
HttpClient
client
(
"http://localhost:1029"
);
...
...
@@ -1355,7 +1232,6 @@ TEST_CASE("bls_sign_api test", "[bls_sign]") {
cout
<<
pubBLSKey
<<
endl
;
Json
::
Value
sign
=
c
.
blsSignMessageHash
(
blsName
,
hash
,
t
,
n
,
1
);
cout
<<
sign
<<
endl
;
REQUIRE
(
sign
[
"status"
]
==
0
);
...
...
@@ -1379,30 +1255,118 @@ TEST_CASE("AES encrypt/decrypt", "[AES-encrypt-decrypt]") {
//init_enclave();
int
errStatus
=
-
1
;
char
*
errMsg
=
(
char
*
)
calloc
(
BUF_LEN
,
1
)
;
vector
<
char
>
errMsg
(
BUF_LEN
,
0
);
;
uint32_t
enc_len
;
string
key
=
"123456789"
;
vector
<
uint8_t
>
encrypted_key
(
BUF_LEN
,
0
);
std
::
string
key
=
"123456789"
;
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
);
status
=
encrypt_key_aes
(
eid
,
&
errStatus
,
errMsg
.
data
(),
key
.
c_str
(),
encrypted_key
.
data
(),
&
enc_len
);
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
];
memset
(
decr_key
,
0
,
BUF_LEN
);
status
=
decrypt_key_aes
(
eid
,
&
errStatus
,
errMsg
,
encrypted_key
,
enc_len
,
decr_key
);
vector
<
char
>
decr_key
(
BUF_LEN
,
0
);
status
=
decrypt_key_aes
(
eid
,
&
errStatus
,
errMsg
.
data
(),
encrypted_key
.
data
(),
enc_len
,
decr_key
.
data
());
REQUIRE
(
status
==
0
);
std
::
cerr
<<
"key encrypted with status "
<<
status
<<
" err msg "
<<
errMsg
<<
std
::
endl
;
std
::
cerr
<<
"decrypted key is "
<<
decr_key
<<
std
::
endl
;
REQUIRE
(
key
.
compare
(
decr_key
)
==
0
);
cerr
<<
"key encrypted with status "
<<
status
<<
" err msg "
<<
errMsg
.
data
()
<<
endl
;
cerr
<<
"decrypted key is "
<<
decr_key
.
data
()
<<
endl
;
REQUIRE
(
key
.
compare
(
decr_key
.
data
())
==
0
);
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
//}
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