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
4394abec
Unverified
Commit
4394abec
authored
Sep 09, 2019
by
kladkogex
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Verifying key
parent
f5fe6ddd
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
90 additions
and
81 deletions
+90
-81
BLSUtils.cpp
secure_enclave/BLSUtils.cpp
+75
-56
BLSUtils.h
secure_enclave/BLSUtils.h
+1
-1
secure_enclave.c
secure_enclave/secure_enclave.c
+6
-24
sgxwallet_common.h
sgxwallet_common.h
+8
-0
No files found.
secure_enclave/BLSUtils.cpp
View file @
4394abec
...
...
@@ -3,6 +3,7 @@
//
#define GMP_WITH_SGX
#include <string.h>
#include <cstdint>
#include "../sgxwallet_common.h"
...
...
@@ -14,117 +15,135 @@
std
::
string
*
stringFromKey
(
libff
::
alt_bn128_Fr
*
_key
)
{
mpz_t
t
;
mpz_init
(
t
);
mpz_t
t
;
mpz_init
(
t
);
_key
->
as_bigint
().
to_mpz
(
t
);
_key
->
as_bigint
().
to_mpz
(
t
);
char
arr
[
mpz_sizeinbase
(
t
,
10
)
+
2
];
char
arr
[
mpz_sizeinbase
(
t
,
10
)
+
2
];
char
*
tmp
=
mpz_get_str
(
arr
,
10
,
t
);
mpz_clear
(
t
);
char
*
tmp
=
mpz_get_str
(
arr
,
10
,
t
);
mpz_clear
(
t
);
return
new
std
::
string
(
tmp
);
return
new
std
::
string
(
tmp
);
}
std
::
string
*
stringFromFq
(
libff
::
alt_bn128_Fq
*
_fq
)
{
std
::
string
*
stringFromFq
(
libff
::
alt_bn128_Fq
*
_fq
)
{
mpz_t
t
;
mpz_init
(
t
);
mpz_t
t
;
mpz_init
(
t
);
_fq
->
as_bigint
().
to_mpz
(
t
);
_fq
->
as_bigint
().
to_mpz
(
t
);
char
arr
[
mpz_sizeinbase
(
t
,
10
)
+
2
];
char
arr
[
mpz_sizeinbase
(
t
,
10
)
+
2
];
char
*
tmp
=
mpz_get_str
(
arr
,
10
,
t
);
mpz_clear
(
t
);
char
*
tmp
=
mpz_get_str
(
arr
,
10
,
t
);
mpz_clear
(
t
);
return
new
std
::
string
(
tmp
);
return
new
std
::
string
(
tmp
);
}
std
::
string
*
stringFromG1
(
libff
::
alt_bn128_G1
*
_g1
)
{
_g1
->
to_affine_coordinates
();
_g1
->
to_affine_coordinates
();
auto
sX
=
stringFromFq
(
&
_g1
->
X
);
auto
sY
=
stringFromFq
(
&
_g1
->
Y
);
auto
sX
=
stringFromFq
(
&
_g1
->
X
);
auto
sY
=
stringFromFq
(
&
_g1
->
Y
);
auto
sG1
=
new
std
::
string
(
*
sX
+
":"
+
*
sY
);
auto
sG1
=
new
std
::
string
(
*
sX
+
":"
+
*
sY
);
delete
(
sX
);
delete
(
sY
);
delete
(
sX
);
delete
(
sY
);
return
sG1
;
return
sG1
;
}
libff
::
alt_bn128_Fr
*
keyFromString
(
const
char
*
_keyString
)
{
return
new
libff
::
alt_bn128_Fr
(
_keyString
);
}
void
check_key
(
int
*
err_status
,
char
*
err_string
,
const
char
*
_keyString
)
{
libff
::
alt_bn128_Fr
*
keyFromString
(
const
char
*
_keyString
)
{
*
err_status
=
UNKNOWN_ERROR
;
return
new
libff
::
alt_bn128_Fr
(
_keyString
);
}
uint64_t
keyLen
=
strnlen
(
_keyString
,
MAX_KEY_LENGTH
);
bool
check_key
(
const
char
*
_keyString
)
{
// check that key is zero terminated string
libff
::
init_alt_bn128_params
();
if
(
keyLen
==
MAX_KEY_LENGTH
)
{
*
err_status
=
PLAINTEXT_KEY_TOO_LONG
;
snprintf
(
err_string
,
MAX_ERR_LEN
,
"Plaintext key too long"
);
return
;
}
if
(
_keyString
==
nullptr
)
return
false
;
std
::
string
ks
(
_keyString
);
// std::string keyString =
// "4160780231445160889237664391382223604184857153814275770598791864649971919844";
auto
key
=
keyFromString
(
ks
.
c_str
());
if
(
_keyString
==
nullptr
)
{
*
err_status
=
NULL_KEY
;
snprintf
(
err_string
,
BUF_LEN
,
"Null key string"
);
return
;
}
auto
s1
=
stringFromKey
(
key
);
for
(
int
i
=
keyLen
;
i
<
MAX_KEY_LENGTH
;
i
++
)
{
if
(
_keyString
[
i
]
!=
0
)
{
*
err_status
=
UNPADDED_KEY
;
snprintf
(
err_string
,
BUF_LEN
,
"Unpadded key passed to wrap"
);
return
;
}
}
if
(
s1
->
compare
(
ks
)
!=
0
)
return
false
;
if
(
s1
->
size
()
<
10
)
return
false
;
std
::
string
ks
(
_keyString
);
if
(
s1
->
size
()
>=
100
)
return
false
;
// std::string keyString =
// "4160780231445160889237664391382223604184857153814275770598791864649971919844"
;
return
true
;
}
auto
key
=
keyFromString
(
ks
.
c_str
());
auto
s1
=
stringFromKey
(
key
);
if
(
s1
->
compare
(
ks
)
!=
0
)
{
*
err_status
=
INCORRECT_STRING_CONVERSION
;
snprintf
(
err_string
,
BUF_LEN
,
"Incorrect string conversion"
);
return
;
}
*
err_status
=
0
;
}
bool
sign
(
const
char
*
_keyString
,
const
char
*
_hashXString
,
const
char
*
_hashYString
,
char
sig
[
BUF_LEN
])
{
auto
key
=
keyFromString
(
_keyString
);
bool
sign
(
const
char
*
_keyString
,
const
char
*
_hashXString
,
const
char
*
_hashYString
,
char
sig
[
BUF_LEN
])
{
libff
::
alt_bn128_Fq
hashX
(
_hashXString
);
libff
::
alt_bn128_Fq
hashY
(
_hashYString
);
libff
::
alt_bn128_Fq
hashZ
=
1
;
auto
key
=
keyFromString
(
_keyString
);
libff
::
alt_bn128_Fq
hashX
(
_hashXString
);
libff
::
alt_bn128_Fq
hashY
(
_hashYString
);
libff
::
alt_bn128_Fq
hashZ
=
1
;
libff
::
alt_bn128_G1
hash
(
hashX
,
hashY
,
hashZ
);
libff
::
alt_bn128_G1
hash
(
hashX
,
hashY
,
hashZ
);
libff
::
alt_bn128_G1
sign
=
key
->
as_bigint
()
*
hash
;
// sign
sign
.
to_affine_coordinates
();
libff
::
alt_bn128_G1
sign
=
key
->
as_bigint
()
*
hash
;
// sign
auto
r
=
stringFromG1
(
&
sign
);
sign
.
to_affine_coordinates
(
);
memset
(
sig
,
0
,
BUF_LEN
);
auto
r
=
stringFromG1
(
&
sign
);
strncpy
(
sig
,
r
->
c_str
()
,
BUF_LEN
);
memset
(
sig
,
0
,
BUF_LEN
);
delete
r
;
strncpy
(
sig
,
r
->
c_str
(),
BUF_LEN
)
;
return
true
;
delete
r
;
return
true
;
}
...
...
secure_enclave/BLSUtils.h
View file @
4394abec
...
...
@@ -13,7 +13,7 @@
#define EXTERNC
#endif
EXTERNC
bool
check_key
(
const
char
*
_keyString
);
EXTERNC
void
check_key
(
int
*
err_status
,
char
*
err_string
,
const
char
*
_keyString
);
EXTERNC
bool
sign
(
const
char
*
_keyString
,
const
char
*
_hashXString
,
const
char
*
_hashYString
,
char
*
_sig
);
...
...
secure_enclave/secure_enclave.c
View file @
4394abec
...
...
@@ -50,6 +50,8 @@ 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
);
...
...
@@ -120,32 +122,12 @@ void generate_ecdsa_key(int *err_status, char *err_string,
void
encrypt_key
(
int
*
err_status
,
char
*
err_string
,
char
*
key
,
uint8_t
*
encrypted_key
,
uint32_t
*
enc_len
)
{
*
err_status
=
-
1
;
uint64_t
keyLen
=
strnlen
(
key
,
MAX_KEY_LENGTH
);
*
err_status
=
UNKNOWN_ERROR
;
// check that key is zero terminated string
check_key
(
err_status
,
err_string
,
key
);
if
(
keyLen
==
MAX_KEY_LENGTH
)
{
snprintf
(
err_string
,
MAX_ERR_LEN
,
"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
)
{
snprintf
(
err_string
,
BUF_LEN
,
"Unpadded key"
);
return
;
}
}
*
err_status
=
-
3
;
if
(
!
check_key
(
key
))
{
snprintf
(
err_string
,
BUF_LEN
,
"check_key failed"
);
if
(
*
err_status
!=
0
)
{
snprintf
(
err_string
+
strlen
(
err_string
),
BUF_LEN
,
":check_key failed"
);
return
;
}
...
...
sgxwallet_common.h
View file @
4394abec
...
...
@@ -27,5 +27,13 @@
#define ADD_ENTROPY_SIZE 32
#define UNKNOWN_ERROR -1
#define PLAINTEXT_KEY_TOO_LONG -2
#define UNPADDED_KEY -3
#define NULL_KEY -4
#define INCORRECT_STRING_CONVERSION -5
#endif //SGXWALLET_SGXWALLET_COMMON_H
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