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
17dca977
Unverified
Commit
17dca977
authored
Sep 03, 2020
by
kladko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SKALE-3213
parent
a71e43c2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
48 deletions
+36
-48
BLSCrypto.cpp
BLSCrypto.cpp
+12
-35
BLSPrivateKeyShareSGX.cpp
BLSPrivateKeyShareSGX.cpp
+6
-13
common.h
common.h
+18
-0
No files found.
BLSCrypto.cpp
View file @
17dca977
...
...
@@ -51,7 +51,7 @@
#include "third_party/spdlog/spdlog.h"
#include "common.h"
st
d
::
st
ring
*
FqToString
(
libff
::
alt_bn128_Fq
*
_fq
)
{
string
*
FqToString
(
libff
::
alt_bn128_Fq
*
_fq
)
{
mpz_t
t
;
mpz_init
(
t
);
...
...
@@ -62,7 +62,7 @@ std::string *FqToString(libff::alt_bn128_Fq *_fq) {
mpz_get_str
(
arr
,
10
,
t
);
mpz_clear
(
t
);
return
new
st
d
::
st
ring
(
arr
);
return
new
string
(
arr
);
}
int
char2int
(
char
_input
)
{
...
...
@@ -167,19 +167,19 @@ bool sign_aes(const char *_encryptedKeyHex, const char *_hashHex, size_t _t, siz
shared_ptr
<
signatures
::
Bls
>
obj
;
obj
=
make_shared
<
signatures
::
Bls
>
(
signatures
::
Bls
(
_t
,
_n
));
std
::
pair
<
libff
::
alt_bn128_G1
,
std
::
string
>
hash_with_hint
=
obj
->
HashtoG1withHint
(
hash
);
pair
<
libff
::
alt_bn128_G1
,
string
>
hash_with_hint
=
obj
->
HashtoG1withHint
(
hash
);
string
*
xStr
=
FqToString
(
&
(
hash_with_hint
.
first
.
X
));
if
(
xStr
==
nullptr
)
{
std
::
cerr
<<
"Null xStr"
<<
std
::
endl
;
cerr
<<
"Null xStr"
<<
endl
;
BOOST_THROW_EXCEPTION
(
runtime_error
(
"Null xStr"
));
}
string
*
yStr
=
FqToString
(
&
(
hash_with_hint
.
first
.
Y
));
if
(
yStr
==
nullptr
)
{
std
::
cerr
<<
"Null yStr"
<<
std
::
endl
;
cerr
<<
"Null yStr"
<<
endl
;
delete
xStr
;
BOOST_THROW_EXCEPTION
(
runtime_error
(
"Null yStr"
));
}
...
...
@@ -208,33 +208,18 @@ bool sign_aes(const char *_encryptedKeyHex, const char *_hashHex, size_t _t, siz
if
(
!
result
)
{
cerr
<<
"Invalid hex encrypted key"
<<
endl
;
BOOST_THROW_EXCEPTION
(
std
::
invalid_argument
(
"Invalid hex encrypted key"
));
BOOST_THROW_EXCEPTION
(
invalid_argument
(
"Invalid hex encrypted key"
));
}
int
errStatus
=
0
;
sgx_status_t
status
=
trustedBlsSignMessageAES
(
eid
,
&
errStatus
,
errMsg
,
encryptedKey
,
sz
,
xStrArg
,
yStrArg
,
signature
);
HANDLE_TRUSTED_FUNCTION_ERROR
(
status
,
errStatus
,
errMsg
);
if
(
status
!=
SGX_SUCCESS
)
{
string
errString
=
string
(
"SGX enclave call to "
)
+
__FUNCTION__
+
" failed with errStatus:"
+
to_string
(
status
)
+
" Err message:"
+
errMsg
;
BOOST_THROW_EXCEPTION
(
runtime_error
(
errString
));
}
if
(
errStatus
!=
0
)
{
string
errString
=
string
(
"SGX enclave call to "
)
+
__FUNCTION__
+
" failed with errStatus:"
+
to_string
(
errStatus
)
+
" Err message:"
+
errMsg
;
BOOST_THROW_EXCEPTION
(
runtime_error
(
errString
));
}
std
::
string
hint
=
BLSutils
::
ConvertToString
(
hash_with_hint
.
first
.
Y
)
+
":"
+
hash_with_hint
.
second
;
string
hint
=
BLSutils
::
ConvertToString
(
hash_with_hint
.
first
.
Y
)
+
":"
+
hash_with_hint
.
second
;
st
d
::
st
ring
sig
=
signature
;
string
sig
=
signature
;
sig
.
append
(
":"
);
sig
.
append
(
hint
);
...
...
@@ -248,28 +233,20 @@ bool bls_sign(const char *_encryptedKeyHex, const char *_hashHex, size_t _t, siz
return
sign_aes
(
_encryptedKeyHex
,
_hashHex
,
_t
,
_n
,
_sig
);
}
st
d
::
st
ring
encryptBLSKeyShare2Hex
(
int
*
errStatus
,
char
*
err_string
,
const
char
*
_key
)
{
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
;
unsigned
int
encryptedLen
=
0
;
status
=
trustedEncryptKeyAES
(
eid
,
errStatus
,
errMsg
->
data
(),
keyArray
->
data
(),
encryptedKey
->
data
(),
&
encryptedLen
);
if
(
*
errStatus
!=
0
)
{
BOOST_THROW_EXCEPTION
(
SGXException
(
-
666
,
errMsg
->
data
()));
}
if
(
status
!=
SGX_SUCCESS
)
{
*
errStatus
=
-
1
;
return
""
;
}
HANDLE_TRUSTED_FUNCTION_ERROR
(
status
,
*
errStatus
,
errMsg
->
data
());
st
d
::
st
ring
result
(
2
*
BUF_LEN
,
'\0'
);
string
result
(
2
*
BUF_LEN
,
'\0'
);
carray2Hex
(
encryptedKey
->
data
(),
encryptedLen
,
&
result
.
front
());
...
...
BLSPrivateKeyShareSGX.cpp
View file @
17dca977
...
...
@@ -25,6 +25,8 @@
#include "BLSSignature.h"
#include "BLSutils.h"
#include "third_party/spdlog/spdlog.h"
#include "secure_enclave_u.h"
#include "sgxwallet_common.h"
#include "sgxwallet.h"
...
...
@@ -121,6 +123,7 @@ std::string BLSPrivateKeyShareSGX::signWithHelperSGXstr(
BOOST_THROW_EXCEPTION
(
runtime_error
(
"Null yStr"
));
}
char
errMsg
[
BUF_LEN
];
memset
(
errMsg
,
0
,
BUF_LEN
);
...
...
@@ -144,26 +147,16 @@ std::string BLSPrivateKeyShareSGX::signWithHelperSGXstr(
bool
result
=
hex2carray
(
encryptedKeyHex
->
c_str
(),
&
sz
,
encryptedKey
);
if
(
!
result
)
{
cerr
<<
"Invalid hex encrypted key"
<<
endl
;
BOOST_THROW_EXCEPTION
(
std
::
invalid_argument
(
"Invalid hex encrypted key"
));
spdlog
::
error
(
"Invalid hex encrypted key"
)
;
BOOST_THROW_EXCEPTION
(
invalid_argument
(
"Invalid hex encrypted key"
));
}
cerr
<<
"Key is "
+
*
encryptedKeyHex
<<
endl
;
sgx_status_t
status
=
trustedBlsSignMessageAES
(
eid
,
&
errStatus
,
errMsg
,
encryptedKey
,
encryptedKeyHex
->
size
()
/
2
,
xStrArg
,
yStrArg
,
signature
);
printf
(
"sig is: %s
\n
"
,
signature
);
HANDLE_TRUSTED_FUNCTION_ERROR
(
status
,
errStatus
,
errMsg
);
if
(
status
!=
SGX_SUCCESS
)
{
gmp_printf
(
"SGX enclave call to trustedBlsSignMessage failed: 0x%04x
\n
"
,
status
);
BOOST_THROW_EXCEPTION
(
runtime_error
(
"SGX enclave call to trustedBlsSignMessage failed"
));
}
if
(
errStatus
!=
0
)
{
BOOST_THROW_EXCEPTION
(
runtime_error
(
"Enclave trustedBlsSignMessage failed:"
+
to_string
(
errStatus
)
+
":"
+
errMsg
));
}
int
sigLen
;
...
...
common.h
View file @
17dca977
...
...
@@ -56,4 +56,22 @@ inline std::string className(const std::string &prettyFunction) {
throw InvalidStateException(__msg__, __CLASS_NAME__);}
#define HANDLE_TRUSTED_FUNCTION_ERROR(__STATUS__, __ERR_STATUS__, __ERR_MSG__) \
if (__STATUS__ != SGX_SUCCESS) { \
string __ERR_STRING__ = string("SGX enclave call to ") + \
__FUNCTION__ + " failed with status:" \
+ to_string(__STATUS__) + \
" Err message:" + __ERR_MSG__; \
BOOST_THROW_EXCEPTION(runtime_error(__ERR_MSG__)); \
}\
\
if (__ERR_STATUS__ != 0) {\
string __ERR_STRING__ = string("SGX enclave call to ") +\
__FUNCTION__ + " failed with errStatus:" + \
to_string(__ERR_STATUS__) + \
" Err message:" + __ERR_MSG__;\
BOOST_THROW_EXCEPTION(runtime_error(__ERR_STRING__)); \
}
#endif //SGXWALLET_COMMON_H
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