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
c81d1128
Unverified
Commit
c81d1128
authored
Mar 24, 2020
by
kladko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SKALE-2341 Added tags for older commits
parent
641e3e57
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
148 additions
and
292 deletions
+148
-292
BLSPrivateKeyShareSGX.cpp
BLSPrivateKeyShareSGX.cpp
+0
-2
DKGCrypto.cpp
DKGCrypto.cpp
+85
-109
DKGCrypto.h
DKGCrypto.h
+3
-3
ECDSACrypto.cpp
ECDSACrypto.cpp
+8
-13
SGXWalletServer.cpp
SGXWalletServer.cpp
+9
-10
SGXWalletServer.hpp
SGXWalletServer.hpp
+1
-1
start.sh
docker/start.sh
+19
-19
sgxwallet_common.h
sgxwallet_common.h
+1
-4
testw.cpp
testw.cpp
+22
-131
No files found.
BLSPrivateKeyShareSGX.cpp
View file @
c81d1128
...
...
@@ -80,10 +80,8 @@ BLSPrivateKeyShareSGX::BLSPrivateKeyShareSGX(
requiredSigners
=
_requiredSigners
;
totalSigners
=
_totalSigners
;
std
::
cerr
<<
"ENTER BLSPrivateKeyShareSGX CONSTRUCTOR"
<<
std
::
endl
;
if
(
requiredSigners
>
totalSigners
)
{
throw
std
::
invalid_argument
(
"requiredSigners > totalSigners"
);
}
...
...
DKGCrypto.cpp
View file @
c81d1128
...
...
@@ -36,7 +36,9 @@
#include "spdlog/spdlog.h"
#include "common.h"
vector
<
string
>
SplitString
(
const
char
*
koefs
,
const
char
symbol
)
{
#define DKG_MAX_SEALED_LEN 3100
vector
<
string
>
splitString
(
const
char
*
koefs
,
const
char
symbol
)
{
string
str
(
koefs
);
string
delim
;
delim
.
push_back
(
symbol
);
...
...
@@ -77,7 +79,7 @@ string gen_dkg_poly(int _t) {
vector
<
char
>
errMsg
(
1024
,
0
);
int
err_status
=
0
;
vector
<
uint8_t
>
encrypted_dkg_secret
(
DKG_MAX_SEALED
_LEN
,
0
);
vector
<
uint8_t
>
encrypted_dkg_secret
(
BUF
_LEN
,
0
);
uint32_t
enc_len
=
0
;
...
...
@@ -110,157 +112,139 @@ string gen_dkg_poly(int _t) {
vector
<
vector
<
string
>>
get_verif_vect
(
const
char
*
encryptedPolyHex
,
int
t
,
int
n
)
{
char
*
errMsg1
=
(
char
*
)
calloc
(
1024
,
1
);
//char errMsg1[BUF_LEN];
int
err_status
=
0
;
vector
<
char
>
errMsg1
(
BUF_LEN
,
0
);
int
errStatus
=
0
;
// cerr << "got encr poly " << encryptedPolyHex << endl;
spdlog
::
debug
(
"got encr poly size {}"
,
char_traits
<
char
>::
length
(
encryptedPolyHex
));
char
*
public_shares
=
(
char
*
)
calloc
(
10000
,
1
);
memset
(
public_shares
,
0
,
10000
);
// char public_shares[10000];
vector
<
char
>
pubShares
(
10000
,
0
);
uint64_t
enc
_l
en
=
0
;
uint64_t
enc
L
en
=
0
;
uint8_t
*
encr_dkg_poly
=
(
uint8_t
*
)
calloc
(
DKG_MAX_SEALED_LEN
*
2
,
1
);
memset
(
encr_dkg_poly
,
0
,
DKG_MAX_SEALED_LEN
*
2
);
//uint8_t encr_dkg_poly[DKG_MAX_SEALED_LEN];
vector
<
uint8_t
>
encrDKGPoly
(
2
*
BUF_LEN
,
0
);
if
(
!
hex2carray2
(
encryptedPolyHex
,
&
enc
_len
,
encr_dkg_poly
,
6100
))
{
if
(
!
hex2carray2
(
encryptedPolyHex
,
&
enc
Len
,
encrDKGPoly
.
data
()
,
6100
))
{
throw
RPCException
(
INVALID_HEX
,
"Invalid encryptedPolyHex"
);
}
//cerr << "hex_encr_poly is " << encryptedPolyHex << std::endl;
spdlog
::
debug
(
"hex_encr_poly length is {}"
,
strlen
(
encryptedPolyHex
));
spdlog
::
debug
(
"enc len {}"
,
enc
_l
en
);
spdlog
::
debug
(
"enc len {}"
,
enc
L
en
);
uint32_t
len
=
0
;
if
(
!
encryptKeys
)
status
=
get_public_shares
(
eid
,
&
err
_status
,
errMsg1
,
encr_dkg_poly
,
len
,
public_shares
,
t
,
n
);
status
=
get_public_shares
(
eid
,
&
err
Status
,
errMsg1
.
data
(),
encrDKGPoly
.
data
(),
len
,
pubShares
.
data
()
,
t
,
n
);
else
{
status
=
get_public_shares_aes
(
eid
,
&
err
_status
,
errMsg1
,
encr_dkg_poly
,
enc_len
,
public_shares
,
t
,
n
);
status
=
get_public_shares_aes
(
eid
,
&
err
Status
,
errMsg1
.
data
(),
encrDKGPoly
.
data
(),
encLen
,
pubShares
.
data
()
,
t
,
n
);
}
if
(
err
_s
tatus
!=
0
)
{
throw
RPCException
(
-
666
,
errMsg1
);
if
(
err
S
tatus
!=
0
)
{
throw
RPCException
(
-
666
,
errMsg1
.
data
()
);
}
spdlog
::
debug
(
"err msg is {}"
,
errMsg1
);
spdlog
::
debug
(
"err msg is {}"
,
errMsg1
.
data
()
);
spdlog
::
debug
(
"public_shares:"
);
spdlog
::
debug
(
"{}"
,
pub
lic_shares
);;
spdlog
::
debug
(
"get_public_shares status: {}"
,
err
_s
tatus
);
vector
<
string
>
G2_strings
=
SplitString
(
public_shares
,
','
);
vector
<
vector
<
string
>>
pub
_shares_v
ect
;
for
(
uint64_t
i
=
0
;
i
<
G2_s
trings
.
size
();
i
++
)
{
vector
<
string
>
koef_str
=
SplitString
(
G2_s
trings
.
at
(
i
).
c_str
(),
':'
);
pub
_shares_vect
.
push_back
(
koef_s
tr
);
spdlog
::
debug
(
"{}"
,
pub
Shares
.
data
()
);;
spdlog
::
debug
(
"get_public_shares status: {}"
,
err
S
tatus
);
vector
<
string
>
g2Strings
=
splitString
(
pubShares
.
data
()
,
','
);
vector
<
vector
<
string
>>
pub
SharesV
ect
;
for
(
uint64_t
i
=
0
;
i
<
g2S
trings
.
size
();
i
++
)
{
vector
<
string
>
coeffStr
=
splitString
(
g2S
trings
.
at
(
i
).
c_str
(),
':'
);
pub
SharesVect
.
push_back
(
coeffS
tr
);
}
free
(
errMsg1
);
free
(
public_shares
);
free
(
encr_dkg_poly
);
return
pub_shares_vect
;
return
pubSharesVect
;
}
string
get_secret_shares
(
const
string
&
polyName
,
const
char
*
encryptedPolyHex
,
const
vector
<
string
>
&
publicKeys
,
int
t
,
int
n
)
{
//char* errMsg1 = (char*) calloc(1024,1);
char
errMsg1
[
BUF_LEN
];
int
err_status
=
0
;
char
hexEncrKey
[
BUF_LEN
];
memset
(
hexEncrKey
,
0
,
BUF_LEN
);
uint64_t
enc_len
=
0
;
// uint8_t* encr_dkg_poly = (uint8_t*) calloc(DKG_MAX_SEALED_LEN, 1);
uint8_t
encr_dkg_poly
[
DKG_MAX_SEALED_LEN
];
memset
(
encr_dkg_poly
,
0
,
DKG_MAX_SEALED_LEN
);
if
(
!
hex2carray2
(
encryptedPolyHex
,
&
enc_len
,
encr_dkg_poly
,
6100
))
{
string
get_secret_shares
(
const
string
&
_polyName
,
const
char
*
_encryptedPolyHex
,
const
vector
<
string
>
&
_publicKeys
,
int
_t
,
int
_n
)
{
vector
<
char
>
errMsg1
(
BUF_LEN
,
0
);
vector
<
char
>
hexEncrKey
(
BUF_LEN
,
0
);
int
errStatus
=
0
;
uint64_t
encLen
=
0
;
vector
<
uint8_t
>
encrDKGPoly
(
BUF_LEN
,
0
);
if
(
!
hex2carray2
(
_encryptedPolyHex
,
&
encLen
,
encrDKGPoly
.
data
(),
6100
))
{
throw
RPCException
(
INVALID_HEX
,
"Invalid encryptedPolyHex"
);
}
std
::
cerr
<<
"enc_len is "
<<
enc_len
<<
std
::
endl
;
if
(
!
encryptKeys
)
status
=
set_encrypted_dkg_poly
(
eid
,
&
err
_status
,
errMsg1
,
encr_dkg_poly
);
status
=
set_encrypted_dkg_poly
(
eid
,
&
err
Status
,
errMsg1
.
data
(),
encrDKGPoly
.
data
()
);
else
status
=
set_encrypted_dkg_poly_aes
(
eid
,
&
err
_status
,
errMsg1
,
encr_dkg_poly
,
&
enc_l
en
);
status
=
set_encrypted_dkg_poly_aes
(
eid
,
&
err
Status
,
errMsg1
.
data
(),
encrDKGPoly
.
data
(),
&
encL
en
);
if
(
status
!=
SGX_SUCCESS
||
err
_s
tatus
!=
0
)
{
throw
RPCException
(
-
666
,
errMsg1
);
if
(
status
!=
SGX_SUCCESS
||
err
S
tatus
!=
0
)
{
throw
RPCException
(
-
666
,
errMsg1
.
data
()
);
}
string
result
;
//char *hexEncrKey = (char *) calloc(2 * BUF_LEN, 1);
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
uint8_t
encryptedSkey
[
BUF_LEN
];
memset
(
encryptedSkey
,
0
,
BUF_LEN
);
uint32_t
dec_len
;
char
cur_share
[
193
];
char
s_shareG2
[
320
];
string
pub_keyB
=
publicKeys
.
at
(
i
);
//publicKeys.substr(128*i, 128*i + 128);
// if (DEBUG_PRINT) {
// spdlog::info("pub_keyB is {}", pub_keyB);
// }
char
pubKeyB
[
129
];
strncpy
(
pubKeyB
,
pub_keyB
.
c_str
(),
128
);
pubKeyB
[
128
]
=
0
;
for
(
int
i
=
0
;
i
<
_n
;
i
++
)
{
vector
<
uint8_t
>
encryptedSkey
(
BUF_LEN
,
0
);
uint32_t
decLen
;
vector
<
char
>
currentShare
(
193
,
0
);
vector
<
char
>
sShareG2
(
320
,
0
);
string
pub_keyB
=
_publicKeys
.
at
(
i
);
vector
<
char
>
pubKeyB
(
129
,
0
);
strncpy
(
pubKeyB
.
data
(),
pub_keyB
.
c_str
(),
128
);
pubKeyB
.
at
(
128
)
=
0
;
spdlog
::
debug
(
"pubKeyB is {}"
,
pub_keyB
);
if
(
!
encryptKeys
)
get_encr_sshare
(
eid
,
&
err
_status
,
errMsg1
,
encryptedSkey
,
&
dec_l
en
,
cur
_share
,
s_shareG2
,
pubKeyB
,
t
,
n
,
i
+
1
);
get_encr_sshare
(
eid
,
&
err
Status
,
errMsg1
.
data
(),
encryptedSkey
.
data
(),
&
decL
en
,
cur
rentShare
.
data
(),
sShareG2
.
data
(),
pubKeyB
.
data
(),
_t
,
_
n
,
i
+
1
);
else
get_encr_sshare_aes
(
eid
,
&
err
_status
,
errMsg1
,
encryptedSkey
,
&
dec_l
en
,
cur
_share
,
s_shareG2
,
pubKeyB
,
t
,
n
,
i
+
1
);
if
(
err
_s
tatus
!=
0
)
{
throw
RPCException
(
-
666
,
errMsg1
);
get_encr_sshare_aes
(
eid
,
&
err
Status
,
errMsg1
.
data
(),
encryptedSkey
.
data
(),
&
decL
en
,
cur
rentShare
.
data
(),
sShareG2
.
data
(),
pubKeyB
.
data
(),
_t
,
_
n
,
i
+
1
);
if
(
err
S
tatus
!=
0
)
{
throw
RPCException
(
-
666
,
errMsg1
.
data
()
);
}
spdlog
::
debug
(
"cur_share is {}"
,
cur
_share
);
spdlog
::
debug
(
"cur_share is {}"
,
cur
rentShare
.
data
()
);
result
+=
string
(
currentShare
.
data
());
result
+=
cur_share
;
spdlog
::
debug
(
"dec len is {}"
,
decLen
);
carray2Hex
(
encryptedSkey
.
data
(),
decLen
,
hexEncrKey
.
data
());
string
dhKeyName
=
"DKG_DH_KEY_"
+
_polyName
+
"_"
+
to_string
(
i
)
+
":"
;
spdlog
::
debug
(
"dec len is {}"
,
dec_len
);
carray2Hex
(
encryptedSkey
,
dec_len
,
hexEncrKey
);
string
dhKeyName
=
"DKG_DH_KEY_"
+
polyName
+
"_"
+
to_string
(
i
)
+
":"
;
spdlog
::
debug
(
"hexEncr DH Key: { }"
,
hexEncrKey
.
data
());
SGXWalletServer
::
writeDataToDB
(
dhKeyName
,
hexEncrKey
.
data
());
spdlog
::
debug
(
"hexEncr DH Key: { }"
,
hexEncrKey
);
SGXWalletServer
::
writeDataToDB
(
dhKeyName
,
hexEncrKey
);
string
shareG2_name
=
"shareG2_"
+
polyName
+
"_"
+
to_string
(
i
)
+
":"
;
string
shareG2_name
=
"shareG2_"
+
_polyName
+
"_"
+
to_string
(
i
)
+
":"
;
spdlog
::
debug
(
"name to write to db is {}"
,
dhKeyName
);
spdlog
::
debug
(
"name to write to db is {}"
,
shareG2_name
);
spdlog
::
debug
(
"s_shareG2: {}"
,
s
_shareG2
);
spdlog
::
debug
(
"s_shareG2: {}"
,
s
ShareG2
.
data
()
);
SGXWalletServer
::
writeDataToDB
(
shareG2_name
,
s
_shareG2
);
SGXWalletServer
::
writeDataToDB
(
shareG2_name
,
s
ShareG2
.
data
()
);
spdlog
::
debug
(
"errMsg: {}"
,
errMsg1
);
spdlog
::
debug
(
"errMsg: {}"
,
errMsg1
.
data
()
);
}
//result += '\0';
//free(encr_dkg_poly);
// free(errMsg1);
//free(hexEncrKey);
return
result
;
}
bool
V
erifyShares
(
const
char
*
publicShares
,
const
char
*
encr_sshare
,
const
char
*
encryptedKeyHex
,
int
t
,
int
n
,
int
ind
)
{
v
erifyShares
(
const
char
*
publicShares
,
const
char
*
encr_sshare
,
const
char
*
encryptedKeyHex
,
int
t
,
int
n
,
int
ind
)
{
//char* errMsg1 = (char*) calloc(1024,1);
char
errMsg1
[
BUF_LEN
];
int
err_status
=
0
;
...
...
@@ -272,10 +256,7 @@ VerifyShares(const char *publicShares, const char *encr_sshare, const char *encr
throw
RPCException
(
INVALID_HEX
,
"Invalid encryptedPolyHex"
);
}
int
result
;
cerr
<<
"encryptedKeyHex "
<<
encryptedKeyHex
<<
endl
;
cerr
<<
"dec_key_len "
<<
dec_key_len
<<
endl
;
cerr
<<
"encr_sshare length is "
<<
strlen
(
encr_sshare
)
<<
endl
;
//cerr << "public shares " << publicShares << endl;
spdlog
::
debug
(
"publicShares length is {}"
,
char_traits
<
char
>::
length
(
publicShares
));
char
pshares
[
8193
];
...
...
@@ -319,31 +300,26 @@ bool CreateBLSShare(const string &blsKeyName, const char *s_shares, const char *
uint32_t
enc_bls_len
=
0
;
//cerr << "BEFORE create_bls_key IN ENCLAVE " << endl;
if
(
!
encryptKeys
)
create_bls_key
(
eid
,
&
err_status
,
errMsg1
,
s_shares
,
encr_key
,
dec_key_len
,
encr_bls_key
,
&
enc_bls_len
);
else
create_bls_key_aes
(
eid
,
&
err_status
,
errMsg1
,
s_shares
,
encr_key
,
dec_key_len
,
encr_bls_key
,
&
enc_bls_len
);
//cerr << "AFTER create_bls_key IN ENCLAVE er msg is " << errMsg1 << endl;
if
(
err_status
!=
0
)
{
//spdlog::info("ERROR IN ENCLAVE with status {}", err_status);
spdlog
::
error
(
errMsg1
);
spdlog
::
error
(
"status {}"
,
err_status
);
throw
RPCException
(
ERROR_IN_ENCLAVE
,
"Create BLS private key failed in enclave"
);
}
else
{
//char *hexBLSKey = (char *) calloc(2 * BUF_LEN, 1);
char
hexBLSKey
[
2
*
BUF_LEN
];
//cerr << "BEFORE carray2Hex" << endl;
//cerr << "enc_bls_len " << enc_bls_len << endl;
carray2Hex
(
encr_bls_key
,
enc_bls_len
,
hexBLSKey
);
// cerr << "BEFORE WRITE BLS KEY TO DB" << endl;
SGXWalletServer
::
writeDataToDB
(
blsKeyName
,
hexBLSKey
);
spdlog
::
debug
(
"hexBLSKey length is {}"
,
char_traits
<
char
>::
length
(
hexBLSKey
));
spdlog
::
debug
(
"bls key {}"
,
blsKeyName
,
" is "
,
hexBLSKey
);
SGXWalletServer
::
writeDataToDB
(
blsKeyName
,
hexBLSKey
);
//free(hexBLSKey);
return
true
;
}
...
...
@@ -369,10 +345,10 @@ vector<string> GetBLSPubKey(const char *encryptedKeyHex) {
else
get_bls_pub_key_aes
(
eid
,
&
err_status
,
errMsg1
,
encr_key
,
dec_key_len
,
pub_key
);
if
(
err_status
!=
0
)
{
s
td
::
cerr
<<
errMsg1
<<
" status is "
<<
err_status
<<
std
::
endl
;
s
pdlog
::
error
(
string
(
errMsg1
)
+
" . Status is {}"
,
err_status
)
;
throw
RPCException
(
ERROR_IN_ENCLAVE
,
"Failed to get BLS public key in enclave"
);
}
vector
<
string
>
pub_key_vect
=
S
plitString
(
pub_key
,
':'
);
vector
<
string
>
pub_key_vect
=
s
plitString
(
pub_key
,
':'
);
spdlog
::
debug
(
"errMsg1 is {}"
,
errMsg1
);
spdlog
::
debug
(
"pub key is "
);
...
...
DKGCrypto.h
View file @
c81d1128
...
...
@@ -31,11 +31,11 @@ std::string gen_dkg_poly( int _t);
std
::
vector
<
std
::
vector
<
std
::
string
>>
get_verif_vect
(
const
char
*
encryptedPolyHex
,
int
t
,
int
n
);
std
::
vector
<
std
::
string
>
S
plitString
(
const
char
*
koefs
,
const
char
symbol
);
std
::
vector
<
std
::
string
>
s
plitString
(
const
char
*
koefs
,
const
char
symbol
);
std
::
string
get_secret_shares
(
const
std
::
string
&
polyName
,
const
char
*
encryptedPolyHex
,
const
std
::
vector
<
std
::
string
>&
publicKeys
,
int
t
,
int
n
);
std
::
string
get_secret_shares
(
const
std
::
string
&
_polyName
,
const
char
*
_encryptedPolyHex
,
const
std
::
vector
<
std
::
string
>&
_publicKeys
,
int
_t
,
int
_
n
);
bool
VerifyShares
(
const
char
*
publicShares
,
const
char
*
encr_sshare
,
const
char
*
encryptedKeyHex
,
int
t
,
int
n
,
int
ind
);
bool
verifyShares
(
const
char
*
publicShares
,
const
char
*
encr_sshare
,
const
char
*
encryptedKeyHex
,
int
t
,
int
n
,
int
ind
);
std
::
string
decrypt_DHKey
(
const
std
::
string
&
polyName
,
int
ind
);
...
...
ECDSACrypto.cpp
View file @
c81d1128
...
...
@@ -34,12 +34,12 @@
#include "spdlog/spdlog.h"
static
std
::
default_random_engine
randGen
((
unsigned
int
)
time
(
0
));
static
default_random_engine
randGen
((
unsigned
int
)
time
(
0
));
st
d
::
st
ring
concatPubKeyWith0x
(
char
*
pub_key_x
,
char
*
pub_key_y
)
{
st
d
::
st
ring
px
=
pub_key_x
;
st
d
::
st
ring
py
=
pub_key_y
;
st
d
::
string
result
=
"0x"
+
px
+
py
;
// + std::to_string(pub_key_x) + std::to_string(pub_key_y)
;
string
concatPubKeyWith0x
(
char
*
pub_key_x
,
char
*
pub_key_y
)
{
string
px
=
pub_key_x
;
string
py
=
pub_key_y
;
st
ring
result
=
"0x"
+
px
+
py
;
return
result
;
}
...
...
@@ -57,25 +57,21 @@ std::vector<std::string> genECDSAKey() {
status
=
generate_ecdsa_key_aes
(
eid
,
&
err_status
,
errMsg
,
encr_pr_key
,
&
enc_len
,
pub_key_x
,
pub_key_y
);
if
(
status
!=
SGX_SUCCESS
||
err_status
!=
0
)
{
s
td
::
cerr
<<
"RPCException thrown with status"
<<
status
<<
std
::
endl
;
s
pdlog
::
error
(
"RPCException thrown with status {}"
,
status
)
;
throw
RPCException
(
status
,
errMsg
);
}
std
::
vector
<
std
::
string
>
keys
(
3
);
std
::
cerr
<<
"account key is "
<<
errMsg
<<
std
::
endl
;
std
::
cerr
<<
"enc_len is "
<<
enc_len
<<
std
::
endl
;
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);//
//std::cerr << "in ECDSACrypto encr key x " << keys.at(0) << std::endl;
//std::cerr << "in ECDSACrypto encr_len %d " << enc_len << std::endl;
unsigned
long
seed
=
randGen
();
spdlog
::
debug
(
"seed is {}"
,
seed
);
std
::
cerr
<<
"strlen is "
<<
strlen
(
hexEncrKey
)
<<
std
::
endl
;
spdlog
::
debug
(
"seed is {}"
,
seed
);
gmp_randstate_t
state
;
gmp_randinit_default
(
state
);
...
...
@@ -90,7 +86,6 @@ std::vector<std::string> genECDSAKey() {
keys
.
at
(
2
)
=
rand_str
;
//std::cerr << "rand_str length is " << strlen(rand_str) << std::endl;
gmp_randclear
(
state
);
mpz_clear
(
rand32
);
...
...
SGXWalletServer.cpp
View file @
c81d1128
...
...
@@ -47,9 +47,9 @@
void
setFullOptions
(
int
_printDebugInfo
,
int
_useHTTPS
,
int
_autoconfirm
,
int
_encryptKeys
)
{
if
(
_printDebugInfo
)
spdlog
::
set_level
(
spdlog
::
level
::
info
);
else
{
spdlog
::
set_level
(
spdlog
::
level
::
debug
);
else
{
spdlog
::
set_level
(
spdlog
::
level
::
info
);
}
printDebugInfo
=
_printDebugInfo
;
useHTTPS
=
_useHTTPS
;
...
...
@@ -481,13 +481,13 @@ Json::Value SGXWalletServer::getVerificationVectorImpl(const string &_polyName,
return
result
;
}
Json
::
Value
SGXWalletServer
::
getSecretShareImpl
(
const
string
&
_polyName
,
const
Json
::
Value
&
_pub
lic
Keys
,
int
_t
,
int
_n
)
{
Json
::
Value
SGXWalletServer
::
getSecretShareImpl
(
const
string
&
_polyName
,
const
Json
::
Value
&
_pubKeys
,
int
_t
,
int
_n
)
{
Json
::
Value
result
;
result
[
"status"
]
=
0
;
result
[
"errorMessage"
]
=
""
;
try
{
if
(
_pub
lic
Keys
.
size
()
!=
(
uint64_t
)
_n
)
{
if
(
_pubKeys
.
size
()
!=
(
uint64_t
)
_n
)
{
throw
RPCException
(
INVALID_DKG_PARAMS
,
"invalid number of public keys"
);
}
if
(
!
checkName
(
_polyName
,
"POLY"
))
{
...
...
@@ -499,16 +499,15 @@ Json::Value SGXWalletServer::getSecretShareImpl(const string &_polyName, const J
shared_ptr
<
string
>
encr_poly_ptr
=
readFromDb
(
_polyName
);
vector
<
string
>
pubKeys
_vect
;
vector
<
string
>
pubKeys
Strs
;
for
(
int
i
=
0
;
i
<
_n
;
i
++
)
{
std
::
cerr
<<
"publicKeys "
<<
i
<<
" is "
<<
_publicKeys
[
i
].
asString
()
<<
std
::
endl
;
if
(
!
checkHex
(
_publicKeys
[
i
].
asString
(),
64
))
{
if
(
!
checkHex
(
_pubKeys
[
i
].
asString
(),
64
))
{
throw
RPCException
(
INVALID_HEX
,
"Invalid public key"
);
}
pubKeys
_vect
.
push_back
(
_public
Keys
[
i
].
asString
());
pubKeys
Strs
.
push_back
(
_pub
Keys
[
i
].
asString
());
}
string
s
=
get_secret_shares
(
_polyName
,
encr_poly_ptr
->
c_str
(),
pubKeys
_vect
,
_t
,
_n
);
string
s
=
get_secret_shares
(
_polyName
,
encr_poly_ptr
->
c_str
(),
pubKeys
Strs
,
_t
,
_n
);
//cerr << "result is " << s << endl;
result
[
"secretShare"
]
=
s
;
...
...
@@ -547,7 +546,7 @@ Json::Value SGXWalletServer::dkgVerificationImpl(const string &_publicShares, co
shared_ptr
<
string
>
encryptedKeyHex_ptr
=
readFromDb
(
_ethKeyName
);
if
(
!
V
erifyShares
(
_publicShares
.
c_str
(),
_secretShare
.
c_str
(),
encryptedKeyHex_ptr
->
c_str
(),
_t
,
_n
,
_index
))
{
if
(
!
v
erifyShares
(
_publicShares
.
c_str
(),
_secretShare
.
c_str
(),
encryptedKeyHex_ptr
->
c_str
(),
_t
,
_n
,
_index
))
{
result
[
"result"
]
=
false
;
}
...
...
SGXWalletServer.hpp
View file @
c81d1128
...
...
@@ -112,7 +112,7 @@ public:
static
Json
::
Value
getVerificationVectorImpl
(
const
string
&
_polyName
,
int
_t
,
int
_n
);
static
Json
::
Value
getSecretShareImpl
(
const
string
&
_polyName
,
const
Json
::
Value
&
_pub
lic
Keys
,
int
_t
,
int
_n
);
static
Json
::
Value
getSecretShareImpl
(
const
string
&
_polyName
,
const
Json
::
Value
&
_pubKeys
,
int
_t
,
int
_n
);
static
Json
::
Value
dkgVerificationImpl
(
const
string
&
_publicShares
,
const
string
&
_ethKeyName
,
const
string
&
_secretShare
,
...
...
docker/start.sh
View file @
c81d1128
...
...
@@ -5,25 +5,25 @@ cd /usr/src/sdk;
echo
$1
if
[
"
$1
"
=
-t
]
;
then
set
-e
#
./testw [bls-key-encrypt]
#
./testw [bls-key-encrypt-decrypt]
#
./testw [dkg-gen]
#
./testw [dkg-pub_shares]
#
./testw [dkg-verify]
#
./testw [ecdsa_test]
#
./testw [test_test]
#
./testw [get_pub_ecdsa_key_test]
#
./testw [bls_dkg]
#
./testw [api_test]
#
./testw [getServerStatus_test]
#
./testw [dkg_api_test]
#
./testw [is_poly_test]
#
./testw [AES-encrypt-decrypt]
#
./testw [ecdsa_api_test]
#
./testw [dkg-encr_sshares]
#./testw [bls_sign]
#.
/testw [many_threads_test]
#
./testw [aes_dkg]
./testw
[
bls-key-encrypt]
./testw
[
bls-key-encrypt-decrypt]
./testw
[
dkg-gen]
./testw
[
dkg-pub_shares]
./testw
[
dkg-verify]
./testw
[
ecdsa_test]
./testw
[
test_test]
./testw
[
get_pub_ecdsa_key_test]
./testw
[
bls_dkg]
./testw
[
api_test]
./testw
[
getServerStatus_test]
./testw
[
dkg_api_test]
./testw
[
is_poly_test]
./testw
[
AES-encrypt-decrypt]
./testw
[
ecdsa_api_test]
./testw
[
dkg-encr_sshares]
#./testw [bls_sign]
/testw
[
many_threads_test]
./testw
[
aes_dkg]
else
./sgxwallet
$1
$2
$3
$4
fi
...
...
sgxwallet_common.h
View file @
c81d1128
...
...
@@ -46,7 +46,7 @@ extern int autoconfirm;
#define BUF_LEN
1024
#define BUF_LEN
4096
#define MAX_KEY_LENGTH 128
#define MAX_COMPONENT_LENGTH 80
...
...
@@ -58,9 +58,6 @@ extern int autoconfirm;
#define ADD_ENTROPY_SIZE 32
#define DKG_BUFER_LENGTH 2490//3060
#define DKG_MAX_SEALED_LEN 3050
#define SECRET_SHARE_NUM_BYTES 96
#define ECDSA_SKEY_LEN 65
...
...
testw.cpp
View file @
c81d1128
...
...
@@ -179,23 +179,22 @@ TEST_CASE("DKG gen test", "[dkg-gen]") {
initAll
(
false
,
true
);
vector
<
uint8_t
>
encrypted
_dkg_secret
(
DKG_MAX_SEALED
_LEN
,
0
);
vector
<
uint8_t
>
encrypted
DKGSecret
(
BUF
_LEN
,
0
);
vector
<
char
>
errMsg
(
BUF_LEN
,
0
);
int
err_status
=
0
;
uint32_t
enc_len
=
0
;
status
=
gen_dkg_secret
(
eid
,
&
err_status
,
errMsg
.
data
(),
encrypted
_dkg_s
ecret
.
data
(),
&
enc_len
,
32
);
status
=
gen_dkg_secret
(
eid
,
&
err_status
,
errMsg
.
data
(),
encrypted
DKGS
ecret
.
data
(),
&
enc_len
,
32
);
REQUIRE
(
status
==
SGX_SUCCESS
);
// printf("gen_dkg_secret completed with status: %d %s \n", err_status, errMsg.data());
// printf("\n Length: %d \n", enc_len);
vector
<
char
>
secret
(
DKG_BUFER_LENGTH
,
0
);
vector
<
char
>
secret
(
BUF_LEN
,
0
);
vector
<
char
>
errMsg1
(
BUF_LEN
,
0
);
uint32_t
dec_len
;
status
=
decrypt_dkg_secret
(
eid
,
&
err_status
,
errMsg1
.
data
(),
encrypted
_dkg_s
ecret
.
data
(),
status
=
decrypt_dkg_secret
(
eid
,
&
err_status
,
errMsg1
.
data
(),
encrypted
DKGS
ecret
.
data
(),
(
uint8_t
*
)
secret
.
data
(),
&
dec_len
);
REQUIRE
(
status
==
SGX_SUCCESS
);
...
...
@@ -270,7 +269,7 @@ TEST_CASE("DKG public shares test", "[dkg-pub_shares]") {
libff
::
init_alt_bn128_params
();
vector
<
uint8_t
>
encrypted_dkg_secret
(
DKG_MAX_SEALED
_LEN
,
0
);
vector
<
uint8_t
>
encrypted_dkg_secret
(
BUF
_LEN
,
0
);
vector
<
char
>
errMsg
(
BUF_LEN
,
0
);
int
err_status
=
0
;
...
...
@@ -295,17 +294,17 @@ TEST_CASE("DKG public shares test", "[dkg-pub_shares]") {
// printf(" LEN: %d \n", (int) strlen(public_shares.data()));
// printf(" result: %s \n", public_shares.data());
vector
<
string
>
G2_strings
=
S
plitString
(
public_shares
.
data
(),
','
);
vector
<
string
>
G2_strings
=
s
plitString
(
public_shares
.
data
(),
','
);
vector
<
libff
::
alt_bn128_G2
>
pub_shares_G2
;
for
(
u_int64_t
i
=
0
;
i
<
G2_strings
.
size
();
i
++
)
{
vector
<
string
>
koef_str
=
S
plitString
(
G2_strings
.
at
(
i
).
c_str
(),
':'
);
vector
<
string
>
koef_str
=
s
plitString
(
G2_strings
.
at
(
i
).
c_str
(),
':'
);
//libff::alt_bn128_G2 el = VectStringToG2(koef_str);
//cerr << "pub_share G2 " << i+1 << " : " << endl;
//el.print_coordinates();
pub_shares_G2
.
push_back
(
VectStringToG2
(
koef_str
));
}
vector
<
char
>
secret
(
DKG_MAX_SEALED
_LEN
,
0
);
vector
<
char
>
secret
(
BUF
_LEN
,
0
);
status
=
decrypt_dkg_secret
(
eid
,
&
err_status
,
errMsg1
.
data
(),
encrypted_dkg_secret
.
data
(),
(
uint8_t
*
)
secret
.
data
(),
&
enc_len
);
...
...
@@ -348,7 +347,7 @@ TEST_CASE("DKG encrypted secret shares test", "[dkg-encr_sshares]") {
int
err_status
=
0
;
uint32_t
enc_len
=
0
;
vector
<
uint8_t
>
encrypted_dkg_secret
(
DKG_MAX_SEALED
_LEN
,
0
);
vector
<
uint8_t
>
encrypted_dkg_secret
(
BUF
_LEN
,
0
);
status
=
gen_dkg_secret
(
eid
,
&
err_status
,
errMsg
.
data
(),
encrypted_dkg_secret
.
data
(),
&
enc_len
,
2
);
REQUIRE
(
status
==
SGX_SUCCESS
);
// cerr << " poly generated" << endl;
...
...
@@ -385,7 +384,7 @@ TEST_CASE("DKG verification test", "[dkg-verify]") {
int
err_status
=
0
;
uint32_t
enc_len
=
0
;
vector
<
uint8_t
>
encrypted_dkg_secret
(
DKG_MAX_SEALED_LEN
,
1
);
vector
<
uint8_t
>
encrypted_dkg_secret
(
BUF_LEN
,
0
);
status
=
gen_dkg_secret
(
eid
,
&
err_status
,
errMsg
.
data
(),
encrypted_dkg_secret
.
data
(),
&
enc_len
,
2
);
REQUIRE
(
status
==
SGX_SUCCESS
);
...
...
@@ -485,31 +484,24 @@ TEST_CASE("get public ECDSA key", "[get_pub_ecdsa_key_test]") {
setOptions
(
false
,
false
,
true
);
initAll
(
false
,
true
);
int
err
_s
tatus
=
0
;
int
err
S
tatus
=
0
;
vector
<
char
>
errMsg
(
BUF_LEN
,
0
);
vector
<
uint8_t
>
enc
r_pr_k
ey
(
BUF_LEN
,
0
);
vector
<
char
>
pub
_key_x
(
BUF_LEN
,
0
);
vector
<
char
>
pub
_key_y
(
BUF_LEN
,
0
);
uint32_t
enc
_l
en
=
0
;
vector
<
uint8_t
>
enc
PrivK
ey
(
BUF_LEN
,
0
);
vector
<
char
>
pub
KeyX
(
BUF_LEN
,
0
);
vector
<
char
>
pub
KeyY
(
BUF_LEN
,
0
);
uint32_t
enc
L
en
=
0
;
status
=
generate_ecdsa_key
(
eid
,
&
err_status
,
errMsg
.
data
(),
encr_pr_key
.
data
(),
&
enc_len
,
pub_key_x
.
data
(),
pub_key_y
.
data
());
// printf("\nerrMsg %s\n", errMsg.data());
REQUIRE
(
status
==
SGX_SUCCESS
);
status
=
generate_ecdsa_key
(
eid
,
&
errStatus
,
errMsg
.
data
(),
encPrivKey
.
data
(),
&
encLen
,
pubKeyX
.
data
(),
pubKeyY
.
data
());
//printf("\nwas pub_key_x %s length %d: \n", pub_key_x.data(), (int) strlen(pub_key_x.data()));
//printf("\nwas pub_key_y %s length %d: \n", pub_key_y.data(), (int) strlen(pub_key_y.data()));
/*printf("\nencr priv_key %s: \n");
for ( int i = 0; i < BUF_LEN ; i++)
printf("%u ", encr_pr_key[i]);*/
REQUIRE
(
status
==
SGX_SUCCESS
);
vector
<
char
>
got_pub_key_x
(
BUF_LEN
,
0
);
vector
<
char
>
got_pub_key_y
(
BUF_LEN
,
0
);
vector
<
char
>
receivedPubKeyX
(
BUF_LEN
,
0
);
vector
<
char
>
receivedPubKeyY
(
BUF_LEN
,
0
);
status
=
get_public_ecdsa_key
(
eid
,
&
err
_status
,
errMsg
.
data
(),
encr_pr_key
.
data
(),
enc_len
,
got_pub_key_x
.
data
(),
got_pub_key_y
.
data
());
status
=
get_public_ecdsa_key
(
eid
,
&
err
Status
,
errMsg
.
data
(),
encPrivKey
.
data
(),
encLen
,
receivedPubKeyX
.
data
(),
receivedPubKeyY
.
data
());
REQUIRE
(
status
==
SGX_SUCCESS
);
//printf("\nnow pub_key_x %s: \n", got_pub_key_x.data());
//printf("\nnow pub_key_y %s: \n", got_pub_key_y.data());
...
...
@@ -825,20 +817,10 @@ void SendRPCRequest() {
BLSSigShare
sig
(
sig_share_ptr
,
i
+
1
,
t
,
n
);
sigShareSet
.
addSigShare
(
make_shared
<
BLSSigShare
>
(
sig
));
// vector<string> pubKey_vect;
// for ( uint8_t j = 0; j < 4; j++){
// pubKey_vect.push_back(pubBLSKeys[i]["blsPublicKeyShare"][j].asString());
// }
// BLSPublicKeyShare pubKey(make_shared<vector<string>>(pubKey_vect), t, n);
// REQUIRE( pubKey.VerifySigWithHelper(hash_arr, make_shared<BLSSigShare>(sig) , t, n));
//koefs_pkeys_map[i+1] = make_shared<BLSPublicKeyShare>(pubKey);
}
shared_ptr
<
BLSSignature
>
commonSig
=
sigShareSet
.
merge
();
// BLSPublicKey common_public(make_shared<map<size_t, shared_ptr<BLSPublicKeyShare>>>(koefs_pkeys_map), t, n);
// REQUIRE( common_public.VerifySigWithHelper(hash_arr, commonSig, t, n) );
}
...
...
@@ -1185,95 +1167,4 @@ TEST_CASE("AES encrypt/decrypt", "[AES-encrypt-decrypt]") {
}
//TEST_CASE("BLS key import", "[bls-key-import]") {
// reset_db();
// init_all(false, true);
//
//
//
// auto result = importBLSKeyShareImpl(TEST_BLS_KEY_SHARE, TEST_BLS_KEY_NAME, 2, 2, 1);
//
// REQUIRE(result["status"] == 0);
//
// REQUIRE(result["encryptedKeyShare"] != "");
//
//
//TEST_CASE("BLS sign test", "[bls-sign]") {
//
// //init_all();
// init_enclave();
//
// char* encryptedKeyHex ="04000200000000000406ffffff02000000000000000000000b000000000000ff0000000000000000813f8390f6228a568e181a4dadb6508e3e66f5247175d65dbd0d8c7fbfa4df45000000f000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000008000000000000000000000000000000000dc044ae0cd79faaf41e8a7abb412790476738a98b5b6ce95fa1a32db5551b0a0d867305f4de558c64fee730a1f62394633c7d4ca65e3a40b7883e89c2801c61918b01c5de8624a52963df6f4de8581bcbdd2f9b69720d4cc764e03a04c7a99314bfdb5d2d55deda2ca40cd691f093fb2ecbae24cdacdd4d5de93189c6dfd6792d7b95bd5e330aec3538e7a85d15793"; //encryptTestKey();
//
// REQUIRE(encryptedKeyHex != nullptr);
//
//
// // const char *hexHash = "001122334455667788" "001122334455667788" "001122334455667788" "001122334455667788";
// const char *hexHash = "3F891FDA3704F0368DAB65FA81EBE616F4AA2A0854995DA4DC0B59D2CADBD64F";
//
// char* hexHashBuf = (char*) calloc(BUF_LEN, 1);
//
// strncpy(hexHashBuf, hexHash, BUF_LEN);
//
// char sig[BUF_LEN];
// auto result = sign(encryptedKeyHex, hexHashBuf, 2, 2, 1, sig);
//
// REQUIRE(result == true);
// printf("Signature is: %s \n", sig );
//
//}
//
//TEST_CASE("Server BLS sign test", "[bls-server-sign]") {
//
// reset_db();
//
// init_all(false, true);
//
//
// auto result = importBLSKeyShareImpl( TEST_BLS_KEY_SHARE, TEST_BLS_KEY_NAME, 2, 2, 1);
//
// REQUIRE(result["status"] == 0);
//
// REQUIRE(result["encryptedKeyShare"] != "");
//
// const char *hexHash = "001122334455667788" "001122334455667788" "001122334455667788" "001122334455667788";
//
// REQUIRE_NOTHROW(result = blsSignMessageHashImpl(TEST_BLS_KEY_NAME, hexHash,2,2,1));
//
// if (result["status"] != 0) {
// printf("Error message: %s", result["errorMessage"].asString().c_str());
// }
//
//
// REQUIRE(result["status"] == 0);
// REQUIRE(result["signatureShare"] != "");
//
// printf("Signature is: %s \n", result["signatureShare"].asString().c_str());
//
//}
//TEST_CASE("KeysDB test", "[keys-db]") {
//
//
//
// reset_db();
// init_all();
//
//
// string key = TEST_BLS_KEY_SHARE;
// string value = TEST_BLS_KEY_SHARE;
//
//
//
// REQUIRE_THROWS(readKeyShare(key));
//
//
// writeKeyShare(key, value, 1, 2, 1);
//
// REQUIRE(readKeyShare(key) != nullptr);
//
//
//// put your test here
//}
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