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
6d82dafc
Unverified
Commit
6d82dafc
authored
Sep 09, 2019
by
kladkogex
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed problem
parent
f51ca696
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
240 additions
and
255 deletions
+240
-255
BLSUtils.cpp
secure_enclave/BLSUtils.cpp
+56
-75
BLSUtils.h
secure_enclave/BLSUtils.h
+1
-1
secure_enclave.c
secure_enclave/secure_enclave.c
+183
-163
sgxwallet_common.h
sgxwallet_common.h
+0
-16
No files found.
secure_enclave/BLSUtils.cpp
View file @
6d82dafc
...
...
@@ -3,7 +3,6 @@
//
#define GMP_WITH_SGX
#include <string.h>
#include <cstdint>
#include "../sgxwallet_common.h"
...
...
@@ -15,135 +14,117 @@
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
)
{
*
err_status
=
UNKNOWN_ERROR
;
uint64_t
keyLen
=
strnlen
(
_keyString
,
MAX_KEY_LENGTH
);
// check that key is zero terminated string
libff
::
alt_bn128_Fr
*
keyFromString
(
const
char
*
_keyString
)
{
if
(
keyLen
==
MAX_KEY_LENGTH
)
{
*
err_status
=
PLAINTEXT_KEY_TOO_LONG
;
snprintf
(
err_string
,
MAX_ERR_LEN
,
"Plaintext key too long"
);
return
;
}
return
new
libff
::
alt_bn128_Fr
(
_keyString
);
}
bool
check_key
(
const
char
*
_keyString
)
{
libff
::
init_alt_bn128_params
();
if
(
_keyString
==
nullptr
)
return
false
;
if
(
_keyString
==
nullptr
)
{
*
err_status
=
NULL_KEY
;
snprintf
(
err_string
,
BUF_LEN
,
"Null key string"
);
return
;
}
std
::
string
ks
(
_keyString
);
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
;
}
}
// std::string keyString =
// "4160780231445160889237664391382223604184857153814275770598791864649971919844";
auto
key
=
keyFromString
(
ks
.
c_str
());
std
::
string
ks
(
_keyString
);
auto
s1
=
stringFromKey
(
key
);
// std::string keyString =
// "4160780231445160889237664391382223604184857153814275770598791864649971919844"
;
if
(
s1
->
compare
(
ks
)
!=
0
)
return
false
;
auto
key
=
keyFromString
(
ks
.
c_str
());
if
(
s1
->
size
()
<
10
)
return
false
;
auto
s1
=
stringFromKey
(
key
);
if
(
s1
->
size
()
>=
100
)
return
false
;
if
(
s1
->
compare
(
ks
)
!=
0
)
{
*
err_status
=
INCORRECT_STRING_CONVERSION
;
snprintf
(
err_string
,
BUF_LEN
,
"Incorrect string conversion"
);
return
;
}
return
true
;
}
*
err_status
=
0
;
}
bool
sign
(
const
char
*
_keyString
,
const
char
*
_hashXString
,
const
char
*
_hashYString
,
char
sig
[
BUF_LEN
])
{
bool
sign
(
const
char
*
_keyString
,
const
char
*
_hashXString
,
const
char
*
_hashYString
,
char
sig
[
BUF_LEN
])
{
auto
key
=
keyFromString
(
_keyString
);
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_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
libff
::
alt_bn128_G1
sign
=
key
->
as_bigint
()
*
hash
;
// sign
sign
.
to_affine_coordinates
();
sign
.
to_affine_coordinates
(
);
auto
r
=
stringFromG1
(
&
sign
);
auto
r
=
stringFromG1
(
&
sign
);
memset
(
sig
,
0
,
BUF_LEN
);
memset
(
sig
,
0
,
BUF_LEN
);
strncpy
(
sig
,
r
->
c_str
()
,
BUF_LEN
);
strncpy
(
sig
,
r
->
c_str
(),
BUF_LEN
)
;
delete
r
;
delete
r
;
return
true
;
return
true
;
}
...
...
secure_enclave/BLSUtils.h
View file @
6d82dafc
...
...
@@ -13,7 +13,7 @@
#define EXTERNC
#endif
EXTERNC
void
check_key
(
int
*
err_status
,
char
*
err_string
,
const
char
*
_keyString
);
EXTERNC
bool
check_key
(
const
char
*
_keyString
);
EXTERNC
bool
sign
(
const
char
*
_keyString
,
const
char
*
_hashXString
,
const
char
*
_hashYString
,
char
*
_sig
);
...
...
secure_enclave/secure_enclave.c
View file @
6d82dafc
This diff is collapsed.
Click to expand it.
sgxwallet_common.h
View file @
6d82dafc
...
...
@@ -27,21 +27,5 @@
#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
#define SEALED_LEN_TOO_LARGE -6
#define SGX_SEAL_DATA_FAILED -7
#define STRING_NOT_NULL_TERMINATED -8
#define ENCRYPTION_DECRYPTION_MISMATCH -9
#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