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
50a42a1e
Unverified
Commit
50a42a1e
authored
Aug 26, 2020
by
Oleh Nikolaiev
Committed by
GitHub
Aug 26, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' into enhancement/SKALE-3007-sgx-parameters-validation
parents
4571af97
8e5e8758
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
42 additions
and
89 deletions
+42
-89
DHDkg.c
secure_enclave/DHDkg.c
+10
-36
DKGUtils.cpp
secure_enclave/DKGUtils.cpp
+27
-40
EnclaveCommon.cpp
secure_enclave/EnclaveCommon.cpp
+4
-2
sgxwall.cpp
sgxwall.cpp
+0
-1
testw.py
testw.py
+1
-10
No files found.
secure_enclave/DHDkg.c
View file @
50a42a1e
...
...
@@ -43,12 +43,7 @@
#include <string.h>
int
gen_session_key
(
char
*
skey_str
,
char
*
pb_keyB
,
char
*
common_key
)
{
int
ret
=
-
1
;
LOG_INFO
(
__FUNCTION__
);
...
...
@@ -60,7 +55,6 @@ int gen_session_key(char *skey_str, char *pb_keyB, char *common_key) {
point
pub_keyB
=
point_init
();
point
session_key
=
point_init
();
if
(
!
common_key
)
{
LOG_ERROR
(
"gen_session_key: Null common_key"
);
goto
clean
;
...
...
@@ -107,18 +101,15 @@ int gen_session_key(char *skey_str, char *pb_keyB, char *common_key) {
point_clear
(
session_key
);
return
ret
;
}
int
session_key_recover
(
const
char
*
skey_str
,
const
char
*
sshare
,
char
*
common_key
)
{
int
ret
=
-
1
;
SAFE_CHAR_BUF
(
pb_keyB_x
,
65
);
SAFE_CHAR_BUF
(
pb_keyB_y
,
65
);
mpz_t
skey
;
mpz_init
(
skey
);
point
pub_keyB
=
point_init
();
...
...
@@ -147,14 +138,6 @@ int session_key_recover(const char *skey_str, const char *sshare, char *common_k
goto
clean
;
}
if
(
mpz_set_str
(
skey
,
skey_str
,
16
)
==
-
1
)
{
goto
clean
;
}
...
...
@@ -187,17 +170,17 @@ int xor_encrypt(char *key, char *message, char *cypher) {
if
(
!
cypher
)
{
LOG_ERROR
(
"xor_encrypt: null cypher"
);
goto
clean
;
return
ret
;
}
if
(
!
key
)
{
LOG_ERROR
(
"xor_encrypt: null key"
);
goto
clean
;
return
ret
;
}
if
(
!
message
)
{
LOG_ERROR
(
"xor_encrypt: null message"
);
goto
clean
;
return
ret
;
}
SAFE_CHAR_BUF
(
cypher_bin
,
33
);
...
...
@@ -206,13 +189,13 @@ int xor_encrypt(char *key, char *message, char *cypher) {
uint64_t
key_length
;
if
(
!
hex2carray
(
key
,
&
key_length
,
(
uint8_t
*
)
key_bin
))
{
goto
clean
;
return
ret
;
}
uint64_t
msg_length
;
uint8_t
msg_bin
[
33
];
if
(
!
hex2carray
(
message
,
&
msg_length
,
msg_bin
))
{
goto
clean
;
return
ret
;
}
for
(
int
i
=
0
;
i
<
32
;
i
++
)
{
...
...
@@ -223,11 +206,7 @@ int xor_encrypt(char *key, char *message, char *cypher) {
ret
=
0
;
clean:
;
return
ret
;
}
int
xor_decrypt
(
char
*
key
,
char
*
cypher
,
char
*
message
)
{
...
...
@@ -236,34 +215,33 @@ int xor_decrypt(char *key, char *cypher, char *message) {
if
(
!
cypher
)
{
LOG_ERROR
(
"xor_encrypt: null cypher"
);
goto
clean
;
return
ret
;
}
if
(
!
key
)
{
LOG_ERROR
(
"xor_encrypt: null key"
);
goto
clean
;
return
ret
;
}
if
(
!
message
)
{
LOG_ERROR
(
"xor_encrypt: null message"
);
goto
clean
;
return
ret
;
}
SAFE_CHAR_BUF
(
msg_bin
,
33
);
SAFE_CHAR_BUF
(
key_bin
,
33
)
uint64_t
key_length
;
if
(
!
hex2carray
(
key
,
&
key_length
,
(
uint8_t
*
)
key_bin
))
{
goto
clean
;
return
ret
;
}
uint64_t
cypher_length
;
SAFE_CHAR_BUF
(
cypher_bin
,
33
);
if
(
!
hex2carray
(
cypher
,
&
cypher_length
,
(
uint8_t
*
)
cypher_bin
))
{
goto
clean
;
return
ret
;
}
for
(
int
i
=
0
;
i
<
32
;
i
++
)
{
...
...
@@ -274,9 +252,5 @@ int xor_decrypt(char *key, char *cypher, char *message) {
ret
=
0
;
clean:
;
return
ret
;
}
secure_enclave/DKGUtils.cpp
View file @
50a42a1e
...
...
@@ -51,10 +51,7 @@ string stringFromFr(const libff::alt_bn128_Fr &_el) {
mpz_t
t
;
mpz_init
(
t
);
try
{
_el
.
as_bigint
().
to_mpz
(
t
);
SAFE_CHAR_BUF
(
arr
,
BUF_LEN
);
...
...
@@ -95,7 +92,6 @@ string ConvertToString(const T &field_elem, int base = 10) {
char
*
tmp
=
mpz_get_str
(
arr
,
base
,
t
);
ret
=
string
(
tmp
);
goto
clean
;
...
...
@@ -128,24 +124,20 @@ string ConvertG2ToString(const libff::alt_bn128_G2 &elem, int base = 10, const s
result
+=
delim
;
result
+=
ConvertToString
(
elem
.
Y
.
c1
);
goto
clean
;
return
result
;
}
catch
(
exception
&
e
)
{
LOG_ERROR
(
e
.
what
());
goto
clean
;
return
result
;
}
catch
(...)
{
LOG_ERROR
(
"Unknown throwable"
);
goto
clean
;
return
result
;
}
clean
:
return
result
;
}
vector
<
libff
::
alt_bn128_Fr
>
SplitStringToFr
(
const
char
*
coeffs
,
const
char
symbol
)
{
vector
<
libff
::
alt_bn128_Fr
>
result
;
string
str
(
coeffs
);
string
delim
;
...
...
@@ -168,14 +160,14 @@ vector <libff::alt_bn128_Fr> SplitStringToFr(const char *coeffs, const char symb
prev
=
pos
+
delim
.
length
();
}
while
(
pos
<
str
.
length
()
&&
prev
<
str
.
length
());
goto
clean
;
return
result
;
}
catch
(
exception
&
e
)
{
LOG_ERROR
(
e
.
what
());
goto
clean
;
return
result
;
}
catch
(...)
{
LOG_ERROR
(
"Unknown throwable"
);
goto
clean
;
return
result
;
}
clean
:
...
...
@@ -202,22 +194,21 @@ int gen_dkg_poly(char *secret, unsigned _t) {
strncpy
(
secret
,
result
.
c_str
(),
result
.
length
()
+
1
);
if
(
strlen
(
secret
)
==
0
)
{
goto
clean
;
return
status
;
}
status
=
0
;
}
catch
(
exception
&
e
)
{
LOG_ERROR
(
e
.
what
());
goto
clean
;
return
status
;
}
catch
(...)
{
LOG_ERROR
(
"Unknown throwable"
);
goto
clean
;
return
status
;
}
clean
:
return
status
;
}
libff
::
alt_bn128_Fr
PolynomialValue
(
const
vector
<
libff
::
alt_bn128_Fr
>
&
pol
,
libff
::
alt_bn128_Fr
point
,
unsigned
_t
)
{
...
...
@@ -232,16 +223,15 @@ libff::alt_bn128_Fr PolynomialValue(const vector <libff::alt_bn128_Fr> &pol, lib
pow
*=
point
;
}
goto
clean
;
return
result
;
}
catch
(
exception
&
e
)
{
LOG_ERROR
(
e
.
what
());
goto
clean
;
return
result
;
}
catch
(...)
{
LOG_ERROR
(
"Unknown throwable"
);
goto
clean
;
return
result
;
}
clean
:
return
result
;
}
...
...
@@ -271,10 +261,10 @@ void calc_secret_shares(const char *decrypted_coeffs,
}
catch
(
exception
&
e
)
{
LOG_ERROR
(
e
.
what
());
goto
clea
n
;
retur
n
;
}
catch
(...)
{
LOG_ERROR
(
"Unknown throwable"
);
goto
clea
n
;
retur
n
;
}
clean
:
...
...
@@ -283,8 +273,6 @@ void calc_secret_shares(const char *decrypted_coeffs,
int
calc_secret_share
(
const
char
*
decrypted_coeffs
,
char
*
s_share
,
unsigned
_t
,
unsigned
_n
,
unsigned
ind
)
{
int
result
=
1
;
CHECK_ARG_CLEAN
(
decrypted_coeffs
);
...
...
@@ -296,7 +284,7 @@ int calc_secret_share(const char *decrypted_coeffs, char *s_share,
char
symbol
=
':'
;
vector
<
libff
::
alt_bn128_Fr
>
poly
=
SplitStringToFr
(
decrypted_coeffs
,
symbol
);
if
(
poly
.
size
()
!=
_t
)
{
goto
clean
;
return
result
;
}
libff
::
alt_bn128_Fr
secret_share
=
PolynomialValue
(
poly
,
libff
::
alt_bn128_Fr
(
ind
),
_t
);
...
...
@@ -306,14 +294,14 @@ int calc_secret_share(const char *decrypted_coeffs, char *s_share,
strncpy
(
s_share
,
cur_share
.
c_str
(),
cur_share
.
length
()
+
1
);
result
=
0
;
goto
clean
;
return
result
;
}
catch
(
exception
&
e
)
{
LOG_ERROR
(
e
.
what
());
goto
clean
;
return
result
;
}
catch
(...)
{
LOG_ERROR
(
"Unknown throwable"
);
goto
clean
;
return
result
;
}
clean
:
...
...
@@ -381,12 +369,11 @@ int calc_public_shares(const char *decrypted_coeffs, char *public_shares,
CHECK_ARG_CLEAN
(
public_shares
);
CHECK_ARG_CLEAN
(
_t
>
0
);
try
{
vector
<
libff
::
alt_bn128_Fr
>
poly
=
SplitStringToFr
(
decrypted_coeffs
,
symbol
);
if
(
poly
.
size
()
!=
_t
)
{
goto
clean
;
return
ret
;
}
for
(
size_t
i
=
0
;
i
<
_t
;
++
i
)
{
libff
::
alt_bn128_G2
pub_share
=
poly
.
at
(
i
)
*
libff
::
alt_bn128_G2
::
one
();
...
...
@@ -406,7 +393,7 @@ int calc_public_shares(const char *decrypted_coeffs, char *public_shares,
}
clean
:
return
ret
;
return
ret
;
}
string
ConvertHexToDec
(
string
hex_str
)
{
...
...
@@ -435,8 +422,8 @@ string ConvertHexToDec(string hex_str) {
}
clean
:
mpz_clear
(
dec
);
return
ret
;
mpz_clear
(
dec
);
return
ret
;
}
int
Verification
(
char
*
public_shares
,
mpz_t
decr_secret_share
,
int
_t
,
int
ind
)
{
...
...
@@ -461,7 +448,7 @@ int Verification(char *public_shares, mpz_t decr_secret_share, int _t, int ind)
string
y_c1_str
=
ConvertHexToDec
(
pub_shares_str
.
substr
(
pos0
+
3
*
coord_length
,
coord_length
));
if
(
x_c0_str
==
""
||
x_c1_str
==
""
||
y_c0_str
==
""
||
y_c1_str
==
""
)
{
ret
=
2
;
goto
clean
;
return
ret
;
}
pub_share
.
X
.
c0
=
libff
::
alt_bn128_Fq
(
x_c0_str
.
c_str
());
pub_share
.
X
.
c1
=
libff
::
alt_bn128_Fq
(
x_c1_str
.
c_str
());
...
...
@@ -498,11 +485,11 @@ int Verification(char *public_shares, mpz_t decr_secret_share, int _t, int ind)
}
catch
(
exception
&
e
)
{
LOG_ERROR
(
e
.
what
());
goto
clean
;
return
ret
;
}
catch
(...)
{
LOG_ERROR
(
"Unknown throwable"
);
goto
clean
;
return
ret
;
}
clean
:
...
...
@@ -550,6 +537,6 @@ int calc_bls_public_key(char *skey_hex, char *pub_key) {
}
clean
:
mpz_clear
(
skey
);
return
ret
;
mpz_clear
(
skey
);
return
ret
;
}
secure_enclave/EnclaveCommon.cpp
View file @
50a42a1e
...
...
@@ -77,7 +77,8 @@ string *stringFromFq(libff::alt_bn128_Fq *_fq) {
string
*
ret
=
nullptr
;
mpz_t
t
;
mpz_init
(
t
);
SAFE_CHAR_BUF
(
arr
,
BUF_LEN
);
mpz_init
(
t
);
SAFE_CHAR_BUF
(
arr
,
BUF_LEN
);
try
{
_fq
->
as_bigint
().
to_mpz
(
t
);
...
...
@@ -140,7 +141,8 @@ string *stringFromG1(libff::alt_bn128_G1 *_g1) {
libff
::
alt_bn128_Fr
*
keyFromString
(
const
char
*
_keyStringHex
)
{
mpz_t
skey
;
mpz_init
(
skey
);
SAFE_CHAR_BUF
(
skey_dec
,
BUF_LEN
);
mpz_init
(
skey
);
SAFE_CHAR_BUF
(
skey_dec
,
BUF_LEN
);
libff
::
alt_bn128_Fr
*
ret
=
nullptr
;
...
...
sgxwall.cpp
View file @
50a42a1e
...
...
@@ -58,7 +58,6 @@ void SGXWallet::printUsage() {
}
void
SGXWallet
::
serializeKeys
(
const
vector
<
string
>&
_ecdsaKeyNames
,
const
vector
<
string
>&
_blsKeyNames
,
const
string
&
_fileName
)
{
Json
::
Value
top
(
Json
::
objectValue
);
Json
::
Value
ecdsaKeysJson
(
Json
::
objectValue
);
...
...
testw.py
View file @
50a42a1e
...
...
@@ -35,30 +35,21 @@ testList = ["[first-run]",
"[get-server-version]"
,
"[backup-key]"
,
"[delete-bls-key]"
,
"[ecdsa-key-gen]"
,
"[ecdsa-aes-key-gen]"
,
"[ecdsa-key-sig-gen]"
,
"[ecdsa-aes-key-sig-gen]"
,
"[ecdsa-get-pub-key]"
,
"[ecdsa-aes-get-pub-key]"
,
"[ecdsa-key-gen-api]"
,
"[ecdsa-key-gen-sign-api]"
,
"[bls-key-encrypt]"
,
"[dkg-gen]"
,
"[dkg-aes-gen]"
,
"[dkg-encr-sshares]"
,
"[dkg-aes-encr-sshares]"
,
"[dkg-verify]"
,
"[dkg-api]"
,
"[dkg-bls]"
,
"[dkg-poly-exists]"
,
# "[dkg-pub-shares]",
"[dkg-aes-pub-shares]"
,
"[many-threads-crypto]"
,
"[aes-encrypt-decrypt]"
,
"[sgx-encrypt-decrypt]"
,
"[aes-dkg]"
,
"[aes-not-aes]"
"[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