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
6f2c10f1
Unverified
Commit
6f2c10f1
authored
Sep 26, 2019
by
svetaro
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SKALE-1594 Add method get Public Key
parent
97dc071c
Changes
19
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
384 additions
and
211 deletions
+384
-211
ECDSACrypto.cpp
ECDSACrypto.cpp
+47
-7
ECDSACrypto.h
ECDSACrypto.h
+3
-1
LevelDB.cpp
LevelDB.cpp
+6
-0
SGXWalletServer.cpp
SGXWalletServer.cpp
+50
-18
SGXWalletServer.hpp
SGXWalletServer.hpp
+5
-9
abstractstubserver.h
abstractstubserver.h
+9
-3
secure_enclave.Po
secure_enclave/.deps/secure_enclave.Po
+18
-114
BLSEnclave.cpp
secure_enclave/BLSEnclave.cpp
+12
-0
DKGUtils.h
secure_enclave/DKGUtils.h
+1
-0
Makefile.am
secure_enclave/Makefile.am
+1
-1
Makefile.in
secure_enclave/Makefile.in
+1
-1
secure_enclave.c
secure_enclave/secure_enclave.c
+68
-22
secure_enclave.edl
secure_enclave/secure_enclave.edl
+13
-5
signature.c
secure_enclave/signature.c
+10
-10
sgxwallet.c
sgxwallet.c
+3
-0
sgxwallet_common.h
sgxwallet_common.h
+1
-0
spec.json
spec.json
+13
-2
stubclient.h
stubclient.h
+13
-2
testw.cpp
testw.cpp
+110
-16
No files found.
ECDSACrypto.cpp
View file @
6f2c10f1
...
...
@@ -22,28 +22,68 @@ std::vector<std::string> gen_ecdsa_key(){
carray2Hex
(
encr_pr_key
,
enc_len
,
hexEncrKey
);
keys
.
at
(
0
)
=
hexEncrKey
;
keys
.
at
(
1
)
=
std
::
string
(
pub_key_x
)
+
std
::
string
(
pub_key_y
);
std
::
cerr
<<
"in ECDSACrypto encr key x "
<<
keys
.
at
(
0
)
<<
std
::
endl
;
//std::cerr << "in ECDSACrypto encr key x " << keys.at(0) << std::endl;
free
(
errMsg
);
free
(
pub_key_x
);
free
(
pub_key_y
);
free
(
encr_pr_key
);
free
(
hexEncrKey
);
return
keys
;
}
std
::
vector
<
std
::
string
>
ecdsa_sign_hash
(
const
char
*
encryptedKeyHex
,
const
char
*
hashHex
){
std
::
string
get_ecdsa_pubkey
(
const
char
*
encryptedKeyHex
){
char
*
errMsg
=
(
char
*
)
calloc
(
1024
,
1
);
int
err_status
=
0
;
char
*
pub_key_x
=
(
char
*
)
calloc
(
1024
,
1
);
char
*
pub_key_y
=
(
char
*
)
calloc
(
1024
,
1
);
uint64_t
enc_len
=
0
;
uint8_t
encr_pr_key
[
BUF_LEN
];
hex2carray
(
encryptedKeyHex
,
&
enc_len
,
encr_pr_key
);
status
=
get_public_ecdsa_key
(
eid
,
&
err_status
,
errMsg
,
encr_pr_key
,
enc_len
,
pub_key_x
,
pub_key_y
);
std
::
string
pubKey
=
std
::
string
(
pub_key_x
)
+
std
::
string
(
pub_key_y
);
std
::
cerr
<<
"err str "
<<
errMsg
<<
std
::
endl
;
free
(
errMsg
);
free
(
pub_key_x
);
free
(
pub_key_y
);
return
pubKey
;
}
std
::
vector
<
std
::
string
>
ecdsa_sign_hash
(
const
char
*
encryptedKeyHex
,
const
char
*
hashHex
,
int
base
){
std
::
vector
<
std
::
string
>
signature_vect
(
3
);
char
*
errMsg
=
(
char
*
)
calloc
(
1024
,
1
);
int
err_status
=
0
;
char
*
signature_r
=
(
char
*
)
malloc
(
1024
);
char
*
signature_s
=
(
char
*
)
malloc
(
1024
);
char
*
signature_v
=
(
char
*
)
calloc
(
4
,
1
)
;
uint8_t
signature_v
=
0
;
uint64_t
dec_len
=
0
;
uint8_t
encr_key
[
BUF_LEN
];
hex2carray
(
encryptedKeyHex
,
&
dec_len
,
encr_key
);
status
=
ecdsa_sign1
(
eid
,
&
err_status
,
errMsg
,
encr_key
,
dec_len
,
(
unsigned
char
*
)
hashHex
,
signature_r
,
signature_s
,
signature_v
);
status
=
ecdsa_sign1
(
eid
,
&
err_status
,
errMsg
,
encr_key
,
dec_len
,
(
unsigned
char
*
)
hashHex
,
signature_r
,
signature_s
,
signature_v
,
base
);
if
(
status
!=
SGX_SUCCESS
){
std
::
cerr
<<
"failed to sign "
<<
std
::
endl
;
}
signature_vect
.
at
(
0
)
=
std
::
to_string
(
signature_v
);
if
(
base
==
16
)
{
signature_vect
.
at
(
1
)
=
"0x"
+
std
::
string
(
signature_r
);
signature_vect
.
at
(
2
)
=
"0x"
+
std
::
string
(
signature_s
);
}
else
{
signature_vect
.
at
(
1
)
=
std
::
string
(
signature_r
);
signature_vect
.
at
(
2
)
=
std
::
string
(
signature_s
);
}
signature_vect
.
at
(
0
)
=
signature_v
;
signature_vect
.
at
(
1
)
=
"0x"
+
std
::
string
(
signature_r
);
signature_vect
.
at
(
2
)
=
"0x"
+
std
::
string
(
signature_s
);
free
(
errMsg
)
;
free
(
signature_r
);
free
(
signature_s
);
return
signature_vect
;
}
\ No newline at end of file
ECDSACrypto.h
View file @
6f2c10f1
...
...
@@ -18,6 +18,8 @@
std
::
vector
<
std
::
string
>
gen_ecdsa_key
();
std
::
vector
<
std
::
string
>
ecdsa_sign_hash
(
const
char
*
encryptedKeyHex
,
const
char
*
hashHex
);
std
::
string
get_ecdsa_pubkey
(
const
char
*
encryptedKeyHex
);
std
::
vector
<
std
::
string
>
ecdsa_sign_hash
(
const
char
*
encryptedKeyHex
,
const
char
*
hashHex
,
int
base
);
#endif //SGXD_ECDSACRYPTO_H
LevelDB.cpp
View file @
6f2c10f1
...
...
@@ -25,6 +25,7 @@
#include <stdexcept>
#include <memory>
#include <string>
#include <iostream>
#include "leveldb/db.h"
...
...
@@ -54,6 +55,8 @@ std::shared_ptr<std::string> LevelDB::readString(const std::string &_key) {
auto
status
=
db
->
Get
(
readOptions
,
_key
,
&*
result
);
std
::
cerr
<<
"key to read from db: "
<<
_key
<<
std
::
endl
;
throwExceptionOnError
(
status
);
if
(
status
.
IsNotFound
())
...
...
@@ -69,6 +72,8 @@ void LevelDB::writeString(const std::string &_key, const std::string &_value) {
auto
status
=
db
->
Put
(
writeOptions
,
Slice
(
_key
),
Slice
(
_value
));
throwExceptionOnError
(
status
);
std
::
cerr
<<
"written key "
<<
_key
<<
" value "
<<
_value
<<
std
::
endl
;
}
void
LevelDB
::
writeByteArray
(
const
char
*
_key
,
size_t
_keyLen
,
const
char
*
value
,
...
...
@@ -93,6 +98,7 @@ void LevelDB::writeByteArray(std::string &_key, const char *value,
}
void
LevelDB
::
throwExceptionOnError
(
Status
_status
)
{
std
::
cerr
<<
" DB exception "
<<
std
::
endl
;
if
(
_status
.
IsNotFound
())
return
;
...
...
SGXWalletServer.cpp
View file @
6f2c10f1
...
...
@@ -31,21 +31,19 @@ SGXWalletServer::SGXWalletServer(AbstractServerConnector &connector,
serverVersion_t
type
)
:
AbstractStubServer
(
connector
,
type
)
{}
SGXWalletServer
*
s
=
nullptr
;
HttpServer
*
hs
=
nullptr
;
SGXWalletServer
*
s
=
nullptr
;
HttpServer
*
hs
=
nullptr
;
int
init_server
()
{
hs
=
new
HttpServer
(
1025
);
s
=
new
SGXWalletServer
(
*
hs
,
hs
=
new
HttpServer
(
1025
);
s
=
new
SGXWalletServer
(
*
hs
,
JSONRPC_SERVER_V2
);
// hybrid server (json-rpc 1.0 & 2.0)
if
(
!
s
->
StartListening
())
{
cerr
<<
"Server could not start listening"
<<
endl
;
exit
(
-
1
);
}
return
0
;
}
return
0
;
}
Json
::
Value
...
...
@@ -84,7 +82,6 @@ importBLSKeyShareImpl(int index, const std::string &_keyShare, const std::string
return
result
;
}
Json
::
Value
blsSignMessageHashImpl
(
const
std
::
string
&
keyShareName
,
const
std
::
string
&
messageHash
)
{
Json
::
Value
result
;
result
[
"status"
]
=
-
1
;
...
...
@@ -151,7 +148,7 @@ Json::Value generateECDSAKeyImpl(const std::string &_keyName) {
result
[
"errorMessage"
]
=
""
;
result
[
"encryptedKey"
]
=
""
;
cerr
<<
"Calling method
"
<<
endl
;
cerr
<<
"Calling method
generateECDSAKey"
<<
endl
;
std
::
vector
<
std
::
string
>
keys
;
...
...
@@ -164,6 +161,7 @@ Json::Value generateECDSAKeyImpl(const std::string &_keyName) {
writeECDSAKey
(
_keyName
,
keys
.
at
(
0
));
}
catch
(
RPCException
&
_e
)
{
std
::
cerr
<<
" err str "
<<
_e
.
errString
<<
std
::
endl
;
result
[
"status"
]
=
_e
.
status
;
result
[
"errorMessage"
]
=
_e
.
errString
;
}
...
...
@@ -172,13 +170,13 @@ Json::Value generateECDSAKeyImpl(const std::string &_keyName) {
result
[
"PublicKey"
]
=
keys
.
at
(
1
);
std
::
cerr
<<
"in SGXWalletServer encr key x "
<<
keys
.
at
(
0
)
<<
std
::
endl
;
//
std::cerr << "in SGXWalletServer encr key x " << keys.at(0) << std::endl;
return
result
;
}
Json
::
Value
ecdsaSignMessageHashImpl
(
const
std
::
string
&
_keyName
,
const
std
::
string
&
messageHash
)
{
Json
::
Value
ecdsaSignMessageHashImpl
(
int
base
,
const
std
::
string
&
_keyName
,
const
std
::
string
&
messageHash
)
{
Json
::
Value
result
;
result
[
"status"
]
=
0
;
result
[
"errorMessage"
]
=
""
;
...
...
@@ -187,15 +185,17 @@ Json::Value ecdsaSignMessageHashImpl(const std::string &_keyName, const std::str
result
[
"signature_s"
]
=
""
;
std
::
vector
<
std
::
string
>
sign_vect
(
3
);
std
::
cerr
<<
"entered ecdsaSignMessageHashImpl"
<<
std
::
endl
;
try
{
std
::
shared_ptr
<
std
::
string
>
key_ptr
=
readECDSAKey
(
_keyName
);
sign_vect
=
ecdsa_sign_hash
((
*
key_ptr
).
c_str
(),
messageHash
.
c_str
());
std
::
cerr
<<
"read encr key"
<<
*
key_ptr
<<
std
::
endl
;
sign_vect
=
ecdsa_sign_hash
(
key_ptr
->
c_str
(),
messageHash
.
c_str
(),
base
);
}
catch
(
RPCException
&
_e
)
{
std
::
cerr
<<
"err str "
<<
_e
.
errString
<<
std
::
endl
;
result
[
"status"
]
=
_e
.
status
;
result
[
"errorMessage"
]
=
_e
.
errString
;
}
std
::
cerr
<<
"got signature_r"
<<
sign_vect
.
at
(
1
)
<<
std
::
endl
;
result
[
"signature_v"
]
=
sign_vect
.
at
(
0
);
result
[
"signature_r"
]
=
sign_vect
.
at
(
1
);
result
[
"signature_s"
]
=
sign_vect
.
at
(
2
);
...
...
@@ -203,12 +203,44 @@ Json::Value ecdsaSignMessageHashImpl(const std::string &_keyName, const std::str
return
result
;
}
Json
::
Value
getPublicECDSAKeyImpl
(
const
std
::
string
&
keyName
){
Json
::
Value
result
;
result
[
"status"
]
=
0
;
result
[
"errorMessage"
]
=
""
;
result
[
"PublicKey"
]
=
""
;
cerr
<<
"Calling method getPublicECDSAKey"
<<
endl
;
std
::
string
Pkey
;
try
{
std
::
shared_ptr
<
std
::
string
>
key_ptr
=
readECDSAKey
(
keyName
);
Pkey
=
get_ecdsa_pubkey
(
key_ptr
->
c_str
());
}
catch
(
RPCException
&
_e
)
{
result
[
"status"
]
=
_e
.
status
;
result
[
"errorMessage"
]
=
_e
.
errString
;
}
std
::
cerr
<<
"PublicKey"
<<
Pkey
<<
std
::
endl
;
result
[
"PublicKey"
]
=
Pkey
;
//std::cerr << "in SGXWalletServer encr key x " << keys.at(0) << std::endl;
return
result
;
}
Json
::
Value
SGXWalletServer
::
generateECDSAKey
(
const
std
::
string
&
_keyName
)
{
return
generateECDSAKeyImpl
(
_keyName
);
}
Json
::
Value
SGXWalletServer
::
ecdsaSignMessageHash
(
const
std
::
string
&
_keyName
,
const
std
::
string
&
messageHash
)
{
return
ecdsaSignMessageHashImpl
(
_keyName
,
messageHash
);
Json
::
Value
SGXWalletServer
::
getPublicECDSAKey
(
const
std
::
string
&
_keyName
)
{
return
getPublicECDSAKeyImpl
(
_keyName
);
}
Json
::
Value
SGXWalletServer
::
ecdsaSignMessageHash
(
int
base
,
const
std
::
string
&
_keyName
,
const
std
::
string
&
messageHash
)
{
std
::
cerr
<<
"entered ecdsaSignMessageHash"
<<
std
::
endl
;
return
ecdsaSignMessageHashImpl
(
base
,
_keyName
,
messageHash
);
}
Json
::
Value
...
...
@@ -265,7 +297,7 @@ shared_ptr <std::string> readECDSAKey(const string &_keyName) {
auto
keyStr
=
levelDb
->
readString
(
"ECDSAKEY:"
+
_keyName
);
if
(
keyStr
==
nullptr
)
{
throw
RPCException
(
KEY_SHARE_DOES_NOT_EXIST
,
"Key
share
with this name does not exists"
);
throw
RPCException
(
KEY_SHARE_DOES_NOT_EXIST
,
"Key with this name does not exists"
);
}
return
keyStr
;
...
...
SGXWalletServer.hpp
View file @
6f2c10f1
...
...
@@ -14,6 +14,7 @@ class SGXWalletServer : public AbstractStubServer {
SGXWalletServer
*
server
=
nullptr
;
public
:
SGXWalletServer
(
AbstractServerConnector
&
connector
,
serverVersion_t
type
);
...
...
@@ -21,16 +22,11 @@ public:
virtual
Json
::
Value
blsSignMessageHash
(
const
std
::
string
&
keyShareName
,
const
std
::
string
&
messageHash
);
virtual
Json
::
Value
importECDSAKey
(
const
std
::
string
&
key
,
const
std
::
string
&
keyName
);
virtual
Json
::
Value
generateECDSAKey
(
const
std
::
string
&
keyName
);
virtual
Json
::
Value
ecdsaSignMessageHash
(
const
std
::
string
&
keyShareName
,
const
std
::
string
&
messageHash
);
virtual
Json
::
Value
ecdsaSignMessageHash
(
int
base
,
const
std
::
string
&
keyShareName
,
const
std
::
string
&
messageHash
);
virtual
Json
::
Value
getPublicECDSAKey
(
const
std
::
string
&
keyName
);
};
void
writeKeyShare
(
const
string
&
_keyShareName
,
const
string
&
value
,
int
index
,
int
n
,
int
t
);
shared_ptr
<
std
::
string
>
readKeyShare
(
const
string
&
_keyShare
);
...
...
@@ -44,8 +40,8 @@ Json::Value importBLSKeyShareImpl(int index, const std::string& keyShare, const
Json
::
Value
blsSignMessageHashImpl
(
const
std
::
string
&
keyShareName
,
const
std
::
string
&
messageHash
);
Json
::
Value
importECDSAKeyImpl
(
const
std
::
string
&
key
,
const
std
::
string
&
keyName
);
Json
::
Value
generateECDSAKeyImpl
(
const
std
::
string
&
keyName
);
Json
::
Value
ecdsaSignMessageHashImpl
(
const
std
::
string
&
keyName
,
const
std
::
string
&
messageHash
);
Json
::
Value
ecdsaSignMessageHashImpl
(
int
base
,
const
std
::
string
&
keyName
,
const
std
::
string
&
messageHash
);
Json
::
Value
getPublicECDSAKeyImpl
(
const
std
::
string
&
keyName
);
...
...
abstractstubserver.h
View file @
6f2c10f1
...
...
@@ -16,7 +16,8 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"blsSignMessageHash"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"keyShareName"
,
jsonrpc
::
JSON_STRING
,
"messageHash"
,
jsonrpc
::
JSON_STRING
,
NULL
),
&
AbstractStubServer
::
blsSignMessageHashI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"importECDSAKey"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"key"
,
jsonrpc
::
JSON_STRING
,
"keyName"
,
jsonrpc
::
JSON_STRING
,
NULL
),
&
AbstractStubServer
::
importECDSAKeyI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"generateECDSAKey"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"keyName"
,
jsonrpc
::
JSON_STRING
,
NULL
),
&
AbstractStubServer
::
generateECDSAKeyI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"ecdsaSignMessageHash"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"keyShareName"
,
jsonrpc
::
JSON_STRING
,
"messageHash"
,
jsonrpc
::
JSON_STRING
,
NULL
),
&
AbstractStubServer
::
ecdsaSignMessageHashI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"getPublicECDSAKey"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"keyName"
,
jsonrpc
::
JSON_STRING
,
NULL
),
&
AbstractStubServer
::
getPublicECDSAKeyI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"ecdsaSignMessageHash"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"base"
,
jsonrpc
::
JSON_INTEGER
,
"keyName"
,
jsonrpc
::
JSON_STRING
,
"messageHash"
,
jsonrpc
::
JSON_STRING
,
NULL
),
&
AbstractStubServer
::
ecdsaSignMessageHashI
);
}
inline
virtual
void
importBLSKeyShareI
(
const
Json
::
Value
&
request
,
Json
::
Value
&
response
)
...
...
@@ -35,15 +36,20 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
{
response
=
this
->
generateECDSAKey
(
request
[
"keyName"
].
asString
());
}
inline
virtual
void
getPublicECDSAKeyI
(
const
Json
::
Value
&
request
,
Json
::
Value
&
response
)
{
response
=
this
->
getPublicECDSAKey
(
request
[
"keyName"
].
asString
());
}
inline
virtual
void
ecdsaSignMessageHashI
(
const
Json
::
Value
&
request
,
Json
::
Value
&
response
)
{
response
=
this
->
ecdsaSignMessageHash
(
request
[
"
keyShare
Name"
].
asString
(),
request
[
"messageHash"
].
asString
());
response
=
this
->
ecdsaSignMessageHash
(
request
[
"
base"
].
asInt
(),
request
[
"key
Name"
].
asString
(),
request
[
"messageHash"
].
asString
());
}
virtual
Json
::
Value
importBLSKeyShare
(
int
index
,
const
std
::
string
&
keyShare
,
const
std
::
string
&
keyShareName
,
int
n
,
int
t
)
=
0
;
virtual
Json
::
Value
blsSignMessageHash
(
const
std
::
string
&
keyShareName
,
const
std
::
string
&
messageHash
)
=
0
;
virtual
Json
::
Value
importECDSAKey
(
const
std
::
string
&
key
,
const
std
::
string
&
keyName
)
=
0
;
virtual
Json
::
Value
generateECDSAKey
(
const
std
::
string
&
keyName
)
=
0
;
virtual
Json
::
Value
ecdsaSignMessageHash
(
const
std
::
string
&
keyShareName
,
const
std
::
string
&
messageHash
)
=
0
;
virtual
Json
::
Value
getPublicECDSAKey
(
const
std
::
string
&
keyName
)
=
0
;
virtual
Json
::
Value
ecdsaSignMessageHash
(
int
base
,
const
std
::
string
&
keyName
,
const
std
::
string
&
messageHash
)
=
0
;
};
#endif //JSONRPC_CPP_STUB_ABSTRACTSTUBSERVER_H_
secure_enclave/.deps/secure_enclave.Po
View file @
6f2c10f1
secure_enclave.o: secure_enclave.c \
../intel-sgx-ssl/Linux/package/include/openssl/ecdsa.h \
../intel-sgx-ssl/Linux/package/include/openssl/ec.h \
../intel-sgx-ssl/Linux/package/include/openssl/opensslconf.h \
../intel-sgx-ssl/Linux/package/include/openssl/opensslv.h \
../intel-sgx-ssl/Linux/package/include/openssl/asn1.h \
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/time.h \
secure_enclave.o: secure_enclave.c secure_enclave_t.h \
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/stdint.h \
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/sys/stdint.h \
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/sys/cdefs.h \
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/sys/_types.h \
../intel-sgx-ssl/Linux/package/include/openssl/e_os2.h \
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/inttypes.h \
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/sys/stdint.h \
../intel-sgx-ssl/Linux/package/include/openssl/bio.h \
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/stdarg.h \
../intel-sgx-ssl/Linux/package/include/openssl/crypto.h \
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/stdlib.h \
../intel-sgx-ssl/Linux/package/include/openssl/safestack.h \
../intel-sgx-ssl/Linux/package/include/openssl/stack.h \
../intel-sgx-ssl/Linux/package/include/openssl/ossl_typ.h \
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/limits.h \
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/sys/limits.h \
../intel-sgx-ssl/Linux/package/include/openssl/cryptoerr.h \
../intel-sgx-ssl/Linux/package/include/openssl/symhacks.h \
../intel-sgx-ssl/Linux/package/include/pthread.h \
../intel-sgx-ssl/Linux/package/include/openssl/bioerr.h \
../intel-sgx-ssl/Linux/package/include/openssl/asn1err.h \
../intel-sgx-ssl/Linux/package/include/openssl/bn.h \
../intel-sgx-ssl/Linux/package/include/openssl/bnerr.h \
../intel-sgx-ssl/Linux/package/include/openssl/ecerr.h \
../intel-sgx-ssl/Linux/package/include/openssl/evp.h \
../intel-sgx-ssl/Linux/package/include/openssl/evperr.h \
../intel-sgx-ssl/Linux/package/include/openssl/objects.h \
../intel-sgx-ssl/Linux/package/include/openssl/obj_mac.h \
../intel-sgx-ssl/Linux/package/include/openssl/objectserr.h \
../intel-sgx-ssl/Linux/package/include/openssl/err.h \
../intel-sgx-ssl/Linux/package/include/openssl/lhash.h \
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/errno.h \
../intel-sgx-ssl/Linux/package/include/openssl/rand.h \
../intel-sgx-ssl/Linux/package/include/openssl/randerr.h \
../intel-sgx-ssl/Linux/package/include/tSgxSSL_api.h secure_enclave_t.h \
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/stdint.h \
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/wchar.h \
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/stddef.h \
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/sgx_edger8r.h \
...
...
@@ -46,6 +10,9 @@ secure_enclave.o: secure_enclave.c \
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/sgx_error.h \
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/sgx_eid.h \
/home/kladko/sgxwallet/tgmp-build/include/sgx_tgmp.h \
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/limits.h \
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/sys/limits.h \
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/stdlib.h \
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/sgx_tcrypto.h \
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/sgx.h \
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/sgx_attributes.h \
...
...
@@ -58,94 +25,23 @@ secure_enclave.o: secure_enclave.c \
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/float.h \
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/string.h \
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/stdio.h \
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/stdarg.h \
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/stdbool.h \
domain_parameters.h point.h signature.h curves.h ../sgxwallet_common.h \
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/unistd.h \
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/sys/types.h \
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/sys/endian.h
../intel-sgx-ssl/Linux/package/include/openssl/ecdsa.h:
../intel-sgx-ssl/Linux/package/include/openssl/ec.h:
../intel-sgx-ssl/Linux/package/include/openssl/opensslconf.h:
../intel-sgx-ssl/Linux/package/include/openssl/opensslv.h:
secure_enclave_t.h:
../intel-sgx-ssl/Linux/package/include/openssl/asn1
.h:
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/stdint
.h:
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/
time
.h:
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/
sys/stdint
.h:
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/sys/cdefs.h:
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/sys/_types.h:
../intel-sgx-ssl/Linux/package/include/openssl/e_os2.h:
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/inttypes.h:
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/sys/stdint.h:
../intel-sgx-ssl/Linux/package/include/openssl/bio.h:
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/stdarg.h:
../intel-sgx-ssl/Linux/package/include/openssl/crypto.h:
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/stdlib.h:
../intel-sgx-ssl/Linux/package/include/openssl/safestack.h:
../intel-sgx-ssl/Linux/package/include/openssl/stack.h:
../intel-sgx-ssl/Linux/package/include/openssl/ossl_typ.h:
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/limits.h:
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/sys/limits.h:
../intel-sgx-ssl/Linux/package/include/openssl/cryptoerr.h:
../intel-sgx-ssl/Linux/package/include/openssl/symhacks.h:
../intel-sgx-ssl/Linux/package/include/pthread.h:
../intel-sgx-ssl/Linux/package/include/openssl/bioerr.h:
../intel-sgx-ssl/Linux/package/include/openssl/asn1err.h:
../intel-sgx-ssl/Linux/package/include/openssl/bn.h:
../intel-sgx-ssl/Linux/package/include/openssl/bnerr.h:
../intel-sgx-ssl/Linux/package/include/openssl/ecerr.h:
../intel-sgx-ssl/Linux/package/include/openssl/evp.h:
../intel-sgx-ssl/Linux/package/include/openssl/evperr.h:
../intel-sgx-ssl/Linux/package/include/openssl/objects.h:
../intel-sgx-ssl/Linux/package/include/openssl/obj_mac.h:
../intel-sgx-ssl/Linux/package/include/openssl/objectserr.h:
../intel-sgx-ssl/Linux/package/include/openssl/err.h:
../intel-sgx-ssl/Linux/package/include/openssl/lhash.h:
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/errno.h:
../intel-sgx-ssl/Linux/package/include/openssl/rand.h:
../intel-sgx-ssl/Linux/package/include/openssl/randerr.h:
../intel-sgx-ssl/Linux/package/include/tSgxSSL_api.h:
secure_enclave_t.h:
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/stdint.h:
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/wchar.h:
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/stddef.h:
...
...
@@ -160,6 +56,12 @@ secure_enclave_t.h:
/home/kladko/sgxwallet/tgmp-build/include/sgx_tgmp.h:
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/limits.h:
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/sys/limits.h:
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/stdlib.h:
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/sgx_tcrypto.h:
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/sgx.h:
...
...
@@ -184,6 +86,8 @@ secure_enclave_t.h:
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/stdio.h:
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/stdarg.h:
/home/kladko/sgxwallet/sgx-sdk-build/sgxsdk/include/tlibc/stdbool.h:
domain_parameters.h:
...
...
secure_enclave/BLSEnclave.cpp
View file @
6f2c10f1
...
...
@@ -171,6 +171,18 @@ bool enclave_sign(const char *_keyString, const char *_hashXString, const char *
}
void
carray2Hex
(
const
unsigned
char
*
d
,
int
_len
,
char
*
_hexArray
)
{
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
++
)
{
_hexArray
[
j
*
2
]
=
hexval
[((
d
[
j
]
>>
4
)
&
0xF
)];
_hexArray
[
j
*
2
+
1
]
=
hexval
[(
d
[
j
])
&
0x0F
];
}
_hexArray
[
_len
*
2
]
=
0
;
}
secure_enclave/DKGUtils.h
View file @
6f2c10f1
...
...
@@ -17,5 +17,6 @@ EXTERNC void calc_secret_shares(const char* decrypted_koefs, char * secret_share
unsigned
_t
,
unsigned
_n
);
EXTERNC
void
calc_public_shares
(
const
char
*
decrypted_koefs
,
char
*
public_shares
,
unsigned
_t
);
#endif //SGXD_DKGUTILS_H
secure_enclave/Makefile.am
View file @
6f2c10f1
...
...
@@ -115,7 +115,7 @@ secure_enclave_LDADD = @SGX_ENCLAVE_LDADD@
## --startgroup and --endgroup flags. (This would be where you'd add
## SGXSSL libraries, and your trusted c++ library
SGX_EXTRA_TLIBS
=
-lsgx_tgmp
-lsgx_tservice
-lsgx_urts
-lsgx_tcxx
-lsgx_tcrypto
SGX_EXTRA_TLIBS
=
-lsgx_tgmp
-lsgx_tservice
-lsgx_urts
-lsgx_tcxx
...
...
secure_enclave/Makefile.in
View file @
6f2c10f1
...
...
@@ -349,7 +349,7 @@ secure_enclave_SOURCES = secure_enclave_t.c secure_enclave_t.h \
../trusted_libff/libff/algebra/curves/alt_bn128/alt_bn128_g1.cpp
$(ENCLAVE_KEY)
$(ENCLAVE_CONFIG)
secure_enclave_LDADD
=
@SGX_ENCLAVE_LDADD@
SGX_EXTRA_TLIBS
=
-lsgx_tgmp
-lsgx_tservice
-lsgx_urts
-lsgx_tcxx
-lsgx_tcrypto
SGX_EXTRA_TLIBS
=
-lsgx_tgmp
-lsgx_tservice
-lsgx_urts
-lsgx_tcxx
all
:
all-am
.SUFFIXES
:
...
...
secure_enclave/secure_enclave.c
View file @
6f2c10f1
...
...
@@ -31,13 +31,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <openssl/ecdsa.h>
/*
#include <openssl/ecdsa.h>
#include <openssl/ec.h>
#include <openssl/bn.h>
#include <openssl/evp.h>
#include <openssl/err.h>
#include <openssl/rand.h>
#include "tSgxSSL_api.h"
#include "tSgxSSL_api.h"
*/
#include "secure_enclave_t.h"
#include "sgx_tcrypto.h"
...
...
@@ -56,7 +56,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "curves.h"
#include <string.h>
#include <sgx_tcrypto.h>
#include "../sgxwallet_common.h"
...
...
@@ -135,7 +134,7 @@ void generate_ecdsa_key(int *err_status, char *err_string,
domain_parameters_load_curve
(
curve
,
secp256k1
);
unsigned
char
*
rand_char
=
(
unsigned
char
*
)
malloc
(
32
);
sgx_read_rand
(
(
unsigned
char
*
)
rand_char
,
32
);
sgx_read_rand
(
rand_char
,
32
);
mpz_t
seed
;
mpz_init
(
seed
);
...
...
@@ -145,11 +144,11 @@ void generate_ecdsa_key(int *err_status, char *err_string,
mpz_t
skey
;
mpz_init
(
skey
);
mpz_mod
(
skey
,
seed
,
curve
->
p
);
//
mpz_mod(skey, seed, curve->p);
mpz_clear
(
seed
);
//mpz_set_str(skey, "4160780231445160889237664391382223604184857153814275770598791864649971919844", 10);
mpz_set_str
(
skey
,
"1"
,
10
);
//Public key
point
Pkey
=
point_init
();
...
...
@@ -162,7 +161,8 @@ void generate_ecdsa_key(int *err_status, char *err_string,
//snprintf(err_string, BUF_LEN, "len = %d\n", len);
char
arr_x
[
len
];
char
*
px
=
mpz_get_str
(
arr_x
,
base
,
Pkey
->
x
);
//snprintf(err_string, BUF_LEN, "arr=%p px=%p\n", arr_x, px);
// snprintf(err_string, BUF_LEN, "arr=%p px=%p\n", arr_x, px);
//snprintf(err_string, BUF_LEN, "x len %d\n", strlen(px));
strncpy
(
pub_key_x
,
arr_x
,
1024
);
...
...
@@ -172,7 +172,7 @@ void generate_ecdsa_key(int *err_status, char *err_string,
char
skey_str
[
mpz_sizeinbase
(
skey
,
10
)
+
2
];
char
*
s
=
mpz_get_str
(
skey_str
,
10
,
skey
);
// snprintf(err_string, BUF_LEN, "skey is %s\n", skey_str);
// snprintf(err_string, BUF_LEN, "skey is %s\n", skey_str);
uint32_t
sealedLen
=
sgx_calc_sealed_data_size
(
0
,
39
);
...
...
@@ -190,6 +190,56 @@ void generate_ecdsa_key(int *err_status, char *err_string,
}
void
get_public_ecdsa_key
(
int
*
err_status
,
char
*
err_string
,
uint8_t
*
encrypted_key
,
uint32_t
dec_len
,
char
*
pub_key_x
,
char
*
pub_key_y
)
{
//uint32_t dec_len = 0;
domain_parameters
curve
=
domain_parameters_init
();
domain_parameters_load_curve
(
curve
,
secp256k1
);
char
skey
[
SGX_ECP256_KEY_SIZE
];
//uint8_t decr_bytes[SGX_ECP256_KEY_SIZE];
sgx_status_t
status
=
sgx_unseal_data
(
(
const
sgx_sealed_data_t
*
)
encrypted_key
,
NULL
,
0
,
(
uint8_t
*
)
skey
,
&
dec_len
);
if
(
status
!=
SGX_SUCCESS
)
{
snprintf
(
err_string
,
BUF_LEN
,
"sgx_unseal_data failed with status %d"
,
status
);
return
;
}
//strncpy(err, arr_x, 1024);
mpz_t
skey_mpz
;
mpz_init
(
skey_mpz
);
mpz_set_str
(
skey_mpz
,
skey
,
16
);
//Public key
point
Pkey
=
point_init
();
signature_generate_key
(
Pkey
,
skey_mpz
,
curve
);
int
base
=
16
;
int
len
=
mpz_sizeinbase
(
Pkey
->
x
,
base
)
+
2
;
//snprintf(err_string, BUF_LEN, "len = %d\n", len);
char
arr_x
[
len
];
char
*
px
=
mpz_get_str
(
arr_x
,
base
,
Pkey
->
x
);
//snprintf(err_string, BUF_LEN, "arr=%p px=%p\n", arr_x, px);
strncpy
(
pub_key_x
,
arr_x
,
1024
);
char
arr_y
[
mpz_sizeinbase
(
Pkey
->
y
,
base
)
+
2
];
char
*
py
=
mpz_get_str
(
arr_y
,
base
,
Pkey
->
y
);
strncpy
(
pub_key_y
,
arr_y
,
1024
);
mpz_clear
(
skey_mpz
);
domain_parameters_clear
(
curve
);
point_clear
(
Pkey
);
}
void
encrypt_key
(
int
*
err_status
,
char
*
err_string
,
char
*
key
,
uint8_t
*
encrypted_key
,
uint32_t
*
enc_len
)
{
...
...
@@ -381,8 +431,8 @@ void get_public_shares(int *err_status, char* err_string, uint8_t* encrypted_dkg
calc_public_shares
(
decrypted_dkg_secret
,
public_shares
,
_t
);
}
void
ecdsa_sign1
(
int
*
err_status
,
char
*
err_string
,
uint8_t
*
encrypted_key
,
uint32_t
dec_len
,
unsigned
char
*
hash
,
char
*
sig_r
,
char
*
sig_s
,
char
*
sig_v
)
{
void
ecdsa_sign1
(
int
*
err_status
,
char
*
err_string
,
uint8_t
*
encrypted_key
,
uint32_t
dec_len
,
unsigned
char
*
hash
,
char
*
sig_r
,
char
*
sig_s
,
uint8_t
sig_v
,
int
base
)
{
domain_parameters
curve
=
domain_parameters_init
();
domain_parameters_load_curve
(
curve
,
secp256k1
);
...
...
@@ -399,7 +449,7 @@ void ecdsa_sign1(int *err_status, char *err_string, uint8_t *encrypted_key,
mpz_t
skey_mpz
;
mpz_init
(
skey_mpz
);
mpz_set_str
(
skey_mpz
,
skey
,
10
);
mpz_set_str
(
skey_mpz
,
skey
,
base
);
/*mpz_t test_skey;
mpz_init(test_skey);
...
...
@@ -411,7 +461,7 @@ void ecdsa_sign1(int *err_status, char *err_string, uint8_t *encrypted_key,
mpz_t
msg_mpz
;
mpz_init
(
msg_mpz
);
mpz_set_str
(
msg_mpz
,
skey
,
10
);
mpz_set_str
(
msg_mpz
,
skey
,
base
);
signature
sign
=
signature_init
();
...
...
@@ -426,8 +476,6 @@ void ecdsa_sign1(int *err_status, char *err_string, uint8_t *encrypted_key,
return
;
}
uint8_t
base
=
16
;
char
arr_r
[
mpz_sizeinbase
(
sign
->
r
,
base
)
+
2
];
char
*
r
=
mpz_get_str
(
arr_r
,
base
,
sign
->
r
);
strncpy
(
sig_r
,
arr_r
,
1024
);
...
...
@@ -436,11 +484,7 @@ void ecdsa_sign1(int *err_status, char *err_string, uint8_t *encrypted_key,
char
*
s
=
mpz_get_str
(
arr_s
,
base
,
sign
->
s
);
strncpy
(
sig_s
,
arr_s
,
1024
);
sig_v
[
0
]
=
'0'
;
sig_v
[
1
]
=
'x'
;
sig_v
[
2
]
=
'1'
;
sig_v
[
3
]
=
'b'
;
sig_v
=
0
;
mpz_t
rem
;
mpz_init
(
rem
);
mpz_mod_ui
(
rem
,
sign
->
r
,
2
);
...
...
@@ -448,13 +492,13 @@ void ecdsa_sign1(int *err_status, char *err_string, uint8_t *encrypted_key,
int
r_gr_n
=
mpz_cmp
(
sign
->
r
,
curve
->
n
);
if
(
mpz_sgn
(
rem
)
&&
r_gr_n
<
0
){
sig_v
[
3
]
=
'c'
;
sig_v
=
1
;
}
else
if
(
mpz_sgn
(
rem
)
>
0
&&
r_gr_n
>
0
){
sig_v
[
3
]
=
'e'
;
sig_v
=
3
;
}
else
if
(
mpz_sgn
(
rem
)
==
0
&&
r_gr_n
>
0
){
sig_v
[
3
]
=
'd'
;
sig_v
=
2
;
}
mpz_clear
(
skey_mpz
);
...
...
@@ -462,5 +506,7 @@ void ecdsa_sign1(int *err_status, char *err_string, uint8_t *encrypted_key,
mpz_clear
(
rem
);
domain_parameters_clear
(
curve
);
signature_clear
(
sign
);
point_clear
(
Pkey
);
}
secure_enclave/secure_enclave.edl
View file @
6f2c10f1
...
...
@@ -26,11 +26,18 @@ from "sgx_tsgxssl.edl" import *;
public void generate_ecdsa_key (
[user_check] int *err_status,
[out, count = 1024] char* err_string,
[out, count =
2048
] uint8_t* encrypted_key,
[out, count =
1024
] uint8_t* encrypted_key,
[user_check] uint32_t *enc_len,
[out, count = 1024] char * pub_key_x,
[out, count = 1024] char * pub_key_y);
public void get_public_ecdsa_key (
[user_check] int *err_status,
[out, count = 1024] char* err_string,
[in, count = 1024] uint8_t* encrypted_key,
uint32_t dec_len,
[out, count = 1024] char * pub_key_x,
[out, count = 1024] char * pub_key_y);
public void encrypt_key (
[user_check] int *err_status,
...
...
@@ -88,13 +95,14 @@ from "sgx_tsgxssl.edl" import *;
public void ecdsa_sign1(
[user_check] int *err_status,
[out, count =
2048
] char* err_string,
[in, count =
2048
] uint8_t* encrypted_key,
uint32_t
de
c_len,
[out, count =
1024
] char* err_string,
[in, count =
1024
] uint8_t* encrypted_key,
uint32_t
en
c_len,
[in, count = 1024] unsigned char* hash,
[out, count = 1024] char* sig_r,
[out, count = 1024] char* sig_s,
[out, count = 4] char* sig_v);
uint8_t sig_v,
int base);
};
...
...
secure_enclave/signature.c
View file @
6f2c10f1
...
...
@@ -86,22 +86,22 @@ void signature_sign(signature sig, mpz_t message, mpz_t private_key, domain_para
mpz_t
t3
;
mpz_init
(
t3
);
mpz_t
s
;
mpz_init
(
s
);
unsigned
char
*
rand_char
=
(
unsigned
char
*
)
malloc
(
32
);
sgx_read_rand
(
rand_char
,
32
);
unsigned
char
*
rand_char
=
(
unsigned
char
*
)
malloc
(
32
);
sgx_read_rand
(
rand_char
,
32
);
gmp_randstate_t
r_state
;
signature_sign_start:
//Set k
sgx_read_rand
(
rand_char
,
32
);
mpz_t
seed
;
mpz_init
(
seed
);
mpz_import
(
seed
,
32
,
1
,
sizeof
(
rand_char
[
0
]),
0
,
0
,
rand_char
);
free
(
rand_char
);
mpz_mod
(
k
,
seed
,
curve
->
p
);
mpz_clear
(
seed
);
sgx_read_rand
(
rand_char
,
32
);
mpz_t
seed
;
mpz_init
(
seed
);
mpz_import
(
seed
,
32
,
1
,
sizeof
(
rand_char
[
0
]),
0
,
0
,
rand_char
);
free
(
rand_char
);
mpz_mod
(
k
,
seed
,
curve
->
p
);
mpz_clear
(
seed
);
//Calculate x
point_multiplication
(
Q
,
k
,
curve
->
G
,
curve
);
...
...
sgxwallet.c
View file @
6f2c10f1
...
...
@@ -50,6 +50,7 @@ int updated;
int
main
(
int
argc
,
char
*
argv
[])
{
int
opt
;
while
((
opt
=
getopt
(
argc
,
argv
,
"h"
))
!=
-
1
)
{
...
...
@@ -68,6 +69,8 @@ int main(int argc, char *argv[]) {
init_all
();
while
(
true
)
{
sleep
(
10
);
}
...
...
sgxwallet_common.h
View file @
6f2c10f1
...
...
@@ -28,6 +28,7 @@
#define DKG_BUFER_LENGTH 1250
#define DKG_MAX_SEALED_LEN 2000
#define ECDSA_LEN 1024
#define UNKNOWN_ERROR -1
#define PLAINTEXT_KEY_TOO_LONG -2
...
...
spec.json
View file @
6f2c10f1
...
...
@@ -56,13 +56,24 @@
}
},
{
"name"
:
"getPublicECDSAKey"
,
"params"
:
{
"keyName"
:
"key1"
},
"returns"
:
{
"status"
:
0
,
"errorMessage"
:
"12345"
,
"PublicKey"
:
"12345"
}
},
{
"name"
:
"ecdsaSignMessageHash"
,
"params"
:
{
"keyName"
:
"key1"
,
"messageHash"
:
"1122334455"
"messageHash"
:
"1122334455"
,
"base"
:
10
},
"returns"
:
{
"status"
:
0
,
...
...
stubclient.h
View file @
6f2c10f1
...
...
@@ -58,10 +58,21 @@ class StubClient : public jsonrpc::Client
else
throw
jsonrpc
::
JsonRpcException
(
jsonrpc
::
Errors
::
ERROR_CLIENT_INVALID_RESPONSE
,
result
.
toStyledString
());
}
Json
::
Value
ecdsaSignMessageHash
(
const
std
::
string
&
keyShareName
,
const
std
::
string
&
messageHash
)
throw
(
jsonrpc
::
JsonRpcException
)
Json
::
Value
getPublicECDSAKey
(
const
std
::
string
&
keyName
)
throw
(
jsonrpc
::
JsonRpcException
)
{
Json
::
Value
p
;
p
[
"keyShareName"
]
=
keyShareName
;
p
[
"keyName"
]
=
keyName
;
Json
::
Value
result
=
this
->
CallMethod
(
"getPublicECDSAKey"
,
p
);
if
(
result
.
isObject
())
return
result
;
else
throw
jsonrpc
::
JsonRpcException
(
jsonrpc
::
Errors
::
ERROR_CLIENT_INVALID_RESPONSE
,
result
.
toStyledString
());
}
Json
::
Value
ecdsaSignMessageHash
(
int
base
,
const
std
::
string
&
keyName
,
const
std
::
string
&
messageHash
)
throw
(
jsonrpc
::
JsonRpcException
)
{
Json
::
Value
p
;
p
[
"base"
]
=
base
;
p
[
"keyName"
]
=
keyName
;
p
[
"messageHash"
]
=
messageHash
;
Json
::
Value
result
=
this
->
CallMethod
(
"ecdsaSignMessageHash"
,
p
);
if
(
result
.
isObject
())
...
...
testw.cpp
View file @
6f2c10f1
...
...
@@ -293,6 +293,8 @@ TEST_CASE( "DKG gen test", "[dkg-gen]" ) {
free
(
errMsg1
);
free
(
encrypted_dkg_secret
);
free
(
secret
);
sgx_destroy_enclave
(
eid
);
}
std
::
vector
<
libff
::
alt_bn128_Fr
>
SplitStringToFr
(
const
char
*
koefs
,
const
char
*
symbol
){
...
...
@@ -316,10 +318,10 @@ std::vector<libff::alt_bn128_Fr> SplitStringToFr(const char* koefs, const char*
return
tokens
;
}
/*TEST_CASE( "DKG auto secret shares test", "[dkg-s_shares]" ) {
init_all();
TEST_CASE
(
"DKG auto secret shares test"
,
"[dkg-s_shares]"
)
{
//init_all();
init_enclave
();
uint8_t
*
encrypted_dkg_secret
=
(
uint8_t
*
)
calloc
(
DKG_MAX_SEALED_LEN
,
1
);
char
*
errMsg
=
(
char
*
)
calloc
(
1024
,
1
);
...
...
@@ -355,25 +357,38 @@ std::vector<libff::alt_bn128_Fr> SplitStringToFr(const char* koefs, const char*
std
::
vector
<
libff
::
alt_bn128_Fr
>
poly
=
SplitStringToFr
((
char
*
)
secret
,
&
colon
);
std
::
vector
<
libff
::
alt_bn128_Fr
>
s_shares_dkg
=
dkg_obj
.
SecretKeyContribution
(
SplitStringToFr
((
char
*
)
secret
,
&
colon
));
printf
(
"calculated secret:
\n
"
);
for
(
int
i
=
0
;
i
<
s_shares_dkg
.
size
();
i
++
){
libff
::
alt_bn128_Fr
cur_share
=
s_shares_dkg
.
at
(
i
);
mpz_t
(
sshare
);
mpz_init
(
sshare
);
cur_share
.
as_bigint
().
to_mpz
(
sshare
);
char
arr
[
mpz_sizeinbase
(
sshare
,
10
)
+
2
];
char
*
share_str
=
mpz_get_str
(
arr
,
10
,
sshare
);
printf
(
" %s
\n
"
,
share_str
);
mpz_clear
(
sshare
);
}
REQUIRE(s_shares == s_shares_dkg);
//
REQUIRE(s_shares == s_shares_dkg);
free
(
errMsg
);
free
(
errMsg1
);
free
(
encrypted_dkg_secret
);
free
(
secret_shares
);
}*/
sgx_destroy_enclave
(
eid
);
}
TEST_CASE
(
"ECDSA keygen and signature test"
,
"[ecdsa_test]"
)
{
init_
all
();
init_
enclave
();
char
*
errMsg
=
(
char
*
)
calloc
(
1024
,
1
);
int
err_status
=
0
;
uint8_t
*
encr_pr_key
=
(
uint8_t
*
)
calloc
(
1024
,
1
);
char
*
pub_key_x
=
(
char
*
)
calloc
(
1024
,
1
);
char
*
pub_key_y
=
(
char
*
)
calloc
(
1024
,
1
);
uint32_t
enc_len
=
0
;
...
...
@@ -381,29 +396,107 @@ TEST_CASE("ECDSA keygen and signature test", "[ecdsa_test]") {
//printf("before %p\n", pub_key_x);
status
=
generate_ecdsa_key
(
eid
,
&
err_status
,
errMsg
,
encr_pr_key
,
&
enc_len
,
pub_key_x
,
pub_key_y
);
printf
(
"
\n
errMsg %s
\n
"
,
errMsg
);
//
printf("\nerrMsg %s\n", errMsg );
REQUIRE
(
status
==
SGX_SUCCESS
);
printf
(
"
\n
pub_key_x %s:
\n
"
,
pub_key_x
);
printf
(
"
\n
pub_key_y %s:
\n
"
,
pub_key_y
);
printf
(
"
\n
encr priv_key
%s
:
\n
"
);
printf
(
"
\n
was
pub_key_x %s:
\n
"
,
pub_key_x
);
printf
(
"
\n
was
pub_key_y %s:
\n
"
,
pub_key_y
);
printf
(
"
\n
encr priv_key :
\n
"
);
for
(
int
i
=
0
;
i
<
1024
;
i
++
)
printf
(
"%u "
,
encr_pr_key
[
i
]);
char
*
hex
=
"38433e5ce087dcc1be82fcc834eae83c256b3db87d34f84440d0b708daa0c6f7"
;
char
*
signature_r
=
(
char
*
)
calloc
(
1024
,
1
);
char
*
signature_s
=
(
char
*
)
calloc
(
1024
,
1
);
char
*
signature_v
=
(
char
*
)
calloc
(
4
,
1
)
;
uint8_t
signature_v
=
0
;
status
=
ecdsa_sign1
(
eid
,
&
err_status
,
errMsg
,
encr_pr_key
,
enc_len
,
(
unsigned
char
*
)
hex
,
signature_r
,
signature_s
,
signature_v
);
status
=
ecdsa_sign1
(
eid
,
&
err_status
,
errMsg
,
encr_pr_key
,
enc_len
,
(
unsigned
char
*
)
hex
,
signature_r
,
signature_s
,
signature_v
,
10
);
REQUIRE
(
status
==
SGX_SUCCESS
);
printf
(
"
\n
signature r : %s "
,
signature_r
);
printf
(
"
\n
signature s: %s "
,
signature_s
);
printf
(
"
\n
signature v: %
s
"
,
signature_v
);
printf
(
"
\n
signature v: %
u
"
,
signature_v
);
printf
(
"
\n
%s
\n
"
,
errMsg
);
free
(
errMsg
);
sgx_destroy_enclave
(
eid
);
printf
(
"the end of ecdsa test
\n
"
);
}
TEST_CASE
(
"Test test"
,
"[test_test]"
)
{
init_enclave
();
char
*
errMsg
=
(
char
*
)
calloc
(
1024
,
1
);
int
err_status
=
0
;
uint8_t
*
encr_pr_key
=
(
uint8_t
*
)
calloc
(
1024
,
1
);
char
*
pub_key_x
=
(
char
*
)
calloc
(
1024
,
1
);
char
*
pub_key_y
=
(
char
*
)
calloc
(
1024
,
1
);
uint32_t
enc_len
=
0
;
status
=
generate_ecdsa_key
(
eid
,
&
err_status
,
errMsg
,
encr_pr_key
,
&
enc_len
,
pub_key_x
,
pub_key_y
);
//printf("\nerrMsg %s\n", errMsg );
REQUIRE
(
status
==
SGX_SUCCESS
);
//printf("\nwas pub_key_x %s: \n", pub_key_x);
//printf("\nwas pub_key_y %s: \n", pub_key_y);
//printf("\nencr priv_key %s: \n");
//for ( int i = 0; i < 1024 ; i++)
// printf("%u ", encr_pr_key[i]);
//printf( "haha");
//free(errMsg);
sgx_destroy_enclave
(
eid
);
}
TEST_CASE
(
"get public ECDSA key"
,
"[get_pub_ecdsa_key_test]"
)
{
//init_all();
init_enclave
();
char
*
errMsg
=
(
char
*
)
calloc
(
1024
,
1
);
int
err_status
=
0
;
uint8_t
*
encr_pr_key
=
(
uint8_t
*
)
calloc
(
1024
,
1
);
char
*
pub_key_x
=
(
char
*
)
calloc
(
1024
,
1
);
char
*
pub_key_y
=
(
char
*
)
calloc
(
1024
,
1
);
uint32_t
enc_len
=
0
;
//printf("before %p\n", pub_key_x);
status
=
generate_ecdsa_key
(
eid
,
&
err_status
,
errMsg
,
encr_pr_key
,
&
enc_len
,
pub_key_x
,
pub_key_y
);
printf
(
"
\n
errMsg %s
\n
"
,
errMsg
);
REQUIRE
(
status
==
SGX_SUCCESS
);
printf
(
"
\n
was pub_key_x %s:
\n
"
,
pub_key_x
);
printf
(
"
\n
was pub_key_y %s:
\n
"
,
pub_key_y
);
/*printf("\nencr priv_key %s: \n");
for ( int i = 0; i < 1024 ; i++)
printf("%u ", encr_pr_key[i]);*/
char
*
got_pub_key_x
=
(
char
*
)
calloc
(
1024
,
1
);
char
*
got_pub_key_y
=
(
char
*
)
calloc
(
1024
,
1
);
status
=
get_public_ecdsa_key
(
eid
,
&
err_status
,
errMsg
,
encr_pr_key
,
enc_len
,
got_pub_key_x
,
got_pub_key_y
);
REQUIRE
(
status
==
SGX_SUCCESS
);
printf
(
"
\n
now pub_key_x %s:
\n
"
,
got_pub_key_x
);
printf
(
"
\n
now pub_key_y %s:
\n
"
,
got_pub_key_y
);
printf
(
"
\n
err %s
\n
"
,
errMsg
);
free
(
errMsg
);
sgx_destroy_enclave
(
eid
);
}
#include "stubclient.h"
...
...
@@ -427,8 +520,9 @@ TEST_CASE("API test", "[api_test]") {
cerr
<<
"Client inited"
<<
endl
;
try
{
//cout << c.generateECDSAKey("test_key") << endl;
cout
<<
c
.
ecdsaSignMessageHash
(
"test_key"
,
"38433e5ce087dcc1be82fcc834eae83c256b3db87d34f84440d0b708daa0c6f7"
);
//cout << c.generateECDSAKey("new_key1") << endl;
//cout<<c.getPublicECDSAKey("test_key");
cout
<<
c
.
ecdsaSignMessageHash
(
16
,
"new_key1"
,
"38433e5ce087dcc1be82fcc834eae83c256b3db87d34f84440d0b708daa0c6f7"
);
}
catch
(
JsonRpcException
&
e
)
{
cerr
<<
e
.
what
()
<<
endl
;
}
...
...
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