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
af3fc638
Unverified
Commit
af3fc638
authored
Sep 09, 2019
by
kladkogex
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added init
parent
a3c8adac
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
176 additions
and
162 deletions
+176
-162
BLSUtils.cpp
secure_enclave/BLSUtils.cpp
+9
-1
BLSUtils.h
secure_enclave/BLSUtils.h
+2
-0
secure_enclave.c
secure_enclave/secure_enclave.c
+165
-161
No files found.
secure_enclave/BLSUtils.cpp
View file @
af3fc638
...
...
@@ -68,10 +68,18 @@ libff::alt_bn128_Fr *keyFromString(const char* _keyString) {
return
new
libff
::
alt_bn128_Fr
(
_keyString
);
}
bool
check_key
(
int
*
err_status
,
char
*
err_string
,
const
char
*
_keyString
)
{
int
inited
=
0
;
void
init
()
{
if
(
inited
==
1
)
return
;
inited
=
1
;
libff
::
init_alt_bn128_params
();
}
bool
check_key
(
int
*
err_status
,
char
*
err_string
,
const
char
*
_keyString
)
{
...
...
secure_enclave/BLSUtils.h
View file @
af3fc638
...
...
@@ -26,5 +26,7 @@ EXTERNC void carray2Hex(const unsigned char *d, int _len, char* _hexArray);
EXTERNC
bool
hex2carray
(
const
char
*
_hex
,
uint64_t
*
_bin_len
,
uint8_t
*
_bin
);
EXTERNC
void
init
();
#endif //SGXWALLET_BLSUTILS_H
secure_enclave/secure_enclave.c
View file @
af3fc638
...
...
@@ -51,11 +51,15 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "../sgxwallet_common.h"
void
*
(
*
gmp_realloc_func
)(
void
*
,
size_t
,
size_t
);
void
*
(
*
oc_realloc_func
)(
void
*
,
size_t
,
size_t
);
void
(
*
gmp_free_func
)(
void
*
,
size_t
);
void
(
*
oc_free_func
)(
void
*
,
size_t
);
void
*
reallocate_function
(
void
*
,
size_t
,
size_t
);
void
free_function
(
void
*
,
size_t
);
...
...
@@ -97,10 +101,10 @@ void *reallocate_function(void *ptr, size_t osize, size_t nsize) {
* free() and try again, but would you trust the OS at this point?
*/
if
(
!
sgx_is_outside_enclave
((
void
*
)
ptr
,
nsize
))
if
(
!
sgx_is_outside_enclave
((
void
*
)
ptr
,
nsize
))
abort
();
return
(
void
*
)
nptr
;
return
(
void
*
)
nptr
;
}
void
e_mpz_add
(
mpz_t
*
c_un
,
mpz_t
*
a_un
,
mpz_t
*
b_un
)
{}
...
...
@@ -120,6 +124,7 @@ void generate_ecdsa_key(int *err_status, char *err_string,
void
encrypt_key
(
int
*
err_status
,
char
*
err_string
,
char
*
key
,
uint8_t
*
encrypted_key
,
uint32_t
*
enc_len
)
{
init
();
*
err_status
=
-
1
;
memset
(
err_string
,
0
,
BUF_LEN
);
...
...
@@ -131,7 +136,7 @@ void encrypt_key(int *err_status, char *err_string, char *key,
check_key
(
err_status
,
err_string
,
key
);
if
(
*
err_status
!=
0
)
{
snprintf
(
err_string
+
strlen
(
err_string
),
BUF_LEN
,
"check_key failed"
);
snprintf
(
err_string
+
strlen
(
err_string
),
BUF_LEN
,
"check_key failed"
);
return
;
}
...
...
@@ -140,7 +145,7 @@ void encrypt_key(int *err_status, char *err_string, char *key,
*
err_status
=
-
4
;
if
(
sealedLen
>
BUF_LEN
)
{
snprintf
(
err_string
,
BUF_LEN
,
"sealedLen > MAX_ENCRYPTED_KEY_LENGTH"
);
snprintf
(
err_string
,
BUF_LEN
,
"sealedLen > MAX_ENCRYPTED_KEY_LENGTH"
);
return
;
}
...
...
@@ -148,16 +153,15 @@ void encrypt_key(int *err_status, char *err_string, char *key,
memset
(
encrypted_key
,
0
,
BUF_LEN
);
if
(
sgx_seal_data
(
0
,
NULL
,
MAX_KEY_LENGTH
,
(
uint8_t
*
)
key
,
sealedLen
,
(
sgx_sealed_data_t
*
)
encrypted_key
)
!=
if
(
sgx_seal_data
(
0
,
NULL
,
MAX_KEY_LENGTH
,
(
uint8_t
*
)
key
,
sealedLen
,
(
sgx_sealed_data_t
*
)
encrypted_key
)
!=
SGX_SUCCESS
)
{
snprintf
(
err_string
,
BUF_LEN
,
"SGX seal data failed"
);
snprintf
(
err_string
,
BUF_LEN
,
"SGX seal data failed"
);
return
;
}
*
enc_len
=
sealedLen
;
char
key2
[
BUF_LEN
];
memset
(
key2
,
0
,
BUF_LEN
);
...
...
@@ -165,16 +169,15 @@ void encrypt_key(int *err_status, char *err_string, char *key,
decrypt_key
(
err_status
,
err_string
,
encrypted_key
,
sealedLen
,
key2
);
if
(
*
err_status
!=
0
)
{
snprintf
(
err_string
+
strlen
(
err_string
),
BUF_LEN
,
":decrypt_key failed"
);
snprintf
(
err_string
+
strlen
(
err_string
),
BUF_LEN
,
":decrypt_key failed"
);
return
;
}
uint64_t
key2Len
=
strnlen
(
key2
,
MAX_KEY_LENGTH
);
if
(
key2Len
==
MAX_KEY_LENGTH
)
{
snprintf
(
err_string
,
MAX_ERR_LEN
,
"Key2 is not null terminated"
);
snprintf
(
err_string
,
MAX_ERR_LEN
,
"Key2 is not null terminated"
);
return
;
}
...
...
@@ -188,7 +191,9 @@ void encrypt_key(int *err_status, char *err_string, char *key,
}
void
decrypt_key
(
int
*
err_status
,
char
*
err_string
,
uint8_t
*
encrypted_key
,
uint32_t
enc_len
,
char
*
key
)
{
uint32_t
enc_len
,
char
*
key
)
{
init
();
uint32_t
decLen
;
...
...
@@ -196,10 +201,10 @@ void decrypt_key(int *err_status, char *err_string, uint8_t *encrypted_key,
*
err_status
=
-
9
;
sgx_status_t
status
=
sgx_unseal_data
(
(
const
sgx_sealed_data_t
*
)
encrypted_key
,
NULL
,
0
,
(
uint8_t
*
)
key
,
&
decLen
);
(
const
sgx_sealed_data_t
*
)
encrypted_key
,
NULL
,
0
,
(
uint8_t
*
)
key
,
&
decLen
);
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
;
}
...
...
@@ -224,7 +229,7 @@ void decrypt_key(int *err_status, char *err_string, uint8_t *encrypted_key,
for
(
int
i
=
keyLen
;
i
<
MAX_KEY_LENGTH
;
i
++
)
{
if
(
key
[
i
]
!=
0
)
{
snprintf
(
err_string
,
BUF_LEN
,
"Unpadded key"
);
snprintf
(
err_string
,
BUF_LEN
,
"Unpadded key"
);
return
;
}
}
...
...
@@ -235,16 +240,15 @@ void decrypt_key(int *err_status, char *err_string, uint8_t *encrypted_key,
}
void
bls_sign_message
(
int
*
err_status
,
char
*
err_string
,
uint8_t
*
encrypted_key
,
uint32_t
enc_len
,
char
*
_hashX
,
char
*
_hashY
,
char
*
signature
)
{
char
*
_hashY
,
char
*
signature
)
{
char
key
[
BUF_LEN
];
char
sig
[
BUF_LEN
];
init
();
decrypt_key
(
err_status
,
err_string
,
encrypted_key
,
enc_len
,
key
);
...
...
@@ -253,7 +257,7 @@ void bls_sign_message(int *err_status, char *err_string, uint8_t *encrypted_key
return
;
}
sign
(
key
,
_hashX
,
_hashY
,
sig
);
sign
(
key
,
_hashX
,
_hashY
,
sig
);
strncpy
(
signature
,
sig
,
BUF_LEN
);
...
...
@@ -292,7 +296,7 @@ void ecdsa_sign_message(int *err_status, char *err_string, uint8_t *encrypted_k
RAND_add
(
entropy_buf
,
sizeof
(
entropy_buf
),
ADD_ENTROPY_SIZE
);
RAND_seed
(
entropy_buf
,
sizeof
(
entropy_buf
));
EC_KEY
*
ec
=
NULL
;
EC_KEY
*
ec
=
NULL
;
int
eccgroup
;
eccgroup
=
OBJ_txt2nid
(
"secp384r1"
);
ec
=
EC_KEY_new_by_curve_name
(
eccgroup
);
...
...
@@ -322,7 +326,7 @@ void ecdsa_sign_message(int *err_status, char *err_string, uint8_t *encrypted_k
for
(
i
=
0
;
i
<
1000
;
i
++
)
{
// Add context
EVP_MD_CTX
*
context
=
EVP_MD_CTX_new
();
EVP_MD_CTX
*
context
=
EVP_MD_CTX_new
();
// Init, update, final
EVP_SignInit_ex
(
context
,
EVP_sha1
(),
NULL
);
EVP_SignUpdate
(
context
,
&
buffer
,
100
);
...
...
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