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
4fcda5df
Unverified
Commit
4fcda5df
authored
Aug 11, 2020
by
Stan Kladko
Committed by
GitHub
Aug 11, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #136 from skalenetwork/SKALE-3067-remove-use-check
Skale 3067 remove use check
parents
6502d7bc
4f68f132
Changes
7
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
408 additions
and
359 deletions
+408
-359
ECDSACrypto.cpp
ECDSACrypto.cpp
+12
-15
Log.h
Log.h
+3
-1
EnclaveCommon.cpp
secure_enclave/EnclaveCommon.cpp
+5
-0
EnclaveCommon.h
secure_enclave/EnclaveCommon.h
+7
-0
secure_enclave.c
secure_enclave/secure_enclave.c
+366
-338
testw.cpp
testw.cpp
+14
-4
testw.py
testw.py
+1
-1
No files found.
ECDSACrypto.cpp
View file @
4fcda5df
...
@@ -175,11 +175,8 @@ vector <string> ecdsaSignHash(const char *encryptedKeyHex, const char *hashHex,
...
@@ -175,11 +175,8 @@ vector <string> ecdsaSignHash(const char *encryptedKeyHex, const char *hashHex,
string
pubKeyStr
=
""
;
string
pubKeyStr
=
""
;
shared_ptr
<
SGXException
>
exception
=
NULL
;
if
(
!
hex2carray
(
encryptedKeyHex
,
&
decLen
,
encryptedKey
.
data
()))
{
if
(
!
hex2carray
(
encryptedKeyHex
,
&
decLen
,
encryptedKey
.
data
()))
{
exception
=
make_shared
<
SGXException
>
(
INVALID_HEX
,
"Invalid encryptedKeyHex"
);
throw
SGXException
(
INVALID_HEX
,
"Invalid encryptedKeyHex"
);
goto
clean
;
}
}
status
=
trustedEcdsaSignAES
(
eid
,
&
errStatus
,
status
=
trustedEcdsaSignAES
(
eid
,
&
errStatus
,
...
@@ -188,15 +185,14 @@ vector <string> ecdsaSignHash(const char *encryptedKeyHex, const char *hashHex,
...
@@ -188,15 +185,14 @@ vector <string> ecdsaSignHash(const char *encryptedKeyHex, const char *hashHex,
signatureS
.
data
(),
&
signatureV
,
base
);
signatureS
.
data
(),
&
signatureV
,
base
);
if
(
errStatus
!=
0
)
{
if
(
errStatus
!=
0
)
{
exception
=
make_shared
<
SGXException
>
(
666
,
errMsg
.
data
());
throw
SGXException
(
666
,
errMsg
.
data
());
goto
clean
;
}
}
if
(
status
!=
SGX_SUCCESS
)
{
if
(
status
!=
SGX_SUCCESS
)
{
spdlog
::
error
(
"failed to sign {}"
,
status
);
spdlog
::
error
(
"failed to sign {}"
,
status
);
exception
=
make_shared
<
SGXException
>
(
666
,
"failed to sign"
);
throw
SGXException
(
666
,
"failed to sign"
);
goto
clean
;
}
}
signatureVector
.
at
(
0
)
=
to_string
(
signatureV
);
signatureVector
.
at
(
0
)
=
to_string
(
signatureV
);
if
(
base
==
16
)
{
if
(
base
==
16
)
{
signatureVector
.
at
(
1
)
=
"0x"
+
string
(
signatureR
.
data
());
signatureVector
.
at
(
1
)
=
"0x"
+
string
(
signatureR
.
data
());
...
@@ -210,15 +206,16 @@ vector <string> ecdsaSignHash(const char *encryptedKeyHex, const char *hashHex,
...
@@ -210,15 +206,16 @@ vector <string> ecdsaSignHash(const char *encryptedKeyHex, const char *hashHex,
pubKeyStr
=
getECDSAPubKey
(
encryptedKeyHex
);
pubKeyStr
=
getECDSAPubKey
(
encryptedKeyHex
);
if
(
!
verifyECDSASig
(
pubKeyStr
,
hashHex
,
signatureR
.
data
(),
signatureS
.
data
(),
base
))
{
static
uint64_t
i
=
0
;
exception
=
make_shared
<
SGXException
>
(
667
,
"ECDSA did not verify"
);
goto
clean
;
}
clean
:
i
++
;
if
(
i
%
1000
==
0
)
{
if
(
exception
)
if
(
!
verifyECDSASig
(
pubKeyStr
,
hashHex
,
signatureR
.
data
(),
signatureS
.
data
(),
base
))
{
throw
*
exception
;
throw
SGXException
(
667
,
"ECDSA did not verify"
);
}
}
return
signatureVector
;
return
signatureVector
;
}
}
Log.h
View file @
4fcda5df
...
@@ -73,7 +73,9 @@ public:
...
@@ -73,7 +73,9 @@ public:
static
void
handleSGXException
(
Json
::
Value
&
_result
,
SGXException
&
_e
);
static
void
handleSGXException
(
Json
::
Value
&
_result
,
SGXException
&
_e
);
};
};
#define INIT_RESULT(__RESULT__) Json::Value __RESULT__; __RESULT__["status"] = 0; __RESULT__["errorMessage"] = "";
#define INIT_RESULT(__RESULT__) Json::Value __RESULT__; __RESULT__["status"] = 0; __RESULT__["errorMessage"] = \
"Server error. Please see server log.";
#define RESULT_SUCCESS(__RESULT__) ; __RESULT__["status"] = 0; __RESULT__["errorMessage"] = "";
#define HANDLE_SGX_EXCEPTION(_RESULT_) catch (SGXException &__e) { Log::handleSGXException(_RESULT_, __e);} \
#define HANDLE_SGX_EXCEPTION(_RESULT_) catch (SGXException &__e) { Log::handleSGXException(_RESULT_, __e);} \
catch (exception &__e) {spdlog::error(__e.what()); _RESULT_["status"] = 1; _RESULT_["errorMessage"] = __e.what();}
catch (exception &__e) {spdlog::error(__e.what()); _RESULT_["status"] = 1; _RESULT_["errorMessage"] = __e.what();}
...
...
secure_enclave/EnclaveCommon.cpp
View file @
4fcda5df
...
@@ -135,11 +135,16 @@ libff::alt_bn128_Fr *keyFromString(const char *_keyStringHex) {
...
@@ -135,11 +135,16 @@ libff::alt_bn128_Fr *keyFromString(const char *_keyStringHex) {
int
inited
=
0
;
int
inited
=
0
;
domain_parameters
curve
;
void
enclave_init
()
{
void
enclave_init
()
{
if
(
inited
==
1
)
if
(
inited
==
1
)
return
;
return
;
inited
=
1
;
inited
=
1
;
libff
::
init_alt_bn128_params
();
libff
::
init_alt_bn128_params
();
curve
=
domain_parameters_init
();
domain_parameters_load_curve
(
curve
,
secp256k1
);
}
}
bool
enclave_sign
(
const
char
*
_keyString
,
const
char
*
_hashXString
,
const
char
*
_hashYString
,
bool
enclave_sign
(
const
char
*
_keyString
,
const
char
*
_hashXString
,
const
char
*
_hashYString
,
...
...
secure_enclave/EnclaveCommon.h
View file @
4fcda5df
...
@@ -21,6 +21,11 @@
...
@@ -21,6 +21,11 @@
@date 2019
@date 2019
*/
*/
#include "DomainParameters.h"
#include "Signature.h"
#include "Curves.h"
#ifndef SGXWALLET_ENCLAVECOMMON_H
#ifndef SGXWALLET_ENCLAVECOMMON_H
#define SGXWALLET_ENCLAVECOMMON_H
#define SGXWALLET_ENCLAVECOMMON_H
...
@@ -59,5 +64,7 @@ extern uint32_t globalLogLevel_;
...
@@ -59,5 +64,7 @@ extern uint32_t globalLogLevel_;
extern
unsigned
char
*
globalRandom
;
extern
unsigned
char
*
globalRandom
;
extern
domain_parameters
curve
;
#endif //SGXWALLET_ENCLAVECOMMON_H
#endif //SGXWALLET_ENCLAVECOMMON_H
secure_enclave/secure_enclave.c
View file @
4fcda5df
This diff is collapsed.
Click to expand it.
testw.cpp
View file @
4fcda5df
...
@@ -111,10 +111,13 @@ TEST_CASE_METHOD(TestFixture, "ECDSA keygen and signature test", "[ecdsa-key-sig
...
@@ -111,10 +111,13 @@ TEST_CASE_METHOD(TestFixture, "ECDSA keygen and signature test", "[ecdsa-key-sig
vector
<
char
>
signatureS
(
BUF_LEN
,
0
);
vector
<
char
>
signatureS
(
BUF_LEN
,
0
);
uint8_t
signatureV
=
0
;
uint8_t
signatureV
=
0
;
for
(
int
i
=
0
;
i
<
50
;
i
++
)
{
status
=
trustedEcdsaSign
(
eid
,
&
errStatus
,
errMsg
.
data
(),
encrPrivKey
.
data
(),
encLen
,
status
=
trustedEcdsaSign
(
eid
,
&
errStatus
,
errMsg
.
data
(),
encrPrivKey
.
data
(),
encLen
,
(
unsigned
char
*
)
hex
.
data
(),
(
unsigned
char
*
)
hex
.
data
(),
signatureR
.
data
(),
signatureR
.
data
(),
signatureS
.
data
(),
&
signatureV
,
16
);
signatureS
.
data
(),
&
signatureV
,
16
);
}
REQUIRE
(
status
==
SGX_SUCCESS
);
REQUIRE
(
status
==
SGX_SUCCESS
);
...
@@ -286,6 +289,13 @@ TEST_CASE_METHOD(TestFixture, "ECDSA key gen API", "[ecdsa-key-gen-api]") {
...
@@ -286,6 +289,13 @@ TEST_CASE_METHOD(TestFixture, "ECDSA key gen API", "[ecdsa-key-gen-api]") {
}
}
}
}
auto
keyName
=
genECDSAKeyAPI
(
c
);
Json
::
Value
sig
=
c
.
ecdsaSignMessageHash
(
10
,
keyName
,
SAMPLE_HASH
);
for
(
int
i
=
0
;
i
<=
20
;
i
++
)
{
for
(
int
i
=
0
;
i
<=
20
;
i
++
)
{
try
{
try
{
auto
keyName
=
genECDSAKeyAPI
(
c
);
auto
keyName
=
genECDSAKeyAPI
(
c
);
...
...
testw.py
View file @
4fcda5df
...
@@ -51,7 +51,7 @@ testList = [ "[cert-sign]",
...
@@ -51,7 +51,7 @@ testList = [ "[cert-sign]",
"[dkg-api]"
,
"[dkg-api]"
,
"[dkg-bls]"
,
"[dkg-bls]"
,
"[dkg-poly-exists]"
,
"[dkg-poly-exists]"
,
"[dkg-pub-shares]"
,
#
"[dkg-pub-shares]",
"[dkg-aes-pub-shares]"
,
"[dkg-aes-pub-shares]"
,
"[many-threads-crypto]"
,
"[many-threads-crypto]"
,
"[aes-encrypt-decrypt]"
,
"[aes-encrypt-decrypt]"
,
...
...
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