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
dd4e9d36
Unverified
Commit
dd4e9d36
authored
Aug 15, 2020
by
kladko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SKALE-3067-cleanup
parent
8b7bc690
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
73 additions
and
34 deletions
+73
-34
DHDkg.c
secure_enclave/DHDkg.c
+5
-1
DKGUtils.cpp
secure_enclave/DKGUtils.cpp
+47
-29
DKGUtils.h
secure_enclave/DKGUtils.h
+0
-2
DomainParameters.c
secure_enclave/DomainParameters.c
+5
-1
EnclaveCommon.h
secure_enclave/EnclaveCommon.h
+6
-0
Point.c
secure_enclave/Point.c
+5
-1
Signature.c
secure_enclave/Signature.c
+5
-0
No files found.
secure_enclave/DHDkg.c
View file @
dd4e9d36
...
...
@@ -42,15 +42,19 @@
#include "EnclaveCommon.h"
#include <string.h>
int
gen_session_key
(
char
*
skey_str
,
char
*
pb_keyB
,
char
*
common_key
)
{
int
ret
=
-
1
;
LOG_INFO
(
__FUNCTION__
);
SAFE_CHAR_BUF
(
pb_keyB_x
,
65
);
SAFE_CHAR_BUF
(
pb_keyB_y
,
65
);
mpz_t
skey
;
mpz_init
(
skey
);
point
pub_keyB
=
point_init
();
...
...
secure_enclave/DKGUtils.cpp
View file @
dd4e9d36
...
...
@@ -144,10 +144,14 @@ string ConvertG2ToString(const libff::alt_bn128_G2 &elem, int base = 10, const s
vector
<
libff
::
alt_bn128_Fr
>
SplitStringToFr
(
const
char
*
coeffs
,
const
char
symbol
)
{
vector
<
libff
::
alt_bn128_Fr
>
result
;
string
str
(
coeffs
);
string
delim
;
CHECK_ARG_CLEAN
(
coeffs
);
try
{
delim
.
push_back
(
symbol
);
...
...
@@ -183,6 +187,8 @@ int gen_dkg_poly(char *secret, unsigned _t) {
int
status
=
1
;
string
result
;
CHECK_ARG_CLEAN
(
secret
);
try
{
for
(
size_t
i
=
0
;
i
<
_t
;
++
i
)
{
libff
::
alt_bn128_Fr
cur_coef
=
libff
::
alt_bn128_Fr
::
random_element
();
...
...
@@ -247,6 +253,14 @@ void calc_secret_shares(const char *decrypted_coeffs,
string
result
;
char
symbol
=
':'
;
CHECK_ARG_CLEAN
(
decrypted_coeffs
);
CHECK_ARG_CLEAN
(
secret_shares
);
CHECK_ARG_CLEAN
(
_n
>
0
);
CHECK_ARG_CLEAN
(
_t
<=
_n
);
try
{
vector
<
libff
::
alt_bn128_Fr
>
poly
=
SplitStringToFr
(
decrypted_coeffs
,
symbol
);
...
...
@@ -260,18 +274,27 @@ void calc_secret_shares(const char *decrypted_coeffs,
}
catch
(
exception
&
e
)
{
LOG_ERROR
(
e
.
what
());
retur
n
;
goto
clea
n
;
}
catch
(...)
{
LOG_ERROR
(
"Unknown throwable"
);
retur
n
;
goto
clea
n
;
}
clean
:
;
}
int
calc_secret_share
(
const
char
*
decrypted_coeffs
,
char
*
s_share
,
unsigned
_t
,
unsigned
_n
,
unsigned
ind
)
{
int
result
=
1
;
CHECK_ARG_CLEAN
(
decrypted_coeffs
);
CHECK_ARG_CLEAN
(
s_share
);
CHECK_ARG_CLEAN
(
_n
>
0
);
CHECK_ARG_CLEAN
(
_t
<=
_n
);
try
{
char
symbol
=
':'
;
vector
<
libff
::
alt_bn128_Fr
>
poly
=
SplitStringToFr
(
decrypted_coeffs
,
symbol
);
...
...
@@ -300,35 +323,19 @@ int calc_secret_share(const char *decrypted_coeffs, char *s_share,
return
result
;
}
void
calc_secret_shareG2_old
(
const
char
*
decrypted_coeffs
,
char
*
s_shareG2
,
unsigned
_t
,
unsigned
ind
)
{
try
{
char
symbol
=
':'
;
vector
<
libff
::
alt_bn128_Fr
>
poly
=
SplitStringToFr
(
decrypted_coeffs
,
symbol
);
libff
::
alt_bn128_Fr
secret_share
=
PolynomialValue
(
poly
,
libff
::
alt_bn128_Fr
(
ind
),
_t
);
libff
::
alt_bn128_G2
secret_shareG2
=
secret_share
*
libff
::
alt_bn128_G2
::
one
();
string
secret_shareG2_str
=
ConvertG2ToString
(
secret_shareG2
);
strncpy
(
s_shareG2
,
secret_shareG2_str
.
c_str
(),
secret_shareG2_str
.
length
()
+
1
);
int
calc_secret_shareG2
(
const
char
*
s_share
,
char
*
s_shareG2
)
{
}
catch
(
exception
&
e
)
{
LOG_ERROR
(
e
.
what
());
}
catch
(...)
{
LOG_ERROR
(
"Unknown throwable"
);
}
}
int
calc_secret_shareG2
(
const
char
*
s_share
,
char
*
s_shareG2
)
{
int
result
=
1
;
mpz_t
share
;
mpz_init
(
share
);
CHECK_ARG_CLEAN
(
s_share
);
CHECK_ARG_CLEAN
(
s_shareG2
);
try
{
...
...
@@ -370,13 +377,21 @@ int calc_secret_shareG2(const char *s_share, char *s_shareG2) {
int
calc_public_shares
(
const
char
*
decrypted_coeffs
,
char
*
public_shares
,
unsigned
_t
)
{
// calculate for each node a list of public shares
int
ret
=
1
;
string
result
;
char
symbol
=
':'
;
CHECK_ARG_CLEAN
(
decrypted_coeffs
);
CHECK_ARG_CLEAN
(
public_shares
);
CHECK_ARG_CLEAN
(
_t
>
0
);
try
{
// calculate for each node a list of public shares
string
result
;
char
symbol
=
':'
;
vector
<
libff
::
alt_bn128_Fr
>
poly
=
SplitStringToFr
(
decrypted_coeffs
,
symbol
);
if
(
poly
.
size
()
!=
_t
)
{
return
1
;
goto
clean
;
}
for
(
size_t
i
=
0
;
i
<
_t
;
++
i
)
{
libff
::
alt_bn128_G2
pub_share
=
poly
.
at
(
i
)
*
libff
::
alt_bn128_G2
::
one
();
...
...
@@ -385,15 +400,18 @@ int calc_public_shares(const char *decrypted_coeffs, char *public_shares,
result
+=
pub_share_str
+
","
;
}
strncpy
(
public_shares
,
result
.
c_str
(),
result
.
length
());
ret
urn
0
;
ret
=
0
;
}
catch
(
exception
&
e
)
{
LOG_ERROR
(
e
.
what
());
ret
urn
1
;
ret
=
1
;
}
catch
(...)
{
LOG_ERROR
(
"Unknown throwable"
);
ret
urn
1
;
ret
=
1
;
}
clean
:
return
ret
;
}
string
ConvertHexToDec
(
string
hex_str
)
{
...
...
secure_enclave/DKGUtils.h
View file @
dd4e9d36
...
...
@@ -52,8 +52,6 @@ EXTERNC int Verification ( char * public_shares, mpz_t decr_secret_share, int _t
EXTERNC
int
calc_bls_public_key
(
char
*
skey
,
char
*
pub_key
);
EXTERNC
void
calc_secret_shareG2_old
(
const
char
*
public_shares
,
char
*
s_shareG2
,
unsigned
_t
,
unsigned
ind
);
EXTERNC
int
calc_secret_shareG2
(
const
char
*
s_share
,
char
*
s_shareG2
);
#endif
...
...
secure_enclave/DomainParameters.c
View file @
dd4e9d36
...
...
@@ -21,6 +21,10 @@
@date 2019
*/
#define SAFE_FREE(__X__) if (__X__) {free(__X__); __X__ = NULL;}
#define SAFE_DELETE(__X__) if (__X__) {delete(__X__); __X__ = NULL;}
#define SAFE_CHAR_BUF(__X__, __Y__) ;char __X__ [ __Y__ ]; memset(__X__, 0, __Y__);
#ifdef USER_SPACE
#include <gmp.h>
#else
...
...
@@ -104,7 +108,7 @@ void domain_parameters_clear(domain_parameters curve)
point_clear
(
curve
->
G
);
mpz_clear
(
curve
->
n
);
mpz_clear
(
curve
->
h
);
free
(
curve
->
name
);
SAFE_FREE
(
curve
->
name
);
free
(
curve
);
}
secure_enclave/EnclaveCommon.h
View file @
dd4e9d36
...
...
@@ -68,5 +68,11 @@ extern domain_parameters curve;
#define SAFE_DELETE(__X__) if (__X__) {delete(__X__); __X__ = NULL;}
#define SAFE_CHAR_BUF(__X__, __Y__) ;char __X__ [ __Y__ ]; memset(__X__, 0, __Y__);
#define CHECK_ARG_CLEAN(_EXPRESSION_) \
if (!(_EXPRESSION_)) { \
LOG_ERROR("State check failed::");LOG_ERROR(#_EXPRESSION_); \
LOG_ERROR(__FILE__); LOG_ERROR(__FUNCTION__);\
goto clean;}
#endif //SGXWALLET_ENCLAVECOMMON_H
secure_enclave/Point.c
View file @
dd4e9d36
...
...
@@ -27,6 +27,10 @@
#include <assert.h>
#include <stdbool.h>
#define SAFE_FREE(__X__) if (__X__) {free(__X__); __X__ = NULL;}
#define SAFE_DELETE(__X__) if (__X__) {delete(__X__); __X__ = NULL;}
#define SAFE_CHAR_BUF(__X__, __Y__) ;char __X__ [ __Y__ ]; memset(__X__, 0, __Y__);
#ifdef USER_SPACE
#include <gmp.h>
#else
...
...
@@ -338,6 +342,6 @@ void point_clear(point p)
return
;
mpz_clear
(
p
->
x
);
mpz_clear
(
p
->
y
);
free
(
p
);
SAFE_FREE
(
p
);
}
secure_enclave/Signature.c
View file @
dd4e9d36
...
...
@@ -26,6 +26,11 @@
#include <stdbool.h>
#include <assert.h>
#define SAFE_FREE(__X__) if (__X__) {free(__X__); __X__ = NULL;}
#define SAFE_DELETE(__X__) if (__X__) {delete(__X__); __X__ = NULL;}
#define SAFE_CHAR_BUF(__X__, __Y__) ;char __X__ [ __Y__ ]; memset(__X__, 0, __Y__);
#ifdef USER_SPACE
#include <gmp.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