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
a7e54aa2
Unverified
Commit
a7e54aa2
authored
Aug 27, 2019
by
a72d9e2bad9edfd58d6c0248c12c953b71d409d2
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added gmp
parent
f3fe85cf
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
52 additions
and
46 deletions
+52
-46
BLSUtils.cpp
secure_enclave/BLSUtils.cpp
+26
-37
BLSUtils.h
secure_enclave/BLSUtils.h
+1
-1
secure_enclave.c
secure_enclave/secure_enclave.c
+17
-2
secure_enclave.edl
secure_enclave/secure_enclave.edl
+2
-2
sgxd.c
sgxd.c
+6
-4
No files found.
secure_enclave/BLSUtils.cpp
View file @
a7e54aa2
...
...
@@ -3,65 +3,54 @@
//
#define GMP_WITH_SGX
#include "libff/algebra/curves/alt_bn128/alt_bn128_pp.hpp"
#include "libff/algebra/curves/alt_bn128/alt_bn128_init.hpp"
#include "BLSUtils.h"
#include "libff/algebra/curves/alt_bn128/alt_bn128_init.hpp"
#include "libff/algebra/curves/alt_bn128/alt_bn128_pp.hpp"
std
::
string
*
stringFromKey
(
libff
::
alt_bn128_Fr
*
_key
)
{
std
::
string
*
stringFromKey
(
libff
::
alt_bn128_Fr
*
_key
)
{
mpz_t
t
;
mpz_init
(
t
);
_key
->
as_bigint
().
to_mpz
(
t
);
mpz_t
t
;
mpz_init
(
t
);
char
arr
[
mpz_sizeinbase
(
t
,
10
)
+
2
]
;
_key
->
as_bigint
().
to_mpz
(
t
)
;
char
*
tmp
=
mpz_get_str
(
arr
,
10
,
t
);
mpz_clear
(
t
);
char
arr
[
mpz_sizeinbase
(
t
,
10
)
+
2
];
return
new
std
::
string
(
tmp
);
char
*
tmp
=
mpz_get_str
(
arr
,
10
,
t
);
mpz_clear
(
t
);
return
new
std
::
string
(
tmp
);
}
libff
::
alt_bn128_Fr
*
keyFromString
(
std
::
string
&
_keyString
)
{
libff
::
alt_bn128_Fr
*
keyFromString
(
std
::
string
&
_keyString
)
{
return
new
libff
::
alt_bn128_Fr
(
_keyString
.
c_str
());
return
new
libff
::
alt_bn128_Fr
(
_keyString
.
c_str
());
}
bool
check_key
(
const
char
*
_keyString
)
{
libff
::
init_alt_bn128_params
();
if
(
_keyString
==
nullptr
)
return
false
;
void
import_key
(
const
char
*
_keyString
,
char
*
encryptedKey
,
uint64_t
bufLen
)
{
libff
::
init_alt_bn128_params
();
if
(
encryptedKey
==
nullptr
&&
bufLen
<
100
)
throw
std
::
exception
();
if
(
_keyString
==
nullptr
)
throw
std
::
exception
();
std
::
string
ks
(
_keyString
);
std
::
string
ks
(
_keyString
);
// std::string keyString =
// "4160780231445160889237664391382223604184857153814275770598791864649971919844";
// std::string keyString = "4160780231445160889237664391382223604184857153814275770598791864649971919844"
;
auto
key
=
keyFromString
(
ks
)
;
auto
key
=
keyFromString
(
ks
);
auto
s1
=
stringFromKey
(
key
);
auto
s1
=
stringFromKey
(
key
);
if
(
s1
->
compare
(
ks
)
!=
0
)
throw
std
::
exception
();
if
(
s1
->
compare
(
ks
)
!=
0
)
return
false
;
if
(
s1
->
size
()
<
10
)
throw
std
::
exception
();
return
false
;
if
(
s1
->
size
()
>=
100
)
throw
std
::
exception
();
strncpy
(
encryptedKey
,
s1
->
c_str
(),
100
);
return
false
;
return
true
;
}
secure_enclave/BLSUtils.h
View file @
a7e54aa2
...
...
@@ -13,7 +13,7 @@
#define EXTERNC
#endif
EXTERNC
void
import_key
(
const
char
*
_keyString
,
char
*
encryptedKey
,
uint64_t
bufLen
);
EXTERNC
bool
check_key
(
const
char
*
_keyString
);
#endif //SGXD_BLSUTILS_H
secure_enclave/secure_enclave.c
View file @
a7e54aa2
...
...
@@ -115,10 +115,25 @@ void encrypt_key(int *err_status, char* key, char* encrypted_key) {
*
err_status
=
-
1
;
if
(
strnlen
(
key
)
==
100
)
if
(
strnlen
(
key
)
>=
128
)
return
;
import_key
(
key
,
encrypted_key
,
100
);
*
err_status
=
-
3
;
check_key
(
key
);
uint32_t
sealedLen
=
sgx_calc_sealed_data_size
(
0
,
strlen
(
key
)
+
1
);
*
err_status
=
-
3
;
if
(
sealedLen
>
1024
)
{
return
;
}
*
err_status
=
-
4
;
if
(
sgx_seal_data
(
0
,
NULL
,
strlen
(
key
)
+
1
,
key
,
sealedLen
,
encrypted_key
)
!=
SGX_SUCCESS
)
return
;
*
err_status
=
0
;
}
...
...
secure_enclave/secure_enclave.edl
View file @
a7e54aa2
...
...
@@ -23,8 +23,8 @@ enclave {
public void encrypt_key (
[user_check] int *err_status,
[in, count = 1
00
] char* key,
[out, count = 10
0
] char* encrypted_key);
[in, count = 1
28
] char* key,
[out, count = 10
24
] char* encrypted_key);
};
...
...
sgxd.c
View file @
a7e54aa2
...
...
@@ -117,17 +117,19 @@ int main (int argc, char *argv[])
const
char
*
key
=
"4160780231445160889237664391382223604184857153814275770598791864649971919844"
;
char
keyArray
[
1
00
];
char
keyArray
[
1
28
];
char
encryptedKey
[
10
0
];
char
encryptedKey
[
10
24
];
strncpy
(
keyArray
,
key
,
1
00
);
strncpy
(
keyArray
,
key
,
1
28
);
int
err_status
=
-
2
;
status
=
encrypt_key
(
eid
,
&
err_status
,
keyArray
,
encryptedKey
);
if
(
status
!=
SGX_SUCCESS
)
{
fprintf
(
stderr
,
"ECALL encrypt_key: 0x%04x
\n
"
,
status
);
return
1
;
...
...
@@ -136,7 +138,7 @@ int main (int argc, char *argv[])
gmp_printf
(
"Encrypt key completed with status: %d
\n
"
,
err_status
);
gmp_printf
(
"Result: %s
\n
"
,
encryptedKey
);
//
gmp_printf("Result: %s \n", encryptedKey);
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