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
7e2ac473
Unverified
Commit
7e2ac473
authored
Aug 10, 2020
by
kladko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SKALE-3067-cleanup-sgx
parent
bf6cefc5
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
249 additions
and
159 deletions
+249
-159
DKGUtils.cpp
secure_enclave/DKGUtils.cpp
+249
-159
No files found.
secure_enclave/DKGUtils.cpp
View file @
7e2ac473
...
...
@@ -61,7 +61,7 @@ string stringFromFr(const libff::alt_bn128_Fr &_el) {
return
string
(
tmp
);
}
catch
(
exception
&
e
)
{
}
catch
(
exception
&
e
)
{
LOG_ERROR
(
e
.
what
());
return
""
;
}
catch
(...)
{
...
...
@@ -119,6 +119,7 @@ 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
>
tokens
;
try
{
string
str
(
coeffs
);
...
...
@@ -139,7 +140,7 @@ vector <libff::alt_bn128_Fr> SplitStringToFr(const char *coeffs, const char symb
return
tokens
;
}
catch
(
exception
&
e
)
{
}
catch
(
exception
&
e
)
{
LOG_ERROR
(
e
.
what
());
return
tokens
;
}
catch
(...)
{
...
...
@@ -168,7 +169,7 @@ int gen_dkg_poly(char *secret, unsigned _t) {
return
0
;
}
catch
(
exception
&
e
)
{
}
catch
(
exception
&
e
)
{
LOG_ERROR
(
e
.
what
());
return
1
;
}
catch
(...)
{
...
...
@@ -179,8 +180,12 @@ int gen_dkg_poly(char *secret, unsigned _t) {
}
libff
::
alt_bn128_Fr
PolynomialValue
(
const
vector
<
libff
::
alt_bn128_Fr
>
&
pol
,
libff
::
alt_bn128_Fr
point
,
unsigned
_t
)
{
libff
::
alt_bn128_Fr
value
=
libff
::
alt_bn128_Fr
::
zero
();
try
{
libff
::
alt_bn128_Fr
pow
=
libff
::
alt_bn128_Fr
::
one
();
for
(
unsigned
i
=
0
;
i
<
pol
.
size
();
++
i
)
{
value
+=
pol
[
i
]
*
pow
;
...
...
@@ -188,14 +193,25 @@ libff::alt_bn128_Fr PolynomialValue(const vector <libff::alt_bn128_Fr> &pol, lib
}
return
value
;
}
catch
(
exception
&
e
)
{
LOG_ERROR
(
e
.
what
());
return
value
;
}
catch
(...)
{
LOG_ERROR
(
"Unknown throwable"
);
return
value
;
}
}
void
calc_secret_shares
(
const
char
*
decrypted_coeffs
,
char
*
secret_shares
,
// calculates secret shares in base 10 to a string secret_shares,
unsigned
_t
,
unsigned
_n
)
{
// separated by ":"
// calculate for each node a list of secret values that will be used for verification
string
result
;
char
symbol
=
':'
;
try
{
vector
<
libff
::
alt_bn128_Fr
>
poly
=
SplitStringToFr
(
decrypted_coeffs
,
symbol
);
for
(
size_t
i
=
0
;
i
<
_n
;
++
i
)
{
...
...
@@ -204,11 +220,20 @@ void calc_secret_shares(const char *decrypted_coeffs,
result
+=
":"
;
}
strncpy
(
secret_shares
,
result
.
c_str
(),
result
.
length
()
+
1
);
}
catch
(
exception
&
e
)
{
LOG_ERROR
(
e
.
what
());
return
;
}
catch
(...)
{
LOG_ERROR
(
"Unknown throwable"
);
return
;
}
}
int
calc_secret_share
(
const
char
*
decrypted_coeffs
,
char
*
s_share
,
unsigned
_t
,
unsigned
_n
,
unsigned
ind
)
{
try
{
char
symbol
=
':'
;
vector
<
libff
::
alt_bn128_Fr
>
poly
=
SplitStringToFr
(
decrypted_coeffs
,
symbol
);
if
(
poly
.
size
()
!=
_t
)
{
...
...
@@ -222,11 +247,20 @@ int calc_secret_share(const char *decrypted_coeffs, char *s_share,
strncpy
(
s_share
,
cur_share
.
c_str
(),
cur_share
.
length
()
+
1
);
return
0
;
}
catch
(
exception
&
e
)
{
LOG_ERROR
(
e
.
what
());
return
1
;
}
catch
(...)
{
LOG_ERROR
(
"Unknown throwable"
);
return
1
;
}
}
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
);
...
...
@@ -237,11 +271,19 @@ void calc_secret_shareG2_old(const char *decrypted_coeffs, char *s_shareG2,
string
secret_shareG2_str
=
ConvertG2ToString
(
secret_shareG2
);
strncpy
(
s_shareG2
,
secret_shareG2_str
.
c_str
(),
secret_shareG2_str
.
length
()
+
1
);
}
catch
(
exception
&
e
)
{
LOG_ERROR
(
e
.
what
());
}
catch
(...)
{
LOG_ERROR
(
"Unknown throwable"
);
}
}
int
calc_secret_shareG2
(
const
char
*
s_share
,
char
*
s_shareG2
)
{
try
{
mpz_t
share
;
mpz_init
(
share
);
if
(
mpz_set_str
(
share
,
s_share
,
16
)
==
-
1
)
{
...
...
@@ -265,11 +307,20 @@ int calc_secret_shareG2(const char *s_share, char *s_shareG2) {
mpz_clear
(
share
);
return
0
;
}
catch
(
exception
&
e
)
{
LOG_ERROR
(
e
.
what
());
return
1
;
}
catch
(...)
{
LOG_ERROR
(
"Unknown throwable"
);
return
1
;
}
}
int
calc_public_shares
(
const
char
*
decrypted_coeffs
,
char
*
public_shares
,
unsigned
_t
)
{
try
{
// calculate for each node a list of public shares
string
result
;
char
symbol
=
':'
;
...
...
@@ -285,15 +336,26 @@ int calc_public_shares(const char *decrypted_coeffs, char *public_shares,
}
strncpy
(
public_shares
,
result
.
c_str
(),
result
.
length
());
return
0
;
}
catch
(
exception
&
e
)
{
LOG_ERROR
(
e
.
what
());
return
1
;
}
catch
(...)
{
LOG_ERROR
(
"Unknown throwable"
);
return
1
;
}
}
string
ConvertHexToDec
(
string
hex_str
)
{
try
{
mpz_t
dec
;
mpz_init
(
dec
);
if
(
mpz_set_str
(
dec
,
hex_str
.
c_str
(),
16
)
==
-
1
)
{
mpz_clear
(
dec
);
return
"false
"
;
return
"
"
;
}
char
arr
[
mpz_sizeinbase
(
dec
,
10
)
+
2
];
...
...
@@ -302,12 +364,24 @@ string ConvertHexToDec(string hex_str) {
mpz_clear
(
dec
);
return
result
;
}
catch
(
exception
&
e
)
{
LOG_ERROR
(
e
.
what
());
return
""
;
}
catch
(...)
{
LOG_ERROR
(
"Unknown throwable"
);
return
""
;
}
}
int
Verification
(
char
*
public_shares
,
mpz_t
decr_secret_share
,
int
_t
,
int
ind
)
{
string
pub_shares_str
=
public_shares
;
try
{
string
pub_shares_str
=
public_shares
;
vector
<
libff
::
alt_bn128_G2
>
pub_shares
;
uint64_t
share_length
=
256
;
uint8_t
coord_length
=
64
;
...
...
@@ -320,7 +394,7 @@ int Verification(char *public_shares, mpz_t decr_secret_share, int _t, int ind)
string
x_c1_str
=
ConvertHexToDec
(
pub_shares_str
.
substr
(
pos0
+
coord_length
,
coord_length
));
string
y_c0_str
=
ConvertHexToDec
(
pub_shares_str
.
substr
(
pos0
+
2
*
coord_length
,
coord_length
));
string
y_c1_str
=
ConvertHexToDec
(
pub_shares_str
.
substr
(
pos0
+
3
*
coord_length
,
coord_length
));
if
(
x_c0_str
==
"false"
||
x_c1_str
==
"false"
||
y_c0_str
==
"false"
||
y_c1_str
==
"false
"
)
{
if
(
x_c0_str
==
""
||
x_c1_str
==
""
||
y_c0_str
==
""
||
y_c1_str
==
"
"
)
{
return
2
;
}
pub_share
.
X
.
c0
=
libff
::
alt_bn128_Fq
(
x_c0_str
.
c_str
());
...
...
@@ -355,11 +429,19 @@ int Verification(char *public_shares, mpz_t decr_secret_share, int _t, int ind)
ConvertToString
(
val2
.
X
.
c0
).
length
());
return
(
val
==
sshare
*
libff
::
alt_bn128_G2
::
one
());
}
catch
(
exception
&
e
)
{
LOG_ERROR
(
e
.
what
());
return
0
;
}
catch
(...)
{
LOG_ERROR
(
"Unknown throwable"
);
return
0
;
}
}
int
calc_bls_public_key
(
char
*
skey_hex
,
char
*
pub_key
)
{
try
{
mpz_t
skey
;
mpz_init
(
skey
);
if
(
mpz_set_str
(
skey
,
skey_hex
,
16
)
==
-
1
)
{
...
...
@@ -382,4 +464,12 @@ int calc_bls_public_key(char *skey_hex, char *pub_key) {
mpz_clear
(
skey
);
return
0
;
}
catch
(
exception
&
e
)
{
LOG_ERROR
(
e
.
what
());
return
1
;
}
catch
(...)
{
LOG_ERROR
(
"Unknown throwable"
);
return
1
;
}
}
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