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
6726b20e
Unverified
Commit
6726b20e
authored
Aug 28, 2020
by
Oleh Nikolaiev
Committed by
GitHub
Aug 28, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #156 from skalenetwork/feature/SKALE-2892-calculate-bls-public-keys
Feature/skale 2892 calculate bls public keys
parents
4efae96b
d5c34bc0
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
211 additions
and
107 deletions
+211
-107
BLSCrypto.cpp
BLSCrypto.cpp
+2
-2
DKGCrypto.cpp
DKGCrypto.cpp
+102
-4
DKGCrypto.h
DKGCrypto.h
+8
-0
SGXWalletServer.cpp
SGXWalletServer.cpp
+50
-42
SGXWalletServer.hpp
SGXWalletServer.hpp
+4
-8
TestUtils.cpp
TestUtils.cpp
+21
-7
abstractstubserver.h
abstractstubserver.h
+6
-13
secure_enclave.c
secure_enclave/secure_enclave.c
+0
-3
stubclient.h
stubclient.h
+15
-24
testw.cpp
testw.cpp
+3
-4
No files found.
BLSCrypto.cpp
View file @
6726b20e
...
...
@@ -59,10 +59,10 @@ std::string *FqToString(libff::alt_bn128_Fq *_fq) {
char
arr
[
mpz_sizeinbase
(
t
,
10
)
+
2
];
char
*
tmp
=
mpz_get_str
(
arr
,
10
,
t
);
mpz_get_str
(
arr
,
10
,
t
);
mpz_clear
(
t
);
return
new
std
::
string
(
tmp
);
return
new
std
::
string
(
arr
);
}
int
char2int
(
char
_input
)
{
...
...
DKGCrypto.cpp
View file @
6726b20e
...
...
@@ -30,8 +30,6 @@
#include "SGXWalletServer.hpp"
#include "SGXException.h"
#include <libff/algebra/curves/alt_bn128/alt_bn128_pp.hpp>
#include "third_party/spdlog/spdlog.h"
#include "common.h"
...
...
@@ -65,14 +63,65 @@ template<class T> string ConvertToString(T field_elem, int base = 10) {
char
arr
[
mpz_sizeinbase
(
t
,
base
)
+
2
];
char
*
tmp
=
mpz_get_str
(
arr
,
base
,
t
);
mpz_get_str
(
arr
,
base
,
t
);
mpz_clear
(
t
);
string
output
=
tmp
;
string
output
=
arr
;
return
output
;
}
string
convertHexToDec
(
const
string
&
hex_str
)
{
mpz_t
dec
;
mpz_init
(
dec
);
string
ret
=
""
;
try
{
if
(
mpz_set_str
(
dec
,
hex_str
.
c_str
(),
16
)
==
-
1
)
{
mpz_clear
(
dec
);
return
ret
;
}
char
arr
[
mpz_sizeinbase
(
dec
,
10
)
+
2
];
mpz_get_str
(
arr
,
10
,
dec
);
ret
=
arr
;
}
catch
(
exception
&
e
)
{
mpz_clear
(
dec
);
throw
SGXException
(
INCORRECT_STRING_CONVERSION
,
e
.
what
());
}
catch
(...)
{
mpz_clear
(
dec
);
throw
SGXException
(
UNKNOWN_ERROR
,
""
);
}
return
ret
;
}
string
convertG2ToString
(
const
libff
::
alt_bn128_G2
&
elem
,
int
base
,
const
string
&
delim
)
{
string
result
=
""
;
try
{
result
+=
ConvertToString
(
elem
.
X
.
c0
);
result
+=
delim
;
result
+=
ConvertToString
(
elem
.
X
.
c1
);
result
+=
delim
;
result
+=
ConvertToString
(
elem
.
Y
.
c0
);
result
+=
delim
;
result
+=
ConvertToString
(
elem
.
Y
.
c1
);
return
result
;
}
catch
(
exception
&
e
)
{
throw
SGXException
(
INCORRECT_STRING_CONVERSION
,
e
.
what
());
return
result
;
}
catch
(...)
{
throw
SGXException
(
UNKNOWN_ERROR
,
""
);
return
result
;
}
return
result
;
}
string
gen_dkg_poly
(
int
_t
)
{
vector
<
char
>
errMsg
(
1024
,
0
);
int
errStatus
=
0
;
...
...
@@ -318,6 +367,55 @@ vector<string> GetBLSPubKey(const char *encryptedKeyHex) {
return
pubKeyVect
;
}
vector
<
string
>
calculateAllBlsPublicKeys
(
const
vector
<
string
>&
public_shares
)
{
size_t
n
=
public_shares
.
size
();
size_t
t
=
public_shares
[
0
].
length
()
/
256
;
uint64_t
share_length
=
256
;
uint8_t
coord_length
=
64
;
vector
<
libff
::
alt_bn128_G2
>
public_keys
(
n
,
libff
::
alt_bn128_G2
::
zero
());
vector
<
libff
::
alt_bn128_G2
>
public_values
(
t
,
libff
::
alt_bn128_G2
::
zero
());
for
(
size_t
i
=
0
;
i
<
n
;
++
i
)
{
for
(
size_t
j
=
0
;
j
<
t
;
++
j
)
{
libff
::
alt_bn128_G2
public_share
;
uint64_t
pos0
=
share_length
*
j
;
string
x_c0_str
=
convertHexToDec
(
public_shares
[
i
].
substr
(
pos0
,
coord_length
));
string
x_c1_str
=
convertHexToDec
(
public_shares
[
i
].
substr
(
pos0
+
coord_length
,
coord_length
));
string
y_c0_str
=
convertHexToDec
(
public_shares
[
i
].
substr
(
pos0
+
2
*
coord_length
,
coord_length
));
string
y_c1_str
=
convertHexToDec
(
public_shares
[
i
].
substr
(
pos0
+
3
*
coord_length
,
coord_length
));
if
(
x_c0_str
==
""
||
x_c1_str
==
""
||
y_c0_str
==
""
||
y_c1_str
==
""
)
{
return
{};
}
public_share
.
X
.
c0
=
libff
::
alt_bn128_Fq
(
x_c0_str
.
c_str
());
public_share
.
X
.
c1
=
libff
::
alt_bn128_Fq
(
x_c1_str
.
c_str
());
public_share
.
Y
.
c0
=
libff
::
alt_bn128_Fq
(
y_c0_str
.
c_str
());
public_share
.
Y
.
c1
=
libff
::
alt_bn128_Fq
(
y_c1_str
.
c_str
());
public_share
.
Z
=
libff
::
alt_bn128_Fq2
::
one
();
public_values
[
j
]
=
public_values
[
j
]
+
public_share
;
}
}
for
(
size_t
i
=
0
;
i
<
n
;
++
i
)
{
for
(
size_t
j
=
0
;
j
<
t
;
++
j
)
{
public_keys
[
i
]
=
public_keys
[
i
]
+
libff
::
power
(
libff
::
alt_bn128_Fr
(
i
+
1
),
j
)
*
public_values
[
j
];
}
public_keys
[
i
].
to_affine_coordinates
();
}
vector
<
string
>
result
(
n
);
for
(
size_t
i
=
0
;
i
<
n
;
++
i
)
{
result
[
i
]
=
convertG2ToString
(
public_keys
[
i
]);
}
return
result
;
}
string
decryptDHKey
(
const
string
&
polyName
,
int
ind
)
{
vector
<
char
>
errMsg1
(
1024
,
0
);
int
errStatus
=
0
;
...
...
DKGCrypto.h
View file @
6726b20e
...
...
@@ -27,6 +27,8 @@
#include <string>
#include <vector>
#include <libff/algebra/curves/alt_bn128/alt_bn128_pp.hpp>
using
namespace
std
;
string
gen_dkg_poly
(
int
_t
);
...
...
@@ -47,6 +49,12 @@ vector<string> GetBLSPubKey(const char * encryptedKeyHex);
vector
<
string
>
mult_G2
(
const
string
&
x
);
string
convertHexToDec
(
const
string
&
hex_str
);
string
convertG2ToString
(
const
libff
::
alt_bn128_G2
&
elem
,
int
base
=
10
,
const
string
&
delim
=
":"
);
vector
<
string
>
calculateAllBlsPublicKeys
(
const
vector
<
string
>&
public_shares
);
bool
TestCreateBLSShare
(
const
char
*
s_shares
);
#endif //SGXD_DKGCRYPTO_H
SGXWalletServer.cpp
View file @
6726b20e
...
...
@@ -255,12 +255,6 @@ SGXWalletServer::blsSignMessageHashImpl(const string &_keyShareName, const strin
}
Json
::
Value
SGXWalletServer
::
importECDSAKeyImpl
(
const
string
&
_key
,
const
string
&
_keyName
)
{
INIT_RESULT
(
result
)
result
[
"encryptedKey"
]
=
""
;
RETURN_SUCCESS
(
result
)
}
Json
::
Value
SGXWalletServer
::
generateECDSAKeyImpl
()
{
spdlog
::
info
(
"Entering {}"
,
__FUNCTION__
);
INIT_RESULT
(
result
)
...
...
@@ -288,34 +282,6 @@ Json::Value SGXWalletServer::generateECDSAKeyImpl() {
RETURN_SUCCESS
(
result
);
}
Json
::
Value
SGXWalletServer
::
renameECDSAKeyImpl
(
const
string
&
_keyName
,
const
string
&
_tempKeyName
)
{
spdlog
::
info
(
"Entering {}"
,
__FUNCTION__
);
INIT_RESULT
(
result
)
result
[
"encryptedKey"
]
=
""
;
try
{
string
prefix
=
_tempKeyName
.
substr
(
0
,
8
);
if
(
prefix
!=
"tmp_NEK:"
)
{
throw
SGXException
(
UNKNOWN_ERROR
,
"invalid temp key name"
);
}
prefix
=
_keyName
.
substr
(
0
,
12
);
if
(
prefix
!=
"NEK_NODE_ID:"
)
{
throw
SGXException
(
UNKNOWN_ERROR
,
"invalid key name"
);
}
string
postfix
=
_keyName
.
substr
(
12
,
_keyName
.
length
());
if
(
!
isStringDec
(
postfix
))
{
throw
SGXException
(
UNKNOWN_ERROR
,
"invalid key name"
);
}
shared_ptr
<
string
>
encryptedKey
=
readFromDb
(
_tempKeyName
);
writeDataToDB
(
_keyName
,
*
encryptedKey
);
LevelDB
::
getLevelDb
()
->
deleteTempNEK
(
_tempKeyName
);
}
HANDLE_SGX_EXCEPTION
(
result
)
RETURN_SUCCESS
(
result
);
}
Json
::
Value
SGXWalletServer
::
ecdsaSignMessageHashImpl
(
int
_base
,
const
string
&
_keyName
,
const
string
&
_messageHash
)
{
spdlog
::
trace
(
"Entering {}"
,
__FUNCTION__
);
INIT_RESULT
(
result
)
...
...
@@ -562,6 +528,52 @@ Json::Value SGXWalletServer::getBLSPublicKeyShareImpl(const string &_blsKeyName)
RETURN_SUCCESS
(
result
);
}
Json
::
Value
SGXWalletServer
::
calculateAllBLSPublicKeysImpl
(
const
Json
::
Value
&
publicShares
,
int
t
,
int
n
)
{
spdlog
::
info
(
"Entering {}"
,
__FUNCTION__
);
INIT_RESULT
(
result
)
try
{
if
(
!
check_n_t
(
t
,
n
))
{
throw
SGXException
(
INVALID_DKG_PARAMS
,
"Invalid DKG parameters: n or t "
);
}
if
(
!
publicShares
.
isArray
())
{
throw
SGXException
(
INVALID_DKG_PARAMS
,
"Invalid public shares format"
);
}
if
(
publicShares
.
size
()
!=
(
uint64_t
)
n
)
{
throw
SGXException
(
INVALID_DKG_PARAMS
,
"Invalid length of public shares"
);
}
for
(
int
i
=
0
;
i
<
n
;
++
i
)
{
if
(
!
publicShares
[
i
].
isString
())
{
throw
SGXException
(
INVALID_DKG_PARAMS
,
"Invalid public shares parts format"
);
}
if
(
publicShares
[
i
].
asString
().
length
()
!=
(
uint64_t
)
256
*
t
)
{
throw
SGXException
(
INVALID_DKG_PARAMS
,
"Invalid length of public shares parts"
);
}
}
vector
<
string
>
public_shares
(
n
);
for
(
int
i
=
0
;
i
<
n
;
++
i
)
{
public_shares
[
i
]
=
publicShares
[
i
].
asString
();
}
vector
<
string
>
public_keys
=
calculateAllBlsPublicKeys
(
public_shares
);
if
(
public_keys
.
size
()
!=
n
)
{
throw
SGXException
(
UNKNOWN_ERROR
,
""
);
}
for
(
int
i
=
0
;
i
<
n
;
++
i
)
{
result
[
"publicKeys"
][
i
]
=
public_keys
[
i
];
}
}
HANDLE_SGX_EXCEPTION
(
result
)
RETURN_SUCCESS
(
result
);
}
Json
::
Value
SGXWalletServer
::
complaintResponseImpl
(
const
string
&
_polyName
,
int
_ind
)
{
spdlog
::
info
(
"Entering {}"
,
__FUNCTION__
);
INIT_RESULT
(
result
)
...
...
@@ -676,12 +688,12 @@ Json::Value SGXWalletServer::getBLSPublicKeyShare(const string &blsKeyName) {
return
getBLSPublicKeyShareImpl
(
blsKeyName
);
}
Json
::
Value
SGXWalletServer
::
generateECDSAKey
(
)
{
return
generateECDSAKeyImpl
(
);
Json
::
Value
SGXWalletServer
::
calculateAllBLSPublicKeys
(
const
Json
::
Value
&
publicShares
,
int
t
,
int
n
)
{
return
calculateAllBLSPublicKeysImpl
(
publicShares
,
t
,
n
);
}
Json
::
Value
SGXWalletServer
::
renameECDSAKey
(
const
string
&
_keyName
,
const
string
&
_tmpKeyName
)
{
return
renameECDSAKeyImpl
(
_keyName
,
_tmpKeyName
);
Json
::
Value
SGXWalletServer
::
generateECDSAKey
(
)
{
return
generateECDSAKeyImpl
(
);
}
Json
::
Value
SGXWalletServer
::
getPublicECDSAKey
(
const
string
&
_keyName
)
{
...
...
@@ -701,10 +713,6 @@ Json::Value SGXWalletServer::blsSignMessageHash(const string &_keyShareName, con
return
blsSignMessageHashImpl
(
_keyShareName
,
_messageHash
,
_t
,
_n
);
}
Json
::
Value
SGXWalletServer
::
importECDSAKey
(
const
string
&
_key
,
const
string
&
_keyName
)
{
return
importECDSAKeyImpl
(
_key
,
_keyName
);
}
Json
::
Value
SGXWalletServer
::
complaintResponse
(
const
string
&
polyName
,
int
ind
)
{
return
complaintResponseImpl
(
polyName
,
ind
);
}
...
...
SGXWalletServer.hpp
View file @
6726b20e
...
...
@@ -51,12 +51,8 @@ public:
virtual
Json
::
Value
blsSignMessageHash
(
const
string
&
_keyShareName
,
const
string
&
_messageHash
,
int
_t
,
int
_n
);
virtual
Json
::
Value
importECDSAKey
(
const
string
&
_key
,
const
string
&
_keyName
);
virtual
Json
::
Value
generateECDSAKey
();
virtual
Json
::
Value
renameECDSAKey
(
const
string
&
_keyName
,
const
string
&
_tmpKeyName
);
virtual
Json
::
Value
ecdsaSignMessageHash
(
int
_base
,
const
string
&
_keyShareName
,
const
string
&
_messageHash
);
...
...
@@ -78,6 +74,8 @@ public:
virtual
Json
::
Value
getBLSPublicKeyShare
(
const
string
&
blsKeyName
);
virtual
Json
::
Value
calculateAllBLSPublicKeys
(
const
Json
::
Value
&
publicShares
,
int
t
,
int
n
);
virtual
Json
::
Value
complaintResponse
(
const
string
&
polyName
,
int
ind
);
virtual
Json
::
Value
multG2
(
const
string
&
x
);
...
...
@@ -102,12 +100,8 @@ public:
static
Json
::
Value
blsSignMessageHashImpl
(
const
string
&
_keyShareName
,
const
string
&
_messageHash
,
int
t
,
int
n
);
static
Json
::
Value
importECDSAKeyImpl
(
const
string
&
_key
,
const
string
&
_keyName
);
static
Json
::
Value
generateECDSAKeyImpl
();
static
Json
::
Value
renameECDSAKeyImpl
(
const
string
&
_keyName
,
const
string
&
_tempKeyName
);
static
Json
::
Value
ecdsaSignMessageHashImpl
(
int
_base
,
const
string
&
keyName
,
const
string
&
_messageHash
);
static
Json
::
Value
getPublicECDSAKeyImpl
(
const
string
&
_keyName
);
...
...
@@ -128,6 +122,8 @@ public:
static
Json
::
Value
getBLSPublicKeyShareImpl
(
const
string
&
_blsKeyName
);
static
Json
::
Value
calculateAllBLSPublicKeysImpl
(
const
Json
::
Value
&
publicShares
,
int
t
,
int
n
);
static
Json
::
Value
complaintResponseImpl
(
const
string
&
_polyName
,
int
_ind
);
static
Json
::
Value
multG2Impl
(
const
string
&
_x
);
...
...
TestUtils.cpp
View file @
6726b20e
...
...
@@ -70,10 +70,10 @@ string TestUtils::stringFromFr(libff::alt_bn128_Fr &el) {
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_get_str
(
arr
,
10
,
t
);
mpz_clear
(
t
);
return
string
(
tmp
);
return
string
(
arr
);
}
...
...
@@ -196,14 +196,12 @@ void TestUtils::sendRPCRequest() {
secretShares
[
i
]
=
c
.
getSecretShare
(
polyNames
[
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
();
string
pubShare
=
verifVects
[
i
][
"
verification
Vector"
][
k
][
j
].
asString
();
pubShares
[
i
]
+=
convertDecToHex
(
pubShare
);
}
}
}
int
k
=
0
;
vector
<
string
>
secShares
(
n
);
for
(
int
i
=
0
;
i
<
n
;
i
++
)
...
...
@@ -212,8 +210,6 @@ void TestUtils::sendRPCRequest() {
secShares
[
i
]
+=
secretShares
[
j
][
"secretShare"
].
asString
().
substr
(
192
*
i
,
192
);
Json
::
Value
verif
=
c
.
dkgVerification
(
pubShares
[
i
],
ethKeys
[
j
][
"keyName"
].
asString
(),
secretShare
,
t
,
n
,
j
);
CHECK_STATE
(
verif
[
"status"
]
==
0
);
k
++
;
}
BLSSigShareSet
sigShareSet
(
t
,
n
);
...
...
@@ -228,6 +224,14 @@ void TestUtils::sendRPCRequest() {
map
<
size_t
,
shared_ptr
<
BLSPublicKeyShare
>>
coeffs_pkeys_map
;
Json
::
Value
publicShares
;
for
(
int
i
=
0
;
i
<
n
;
++
i
)
{
publicShares
[
"publicShares"
][
i
]
=
pubShares
[
i
];
}
Json
::
Value
blsPublicKeys
=
c
.
calculateAllBLSPublicKeys
(
publicShares
,
t
,
n
);
CHECK_STATE
(
blsPublicKeys
[
"status"
]
==
0
);
for
(
int
i
=
0
;
i
<
t
;
i
++
)
{
string
endName
=
polyNames
[
i
].
substr
(
4
);
string
blsName
=
"BLS_KEY"
+
polyNames
[
i
].
substr
(
4
);
...
...
@@ -238,6 +242,16 @@ void TestUtils::sendRPCRequest() {
pubBLSKeys
[
i
]
=
c
.
getBLSPublicKeyShare
(
blsName
);
CHECK_STATE
(
pubBLSKeys
[
i
][
"status"
]
==
0
);
libff
::
alt_bn128_G2
publicKey
(
libff
::
alt_bn128_Fq2
(
libff
::
alt_bn128_Fq
(
pubBLSKeys
[
i
][
"blsPublicKeyShare"
][
0
].
asCString
()),
libff
::
alt_bn128_Fq
(
pubBLSKeys
[
i
][
"blsPublicKeyShare"
][
1
].
asCString
())),
libff
::
alt_bn128_Fq2
(
libff
::
alt_bn128_Fq
(
pubBLSKeys
[
i
][
"blsPublicKeyShare"
][
2
].
asCString
()),
libff
::
alt_bn128_Fq
(
pubBLSKeys
[
i
][
"blsPublicKeyShare"
][
3
].
asCString
())),
libff
::
alt_bn128_Fq2
::
one
());
string
public_key_str
=
convertG2ToString
(
publicKey
);
CHECK_STATE
(
public_key_str
==
blsPublicKeys
[
"publicKeys"
][
i
].
asString
());
string
hash
=
SAMPLE_HASH
;
blsSigShares
[
i
]
=
c
.
blsSignMessageHash
(
blsName
,
hash
,
t
,
n
);
CHECK_STATE
(
blsSigShares
[
i
][
"status"
]
==
0
);
...
...
abstractstubserver.h
View file @
6726b20e
...
...
@@ -39,18 +39,17 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"importBLSKeyShare"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"keyShare"
,
jsonrpc
::
JSON_STRING
,
"keyShareName"
,
jsonrpc
::
JSON_STRING
,
NULL
),
&
AbstractStubServer
::
importBLSKeyShareI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"blsSignMessageHash"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"keyShareName"
,
jsonrpc
::
JSON_STRING
,
"messageHash"
,
jsonrpc
::
JSON_STRING
,
"t"
,
jsonrpc
::
JSON_INTEGER
,
"n"
,
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
(
"generateECDSAKey"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
NULL
),
&
AbstractStubServer
::
generateECDSAKeyI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"renameECDSAKey"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"keyName"
,
jsonrpc
::
JSON_STRING
,
"tempKeyName"
,
jsonrpc
::
JSON_STRING
,
NULL
),
&
AbstractStubServer
::
renameECDSAKeyI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"getPublicECDSAKey"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"keyName"
,
jsonrpc
::
JSON_STRING
,
NULL
),
&
AbstractStubServer
::
getPublicECDSAKeyI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"ecdsaSignMessageHash"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"base"
,
jsonrpc
::
JSON_INTEGER
,
"keyName"
,
jsonrpc
::
JSON_STRING
,
"messageHash"
,
jsonrpc
::
JSON_STRING
,
NULL
),
&
AbstractStubServer
::
ecdsaSignMessageHashI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"generateDKGPoly"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"polyName"
,
jsonrpc
::
JSON_STRING
,
"t"
,
jsonrpc
::
JSON_INTEGER
,
NULL
),
&
AbstractStubServer
::
generateDKGPolyI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"getVerificationVector"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"polyName"
,
jsonrpc
::
JSON_STRING
,
"t"
,
jsonrpc
::
JSON_INTEGER
,
"t"
,
jsonrpc
::
JSON_INTEGER
,
NULL
),
&
AbstractStubServer
::
getVerificationVectorI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"getVerificationVector"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"polyName"
,
jsonrpc
::
JSON_STRING
,
"t"
,
jsonrpc
::
JSON_INTEGER
,
NULL
),
&
AbstractStubServer
::
getVerificationVectorI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"getSecretShare"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"polyName"
,
jsonrpc
::
JSON_STRING
,
"publicKeys"
,
jsonrpc
::
JSON_ARRAY
,
"n"
,
jsonrpc
::
JSON_INTEGER
,
"t"
,
jsonrpc
::
JSON_INTEGER
,
NULL
),
&
AbstractStubServer
::
getSecretShareI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"dkgVerification"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"publicShares"
,
jsonrpc
::
JSON_STRING
,
"ethKeyName"
,
jsonrpc
::
JSON_STRING
,
"secretShare"
,
jsonrpc
::
JSON_STRING
,
"t"
,
jsonrpc
::
JSON_INTEGER
,
"n"
,
jsonrpc
::
JSON_INTEGER
,
"index"
,
jsonrpc
::
JSON_INTEGER
,
NULL
),
&
AbstractStubServer
::
dkgVerificationI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"createBLSPrivateKey"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"blsKeyName"
,
jsonrpc
::
JSON_STRING
,
"ethKeyName"
,
jsonrpc
::
JSON_STRING
,
"polyName"
,
jsonrpc
::
JSON_STRING
,
"secretShare"
,
jsonrpc
::
JSON_STRING
,
"t"
,
jsonrpc
::
JSON_INTEGER
,
"n"
,
jsonrpc
::
JSON_INTEGER
,
NULL
),
&
AbstractStubServer
::
createBLSPrivateKeyI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"getBLSPublicKeyShare"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"blsKeyName"
,
jsonrpc
::
JSON_STRING
,
NULL
),
&
AbstractStubServer
::
getBLSPublicKeyShareI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"calculateAllBLSPublicKeys"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"publicShares"
,
jsonrpc
::
JSON_ARRAY
,
"n"
,
jsonrpc
::
JSON_INTEGER
,
"t"
,
jsonrpc
::
JSON_INTEGER
,
NULL
),
&
AbstractStubServer
::
calculateAllBLSPublicKeysI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"complaintResponse"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"polyName"
,
jsonrpc
::
JSON_STRING
,
"ind"
,
jsonrpc
::
JSON_INTEGER
,
NULL
),
&
AbstractStubServer
::
complaintResponseI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"multG2"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"x"
,
jsonrpc
::
JSON_STRING
,
NULL
),
&
AbstractStubServer
::
multG2I
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"isPolyExists"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"polyName"
,
jsonrpc
::
JSON_STRING
,
NULL
),
&
AbstractStubServer
::
isPolyExistsI
);
...
...
@@ -69,18 +68,10 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
response
=
this
->
blsSignMessageHash
(
request
[
"keyShareName"
].
asString
(),
request
[
"messageHash"
].
asString
(),
request
[
"t"
].
asInt
(),
request
[
"n"
].
asInt
());
}
inline
virtual
void
importECDSAKeyI
(
const
Json
::
Value
&
request
,
Json
::
Value
&
response
)
{
response
=
this
->
importECDSAKey
(
request
[
"key"
].
asString
(),
request
[
"keyName"
].
asString
());
}
inline
virtual
void
generateECDSAKeyI
(
const
Json
::
Value
&
request
,
Json
::
Value
&
response
)
{
(
void
)
request
;
response
=
this
->
generateECDSAKey
();
}
inline
virtual
void
renameECDSAKeyI
(
const
Json
::
Value
&
request
,
Json
::
Value
&
response
)
{
response
=
this
->
renameECDSAKey
(
request
[
"keyName"
].
asString
(),
request
[
"tempKeyName"
].
asString
());
}
inline
virtual
void
getPublicECDSAKeyI
(
const
Json
::
Value
&
request
,
Json
::
Value
&
response
)
{
...
...
@@ -115,6 +106,9 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
{
response
=
this
->
getBLSPublicKeyShare
(
request
[
"blsKeyName"
].
asString
());
}
inline
virtual
void
calculateAllBLSPublicKeysI
(
const
Json
::
Value
&
request
,
Json
::
Value
&
response
)
{
response
=
this
->
calculateAllBLSPublicKeys
(
request
[
"publicShares"
],
request
[
"t"
].
asInt
(),
request
[
"n"
].
asInt
());
}
inline
virtual
void
complaintResponseI
(
const
Json
::
Value
&
request
,
Json
::
Value
&
response
)
{
response
=
this
->
complaintResponse
(
request
[
"polyName"
].
asString
(),
request
[
"ind"
].
asInt
());
...
...
@@ -147,9 +141,7 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
virtual
Json
::
Value
importBLSKeyShare
(
const
std
::
string
&
keyShare
,
const
std
::
string
&
keyShareName
)
=
0
;
virtual
Json
::
Value
blsSignMessageHash
(
const
std
::
string
&
keyShareName
,
const
std
::
string
&
messageHash
,
int
t
,
int
n
)
=
0
;
virtual
Json
::
Value
importECDSAKey
(
const
std
::
string
&
key
,
const
std
::
string
&
keyName
)
=
0
;
virtual
Json
::
Value
generateECDSAKey
()
=
0
;
virtual
Json
::
Value
renameECDSAKey
(
const
std
::
string
&
KeyName
,
const
std
::
string
&
tempKeyName
)
=
0
;
virtual
Json
::
Value
getPublicECDSAKey
(
const
std
::
string
&
keyName
)
=
0
;
virtual
Json
::
Value
ecdsaSignMessageHash
(
int
base
,
const
std
::
string
&
keyName
,
const
std
::
string
&
messageHash
)
=
0
;
...
...
@@ -159,6 +151,7 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
virtual
Json
::
Value
dkgVerification
(
const
std
::
string
&
publicShares
,
const
std
::
string
&
ethKeyName
,
const
std
::
string
&
SecretShare
,
int
t
,
int
n
,
int
index
)
=
0
;
virtual
Json
::
Value
createBLSPrivateKey
(
const
std
::
string
&
blsKeyName
,
const
std
::
string
&
ethKeyName
,
const
std
::
string
&
polyName
,
const
std
::
string
&
SecretShare
,
int
t
,
int
n
)
=
0
;
virtual
Json
::
Value
getBLSPublicKeyShare
(
const
std
::
string
&
blsKeyName
)
=
0
;
virtual
Json
::
Value
calculateAllBLSPublicKeys
(
const
Json
::
Value
&
publicShares
,
int
t
,
int
n
)
=
0
;
virtual
Json
::
Value
complaintResponse
(
const
std
::
string
&
polyName
,
int
ind
)
=
0
;
virtual
Json
::
Value
multG2
(
const
std
::
string
&
x
)
=
0
;
virtual
Json
::
Value
isPolyExists
(
const
std
::
string
&
polyName
)
=
0
;
...
...
secure_enclave/secure_enclave.c
View file @
6726b20e
...
...
@@ -962,9 +962,6 @@ void trustedCreateBlsKeyAES(int *errStatus, char *errString, const char *s_share
CHECK_STATUS
(
"session_key_recover failed"
);
common_key
[
64
]
=
0
;
SAFE_CHAR_BUF
(
decr_sshare
,
65
);
...
...
stubclient.h
View file @
6726b20e
...
...
@@ -6,6 +6,7 @@
#define JSONRPC_CPP_STUB_STUBCLIENT_H_
#include <jsonrpccpp/client.h>
#include <cassert>
class
StubClient
:
public
jsonrpc
::
Client
{
...
...
@@ -38,18 +39,6 @@ class StubClient : public jsonrpc::Client
throw
jsonrpc
::
JsonRpcException
(
jsonrpc
::
Errors
::
ERROR_CLIENT_INVALID_RESPONSE
,
result
.
toStyledString
());
}
Json
::
Value
importECDSAKey
(
const
std
::
string
&
key
,
const
std
::
string
&
keyName
)
{
Json
::
Value
p
;
p
[
"key"
]
=
key
;
p
[
"keyName"
]
=
keyName
;
Json
::
Value
result
=
this
->
CallMethod
(
"importECDSAKey"
,
p
);
if
(
result
.
isObject
())
return
result
;
else
throw
jsonrpc
::
JsonRpcException
(
jsonrpc
::
Errors
::
ERROR_CLIENT_INVALID_RESPONSE
,
result
.
toStyledString
());
}
Json
::
Value
generateECDSAKey
()
{
Json
::
Value
p
;
...
...
@@ -61,18 +50,6 @@ class StubClient : public jsonrpc::Client
throw
jsonrpc
::
JsonRpcException
(
jsonrpc
::
Errors
::
ERROR_CLIENT_INVALID_RESPONSE
,
result
.
toStyledString
());
}
Json
::
Value
renameECDSAKey
(
const
std
::
string
&
KeyName
,
const
std
::
string
&
tempKeyName
)
{
Json
::
Value
p
;
p
[
"keyName"
]
=
KeyName
;
p
[
"tempKeyName"
]
=
tempKeyName
;
Json
::
Value
result
=
this
->
CallMethod
(
"renameECDSAKey"
,
p
);
if
(
result
.
isObject
())
return
result
;
else
throw
jsonrpc
::
JsonRpcException
(
jsonrpc
::
Errors
::
ERROR_CLIENT_INVALID_RESPONSE
,
result
.
toStyledString
());
}
Json
::
Value
getPublicECDSAKey
(
const
std
::
string
&
keyName
)
{
Json
::
Value
p
;
...
...
@@ -180,6 +157,20 @@ class StubClient : public jsonrpc::Client
throw
jsonrpc
::
JsonRpcException
(
jsonrpc
::
Errors
::
ERROR_CLIENT_INVALID_RESPONSE
,
result
.
toStyledString
());
}
Json
::
Value
calculateAllBLSPublicKeys
(
const
Json
::
Value
&
publicShares
,
int
t
,
int
n
)
{
Json
::
Value
p
;
p
[
"publicShares"
]
=
publicShares
[
"publicShares"
];
p
[
"t"
]
=
t
;
p
[
"n"
]
=
n
;
Json
::
Value
result
=
this
->
CallMethod
(
"calculateAllBLSPublicKeys"
,
p
);
if
(
result
.
isObject
())
return
result
;
else
throw
jsonrpc
::
JsonRpcException
(
jsonrpc
::
Errors
::
ERROR_CLIENT_INVALID_RESPONSE
,
result
.
toStyledString
());
}
Json
::
Value
complaintResponse
(
const
std
::
string
&
polyName
,
int
ind
)
{
Json
::
Value
p
;
...
...
testw.cpp
View file @
6726b20e
...
...
@@ -286,15 +286,14 @@ TEST_CASE_METHOD(TestFixture, "DKG AES gen test", "[dkg-aes-gen]") {
REQUIRE
(
status
==
SGX_SUCCESS
);
REQUIRE
(
errStatus
==
SGX_SUCCESS
);
vector
<
char
>
secret
(
2490
,
0
);
vector
<
char
>
secret
(
BUF_LEN
,
0
);
vector
<
char
>
errMsg1
(
BUF_LEN
,
0
);
/*
status = trustedDecryptDkgSecretAES(eid, &errStatus, errMsg1.data(), encryptedDKGSecret.data(),
(uint8_t *) secret.data(), &encLen
);
status
=
trustedDecryptDkgSecretAES
(
eid
,
&
errStatus
,
errMsg1
.
data
(),
encryptedDKGSecret
.
data
(),
encLen
,
(
uint8_t
*
)
secret
.
data
()
);
REQUIRE
(
status
==
SGX_SUCCESS
);
REQUIRE
(
errStatus
==
SGX_SUCCESS
);
*/
}
...
...
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