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
b4b0013a
Unverified
Commit
b4b0013a
authored
Sep 03, 2019
by
a72d9e2bad9edfd58d6c0248c12c953b71d409d2
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Working on BLSSigshare
parent
2468b215
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
81 additions
and
193 deletions
+81
-193
CMakeLists.txt
CMakeLists.txt
+1
-1
Makefile.am
Makefile.am
+1
-1
secure_enclave.c
secure_enclave/secure_enclave.c
+3
-9
secure_enclave.edl
secure_enclave/secure_enclave.edl
+3
-2
sgxd.c
sgxd.c
+1
-48
sgxd_common.h
sgxd_common.h
+72
-0
sgxgmpmath.c
sgxgmpmath.c
+0
-132
No files found.
CMakeLists.txt
View file @
b4b0013a
...
...
@@ -115,4 +115,4 @@ add_custom_target(sgxd COMMAND make all
sgx_stub.h
sgx_tgmp.h
sgxd.c
sgxgmpmath.c
)
)
Makefile.am
View file @
b4b0013a
...
...
@@ -87,5 +87,5 @@ secure_enclave.signed.so: secure_enclave/secure_enclave.signed.so
## Use the variables, not the actual library names to ensure these
## targets work on simulation builds.
sgxd_LDADD
=
-l
$(SGX_URTS_LIB)
-Lleveldb
/build
-LlibBLS
/build
-LlibBLS
/build/libff/libff
-l
:libbls.a
-l
:libleveldb.a
-l
:libff.a
-lgmp
-ldl
-l
:libsgx_capable.a
-l
:libsgx_tprotected_fs.a
-lpthread
-ljsonrpccpp-common
-ljsonrpccpp-server
-ljsonrpccpp-stub
-lprocps
sgxd_LDADD
=
-l
$(SGX_URTS_LIB)
-Lleveldb
/build
-LlibBLS
/build
-LlibBLS
/build/libff/libff
-l
:libbls.a
-l
:libleveldb.a
-l
:libff.a
-lgmp
-ldl
-l
:libsgx_capable.a
-l
:libsgx_tprotected_fs.a
-lpthread
-ljsonrpccpp-common
-ljsonrpccpp-server
-ljsonrpccpp-stub
-lprocps
secure_enclave/secure_enclave.c
View file @
b4b0013a
...
...
@@ -48,14 +48,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <openssl/rand.h>
#include "tSgxSSL_api.h"
#define MAX_KEY_LENGTH 128
#define MAX_ENCRYPTED_KEY_LENGTH 1024
#define MAX_SIG_LEN 1024
#define MAX_ERR_LEN 1024
#define ADD_ENTROPY_SIZE 32
#include "../sgxd_common.h"
void
*
(
*
gmp_realloc_func
)(
void
*
,
size_t
,
size_t
);
void
*
(
*
oc_realloc_func
)(
void
*
,
size_t
,
size_t
);
...
...
@@ -258,7 +251,8 @@ 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
,
uint8_t
*
message
,
char
*
signature
)
{
uint32_t
enc_len
,
char
*
messageX
,
char
*
messageY
,
char
*
signature
)
{
}
...
...
secure_enclave/secure_enclave.edl
View file @
b4b0013a
...
...
@@ -43,9 +43,10 @@ enclave {
public void bls_sign_message (
[user_check] int *err_status,
[out, count = 1024] char* err_string,
[in, count = 1024] u
nsigned char
* encrypted_key,
[in, count = 1024] u
int8_t
* encrypted_key,
uint32_t enc_len,
[in, count = 16] uint8_t* hash,
[in, count = 128] char* hashX ,
[in, count = 128] char* hashY ,
[out, count = 1024] char* signature);
public void ecdsa_sign_message (
...
...
sgxd.c
View file @
b4b0013a
...
...
@@ -40,62 +40,15 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <stdlib.h>
#include <unistd.h>
#include "sgxd_common.h"
#include "BLSCrypto.h"
#define ENCLAVE_NAME "secure_enclave.signed.so"
int
char2int
(
char
_input
)
{
if
(
_input
>=
'0'
&&
_input
<=
'9'
)
return
_input
-
'0'
;
if
(
_input
>=
'A'
&&
_input
<=
'F'
)
return
_input
-
'A'
+
10
;
if
(
_input
>=
'a'
&&
_input
<=
'f'
)
return
_input
-
'a'
+
10
;
return
-
1
;
}
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'
,
'8'
,
'9'
,
'a'
,
'b'
,
'c'
,
'd'
,
'e'
,
'f'
};
for
(
int
j
=
0
;
j
<
_len
;
j
++
)
{
hex
[
j
*
2
]
=
hexval
[((
d
[
j
]
>>
4
)
&
0xF
)];
hex
[
j
*
2
+
1
]
=
hexval
[(
d
[
j
])
&
0x0F
];
}
return
hex
;
}
uint8_t
*
hex2carray
(
unsigned
char
*
_hex
,
uint64_t
*
_bin_len
)
{
uint64_t
len
=
strlen
((
char
*
)
_hex
);
if
(
len
==
0
&&
len
%
2
==
1
)
return
NULL
;
*
_bin_len
=
len
/
2
;
uint8_t
*
bin
=
malloc
(
len
/
2
);
for
(
int
i
=
0
;
i
<
len
/
2
;
i
++
)
{
int
high
=
char2int
((
char
)
_hex
[
i
*
2
]);
int
low
=
char2int
((
char
)
_hex
[
i
*
2
+
1
]);
if
(
high
<
0
||
low
<
0
)
{
return
NULL
;
}
bin
[
i
]
=
(
uint8_t
)
(
high
*
16
+
low
);
}
return
bin
;
}
...
...
sgxd_common.h
0 → 100644
View file @
b4b0013a
//
// Created by kladko on 9/3/19.
//
#ifndef SGXD_SGXD_COMMON_H
#define SGXD_SGXD_COMMON_H
#define MAX_KEY_LENGTH 128
#define MAX_COMPONENT_LENGTH 80
#define MAX_COMPONENT_HEX_LENGTH MAX_COMPONENT_LENGTH * 2
#define MAX_ENCRYPTED_KEY_LENGTH 1024
#define MAX_SIG_LEN 1024
#define MAX_ERR_LEN 1024
#define SHA_256_LEN 32
#define ADD_ENTROPY_SIZE 32
inline
int
char2int
(
char
_input
)
{
if
(
_input
>=
'0'
&&
_input
<=
'9'
)
return
_input
-
'0'
;
if
(
_input
>=
'A'
&&
_input
<=
'F'
)
return
_input
-
'A'
+
10
;
if
(
_input
>=
'a'
&&
_input
<=
'f'
)
return
_input
-
'a'
+
10
;
return
-
1
;
}
inline
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'
,
'8'
,
'9'
,
'a'
,
'b'
,
'c'
,
'd'
,
'e'
,
'f'
};
for
(
int
j
=
0
;
j
<
_len
;
j
++
)
{
hex
[
j
*
2
]
=
hexval
[((
d
[
j
]
>>
4
)
&
0xF
)];
hex
[
j
*
2
+
1
]
=
hexval
[(
d
[
j
])
&
0x0F
];
}
return
hex
;
}
inline
uint8_t
*
hex2carray
(
unsigned
char
*
_hex
,
uint64_t
*
_bin_len
)
{
uint64_t
len
=
strlen
((
char
*
)
_hex
);
if
(
len
==
0
&&
len
%
2
==
1
)
return
NULL
;
*
_bin_len
=
len
/
2
;
uint8_t
*
bin
=
malloc
(
len
/
2
);
for
(
int
i
=
0
;
i
<
len
/
2
;
i
++
)
{
int
high
=
char2int
((
char
)
_hex
[
i
*
2
]);
int
low
=
char2int
((
char
)
_hex
[
i
*
2
+
1
]);
if
(
high
<
0
||
low
<
0
)
{
return
NULL
;
}
bin
[
i
]
=
(
uint8_t
)
(
high
*
16
+
low
);
}
return
bin
;
}
#endif //SGXD_SGXD_COMMON_H
sgxgmpmath.c
deleted
100644 → 0
View file @
2468b215
/*
Copyright 2018 Intel Corporation
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <sgx_urts.h>
#include <gmp.h>
#include <stdio.h>
#include <stdlib.h>
#include "secure_enclave_u.h"
#include "create_enclave.h"
#include "sgx_detect.h"
#define ENCLAVE_NAME "secure_enclave.signed.so"
int
main
(
int
argc
,
char
*
argv
[])
{
sgx_launch_token_t
token
=
{
0
};
sgx_enclave_id_t
eid
=
0
;
sgx_status_t
status
;
int
updated
=
0
;
unsigned
long
support
;
mpz_t
a
,
b
,
c
;
mpf_t
fa
,
fb
,
fc
;
if
(
argc
!=
3
)
{
fprintf
(
stderr
,
"usage: sgxgmptest num1 num2
\n
"
);
return
1
;
}
mpz_init_set_str
(
a
,
argv
[
1
],
10
);
/* Assume base 10 */
mpz_init_set_str
(
b
,
argv
[
2
],
10
);
/* Assume base 10 */
mpz_init
(
c
);
mpf_inits
(
fa
,
fb
,
fc
,
NULL
);
mpf_set_z
(
fa
,
a
);
mpf_set_z
(
fb
,
b
);
#ifndef SGX_HW_SIM
support
=
get_sgx_support
();
if
(
!
SGX_OK
(
support
)
)
{
sgx_support_perror
(
support
);
return
1
;
}
#endif
status
=
sgx_create_enclave_search
(
ENCLAVE_NAME
,
SGX_DEBUG_FLAG
,
&
token
,
&
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
);
}
return
1
;
}
fprintf
(
stderr
,
"Enclave launched
\n
"
);
status
=
tgmp_init
(
eid
);
if
(
status
!=
SGX_SUCCESS
)
{
fprintf
(
stderr
,
"ECALL test_mpz_add: 0x%04x
\n
"
,
status
);
return
1
;
}
fprintf
(
stderr
,
"libtgmp initialized
\n
"
);
status
=
e_mpz_add
(
eid
,
&
c
,
&
a
,
&
b
);
if
(
status
!=
SGX_SUCCESS
)
{
fprintf
(
stderr
,
"ECALL test_mpz_add_ui: 0x%04x
\n
"
,
status
);
return
1
;
}
gmp_printf
(
"iadd : %Zd + %Zd = %Zd
\n\n
"
,
a
,
b
,
c
);
status
=
e_mpz_mul
(
eid
,
&
c
,
&
a
,
&
b
);
if
(
status
!=
SGX_SUCCESS
)
{
fprintf
(
stderr
,
"ECALL test_mpz_mul: 0x%04x
\n
"
,
status
);
return
1
;
}
gmp_printf
(
"imul : %Zd * %Zd = %Zd
\n\n
"
,
a
,
b
,
c
);
status
=
e_mpz_div
(
eid
,
&
c
,
&
a
,
&
b
);
if
(
status
!=
SGX_SUCCESS
)
{
fprintf
(
stderr
,
"ECALL test_mpz_div: 0x%04x
\n
"
,
status
);
return
1
;
}
gmp_printf
(
"idiv : %Zd / %Zd = %Zd
\n\n
"
,
a
,
b
,
c
);
status
=
e_mpf_div
(
eid
,
&
fc
,
&
fa
,
&
fb
);
if
(
status
!=
SGX_SUCCESS
)
{
fprintf
(
stderr
,
"ECALL test_mpz_div: 0x%04x
\n
"
,
status
);
return
1
;
}
gmp_printf
(
"fdiv : %Zd / %Zd = %.12Ff
\n\n
"
,
a
,
b
,
fc
);
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