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
bfa691b4
Unverified
Commit
bfa691b4
authored
Sep 02, 2019
by
a72d9e2bad9edfd58d6c0248c12c953b71d409d2
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes
parent
c15cb343
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
15 deletions
+34
-15
secure_enclave.c
secure_enclave/secure_enclave.c
+32
-13
sgxd.c
sgxd.c
+2
-2
No files found.
secure_enclave/secure_enclave.c
View file @
bfa691b4
...
...
@@ -50,7 +50,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define MAX_KEY_LENGTH 128
#define MAX_ENCRYPTED_KEY_LENGTH 1
28
#define MAX_ENCRYPTED_KEY_LENGTH 1
024
#define ADD_ENTROPY_SIZE 32
...
...
@@ -116,25 +116,41 @@ void e_mpz_div(mpz_t *c_un, mpz_t *a_un, mpz_t *b_un) {}
void
e_mpf_div
(
mpf_t
*
c_un
,
mpf_t
*
a_un
,
mpf_t
*
b_un
)
{}
void
encrypt_key
(
int
*
err_status
,
unsigned
char
*
key
,
unsigned
char
*
encrypted_key
,
uint32_t
*
enc_len
)
{
*
err_status
=
-
1
;
if
(
strnlen
(
key
,
MAX_KEY_LENGTH
-
1
)
==
MAX_KEY_LENGTH
-
1
)
uint64_t
keyLen
=
strnlen
(
key
,
MAX_KEY_LENGTH
);
// check that key is zero terminated string
if
(
keyLen
==
MAX_KEY_LENGTH
)
return
;
*
err_status
=
-
2
;
// check that key is padded with 0s
for
(
int
i
=
keyLen
;
i
<
MAX_KEY_LENGTH
;
i
++
)
{
if
(
key
[
i
]
!=
0
)
{
return
;
}
}
*
err_status
=
-
3
;
if
(
!
check_key
(
key
))
{
return
;
}
uint32_t
sealedLen
=
sgx_calc_sealed_data_size
(
0
,
strlen
(
key
)
+
1
);
uint32_t
sealedLen
=
sgx_calc_sealed_data_size
(
0
,
MAX_KEY_LENGTH
);
*
err_status
=
-
4
;
if
(
sealedLen
>
1024
)
{
if
(
sealedLen
>
MAX_ENCRYPTED_KEY_LENGTH
)
{
return
;
}
...
...
@@ -142,15 +158,13 @@ void encrypt_key(int *err_status, unsigned char *key,
memset
(
encrypted_key
,
0
,
MAX_ENCRYPTED_KEY_LENGTH
);
if
(
sgx_seal_data
(
0
,
NULL
,
strlen
(
key
)
+
1
,
key
,
sealedLen
,
encrypted_key
)
!=
if
(
sgx_seal_data
(
0
,
NULL
,
MAX_KEY_LENGTH
,
key
,
sealedLen
,
encrypted_key
)
!=
SGX_SUCCESS
)
return
;
*
enc_len
=
sealedLen
;
*
err_status
=
-
6
;
char
key2
[
MAX_KEY_LENGTH
];
...
...
@@ -158,17 +172,22 @@ void encrypt_key(int *err_status, unsigned char *key,
decrypt_key
(
err_status
,
encrypted_key
,
sealedLen
,
key2
);
if
(
strnlen
(
key2
,
MAX_KEY_LENGTH
-
1
)
==
MAX_KEY_LENGTH
-
1
)
return
;
*
err_status
=
-
7
;
if
(
*
err_status
!=
0
)
{
return
*
err_status
-
100
;
}
if
(
strcmp
(
key
,
key2
)
!=
0
)
uint64_t
key2Len
=
strnlen
(
key2
,
MAX_KEY_LENGTH
);
if
(
key2Len
==
MAX_KEY_LENGTH
)
return
;
*
err_status
=
-
8
;
if
(
str
cmp
(
key
,
key2
)
!=
0
)
if
(
str
ncmp
(
key
,
key2
,
MAX_KEY_LENGTH
)
!=
0
)
return
;
*
err_status
=
0
;
...
...
sgxd.c
View file @
bfa691b4
...
...
@@ -182,8 +182,8 @@ int main(int argc, char *argv[]) {
status
=
encrypt_key
(
eid
,
&
err_status
,
keyArray
,
encryptedKey
,
&
enc_len
);
if
(
status
!=
SGX_SUCCESS
||
enc_len
<
10
)
{
f
printf
(
stderr
,
"ECALL encrypt_key: 0x%04x
\n
"
,
status
);
if
(
status
!=
SGX_SUCCESS
)
{
gmp_
printf
(
stderr
,
"ECALL encrypt_key: 0x%04x
\n
"
,
status
);
return
1
;
}
...
...
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