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
5fa947c4
Unverified
Commit
5fa947c4
authored
Sep 12, 2019
by
svetaro
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SKALE-1512-add-DKG-to-SGX Add sealing and unsealing of DKG secret
parent
56e39f58
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
69 additions
and
50 deletions
+69
-50
DKGUtils.Po
secure_enclave/.deps/DKGUtils.Po
+1
-4
DKGUtils.cpp
secure_enclave/DKGUtils.cpp
+23
-7
DKGUtils.h
secure_enclave/DKGUtils.h
+2
-1
Makefile.am
secure_enclave/Makefile.am
+0
-1
secure_enclave.c
secure_enclave/secure_enclave.c
+17
-16
secure_enclave.edl
secure_enclave/secure_enclave.edl
+12
-3
sgxwallet_common.h
sgxwallet_common.h
+2
-1
testw.cpp
testw.cpp
+12
-17
No files found.
secure_enclave/.deps/DKGUtils.Po
View file @
5fa947c4
...
@@ -90,8 +90,7 @@ DKGUtils.o: DKGUtils.cpp DKGUtils.h \
...
@@ -90,8 +90,7 @@ DKGUtils.o: DKGUtils.cpp DKGUtils.h \
../trusted_libff/libff/algebra/fields/fp.hpp ../sgxwallet_common.h \
../trusted_libff/libff/algebra/fields/fp.hpp ../sgxwallet_common.h \
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/unistd.h \
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/unistd.h \
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/sys/types.h \
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/sys/types.h \
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/stdbool.h \
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/stdbool.h
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/mbusafecrt.h
DKGUtils.h:
DKGUtils.h:
...
@@ -280,5 +279,3 @@ DKGUtils.h:
...
@@ -280,5 +279,3 @@ DKGUtils.h:
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/sys/types.h:
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/sys/types.h:
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/stdbool.h:
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/stdbool.h:
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/mbusafecrt.h:
secure_enclave/DKGUtils.cpp
View file @
5fa947c4
...
@@ -12,8 +12,6 @@
...
@@ -12,8 +12,6 @@
#include <cstdio>
#include <cstdio>
#include <stdio.h>
#include <stdio.h>
#include <mbusafecrt.h>
std
::
string
stringFromFr
(
libff
::
alt_bn128_Fr
&
_el
)
{
std
::
string
stringFromFr
(
libff
::
alt_bn128_Fr
&
_el
)
{
...
@@ -30,7 +28,26 @@ std::string stringFromFr(libff::alt_bn128_Fr& _el) {
...
@@ -30,7 +28,26 @@ std::string stringFromFr(libff::alt_bn128_Fr& _el) {
return
std
::
string
(
tmp
);
return
std
::
string
(
tmp
);
}
}
void
gen_dkg_poly
(
char
*
secret
/*[BUF_LEN]*/
,
unsigned
len
,
unsigned
_t
){
std
::
vector
<
libff
::
alt_bn128_Fr
>
SplitString
(
const
std
::
string
&
str
,
const
std
::
string
&
delim
){
std
::
vector
<
libff
::
alt_bn128_Fr
>
tokens
;
size_t
prev
=
0
,
pos
=
0
;
do
{
pos
=
str
.
find
(
delim
,
prev
);
if
(
pos
==
std
::
string
::
npos
)
pos
=
str
.
length
();
std
::
string
token
=
str
.
substr
(
prev
,
pos
-
prev
);
if
(
!
token
.
empty
())
{
libff
::
alt_bn128_Fr
koef
(
token
.
c_str
());
tokens
.
push_back
(
koef
);
}
prev
=
pos
+
delim
.
length
();
}
while
(
pos
<
str
.
length
()
&&
prev
<
str
.
length
());
return
tokens
;
}
void
gen_dkg_poly
(
char
*
secret
/*[BUF_LEN]*/
,
unsigned
_t
){
libff
::
init_alt_bn128_params
();
libff
::
init_alt_bn128_params
();
std
::
string
result
;
std
::
string
result
;
for
(
size_t
i
=
0
;
i
<
_t
;
++
i
)
{
for
(
size_t
i
=
0
;
i
<
_t
;
++
i
)
{
...
@@ -39,10 +56,9 @@ void gen_dkg_poly( char* secret/*[BUF_LEN]*/, unsigned len, unsigned _t ){
...
@@ -39,10 +56,9 @@ void gen_dkg_poly( char* secret/*[BUF_LEN]*/, unsigned len, unsigned _t ){
while
(
i
==
_t
-
1
&&
cur_coef
==
libff
::
alt_bn128_Fr
::
zero
())
{
while
(
i
==
_t
-
1
&&
cur_coef
==
libff
::
alt_bn128_Fr
::
zero
())
{
cur_coef
=
libff
::
alt_bn128_Fr
::
random_element
();
cur_coef
=
libff
::
alt_bn128_Fr
::
random_element
();
}
}
result
=
stringFromFr
(
cur_coef
);
result
+
=
stringFromFr
(
cur_coef
);
result
+=
":"
;
result
+=
":"
;
}
}
strncpy
(
secret
,
result
.
c_str
(),
result
.
length
());
strncpy
(
secret
,
result
.
c_str
(),
result
.
length
());
len
=
_t
*
33
;
//result.length();
}
}
\ No newline at end of file
secure_enclave/DKGUtils.h
View file @
5fa947c4
...
@@ -11,7 +11,8 @@
...
@@ -11,7 +11,8 @@
#define EXTERNC
#define EXTERNC
#endif
#endif
EXTERNC
void
gen_dkg_poly
(
char
*
secret
,
unsigned
len
,
unsigned
_t
);
EXTERNC
void
gen_dkg_poly
(
char
*
secret
,
unsigned
_t
);
#endif //SGXD_DKGUTILS_H
#endif //SGXD_DKGUTILS_H
secure_enclave/Makefile.am
View file @
5fa947c4
...
@@ -86,7 +86,6 @@ CLEANFILES+= secure_enclave_t.c secure_enclave_t.h
...
@@ -86,7 +86,6 @@ CLEANFILES+= secure_enclave_t.c secure_enclave_t.h
secure_enclave_SOURCES
=
secure_enclave_t.c secure_enclave_t.h
\
secure_enclave_SOURCES
=
secure_enclave_t.c secure_enclave_t.h
\
secure_enclave.c
\
secure_enclave.c
\
DKGUtils.cpp BLSUtils.cpp ../trusted_libff/libff/algebra/curves/alt_bn128/alt_bn128_init.cpp
\
DKGUtils.cpp BLSUtils.cpp ../trusted_libff/libff/algebra/curves/alt_bn128/alt_bn128_init.cpp
\
## ../trusted_libff/libff/algebra/curves/alt_bn128/alt_bn128_pp.cpp
\
../trusted_libff/libff/algebra/curves/alt_bn128/alt_bn128_g1.cpp
$(ENCLAVE_KEY)
$(ENCLAVE_CONFIG)
../trusted_libff/libff/algebra/curves/alt_bn128/alt_bn128_g1.cpp
$(ENCLAVE_KEY)
$(ENCLAVE_CONFIG)
...
...
secure_enclave/secure_enclave.c
View file @
5fa947c4
...
@@ -347,39 +347,40 @@ void ecdsa_sign_message(int *err_status, char *err_string, uint8_t *encrypted_k
...
@@ -347,39 +347,40 @@ void ecdsa_sign_message(int *err_status, char *err_string, uint8_t *encrypted_k
}
}
void
gen_dkg_secret
(
int
*
err_status
,
char
*
err_string
,
uint8_t
*
encrypted_dkg_secret
,
size_t
_t
){
void
gen_dkg_secret
(
int
*
err_status
,
char
*
err_string
,
uint8_t
*
encrypted_dkg_secret
,
uint32_t
*
enc_len
,
size_t
_t
){
size_t
len
=
0
;
char
*
dkg_secret
=
(
char
*
)
malloc
(
DKG_BUFER_LENGTH
);
//char dkg_secret[BUF_LEN];
//char dkg_secret[10];
//memset(dkg_secret, 5, 10);
char
*
dkg_secret
=
(
char
*
)
malloc
(
1024
);
memset
(
dkg_secret
,
0
,
1024
);
gen_dkg_poly
(
dkg_secret
,
len
,
_t
);
gen_dkg_poly
(
dkg_secret
,
_t
);
uint32_t
sealedLen
=
sgx_calc_sealed_data_size
(
0
,
sizeof
((
uint8_t
*
)
dkg_secret
));
//sizeof(sgx_sealed_data_t) + sizeof(dkg_secret); //
uint32_t
sealedLen
=
sgx_calc_sealed_data_size
(
0
,
DKG_BUFER_LENGTH
);
//sizeof(sgx_sealed_data_t) + sizeof(dkg_secret);
sgx_status_t
status
=
sgx_seal_data
(
0
,
NULL
,
sizeof
(
dkg_secret
)
,
(
uint8_t
*
)
dkg_secret
,
sealedLen
,(
sgx_sealed_data_t
*
)
encrypted_dkg_secret
);
sgx_status_t
status
=
sgx_seal_data
(
0
,
NULL
,
DKG_BUFER_LENGTH
,
(
uint8_t
*
)
dkg_secret
,
sealedLen
,(
sgx_sealed_data_t
*
)
encrypted_dkg_secret
);
if
(
status
!=
SGX_SUCCESS
)
{
if
(
status
!=
SGX_SUCCESS
)
{
snprintf
(
err_string
,
BUF_LEN
,
"SGX seal data failed"
);
snprintf
(
err_string
,
BUF_LEN
,
"SGX seal data failed"
);
}
}
*
enc_len
=
sealedLen
;
}
}
void
decrypt_dkg_secret
(
int
*
err_status
,
char
*
err_string
,
uint8_t
*
encrypted_dkg_secret
,
uint8_t
*
decrypted_dkg_secret
){
void
decrypt_dkg_secret
(
int
*
err_status
,
char
*
err_string
,
uint8_t
*
encrypted_dkg_secret
,
uint8_t
*
decrypted_dkg_secret
,
uint32_t
enc_len
){
uint32_t
dec_size
=
1024
;
//sgx_get_encrypt_txt_len( (const sgx_sealed_data_t *)encrypted_dkg_secret);
//uint32_t dec_size = DKG_BUFER_LENGTH;//sgx_get_encrypt_txt_len( ( sgx_sealed_data_t *)encrypted_dkg_secret);
// sgx_sealed_data_t *tmp = (sgx_sealed_data_t*)malloc(dec_size);
//memcpy(tmp, encrypted_dkg_secret, dec_size);
sgx_status_t
status
=
sgx_unseal_data
(
sgx_status_t
status
=
sgx_unseal_data
(
(
const
sgx_sealed_data_t
*
)
encrypted_dkg_secret
,
NULL
,
0
,
decrypted_dkg_secret
,
&
dec_size
);
(
const
sgx_sealed_data_t
*
)
encrypted_dkg_secret
,
NULL
,
0
,
decrypted_dkg_secret
,
&
enc_len
);
//tmp, NULL, 0, decrypted_dkg_secret, &dec_size);
if
(
status
!=
SGX_SUCCESS
)
{
if
(
status
!=
SGX_SUCCESS
)
{
snprintf
(
err_string
,
BUF_LEN
,
"sgx_unseal_data failed with status %d"
,
status
);
snprintf
(
err_string
,
BUF_LEN
,
"sgx_unseal_data failed with status %d"
,
status
);
return
;
return
;
}
}
}
void
get_dkg_verif_vector
(
int
*
err_status
,
char
*
err_string
,
uint8_t
*
encrypted_dkg_secret
,
char
*
verif_array
,
uint32_t
enc_len
){
char
*
decrypted_dkg_secret
=
(
char
*
)
malloc
(
DKG_MAX_SEALED_LEN
);
decrypt_dkg_secret
(
err_status
,
err_string
,
encrypted_dkg_secret
,
decrypted_dkg_secret
,
enc_len
);
}
}
\ No newline at end of file
secure_enclave/secure_enclave.edl
View file @
5fa947c4
...
@@ -60,14 +60,23 @@ enclave {
...
@@ -60,14 +60,23 @@ enclave {
public void gen_dkg_secret (
public void gen_dkg_secret (
[user_check] int *err_status,
[user_check] int *err_status,
[out, count = 1024] char* err_string,
[out, count = 1024] char* err_string,
[out, count = 1024] uint8_t* encrypted_dkg_secret,
[out, count = 2000] uint8_t* encrypted_dkg_secret,
[user_check] uint32_t * enc_len,
size_t _t);
size_t _t);
public void decrypt_dkg_secret (
public void decrypt_dkg_secret (
[user_check] int *err_status,
[user_check] int *err_status,
[out, count = 1024] char* err_string,
[out, count = 1024] char* err_string,
[in, count = 1024] uint8_t* encrypted_dkg_secret,
[in, count = 2000] uint8_t* encrypted_dkg_secret,
[out, count = 1024] uint8_t* decrypted_dkg_secret);
[out, count = 2000] uint8_t* decrypted_dkg_secret,
uint32_t enc_len);
public void get_dkg_verif_vector (
[user_check] int *err_status,
[out, count = 1024] char* err_string,
[in, count = 2000] uint8_t* encrypted_dkg_secret,
[out, count = 2024] char* verif_vector,
uint32_t enc_len);
};
};
...
...
sgxwallet_common.h
View file @
5fa947c4
...
@@ -26,6 +26,7 @@
...
@@ -26,6 +26,7 @@
#define ADD_ENTROPY_SIZE 32
#define ADD_ENTROPY_SIZE 32
#define DKG_BUFER_LENGTH 1250
#define DKG_MAX_SEALED_LEN 2000
#endif //SGXD_SGXD_COMMON_H
#endif //SGXD_SGXD_COMMON_H
testw.cpp
View file @
5fa947c4
...
@@ -139,40 +139,35 @@ TEST_CASE( "BLS sign test", "[bls-sign]" ) {
...
@@ -139,40 +139,35 @@ TEST_CASE( "BLS sign test", "[bls-sign]" ) {
}
}
TEST_CASE
(
"DKG gen test"
,
"[dkg-gen]"
)
{
TEST_CASE
(
"DKG gen test"
,
"[dkg-gen]"
)
{
init_all
();
init_all
();
uint8_t
*
encrypted_dkg_secret
=
(
uint8_t
*
)
malloc
(
1024
);
//(uint8_t*) calloc(1024, 1);
uint8_t
*
encrypted_dkg_secret
=
(
uint8_t
*
)
calloc
(
DKG_MAX_SEALED_LEN
,
1
);
memset
(
encrypted_dkg_secret
,
0
,
1024
);
char
*
errMsg
=
(
char
*
)
calloc
(
1024
,
1
);
char
*
errMsg
=
(
char
*
)
calloc
(
1024
,
1
);
int
err_status
=
0
;
int
err_status
=
0
;
uint32_t
enc_len
=
0
;
status
=
gen_dkg_secret
(
eid
,
&
err_status
,
errMsg
,
encrypted_dkg_secret
,
1
);
status
=
gen_dkg_secret
(
eid
,
&
err_status
,
errMsg
,
encrypted_dkg_secret
,
&
enc_len
,
16
);
REQUIRE
(
status
==
SGX_SUCCESS
);
REQUIRE
(
status
==
SGX_SUCCESS
);
printf
(
"gen_dkg_secret completed with status: %d %s
\n
"
,
err_status
,
errMsg
);
printf
(
"gen_dkg_secret completed with status: %d %s
\n
"
,
err_status
,
errMsg
);
printf
(
"
encrypted secret length %ld
\n
"
,
sizeof
(
encrypted_dkg_secret
)
);
printf
(
"
\n
Length: %d
\n
"
,
enc_len
);
uint8_t
*
secret
=
(
uint8_t
*
)
calloc
(
1024
,
sizeof
(
uint8_t
));
char
*
secret
=
(
char
*
)
calloc
(
DKG_MAX_SEALED_LEN
,
sizeof
(
char
));
char
*
errMsg1
=
(
char
*
)
calloc
(
1024
,
1
);
char
*
errMsg1
=
(
char
*
)
calloc
(
1024
,
1
);
status
=
decrypt_dkg_secret
(
eid
,
&
err_status
,
errMsg1
,
(
uint8_t
*
)
encrypted_dkg_secret
,
secret
);
status
=
decrypt_dkg_secret
(
eid
,
&
err_status
,
errMsg1
,
encrypted_dkg_secret
,
(
uint8_t
*
)
secret
,
enc_len
);
REQUIRE
(
status
==
SGX_SUCCESS
);
REQUIRE
(
status
==
SGX_SUCCESS
);
printf
(
"decrypt_dkg_secret completed with status: %d %s
\n
"
,
err_status
,
errMsg1
);
printf
(
"
\n
decrypt_dkg_secret completed with status: %d %s
\n
"
,
err_status
,
errMsg1
);
printf
(
"decrypted secret length %ld
\n
"
,
sizeof
(
secret
));
printf
(
"decrypted secret %s
\n\n
"
,
secret
);
printf
(
"decrypted secret %s
\n
"
,
secret
);
/*libff::alt_bn128_Fr cur_coef = libff::alt_bn128_Fr::random_element(
);
free
(
errMsg
);
std::string rand_el_str = stringFromFr(cur_coef
);
free
(
errMsg1
);
printf("rand element is: %s", rand_el_str.c_str()
);
free
(
encrypted_dkg_secret
);
printf("rand element length: %d", (int)rand_el_str.length());*/
free
(
secret
);
}
}
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