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
af2844db
Unverified
Commit
af2844db
authored
Oct 04, 2019
by
svetaro
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SKALE-1512-add-DKG-to-SGX Fix crash bls sign
parent
c3e05f2a
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
175 additions
and
31 deletions
+175
-31
BLSCrypto.cpp
BLSCrypto.cpp
+13
-1
BLSPrivateKeyShareSGX.cpp
BLSPrivateKeyShareSGX.cpp
+124
-7
BLSPrivateKeyShareSGX.h
BLSPrivateKeyShareSGX.h
+6
-0
Makefile.am
Makefile.am
+3
-3
SGXWalletServer.cpp
SGXWalletServer.cpp
+5
-4
SGXWalletServer.hpp
SGXWalletServer.hpp
+3
-3
abstractstubserver.h
abstractstubserver.h
+3
-3
configure.gmp
configure.gmp
+0
-0
spec.json
spec.json
+4
-1
stubclient.h
stubclient.h
+4
-1
testw.cpp
testw.cpp
+10
-8
No files found.
BLSCrypto.cpp
View file @
af2844db
...
@@ -97,15 +97,27 @@ bool sign(const char* _encryptedKeyHex, const char* _hashHex, size_t _t, size_t
...
@@ -97,15 +97,27 @@ bool sign(const char* _encryptedKeyHex, const char* _hashHex, size_t _t, size_t
uint64_t
binLen
;
uint64_t
binLen
;
hex2carray
(
_hashHex
,
&
binLen
,
hash
->
data
());
hex2carray
(
_hashHex
,
&
binLen
,
hash
->
data
());
// assert(binLen == hash->size());
auto
keyShare
=
std
::
make_shared
<
BLSPrivateKeyShareSGX
>
(
keyStr
,
_t
,
_n
);
auto
keyShare
=
std
::
make_shared
<
BLSPrivateKeyShareSGX
>
(
keyStr
,
_t
,
_n
);
auto
sigShare
=
keyShare
->
signWithHelperSGX
(
hash
,
_signerIndex
);
// {
auto
sigShare
=
keyShare
->
signWithHelperSGX
(
hash
,
_signerIndex
);
// }
auto
sigShareStr
=
sigShare
->
toString
();
auto
sigShareStr
=
sigShare
->
toString
();
strncpy
(
_sig
,
sigShareStr
->
c_str
(),
BUF_LEN
);
strncpy
(
_sig
,
sigShareStr
->
c_str
(),
BUF_LEN
);
//std::string sigShareStr = keyShare->signWithHelperSGXstr(hash, _signerIndex);
//strncpy(_sig, sigShareStr.c_str(), BUF_LEN);
// std::string test_sig = "8175162913343900215959836578795929492705714455632345516427532159927644835012:15265825550804683171644566522808807137117748565649051208189914766494241035855:9810286616503120081238481858289626967170509983220853777870754480048381194141:5";
// auto sig_ptr = std::make_shared<std::string>(test_sig);
// strncpy(_sig, sig_ptr->c_str(), BUF_LEN);
std
::
cerr
<<
"sig "
<<
_sig
<<
std
::
endl
;
return
true
;
return
true
;
}
}
...
...
BLSPrivateKeyShareSGX.cpp
View file @
af2844db
...
@@ -99,7 +99,7 @@ BLSPrivateKeyShareSGX::BLSPrivateKeyShareSGX(
...
@@ -99,7 +99,7 @@ BLSPrivateKeyShareSGX::BLSPrivateKeyShareSGX(
encryptedKeyHex
=
_encryptedKeyHex
;
encryptedKeyHex
=
_encryptedKeyHex
;
}
}
std
::
s
hared_ptr
<
BLSSigShare
>
BLSPrivateKeyShareSGX
::
signWithHelperSGX
(
std
::
s
tring
BLSPrivateKeyShareSGX
::
signWithHelperSGXstr
(
std
::
shared_ptr
<
std
::
array
<
uint8_t
,
32
>>
hash_byte_arr
,
std
::
shared_ptr
<
std
::
array
<
uint8_t
,
32
>>
hash_byte_arr
,
size_t
_signerIndex
)
{
size_t
_signerIndex
)
{
shared_ptr
<
signatures
::
Bls
>
obj
;
shared_ptr
<
signatures
::
Bls
>
obj
;
...
@@ -133,8 +133,6 @@ std::shared_ptr<BLSSigShare> BLSPrivateKeyShareSGX::signWithHelperSGX(
...
@@ -133,8 +133,6 @@ std::shared_ptr<BLSSigShare> BLSPrivateKeyShareSGX::signWithHelperSGX(
}
}
char
errMsg
[
BUF_LEN
];
char
errMsg
[
BUF_LEN
];
memset
(
errMsg
,
0
,
BUF_LEN
);
memset
(
errMsg
,
0
,
BUF_LEN
);
...
@@ -165,6 +163,10 @@ std::shared_ptr<BLSSigShare> BLSPrivateKeyShareSGX::signWithHelperSGX(
...
@@ -165,6 +163,10 @@ std::shared_ptr<BLSSigShare> BLSPrivateKeyShareSGX::signWithHelperSGX(
bls_sign_message
(
eid
,
&
errStatus
,
errMsg
,
encryptedKey
,
bls_sign_message
(
eid
,
&
errStatus
,
errMsg
,
encryptedKey
,
encryptedKeyHex
->
size
()
/
2
,
xStrArg
,
yStrArg
,
signature
);
encryptedKeyHex
->
size
()
/
2
,
xStrArg
,
yStrArg
,
signature
);
// strncpy(signature, "8175162913343900215959836578795929492705714455632345516427532159927644835012:15265825550804683171644566522808807137117748565649051208189914766494241035855", 1024);
printf
(
"---: %s
\n
"
,
signature
);
if
(
status
!=
SGX_SUCCESS
)
{
if
(
status
!=
SGX_SUCCESS
)
{
gmp_printf
(
"SGX enclave call to bls_sign_message failed: 0x%04x
\n
"
,
status
);
gmp_printf
(
"SGX enclave call to bls_sign_message failed: 0x%04x
\n
"
,
status
);
...
@@ -186,16 +188,131 @@ std::shared_ptr<BLSSigShare> BLSPrivateKeyShareSGX::signWithHelperSGX(
...
@@ -186,16 +188,131 @@ std::shared_ptr<BLSSigShare> BLSPrivateKeyShareSGX::signWithHelperSGX(
std
::
string
hint
=
BLSutils
::
ConvertToString
(
hash_with_hint
.
first
.
Y
)
+
":"
+
hash_with_hint
.
second
;
std
::
string
sig
=
signature
;
sig
.
append
(
":"
);
sig
.
append
(
hint
);
return
sig
;
}
std
::
shared_ptr
<
BLSSigShare
>
BLSPrivateKeyShareSGX
::
signWithHelperSGX
(
std
::
shared_ptr
<
std
::
array
<
uint8_t
,
32
>>
hash_byte_arr
,
size_t
_signerIndex
)
{
/* shared_ptr<signatures::Bls> obj;
if (_signerIndex == 0) {
BOOST_THROW_EXCEPTION(runtime_error("Zero signer index"));
}
if (hash_byte_arr == nullptr) {
BOOST_THROW_EXCEPTION(runtime_error("Hash is null"));
}
obj = make_shared<signatures::Bls>(
signatures::Bls(requiredSigners, totalSigners));
std::pair<libff::alt_bn128_G1, std::string> hash_with_hint =
obj->HashtoG1withHint(hash_byte_arr);
int errStatus = 0;
string* xStr = stringFromFq(&(hash_with_hint.first.X));
if (xStr == nullptr) {
BOOST_THROW_EXCEPTION(runtime_error("Null xStr"));
}
string* yStr = stringFromFq(&(hash_with_hint.first.Y));
if (xStr == nullptr) {
BOOST_THROW_EXCEPTION(runtime_error("Null yStr"));
}
char errMsg[BUF_LEN];
memset(errMsg, 0, BUF_LEN);
char xStrArg[BUF_LEN];
char yStrArg[BUF_LEN];
char signature [BUF_LEN];
memset(xStrArg, 0, BUF_LEN);
memset(yStrArg, 0, BUF_LEN);
strncpy(xStrArg, xStr->c_str(), BUF_LEN);
strncpy(yStrArg, yStr->c_str(), BUF_LEN);
size_t sz = 0;
uint8_t encryptedKey[BUF_LEN];
bool result = hex2carray(encryptedKeyHex->c_str(), &sz, encryptedKey);
if (!result) {
BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid hex encrypted key"));
}
cerr << "Key is " + *encryptedKeyHex << endl;
// sgx_status_t status =
// bls_sign_message(eid, &errStatus, errMsg, encryptedKey,
// encryptedKeyHex->size() / 2, xStrArg, yStrArg, signature);
strncpy(signature, "8175162913343900215959836578795929492705714455632345516427532159927644835012:15265825550804683171644566522808807137117748565649051208189914766494241035855", 1024);
printf("---: %s\n", signature);
// if (status != SGX_SUCCESS) {
// gmp_printf("SGX enclave call to bls_sign_message failed: 0x%04x\n", status);
// BOOST_THROW_EXCEPTION(runtime_error("SGX enclave call to bls_sign_message failed"));
// }
// if (errStatus != 0) {
// BOOST_THROW_EXCEPTION(runtime_error("Enclave bls_sign_message failed:" + to_string(errStatus) + ":" + errMsg ));
// return nullptr;
// }
int sigLen;
if ((sigLen = strnlen(signature, 10)) < 10) {
BOOST_THROW_EXCEPTION(runtime_error("Signature too short:" + to_string(sigLen)));
}
std::string hint = BLSutils::ConvertToString(hash_with_hint.first.Y) + ":" +
std::string hint = BLSutils::ConvertToString(hash_with_hint.first.Y) + ":" +
hash_with_hint.second;
hash_with_hint.second;
auto sig = make_shared<string>(signature);
auto sig = make_shared<string>(signature);
sig->append(":");
sig->append(":");
sig
->
append
(
hint
);
sig->append(hint);*/
std
::
string
signature
=
signWithHelperSGXstr
(
hash_byte_arr
,
_signerIndex
);
auto
s
=
make_shared
<
BLSSigShare
>
(
sig
,
_signerIndex
,
requiredSigners
,
auto
sig
=
make_shared
<
string
>
(
signature
);
totalSigners
);
//BLSSigShare* sig_test = new BLSSigShare(sig, _signerIndex, requiredSigners, totalSigners);
//std::string hello = "hello";
//std::cout << "HINT " << *((void**)&(sig_test->hint)) << std::endl;
//std::shared_ptr<BLSSigShare> s; s.reset( sig_test );//(sig, _signerIndex, requiredSigners,
//totalSigners);
std
::
shared_ptr
<
BLSSigShare
>
s
=
std
::
make_shared
<
BLSSigShare
>
(
sig
,
_signerIndex
,
requiredSigners
,
totalSigners
);
return
s
;
return
s
;
}
}
\ No newline at end of file
BLSPrivateKeyShareSGX.h
View file @
af2844db
...
@@ -41,8 +41,14 @@ public:
...
@@ -41,8 +41,14 @@ public:
signWithHelperSGX
(
std
::
shared_ptr
<
std
::
array
<
uint8_t
,
32
>>
_hash
,
signWithHelperSGX
(
std
::
shared_ptr
<
std
::
array
<
uint8_t
,
32
>>
_hash
,
size_t
_signerIndex
);
size_t
_signerIndex
);
std
::
string
signWithHelperSGXstr
(
std
::
shared_ptr
<
std
::
array
<
uint8_t
,
32
>>
hash_byte_arr
,
size_t
_signerIndex
);
BLSPrivateKeyShareSGX
(
std
::
shared_ptr
<
std
::
string
>
_encryptedKeyHex
,
BLSPrivateKeyShareSGX
(
std
::
shared_ptr
<
std
::
string
>
_encryptedKeyHex
,
size_t
_requiredSigners
,
size_t
_totalSigners
);
size_t
_requiredSigners
,
size_t
_totalSigners
);
};
};
#endif // LIBBLS_BLSPRIVATEKEYSHARE_H
#endif // LIBBLS_BLSPRIVATEKEYSHARE_H
Makefile.am
View file @
af2844db
...
@@ -41,9 +41,9 @@ secure_enclave.edl: secure_enclave/secure_enclave.edl
...
@@ -41,9 +41,9 @@ secure_enclave.edl: secure_enclave/secure_enclave.edl
## Additional automake variables
## Additional automake variables
##
##
#
# AM_CPPFLAGS +=
#
AM_CPPFLAGS += -g -Og
#
# AM_CFLAGS =
#
AM_CFLAGS = -g -Og
#
# AM_CXXFLAGS =
#
AM_CXXFLAGS = ${AM_CPPFLAGS}
AM_CPPFLAGS
+=
-Wall
-DSKALE_SGX
=
1
-DBINARY_OUTPUT
=
1
-Ileveldb
/include
-IlibBLS
/bls
-IlibBLS
/libff
-IlibBLS
-fno-builtin-memset
$(GMP_CPPFLAGS)
-I
.
AM_CPPFLAGS
+=
-Wall
-DSKALE_SGX
=
1
-DBINARY_OUTPUT
=
1
-Ileveldb
/include
-IlibBLS
/bls
-IlibBLS
/libff
-IlibBLS
-fno-builtin-memset
$(GMP_CPPFLAGS)
-I
.
...
...
SGXWalletServer.cpp
View file @
af2844db
...
@@ -84,7 +84,7 @@ importBLSKeyShareImpl(int index, const std::string &_keyShare, const std::string
...
@@ -84,7 +84,7 @@ importBLSKeyShareImpl(int index, const std::string &_keyShare, const std::string
return
result
;
return
result
;
}
}
Json
::
Value
blsSignMessageHashImpl
(
const
std
::
string
&
keyShareName
,
const
std
::
string
&
messageHash
)
{
Json
::
Value
blsSignMessageHashImpl
(
const
std
::
string
&
keyShareName
,
const
std
::
string
&
messageHash
,
int
n
,
int
t
,
int
signerIndex
)
{
Json
::
Value
result
;
Json
::
Value
result
;
result
[
"status"
]
=
-
1
;
result
[
"status"
]
=
-
1
;
result
[
"errorMessage"
]
=
"Unknown server error"
;
result
[
"errorMessage"
]
=
"Unknown server error"
;
...
@@ -115,7 +115,7 @@ Json::Value blsSignMessageHashImpl(const std::string &keyShareName, const std::s
...
@@ -115,7 +115,7 @@ Json::Value blsSignMessageHashImpl(const std::string &keyShareName, const std::s
}
}
try
{
try
{
if
(
!
sign
(
value
->
c_str
(),
messageHash
.
c_str
(),
2
,
2
,
1
,
signature
))
{
if
(
!
sign
(
value
->
c_str
(),
messageHash
.
c_str
(),
t
,
n
,
signerIndex
,
signature
))
{
result
[
"status"
]
=
-
1
;
result
[
"status"
]
=
-
1
;
result
[
"errorMessage"
]
=
"Could not sign"
;
result
[
"errorMessage"
]
=
"Could not sign"
;
return
result
;
return
result
;
...
@@ -288,8 +288,9 @@ SGXWalletServer::importBLSKeyShare(int index, const std::string &_keyShare, cons
...
@@ -288,8 +288,9 @@ SGXWalletServer::importBLSKeyShare(int index, const std::string &_keyShare, cons
}
}
Json
::
Value
SGXWalletServer
::
blsSignMessageHash
(
const
std
::
string
&
keyShareName
,
const
std
::
string
&
messageHash
)
{
Json
::
Value
SGXWalletServer
::
blsSignMessageHash
(
const
std
::
string
&
keyShareName
,
const
std
::
string
&
messageHash
,
int
n
,
return
blsSignMessageHashImpl
(
keyShareName
,
messageHash
);
int
t
,
int
signerIndex
)
{
return
blsSignMessageHashImpl
(
keyShareName
,
messageHash
,
n
,
t
,
signerIndex
);
}
}
...
...
SGXWalletServer.hpp
View file @
af2844db
...
@@ -19,11 +19,11 @@ public:
...
@@ -19,11 +19,11 @@ public:
SGXWalletServer
(
AbstractServerConnector
&
connector
,
serverVersion_t
type
);
SGXWalletServer
(
AbstractServerConnector
&
connector
,
serverVersion_t
type
);
virtual
Json
::
Value
importBLSKeyShare
(
int
index
,
const
std
::
string
&
keyShare
,
const
std
::
string
&
keyShareName
,
int
n
,
int
t
);
virtual
Json
::
Value
importBLSKeyShare
(
int
index
,
const
std
::
string
&
keyShare
,
const
std
::
string
&
keyShareName
,
int
n
,
int
t
);
virtual
Json
::
Value
blsSignMessageHash
(
const
std
::
string
&
keyShareName
,
const
std
::
string
&
messageHash
);
virtual
Json
::
Value
blsSignMessageHash
(
const
std
::
string
&
keyShareName
,
const
std
::
string
&
messageHash
,
int
n
,
int
t
,
int
signerIndex
);
virtual
Json
::
Value
importECDSAKey
(
const
std
::
string
&
key
,
const
std
::
string
&
keyName
);
virtual
Json
::
Value
importECDSAKey
(
const
std
::
string
&
key
,
const
std
::
string
&
keyName
);
virtual
Json
::
Value
generateECDSAKey
(
const
std
::
string
&
keyName
);
virtual
Json
::
Value
generateECDSAKey
(
const
std
::
string
&
keyName
);
virtual
Json
::
Value
ecdsaSignMessageHash
(
int
base
,
const
std
::
string
&
keyShareName
,
const
std
::
string
&
messageHash
);
virtual
Json
::
Value
ecdsaSignMessageHash
(
int
base
,
const
std
::
string
&
keyShareName
,
const
std
::
string
&
messageHash
);
virtual
Json
::
Value
getPublicECDSAKey
(
const
std
::
string
&
keyName
);
virtual
Json
::
Value
getPublicECDSAKey
(
const
std
::
string
&
keyName
);
virtual
Json
::
Value
generateDKGPoly
(
const
std
::
string
&
polyName
,
int
t
);
virtual
Json
::
Value
generateDKGPoly
(
const
std
::
string
&
polyName
,
int
t
);
...
@@ -42,7 +42,7 @@ void writeDKGPoly(const string &_polyName, const string &value);
...
@@ -42,7 +42,7 @@ void writeDKGPoly(const string &_polyName, const string &value);
Json
::
Value
importBLSKeyShareImpl
(
int
index
,
const
std
::
string
&
keyShare
,
const
std
::
string
&
keyShareName
,
int
n
,
int
t
);
Json
::
Value
importBLSKeyShareImpl
(
int
index
,
const
std
::
string
&
keyShare
,
const
std
::
string
&
keyShareName
,
int
n
,
int
t
);
Json
::
Value
blsSignMessageHashImpl
(
const
std
::
string
&
keyShareName
,
const
std
::
string
&
messageHash
);
Json
::
Value
blsSignMessageHashImpl
(
const
std
::
string
&
keyShareName
,
const
std
::
string
&
messageHash
,
int
n
,
int
t
,
int
signerIndex
);
Json
::
Value
importECDSAKeyImpl
(
const
std
::
string
&
key
,
const
std
::
string
&
keyName
);
Json
::
Value
importECDSAKeyImpl
(
const
std
::
string
&
key
,
const
std
::
string
&
keyName
);
Json
::
Value
generateECDSAKeyImpl
(
const
std
::
string
&
keyName
);
Json
::
Value
generateECDSAKeyImpl
(
const
std
::
string
&
keyName
);
...
...
abstractstubserver.h
View file @
af2844db
...
@@ -13,7 +13,7 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
...
@@ -13,7 +13,7 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
AbstractStubServer
(
jsonrpc
::
AbstractServerConnector
&
conn
,
jsonrpc
::
serverVersion_t
type
=
jsonrpc
::
JSONRPC_SERVER_V2
)
:
jsonrpc
::
AbstractServer
<
AbstractStubServer
>
(
conn
,
type
)
AbstractStubServer
(
jsonrpc
::
AbstractServerConnector
&
conn
,
jsonrpc
::
serverVersion_t
type
=
jsonrpc
::
JSONRPC_SERVER_V2
)
:
jsonrpc
::
AbstractServer
<
AbstractStubServer
>
(
conn
,
type
)
{
{
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"importBLSKeyShare"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"index"
,
jsonrpc
::
JSON_INTEGER
,
"keyShare"
,
jsonrpc
::
JSON_STRING
,
"keyShareName"
,
jsonrpc
::
JSON_STRING
,
"n"
,
jsonrpc
::
JSON_INTEGER
,
"t"
,
jsonrpc
::
JSON_INTEGER
,
NULL
),
&
AbstractStubServer
::
importBLSKeyShareI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"importBLSKeyShare"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"index"
,
jsonrpc
::
JSON_INTEGER
,
"keyShare"
,
jsonrpc
::
JSON_STRING
,
"keyShareName"
,
jsonrpc
::
JSON_STRING
,
"n"
,
jsonrpc
::
JSON_INTEGER
,
"t"
,
jsonrpc
::
JSON_INTEGER
,
NULL
),
&
AbstractStubServer
::
importBLSKeyShareI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"blsSignMessageHash"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"keyShareName"
,
jsonrpc
::
JSON_STRING
,
"messageHash"
,
jsonrpc
::
JSON_STRING
,
NULL
),
&
AbstractStubServer
::
blsSignMessageHashI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"blsSignMessageHash"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"keyShareName"
,
jsonrpc
::
JSON_STRING
,
"messageHash"
,
jsonrpc
::
JSON_STRING
,
"n"
,
jsonrpc
::
JSON_INTEGER
,
"signerIndex"
,
jsonrpc
::
JSON_INTEGER
,
"t"
,
jsonrpc
::
JSON_INTEGER
,
NULL
),
&
AbstractStubServer
::
blsSignMessageHashI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"importECDSAKey"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"key"
,
jsonrpc
::
JSON_STRING
,
"keyName"
,
jsonrpc
::
JSON_STRING
,
NULL
),
&
AbstractStubServer
::
importECDSAKeyI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"importECDSAKey"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"key"
,
jsonrpc
::
JSON_STRING
,
"keyName"
,
jsonrpc
::
JSON_STRING
,
NULL
),
&
AbstractStubServer
::
importECDSAKeyI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"generateECDSAKey"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"keyName"
,
jsonrpc
::
JSON_STRING
,
NULL
),
&
AbstractStubServer
::
generateECDSAKeyI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"generateECDSAKey"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"keyName"
,
jsonrpc
::
JSON_STRING
,
NULL
),
&
AbstractStubServer
::
generateECDSAKeyI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"getPublicECDSAKey"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"keyName"
,
jsonrpc
::
JSON_STRING
,
NULL
),
&
AbstractStubServer
::
getPublicECDSAKeyI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"getPublicECDSAKey"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"keyName"
,
jsonrpc
::
JSON_STRING
,
NULL
),
&
AbstractStubServer
::
getPublicECDSAKeyI
);
...
@@ -27,7 +27,7 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
...
@@ -27,7 +27,7 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
}
}
inline
virtual
void
blsSignMessageHashI
(
const
Json
::
Value
&
request
,
Json
::
Value
&
response
)
inline
virtual
void
blsSignMessageHashI
(
const
Json
::
Value
&
request
,
Json
::
Value
&
response
)
{
{
response
=
this
->
blsSignMessageHash
(
request
[
"keyShareName"
].
asString
(),
request
[
"messageHash"
].
asString
());
response
=
this
->
blsSignMessageHash
(
request
[
"keyShareName"
].
asString
(),
request
[
"messageHash"
].
asString
()
,
request
[
"n"
].
asInt
(),
request
[
"signerIndex"
].
asInt
(),
request
[
"t"
].
asInt
()
);
}
}
inline
virtual
void
importECDSAKeyI
(
const
Json
::
Value
&
request
,
Json
::
Value
&
response
)
inline
virtual
void
importECDSAKeyI
(
const
Json
::
Value
&
request
,
Json
::
Value
&
response
)
{
{
...
@@ -50,7 +50,7 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
...
@@ -50,7 +50,7 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
response
=
this
->
generateDKGPoly
(
request
[
"keyName"
].
asString
(),
request
[
"t"
].
asInt
());
response
=
this
->
generateDKGPoly
(
request
[
"keyName"
].
asString
(),
request
[
"t"
].
asInt
());
}
}
virtual
Json
::
Value
importBLSKeyShare
(
int
index
,
const
std
::
string
&
keyShare
,
const
std
::
string
&
keyShareName
,
int
n
,
int
t
)
=
0
;
virtual
Json
::
Value
importBLSKeyShare
(
int
index
,
const
std
::
string
&
keyShare
,
const
std
::
string
&
keyShareName
,
int
n
,
int
t
)
=
0
;
virtual
Json
::
Value
blsSignMessageHash
(
const
std
::
string
&
keyShareName
,
const
std
::
string
&
messageHash
)
=
0
;
virtual
Json
::
Value
blsSignMessageHash
(
const
std
::
string
&
keyShareName
,
const
std
::
string
&
messageHash
,
int
n
,
int
signerIndex
,
int
t
)
=
0
;
virtual
Json
::
Value
importECDSAKey
(
const
std
::
string
&
key
,
const
std
::
string
&
keyName
)
=
0
;
virtual
Json
::
Value
importECDSAKey
(
const
std
::
string
&
key
,
const
std
::
string
&
keyName
)
=
0
;
virtual
Json
::
Value
generateECDSAKey
(
const
std
::
string
&
keyName
)
=
0
;
virtual
Json
::
Value
generateECDSAKey
(
const
std
::
string
&
keyName
)
=
0
;
virtual
Json
::
Value
getPublicECDSAKey
(
const
std
::
string
&
keyName
)
=
0
;
virtual
Json
::
Value
getPublicECDSAKey
(
const
std
::
string
&
keyName
)
=
0
;
...
...
configure.gmp
100755 → 100644
View file @
af2844db
File mode changed from 100755 to 100644
spec.json
View file @
af2844db
...
@@ -19,7 +19,10 @@
...
@@ -19,7 +19,10 @@
"name"
:
"blsSignMessageHash"
,
"name"
:
"blsSignMessageHash"
,
"params"
:
{
"params"
:
{
"keyShareName"
:
"key1"
,
"keyShareName"
:
"key1"
,
"messageHash"
:
"1122334455"
"messageHash"
:
"1122334455"
,
"n"
:
2
,
"t"
:
2
,
"signerIndex"
:
1
},
},
"returns"
:
{
"returns"
:
{
"status"
:
0
,
"status"
:
0
,
...
...
stubclient.h
View file @
af2844db
...
@@ -26,11 +26,14 @@ class StubClient : public jsonrpc::Client
...
@@ -26,11 +26,14 @@ class StubClient : public jsonrpc::Client
else
else
throw
jsonrpc
::
JsonRpcException
(
jsonrpc
::
Errors
::
ERROR_CLIENT_INVALID_RESPONSE
,
result
.
toStyledString
());
throw
jsonrpc
::
JsonRpcException
(
jsonrpc
::
Errors
::
ERROR_CLIENT_INVALID_RESPONSE
,
result
.
toStyledString
());
}
}
Json
::
Value
blsSignMessageHash
(
const
std
::
string
&
keyShareName
,
const
std
::
string
&
messageHash
)
throw
(
jsonrpc
::
JsonRpcException
)
Json
::
Value
blsSignMessageHash
(
const
std
::
string
&
keyShareName
,
const
std
::
string
&
messageHash
,
int
n
,
int
signerIndex
,
int
t
)
throw
(
jsonrpc
::
JsonRpcException
)
{
{
Json
::
Value
p
;
Json
::
Value
p
;
p
[
"keyShareName"
]
=
keyShareName
;
p
[
"keyShareName"
]
=
keyShareName
;
p
[
"messageHash"
]
=
messageHash
;
p
[
"messageHash"
]
=
messageHash
;
p
[
"n"
]
=
n
;
p
[
"signerIndex"
]
=
signerIndex
;
p
[
"t"
]
=
t
;
Json
::
Value
result
=
this
->
CallMethod
(
"blsSignMessageHash"
,
p
);
Json
::
Value
result
=
this
->
CallMethod
(
"blsSignMessageHash"
,
p
);
if
(
result
.
isObject
())
if
(
result
.
isObject
())
return
result
;
return
result
;
...
...
testw.cpp
View file @
af2844db
...
@@ -180,23 +180,25 @@ TEST_CASE("BLS key import", "[bls-key-import]") {
...
@@ -180,23 +180,25 @@ TEST_CASE("BLS key import", "[bls-key-import]") {
TEST_CASE
(
"BLS sign test"
,
"[bls-sign]"
)
{
TEST_CASE
(
"BLS sign test"
,
"[bls-sign]"
)
{
init_all
();
//init_all();
init_enclave
();
char
*
encryptedKeyHex
=
encryptTestKey
();
char
*
encryptedKeyHex
=
"04000200000000000406ffffff02000000000000000000000b000000000000ff0000000000000000813f8390f6228a568e181a4dadb6508e3e66f5247175d65dbd0d8c7fbfa4df45000000f000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000008000000000000000000000000000000000dc044ae0cd79faaf41e8a7abb412790476738a98b5b6ce95fa1a32db5551b0a0d867305f4de558c64fee730a1f62394633c7d4ca65e3a40b7883e89c2801c61918b01c5de8624a52963df6f4de8581bcbdd2f9b69720d4cc764e03a04c7a99314bfdb5d2d55deda2ca40cd691f093fb2ecbae24cdacdd4d5de93189c6dfd6792d7b95bd5e330aec3538e7a85d15793"
;
//
encryptTestKey();
REQUIRE
(
encryptedKeyHex
!=
nullptr
);
REQUIRE
(
encryptedKeyHex
!=
nullptr
);
const
char
*
hexHash
=
"001122334455667788"
"001122334455667788"
"001122334455667788"
"001122334455667788"
;
// const char *hexHash = "001122334455667788" "001122334455667788" "001122334455667788" "001122334455667788";
const
char
*
hexHash
=
"3F891FDA3704F0368DAB65FA81EBE616F4AA2A0854995DA4DC0B59D2CADBD64F"
;
char
*
hexHashBuf
=
(
char
*
)
calloc
(
BUF_LEN
,
1
);
char
*
hexHashBuf
=
(
char
*
)
calloc
(
BUF_LEN
,
1
);
strncpy
(
hexHashBuf
,
hexHash
,
BUF_LEN
);
strncpy
(
hexHashBuf
,
hexHash
,
BUF_LEN
);
char
sig
[
BUF_LEN
];
char
sig
[
BUF_LEN
];
auto
result
=
sign
(
encryptedKeyHex
,
hexHashBuf
,
2
,
2
,
1
,
sig
);
REQUIRE
(
sign
(
encryptedKeyHex
,
hexHashBuf
,
2
,
2
,
1
,
sig
));
REQUIRE
(
result
==
true
);
printf
(
"Signature is: %s
\n
"
,
sig
);
printf
(
"Signature is: %s
\n
"
,
sig
);
}
}
...
@@ -215,7 +217,7 @@ TEST_CASE("Server BLS sign test", "[bls-server-sign]") {
...
@@ -215,7 +217,7 @@ TEST_CASE("Server BLS sign test", "[bls-server-sign]") {
const
char
*
hexHash
=
"001122334455667788"
"001122334455667788"
"001122334455667788"
"001122334455667788"
;
const
char
*
hexHash
=
"001122334455667788"
"001122334455667788"
"001122334455667788"
"001122334455667788"
;
REQUIRE_NOTHROW
(
result
=
blsSignMessageHashImpl
(
TEST_BLS_KEY_NAME
,
hexHash
));
REQUIRE_NOTHROW
(
result
=
blsSignMessageHashImpl
(
TEST_BLS_KEY_NAME
,
hexHash
,
2
,
2
,
1
));
if
(
result
[
"status"
]
!=
0
)
{
if
(
result
[
"status"
]
!=
0
)
{
printf
(
"Error message: %s"
,
result
[
"errorMessage"
].
asString
().
c_str
());
printf
(
"Error message: %s"
,
result
[
"errorMessage"
].
asString
().
c_str
());
...
@@ -637,8 +639,8 @@ TEST_CASE("API test", "[api_test]") {
...
@@ -637,8 +639,8 @@ TEST_CASE("API test", "[api_test]") {
// cout << c.generateECDSAKey("known_key1") << endl;
// cout << c.generateECDSAKey("known_key1") << endl;
//cout<<c.getPublicECDSAKey("test_key");
//cout<<c.getPublicECDSAKey("test_key");
//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
.
generateDKGPoly
(
"poly"
,
3
);
//
cout << c.generateDKGPoly("poly", 3);
}
catch
(
JsonRpcException
&
e
)
{
}
catch
(
JsonRpcException
&
e
)
{
cerr
<<
e
.
what
()
<<
endl
;
cerr
<<
e
.
what
()
<<
endl
;
}
}
...
...
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