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
db9556e1
Unverified
Commit
db9556e1
authored
Jul 22, 2020
by
Oleh Nikolaiev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SKALE-2830 fix missformated signature
parent
1df9c12c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
16 deletions
+42
-16
BLSCrypto.cpp
BLSCrypto.cpp
+42
-16
No files found.
BLSCrypto.cpp
View file @
db9556e1
...
...
@@ -51,6 +51,20 @@
#include "third_party/spdlog/spdlog.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
)
{
if
(
_input
>=
'0'
&&
_input
<=
'9'
)
return
_input
-
'0'
;
...
...
@@ -156,29 +170,38 @@ 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
);
string
xStr
=
BLSutils
::
ConvertToString
(
hash_with_hint
.
first
.
X
);
string
*
xStr
=
FqToString
(
&
(
hash_with_hint
.
first
.
X
)
);
if
(
xStr
.
empty
()
)
{
std
::
cerr
<<
"
Empty
xStr"
<<
std
::
endl
;
BOOST_THROW_EXCEPTION
(
runtime_error
(
"
Empty
xStr"
));
if
(
xStr
==
nullptr
)
{
std
::
cerr
<<
"
Null
xStr"
<<
std
::
endl
;
BOOST_THROW_EXCEPTION
(
runtime_error
(
"
Null
xStr"
));
}
string
yStr
=
BLSutils
::
ConvertToString
(
hash_with_hint
.
first
.
Y
);
string
*
yStr
=
FqToString
(
&
(
hash_with_hint
.
first
.
Y
)
);
if
(
yStr
.
empty
()
)
{
std
::
cerr
<<
"
Empty
yStr"
<<
std
::
endl
;
BOOST_THROW_EXCEPTION
(
runtime_error
(
"
Empty
yStr"
));
if
(
yStr
==
nullptr
)
{
std
::
cerr
<<
"
Null
yStr"
<<
std
::
endl
;
BOOST_THROW_EXCEPTION
(
runtime_error
(
"
Null
yStr"
));
}
vector
<
char
>
errMsg
(
BUF_LEN
,
0
);
char
errMsg
[
BUF_LEN
];
memset
(
errMsg
,
0
,
BUF_LEN
);
char
xStrArg
[
BUF_LEN
];
char
yStrArg
[
BUF_LEN
];
char
signature
[
BUF_LEN
];
vector
<
char
>
signature
(
BUF_LEN
);
memset
(
xStrArg
,
0
,
BUF_LEN
);
memset
(
yStrArg
,
0
,
BUF_LEN
);
strncpy
(
xStrArg
,
xStr
->
c_str
(),
BUF_LEN
);
strncpy
(
yStrArg
,
yStr
->
c_str
(),
BUF_LEN
);
size_t
sz
=
0
;
vector
<
uint8_t
>
encryptedKey
(
BUF_LEN
)
;
uint8_t
encryptedKey
[
BUF_LEN
]
;
bool
result
=
hex2carray
(
_encryptedKeyHex
,
&
sz
,
encryptedKey
.
data
()
);
bool
result
=
hex2carray
(
_encryptedKeyHex
,
&
sz
,
encryptedKey
);
if
(
!
result
)
{
cerr
<<
"Invalid hex encrypted key"
<<
endl
;
...
...
@@ -188,8 +211,8 @@ bool sign_aes(const char *_encryptedKeyHex, const char *_hashHex, size_t _t, siz
int
errStatus
=
0
;
sgx_status_t
status
=
trustedBlsSignMessageAES
(
eid
,
&
errStatus
,
&
errMsg
.
front
(),
encryptedKey
.
data
()
,
sz
,
&
xStr
.
front
(),
&
yStr
.
front
(),
&
signature
.
front
()
);
trustedBlsSignMessageAES
(
eid
,
&
errStatus
,
errMsg
,
encryptedKey
,
sz
,
xStrArg
,
yStrArg
,
signature
);
if
(
status
!=
SGX_SUCCESS
)
{
cerr
<<
"SGX enclave call to trustedBlsSignMessage failed:"
<<
status
<<
std
::
endl
;
...
...
@@ -201,15 +224,18 @@ bool sign_aes(const char *_encryptedKeyHex, const char *_hashHex, size_t _t, siz
BOOST_THROW_EXCEPTION
(
runtime_error
(
"SGX enclave call to trustedBlsSignMessage failed"
));
}
std
::
string
hint
=
yStr
+
":"
+
hash_with_hint
.
second
;
std
::
string
hint
=
BLSutils
::
ConvertToString
(
hash_with_hint
.
first
.
Y
)
+
":"
+
hash_with_hint
.
second
;
std
::
string
sig
(
signature
.
begin
(),
signature
.
end
())
;
std
::
string
sig
=
signature
;
sig
.
append
(
":"
);
sig
.
append
(
hint
);
strncpy
(
_sig
,
sig
.
c_str
(),
BUF_LEN
);
delete
xStr
;
delete
yStr
;
return
true
;
}
...
...
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