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
2f267c40
Unverified
Commit
2f267c40
authored
Apr 17, 2020
by
kladko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SKALE-2454-add-logs-to-enclave
parent
d79cbb71
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
168 additions
and
168 deletions
+168
-168
DKGCrypto.cpp
DKGCrypto.cpp
+36
-36
DKGCrypto.h
DKGCrypto.h
+2
-2
SGXWalletServer.cpp
SGXWalletServer.cpp
+1
-1
DKGUtils.cpp
secure_enclave/DKGUtils.cpp
+14
-14
DKGUtils.h
secure_enclave/DKGUtils.h
+3
-3
secure_enclave.c
secure_enclave/secure_enclave.c
+4
-4
secure_enclave.edl
secure_enclave/secure_enclave.edl
+84
-84
testw.cpp
testw.cpp
+24
-24
No files found.
DKGCrypto.cpp
View file @
2f267c40
...
...
@@ -38,8 +38,8 @@
#define DKG_MAX_SEALED_LEN 3100
vector
<
string
>
splitString
(
const
char
*
koe
fs
,
const
char
symbol
)
{
string
str
(
koe
fs
);
vector
<
string
>
splitString
(
const
char
*
coef
fs
,
const
char
symbol
)
{
string
str
(
coef
fs
);
string
delim
;
delim
.
push_back
(
symbol
);
vector
<
string
>
G2_strings
;
...
...
@@ -49,8 +49,8 @@ vector<string> splitString(const char *koefs, const char symbol) {
if
(
pos
==
string
::
npos
)
pos
=
str
.
length
();
string
token
=
str
.
substr
(
prev
,
pos
-
prev
);
if
(
!
token
.
empty
())
{
string
koe
f
(
token
.
c_str
());
G2_strings
.
push_back
(
koe
f
);
string
coef
f
(
token
.
c_str
());
G2_strings
.
push_back
(
coef
f
);
}
prev
=
pos
+
delim
.
length
();
}
while
(
pos
<
str
.
length
()
&&
prev
<
str
.
length
());
...
...
@@ -249,10 +249,10 @@ verifyShares(const char *publicShares, const char *encr_sshare, const char *encr
char
errMsg1
[
BUF_LEN
];
int
err_status
=
0
;
uint64_t
dec
_key_l
en
;
uint64_t
dec
KeyL
en
;
uint8_t
encr_key
[
BUF_LEN
];
memset
(
encr_key
,
0
,
BUF_LEN
);
if
(
!
hex2carray
(
encryptedKeyHex
,
&
dec
_key_l
en
,
encr_key
))
{
if
(
!
hex2carray
(
encryptedKeyHex
,
&
dec
KeyL
en
,
encr_key
))
{
throw
SGXException
(
INVALID_HEX
,
"Invalid encryptedPolyHex"
);
}
int
result
;
...
...
@@ -265,9 +265,9 @@ verifyShares(const char *publicShares, const char *encr_sshare, const char *encr
if
(
!
encryptKeys
)
trustedDkgVerify
(
eid
,
&
err_status
,
errMsg1
,
pshares
,
encr_sshare
,
encr_key
,
dec
_key_l
en
,
t
,
ind
,
&
result
);
trustedDkgVerify
(
eid
,
&
err_status
,
errMsg1
,
pshares
,
encr_sshare
,
encr_key
,
dec
KeyL
en
,
t
,
ind
,
&
result
);
else
trustedDkgVerify_aes
(
eid
,
&
err_status
,
errMsg1
,
pshares
,
encr_sshare
,
encr_key
,
dec
_key_l
en
,
t
,
ind
,
&
result
);
trustedDkgVerify_aes
(
eid
,
&
err_status
,
errMsg1
,
pshares
,
encr_sshare
,
encr_key
,
dec
KeyL
en
,
t
,
ind
,
&
result
);
if
(
result
==
2
)
{
throw
SGXException
(
INVALID_HEX
,
"Invalid public shares"
);
...
...
@@ -289,12 +289,12 @@ bool CreateBLSShare(const string &blsKeyName, const char *s_shares, const char *
char
errMsg1
[
BUF_LEN
];
int
err_status
=
0
;
uint64_t
dec
_key_l
en
;
uint64_t
dec
KeyL
en
;
uint8_t
encr_bls_key
[
BUF_LEN
];
memset
(
encr_bls_key
,
0
,
BUF_LEN
);
uint8_t
encr_key
[
BUF_LEN
];
memset
(
encr_key
,
0
,
BUF_LEN
);
if
(
!
hex2carray
(
encryptedKeyHex
,
&
dec
_key_l
en
,
encr_key
))
{
if
(
!
hex2carray
(
encryptedKeyHex
,
&
dec
KeyL
en
,
encr_key
))
{
throw
SGXException
(
INVALID_HEX
,
"Invalid encryptedKeyHex"
);
}
...
...
@@ -302,9 +302,9 @@ bool CreateBLSShare(const string &blsKeyName, const char *s_shares, const char *
if
(
!
encryptKeys
)
trustedCreateBlsKey
(
eid
,
&
err_status
,
errMsg1
,
s_shares
,
encr_key
,
dec
_key_l
en
,
encr_bls_key
,
&
enc_bls_len
);
trustedCreateBlsKey
(
eid
,
&
err_status
,
errMsg1
,
s_shares
,
encr_key
,
dec
KeyL
en
,
encr_bls_key
,
&
enc_bls_len
);
else
trustedCreateBlsKey_aes
(
eid
,
&
err_status
,
errMsg1
,
s_shares
,
encr_key
,
dec
_key_l
en
,
encr_bls_key
,
&
enc_bls_len
);
trustedCreateBlsKey_aes
(
eid
,
&
err_status
,
errMsg1
,
s_shares
,
encr_key
,
dec
KeyL
en
,
encr_bls_key
,
&
enc_bls_len
);
if
(
err_status
!=
0
)
{
...
...
@@ -326,65 +326,65 @@ bool CreateBLSShare(const string &blsKeyName, const char *s_shares, const char *
}
vector
<
string
>
GetBLSPubKey
(
const
char
*
encryptedKeyHex
)
{
//char* errMsg1 = (char*) calloc(1024,1);
char
errMsg1
[
BUF_LEN
];
int
err
_s
tatus
=
0
;
int
err
S
tatus
=
0
;
uint64_t
dec
_key_l
en
;
uint8_t
encr
_k
ey
[
BUF_LEN
];
if
(
!
hex2carray
(
encryptedKeyHex
,
&
dec
_key_len
,
encr_k
ey
))
{
uint64_t
dec
KeyL
en
;
uint8_t
encr
K
ey
[
BUF_LEN
];
if
(
!
hex2carray
(
encryptedKeyHex
,
&
dec
KeyLen
,
encrK
ey
))
{
throw
SGXException
(
INVALID_HEX
,
"Invalid encryptedKeyHex"
);
}
char
pub
_k
ey
[
320
];
spdlog
::
debug
(
"dec
_key_len is {}"
,
dec_key_l
en
);
char
pub
K
ey
[
320
];
spdlog
::
debug
(
"dec
KeyLen is {}"
,
decKeyL
en
);
if
(
!
encryptKeys
)
trustedGetBlsPubKey
(
eid
,
&
err
_status
,
errMsg1
,
encr_key
,
dec_key_len
,
pub_k
ey
);
trustedGetBlsPubKey
(
eid
,
&
err
Status
,
errMsg1
,
encrKey
,
decKeyLen
,
pubK
ey
);
else
trustedGetBlsPubKey
_aes
(
eid
,
&
err_status
,
errMsg1
,
encr_key
,
dec_key_len
,
pub_k
ey
);
if
(
err
_s
tatus
!=
0
)
{
spdlog
::
error
(
string
(
errMsg1
)
+
" . Status is {}"
,
err
_s
tatus
);
trustedGetBlsPubKey
AES
(
eid
,
&
errStatus
,
errMsg1
,
encrKey
,
decKeyLen
,
pubK
ey
);
if
(
err
S
tatus
!=
0
)
{
spdlog
::
error
(
string
(
errMsg1
)
+
" . Status is {}"
,
err
S
tatus
);
throw
SGXException
(
ERROR_IN_ENCLAVE
,
"Failed to get BLS public key in enclave"
);
}
vector
<
string
>
pub
_key_vect
=
splitString
(
pub_k
ey
,
':'
);
vector
<
string
>
pub
KeyVect
=
splitString
(
pubK
ey
,
':'
);
spdlog
::
debug
(
"errMsg1 is {}"
,
errMsg1
);
spdlog
::
debug
(
"pub key is "
);
for
(
int
i
=
0
;
i
<
4
;
i
++
)
spdlog
::
debug
(
"{}"
,
pub
_key_v
ect
.
at
(
i
));
spdlog
::
debug
(
"{}"
,
pub
KeyV
ect
.
at
(
i
));
return
pub
_key_v
ect
;
return
pub
KeyV
ect
;
}
string
decrypt
_
DHKey
(
const
string
&
polyName
,
int
ind
)
{
string
decryptDHKey
(
const
string
&
polyName
,
int
ind
)
{
vector
<
char
>
errMsg1
(
1024
,
0
);
int
err_status
=
0
;
string
DH_key_name
=
polyName
+
"_"
+
to_string
(
ind
)
+
":"
;
shared_ptr
<
string
>
hexEncrKey
_p
tr
=
SGXWalletServer
::
readFromDb
(
DH_key_name
,
"DKG_DH_KEY_"
);
shared_ptr
<
string
>
hexEncrKey
P
tr
=
SGXWalletServer
::
readFromDb
(
DH_key_name
,
"DKG_DH_KEY_"
);
spdlog
::
debug
(
"encr DH key is {}"
,
*
hexEncrKey
_p
tr
);
spdlog
::
debug
(
"encr DH key is {}"
,
*
hexEncrKey
P
tr
);
vector
<
char
>
hexEncrKey
(
2
*
BUF_LEN
,
0
);
uint64_t
DH_enc_l
en
=
0
;
uint8_t
encrypted
_DHk
ey
[
BUF_LEN
];
if
(
!
hex2carray
(
hexEncrKey
_ptr
->
c_str
(),
&
DH_enc_len
,
encrypted_DHk
ey
))
{
uint64_t
dhEncL
en
=
0
;
uint8_t
encrypted
DHK
ey
[
BUF_LEN
];
if
(
!
hex2carray
(
hexEncrKey
Ptr
->
c_str
(),
&
dhEncLen
,
encryptedDHK
ey
))
{
throw
SGXException
(
INVALID_HEX
,
"Invalid hexEncrKey"
);
}
spdlog
::
debug
(
"encr DH key length is {}"
,
DH_enc_l
en
);
spdlog
::
debug
(
"hex encr DH key length is {}"
,
hexEncrKey
_p
tr
->
length
());
spdlog
::
debug
(
"encr DH key length is {}"
,
dhEncL
en
);
spdlog
::
debug
(
"hex encr DH key length is {}"
,
hexEncrKey
P
tr
->
length
());
char
DHKey
[
ECDSA_SKEY_LEN
];
if
(
!
encryptKeys
)
decrypt_key
(
eid
,
&
err_status
,
errMsg1
.
data
(),
encrypted
_DHkey
,
DH_enc_l
en
,
DHKey
);
decrypt_key
(
eid
,
&
err_status
,
errMsg1
.
data
(),
encrypted
DHKey
,
dhEncL
en
,
DHKey
);
else
decrypt_key_aes
(
eid
,
&
err_status
,
errMsg1
.
data
(),
encrypted
_DHkey
,
DH_enc_l
en
,
DHKey
);
decrypt_key_aes
(
eid
,
&
err_status
,
errMsg1
.
data
(),
encrypted
DHKey
,
dhEncL
en
,
DHKey
);
if
(
err_status
!=
0
)
{
throw
SGXException
(
/*ERROR_IN_ENCLAVE*/
err_status
,
"decrypt key failed in enclave"
);
}
...
...
DKGCrypto.h
View file @
2f267c40
...
...
@@ -31,13 +31,13 @@ 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
>
splitString
(
const
char
*
koe
fs
,
const
char
symbol
);
std
::
vector
<
std
::
string
>
splitString
(
const
char
*
coef
fs
,
const
char
symbol
);
std
::
string
trustedGetSecretShares
(
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
);
std
::
string
decrypt
_
DHKey
(
const
std
::
string
&
polyName
,
int
ind
);
std
::
string
decryptDHKey
(
const
std
::
string
&
polyName
,
int
ind
);
bool
CreateBLSShare
(
const
std
::
string
&
blsKeyName
,
const
char
*
s_shares
,
const
char
*
encryptedKeyHex
);
...
...
SGXWalletServer.cpp
View file @
2f267c40
...
...
@@ -671,7 +671,7 @@ Json::Value SGXWalletServer::complaintResponseImpl(const string &_polyName, int
string
shareG2_name
=
"shareG2_"
+
_polyName
+
"_"
+
to_string
(
_ind
)
+
":"
;
shared_ptr
<
string
>
shareG2_ptr
=
readFromDb
(
shareG2_name
);
string
DHKey
=
decrypt
_
DHKey
(
_polyName
,
_ind
);
string
DHKey
=
decryptDHKey
(
_polyName
,
_ind
);
result
[
"share*G2"
]
=
*
shareG2_ptr
;
result
[
"dhKey"
]
=
DHKey
;
...
...
secure_enclave/DKGUtils.cpp
View file @
2f267c40
...
...
@@ -86,8 +86,8 @@ std::string ConvertG2ToString(const libff::alt_bn128_G2 & elem, int base = 10, s
return
result
;
}
std
::
vector
<
libff
::
alt_bn128_Fr
>
SplitStringToFr
(
const
char
*
koe
fs
,
const
char
symbol
){
std
::
string
str
(
koe
fs
);
std
::
vector
<
libff
::
alt_bn128_Fr
>
SplitStringToFr
(
const
char
*
coef
fs
,
const
char
symbol
){
std
::
string
str
(
coef
fs
);
std
::
string
delim
;
delim
.
push_back
(
symbol
);
std
::
vector
<
libff
::
alt_bn128_Fr
>
tokens
;
...
...
@@ -98,8 +98,8 @@ std::vector<libff::alt_bn128_Fr> SplitStringToFr(const char* koefs, const char s
if
(
pos
==
std
::
string
::
npos
)
pos
=
str
.
length
();
std
::
string
token
=
str
.
substr
(
prev
,
pos
-
prev
);
if
(
!
token
.
empty
())
{
libff
::
alt_bn128_Fr
koe
f
(
token
.
c_str
());
tokens
.
push_back
(
koe
f
);
libff
::
alt_bn128_Fr
coef
f
(
token
.
c_str
());
tokens
.
push_back
(
coef
f
);
}
prev
=
pos
+
delim
.
length
();
}
...
...
@@ -146,12 +146,12 @@ libff::alt_bn128_Fr PolynomialValue(const std::vector<libff::alt_bn128_Fr>& pol,
return
value
;
}
void
calc_secret_shares
(
const
char
*
decrypted_
koe
fs
,
char
*
secret_shares
,
// calculates secret shares in base 10 to a string secret_shares,
void
calc_secret_shares
(
const
char
*
decrypted_
coef
fs
,
char
*
secret_shares
,
// calculates secret shares in base 10 to a string secret_shares,
unsigned
_t
,
unsigned
_n
)
{
// separated by ":"
// calculate for each node a list of secret values that will be used for verification
std
::
string
result
;
char
symbol
=
':'
;
std
::
vector
<
libff
::
alt_bn128_Fr
>
poly
=
SplitStringToFr
(
decrypted_
koe
fs
,
symbol
);
std
::
vector
<
libff
::
alt_bn128_Fr
>
poly
=
SplitStringToFr
(
decrypted_
coef
fs
,
symbol
);
for
(
size_t
i
=
0
;
i
<
_n
;
++
i
)
{
libff
::
alt_bn128_Fr
secret_share
=
PolynomialValue
(
poly
,
libff
::
alt_bn128_Fr
(
i
+
1
),
_t
);
...
...
@@ -159,15 +159,15 @@ void calc_secret_shares(const char* decrypted_koefs, char * secret_shares,
result
+=
":"
;
}
strncpy
(
secret_shares
,
result
.
c_str
(),
result
.
length
()
+
1
);
//strncpy(secret_shares, decrypted_
koe
fs, 3650);
//strncpy(secret_shares, decrypted_
coef
fs, 3650);
}
int
calc_secret_share
(
const
char
*
decrypted_
koe
fs
,
char
*
s_share
,
int
calc_secret_share
(
const
char
*
decrypted_
coef
fs
,
char
*
s_share
,
unsigned
_t
,
unsigned
_n
,
unsigned
ind
)
{
libff
::
init_alt_bn128_params
();
char
symbol
=
':'
;
std
::
vector
<
libff
::
alt_bn128_Fr
>
poly
=
SplitStringToFr
(
decrypted_
koe
fs
,
symbol
);
std
::
vector
<
libff
::
alt_bn128_Fr
>
poly
=
SplitStringToFr
(
decrypted_
coef
fs
,
symbol
);
if
(
poly
.
size
()
!=
_t
){
return
1
;
}
...
...
@@ -182,12 +182,12 @@ int calc_secret_share(const char* decrypted_koefs, char * s_share,
}
void
calc_secret_shareG2_old
(
const
char
*
decrypted_
koe
fs
,
char
*
s_shareG2
,
void
calc_secret_shareG2_old
(
const
char
*
decrypted_
coef
fs
,
char
*
s_shareG2
,
unsigned
_t
,
unsigned
ind
){
libff
::
init_alt_bn128_params
();
char
symbol
=
':'
;
std
::
vector
<
libff
::
alt_bn128_Fr
>
poly
=
SplitStringToFr
(
decrypted_
koe
fs
,
symbol
);
std
::
vector
<
libff
::
alt_bn128_Fr
>
poly
=
SplitStringToFr
(
decrypted_
coef
fs
,
symbol
);
// if ( poly.size() != _t){
// //"t != poly.size()" +
// //strncpy(s_shareG2, std::to_string(poly.size()).c_str(), 18);
...
...
@@ -200,7 +200,7 @@ void calc_secret_shareG2_old(const char* decrypted_koefs, char * s_shareG2,
std
::
string
secret_shareG2_str
=
ConvertG2ToString
(
secret_shareG2
);
strncpy
(
s_shareG2
,
secret_shareG2_str
.
c_str
(),
secret_shareG2_str
.
length
()
+
1
);
//strncpy(s_shareG2, decrypted_
koe
fs, 320);
//strncpy(s_shareG2, decrypted_
coef
fs, 320);
}
int
calc_secret_shareG2
(
const
char
*
s_share
,
char
*
s_shareG2
){
...
...
@@ -229,13 +229,13 @@ int calc_secret_shareG2(const char* s_share, char * s_shareG2){
return
0
;
}
int
calc_public_shares
(
const
char
*
decrypted_
koe
fs
,
char
*
public_shares
,
int
calc_public_shares
(
const
char
*
decrypted_
coef
fs
,
char
*
public_shares
,
unsigned
_t
)
{
libff
::
init_alt_bn128_params
();
// calculate for each node a list of public shares
std
::
string
result
;
char
symbol
=
':'
;
std
::
vector
<
libff
::
alt_bn128_Fr
>
poly
=
SplitStringToFr
(
decrypted_
koe
fs
,
symbol
);
std
::
vector
<
libff
::
alt_bn128_Fr
>
poly
=
SplitStringToFr
(
decrypted_
coef
fs
,
symbol
);
if
(
poly
.
size
()
!=
_t
){
return
1
;
}
...
...
secure_enclave/DKGUtils.h
View file @
2f267c40
...
...
@@ -34,13 +34,13 @@
EXTERNC
int
gen_dkg_poly
(
char
*
secret
,
unsigned
_t
);
EXTERNC
void
calc_secret_shares
(
const
char
*
decrypted_
koe
fs
,
char
*
secret_shares
,
EXTERNC
void
calc_secret_shares
(
const
char
*
decrypted_
coef
fs
,
char
*
secret_shares
,
unsigned
_t
,
unsigned
_n
);
EXTERNC
int
calc_secret_share
(
const
char
*
decrypted_
koe
fs
,
char
*
s_share
,
EXTERNC
int
calc_secret_share
(
const
char
*
decrypted_
coef
fs
,
char
*
s_share
,
unsigned
_t
,
unsigned
_n
,
unsigned
ind
);
EXTERNC
int
calc_public_shares
(
const
char
*
decrypted_
koe
fs
,
char
*
public_shares
,
EXTERNC
int
calc_public_shares
(
const
char
*
decrypted_
coef
fs
,
char
*
public_shares
,
unsigned
_t
);
EXTERNC
int
Verification
(
char
*
public_shares
,
mpz_t
decr_secret_share
,
int
_t
,
int
ind
);
...
...
secure_enclave/secure_enclave.c
View file @
2f267c40
...
...
@@ -703,16 +703,16 @@ void trustedGetEncryptedSecretShare(int *err_status, char *err_string, uint8_t *
//free(cypher);
}
void
trustedComplaintResponse
(
int
*
err_status
,
char
*
err_string
,
uint8_t
*
encrypted
_DHk
ey
,
uint8_t
*
encrypted_dkg_secret
,
void
trustedComplaintResponse
(
int
*
err_status
,
char
*
err_string
,
uint8_t
*
encrypted
DHK
ey
,
uint8_t
*
encrypted_dkg_secret
,
uint32_t
*
dec_len
,
char
*
DH_key
,
char
*
s_shareG2
,
uint8_t
_t
,
uint8_t
_n
,
uint8_t
ind1
)
{
uint32_t
enc_len
;
// sgx_status_t status = sgx_unseal_data(
// (const sgx_sealed_data_t *)encrypted
_DHk
ey, NULL, 0, (uint8_t *)DH_key, &enc_len);
// (const sgx_sealed_data_t *)encrypted
DHK
ey, NULL, 0, (uint8_t *)DH_key, &enc_len);
// if (status != SGX_SUCCESS) {
// snprintf(err_string, BUF_LEN,"sgx_unseal_data - encrypted
_DHk
ey failed with status %d", status);
// snprintf(err_string, BUF_LEN,"sgx_unseal_data - encrypted
DHK
ey failed with status %d", status);
// return;
// }
...
...
@@ -1694,7 +1694,7 @@ void trustedCreateBlsKey_aes(int *err_status, char *err_string, const char *s_sh
}
void
trustedGetBlsPubKey
_aes
(
int
*
err_status
,
char
*
err_string
,
uint8_t
*
encrypted_key
,
uint64_t
key_len
,
char
*
bls_pub_key
)
{
trustedGetBlsPubKey
AES
(
int
*
err_status
,
char
*
err_string
,
uint8_t
*
encrypted_key
,
uint64_t
key_len
,
char
*
bls_pub_key
)
{
char
skey_hex
[
ECDSA_SKEY_LEN
];
...
...
secure_enclave/secure_enclave.edl
View file @
2f267c40
This diff is collapsed.
Click to expand it.
testw.cpp
View file @
2f267c40
...
...
@@ -207,8 +207,8 @@ TEST_CASE("DKG gen test", "[dkg-gen]") {
sgx_destroy_enclave
(
eid
);
}
vector
<
libff
::
alt_bn128_Fr
>
SplitStringToFr
(
const
char
*
koe
fs
,
const
char
symbol
)
{
string
str
(
koe
fs
);
vector
<
libff
::
alt_bn128_Fr
>
SplitStringToFr
(
const
char
*
coef
fs
,
const
char
symbol
)
{
string
str
(
coef
fs
);
string
delim
;
delim
.
push_back
(
symbol
);
vector
<
libff
::
alt_bn128_Fr
>
tokens
;
...
...
@@ -218,8 +218,8 @@ vector<libff::alt_bn128_Fr> SplitStringToFr(const char *koefs, const char symbol
if
(
pos
==
string
::
npos
)
pos
=
str
.
length
();
string
token
=
str
.
substr
(
prev
,
pos
-
prev
);
if
(
!
token
.
empty
())
{
libff
::
alt_bn128_Fr
koe
f
(
token
.
c_str
());
tokens
.
push_back
(
koe
f
);
libff
::
alt_bn128_Fr
coef
f
(
token
.
c_str
());
tokens
.
push_back
(
coef
f
);
}
prev
=
pos
+
delim
.
length
();
}
while
(
pos
<
str
.
length
()
&&
prev
<
str
.
length
());
...
...
@@ -227,9 +227,9 @@ vector<libff::alt_bn128_Fr> SplitStringToFr(const char *koefs, const char symbol
return
tokens
;
}
vector
<
string
>
SplitStringTest
(
const
char
*
koe
fs
,
const
char
symbol
)
{
vector
<
string
>
SplitStringTest
(
const
char
*
coef
fs
,
const
char
symbol
)
{
libff
::
init_alt_bn128_params
();
string
str
(
koe
fs
);
string
str
(
coef
fs
);
string
delim
;
delim
.
push_back
(
symbol
);
vector
<
string
>
G2_strings
;
...
...
@@ -239,8 +239,8 @@ vector<string> SplitStringTest(const char *koefs, const char symbol) {
if
(
pos
==
string
::
npos
)
pos
=
str
.
length
();
string
token
=
str
.
substr
(
prev
,
pos
-
prev
);
if
(
!
token
.
empty
())
{
string
koe
f
(
token
.
c_str
());
G2_strings
.
push_back
(
koe
f
);
string
coef
f
(
token
.
c_str
());
G2_strings
.
push_back
(
coef
f
);
}
prev
=
pos
+
delim
.
length
();
}
while
(
pos
<
str
.
length
()
&&
prev
<
str
.
length
());
...
...
@@ -250,15 +250,15 @@ vector<string> SplitStringTest(const char *koefs, const char symbol) {
libff
::
alt_bn128_G2
VectStringToG2
(
const
vector
<
string
>
&
G2_str_vect
)
{
libff
::
init_alt_bn128_params
();
libff
::
alt_bn128_G2
koe
f
=
libff
::
alt_bn128_G2
::
zero
();
koe
f
.
X
.
c0
=
libff
::
alt_bn128_Fq
(
G2_str_vect
.
at
(
0
).
c_str
());
koe
f
.
X
.
c1
=
libff
::
alt_bn128_Fq
(
G2_str_vect
.
at
(
1
).
c_str
());
koe
f
.
Y
.
c0
=
libff
::
alt_bn128_Fq
(
G2_str_vect
.
at
(
2
).
c_str
());
koe
f
.
Y
.
c1
=
libff
::
alt_bn128_Fq
(
G2_str_vect
.
at
(
3
).
c_str
());
koe
f
.
Z
.
c0
=
libff
::
alt_bn128_Fq
::
one
();
koe
f
.
Z
.
c1
=
libff
::
alt_bn128_Fq
::
zero
();
return
koe
f
;
libff
::
alt_bn128_G2
coef
f
=
libff
::
alt_bn128_G2
::
zero
();
coef
f
.
X
.
c0
=
libff
::
alt_bn128_Fq
(
G2_str_vect
.
at
(
0
).
c_str
());
coef
f
.
X
.
c1
=
libff
::
alt_bn128_Fq
(
G2_str_vect
.
at
(
1
).
c_str
());
coef
f
.
Y
.
c0
=
libff
::
alt_bn128_Fq
(
G2_str_vect
.
at
(
2
).
c_str
());
coef
f
.
Y
.
c1
=
libff
::
alt_bn128_Fq
(
G2_str_vect
.
at
(
3
).
c_str
());
coef
f
.
Z
.
c0
=
libff
::
alt_bn128_Fq
::
one
();
coef
f
.
Z
.
c1
=
libff
::
alt_bn128_Fq
::
zero
();
return
coef
f
;
}
TEST_CASE
(
"DKG public shares test"
,
"[dkg-pub-shares]"
)
{
...
...
@@ -297,11 +297,11 @@ TEST_CASE("DKG public shares test", "[dkg-pub-shares]") {
vector
<
string
>
G2_strings
=
splitString
(
public_shares
.
data
(),
','
);
vector
<
libff
::
alt_bn128_G2
>
pub_shares_G2
;
for
(
u_int64_t
i
=
0
;
i
<
G2_strings
.
size
();
i
++
)
{
vector
<
string
>
koe
f_str
=
splitString
(
G2_strings
.
at
(
i
).
c_str
(),
':'
);
//libff::alt_bn128_G2 el = VectStringToG2(
koe
f_str);
vector
<
string
>
coef
f_str
=
splitString
(
G2_strings
.
at
(
i
).
c_str
(),
':'
);
//libff::alt_bn128_G2 el = VectStringToG2(
coef
f_str);
//cerr << "pub_share G2 " << i+1 << " : " << endl;
//el.print_coordinates();
pub_shares_G2
.
push_back
(
VectStringToG2
(
koe
f_str
));
pub_shares_G2
.
push_back
(
VectStringToG2
(
coef
f_str
));
}
vector
<
char
>
secret
(
BUF_LEN
,
0
);
...
...
@@ -809,7 +809,7 @@ void SendRPCRequest() {
throw
SGXException
(
INVALID_HEX
,
"Invalid hash"
);
}
map
<
size_t
,
shared_ptr
<
BLSPublicKeyShare
>>
koe
fs_pkeys_map
;
map
<
size_t
,
shared_ptr
<
BLSPublicKeyShare
>>
coef
fs_pkeys_map
;
for
(
int
i
=
0
;
i
<
t
;
i
++
)
{
...
...
@@ -1082,7 +1082,7 @@ TEST_CASE("AES_DKG test", "[aes-dkg]") {
}
map
<
size_t
,
shared_ptr
<
BLSPublicKeyShare
>>
koe
fs_pkeys_map
;
map
<
size_t
,
shared_ptr
<
BLSPublicKeyShare
>>
coef
fs_pkeys_map
;
for
(
int
i
=
0
;
i
<
t
;
i
++
)
{
string
endName
=
poly_names
[
i
].
substr
(
4
);
...
...
@@ -1108,12 +1108,12 @@ TEST_CASE("AES_DKG test", "[aes-dkg]") {
BLSPublicKeyShare
pubKey
(
make_shared
<
vector
<
string
>>
(
pubKey_vect
),
t
,
n
);
REQUIRE
(
pubKey
.
VerifySigWithHelper
(
hash_arr
,
make_shared
<
BLSSigShare
>
(
sig
),
t
,
n
));
koe
fs_pkeys_map
[
i
+
1
]
=
make_shared
<
BLSPublicKeyShare
>
(
pubKey
);
coef
fs_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
>>>
(
koe
fs_pkeys_map
),
t
,
n
);
BLSPublicKey
common_public
(
make_shared
<
map
<
size_t
,
shared_ptr
<
BLSPublicKeyShare
>>>
(
coef
fs_pkeys_map
),
t
,
n
);
REQUIRE
(
common_public
.
VerifySigWithHelper
(
hash_arr
,
commonSig
,
t
,
n
));
sgx_destroy_enclave
(
eid
);
...
...
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