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
67c016b0
Unverified
Commit
67c016b0
authored
Sep 03, 2019
by
a72d9e2bad9edfd58d6c0248c12c953b71d409d2
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixing BLS
parent
659b480a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
51 additions
and
32 deletions
+51
-32
BLSUtils.cpp
secure_enclave/BLSUtils.cpp
+15
-12
BLSUtils.h
secure_enclave/BLSUtils.h
+2
-2
secure_enclave.c
secure_enclave/secure_enclave.c
+17
-2
sgxd.c
sgxd.c
+6
-2
sgxd_common.h
sgxd_common.h
+11
-14
No files found.
secure_enclave/BLSUtils.cpp
View file @
67c016b0
...
...
@@ -3,8 +3,9 @@
//
#define GMP_WITH_SGX
#include <string.h>
#include "../sgxd_common.h"
#define MAX_SIG_LEN 1024
#include "BLSUtils.h"
#include "libff/algebra/curves/alt_bn128/alt_bn128_init.hpp"
...
...
@@ -43,16 +44,15 @@ std::string *stringFromFq(libff::alt_bn128_Fq*_fq) {
std
::
string
*
stringFromG1
(
libff
::
alt_bn128_G1
*
_g1
)
{
_g1
->
to_affine_coordinates
();
auto
sX
=
stringFromFq
(
&
_g1
->
X
);
auto
sY
=
stringFromFq
(
&
_g1
->
Y
);
auto
sZ
=
stringFromFq
(
&
_g1
->
Z
);
auto
sG1
=
new
std
::
string
(
*
sX
+
":"
+
*
sY
+
":"
+
*
sZ
);
auto
sG1
=
new
std
::
string
(
*
sX
+
":"
+
*
sY
);
delete
(
sX
);
delete
(
sY
);
delete
(
sZ
);
return
sG1
;
...
...
@@ -97,14 +97,14 @@ bool check_key(const char *_keyString) {
char
*
sign
(
const
char
*
_keyString
,
const
char
*
_hashXString
,
const
char
*
_hashYString
,
const
char
*
_hashZString
)
{
bool
sign
(
const
char
*
_keyString
,
const
char
*
_hashXString
,
const
char
*
_hashYString
,
char
sig
[
BUF_LEN
]
)
{
auto
key
=
keyFromString
(
_keyString
);
libff
::
alt_bn128_Fq
hashX
(
_hashXString
);
libff
::
alt_bn128_Fq
hashY
(
_hashYString
);
libff
::
alt_bn128_Fq
hashZ
(
_hashZString
)
;
libff
::
alt_bn128_Fq
hashZ
=
1
;
libff
::
alt_bn128_G1
hash
(
hashX
,
hashY
,
hashZ
);
...
...
@@ -112,15 +112,18 @@ char* sign(const char *_keyString, const char* _hashXString, const char* _hashYS
libff
::
alt_bn128_G1
sign
=
key
->
as_bigint
()
*
hash
;
// sign
auto
r
=
stringFromG1
(
&
sign
);
sign
.
to_affine_coordinates
(
);
char
*
result
=
(
char
*
)
calloc
(
r
->
size
()
+
1
,
1
);
auto
r
=
stringFromG1
(
&
sign
);
memset
(
sig
,
0
,
BUF_LEN
);
strncpy
(
result
,
r
->
c_str
(),
MAX_SIG
_LEN
);
strncpy
(
sig
,
r
->
c_str
(),
BUF
_LEN
);
delete
r
;
return
result
;
return
true
;
}
secure_enclave/BLSUtils.h
View file @
67c016b0
...
...
@@ -15,8 +15,8 @@
EXTERNC
bool
check_key
(
const
char
*
_keyString
);
EXTERNC
char
*
sign
(
const
char
*
_keyString
,
const
char
*
_hashXString
,
const
char
*
_hashYString
,
c
onst
char
*
_hashZStrin
g
);
EXTERNC
bool
sign
(
const
char
*
_keyString
,
const
char
*
_hashXString
,
const
char
*
_hashYString
,
c
har
*
_si
g
);
#endif //SGXD_BLSUTILS_H
secure_enclave/secure_enclave.c
View file @
67c016b0
...
...
@@ -251,8 +251,23 @@ 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
,
char
*
messageX
,
char
*
messageY
,
char
*
signature
)
{
uint32_t
enc_len
,
char
*
_hashX
,
char
*
_hashY
,
char
*
signature
)
{
char
key
[
BUF_LEN
];
char
sig
[
BUF_LEN
];
decrypt_key
(
err_status
,
err_string
,
encrypted_key
,
enc_len
,
key
);
if
(
err_status
!=
0
)
{
return
;
}
sign
(
key
,
_hashX
,
_hashY
,
sig
);
strncpy
(
signature
,
sig
,
BUF_LEN
);
}
...
...
sgxd.c
View file @
67c016b0
...
...
@@ -144,11 +144,15 @@ int main(int argc, char *argv[]) {
gmp_printf
(
"Encrypt key completed with status: %d %s
\n
"
,
err_status
,
errMsg
);
char
*
result
=
carray2Hex
(
encryptedKey
,
enc_len
);
char
result
[
BUF_LEN
];
carray2Hex
(
encryptedKey
,
enc_len
,
result
);
uint64_t
dec_len
;
uint8_t
*
bin
=
hex2carray
(
result
,
&
dec_len
);
uint8_t
bin
[
BUF_LEN
];
hex2carray
(
result
,
&
dec_len
,
bin
);
if
(
dec_len
!=
enc_len
)
{
return
1
;
...
...
sgxd_common.h
View file @
67c016b0
...
...
@@ -29,45 +29,42 @@ inline int char2int(char _input) {
char
*
carray2Hex
(
const
uint8_t
*
d
,
int
_len
)
{
char
*
hex
=
(
char
*
)
calloc
(
2
*
_len
,
1
);
void
carray2Hex
(
const
unsigned
char
*
d
,
int
_len
,
char
*
_hexArray
)
{
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
];
_hexArray
[
j
*
2
]
=
hexval
[((
d
[
j
]
>>
4
)
&
0xF
)];
_hexArray
[
j
*
2
+
1
]
=
hexval
[(
d
[
j
])
&
0x0F
];
}
return
hex
;
}
uint8_t
*
hex2carray
(
const
char
*
_hex
,
uint64_t
*
_bin_len
)
{
int
hex2carray
(
const
char
*
_hex
,
unsigned
long
long
*
_bin_len
,
unsigned
char
*
_bin
)
{
uint64_t
len
=
strlen
(
_hex
);
int
len
=
strnlen
(
_hex
,
BUF_LEN
);
if
(
len
==
0
&&
len
%
2
==
1
)
return
NULL
;
return
-
1
;
*
_bin_len
=
len
/
2
;
uint8_t
*
bin
=
(
uint8_t
*
)
calloc
(
len
/
2
,
1
);
for
(
uint64_t
i
=
0
;
i
<
len
/
2
;
i
++
)
{
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
;
return
-
1
;
}
bin
[
i
]
=
(
uint8_t
)
(
high
*
16
+
low
);
_bin
[
i
]
=
(
unsigned
char
)
(
high
*
16
+
low
);
}
return
bin
;
}
...
...
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