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
4840fa0c
Unverified
Commit
4840fa0c
authored
Oct 05, 2020
by
Oleh Nikolaiev
Committed by
GitHub
Oct 05, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' into bug/bls-sign-crash-with-imported-keys
parents
fd6f6c31
2c73c2d7
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
64 additions
and
24 deletions
+64
-24
DKGCrypto.cpp
DKGCrypto.cpp
+31
-5
DKGCrypto.h
DKGCrypto.h
+3
-1
SGXWalletServer.cpp
SGXWalletServer.cpp
+21
-11
SGXWalletServer.hpp
SGXWalletServer.hpp
+2
-2
abstractstubserver.h
abstractstubserver.h
+3
-3
stubclient.h
stubclient.h
+3
-1
testw.cpp
testw.cpp
+1
-1
No files found.
DKGCrypto.cpp
View file @
4840fa0c
...
...
@@ -152,9 +152,11 @@ string gen_dkg_poly(int _t) {
return
result
;
}
vector
<
vector
<
string
>>
get_verif_vect
(
const
char
*
encryptedPolyHex
,
int
t
,
int
n
)
{
vector
<
vector
<
string
>>
get_verif_vect
(
const
string
&
encryptedPolyHex
,
int
t
,
int
n
)
{
CHECK_STATE
(
encryptedPolyHex
);
auto
encryptedPolyHexPtr
=
encryptedPolyHex
.
c_str
();
CHECK_STATE
(
encryptedPolyHexPtr
);
vector
<
char
>
errMsg
(
BUF_LEN
,
0
);
...
...
@@ -166,7 +168,7 @@ vector <vector<string>> get_verif_vect(const char *encryptedPolyHex, int t, int
vector
<
uint8_t
>
encrDKGPoly
(
2
*
BUF_LEN
,
0
);
if
(
!
hex2carray
(
encryptedPolyHex
,
&
encLen
,
encrDKGPoly
.
data
(),
6100
))
{
if
(
!
hex2carray
(
encryptedPolyHex
Ptr
,
&
encLen
,
encrDKGPoly
.
data
(),
6100
))
{
throw
SGXException
(
INVALID_HEX
,
"Invalid encryptedPolyHex"
);
}
...
...
@@ -182,15 +184,39 @@ vector <vector<string>> get_verif_vect(const char *encryptedPolyHex, int t, int
HANDLE_TRUSTED_FUNCTION_ERROR
(
status
,
errStatus
,
errMsg
.
data
());
vector
<
string
>
g2Strings
=
splitString
(
pubShares
.
data
(),
','
);
vector
<
vector
<
string
>>
pubSharesVect
;
vector
<
vector
<
string
>>
pubSharesVect
(
t
)
;
for
(
uint64_t
i
=
0
;
i
<
g2Strings
.
size
();
i
++
)
{
vector
<
string
>
coeffStr
=
splitString
(
g2Strings
.
at
(
i
).
c_str
(),
':'
);
pubSharesVect
.
push_back
(
coeffStr
)
;
pubSharesVect
[
i
]
=
coeffStr
;
}
return
pubSharesVect
;
}
vector
<
vector
<
string
>>
getVerificationVectorMult
(
const
std
::
string
&
encryptedPolyHex
,
int
t
,
int
n
,
size_t
ind
)
{
auto
verificationVector
=
get_verif_vect
(
encryptedPolyHex
,
t
,
n
);
vector
<
vector
<
string
>>
result
(
t
);
for
(
size_t
i
=
0
;
i
<
t
;
++
i
)
{
libff
::
alt_bn128_G2
current_coefficient
;
current_coefficient
.
X
.
c0
=
libff
::
alt_bn128_Fq
(
verificationVector
[
i
][
0
].
c_str
());
current_coefficient
.
X
.
c1
=
libff
::
alt_bn128_Fq
(
verificationVector
[
i
][
1
].
c_str
());
current_coefficient
.
Y
.
c0
=
libff
::
alt_bn128_Fq
(
verificationVector
[
i
][
2
].
c_str
());
current_coefficient
.
Y
.
c1
=
libff
::
alt_bn128_Fq
(
verificationVector
[
i
][
3
].
c_str
());
current_coefficient
.
Z
=
libff
::
alt_bn128_Fq2
::
one
();
current_coefficient
=
libff
::
power
(
libff
::
alt_bn128_Fr
(
ind
+
1
),
i
)
*
current_coefficient
;
current_coefficient
.
to_affine_coordinates
();
auto
g2_str
=
convertG2ToString
(
current_coefficient
);
result
[
i
]
=
splitString
(
g2_str
.
c_str
(),
':'
);
}
return
result
;
}
string
getSecretShares
(
const
string
&
_polyName
,
const
char
*
_encryptedPolyHex
,
const
vector
<
string
>
&
_publicKeys
,
int
_t
,
...
...
DKGCrypto.h
View file @
4840fa0c
...
...
@@ -33,7 +33,9 @@ using namespace std;
string
gen_dkg_poly
(
int
_t
);
vector
<
vector
<
string
>>
get_verif_vect
(
const
char
*
encryptedPolyHex
,
int
t
,
int
n
);
vector
<
vector
<
string
>>
get_verif_vect
(
const
string
&
encryptedPolyHex
,
int
t
,
int
n
);
vector
<
vector
<
string
>>
getVerificationVectorMult
(
const
std
::
string
&
encryptedPolyHex
,
int
t
,
int
n
,
size_t
ind
);
vector
<
string
>
splitString
(
const
char
*
coeffs
,
const
char
symbol
);
...
...
SGXWalletServer.cpp
View file @
4840fa0c
...
...
@@ -397,7 +397,7 @@ Json::Value SGXWalletServer::getVerificationVectorImpl(const string &_polyName,
shared_ptr
<
string
>
encrPoly
=
readFromDb
(
_polyName
);
verifVector
=
get_verif_vect
(
encrPoly
->
c_str
()
,
_t
,
_n
);
verifVector
=
get_verif_vect
(
*
encrPoly
,
_t
,
_n
);
for
(
int
i
=
0
;
i
<
_t
;
i
++
)
{
vector
<
string
>
currentCoef
=
verifVector
.
at
(
i
);
...
...
@@ -595,7 +595,7 @@ Json::Value SGXWalletServer::calculateAllBLSPublicKeysImpl(const Json::Value& pu
RETURN_SUCCESS
(
result
);
}
Json
::
Value
SGXWalletServer
::
complaintResponseImpl
(
const
string
&
_polyName
,
int
_ind
)
{
Json
::
Value
SGXWalletServer
::
complaintResponseImpl
(
const
string
&
_polyName
,
int
_
t
,
int
_n
,
int
_
ind
)
{
spdlog
::
info
(
"Entering {}"
,
__FUNCTION__
);
INIT_RESULT
(
result
)
...
...
@@ -612,13 +612,23 @@ Json::Value SGXWalletServer::complaintResponseImpl(const string &_polyName, int
result
[
"share*G2"
]
=
*
shareG2_ptr
;
result
[
"dhKey"
]
=
DHKey
;
// TODO: delete dh keys
// for (int i = 0; i < _n; i++) {
// string name = _polyName + "_" + to_string(i) + ":";
// LevelDB::getLevelDb()->deleteDHDKGKey(name);
// string shareG2_name = "shareG2_" + _polyName + "_" + to_string(i) + ":";
// LevelDB::getLevelDb()->deleteKey(shareG2_name);
// }
shared_ptr
<
string
>
encrPoly
=
readFromDb
(
_polyName
);
auto
verificationVectorMult
=
getVerificationVectorMult
(
encrPoly
->
c_str
(),
_t
,
_n
,
_ind
);
for
(
int
i
=
0
;
i
<
_t
;
i
++
)
{
vector
<
string
>
currentCoef
=
verificationVectorMult
.
at
(
i
);
for
(
int
j
=
0
;
j
<
4
;
j
++
)
{
result
[
"verificationVectorMult"
][
i
][
j
]
=
currentCoef
.
at
(
j
);
}
}
for
(
int
i
=
0
;
i
<
_n
;
i
++
)
{
string
name
=
_polyName
+
"_"
+
to_string
(
i
)
+
":"
;
LevelDB
::
getLevelDb
()
->
deleteDHDKGKey
(
name
);
string
shareG2_name
=
"shareG2_"
+
_polyName
+
"_"
+
to_string
(
i
)
+
":"
;
LevelDB
::
getLevelDb
()
->
deleteKey
(
shareG2_name
);
}
LevelDB
::
getLevelDb
()
->
deleteKey
(
_polyName
);
string
encryptedSecretShareName
=
"encryptedSecretShare:"
+
_polyName
;
...
...
@@ -746,8 +756,8 @@ Json::Value SGXWalletServer::blsSignMessageHash(const string &_keyShareName, con
return
blsSignMessageHashImpl
(
_keyShareName
,
_messageHash
,
_t
,
_n
);
}
Json
::
Value
SGXWalletServer
::
complaintResponse
(
const
string
&
polyName
,
int
ind
)
{
return
complaintResponseImpl
(
polyName
,
ind
);
Json
::
Value
SGXWalletServer
::
complaintResponse
(
const
string
&
polyName
,
int
t
,
int
n
,
int
ind
)
{
return
complaintResponseImpl
(
polyName
,
t
,
n
,
ind
);
}
Json
::
Value
SGXWalletServer
::
multG2
(
const
string
&
x
)
{
...
...
SGXWalletServer.hpp
View file @
4840fa0c
...
...
@@ -76,7 +76,7 @@ public:
virtual
Json
::
Value
calculateAllBLSPublicKeys
(
const
Json
::
Value
&
publicShares
,
int
t
,
int
n
);
virtual
Json
::
Value
complaintResponse
(
const
string
&
polyName
,
int
ind
);
virtual
Json
::
Value
complaintResponse
(
const
string
&
polyName
,
int
t
,
int
n
,
int
ind
);
virtual
Json
::
Value
multG2
(
const
string
&
x
);
...
...
@@ -126,7 +126,7 @@ public:
static
Json
::
Value
calculateAllBLSPublicKeysImpl
(
const
Json
::
Value
&
publicShares
,
int
t
,
int
n
);
static
Json
::
Value
complaintResponseImpl
(
const
string
&
_polyName
,
int
_ind
);
static
Json
::
Value
complaintResponseImpl
(
const
string
&
_polyName
,
int
t
,
int
n
,
int
_ind
);
static
Json
::
Value
multG2Impl
(
const
string
&
_x
);
...
...
abstractstubserver.h
View file @
4840fa0c
...
...
@@ -50,7 +50,7 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"createBLSPrivateKey"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"blsKeyName"
,
jsonrpc
::
JSON_STRING
,
"ethKeyName"
,
jsonrpc
::
JSON_STRING
,
"polyName"
,
jsonrpc
::
JSON_STRING
,
"secretShare"
,
jsonrpc
::
JSON_STRING
,
"t"
,
jsonrpc
::
JSON_INTEGER
,
"n"
,
jsonrpc
::
JSON_INTEGER
,
NULL
),
&
AbstractStubServer
::
createBLSPrivateKeyI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"getBLSPublicKeyShare"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"blsKeyName"
,
jsonrpc
::
JSON_STRING
,
NULL
),
&
AbstractStubServer
::
getBLSPublicKeyShareI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"calculateAllBLSPublicKeys"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"publicShares"
,
jsonrpc
::
JSON_ARRAY
,
"n"
,
jsonrpc
::
JSON_INTEGER
,
"t"
,
jsonrpc
::
JSON_INTEGER
,
NULL
),
&
AbstractStubServer
::
calculateAllBLSPublicKeysI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"complaintResponse"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"polyName"
,
jsonrpc
::
JSON_STRING
,
"ind"
,
jsonrpc
::
JSON_INTEGER
,
NULL
),
&
AbstractStubServer
::
complaintResponseI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"complaintResponse"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"polyName"
,
jsonrpc
::
JSON_STRING
,
"
t"
,
jsonrpc
::
JSON_INTEGER
,
"n"
,
jsonrpc
::
JSON_INTEGER
,
"
ind"
,
jsonrpc
::
JSON_INTEGER
,
NULL
),
&
AbstractStubServer
::
complaintResponseI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"multG2"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"x"
,
jsonrpc
::
JSON_STRING
,
NULL
),
&
AbstractStubServer
::
multG2I
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"isPolyExists"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"polyName"
,
jsonrpc
::
JSON_STRING
,
NULL
),
&
AbstractStubServer
::
isPolyExistsI
);
...
...
@@ -111,7 +111,7 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
}
inline
virtual
void
complaintResponseI
(
const
Json
::
Value
&
request
,
Json
::
Value
&
response
)
{
response
=
this
->
complaintResponse
(
request
[
"polyName"
].
asString
(),
request
[
"ind"
].
asInt
());
response
=
this
->
complaintResponse
(
request
[
"polyName"
].
asString
(),
request
[
"
t"
].
asInt
(),
request
[
"n"
].
asInt
(),
request
[
"
ind"
].
asInt
());
}
inline
virtual
void
multG2I
(
const
Json
::
Value
&
request
,
Json
::
Value
&
response
)
{
...
...
@@ -152,7 +152,7 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
virtual
Json
::
Value
createBLSPrivateKey
(
const
std
::
string
&
blsKeyName
,
const
std
::
string
&
ethKeyName
,
const
std
::
string
&
polyName
,
const
std
::
string
&
SecretShare
,
int
t
,
int
n
)
=
0
;
virtual
Json
::
Value
getBLSPublicKeyShare
(
const
std
::
string
&
blsKeyName
)
=
0
;
virtual
Json
::
Value
calculateAllBLSPublicKeys
(
const
Json
::
Value
&
publicShares
,
int
t
,
int
n
)
=
0
;
virtual
Json
::
Value
complaintResponse
(
const
std
::
string
&
polyName
,
int
ind
)
=
0
;
virtual
Json
::
Value
complaintResponse
(
const
std
::
string
&
polyName
,
int
t
,
int
n
,
int
ind
)
=
0
;
virtual
Json
::
Value
multG2
(
const
std
::
string
&
x
)
=
0
;
virtual
Json
::
Value
isPolyExists
(
const
std
::
string
&
polyName
)
=
0
;
...
...
stubclient.h
View file @
4840fa0c
...
...
@@ -171,10 +171,12 @@ class StubClient : public jsonrpc::Client
throw
jsonrpc
::
JsonRpcException
(
jsonrpc
::
Errors
::
ERROR_CLIENT_INVALID_RESPONSE
,
result
.
toStyledString
());
}
Json
::
Value
complaintResponse
(
const
std
::
string
&
polyName
,
int
ind
)
Json
::
Value
complaintResponse
(
const
std
::
string
&
polyName
,
int
t
,
int
n
,
int
ind
)
{
Json
::
Value
p
;
p
[
"polyName"
]
=
polyName
;
p
[
"t"
]
=
t
;
p
[
"n"
]
=
n
;
p
[
"ind"
]
=
ind
;
Json
::
Value
result
=
this
->
CallMethod
(
"complaintResponse"
,
p
);
if
(
result
.
isObject
())
...
...
testw.cpp
View file @
4840fa0c
...
...
@@ -650,7 +650,7 @@ TEST_CASE_METHOD(TestFixture, "AES_DKG test", "[aes-dkg]") {
REQUIRE
(
res
);
}
Json
::
Value
complaintResponse
=
c
.
complaintResponse
(
polyNames
[
1
],
0
);
Json
::
Value
complaintResponse
=
c
.
complaintResponse
(
polyNames
[
1
],
t
,
n
,
0
);
REQUIRE
(
complaintResponse
[
"status"
]
==
0
);
BLSSigShareSet
sigShareSet
(
t
,
n
);
...
...
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