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
d3e8b548
Unverified
Commit
d3e8b548
authored
Aug 28, 2019
by
a72d9e2bad9edfd58d6c0248c12c953b71d409d2
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added gmp
parent
5fba6748
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
79 additions
and
92 deletions
+79
-92
sgxd.c
sgxd.c
+79
-92
No files found.
sgxd.c
View file @
d3e8b548
...
@@ -31,24 +31,22 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
...
@@ -31,24 +31,22 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
*/
#include <sgx_urts.h>
#include "create_enclave.h"
#include "secure_enclave_u.h"
#include "sgx_detect.h"
#include <gmp.h>
#include <gmp.h>
#include <sgx_urts.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <unistd.h>
#include <unistd.h>
#include "sgx_detect.h"
#include "secure_enclave_u.h"
#include "create_enclave.h"
#define ENCLAVE_NAME "secure_enclave.signed.so"
#define ENCLAVE_NAME "secure_enclave.signed.so"
unsigned
char
*
carray2Hex
(
const
uint8_t
*
d
,
int
_len
)
{
unsigned
char
*
hex
=
malloc
(
2
*
_len
);
static
char
hexval
[
16
]
=
{
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
unsigned
char
*
carray2Hex
(
const
uint8_t
*
d
,
int
_len
)
{
'8'
,
'9'
,
'a'
,
'b'
,
'c'
,
'd'
,
'e'
,
'f'
};
unsigned
char
*
hex
=
malloc
(
2
*
_len
);
static
char
hexval
[
16
]
=
{
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
,
'a'
,
'b'
,
'c'
,
'd'
,
'e'
,
'f'
};
for
(
int
j
=
0
;
j
<
_len
;
j
++
)
{
for
(
int
j
=
0
;
j
<
_len
;
j
++
)
{
hex
[
j
*
2
]
=
hexval
[((
d
[
j
]
>>
4
)
&
0xF
)];
hex
[
j
*
2
]
=
hexval
[((
d
[
j
]
>>
4
)
&
0xF
)];
...
@@ -58,123 +56,112 @@ unsigned char* carray2Hex(const uint8_t *d, int _len) {
...
@@ -58,123 +56,112 @@ unsigned char* carray2Hex(const uint8_t *d, int _len) {
return
hex
;
return
hex
;
}
}
int
char2int
(
char
_input
)
{
int
char2int
(
char
_input
)
{
if
(
_input
>=
'0'
&&
_input
<=
'9'
)
if
(
_input
>=
'0'
&&
_input
<=
'9'
)
return
_input
-
'0'
;
return
_input
-
'0'
;
if
if
(
_input
>=
'A'
&&
_input
<=
'F'
)
(
_input
>=
'A'
&&
_input
<=
'F'
)
return
_input
-
'A'
+
10
;
return
_input
-
'A'
+
10
;
if
(
_input
>=
'a'
&&
_input
<=
'f'
)
if
(
_input
>=
'a'
&&
_input
<=
'f'
)
return
_input
-
'a'
+
10
;
return
_input
-
'a'
+
10
;
return
-
1
;
return
-
1
;
}
}
void
usage
()
{
fprintf
(
stderr
,
"usage: sgxd
\n
"
);
void
usage
()
{
exit
(
1
);
fprintf
(
stderr
,
"usage: sgxd
\n
"
);
exit
(
1
);
}
}
int
main
(
int
argc
,
char
*
argv
[])
sgx_launch_token_t
token
=
{
0
};
{
sgx_enclave_id_t
eid
;
sgx_launch_token_t
token
=
{
0
};
sgx_status_t
status
;
sgx_enclave_id_t
eid
=
0
;
int
updated
;
sgx_status_t
status
;
int
updated
=
0
;
unsigned
long
support
;
int
opt
;
while
(
(
opt
=
getopt
(
argc
,
argv
,
"h"
))
!=
-
1
)
{
void
init_enclave
()
{
switch
(
opt
)
{
case
'h'
:
default:
usage
();
}
}
argc
-=
optind
;
eid
=
0
;
argv
+=
optind
;
updated
=
0
;
if
(
argc
!=
0
)
usage
();
unsigned
long
support
;
/*
digits= strtoull(argv[0], NULL, 10);
if ( digits == 0 ) {
fprintf(stderr, "invalid digit count\n");
return 1;
}
*/
#ifndef SGX_HW_SIM
#ifndef SGX_HW_SIM
support
=
get_sgx_support
();
support
=
get_sgx_support
();
if
(
!
SGX_OK
(
support
)
)
{
if
(
!
SGX_OK
(
support
)
)
{
sgx_support_perror
(
support
);
sgx_support_perror
(
support
);
return
1
;
exit
(
1
)
;
}
}
#endif
#endif
status
=
sgx_create_enclave_search
(
ENCLAVE_NAME
,
SGX_DEBUG_FLAG
,
status
=
sgx_create_enclave_search
(
ENCLAVE_NAME
,
SGX_DEBUG_FLAG
,
&
token
,
&
token
,
&
updated
,
&
eid
,
0
);
&
updated
,
&
eid
,
0
);
if
(
status
!=
SGX_SUCCESS
)
{
if
(
status
==
SGX_ERROR_ENCLAVE_FILE_ACCESS
)
{
fprintf
(
stderr
,
"sgx_create_enclave: %s: file not found
\n
"
,
ENCLAVE_NAME
);
fprintf
(
stderr
,
"Did you forget to set LD_LIBRARY_PATH?
\n
"
);
}
else
{
fprintf
(
stderr
,
"%s: 0x%04x
\n
"
,
ENCLAVE_NAME
,
status
);
}
exit
(
1
);
}
if
(
status
!=
SGX_SUCCESS
)
{
fprintf
(
stderr
,
"Enclave launched
\n
"
);
if
(
status
==
SGX_ERROR_ENCLAVE_FILE_ACCESS
)
{
fprintf
(
stderr
,
"sgx_create_enclave: %s: file not found
\n
"
,
ENCLAVE_NAME
);
fprintf
(
stderr
,
"Did you forget to set LD_LIBRARY_PATH?
\n
"
);
}
else
{
fprintf
(
stderr
,
"%s: 0x%04x
\n
"
,
ENCLAVE_NAME
,
status
);
}
return
1
;
}
fprintf
(
stderr
,
"Enclave launched
\n
"
);
status
=
tgmp_init
(
eid
);
if
(
status
!=
SGX_SUCCESS
)
{
fprintf
(
stderr
,
"ECALL tgmp_init: 0x%04x
\n
"
,
status
);
exit
(
1
);
}
status
=
tgmp_init
(
eid
);
fprintf
(
stderr
,
"libtgmp initialized
\n
"
);
if
(
status
!=
SGX_SUCCESS
)
{
}
fprintf
(
stderr
,
"ECALL tgmp_init: 0x%04x
\n
"
,
status
);
return
1
;
}
fprintf
(
stderr
,
"libtgmp initialized
\n
"
);
int
main
(
int
argc
,
char
*
argv
[])
{
int
opt
;
const
char
*
key
=
"4160780231445160889237664391382223604184857153814275770598791864649971919844"
;
while
((
opt
=
getopt
(
argc
,
argv
,
"h"
))
!=
-
1
)
{
switch
(
opt
)
{
case
'h'
:
default:
usage
();
}
}
char
keyArray
[
128
];
argc
-=
optind
;
argv
+=
optind
;
unsigned
char
encryptedKey
[
1024
];
if
(
argc
!=
0
)
usage
();
strncpy
(
keyArray
,
key
,
128
);
init_enclave
(
);
int
err_status
=
-
2
;
const
char
*
key
=
"4160780231445160889237664391382223604184857153814275770598"
"791864649971919844"
;
int
enc_len
=
-
1
;
char
keyArray
[
128
]
;
unsigned
char
encryptedKey
[
1024
];
status
=
encrypt_key
(
eid
,
&
err_status
,
keyArray
,
encryptedKey
,
&
enc_len
);
strncpy
(
keyArray
,
key
,
128
);
int
err_status
=
0
;
if
(
status
!=
SGX_SUCCESS
||
enc_len
<
10
)
{
int
enc_len
=
0
;
fprintf
(
stderr
,
"ECALL encrypt_key: 0x%04x
\n
"
,
status
);
return
1
;
}
status
=
encrypt_key
(
eid
,
&
err_status
,
keyArray
,
encryptedKey
,
&
enc_len
);
gmp_printf
(
"Encrypt key completed with status: %d
\n
"
,
err_status
);
if
(
status
!=
SGX_SUCCESS
||
enc_len
<
10
)
{
fprintf
(
stderr
,
"ECALL encrypt_key: 0x%04x
\n
"
,
status
);
return
1
;
}
unsigned
char
*
result
=
carray2Hex
(
encryptedKey
,
enc_len
);
gmp_printf
(
"Encrypt key completed with status: %d
\n
"
,
err_status
);
gmp_printf
(
"Result: %s"
,
result
);
unsigned
char
*
result
=
carray2Hex
(
encryptedKey
,
enc_len
);
gmp_printf
(
"
\n
Length: %d
\n
"
,
enc_len
);
gmp_printf
(
"Result: %s"
,
result
);
gmp_printf
(
"
\n
Length: %d
\n
"
,
enc_len
);
return
0
;
return
0
;
}
}
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