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
e0392674
Unverified
Commit
e0392674
authored
Nov 05, 2020
by
Stan Kladko
Committed by
GitHub
Nov 05, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #200 from skalenetwork/feature/SKALE-3430-use-fast-ecdsa
Feature/skale 3430 use fast ecdsa
parents
2259ae3d
aadd2957
Changes
16
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
193 additions
and
58 deletions
+193
-58
dockerimage.yml
.github/workflows/dockerimage.yml
+1
-3
dockerimagebase.yml
.github/workflows/dockerimagebase.yml
+1
-3
dockerimagerelease.yml
.github/workflows/dockerimagerelease.yml
+1
-3
dockerimagesim.yml
.github/workflows/dockerimagesim.yml
+1
-3
.gitmodules
.gitmodules
+4
-0
BLSCrypto.cpp
BLSCrypto.cpp
+7
-11
BLSCrypto.h
BLSCrypto.h
+3
-2
DKGCrypto.cpp
DKGCrypto.cpp
+9
-11
ECDSACrypto.cpp
ECDSACrypto.cpp
+2
-7
SEKManager.cpp
SEKManager.cpp
+3
-10
SGXWalletServer.cpp
SGXWalletServer.cpp
+2
-2
TestUtils.cpp
TestUtils.cpp
+123
-0
TestUtils.h
TestUtils.h
+4
-0
secp256k1-sgx
secure_enclave/secp256k1-sgx
+1
-0
testw.cpp
testw.cpp
+31
-2
testw.py
testw.py
+0
-1
No files found.
.github/workflows/dockerimage.yml
View file @
e0392674
...
@@ -8,9 +8,7 @@ jobs:
...
@@ -8,9 +8,7 @@ jobs:
DOCKER_PASSWORD
:
${{ secrets.DOCKER_PASSWORD }}
DOCKER_PASSWORD
:
${{ secrets.DOCKER_PASSWORD }}
steps
:
steps
:
-
name
:
Login to docker
-
name
:
Login to docker
env
:
run
:
docker login -u ${DOCKER_USERNAME} -p ${DOCKER_PASSWORD}
GITHUB_TOKEN
:
${{ secrets.DOCKER_SECRET }}
run
:
docker login -u skalelabs -p ${GITHUB_TOKEN}
-
uses
:
actions/checkout@v1
-
uses
:
actions/checkout@v1
-
name
:
submodule update
-
name
:
submodule update
run
:
git submodule update --init --recursive
run
:
git submodule update --init --recursive
...
...
.github/workflows/dockerimagebase.yml
View file @
e0392674
...
@@ -11,9 +11,7 @@ jobs:
...
@@ -11,9 +11,7 @@ jobs:
DOCKER_PASSWORD
:
${{ secrets.DOCKER_PASSWORD }}
DOCKER_PASSWORD
:
${{ secrets.DOCKER_PASSWORD }}
steps
:
steps
:
-
name
:
Login to docker
-
name
:
Login to docker
env
:
run
:
docker login -u ${DOCKER_USERNAME} -p ${DOCKER_PASSWORD}
GITHUB_TOKEN
:
${{ secrets.DOCKER_SECRET }}
run
:
docker login -u skalelabs -p ${GITHUB_TOKEN}
-
uses
:
actions/checkout@v1
-
uses
:
actions/checkout@v1
-
name
:
submodule update
-
name
:
submodule update
run
:
git submodule update --init --recursive
run
:
git submodule update --init --recursive
...
...
.github/workflows/dockerimagerelease.yml
View file @
e0392674
...
@@ -8,9 +8,7 @@ jobs:
...
@@ -8,9 +8,7 @@ jobs:
DOCKER_PASSWORD
:
${{ secrets.DOCKER_PASSWORD }}
DOCKER_PASSWORD
:
${{ secrets.DOCKER_PASSWORD }}
steps
:
steps
:
-
name
:
Login to docker
-
name
:
Login to docker
env
:
run
:
docker login -u ${DOCKER_USERNAME} -p ${DOCKER_PASSWORD}
GITHUB_TOKEN
:
${{ secrets.DOCKER_SECRET }}
run
:
docker login -u skalelabs -p ${GITHUB_TOKEN}
-
uses
:
actions/checkout@v1
-
uses
:
actions/checkout@v1
-
name
:
submodule update
-
name
:
submodule update
run
:
git submodule update --init --recursive
run
:
git submodule update --init --recursive
...
...
.github/workflows/dockerimagesim.yml
View file @
e0392674
...
@@ -10,9 +10,7 @@ jobs:
...
@@ -10,9 +10,7 @@ jobs:
-
name
:
Check that /dev/urandom exists
-
name
:
Check that /dev/urandom exists
run
:
ls /dev/urandom
run
:
ls /dev/urandom
-
name
:
Login to docker
-
name
:
Login to docker
env
:
run
:
docker login -u ${DOCKER_USERNAME} -p ${DOCKER_PASSWORD}
GITHUB_TOKEN
:
${{ secrets.DOCKER_SECRET }}
run
:
docker login -u skalelabs -p ${GITHUB_TOKEN}
-
uses
:
actions/checkout@v1
-
uses
:
actions/checkout@v1
-
name
:
submodule update
-
name
:
submodule update
run
:
git submodule update --init --recursive
run
:
git submodule update --init --recursive
...
...
.gitmodules
View file @
e0392674
...
@@ -16,3 +16,7 @@
...
@@ -16,3 +16,7 @@
[submodule "sgx-software-enable"]
[submodule "sgx-software-enable"]
path = sgx-software-enable
path = sgx-software-enable
url = https://github.com/intel/sgx-software-enable
url = https://github.com/intel/sgx-software-enable
[submodule "secure_enclave/secp256k1-sgx"]
path = secure_enclave/secp256k1-sgx
url = https://github.com/bl4ck5un/secp256k1-sgx
branch = master
BLSCrypto.cpp
View file @
e0392674
...
@@ -75,23 +75,22 @@ int char2int(char _input) {
...
@@ -75,23 +75,22 @@ int char2int(char _input) {
return
-
1
;
return
-
1
;
}
}
void
carray2Hex
(
const
unsigned
char
*
d
,
uint64_t
_len
,
char
*
_hexArray
,
vector
<
char
>
carray2Hex
(
const
unsigned
char
*
d
,
uint64_t
_len
)
{
uint64_t
_hexArrayLen
)
{
CHECK_STATE
(
d
);
CHECK_STATE
(
d
);
CHECK_STATE
(
_hexArray
);
vector
<
char
>
_hexArray
(
2
*
_len
+
1
);
char
hexval
[
16
]
=
{
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
char
hexval
[
16
]
=
{
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
,
'a'
,
'b'
,
'c'
,
'd'
,
'e'
,
'f'
};
'8'
,
'9'
,
'a'
,
'b'
,
'c'
,
'd'
,
'e'
,
'f'
};
CHECK_STATE
(
_hexArrayLen
>
2
*
_len
);
for
(
uint64_t
j
=
0
;
j
<
_len
;
j
++
)
{
for
(
uint64_t
j
=
0
;
j
<
_len
;
j
++
)
{
_hexArray
[
j
*
2
]
=
hexval
[((
d
[
j
]
>>
4
)
&
0xF
)];
_hexArray
[
j
*
2
]
=
hexval
[((
d
[
j
]
>>
4
)
&
0xF
)];
_hexArray
[
j
*
2
+
1
]
=
hexval
[(
d
[
j
])
&
0x0F
];
_hexArray
[
j
*
2
+
1
]
=
hexval
[(
d
[
j
])
&
0x0F
];
}
}
_hexArray
[
_len
*
2
]
=
0
;
_hexArray
[
_len
*
2
]
=
0
;
return
_hexArray
;
}
}
...
@@ -166,8 +165,7 @@ bool sign_aes(const char *_encryptedKeyHex, const char *_hashHex, size_t _t, siz
...
@@ -166,8 +165,7 @@ bool sign_aes(const char *_encryptedKeyHex, const char *_hashHex, size_t _t, siz
CHECK_STATE
(
_hashHex
);
CHECK_STATE
(
_hashHex
);
CHECK_STATE
(
_sig
);
CHECK_STATE
(
_sig
);
auto
hash
=
make_shared
<
array
<
uint8_t
,
auto
hash
=
make_shared
<
array
<
uint8_t
,
32
>>
();
32
>>
();
uint64_t
binLen
;
uint64_t
binLen
;
...
@@ -265,9 +263,7 @@ string encryptBLSKeyShare2Hex(int *errStatus, char *err_string, const char *_key
...
@@ -265,9 +263,7 @@ string encryptBLSKeyShare2Hex(int *errStatus, char *err_string, const char *_key
HANDLE_TRUSTED_FUNCTION_ERROR
(
status
,
*
errStatus
,
errMsg
.
data
());
HANDLE_TRUSTED_FUNCTION_ERROR
(
status
,
*
errStatus
,
errMsg
.
data
());
SAFE_CHAR_BUF
(
resultBuf
,
2
*
BUF_LEN
+
1
);
vector
<
char
>
resultBuf
=
carray2Hex
(
encryptedKey
->
data
(),
encryptedLen
);
carray2Hex
(
encryptedKey
->
data
(),
encryptedLen
,
resultBuf
,
2
*
BUF_LEN
+
1
);
return
string
(
resultBuf
);
return
string
(
resultBuf
.
begin
(),
resultBuf
.
end
()
);
}
}
BLSCrypto.h
View file @
e0392674
...
@@ -33,13 +33,14 @@
...
@@ -33,13 +33,14 @@
#include "stddef.h"
#include "stddef.h"
#include "stdint.h"
#include "stdint.h"
#include <string>
#include <string>
#include <vector>
EXTERNC
bool
bls_sign
(
const
char
*
encryptedKeyHex
,
const
char
*
hashHex
,
size_t
t
,
size_t
n
,
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
);
EXTERNC
int
char2int
(
char
_input
);
EXTERNC
void
carray2Hex
(
const
unsigned
char
*
d
,
uint64_t
,
char
*
_hexArray
,
EXTERNC
std
::
vector
<
char
>
carray2Hex
(
const
unsigned
char
*
d
,
uint64_t
_len
);
uint64_t
_hexArrayLen
);
EXTERNC
bool
hex2carray
(
const
char
*
_hex
,
uint64_t
*
_bin_len
,
EXTERNC
bool
hex2carray
(
const
char
*
_hex
,
uint64_t
*
_bin_len
,
uint8_t
*
_bin
,
uint64_t
_max_length
);
uint8_t
*
_bin
,
uint64_t
_max_length
);
...
...
DKGCrypto.cpp
View file @
e0392674
...
@@ -144,9 +144,8 @@ string gen_dkg_poly(int _t) {
...
@@ -144,9 +144,8 @@ string gen_dkg_poly(int _t) {
uint64_t
length
=
enc_len
;;
uint64_t
length
=
enc_len
;;
vector
<
char
>
hexEncrPoly
(
BUF_LEN
,
0
);
CHECK_STATE
(
encrypted_dkg_secret
.
size
()
>=
length
);
CHECK_STATE
(
encrypted_dkg_secret
.
size
()
>=
length
);
carray2Hex
(
encrypted_dkg_secret
.
data
(),
length
,
hexEncrPoly
.
data
(),
BUF_LEN
);
vector
<
char
>
hexEncrPoly
=
carray2Hex
(
encrypted_dkg_secret
.
data
(),
length
);
string
result
(
hexEncrPoly
.
data
());
string
result
(
hexEncrPoly
.
data
());
return
result
;
return
result
;
...
@@ -271,7 +270,7 @@ getSecretShares(const string &_polyName, const char *_encryptedPolyHex, const ve
...
@@ -271,7 +270,7 @@ getSecretShares(const string &_polyName, const char *_encryptedPolyHex, const ve
result
+=
string
(
currentShare
.
data
());
result
+=
string
(
currentShare
.
data
());
spdlog
::
debug
(
"dec len is {}"
,
decLen
);
spdlog
::
debug
(
"dec len is {}"
,
decLen
);
carray2Hex
(
encryptedSkey
.
data
(),
decLen
,
hexEncrKey
.
data
(),
BUF_LEN
);
hexEncrKey
=
carray2Hex
(
encryptedSkey
.
data
(),
decLen
);
string
dhKeyName
=
"DKG_DH_KEY_"
+
_polyName
+
"_"
+
to_string
(
i
)
+
":"
;
string
dhKeyName
=
"DKG_DH_KEY_"
+
_polyName
+
"_"
+
to_string
(
i
)
+
":"
;
spdlog
::
debug
(
"hexEncr DH Key: { }"
,
hexEncrKey
.
data
());
spdlog
::
debug
(
"hexEncr DH Key: { }"
,
hexEncrKey
.
data
());
...
@@ -351,11 +350,9 @@ bool createBLSShare(const string &blsKeyName, const char *s_shares, const char *
...
@@ -351,11 +350,9 @@ bool createBLSShare(const string &blsKeyName, const char *s_shares, const char *
HANDLE_TRUSTED_FUNCTION_ERROR
(
status
,
errStatus
,
errMsg
.
data
());
HANDLE_TRUSTED_FUNCTION_ERROR
(
status
,
errStatus
,
errMsg
.
data
());
SAFE_CHAR_BUF
(
hexBLSKey
,
2
*
BUF_LEN
)
vector
<
char
>
hexBLSKey
=
carray2Hex
(
encr_bls_key
,
enc_bls_len
);
carray2Hex
(
encr_bls_key
,
enc_bls_len
,
hexBLSKey
,
2
*
BUF_LEN
);
SGXWalletServer
::
writeDataToDB
(
blsKeyName
,
hexBLSKey
.
data
());
SGXWalletServer
::
writeDataToDB
(
blsKeyName
,
hexBLSKey
);
return
true
;
return
true
;
...
@@ -452,24 +449,25 @@ string decryptDHKey(const string &polyName, int ind) {
...
@@ -452,24 +449,25 @@ string decryptDHKey(const string &polyName, int ind) {
shared_ptr
<
string
>
hexEncrKeyPtr
=
SGXWalletServer
::
readFromDb
(
DH_key_name
,
"DKG_DH_KEY_"
);
shared_ptr
<
string
>
hexEncrKeyPtr
=
SGXWalletServer
::
readFromDb
(
DH_key_name
,
"DKG_DH_KEY_"
);
spdlog
::
debug
(
"encr DH key is {}"
,
*
hexEncrKeyPtr
);
spdlog
::
debug
(
"encr DH key is {}"
,
*
hexEncrKeyPtr
);
spdlog
::
debug
(
"encr DH key length is {}"
,
hexEncrKeyPtr
->
length
());
vector
<
char
>
hexEncrKey
(
2
*
BUF_LEN
,
0
);
vector
<
char
>
hexEncrKey
(
2
*
BUF_LEN
,
0
);
uint64_t
dhEncLen
=
0
;
SAFE_UINT8_BUF
(
encryptedDHKey
,
BUF_LEN
);
uint64_t
dhEncLen
=
0
;
SAFE_UINT8_BUF
(
encryptedDHKey
,
BUF_LEN
)
if
(
!
hex2carray
(
hexEncrKeyPtr
->
c_str
(),
&
dhEncLen
,
encryptedDHKey
,
BUF_LEN
))
{
if
(
!
hex2carray
(
hexEncrKeyPtr
->
c_str
(),
&
dhEncLen
,
encryptedDHKey
,
BUF_LEN
))
{
throw
SGXException
(
INVALID_HEX
,
"Invalid hexEncrKey"
);
throw
SGXException
(
INVALID_HEX
,
"Invalid hexEncrKey"
);
}
}
spdlog
::
debug
(
"encr DH key length is {}"
,
dhEncLen
);
spdlog
::
debug
(
"encr DH key length is {}"
,
dhEncLen
);
spdlog
::
debug
(
"hex encr DH key length is {}"
,
hexEncrKeyPtr
->
length
());
SAFE_CHAR_BUF
(
DHKey
,
ECDSA_SKEY_LEN
)
;
SAFE_CHAR_BUF
(
DHKey
,
ECDSA_SKEY_LEN
)
sgx_status_t
status
=
SGX_SUCCESS
;
sgx_status_t
status
=
SGX_SUCCESS
;
RESTART_BEGIN
RESTART_BEGIN
status
=
trustedDecryptKey
(
eid
,
&
errStatus
,
errMsg1
.
data
(),
encryptedDHKey
,
dhEncLen
,
DHKey
);
status
=
trustedDecryptKey
(
eid
,
&
errStatus
,
errMsg1
.
data
(),
encryptedDHKey
,
dhEncLen
,
DHKey
);
RESTART_END
RESTART_END
HANDLE_TRUSTED_FUNCTION_ERROR
(
status
,
errStatus
,
errMsg1
.
data
())
;
HANDLE_TRUSTED_FUNCTION_ERROR
(
status
,
errStatus
,
errMsg1
.
data
())
return
DHKey
;
return
DHKey
;
}
}
...
...
ECDSACrypto.cpp
View file @
e0392674
...
@@ -69,19 +69,14 @@ vector <string> genECDSAKey() {
...
@@ -69,19 +69,14 @@ vector <string> genECDSAKey() {
vector
<
string
>
keys
(
3
);
vector
<
string
>
keys
(
3
);
vector
<
char
>
hexEncrKey
(
BUF_LEN
*
2
,
0
);
vector
<
char
>
hexEncrKey
=
carray2Hex
(
encr_pr_key
.
data
(),
enc_len
);
carray2Hex
(
encr_pr_key
.
data
(),
enc_len
,
hexEncrKey
.
data
(),
BUF_LEN
*
2
);
keys
.
at
(
0
)
=
hexEncrKey
.
data
();
keys
.
at
(
0
)
=
hexEncrKey
.
data
();
keys
.
at
(
1
)
=
string
(
pub_key_x
.
data
())
+
string
(
pub_key_y
.
data
());
keys
.
at
(
1
)
=
string
(
pub_key_x
.
data
())
+
string
(
pub_key_y
.
data
());
vector
<
unsigned
char
>
randBuffer
(
32
,
0
);
vector
<
unsigned
char
>
randBuffer
(
32
,
0
);
fillRandomBuffer
(
randBuffer
);
fillRandomBuffer
(
randBuffer
);
vector
<
char
>
rand_str
(
BUF_LEN
,
0
);
vector
<
char
>
rand_str
=
carray2Hex
(
randBuffer
.
data
(),
32
);
carray2Hex
(
randBuffer
.
data
(),
32
,
rand_str
.
data
(),
BUF_LEN
);
keys
.
at
(
2
)
=
rand_str
.
data
();
keys
.
at
(
2
)
=
rand_str
.
data
();
...
...
SEKManager.cpp
View file @
e0392674
...
@@ -71,9 +71,7 @@ void create_test_key() {
...
@@ -71,9 +71,7 @@ void create_test_key() {
HANDLE_TRUSTED_FUNCTION_ERROR
(
status
,
errStatus
,
errMsg
.
data
());
HANDLE_TRUSTED_FUNCTION_ERROR
(
status
,
errStatus
,
errMsg
.
data
());
vector
<
char
>
hexEncrKey
(
2
*
enc_len
+
1
,
0
);
vector
<
char
>
hexEncrKey
=
carray2Hex
(
encrypted_key
,
enc_len
);
carray2Hex
(
encrypted_key
,
enc_len
,
hexEncrKey
.
data
(),
2
*
enc_len
+
1
);
LevelDB
::
getLevelDb
()
->
writeDataUnique
(
"TEST_KEY"
,
hexEncrKey
.
data
());
LevelDB
::
getLevelDb
()
->
writeDataUnique
(
"TEST_KEY"
,
hexEncrKey
.
data
());
}
}
...
@@ -167,9 +165,7 @@ void gen_SEK() {
...
@@ -167,9 +165,7 @@ void gen_SEK() {
throw
SGXException
(
-
1
,
"strnlen(SEK,33) != 32"
);
throw
SGXException
(
-
1
,
"strnlen(SEK,33) != 32"
);
}
}
vector
<
char
>
hexEncrKey
(
2
*
enc_len
+
1
,
0
);
vector
<
char
>
hexEncrKey
=
carray2Hex
(
encrypted_SEK
.
data
(),
enc_len
);
carray2Hex
(
encrypted_SEK
.
data
(),
enc_len
,
hexEncrKey
.
data
(),
2
*
enc_len
+
1
);
spdlog
::
info
(
string
(
"Encrypted storage encryption key:"
)
+
hexEncrKey
.
data
());
spdlog
::
info
(
string
(
"Encrypted storage encryption key:"
)
+
hexEncrKey
.
data
());
...
@@ -281,10 +277,7 @@ void enter_SEK() {
...
@@ -281,10 +277,7 @@ void enter_SEK() {
auto
encrypted_SEK
=
check_and_set_SEK
(
sek
);
auto
encrypted_SEK
=
check_and_set_SEK
(
sek
);
vector
<
char
>
hexEncrKey
(
BUF_LEN
,
0
);
vector
<
char
>
hexEncrKey
=
carray2Hex
(
encrypted_SEK
->
data
(),
encrypted_SEK
->
size
());
carray2Hex
(
encrypted_SEK
->
data
(),
encrypted_SEK
->
size
(),
hexEncrKey
.
data
(),
BUF_LEN
);
spdlog
::
info
(
"Got sealed storage encryption key."
);
spdlog
::
info
(
"Got sealed storage encryption key."
);
...
...
SGXWalletServer.cpp
View file @
e0392674
...
@@ -623,12 +623,12 @@ Json::Value SGXWalletServer::complaintResponseImpl(const string &_polyName, int
...
@@ -623,12 +623,12 @@ Json::Value SGXWalletServer::complaintResponseImpl(const string &_polyName, int
}
}
}
}
for
(
int
i
=
0
;
i
<
_n
;
i
++
)
{
for
(
int
i
=
0
;
i
<
_n
;
i
++
)
{
string
name
=
_polyName
+
"_"
+
to_string
(
i
)
+
":"
;
string
name
=
_polyName
+
"_"
+
to_string
(
i
)
+
":"
;
LevelDB
::
getLevelDb
()
->
deleteDHDKGKey
(
name
);
LevelDB
::
getLevelDb
()
->
deleteDHDKGKey
(
name
);
string
shareG2_name
=
"shareG2_"
+
_polyName
+
"_"
+
to_string
(
i
)
+
":"
;
string
shareG2_name
=
"shareG2_"
+
_polyName
+
"_"
+
to_string
(
i
)
+
":"
;
LevelDB
::
getLevelDb
()
->
deleteKey
(
shareG2_name
);
LevelDB
::
getLevelDb
()
->
deleteKey
(
shareG2_name
);
}
}
LevelDB
::
getLevelDb
()
->
deleteKey
(
_polyName
);
LevelDB
::
getLevelDb
()
->
deleteKey
(
_polyName
);
string
encryptedSecretShareName
=
"encryptedSecretShare:"
+
_polyName
;
string
encryptedSecretShareName
=
"encryptedSecretShare:"
+
_polyName
;
...
...
TestUtils.cpp
View file @
e0392674
...
@@ -412,3 +412,126 @@ void TestUtils::doDKG(StubClient &c, int n, int t,
...
@@ -412,3 +412,126 @@ void TestUtils::doDKG(StubClient &c, int n, int t,
for
(
auto
&&
i
:
_blsKeyNames
)
for
(
auto
&&
i
:
_blsKeyNames
)
cerr
<<
i
<<
endl
;
cerr
<<
i
<<
endl
;
}
}
int
sessionKeyRecoverDH
(
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
();
point
session_key
=
point_init
();
pb_keyB_x
[
64
]
=
0
;
strncpy
(
pb_keyB_x
,
sshare
,
64
);
strncpy
(
pb_keyB_y
,
sshare
+
64
,
64
);
pb_keyB_y
[
64
]
=
0
;
if
(
!
common_key
)
{
mpz_clear
(
skey
);
point_clear
(
pub_keyB
);
point_clear
(
session_key
);
return
ret
;
}
common_key
[
0
]
=
0
;
if
(
!
skey_str
)
{
mpz_clear
(
skey
);
point_clear
(
pub_keyB
);
point_clear
(
session_key
);
return
ret
;
}
if
(
!
sshare
)
{
mpz_clear
(
skey
);
point_clear
(
pub_keyB
);
point_clear
(
session_key
);
return
ret
;
}
if
(
mpz_set_str
(
skey
,
skey_str
,
16
)
==
-
1
)
{
mpz_clear
(
skey
);
point_clear
(
pub_keyB
);
point_clear
(
session_key
);
return
ret
;
}
domain_parameters
curve
;
curve
=
domain_parameters_init
();
domain_parameters_load_curve
(
curve
,
secp256k1
);
if
(
point_set_hex
(
pub_keyB
,
pb_keyB_x
,
pb_keyB_y
)
!=
0
)
{
return
ret
;
}
point_multiplication
(
session_key
,
skey
,
pub_keyB
,
curve
);
SAFE_CHAR_BUF
(
arr_x
,
BUF_LEN
);
mpz_get_str
(
arr_x
,
16
,
session_key
->
x
);
int
n_zeroes
=
64
-
strlen
(
arr_x
);
for
(
int
i
=
0
;
i
<
n_zeroes
;
i
++
)
{
common_key
[
i
]
=
'0'
;
}
strncpy
(
common_key
+
n_zeroes
,
arr_x
,
strlen
(
arr_x
));
ret
=
0
;
mpz_clear
(
skey
);
point_clear
(
pub_keyB
);
point_clear
(
session_key
);
return
ret
;
}
int
xorDecryptDH
(
char
*
key
,
const
char
*
cypher
,
vector
<
char
>&
message
)
{
int
ret
=
-
1
;
if
(
!
cypher
)
{
return
ret
;
}
if
(
!
key
)
{
return
ret
;
}
if
(
!
message
.
data
())
{
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
,
33
))
{
return
ret
;
}
uint64_t
cypher_length
;
SAFE_CHAR_BUF
(
cypher_bin
,
33
);
if
(
!
hex2carray
(
cypher
,
&
cypher_length
,
(
uint8_t
*
)
cypher_bin
,
33
))
{
return
ret
;
}
for
(
int
i
=
0
;
i
<
32
;
i
++
)
{
msg_bin
[
i
]
=
cypher_bin
[
i
]
^
key_bin
[
i
];
}
message
=
carray2Hex
((
unsigned
char
*
)
msg_bin
,
32
);
ret
=
0
;
return
ret
;
}
TestUtils.h
View file @
e0392674
...
@@ -78,4 +78,8 @@ public:
...
@@ -78,4 +78,8 @@ public:
int
schainID
,
int
dkgID
);
int
schainID
,
int
dkgID
);
};
};
int
sessionKeyRecoverDH
(
const
char
*
skey_str
,
const
char
*
sshare
,
char
*
common_key
);
int
xorDecryptDH
(
char
*
key
,
const
char
*
cypher
,
vector
<
char
>&
message
);
#endif //SGXWALLET_TESTW_H
#endif //SGXWALLET_TESTW_H
secp256k1-sgx
@
5f235e8e
Subproject commit 5f235e8e9e821cd972c4a57afdfe47a7fe83acd0
testw.cpp
View file @
e0392674
...
@@ -31,6 +31,7 @@
...
@@ -31,6 +31,7 @@
#include "sgxwallet_common.h"
#include "sgxwallet_common.h"
#include "third_party/intel/create_enclave.h"
#include "third_party/intel/create_enclave.h"
#include "secure_enclave_u.h"
#include "secure_enclave_u.h"
#include "secure_enclave/DHDkg.h"
#include "third_party/intel/sgx_detect.h"
#include "third_party/intel/sgx_detect.h"
#include <gmp.h>
#include <gmp.h>
#include <sgx_urts.h>
#include <sgx_urts.h>
...
@@ -653,12 +654,40 @@ TEST_CASE_METHOD(TestFixture, "AES_DKG test", "[aes-dkg]") {
...
@@ -653,12 +654,40 @@ TEST_CASE_METHOD(TestFixture, "AES_DKG test", "[aes-dkg]") {
Json
::
Value
complaintResponse
=
c
.
complaintResponse
(
polyNames
[
1
],
t
,
n
,
0
);
Json
::
Value
complaintResponse
=
c
.
complaintResponse
(
polyNames
[
1
],
t
,
n
,
0
);
REQUIRE
(
complaintResponse
[
"status"
]
==
0
);
REQUIRE
(
complaintResponse
[
"status"
]
==
0
);
string
dhKey
=
complaintResponse
[
"dhKey"
].
asString
();
string
shareG2
=
complaintResponse
[
"share*G2"
].
asString
();
string
secretShare
=
secretShares
[
1
][
"secretShare"
].
asString
().
substr
(
0
,
192
);
vector
<
char
>
message
(
65
,
0
);
SAFE_CHAR_BUF
(
encr_sshare
,
BUF_LEN
)
strncpy
(
encr_sshare
,
pubEthKeys
[
0
].
asString
().
c_str
(),
128
);
SAFE_CHAR_BUF
(
common_key
,
BUF_LEN
);
REQUIRE
(
sessionKeyRecoverDH
(
dhKey
.
c_str
(),
encr_sshare
,
common_key
)
==
0
);
SAFE_CHAR_BUF
(
encr_sshare_check
,
BUF_LEN
)
strncpy
(
encr_sshare_check
,
secretShare
.
c_str
(),
ECDSA_SKEY_LEN
-
1
);
REQUIRE
(
xorDecryptDH
(
common_key
,
encr_sshare_check
,
message
)
==
0
);
mpz_t
hex_share
;
mpz_init
(
hex_share
);
mpz_set_str
(
hex_share
,
message
.
data
(),
16
);
libff
::
alt_bn128_Fr
share
(
hex_share
);
libff
::
alt_bn128_G2
decrypted_share_G2
=
share
*
libff
::
alt_bn128_G2
::
one
();
decrypted_share_G2
.
to_affine_coordinates
();
mpz_clear
(
hex_share
);
REQUIRE
(
convertG2ToString
(
decrypted_share_G2
)
==
shareG2
);
BLSSigShareSet
sigShareSet
(
t
,
n
);
BLSSigShareSet
sigShareSet
(
t
,
n
);
string
hash
=
SAMPLE_HASH
;
string
hash
=
SAMPLE_HASH
;
auto
hash_arr
=
make_shared
<
array
<
uint8_t
,
auto
hash_arr
=
make_shared
<
array
<
uint8_t
,
32
>
>
();
32
>>
();
uint64_t
binLen
;
uint64_t
binLen
;
...
...
testw.py
View file @
e0392674
...
@@ -43,7 +43,6 @@ testList = ["[first-run]",
...
@@ -43,7 +43,6 @@ testList = ["[first-run]",
"[bls-key-encrypt]"
,
"[bls-key-encrypt]"
,
"[dkg-aes-gen]"
,
"[dkg-aes-gen]"
,
"[dkg-aes-encr-sshares]"
,
"[dkg-aes-encr-sshares]"
,
"[dkg-verify]"
,
"[dkg-api]"
,
"[dkg-api]"
,
"[dkg-bls]"
,
"[dkg-bls]"
,
"[dkg-poly-exists]"
,
"[dkg-poly-exists]"
,
...
...
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