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
f51ca696
Unverified
Commit
f51ca696
authored
Sep 09, 2019
by
kladkogex
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixing tests
parent
4394abec
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
172 additions
and
166 deletions
+172
-166
secure_enclave.c
secure_enclave/secure_enclave.c
+164
-166
sgxwallet_common.h
sgxwallet_common.h
+8
-0
No files found.
secure_enclave/secure_enclave.c
View file @
f51ca696
...
...
@@ -51,13 +51,16 @@ 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
);
...
...
@@ -99,10 +102,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
)
{}
...
...
@@ -127,74 +130,71 @@ 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
;
}
uint32_t
sealedLen
=
sgx_calc_sealed_data_size
(
0
,
MAX_KEY_LENGTH
);
*
err_status
=
-
4
;
if
(
sealedLen
>
BUF_LEN
)
{
snprintf
(
err_string
,
BUF_LEN
,
"sealedLen > MAX_ENCRYPTED_KEY_LENGTH
"
);
snprintf
(
err_string
,
BUF_LEN
,
"sealedLen > BUF_LEN
"
);
return
;
}
*
err_status
=
-
5
;
sgx_status_t
status
;
memset
(
encrypted_key
,
0
,
BUF_LEN
);
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"
)
;
if
(
status
!=
SGX_SUCCESS
)
{
snprintf
(
err_string
,
BUF_LEN
,
"SGX seal data failed with status %d"
,
status
);
err_status
=
SGX_SEAL_DATA_FAILED
;
return
;
}
*
enc_len
=
sealedLen
;
char
decryptedKey
[
BUF_LEN
];
char
key2
[
BUF_LEN
];
memset
(
key2
,
0
,
BUF_LEN
);
decrypt_key
(
err_status
,
err_string
,
encrypted_key
,
sealedLen
,
key2
);
decrypt_key
(
err_status
,
err_string
,
encrypted_key
,
sealedLen
,
decryptedKey
);
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
decryptedKeyLen
=
strnlen
(
decryptedKey
,
MAX_KEY_LENGTH
);
uint64_t
key2Len
=
strnlen
(
key2
,
MAX_KEY_LENGTH
);
if
(
key2Len
==
MAX_KEY_LENGTH
)
{
snprintf
(
err_string
,
MAX_ERR_LEN
,
"Key2 is not null terminated"
);
if
(
decryptedKeyLen
==
MAX_KEY_LENGTH
)
{
*
err_status
=
STRING_NOT_NULL_TERMINATED
;
snprintf
(
err_string
,
MAX_ERR_LEN
,
"Key2 is not null terminated"
);
return
;
}
*
err_status
=
-
8
;
if
(
strncmp
(
key
,
key2
,
MAX_KEY_LENGTH
)
!=
0
)
if
(
strncmp
(
key
,
decryptedKey
,
MAX_KEY_LENGTH
)
!=
0
)
{
*
err_status
=
ENCRYPTION_DECRYPTION_MISMATCH
;
snprintf
(
err_string
,
MAX_ERR_LEN
,
"Decrypted key does not match original"
);
return
;
}
*
err_status
=
0
;
}
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
)
{
uint32_t
decLen
;
*
err_status
=
-
9
;
memset
(
key
,
0
,
BUF_LEN
);
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
;
}
...
...
@@ -219,7 +219,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
;
}
}
...
...
@@ -230,11 +230,9 @@ 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
];
...
...
@@ -246,7 +244,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
);
...
...
@@ -285,7 +283,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
);
...
...
@@ -315,7 +313,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
);
...
...
sgxwallet_common.h
View file @
f51ca696
...
...
@@ -32,6 +32,14 @@
#define UNPADDED_KEY -3
#define NULL_KEY -4
#define INCORRECT_STRING_CONVERSION -5
#define SEALED_LEN_TOO_LARGE -6
#define SGX_SEAL_DATA_FAILED -7
#define STRING_NOT_NULL_TERMINATED -8
#define ENCRYPTION_DECRYPTION_MISMATCH -9
...
...
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