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
2a1e807a
Unverified
Commit
2a1e807a
authored
May 21, 2020
by
kladko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SKALE-1880-fix-ecdsa
parent
d2e6f8ca
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
28 deletions
+28
-28
SGXWalletServer.cpp
SGXWalletServer.cpp
+28
-28
No files found.
SGXWalletServer.cpp
View file @
2a1e807a
...
@@ -212,15 +212,15 @@ SGXWalletServer::blsSignMessageHashImpl(const string &_keyShareName, const strin
...
@@ -212,15 +212,15 @@ SGXWalletServer::blsSignMessageHashImpl(const string &_keyShareName, const strin
if
(
!
checkName
(
_keyShareName
,
"BLS_KEY"
))
{
if
(
!
checkName
(
_keyShareName
,
"BLS_KEY"
))
{
throw
SGXException
(
INVALID_POLY_NAME
,
"Invalid BLSKey name"
);
throw
SGXException
(
INVALID_POLY_NAME
,
"Invalid BLSKey name"
);
}
}
string
cutHash
=
_messageHash
;
string
hashTmp
=
_messageHash
;
if
(
cutHash
[
0
]
==
'0'
&&
(
cutHash
[
1
]
==
'x'
||
cutHash
[
1
]
==
'X'
))
{
if
(
hashTmp
[
0
]
==
'0'
&&
(
hashTmp
[
1
]
==
'x'
||
hashTmp
[
1
]
==
'X'
))
{
cutHash
.
erase
(
cutHash
.
begin
(),
cutHash
.
begin
()
+
2
);
hashTmp
.
erase
(
hashTmp
.
begin
(),
hashTmp
.
begin
()
+
2
);
}
}
while
(
cutHash
[
0
]
==
'0'
)
{
while
(
hashTmp
[
0
]
==
'0'
)
{
cutHash
.
erase
(
cutHash
.
begin
(),
cutHash
.
begin
()
+
1
);
hashTmp
.
erase
(
hashTmp
.
begin
(),
hashTmp
.
begin
()
+
1
);
}
}
if
(
!
checkHex
(
cutHash
))
{
if
(
!
checkHex
(
hashTmp
))
{
throw
SGXException
(
INVALID_HEX
,
"Invalid hash"
);
throw
SGXException
(
INVALID_HEX
,
"Invalid hash"
);
}
}
...
@@ -318,10 +318,10 @@ Json::Value SGXWalletServer::renameECDSAKeyImpl(const string &_keyName, const st
...
@@ -318,10 +318,10 @@ Json::Value SGXWalletServer::renameECDSAKeyImpl(const string &_keyName, const st
throw
SGXException
(
UNKNOWN_ERROR
,
"invalid key name"
);
throw
SGXException
(
UNKNOWN_ERROR
,
"invalid key name"
);
}
}
shared_ptr
<
string
>
key_ptr
=
readFromDb
(
_tempKeyName
);
shared_ptr
<
string
>
encryptedKey
=
readFromDb
(
_tempKeyName
);
writeDataToDB
(
_keyName
,
*
key_ptr
);
writeDataToDB
(
_keyName
,
*
encryptedKey
);
LevelDB
::
getLevelDb
()
->
deleteTempNEK
(
_tempKeyName
);
LevelDB
::
getLevelDb
()
->
deleteTempNEK
(
_tempKeyName
);
}
HANDLE_SGX_EXCEPTION
(
result
)
}
HANDLE_SGX_EXCEPTION
(
result
)
...
@@ -339,40 +339,40 @@ Json::Value SGXWalletServer::ecdsaSignMessageHashImpl(int _base, const string &_
...
@@ -339,40 +339,40 @@ Json::Value SGXWalletServer::ecdsaSignMessageHashImpl(int _base, const string &_
result
[
"signature_r"
]
=
""
;
result
[
"signature_r"
]
=
""
;
result
[
"signature_s"
]
=
""
;
result
[
"signature_s"
]
=
""
;
vector
<
string
>
sign
_vect
(
3
);
vector
<
string
>
sign
atureVector
(
3
);
try
{
try
{
string
cutHash
=
_messageHash
;
string
hashTmp
=
_messageHash
;
if
(
cutHash
[
0
]
==
'0'
&&
(
cutHash
[
1
]
==
'x'
||
cutHash
[
1
]
==
'X'
))
{
if
(
hashTmp
[
0
]
==
'0'
&&
(
hashTmp
[
1
]
==
'x'
||
hashTmp
[
1
]
==
'X'
))
{
cutHash
.
erase
(
cutHash
.
begin
(),
cutHash
.
begin
()
+
2
);
hashTmp
.
erase
(
hashTmp
.
begin
(),
hashTmp
.
begin
()
+
2
);
}
}
while
(
cutHash
[
0
]
==
'0'
)
{
while
(
hashTmp
[
0
]
==
'0'
)
{
cutHash
.
erase
(
cutHash
.
begin
(),
cutHash
.
begin
()
+
1
);
hashTmp
.
erase
(
hashTmp
.
begin
(),
hashTmp
.
begin
()
+
1
);
}
}
if
(
!
checkECDSAKeyName
(
_keyName
))
{
if
(
!
checkECDSAKeyName
(
_keyName
))
{
throw
SGXException
(
INVALID_ECDSA_KEY_NAME
,
"Invalid ECDSA key name"
);
throw
SGXException
(
INVALID_ECDSA_KEY_NAME
,
"Invalid ECDSA key name"
);
}
}
if
(
!
checkHex
(
cutHash
))
{
if
(
!
checkHex
(
hashTmp
))
{
throw
SGXException
(
INVALID_HEX
,
"Invalid hash"
);
throw
SGXException
(
INVALID_HEX
,
"Invalid hash"
);
}
}
if
(
_base
<=
0
||
_base
>
32
)
{
if
(
_base
<=
0
||
_base
>
32
)
{
throw
SGXException
(
-
22
,
"Invalid base"
);
throw
SGXException
(
-
22
,
"Invalid base"
);
}
}
shared_ptr
<
string
>
key_ptr
=
readFromDb
(
_keyName
,
""
);
shared_ptr
<
string
>
encryptedKey
=
readFromDb
(
_keyName
,
""
);
sign
_vect
=
ecdsaSignHash
(
key_ptr
->
c_str
(),
cutHash
.
c_str
(),
_base
);
sign
atureVector
=
ecdsaSignHash
(
encryptedKey
->
c_str
(),
hashTmp
.
c_str
(),
_base
);
if
(
sign
_vect
.
size
()
!=
3
)
{
if
(
sign
atureVector
.
size
()
!=
3
)
{
throw
SGXException
(
INVALID_ECSDA_SIGNATURE
,
"Invalid ecdsa signature"
);
throw
SGXException
(
INVALID_ECSDA_SIGNATURE
,
"Invalid ecdsa signature"
);
}
}
spdlog
::
debug
(
"got signature_s {}"
,
sign
_vect
.
at
(
2
));
spdlog
::
debug
(
"got signature_s {}"
,
sign
atureVector
.
at
(
2
));
result
[
"signature_v"
]
=
sign
_vect
.
at
(
0
);
result
[
"signature_v"
]
=
sign
atureVector
.
at
(
0
);
result
[
"signature_r"
]
=
sign
_vect
.
at
(
1
);
result
[
"signature_r"
]
=
sign
atureVector
.
at
(
1
);
result
[
"signature_s"
]
=
sign
_vect
.
at
(
2
);
result
[
"signature_s"
]
=
sign
atureVector
.
at
(
2
);
}
HANDLE_SGX_EXCEPTION
(
result
)
}
HANDLE_SGX_EXCEPTION
(
result
)
...
@@ -443,14 +443,14 @@ Json::Value SGXWalletServer::getVerificationVectorImpl(const string &_polyName,
...
@@ -443,14 +443,14 @@ Json::Value SGXWalletServer::getVerificationVectorImpl(const string &_polyName,
throw
SGXException
(
INVALID_DKG_PARAMS
,
"Invalid parameters: n or t "
);
throw
SGXException
(
INVALID_DKG_PARAMS
,
"Invalid parameters: n or t "
);
}
}
shared_ptr
<
string
>
encr_poly_ptr
=
readFromDb
(
_polyName
);
shared_ptr
<
string
>
encrPoly
=
readFromDb
(
_polyName
);
verifVector
=
get_verif_vect
(
encr
_poly_ptr
->
c_str
(),
_t
,
_n
);
verifVector
=
get_verif_vect
(
encr
Poly
->
c_str
(),
_t
,
_n
);
for
(
int
i
=
0
;
i
<
_t
;
i
++
)
{
for
(
int
i
=
0
;
i
<
_t
;
i
++
)
{
vector
<
string
>
cur
_c
oef
=
verifVector
.
at
(
i
);
vector
<
string
>
cur
rentC
oef
=
verifVector
.
at
(
i
);
for
(
int
j
=
0
;
j
<
4
;
j
++
)
{
for
(
int
j
=
0
;
j
<
4
;
j
++
)
{
result
[
"verificationVector"
][
i
][
j
]
=
cur
_c
oef
.
at
(
j
);
result
[
"verificationVector"
][
i
][
j
]
=
cur
rentC
oef
.
at
(
j
);
}
}
}
}
...
@@ -480,7 +480,7 @@ Json::Value SGXWalletServer::getSecretShareImpl(const string &_polyName, const J
...
@@ -480,7 +480,7 @@ Json::Value SGXWalletServer::getSecretShareImpl(const string &_polyName, const J
throw
SGXException
(
INVALID_DKG_PARAMS
,
"Invalid DKG parameters: n or t "
);
throw
SGXException
(
INVALID_DKG_PARAMS
,
"Invalid DKG parameters: n or t "
);
}
}
shared_ptr
<
string
>
encr
_poly_ptr
=
readFromDb
(
_polyName
);
shared_ptr
<
string
>
encr
Poly
=
readFromDb
(
_polyName
);
vector
<
string
>
pubKeysStrs
;
vector
<
string
>
pubKeysStrs
;
for
(
int
i
=
0
;
i
<
_n
;
i
++
)
{
for
(
int
i
=
0
;
i
<
_n
;
i
++
)
{
...
@@ -490,7 +490,7 @@ Json::Value SGXWalletServer::getSecretShareImpl(const string &_polyName, const J
...
@@ -490,7 +490,7 @@ Json::Value SGXWalletServer::getSecretShareImpl(const string &_polyName, const J
pubKeysStrs
.
push_back
(
_pubKeys
[
i
].
asString
());
pubKeysStrs
.
push_back
(
_pubKeys
[
i
].
asString
());
}
}
string
s
=
trustedGetSecretShares
(
_polyName
,
encr
_poly_ptr
->
c_str
(),
pubKeysStrs
,
_t
,
_n
);
string
s
=
trustedGetSecretShares
(
_polyName
,
encr
Poly
->
c_str
(),
pubKeysStrs
,
_t
,
_n
);
//cerr << "result is " << s << endl;
//cerr << "result is " << s << endl;
result
[
"secretShare"
]
=
s
;
result
[
"secretShare"
]
=
s
;
...
...
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