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
11f0cfb2
Unverified
Commit
11f0cfb2
authored
Aug 31, 2020
by
kladko
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' into bug/SKALE-3170-backup-key
parents
890023df
6726b20e
Changes
18
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
327 additions
and
271 deletions
+327
-271
BLSCrypto.cpp
BLSCrypto.cpp
+7
-8
BLSCrypto.h
BLSCrypto.h
+1
-2
DKGCrypto.cpp
DKGCrypto.cpp
+102
-4
DKGCrypto.h
DKGCrypto.h
+8
-0
SGXWalletServer.cpp
SGXWalletServer.cpp
+82
-70
SGXWalletServer.hpp
SGXWalletServer.hpp
+9
-15
TestUtils.cpp
TestUtils.cpp
+23
-9
abstractstubserver.h
abstractstubserver.h
+12
-19
docker-compose.yml
run_sgx_sim/docker-compose.yml
+1
-2
DHDkg.c
secure_enclave/DHDkg.c
+10
-36
DKGUtils.cpp
secure_enclave/DKGUtils.cpp
+27
-40
EnclaveCommon.cpp
secure_enclave/EnclaveCommon.cpp
+7
-3
secure_enclave.c
secure_enclave/secure_enclave.c
+6
-4
sgxwall.cpp
sgxwall.cpp
+0
-1
sgxwallet_common.h
sgxwallet_common.h
+0
-1
stubclient.h
stubclient.h
+17
-30
testw.cpp
testw.cpp
+14
-17
testw.py
testw.py
+1
-10
No files found.
BLSCrypto.cpp
View file @
11f0cfb2
...
...
@@ -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
)
{
...
...
@@ -155,8 +155,7 @@ bool sign(const char *_encryptedKeyHex, const char *_hashHex, size_t _t, size_t
return
true
;
}
bool
sign_aes
(
const
char
*
_encryptedKeyHex
,
const
char
*
_hashHex
,
size_t
_t
,
size_t
_n
,
size_t
_signerIndex
,
char
*
_sig
)
{
bool
sign_aes
(
const
char
*
_encryptedKeyHex
,
const
char
*
_hashHex
,
size_t
_t
,
size_t
_n
,
char
*
_sig
)
{
auto
hash
=
make_shared
<
array
<
uint8_t
,
32
>>
();
uint64_t
binLen
;
...
...
@@ -240,15 +239,15 @@ bool sign_aes(const char *_encryptedKeyHex, const char *_hashHex, size_t _t, siz
return
true
;
}
bool
bls_sign
(
const
char
*
_encryptedKeyHex
,
const
char
*
_hashHex
,
size_t
_t
,
size_t
_n
,
size_t
_signerIndex
,
char
*
_sig
)
{
return
sign_aes
(
_encryptedKeyHex
,
_hashHex
,
_t
,
_n
,
_signerIndex
,
_sig
);
bool
bls_sign
(
const
char
*
_encryptedKeyHex
,
const
char
*
_hashHex
,
size_t
_t
,
size_t
_n
,
char
*
_sig
)
{
return
sign_aes
(
_encryptedKeyHex
,
_hashHex
,
_t
,
_n
,
_sig
);
}
std
::
string
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
;
...
...
@@ -265,7 +264,7 @@ std::string encryptBLSKeyShare2Hex(int *errStatus, char *err_string, const char
if
(
status
!=
SGX_SUCCESS
)
{
*
errStatus
=
-
1
;
return
nullptr
;
return
""
;
}
std
::
string
result
(
2
*
BUF_LEN
,
'\0'
);
...
...
BLSCrypto.h
View file @
11f0cfb2
...
...
@@ -34,8 +34,7 @@
#include "stdint.h"
#include <string>
EXTERNC
bool
bls_sign
(
const
char
*
encryptedKeyHex
,
const
char
*
hashHex
,
size_t
t
,
size_t
n
,
size_t
signerIndex
,
char
*
_sig
);
EXTERNC
bool
bls_sign
(
const
char
*
encryptedKeyHex
,
const
char
*
hashHex
,
size_t
t
,
size_t
n
,
char
*
_sig
);
EXTERNC
int
char2int
(
char
_input
);
...
...
DKGCrypto.cpp
View file @
11f0cfb2
...
...
@@ -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 @
11f0cfb2
...
...
@@ -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 @
11f0cfb2
This diff is collapsed.
Click to expand it.
SGXWalletServer.hpp
View file @
11f0cfb2
...
...
@@ -46,18 +46,13 @@ public:
SGXWalletServer
(
AbstractServerConnector
&
_connector
,
serverVersion_t
_type
);
virtual
Json
::
Value
importBLSKeyShare
(
const
string
&
_keyShare
,
const
string
&
_keyShareName
,
int
_t
,
int
_n
,
int
index
);
importBLSKeyShare
(
const
string
&
_keyShare
,
const
string
&
_keyShareName
);
virtual
Json
::
Value
blsSignMessageHash
(
const
string
&
_keyShareName
,
const
string
&
_messageHash
,
int
_t
,
int
_n
,
int
_signerIndex
);
virtual
Json
::
Value
importECDSAKey
(
const
string
&
_key
,
const
string
&
_keyName
);
blsSignMessageHash
(
const
string
&
_keyShareName
,
const
string
&
_messageHash
,
int
_t
,
int
_n
);
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
);
...
...
@@ -79,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
);
...
...
@@ -95,21 +92,16 @@ public:
static
void
writeDataToDB
(
const
string
&
Name
,
const
string
&
value
);
static
void
writeKeyShare
(
const
string
&
_keyShareName
,
const
string
&
_value
,
int
_index
,
int
_n
,
int
_t
);
static
void
writeKeyShare
(
const
string
&
_keyShareName
,
const
string
&
_value
);
static
Json
::
Value
importBLSKeyShareImpl
(
const
string
&
_keyShare
,
const
string
&
_keyShareName
,
int
t
,
int
n
,
int
_index
);
importBLSKeyShareImpl
(
const
string
&
_keyShare
,
const
string
&
_keyShareName
);
static
Json
::
Value
blsSignMessageHashImpl
(
const
string
&
_keyShareName
,
const
string
&
_messageHash
,
int
t
,
int
n
,
int
_signerIndex
);
static
Json
::
Value
importECDSAKeyImpl
(
const
string
&
_key
,
const
string
&
_keyName
);
blsSignMessageHashImpl
(
const
string
&
_keyShareName
,
const
string
&
_messageHash
,
int
t
,
int
n
);
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
);
...
...
@@ -130,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 @
11f0cfb2
...
...
@@ -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,8 +242,18 @@ 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
,
i
+
1
);
blsSigShares
[
i
]
=
c
.
blsSignMessageHash
(
blsName
,
hash
,
t
,
n
);
CHECK_STATE
(
blsSigShares
[
i
][
"status"
]
==
0
);
shared_ptr
<
string
>
sig_share_ptr
=
make_shared
<
string
>
(
blsSigShares
[
i
][
"signatureShare"
].
asString
());
...
...
@@ -376,7 +390,7 @@ void TestUtils::doDKG(StubClient &c, int n, int t,
for
(
int
i
=
0
;
i
<
t
;
i
++
)
{
string
blsName
=
"BLS_KEY"
+
polyNames
[
i
].
substr
(
4
);
blsSigShares
[
i
]
=
c
.
blsSignMessageHash
(
blsName
,
hash
,
t
,
n
,
i
+
1
);
blsSigShares
[
i
]
=
c
.
blsSignMessageHash
(
blsName
,
hash
,
t
,
n
);
CHECK_STATE
(
blsSigShares
[
i
][
"status"
]
==
0
);
shared_ptr
<
string
>
sig_share_ptr
=
make_shared
<
string
>
(
blsSigShares
[
i
][
"signatureShare"
].
asString
());
BLSSigShare
sig
(
sig_share_ptr
,
i
+
1
,
t
,
n
);
...
...
abstractstubserver.h
View file @
11f0cfb2
...
...
@@ -36,21 +36,20 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
public
:
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
,
"keyShare"
,
jsonrpc
::
JSON_STRING
,
"keyShareName"
,
jsonrpc
::
JSON_STRING
,
"t"
,
jsonrpc
::
JSON_INTEGER
,
"n"
,
jsonrpc
::
JSON_INTEGER
,
"index"
,
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
,
"t"
,
jsonrpc
::
JSON_INTEGER
,
"n"
,
jsonrpc
::
JSON_INTEGER
,
"signerIndex"
,
jsonrpc
::
JSON_INTEGER
,
NULL
),
&
AbstractStubServer
::
blsSignMessageHashI
);
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
);
...
...
@@ -62,25 +61,17 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
inline
virtual
void
importBLSKeyShareI
(
const
Json
::
Value
&
request
,
Json
::
Value
&
response
)
{
response
=
this
->
importBLSKeyShare
(
request
[
"keyShare"
].
asString
(),
request
[
"keyShareName"
].
asString
()
,
request
[
"t"
].
asInt
(),
request
[
"n"
].
asInt
(),
request
[
"index"
].
asInt
()
);
response
=
this
->
importBLSKeyShare
(
request
[
"keyShare"
].
asString
(),
request
[
"keyShareName"
].
asString
());
}
inline
virtual
void
blsSignMessageHashI
(
const
Json
::
Value
&
request
,
Json
::
Value
&
response
)
{
response
=
this
->
blsSignMessageHash
(
request
[
"keyShareName"
].
asString
(),
request
[
"messageHash"
].
asString
(),
request
[
"t"
].
asInt
(),
request
[
"n"
].
asInt
()
,
request
[
"signerIndex"
].
asInt
()
);
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
());
...
...
@@ -145,11 +139,9 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
response
=
this
->
deleteBlsKey
(
request
[
"blsKeyName"
].
asString
());
}
virtual
Json
::
Value
importBLSKeyShare
(
const
std
::
string
&
keyShare
,
const
std
::
string
&
keyShareName
,
int
t
,
int
n
,
int
index
)
=
0
;
virtual
Json
::
Value
blsSignMessageHash
(
const
std
::
string
&
keyShareName
,
const
std
::
string
&
messageHash
,
int
t
,
int
n
,
int
signerIndex
)
=
0
;
virtual
Json
::
Value
importECDSAKey
(
const
std
::
string
&
key
,
const
std
::
string
&
keyName
)
=
0
;
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
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
;
...
...
run_sgx_sim/docker-compose.yml
View file @
11f0cfb2
...
...
@@ -16,5 +16,4 @@ services:
max-size
:
"
10m"
max-file
:
"
4"
restart
:
unless-stopped
command
:
-s
command
:
-s -y
secure_enclave/DHDkg.c
View file @
11f0cfb2
...
...
@@ -43,12 +43,7 @@
#include <string.h>
int
gen_session_key
(
char
*
skey_str
,
char
*
pb_keyB
,
char
*
common_key
)
{
int
ret
=
-
1
;
LOG_INFO
(
__FUNCTION__
);
...
...
@@ -60,7 +55,6 @@ int gen_session_key(char *skey_str, char *pb_keyB, char *common_key) {
point
pub_keyB
=
point_init
();
point
session_key
=
point_init
();
if
(
!
common_key
)
{
LOG_ERROR
(
"gen_session_key: Null common_key"
);
goto
clean
;
...
...
@@ -107,18 +101,15 @@ int gen_session_key(char *skey_str, char *pb_keyB, char *common_key) {
point_clear
(
session_key
);
return
ret
;
}
int
session_key_recover
(
const
char
*
skey_str
,
const
char
*
sshare
,
char
*
common_key
)
{
int
ret
=
-
1
;
SAFE_CHAR_BUF
(
pb_keyB_x
,
65
);
SAFE_CHAR_BUF
(
pb_keyB_y
,
65
);
mpz_t
skey
;
mpz_init
(
skey
);
point
pub_keyB
=
point_init
();
...
...
@@ -147,14 +138,6 @@ int session_key_recover(const char *skey_str, const char *sshare, char *common_k
goto
clean
;
}
if
(
mpz_set_str
(
skey
,
skey_str
,
16
)
==
-
1
)
{
goto
clean
;
}
...
...
@@ -187,17 +170,17 @@ int xor_encrypt(char *key, char *message, char *cypher) {
if
(
!
cypher
)
{
LOG_ERROR
(
"xor_encrypt: null cypher"
);
goto
clean
;
return
ret
;
}
if
(
!
key
)
{
LOG_ERROR
(
"xor_encrypt: null key"
);
goto
clean
;
return
ret
;
}
if
(
!
message
)
{
LOG_ERROR
(
"xor_encrypt: null message"
);
goto
clean
;
return
ret
;
}
SAFE_CHAR_BUF
(
cypher_bin
,
33
);
...
...
@@ -206,13 +189,13 @@ int xor_encrypt(char *key, char *message, char *cypher) {
uint64_t
key_length
;
if
(
!
hex2carray
(
key
,
&
key_length
,
(
uint8_t
*
)
key_bin
))
{
goto
clean
;
return
ret
;
}
uint64_t
msg_length
;
uint8_t
msg_bin
[
33
];
if
(
!
hex2carray
(
message
,
&
msg_length
,
msg_bin
))
{
goto
clean
;
return
ret
;
}
for
(
int
i
=
0
;
i
<
32
;
i
++
)
{
...
...
@@ -223,11 +206,7 @@ int xor_encrypt(char *key, char *message, char *cypher) {
ret
=
0
;
clean:
;
return
ret
;
}
int
xor_decrypt
(
char
*
key
,
char
*
cypher
,
char
*
message
)
{
...
...
@@ -236,34 +215,33 @@ int xor_decrypt(char *key, char *cypher, char *message) {
if
(
!
cypher
)
{
LOG_ERROR
(
"xor_encrypt: null cypher"
);
goto
clean
;
return
ret
;
}
if
(
!
key
)
{
LOG_ERROR
(
"xor_encrypt: null key"
);
goto
clean
;
return
ret
;
}
if
(
!
message
)
{
LOG_ERROR
(
"xor_encrypt: null message"
);
goto
clean
;
return
ret
;
}
SAFE_CHAR_BUF
(
msg_bin
,
33
);
SAFE_CHAR_BUF
(
key_bin
,
33
)
uint64_t
key_length
;
if
(
!
hex2carray
(
key
,
&
key_length
,
(
uint8_t
*
)
key_bin
))
{
goto
clean
;
return
ret
;
}
uint64_t
cypher_length
;
SAFE_CHAR_BUF
(
cypher_bin
,
33
);
if
(
!
hex2carray
(
cypher
,
&
cypher_length
,
(
uint8_t
*
)
cypher_bin
))
{
goto
clean
;
return
ret
;
}
for
(
int
i
=
0
;
i
<
32
;
i
++
)
{
...
...
@@ -274,9 +252,5 @@ int xor_decrypt(char *key, char *cypher, char *message) {
ret
=
0
;
clean:
;
return
ret
;
}
secure_enclave/DKGUtils.cpp
View file @
11f0cfb2
...
...
@@ -51,10 +51,7 @@ string stringFromFr(const libff::alt_bn128_Fr &_el) {
mpz_t
t
;
mpz_init
(
t
);
try
{
_el
.
as_bigint
().
to_mpz
(
t
);
SAFE_CHAR_BUF
(
arr
,
BUF_LEN
);
...
...
@@ -95,7 +92,6 @@ string ConvertToString(const T &field_elem, int base = 10) {
char
*
tmp
=
mpz_get_str
(
arr
,
base
,
t
);
ret
=
string
(
tmp
);
goto
clean
;
...
...
@@ -128,24 +124,20 @@ string ConvertG2ToString(const libff::alt_bn128_G2 &elem, int base = 10, const s
result
+=
delim
;
result
+=
ConvertToString
(
elem
.
Y
.
c1
);
goto
clean
;
return
result
;
}
catch
(
exception
&
e
)
{
LOG_ERROR
(
e
.
what
());
goto
clean
;
return
result
;
}
catch
(...)
{
LOG_ERROR
(
"Unknown throwable"
);
goto
clean
;
return
result
;
}
clean
:
return
result
;
}
vector
<
libff
::
alt_bn128_Fr
>
SplitStringToFr
(
const
char
*
coeffs
,
const
char
symbol
)
{
vector
<
libff
::
alt_bn128_Fr
>
result
;
string
str
(
coeffs
);
string
delim
;
...
...
@@ -168,14 +160,14 @@ vector <libff::alt_bn128_Fr> SplitStringToFr(const char *coeffs, const char symb
prev
=
pos
+
delim
.
length
();
}
while
(
pos
<
str
.
length
()
&&
prev
<
str
.
length
());
goto
clean
;
return
result
;
}
catch
(
exception
&
e
)
{
LOG_ERROR
(
e
.
what
());
goto
clean
;
return
result
;
}
catch
(...)
{
LOG_ERROR
(
"Unknown throwable"
);
goto
clean
;
return
result
;
}
clean
:
...
...
@@ -202,22 +194,21 @@ int gen_dkg_poly(char *secret, unsigned _t) {
strncpy
(
secret
,
result
.
c_str
(),
result
.
length
()
+
1
);
if
(
strlen
(
secret
)
==
0
)
{
goto
clean
;
return
status
;
}
status
=
0
;
}
catch
(
exception
&
e
)
{
LOG_ERROR
(
e
.
what
());
goto
clean
;
return
status
;
}
catch
(...)
{
LOG_ERROR
(
"Unknown throwable"
);
goto
clean
;
return
status
;
}
clean
:
return
status
;
}
libff
::
alt_bn128_Fr
PolynomialValue
(
const
vector
<
libff
::
alt_bn128_Fr
>
&
pol
,
libff
::
alt_bn128_Fr
point
,
unsigned
_t
)
{
...
...
@@ -232,16 +223,15 @@ libff::alt_bn128_Fr PolynomialValue(const vector <libff::alt_bn128_Fr> &pol, lib
pow
*=
point
;
}
goto
clean
;
return
result
;
}
catch
(
exception
&
e
)
{
LOG_ERROR
(
e
.
what
());
goto
clean
;
return
result
;
}
catch
(...)
{
LOG_ERROR
(
"Unknown throwable"
);
goto
clean
;
return
result
;
}
clean
:
return
result
;
}
...
...
@@ -271,10 +261,10 @@ void calc_secret_shares(const char *decrypted_coeffs,
}
catch
(
exception
&
e
)
{
LOG_ERROR
(
e
.
what
());
goto
clea
n
;
retur
n
;
}
catch
(...)
{
LOG_ERROR
(
"Unknown throwable"
);
goto
clea
n
;
retur
n
;
}
clean
:
...
...
@@ -283,8 +273,6 @@ void calc_secret_shares(const char *decrypted_coeffs,
int
calc_secret_share
(
const
char
*
decrypted_coeffs
,
char
*
s_share
,
unsigned
_t
,
unsigned
_n
,
unsigned
ind
)
{
int
result
=
1
;
CHECK_ARG_CLEAN
(
decrypted_coeffs
);
...
...
@@ -296,7 +284,7 @@ int calc_secret_share(const char *decrypted_coeffs, char *s_share,
char
symbol
=
':'
;
vector
<
libff
::
alt_bn128_Fr
>
poly
=
SplitStringToFr
(
decrypted_coeffs
,
symbol
);
if
(
poly
.
size
()
!=
_t
)
{
goto
clean
;
return
result
;
}
libff
::
alt_bn128_Fr
secret_share
=
PolynomialValue
(
poly
,
libff
::
alt_bn128_Fr
(
ind
),
_t
);
...
...
@@ -306,14 +294,14 @@ int calc_secret_share(const char *decrypted_coeffs, char *s_share,
strncpy
(
s_share
,
cur_share
.
c_str
(),
cur_share
.
length
()
+
1
);
result
=
0
;
goto
clean
;
return
result
;
}
catch
(
exception
&
e
)
{
LOG_ERROR
(
e
.
what
());
goto
clean
;
return
result
;
}
catch
(...)
{
LOG_ERROR
(
"Unknown throwable"
);
goto
clean
;
return
result
;
}
clean
:
...
...
@@ -381,12 +369,11 @@ int calc_public_shares(const char *decrypted_coeffs, char *public_shares,
CHECK_ARG_CLEAN
(
public_shares
);
CHECK_ARG_CLEAN
(
_t
>
0
);
try
{
vector
<
libff
::
alt_bn128_Fr
>
poly
=
SplitStringToFr
(
decrypted_coeffs
,
symbol
);
if
(
poly
.
size
()
!=
_t
)
{
goto
clean
;
return
ret
;
}
for
(
size_t
i
=
0
;
i
<
_t
;
++
i
)
{
libff
::
alt_bn128_G2
pub_share
=
poly
.
at
(
i
)
*
libff
::
alt_bn128_G2
::
one
();
...
...
@@ -406,7 +393,7 @@ int calc_public_shares(const char *decrypted_coeffs, char *public_shares,
}
clean
:
return
ret
;
return
ret
;
}
string
ConvertHexToDec
(
string
hex_str
)
{
...
...
@@ -435,8 +422,8 @@ string ConvertHexToDec(string hex_str) {
}
clean
:
mpz_clear
(
dec
);
return
ret
;
mpz_clear
(
dec
);
return
ret
;
}
int
Verification
(
char
*
public_shares
,
mpz_t
decr_secret_share
,
int
_t
,
int
ind
)
{
...
...
@@ -461,7 +448,7 @@ int Verification(char *public_shares, mpz_t decr_secret_share, int _t, int ind)
string
y_c1_str
=
ConvertHexToDec
(
pub_shares_str
.
substr
(
pos0
+
3
*
coord_length
,
coord_length
));
if
(
x_c0_str
==
""
||
x_c1_str
==
""
||
y_c0_str
==
""
||
y_c1_str
==
""
)
{
ret
=
2
;
goto
clean
;
return
ret
;
}
pub_share
.
X
.
c0
=
libff
::
alt_bn128_Fq
(
x_c0_str
.
c_str
());
pub_share
.
X
.
c1
=
libff
::
alt_bn128_Fq
(
x_c1_str
.
c_str
());
...
...
@@ -498,11 +485,11 @@ int Verification(char *public_shares, mpz_t decr_secret_share, int _t, int ind)
}
catch
(
exception
&
e
)
{
LOG_ERROR
(
e
.
what
());
goto
clean
;
return
ret
;
}
catch
(...)
{
LOG_ERROR
(
"Unknown throwable"
);
goto
clean
;
return
ret
;
}
clean
:
...
...
@@ -550,6 +537,6 @@ int calc_bls_public_key(char *skey_hex, char *pub_key) {
}
clean
:
mpz_clear
(
skey
);
return
ret
;
mpz_clear
(
skey
);
return
ret
;
}
secure_enclave/EnclaveCommon.cpp
View file @
11f0cfb2
...
...
@@ -77,7 +77,8 @@ string *stringFromFq(libff::alt_bn128_Fq *_fq) {
string
*
ret
=
nullptr
;
mpz_t
t
;
mpz_init
(
t
);
SAFE_CHAR_BUF
(
arr
,
BUF_LEN
);
mpz_init
(
t
);
SAFE_CHAR_BUF
(
arr
,
BUF_LEN
);
try
{
_fq
->
as_bigint
().
to_mpz
(
t
);
...
...
@@ -140,11 +141,14 @@ string *stringFromG1(libff::alt_bn128_G1 *_g1) {
libff
::
alt_bn128_Fr
*
keyFromString
(
const
char
*
_keyStringHex
)
{
mpz_t
skey
;
mpz_init
(
skey
);
SAFE_CHAR_BUF
(
skey_dec
,
BUF_LEN
);
mpz_init
(
skey
);
SAFE_CHAR_BUF
(
skey_dec
,
BUF_LEN
);
libff
::
alt_bn128_Fr
*
ret
=
nullptr
;
if
(
mpz_set_str
(
skey
,
_keyStringHex
,
16
)
==
-
1
)
{
goto
clean
;
}
mpz_set_str
(
skey
,
_keyStringHex
,
16
);
mpz_get_str
(
skey_dec
,
10
,
skey
);
ret
=
new
libff
::
alt_bn128_Fr
(
skey_dec
);
...
...
secure_enclave/secure_enclave.c
View file @
11f0cfb2
...
...
@@ -683,7 +683,12 @@ void trustedBlsSignMessageAES(int *errStatus, char *errString, uint8_t *encrypte
CHECK_STATUS
(
"AES decrypt failed"
)
enclave_sign
(
key
,
_hashX
,
_hashY
,
sig
);
if
(
!
enclave_sign
(
key
,
_hashX
,
_hashY
,
sig
))
{
strncpy
(
errString
,
"Enclave failed to create bls signature"
,
BUF_LEN
);
LOG_ERROR
(
errString
);
*
errStatus
=
-
1
;
goto
clean
;
}
strncpy
(
signature
,
sig
,
BUF_LEN
);
...
...
@@ -972,9 +977,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
);
...
...
sgxwall.cpp
View file @
11f0cfb2
...
...
@@ -58,7 +58,6 @@ void SGXWallet::printUsage() {
}
void
SGXWallet
::
serializeKeys
(
const
vector
<
string
>&
_ecdsaKeyNames
,
const
vector
<
string
>&
_blsKeyNames
,
const
string
&
_fileName
)
{
Json
::
Value
top
(
Json
::
objectValue
);
Json
::
Value
ecdsaKeysJson
(
Json
::
objectValue
);
...
...
sgxwallet_common.h
View file @
11f0cfb2
...
...
@@ -91,7 +91,6 @@ extern bool autoconfirm;
#define INVALID_ECSDA_SIGNATURE -22
#define KEY_NAME_ALREADY_EXISTS -23 \
#define ERROR_IN_ENCLAVE -33
#define FILE_NOT_FOUND -44
...
...
stubclient.h
View file @
11f0cfb2
...
...
@@ -6,20 +6,18 @@
#define JSONRPC_CPP_STUB_STUBCLIENT_H_
#include <jsonrpccpp/client.h>
#include <cassert>
class
StubClient
:
public
jsonrpc
::
Client
{
public
:
StubClient
(
jsonrpc
::
IClientConnector
&
conn
,
jsonrpc
::
clientVersion_t
type
=
jsonrpc
::
JSONRPC_CLIENT_V2
)
:
jsonrpc
::
Client
(
conn
,
type
)
{}
Json
::
Value
importBLSKeyShare
(
const
std
::
string
&
keyShare
,
const
std
::
string
&
keyShareName
,
int
t
,
int
n
,
int
index
)
Json
::
Value
importBLSKeyShare
(
const
std
::
string
&
keyShare
,
const
std
::
string
&
keyShareName
)
{
Json
::
Value
p
;
p
[
"index"
]
=
index
;
p
[
"keyShare"
]
=
keyShare
;
p
[
"keyShareName"
]
=
keyShareName
;
p
[
"n"
]
=
n
;
p
[
"t"
]
=
t
;
Json
::
Value
result
=
this
->
CallMethod
(
"importBLSKeyShare"
,
p
);
if
(
result
.
isObject
())
return
result
;
...
...
@@ -27,13 +25,12 @@ class StubClient : public jsonrpc::Client
throw
jsonrpc
::
JsonRpcException
(
jsonrpc
::
Errors
::
ERROR_CLIENT_INVALID_RESPONSE
,
result
.
toStyledString
());
}
Json
::
Value
blsSignMessageHash
(
const
std
::
string
&
keyShareName
,
const
std
::
string
&
messageHash
,
int
t
,
int
n
,
int
signerIndex
)
Json
::
Value
blsSignMessageHash
(
const
std
::
string
&
keyShareName
,
const
std
::
string
&
messageHash
,
int
t
,
int
n
)
{
Json
::
Value
p
;
p
[
"keyShareName"
]
=
keyShareName
;
p
[
"messageHash"
]
=
messageHash
;
p
[
"n"
]
=
n
;
p
[
"signerIndex"
]
=
signerIndex
;
p
[
"t"
]
=
t
;
Json
::
Value
result
=
this
->
CallMethod
(
"blsSignMessageHash"
,
p
);
if
(
result
.
isObject
())
...
...
@@ -42,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
;
...
...
@@ -65,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
;
...
...
@@ -184,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 @
11f0cfb2
...
...
@@ -82,27 +82,27 @@ public:
}
};
class
TestFixture
NoReset
{
class
TestFixture
HTTPS
{
public
:
TestFixtureNoReset
()
{
setOptions
(
L_INFO
,
false
,
true
);
TestFixtureHTTPS
()
{
TestUtils
::
resetDB
();
setOptions
(
L_INFO
,
true
,
true
);
initAll
(
L_INFO
,
false
,
true
);
}
~
TestFixture
NoReset
()
{
~
TestFixture
HTTPS
()
{
TestUtils
::
destroyEnclave
();
}
};
class
TestFixture
HTTPS
{
class
TestFixture
NoReset
{
public
:
TestFixtureHTTPS
()
{
TestUtils
::
resetDB
();
setOptions
(
L_INFO
,
true
,
true
);
TestFixtureNoReset
()
{
setOptions
(
L_INFO
,
false
,
true
);
initAll
(
L_INFO
,
false
,
true
);
}
~
TestFixture
HTTPS
()
{
~
TestFixture
NoReset
()
{
TestUtils
::
destroyEnclave
();
}
};
...
...
@@ -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
);
*/
}
...
...
@@ -432,7 +431,7 @@ TEST_CASE_METHOD(TestFixture, "Delete Bls Key", "[delete-bls-key]") {
libff
::
alt_bn128_Fr
key
=
libff
::
alt_bn128_Fr
(
"6507625568967977077291849236396320012317305261598035438182864059942098934847"
);
std
::
string
key_str
=
TestUtils
::
stringFromFr
(
key
);
PRINT_SRC_LINE
c
.
importBLSKeyShare
(
key_str
,
name
,
1
,
2
,
1
);
c
.
importBLSKeyShare
(
key_str
,
name
);
PRINT_SRC_LINE
REQUIRE
(
c
.
deleteBlsKey
(
name
)[
"deleted"
]
==
true
);
}
...
...
@@ -658,7 +657,7 @@ TEST_CASE_METHOD(TestFixture, "AES_DKG test", "[aes-dkg]") {
REQUIRE
(
pubBLSKeys
[
i
][
"status"
]
==
0
);
string
hash
=
SAMPLE_HASH
;
blsSigShares
[
i
]
=
c
.
blsSignMessageHash
(
blsName
,
hash
,
t
,
n
,
i
+
1
);
blsSigShares
[
i
]
=
c
.
blsSignMessageHash
(
blsName
,
hash
,
t
,
n
);
REQUIRE
(
blsSigShares
[
i
][
"status"
]
==
0
);
shared_ptr
<
string
>
sig_share_ptr
=
make_shared
<
string
>
(
blsSigShares
[
i
][
"signatureShare"
].
asString
());
...
...
@@ -722,5 +721,3 @@ TEST_CASE_METHOD(TestFixture, "First run", "[first-run]") {
TEST_CASE_METHOD
(
TestFixtureNoReset
,
"Second run"
,
"[second-run]"
)
{
}
testw.py
View file @
11f0cfb2
...
...
@@ -35,30 +35,21 @@ testList = ["[first-run]",
"[get-server-version]"
,
"[backup-key]"
,
"[delete-bls-key]"
,
"[ecdsa-key-gen]"
,
"[ecdsa-aes-key-gen]"
,
"[ecdsa-key-sig-gen]"
,
"[ecdsa-aes-key-sig-gen]"
,
"[ecdsa-get-pub-key]"
,
"[ecdsa-aes-get-pub-key]"
,
"[ecdsa-key-gen-api]"
,
"[ecdsa-key-gen-sign-api]"
,
"[bls-key-encrypt]"
,
"[dkg-gen]"
,
"[dkg-aes-gen]"
,
"[dkg-encr-sshares]"
,
"[dkg-aes-encr-sshares]"
,
"[dkg-verify]"
,
"[dkg-api]"
,
"[dkg-bls]"
,
"[dkg-poly-exists]"
,
# "[dkg-pub-shares]",
"[dkg-aes-pub-shares]"
,
"[many-threads-crypto]"
,
"[aes-encrypt-decrypt]"
,
"[sgx-encrypt-decrypt]"
,
"[aes-dkg]"
,
"[aes-not-aes]"
"[aes-dkg]"
]
...
...
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