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
90470814
Unverified
Commit
90470814
authored
May 13, 2020
by
kladko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SKALE-2568
parent
d692d477
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
53 additions
and
64 deletions
+53
-64
ECDSACrypto.cpp
ECDSACrypto.cpp
+37
-37
SGXWALLET_VERSION
SGXWALLET_VERSION
+1
-1
testw.cpp
testw.cpp
+14
-25
testw.py
testw.py
+1
-1
No files found.
ECDSACrypto.cpp
View file @
90470814
...
...
@@ -21,20 +21,25 @@
@date 2019
*/
#include "ECDSACrypto.h"
#include "BLSCrypto.h"
#include "sgxwallet.h"
#include "SGXException.h"
#include <iostream>
#include <fstream>
#include <gmp.h>
#include <random>
#include "spdlog/spdlog.h"
#include "common.h"
#include "BLSCrypto.h"
#include "ECDSACrypto.h"
static
default_random_engine
randGen
((
unsigned
int
)
time
(
0
));
string
concatPubKeyWith0x
(
char
*
pub_key_x
,
char
*
pub_key_y
)
{
string
px
=
pub_key_x
;
...
...
@@ -43,58 +48,53 @@ string concatPubKeyWith0x(char *pub_key_x, char *pub_key_y) {
return
result
;
}
void
fillRandomBuffer
(
vector
<
unsigned
char
>&
_buffer
)
{
ifstream
devRandom
(
"/dev/urandom"
,
ios
::
in
|
ios
::
binary
);
devRandom
.
exceptions
(
std
::
ifstream
::
failbit
|
std
::
ifstream
::
badbit
);
devRandom
.
read
((
char
*
)
_buffer
.
data
(),
_buffer
.
size
());
devRandom
.
close
();
}
std
::
vector
<
std
::
string
>
genECDSAKey
()
{
char
*
errMsg
=
(
char
*
)
calloc
(
1024
,
1
);
vector
<
char
>
errMsg
(
1024
,
0
);
int
errStatus
=
0
;
uint8_t
*
encr_pr_key
=
(
uint8_t
*
)
calloc
(
1024
,
1
);
char
*
pub_key_x
=
(
char
*
)
calloc
(
1024
,
1
);
char
*
pub_key_y
=
(
char
*
)
calloc
(
1024
,
1
);
vector
<
uint8_t
>
encr_pr_key
(
1024
,
0
);
vector
<
char
>
pub_key_x
(
1024
,
0
);
vector
<
char
>
pub_key_y
(
1024
,
0
);
uint32_t
enc_len
=
0
;
if
(
!
encryptKeys
)
status
=
trustedGenerateEcdsaKey
(
eid
,
&
errStatus
,
errMsg
,
encr_pr_key
,
&
enc_len
,
pub_key_x
,
pub_key_y
);
status
=
trustedGenerateEcdsaKey
(
eid
,
&
errStatus
,
errMsg
.
data
(),
encr_pr_key
.
data
(),
&
enc_len
,
pub_key_x
.
data
(),
pub_key_y
.
data
());
else
status
=
trustedGenerateEcdsaKeyAES
(
eid
,
&
errStatus
,
errMsg
,
encr_pr_key
,
&
enc_len
,
pub_key_x
,
pub_key_y
);
status
=
trustedGenerateEcdsaKeyAES
(
eid
,
&
errStatus
,
errMsg
.
data
(),
encr_pr_key
.
data
(),
&
enc_len
,
pub_key_x
.
data
(),
pub_key_y
.
data
());
if
(
status
!=
SGX_SUCCESS
||
errStatus
!=
0
)
{
spdlog
::
error
(
"RPCException thrown with status {}"
,
status
);
throw
SGXException
(
status
,
errMsg
);
throw
SGXException
(
status
,
errMsg
.
data
()
);
}
std
::
vector
<
std
::
string
>
keys
(
3
);
vector
<
char
>
hexEncrKey
(
BUF_LEN
*
2
,
0
);
carray2Hex
(
encr_pr_key
.
data
(),
enc_len
,
hexEncrKey
.
data
());
keys
.
at
(
0
)
=
hexEncrKey
.
data
();
keys
.
at
(
1
)
=
std
::
string
(
pub_key_x
.
data
())
+
std
::
string
(
pub_key_y
.
data
());
char
*
hexEncrKey
=
(
char
*
)
calloc
(
BUF_LEN
*
2
,
1
);
carray2Hex
(
encr_pr_key
,
enc_len
,
hexEncrKey
);
keys
.
at
(
0
)
=
hexEncrKey
;
keys
.
at
(
1
)
=
std
::
string
(
pub_key_x
)
+
std
::
string
(
pub_key_y
);
//concatPubKeyWith0x(pub_key_x, pub_key_y);//
unsigned
long
seed
=
randGen
();
spdlog
::
debug
(
"seed is {}"
,
seed
);
gmp_randstate_t
state
;
gmp_randinit_default
(
state
);
vector
<
unsigned
char
>
randBuffer
(
32
,
0
);
fillRandomBuffer
(
randBuffer
);
gmp_randseed_ui
(
state
,
seed
);
vector
<
char
>
rand_str
(
64
,
0
);
mpz_t
rand32
;
mpz_init
(
rand32
);
mpz_urandomb
(
rand32
,
state
,
256
);
carray2Hex
(
randBuffer
.
data
(),
32
,
rand_str
.
data
());
char
arr
[
mpz_sizeinbase
(
rand32
,
16
)
+
2
];
char
*
rand_str
=
mpz_get_str
(
arr
,
16
,
rand32
);
keys
.
at
(
2
)
=
rand_str
.
data
();
keys
.
at
(
2
)
=
rand_str
;
gmp_randclear
(
state
);
mpz_clear
(
rand32
);
free
(
errMsg
);
free
(
pub_key_x
);
free
(
pub_key_y
);
free
(
encr_pr_key
);
free
(
hexEncrKey
);
CHECK_STATE
(
keys
.
at
(
2
).
size
()
==
64
);
return
keys
;
}
...
...
SGXWALLET_VERSION
View file @
90470814
#define SGXWALLET_VERSION "1.49.2"
\ No newline at end of file
#define SGXWALLET_VERSION "1.49.3"
\ No newline at end of file
testw.cpp
View file @
90470814
...
...
@@ -433,37 +433,26 @@ TEST_CASE_METHOD(TestFixture, "ECDSA key gen API", "[ecdsa-key-gen-api]") {
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
try
{
for
(
int
i
=
0
;
i
<=
20
;
i
++
)
{
try
{
Json
::
Value
genKey
=
c
.
generateECDSAKey
();
cout
<<
genKey
<<
endl
;
cout
<<
c
.
ecdsaSignMessageHash
(
16
,
genKey
[
"keyName"
].
asString
(),
SAMPLE_HASH
);
Json
::
Value
getPubKey
=
c
.
getPublicECDSAKey
(
genKey
[
"keyName"
].
asString
());
Json
::
Value
publicKeys
;
publicKeys
.
append
(
SAMPLE_DKG_PUB_KEY_1
);
publicKeys
.
append
(
SAMPLE_DKG_PUB_KEY_2
);
string
share_big0
=
"501e364a6ea516f4812b013bcc150cbb435a2c465c9fd525951264969d8441a986798fd3317c1c3e60f868bb26c4cff837d9185f4be6015d8326437cb5b69480495859cd5a385430ece51252acdc234d8dbde75708b600ac50b2974e813ee26bd87140d88647fcc44df7262bbba24328e8ce622cd627a15b508ffa0db9ae81e0e110fab42cfe40da66b524218ca3c8e5aa3363fbcadef748dc3523a7ffb95b8f5d8141a5163db9f69d1ab223494ed71487c9bb032a74c08a222d897a5e49a617"
;
string
share_big
=
"03f749e2fcc28021895d757ec16d1636784446f5effcd3096b045136d8ab02657b32adc577f421330b81f5b7063df3b08a0621a897df2584b9046ca416e50ecc27e8c3277e981f7e650f8640289be128eecf0105f89a20e5ffb164744c45cf191d627ce9ab6c44e2ef96f230f2a4de742ea43b6f74b56849138026610b2d965605ececba527048a0f29f46334b1cec1d23df036248b24eccca99057d24764acee66c1a3f2f44771d0d237bf9d18c4177277e3ce3dc4e83686a2647fce1565ee0"
;
string
share
=
share_big
.
substr
(
0
,
192
);
string
publicShares
=
"1fc8154abcbf0c2ebf559571d7b57a8995c0e293a73d4676a8f76051a0d0ace30e00a87c9f087254c9c860c3215c4f11e8f85a3e8fae19358f06a0cbddf3df1924b1347b9b58f5bcb20958a19bdbdd832181cfa9f9e9fd698f6a485051cb47b829d10f75b6e227a7d7366dd02825b5718072cd42c39f0352071808622b7db6421b1069f519527e49052a8da6e3720cbda9212fc656eef945f5e56a4159c3b9622d883400460a9eff07fe1873f9b1ec50f6cf70098b9da0b90625b176f12329fa2ecc65082c626dc702d9cfb23a06770d4a2c7867e269efe84e3709b11001fb380a32d609855d1d46bc60f21140c636618b8ff55ed06d7788b6f81b498f96d3f9"
;
Json
::
Value
SecretShare
;
SecretShare
.
append
(
share_big0
);
SecretShare
.
append
(
share_big
);
REQUIRE
(
genKey
[
"status"
].
asInt
()
==
0
);
string
shares
=
"252122c309ed1f32faa897ede140c5b9c1bc07d5d9c94b7a22d4eeb13da7b7142aa466376a6008de4aab9858aa34848775282c4c3b56370bf25827321619c6e47701c8a32e3f4bb28f5a3b12a09800f318c550cedff6150e9a673ea56ece8b7637092c06c423b627c38ff86d1e66608bdc1496ef855b86e9f773441ac0b285d92aa466376a6008de4aab9858aa34848775282c4c3b56370bf25827321619c6e47701c8a32e3f4bb28f5a3b12a09800f318c550cedff6150e9a673ea56ece8b76"
;
auto
keyName
=
genKey
[
"keyName"
].
asString
()
;
REQUIRE
(
keyName
.
size
()
==
68
);
string
s_share
=
"13b871ad5025fed10a41388265b19886e78f449f758fe8642ade51440fcf850bb2083f87227d8fb53fdfb2854e2d0abec4f47e2197b821b564413af96124cd84a8700f8eb9ed03161888c9ef58d6e5896403de3608e634e23e92fba041aa283484427d0e6de20922216c65865cfe26edd2cf9cbfc3116d007710e8d82feafd9135c497bef0c800ca310ba6044763572681510dad5e043ebd87ffaa1a4cd45a899222207f3d05dec8110d132ad34c62d6a3b40bf8e9f40f875125c3035062d2ca"
;
string
ethKeyName
=
SAMPLE_KEY_NAME
;
Json
::
Value
sig
=
c
.
ecdsaSignMessageHash
(
16
,
genKey
[
"keyName"
].
asString
(),
SAMPLE_HASH
);
REQUIRE
(
sig
[
"status"
].
asInt
()
==
0
);
Json
::
Value
getPubKey
=
c
.
getPublicECDSAKey
(
genKey
[
"keyName"
].
asString
());
REQUIRE
(
getPubKey
[
"status"
].
asInt
()
==
0
);
}
catch
(
JsonRpcException
&
e
)
{
cerr
<<
e
.
what
()
<<
endl
;
throw
;
}
}
}
...
...
testw.py
View file @
90470814
...
...
@@ -50,7 +50,7 @@ testList = [ "[cert-sign]",
"[dkg-bls]"
,
"[dkg-poly-exists]"
,
"[dkg-pub-shares]"
,
"[many-threads-crypto]"
,
#
"[many-threads-crypto]",
"[aes-encrypt-decrypt]"
,
"[aes-dkg]"
]
...
...
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