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
964dac2b
Unverified
Commit
964dac2b
authored
Jan 24, 2020
by
svetaro
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SKALE-2003 Add backup key to ECDSA procedures
parent
3fb4836a
Changes
13
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
623 additions
and
71 deletions
+623
-71
BLSCrypto.cpp
BLSCrypto.cpp
+6
-3
ECDSACrypto.cpp
ECDSACrypto.cpp
+32
-9
SEKManager.cpp
SEKManager.cpp
+6
-6
SGXWalletServer.cpp
SGXWalletServer.cpp
+0
-1
AESUtils.c
secure_enclave/AESUtils.c
+38
-0
AESUtils.h
secure_enclave/AESUtils.h
+14
-0
Makefile.am
secure_enclave/Makefile.am
+1
-1
Makefile.in
secure_enclave/Makefile.in
+9
-5
enclave_common.h
secure_enclave/enclave_common.h
+38
-0
secure_enclave.c
secure_enclave/secure_enclave.c
+373
-9
secure_enclave.edl
secure_enclave/secure_enclave.edl
+70
-12
sgxwallet_common.h
sgxwallet_common.h
+1
-1
testw.cpp
testw.cpp
+35
-24
No files found.
BLSCrypto.cpp
View file @
964dac2b
...
...
@@ -185,10 +185,12 @@ char *encryptBLSKeyShare2Hex(int *errStatus, char *err_string, const char *_key)
unsigned
int
encryptedLen
=
0
;
status
=
encrypt_key
(
eid
,
errStatus
,
errMsg
,
keyArray
,
encryptedKey
,
&
encryptedLen
);
//status = encrypt_key(eid, errStatus, errMsg, keyArray, encryptedKey, &encryptedLen);
status
=
encrypt_key_aes
(
eid
,
errStatus
,
errMsg
,
keyArray
,
encryptedKey
,
&
encryptedLen
);
if
(
DEBUG_PRINT
)
{
spdlog
::
info
(
"errStatus is {}"
,
*
errStatus
,
" errMsg is "
,
errMsg
);
spdlog
::
info
(
"errStatus is {}"
,
*
errStatus
);
spdlog
::
info
(
" errMsg is "
,
errMsg
);
}
if
(
status
!=
SGX_SUCCESS
)
{
...
...
@@ -224,7 +226,8 @@ char *decryptBLSKeyShareFromHex(int *errStatus, char *errMsg, const char *_encry
char
*
plaintextKey
=
(
char
*
)
calloc
(
BUF_LEN
,
1
);
status
=
decrypt_key
(
eid
,
errStatus
,
errMsg
,
decoded
,
decodedLen
,
plaintextKey
);
//status = decrypt_key(eid, errStatus, errMsg, decoded, decodedLen, plaintextKey);
status
=
decrypt_key_aes
(
eid
,
errStatus
,
errMsg
,
decoded
,
decodedLen
,
plaintextKey
);
if
(
status
!=
SGX_SUCCESS
)
{
return
nullptr
;
...
...
ECDSACrypto.cpp
View file @
964dac2b
...
...
@@ -51,14 +51,21 @@ std::vector<std::string> gen_ecdsa_key(){
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
);
//status = generate_ecdsa_key(eid, &err_status, errMsg, encr_pr_key, &enc_len, pub_key_x, pub_key_y );
status
=
generate_ecdsa_key_aes
(
eid
,
&
err_status
,
errMsg
,
encr_pr_key
,
&
enc_len
,
pub_key_x
,
pub_key_y
);
if
(
err_status
!=
0
){
std
::
cerr
<<
"RPCException thrown"
<<
std
::
endl
;
throw
RPCException
(
-
666
,
errMsg
)
;
}
std
::
vector
<
std
::
string
>
keys
(
3
);
//std::cerr << "account key is " << errMsg << std::endl;
char
*
hexEncrKey
=
(
char
*
)
calloc
(
2
*
BUF_LEN
,
1
);
if
(
DEBUG_PRINT
)
{
std
::
cerr
<<
"account key is "
<<
errMsg
<<
std
::
endl
;
std
::
cerr
<<
"enc_len is "
<<
enc_len
<<
std
::
endl
;
std
::
cerr
<<
"enc_key is "
<<
std
::
endl
;
for
(
int
i
=
0
;
i
<
1024
;
i
++
)
std
::
cerr
<<
(
int
)
encr_pr_key
[
i
]
<<
" "
;
}
char
*
hexEncrKey
=
(
char
*
)
calloc
(
BUF_LEN
,
1
);
carray2Hex
(
encr_pr_key
,
enc_len
,
hexEncrKey
);
keys
.
at
(
0
)
=
hexEncrKey
;
keys
.
at
(
1
)
=
std
::
string
(
pub_key_x
)
+
std
::
string
(
pub_key_y
);
//concatPubKeyWith0x(pub_key_x, pub_key_y);//
...
...
@@ -69,6 +76,7 @@ std::vector<std::string> gen_ecdsa_key(){
unsigned
long
seed
=
rand_gen
();
if
(
DEBUG_PRINT
)
{
spdlog
::
info
(
"seed is {}"
,
seed
);
std
::
cerr
<<
"strlen is "
<<
strlen
(
hexEncrKey
)
<<
std
::
endl
;
}
gmp_randstate_t
state
;
gmp_randinit_default
(
state
);
...
...
@@ -105,26 +113,38 @@ std::string get_ecdsa_pubkey(const char* encryptedKeyHex){
char
*
pub_key_y
=
(
char
*
)
calloc
(
1024
,
1
);
uint64_t
enc_len
=
0
;
uint8_t
encr_pr_key
[
BUF_LEN
];
//uint8_t encr_pr_key[BUF_LEN];
uint8_t
*
encr_pr_key
=
(
uint8_t
*
)
calloc
(
1024
,
1
);
if
(
!
hex2carray
(
encryptedKeyHex
,
&
enc_len
,
encr_pr_key
)){
throw
RPCException
(
INVALID_HEX
,
"Invalid encryptedKeyHex"
);
}
status
=
get_public_ecdsa_key
(
eid
,
&
err_status
,
errMsg
,
encr_pr_key
,
enc_len
,
pub_key_x
,
pub_key_y
);
spdlog
::
info
(
"encr_hex_key is {}"
,
encryptedKeyHex
);
std
::
cerr
<<
"enc_key is "
<<
std
::
endl
;
for
(
int
i
=
0
;
i
<
BUF_LEN
;
i
++
)
std
::
cerr
<<
(
int
)
encr_pr_key
[
i
]
<<
" "
;
//status = get_public_ecdsa_key(eid, &err_status, errMsg, encr_pr_key, enc_len, pub_key_x, pub_key_y );
status
=
get_public_ecdsa_key_aes
(
eid
,
&
err_status
,
errMsg
,
encr_pr_key
,
enc_len
,
pub_key_x
,
pub_key_y
);
if
(
err_status
!=
0
){
throw
RPCException
(
-
666
,
errMsg
)
;
}
std
::
string
pubKey
=
std
::
string
(
pub_key_x
)
+
std
::
string
(
pub_key_y
);
//concatPubKeyWith0x(pub_key_x, pub_key_y);//
if
(
DEBUG_PRINT
)
{
spdlog
::
info
(
"enc_len is {}"
,
enc_len
);
spdlog
::
info
(
"pubkey is {}"
,
pubKey
);
spdlog
::
info
(
"pubkey length is {}"
,
pubKey
.
length
());
spdlog
::
info
(
"err str is {}"
,
errMsg
);
spdlog
::
info
(
"err status is {}"
,
err_status
);
}
free
(
errMsg
);
free
(
pub_key_x
);
free
(
pub_key_y
);
free
(
encr_pr_key
);
return
pubKey
;
}
...
...
@@ -134,12 +154,13 @@ std::vector<std::string> ecdsa_sign_hash(const char* encryptedKeyHex, const char
char
*
errMsg
=
(
char
*
)
calloc
(
1024
,
1
);
int
err_status
=
0
;
char
*
signature_r
=
(
char
*
)
malloc
(
1024
);
char
*
signature_s
=
(
char
*
)
malloc
(
1024
);
char
*
signature_r
=
(
char
*
)
calloc
(
1024
,
1
);
char
*
signature_s
=
(
char
*
)
calloc
(
1024
,
1
);
uint8_t
signature_v
=
0
;
uint64_t
dec_len
=
0
;
uint8_t
encr_key
[
BUF_LEN
];
//uint8_t encr_key[BUF_LEN];
uint8_t
*
encr_key
=
(
uint8_t
*
)
calloc
(
1024
,
1
);
if
(
!
hex2carray
(
encryptedKeyHex
,
&
dec_len
,
encr_key
)){
throw
RPCException
(
INVALID_HEX
,
"Invalid encryptedKeyHex"
);
}
...
...
@@ -150,7 +171,8 @@ std::vector<std::string> ecdsa_sign_hash(const char* encryptedKeyHex, const char
spdlog
::
info
(
"encrypted len: {}"
,
dec_len
);
}
status
=
ecdsa_sign1
(
eid
,
&
err_status
,
errMsg
,
encr_key
,
ECDSA_ENCR_LEN
,
(
unsigned
char
*
)
hashHex
,
signature_r
,
signature_s
,
&
signature_v
,
base
);
//status = ecdsa_sign1(eid, &err_status, errMsg, encr_key, ECDSA_ENCR_LEN, (unsigned char*)hashHex, signature_r, signature_s, &signature_v, base );
status
=
ecdsa_sign_aes
(
eid
,
&
err_status
,
errMsg
,
encr_key
,
dec_len
,
(
unsigned
char
*
)
hashHex
,
signature_r
,
signature_s
,
&
signature_v
,
base
);
if
(
err_status
!=
0
){
throw
RPCException
(
-
666
,
errMsg
)
;
}
...
...
@@ -176,6 +198,7 @@ std::vector<std::string> ecdsa_sign_hash(const char* encryptedKeyHex, const char
free
(
errMsg
);
free
(
signature_r
);
free
(
signature_s
);
free
(
encr_key
);
return
signature_vect
;
}
\ No newline at end of file
SEKManager.cpp
View file @
964dac2b
...
...
@@ -35,23 +35,23 @@ void generate_SEK(){
char
*
errMsg
=
(
char
*
)
calloc
(
1024
,
1
);
int
err_status
=
0
;
uint8_t
*
encr_
pr_key
=
(
uint8_t
*
)
calloc
(
1024
,
1
);
uint8_t
*
encr_
SEK
=
(
uint8_t
*
)
calloc
(
1024
,
1
);
uint32_t
enc_len
=
0
;
status
=
generate_SEK
(
eid
,
&
err_status
,
errMsg
,
encr_
pr_key
,
&
enc_len
);
status
=
generate_SEK
(
eid
,
&
err_status
,
errMsg
,
encr_
SEK
,
&
enc_len
);
if
(
err_status
!=
0
){
std
::
cerr
<<
"RPCException thrown"
<<
std
::
endl
;
throw
RPCException
(
-
666
,
errMsg
)
;
}
char
*
hexEncrKey
=
(
char
*
)
calloc
(
BUF_LEN
,
1
);
//carray2Hex(encr_pr_key
, enc_len, hexEncrKey);
char
*
hexEncrKey
=
(
char
*
)
calloc
(
2
*
enc_len
+
1
,
1
);
carray2Hex
(
encr_SEK
,
enc_len
,
hexEncrKey
);
std
::
cerr
<<
"key is "
<<
errMsg
<<
std
::
endl
;
//
levelDb->writeDataUnique("SEK", hexEncrKey);
levelDb
->
writeDataUnique
(
"SEK"
,
hexEncrKey
);
free
(
errMsg
);
free
(
encr_
pr_key
);
free
(
encr_
SEK
);
free
(
hexEncrKey
);
}
SGXWalletServer.cpp
View file @
964dac2b
...
...
@@ -275,7 +275,6 @@ Json::Value generateECDSAKeyImpl() {
spdlog
::
info
(
"key name generated: {}"
,
keyName
);
}
//writeECDSAKey(keyName, keys.at(0));
writeDataToDB
(
keyName
,
keys
.
at
(
0
));
result
[
"encryptedKey"
]
=
keys
.
at
(
0
);
...
...
secure_enclave/AESUtils.c
0 → 100644
View file @
964dac2b
//
// Created by kladko on 1/22/20.
//
#include "sgx_trts.h"
#include "sgx_tcrypto.h"
#include "stdlib.h"
#include <string.h>
#include "AESUtils.h"
int
AES_encrypt
(
char
*
message
,
uint8_t
*
encr_message
){
sgx_read_rand
(
encr_message
+
SGX_AESGCM_MAC_SIZE
,
SGX_AESGCM_IV_SIZE
);
sgx_status_t
status
=
sgx_rijndael128GCM_encrypt
(
&
AES_key
,
(
uint8_t
*
)
message
,
strlen
(
message
),
encr_message
+
SGX_AESGCM_MAC_SIZE
+
SGX_AESGCM_IV_SIZE
,
encr_message
+
SGX_AESGCM_MAC_SIZE
,
SGX_AESGCM_IV_SIZE
,
NULL
,
0
,
(
sgx_aes_gcm_128bit_tag_t
*
)
encr_message
);
return
status
;
}
int
AES_decrypt
(
uint8_t
*
encr_message
,
uint64_t
length
,
char
*
message
){
uint64_t
len
=
length
-
SGX_AESGCM_MAC_SIZE
-
SGX_AESGCM_IV_SIZE
;
sgx_status_t
status
=
sgx_rijndael128GCM_decrypt
(
&
AES_key
,
encr_message
+
SGX_AESGCM_MAC_SIZE
+
SGX_AESGCM_IV_SIZE
,
len
,
message
,
encr_message
+
SGX_AESGCM_MAC_SIZE
,
SGX_AESGCM_IV_SIZE
,
NULL
,
0
,
(
sgx_aes_gcm_128bit_tag_t
*
)
encr_message
);
return
status
;
}
\ No newline at end of file
secure_enclave/AESUtils.h
0 → 100644
View file @
964dac2b
//
// Created by kladko on 1/22/20.
//
#ifndef SGXD_AESUTILS_H
#define SGXD_AESUTILS_H
sgx_aes_gcm_128bit_key_t
AES_key
;
int
AES_encrypt
(
char
*
message
,
uint8_t
*
encr_message
);
int
AES_decrypt
(
uint8_t
*
encr_message
,
uint64_t
length
,
char
*
message
);
#endif //SGXD_AESUTILS_H
secure_enclave/Makefile.am
View file @
964dac2b
...
...
@@ -85,7 +85,7 @@ CLEANFILES+= secure_enclave_t.c secure_enclave_t.h
secure_enclave_SOURCES
=
secure_enclave_t.c secure_enclave_t.h
\
secure_enclave.c
\
curves.c domain_parameters.c numbertheory.c point.c signature.c DH_dkg.c
\
curves.c domain_parameters.c numbertheory.c point.c signature.c DH_dkg.c
AESUtils.c
\
DKGUtils.cpp BLSEnclave.cpp ../trusted_libff/libff/algebra/curves/alt_bn128/alt_bn128_init.cpp
\
../trusted_libff/libff/algebra/curves/alt_bn128/alt_bn128_g2.cpp
\
../trusted_libff/libff/algebra/curves/alt_bn128/alt_bn128_g1.cpp
$(ENCLAVE_KEY)
$(ENCLAVE_CONFIG)
...
...
secure_enclave/Makefile.in
View file @
964dac2b
...
...
@@ -110,7 +110,7 @@ am_secure_enclave_OBJECTS = secure_enclave_t.$(OBJEXT) \
secure_enclave.
$(OBJEXT)
curves.
$(OBJEXT)
\
domain_parameters.
$(OBJEXT)
numbertheory.
$(OBJEXT)
\
point.
$(OBJEXT)
signature.
$(OBJEXT)
DH_dkg.
$(OBJEXT)
\
DKGUtils.
$(OBJEXT)
BLSEnclave.
$(OBJEXT)
\
AESUtils.
$(OBJEXT)
DKGUtils.
$(OBJEXT)
BLSEnclave.
$(OBJEXT)
\
alt_bn128_init.
$(OBJEXT)
alt_bn128_g2.
$(OBJEXT)
\
alt_bn128_g1.
$(OBJEXT)
$(am__objects_1)
$(am__objects_1)
secure_enclave_OBJECTS
=
$(am_secure_enclave_OBJECTS)
...
...
@@ -138,7 +138,8 @@ am__v_at_1 =
DEFAULT_INCLUDES
=
-I
.@am__isrc@
depcomp
=
$(SHELL)
$(top_srcdir)
/depcomp
am__maybe_remake_depfiles
=
depfiles
am__depfiles_remade
=
./
$(DEPDIR)
/BLSEnclave.Po ./
$(DEPDIR)
/DH_dkg.Po
\
am__depfiles_remade
=
./
$(DEPDIR)
/AESUtils.Po
\
./
$(DEPDIR)
/BLSEnclave.Po ./
$(DEPDIR)
/DH_dkg.Po
\
./
$(DEPDIR)
/DKGUtils.Po ./
$(DEPDIR)
/alt_bn128_g1.Po
\
./
$(DEPDIR)
/alt_bn128_g2.Po ./
$(DEPDIR)
/alt_bn128_init.Po
\
./
$(DEPDIR)
/curves.Po ./
$(DEPDIR)
/domain_parameters.Po
\
...
...
@@ -346,7 +347,7 @@ ENCLAVE_CONFIG = $(ENCLAVE).config.xml
ENCLAVE_KEY
=
test_insecure_private_key.pem
#
$(ENCLAVE)
_private.pem
secure_enclave_SOURCES
=
secure_enclave_t.c secure_enclave_t.h
\
secure_enclave.c
\
curves.c domain_parameters.c numbertheory.c point.c signature.c DH_dkg.c
\
curves.c domain_parameters.c numbertheory.c point.c signature.c DH_dkg.c
AESUtils.c
\
DKGUtils.cpp BLSEnclave.cpp ../trusted_libff/libff/algebra/curves/alt_bn128/alt_bn128_init.cpp
\
../trusted_libff/libff/algebra/curves/alt_bn128/alt_bn128_g2.cpp
\
../trusted_libff/libff/algebra/curves/alt_bn128/alt_bn128_g1.cpp
$(ENCLAVE_KEY)
$(ENCLAVE_CONFIG)
...
...
@@ -440,6 +441,7 @@ mostlyclean-compile:
distclean-compile
:
-
rm
-f
*
.tab.c
@AMDEP_TRUE@@am__include@
@am__quote@./$(DEPDIR)/AESUtils.Po@am__quote@
# am--include-marker
@AMDEP_TRUE@@am__include@
@am__quote@./$(DEPDIR)/BLSEnclave.Po@am__quote@
# am--include-marker
@AMDEP_TRUE@@am__include@
@am__quote@./$(DEPDIR)/DH_dkg.Po@am__quote@
# am--include-marker
@AMDEP_TRUE@@am__include@
@am__quote@./$(DEPDIR)/DKGUtils.Po@am__quote@
# am--include-marker
...
...
@@ -660,7 +662,8 @@ clean: clean-am
clean-am
:
clean-generic clean-libexecPROGRAMS mostlyclean-am
distclean
:
distclean-am
-
rm
-f
./
$(DEPDIR)
/BLSEnclave.Po
-
rm
-f
./
$(DEPDIR)
/AESUtils.Po
-
rm
-f
./
$(DEPDIR)
/BLSEnclave.Po
-
rm
-f
./
$(DEPDIR)
/DH_dkg.Po
-
rm
-f
./
$(DEPDIR)
/DKGUtils.Po
-
rm
-f
./
$(DEPDIR)
/alt_bn128_g1.Po
...
...
@@ -720,7 +723,8 @@ install-ps-am:
installcheck-am
:
maintainer-clean
:
maintainer-clean-am
-
rm
-f
./
$(DEPDIR)
/BLSEnclave.Po
-
rm
-f
./
$(DEPDIR)
/AESUtils.Po
-
rm
-f
./
$(DEPDIR)
/BLSEnclave.Po
-
rm
-f
./
$(DEPDIR)
/DH_dkg.Po
-
rm
-f
./
$(DEPDIR)
/DKGUtils.Po
-
rm
-f
./
$(DEPDIR)
/alt_bn128_g1.Po
...
...
secure_enclave/enclave_common.h
0 → 100644
View file @
964dac2b
//
// Created by kladko on 1/24/20.
//
#ifndef SGXD_ENCLAVE_COMMON_H
#define SGXD_ENCLAVE_COMMON_H
#define BUF_LEN 1024
#define MAX_KEY_LENGTH 128
#define MAX_COMPONENT_LENGTH 80
#define MAX_COMPONENT_HEX_LENGTH MAX_COMPONENT_LENGTH * 2
#define MAX_ENCRYPTED_KEY_LENGTH 1024
#define MAX_SIG_LEN 1024
#define MAX_ERR_LEN 1024
#define SHA_256_LEN 32
#define ADD_ENTROPY_SIZE 32
#define DKG_BUFER_LENGTH 2490//3060
#define DKG_MAX_SEALED_LEN 3050
#define SECRET_SHARE_NUM_BYTES 96
#define ECDSA_SKEY_LEN 65
#define ECDSA_SKEY_BASE 16
#define ECDSA_ENCR_LEN 93
#define ECDSA_BIN_LEN 33
#define UNKNOWN_ERROR -1
#define PLAINTEXT_KEY_TOO_LONG -2
#define UNPADDED_KEY -3
#define NULL_KEY -4
#define INCORRECT_STRING_CONVERSION -5
#define ENCRYPTED_KEY_TOO_LONG -6
#define SEAL_KEY_FAILED -7
#endif //SGXD_ENCLAVE_COMMON_H
secure_enclave/secure_enclave.c
View file @
964dac2b
This diff is collapsed.
Click to expand it.
secure_enclave/secure_enclave.edl
View file @
964dac2b
#define ECDSA_SKEY_LEN 65
#define ECDSA_SKEY_BASE 16
#define ECDSA_ENCR_LEN 93
#define ECDSA_BIN_LEN 33
enclave {
trusted {
include "sgx_tgmp.h"
public void tgmp_init();
public void e_mpz_add(
...
...
@@ -52,20 +59,20 @@ enclave {
[out, count = 1024] char* key );
public void bls_sign_message (
[user_check] int *err_status,
[out, count = 1024] char* err_string,
[in, count = 1024] uint8_t* encrypted_key,
uint32_t enc_len,
[in, count = 1024] char* hashX ,
[in, count = 1024] char* hashY ,
[out, count = 1024] char* signature);
[user_check] int *err_status,
[out, count = 1024] char* err_string,
[in, count = 1024] uint8_t* encrypted_key,
uint32_t enc_len,
[in, count = 1024] char* hashX ,
[in, count = 1024] char* hashY ,
[out, count = 1024] char* signature);
public void gen_dkg_secret (
[user_check] int *err_status,
[out, count = 1024] char* err_string,
[out, count = 3050] uint8_t* encrypted_dkg_secret,
[user_check] uint32_t * enc_len,
size_t _t);
[user_check] int *err_status,
[out, count = 1024] char* err_string,
[out, count = 3050] uint8_t* encrypted_dkg_secret,
[user_check] uint32_t * enc_len,
size_t _t);
public void decrypt_dkg_secret (
[user_check] int *err_status,
...
...
@@ -163,6 +170,57 @@ enclave {
[out, count = 1024] char *err_string,
[in, count = 1024] uint8_t *encrypted_SEK,
[user_check] uint32_t *enc_len);
public void generate_ecdsa_key_aes (
[user_check] int *err_status,
[out, count = 1024] char* err_string,
[out, count = ECDSA_ENCR_LEN] 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_aes(
[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 ecdsa_sign_aes(
[user_check] int *err_status,
[out, count = 1024] char* err_string,
[in, count = 1024] uint8_t* encrypted_key,
uint32_t enc_len,
[in, count = 1024] unsigned char* hash,
[out, count = 1024] char* sig_r,
[out, count = 1024] char* sig_s,
[user_check] uint8_t* sig_v,
int base);
public void encrypt_key_aes (
[user_check] int *err_status,
[out, count = 1024] char* err_string,
[in, count = 1024] char* key,
[out, count = 1024] uint8_t* encrypted_key,
[user_check] uint32_t *enc_len);
public void decrypt_key_aes (
[user_check] int *err_status,
[out, count = 1024] char* err_string,
[in, count = 1024] uint8_t* encrypted_key,
uint32_t enc_len,
[out, count = 1024] char* key );
public void bls_sign_message_aes (
[user_check] int *err_status,
[out, count = 1024] char* err_string,
[in, count = 1024] uint8_t* encrypted_key,
uint32_t enc_len,
[in, count = 1024] char* hashX ,
[in, count = 1024] char* hashY ,
[out, count = 1024] char* signature);
};
...
...
sgxwallet_common.h
View file @
964dac2b
...
...
@@ -57,7 +57,7 @@ extern int is_sgx_https;
#define ECDSA_SKEY_LEN 65
#define ECDSA_SKEY_BASE 16
#define ECDSA_ENCR_LEN
625
#define ECDSA_ENCR_LEN
93
#define ECDSA_BIN_LEN 33
#define UNKNOWN_ERROR -1
...
...
testw.cpp
View file @
964dac2b
...
...
@@ -139,7 +139,8 @@ char* encryptTestKey() {
TEST_CASE
(
"BLS key encrypt"
,
"[bls-key-encrypt]"
)
{
DEBUG_PRINT
=
1
;
is_sgx_https
=
0
;
init_all
(
false
,
false
);
char
*
key
=
encryptTestKey
();
REQUIRE
(
key
!=
nullptr
);
...
...
@@ -150,8 +151,11 @@ TEST_CASE("BLS key encrypt", "[bls-key-encrypt]") {
TEST_CASE
(
"BLS key encrypt/decrypt"
,
"[bls-key-encrypt-decrypt]"
)
{
{
DEBUG_PRINT
=
1
;
is_sgx_https
=
0
;
init_all
(
false
,
false
);
init_all
(
false
,
false
);
//init_enclave();
int
errStatus
=
-
1
;
char
*
errMsg
=
(
char
*
)
calloc
(
BUF_LEN
,
1
);
...
...
@@ -171,6 +175,8 @@ TEST_CASE("BLS key encrypt/decrypt", "[bls-key-encrypt-decrypt]") {
printf
(
"Decrypted key len %d
\n
"
,
(
int
)
strlen
(
plaintextKey
));
printf
(
"Decrypted key: %s
\n
"
,
plaintextKey
);
sgx_destroy_enclave
(
eid
);
}
}
...
...
@@ -1076,32 +1082,37 @@ TEST_CASE("ecdsa API test", "[ecdsa_api_test]") {
cerr
<<
"Client inited"
<<
endl
;
Json
::
Value
genKey
=
c
.
generateECDSAKey
();
REQUIRE
(
genKey
[
"status"
].
asInt
()
==
0
);
cout
<<
genKey
<<
endl
;
Json
::
Value
ecdsaSign
=
c
.
ecdsaSignMessageHash
(
16
,
genKey
[
"KeyName"
].
asString
(),
"0x09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db"
);
REQUIRE
(
ecdsaSign
[
"status"
].
asInt
()
==
0
);
cout
<<
ecdsaSign
<<
std
::
endl
;
REQUIRE
(
genKey
[
"status"
].
asInt
()
==
0
);
Json
::
Value
getPubKey
=
c
.
getPublicECDSAKey
(
genKey
[
"KeyName"
].
asString
());
REQUIRE
(
getPubKey
[
"status"
].
asInt
()
==
0
);
cout
<<
getPubKey
<<
std
::
endl
;
REQUIRE
(
getPubKey
[
"status"
].
asInt
()
==
0
);
REQUIRE
(
getPubKey
[
"PublicKey"
].
asString
()
==
genKey
[
"PublicKey"
].
asString
());
Json
::
Value
ecdsaSign
=
c
.
ecdsaSignMessageHash
(
16
,
genKey
[
"KeyName"
].
asString
(),
"0x09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db"
);
cout
<<
ecdsaSign
<<
std
::
endl
;
REQUIRE
(
ecdsaSign
[
"status"
].
asInt
()
==
0
);
//wrong base
Json
::
Value
ecdsaSignWrongBase
=
c
.
ecdsaSignMessageHash
(
0
,
genKey
[
"KeyName"
].
asString
(),
"0x09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db"
);
cout
<<
ecdsaSignWrongBase
<<
std
::
endl
;
REQUIRE
(
ecdsaSignWrongBase
[
"status"
].
asInt
()
!=
0
);
//wrong keyName
Json
::
Value
ecdsaSignWrongKeyName
=
c
.
ecdsaSignMessageHash
(
0
,
""
,
"0x09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db"
);
cout
<<
ecdsaSignWrongKeyName
<<
std
::
endl
;
REQUIRE
(
ecdsaSignWrongKeyName
[
"status"
].
asInt
()
!=
0
);
Json
::
Value
getPubKeyWrongKeyName
=
c
.
getPublicECDSAKey
(
"keyName"
);
REQUIRE
(
getPubKeyWrongKeyName
[
"status"
].
asInt
()
!=
0
);
cout
<<
getPubKeyWrongKeyName
<<
std
::
endl
;
//wrong hash
Json
::
Value
ecdsaSignWrongHash
=
c
.
ecdsaSignMessageHash
(
16
,
genKey
[
"KeyName"
].
asString
(),
""
);
cout
<<
ecdsaSignWrongHash
<<
std
::
endl
;
REQUIRE
(
ecdsaSignWrongHash
[
"status"
].
asInt
()
!=
0
);
// //wrong base
// Json::Value ecdsaSignWrongBase = c.ecdsaSignMessageHash(0, genKey["KeyName"].asString(), "0x09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db");
// cout << ecdsaSignWrongBase << std::endl;
// REQUIRE(ecdsaSignWrongBase["status"].asInt() != 0);
//
// //wrong keyName
// Json::Value ecdsaSignWrongKeyName = c.ecdsaSignMessageHash(0, "", "0x09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db");
// cout << ecdsaSignWrongKeyName << std::endl;
// REQUIRE(ecdsaSignWrongKeyName["status"].asInt() != 0);
// Json::Value getPubKeyWrongKeyName = c.getPublicECDSAKey("keyName");
// REQUIRE(getPubKeyWrongKeyName["status"].asInt() != 0);
// cout << getPubKeyWrongKeyName << std::endl;
//
// //wrong hash
// Json::Value ecdsaSignWrongHash = c.ecdsaSignMessageHash(16, genKey["KeyName"].asString(), "");
// cout << ecdsaSignWrongHash << std::endl;
// REQUIRE(ecdsaSignWrongHash["status"].asInt() != 0);
sgx_destroy_enclave
(
eid
);
}
...
...
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