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
1df9c12c
Unverified
Commit
1df9c12c
authored
Jul 22, 2020
by
Oleh Nikolaiev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SKALE-2830 fix memory leaks
parent
615056d8
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
24 additions
and
41 deletions
+24
-41
BLSCrypto.cpp
BLSCrypto.cpp
+16
-39
BLSPrivateKeyShareSGX.cpp
BLSPrivateKeyShareSGX.cpp
+4
-1
SGXWalletServer.cpp
SGXWalletServer.cpp
+1
-1
DHDkg.c
secure_enclave/DHDkg.c
+1
-0
EnclaveCommon.cpp
secure_enclave/EnclaveCommon.cpp
+2
-0
No files found.
BLSCrypto.cpp
View file @
1df9c12c
...
@@ -51,20 +51,6 @@
...
@@ -51,20 +51,6 @@
#include "third_party/spdlog/spdlog.h"
#include "third_party/spdlog/spdlog.h"
#include "common.h"
#include "common.h"
std
::
string
*
FqToString
(
libff
::
alt_bn128_Fq
*
_fq
)
{
mpz_t
t
;
mpz_init
(
t
);
_fq
->
as_bigint
().
to_mpz
(
t
);
char
arr
[
mpz_sizeinbase
(
t
,
10
)
+
2
];
char
*
tmp
=
mpz_get_str
(
arr
,
10
,
t
);
mpz_clear
(
t
);
return
new
std
::
string
(
tmp
);
}
int
char2int
(
char
_input
)
{
int
char2int
(
char
_input
)
{
if
(
_input
>=
'0'
&&
_input
<=
'9'
)
if
(
_input
>=
'0'
&&
_input
<=
'9'
)
return
_input
-
'0'
;
return
_input
-
'0'
;
...
@@ -170,38 +156,29 @@ bool sign_aes(const char *_encryptedKeyHex, const char *_hashHex, size_t _t, siz
...
@@ -170,38 +156,29 @@ bool sign_aes(const char *_encryptedKeyHex, const char *_hashHex, size_t _t, siz
std
::
pair
<
libff
::
alt_bn128_G1
,
std
::
string
>
hash_with_hint
=
obj
->
HashtoG1withHint
(
hash
);
std
::
pair
<
libff
::
alt_bn128_G1
,
std
::
string
>
hash_with_hint
=
obj
->
HashtoG1withHint
(
hash
);
string
*
xStr
=
FqToString
(
&
(
hash_with_hint
.
first
.
X
)
);
string
xStr
=
BLSutils
::
ConvertToString
(
hash_with_hint
.
first
.
X
);
if
(
xStr
==
nullptr
)
{
if
(
xStr
.
empty
()
)
{
std
::
cerr
<<
"
Null
xStr"
<<
std
::
endl
;
std
::
cerr
<<
"
Empty
xStr"
<<
std
::
endl
;
BOOST_THROW_EXCEPTION
(
runtime_error
(
"
Null
xStr"
));
BOOST_THROW_EXCEPTION
(
runtime_error
(
"
Empty
xStr"
));
}
}
string
*
yStr
=
FqToString
(
&
(
hash_with_hint
.
first
.
Y
)
);
string
yStr
=
BLSutils
::
ConvertToString
(
hash_with_hint
.
first
.
Y
);
if
(
yStr
==
nullptr
)
{
if
(
yStr
.
empty
()
)
{
std
::
cerr
<<
"
Null
yStr"
<<
std
::
endl
;
std
::
cerr
<<
"
Empty
yStr"
<<
std
::
endl
;
BOOST_THROW_EXCEPTION
(
runtime_error
(
"
Null
yStr"
));
BOOST_THROW_EXCEPTION
(
runtime_error
(
"
Empty
yStr"
));
}
}
char
errMsg
[
BUF_LEN
];
vector
<
char
>
errMsg
(
BUF_LEN
,
0
);
memset
(
errMsg
,
0
,
BUF_LEN
);
char
xStrArg
[
BUF_LEN
];
char
yStrArg
[
BUF_LEN
];
char
signature
[
BUF_LEN
];
memset
(
xStrArg
,
0
,
BUF_LEN
);
memset
(
yStrArg
,
0
,
BUF_LEN
);
strncpy
(
xStrArg
,
xStr
->
c_str
(),
BUF_LEN
);
vector
<
char
>
signature
(
BUF_LEN
);
strncpy
(
yStrArg
,
yStr
->
c_str
(),
BUF_LEN
);
size_t
sz
=
0
;
size_t
sz
=
0
;
uint8_t
encryptedKey
[
BUF_LEN
]
;
vector
<
uint8_t
>
encryptedKey
(
BUF_LEN
)
;
bool
result
=
hex2carray
(
_encryptedKeyHex
,
&
sz
,
encryptedKey
);
bool
result
=
hex2carray
(
_encryptedKeyHex
,
&
sz
,
encryptedKey
.
data
()
);
if
(
!
result
)
{
if
(
!
result
)
{
cerr
<<
"Invalid hex encrypted key"
<<
endl
;
cerr
<<
"Invalid hex encrypted key"
<<
endl
;
...
@@ -211,8 +188,8 @@ bool sign_aes(const char *_encryptedKeyHex, const char *_hashHex, size_t _t, siz
...
@@ -211,8 +188,8 @@ bool sign_aes(const char *_encryptedKeyHex, const char *_hashHex, size_t _t, siz
int
errStatus
=
0
;
int
errStatus
=
0
;
sgx_status_t
status
=
sgx_status_t
status
=
trustedBlsSignMessageAES
(
eid
,
&
errStatus
,
errMsg
,
encryptedKey
,
trustedBlsSignMessageAES
(
eid
,
&
errStatus
,
&
errMsg
.
front
(),
encryptedKey
.
data
()
,
sz
,
xStrArg
,
yStrArg
,
signature
);
sz
,
&
xStr
.
front
(),
&
yStr
.
front
(),
&
signature
.
front
()
);
if
(
status
!=
SGX_SUCCESS
)
{
if
(
status
!=
SGX_SUCCESS
)
{
cerr
<<
"SGX enclave call to trustedBlsSignMessage failed:"
<<
status
<<
std
::
endl
;
cerr
<<
"SGX enclave call to trustedBlsSignMessage failed:"
<<
status
<<
std
::
endl
;
...
@@ -224,9 +201,9 @@ bool sign_aes(const char *_encryptedKeyHex, const char *_hashHex, size_t _t, siz
...
@@ -224,9 +201,9 @@ bool sign_aes(const char *_encryptedKeyHex, const char *_hashHex, size_t _t, siz
BOOST_THROW_EXCEPTION
(
runtime_error
(
"SGX enclave call to trustedBlsSignMessage failed"
));
BOOST_THROW_EXCEPTION
(
runtime_error
(
"SGX enclave call to trustedBlsSignMessage failed"
));
}
}
std
::
string
hint
=
BLSutils
::
ConvertToString
(
hash_with_hint
.
first
.
Y
)
+
":"
+
hash_with_hint
.
second
;
std
::
string
hint
=
yStr
+
":"
+
hash_with_hint
.
second
;
std
::
string
sig
=
signature
;
std
::
string
sig
(
signature
.
begin
(),
signature
.
end
())
;
sig
.
append
(
":"
);
sig
.
append
(
":"
);
sig
.
append
(
hint
);
sig
.
append
(
hint
);
...
...
BLSPrivateKeyShareSGX.cpp
View file @
1df9c12c
...
@@ -140,7 +140,7 @@ std::string BLSPrivateKeyShareSGX::signWithHelperSGXstr(
...
@@ -140,7 +140,7 @@ std::string BLSPrivateKeyShareSGX::signWithHelperSGXstr(
bool
result
=
hex2carray
(
encryptedKeyHex
->
c_str
(),
&
sz
,
encryptedKey
);
bool
result
=
hex2carray
(
encryptedKeyHex
->
c_str
(),
&
sz
,
encryptedKey
);
if
(
!
result
)
{
if
(
!
result
)
{
cerr
<<
"Invalid hex encrypted key"
<<
endl
;
cerr
<<
"Invalid hex encrypted key"
<<
endl
;
BOOST_THROW_EXCEPTION
(
std
::
invalid_argument
(
"Invalid hex encrypted key"
));
BOOST_THROW_EXCEPTION
(
std
::
invalid_argument
(
"Invalid hex encrypted key"
));
}
}
...
@@ -176,6 +176,9 @@ std::string BLSPrivateKeyShareSGX::signWithHelperSGXstr(
...
@@ -176,6 +176,9 @@ std::string BLSPrivateKeyShareSGX::signWithHelperSGXstr(
sig
.
append
(
":"
);
sig
.
append
(
":"
);
sig
.
append
(
hint
);
sig
.
append
(
hint
);
delete
xStr
;
delete
yStr
;
return
sig
;
return
sig
;
}
}
...
...
SGXWalletServer.cpp
View file @
1df9c12c
...
@@ -355,7 +355,7 @@ Json::Value SGXWalletServer::ecdsaSignMessageHashImpl(int _base, const string &_
...
@@ -355,7 +355,7 @@ Json::Value SGXWalletServer::ecdsaSignMessageHashImpl(int _base, const string &_
throw
SGXException
(
INVALID_ECSDA_SIGNATURE
,
"Invalid ecdsa signature"
);
throw
SGXException
(
INVALID_ECSDA_SIGNATURE
,
"Invalid ecdsa signature"
);
}
}
spdlog
::
debug
(
"got signature_s
{}"
,
signatureVector
.
at
(
2
));
spdlog
::
debug
(
"got signature_s {}"
,
signatureVector
.
at
(
2
));
result
[
"signature_v"
]
=
signatureVector
.
at
(
0
);
result
[
"signature_v"
]
=
signatureVector
.
at
(
0
);
result
[
"signature_r"
]
=
signatureVector
.
at
(
1
);
result
[
"signature_r"
]
=
signatureVector
.
at
(
1
);
...
...
secure_enclave/DHDkg.c
View file @
1df9c12c
...
@@ -71,6 +71,7 @@ void gen_session_key(char *skey_str, char* pb_keyB, char* common_key) {
...
@@ -71,6 +71,7 @@ void gen_session_key(char *skey_str, char* pb_keyB, char* common_key) {
mpz_clear
(
skey
);
mpz_clear
(
skey
);
point_clear
(
pub_keyB
);
point_clear
(
pub_keyB
);
point_clear
(
session_key
);
domain_parameters_clear
(
curve
);
domain_parameters_clear
(
curve
);
free
(
pb_keyB_x
);
free
(
pb_keyB_x
);
free
(
pb_keyB_y
);
free
(
pb_keyB_y
);
...
...
secure_enclave/EnclaveCommon.cpp
View file @
1df9c12c
...
@@ -117,6 +117,8 @@ bool enclave_sign(const char *_keyString, const char *_hashXString, const char *
...
@@ -117,6 +117,8 @@ bool enclave_sign(const char *_keyString, const char *_hashXString, const char *
libff
::
alt_bn128_G1
sign
=
key
->
as_bigint
()
*
hash
;
libff
::
alt_bn128_G1
sign
=
key
->
as_bigint
()
*
hash
;
delete
key
;
sign
.
to_affine_coordinates
();
sign
.
to_affine_coordinates
();
auto
r
=
stringFromG1
(
&
sign
);
auto
r
=
stringFromG1
(
&
sign
);
...
...
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