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
07538aef
Unverified
Commit
07538aef
authored
Jun 02, 2020
by
Oleh Nikolaiev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SKALE-2002 fix few potential memory leaks
parent
ebe09c37
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
55 deletions
+17
-55
SEKManager.cpp
SEKManager.cpp
+2
-5
secure_enclave.c
secure_enclave/secure_enclave.c
+15
-50
No files found.
SEKManager.cpp
View file @
07538aef
...
@@ -129,12 +129,11 @@ void gen_SEK(){
...
@@ -129,12 +129,11 @@ void gen_SEK(){
vector
<
uint8_t
>
encr_SEK
(
1024
,
0
);
vector
<
uint8_t
>
encr_SEK
(
1024
,
0
);
uint32_t
enc_len
=
0
;
uint32_t
enc_len
=
0
;
//vector<char> SEK(65, 0);
char
SEK
[
65
];
char
SEK
[
65
];
memset
(
SEK
,
0
,
65
);
memset
(
SEK
,
0
,
65
);
status
=
trustedGenerateSEK
(
eid
,
&
err_status
,
errMsg
.
data
(),
encr_SEK
.
data
(),
&
enc_len
,
SEK
);
status
=
trustedGenerateSEK
(
eid
,
&
err_status
,
errMsg
.
data
(),
encr_SEK
.
data
(),
&
enc_len
,
SEK
);
if
(
status
!=
SGX_SUCCESS
||
err_status
!=
0
)
{
if
(
status
!=
SGX_SUCCESS
||
err_status
!=
0
)
{
throw
SGXException
(
status
,
errMsg
.
data
())
;
throw
SGXException
(
status
,
errMsg
.
data
())
;
}
}
...
@@ -143,7 +142,7 @@ void gen_SEK(){
...
@@ -143,7 +142,7 @@ void gen_SEK(){
carray2Hex
(
encr_SEK
.
data
(),
enc_len
,
hexEncrKey
.
data
());
carray2Hex
(
encr_SEK
.
data
(),
enc_len
,
hexEncrKey
.
data
());
cout
<<
"ATTENTION! THIS IS YOUR KEY FOR BACK UP. PLEASE COPY IT TO THE SAFE PLACE"
<<
endl
;
cout
<<
"ATTENTION! THIS IS YOUR KEY FOR BACK UP. PLEASE COPY IT TO THE SAFE PLACE"
<<
endl
;
cout
<<
"
key is
"
<<
SEK
<<
endl
;
cout
<<
"
YOUR KEY IS
"
<<
SEK
<<
endl
;
if
(
!
autoconfirm
)
{
if
(
!
autoconfirm
)
{
std
::
string
confirm_str
=
"I confirm"
;
std
::
string
confirm_str
=
"I confirm"
;
...
@@ -200,8 +199,6 @@ void enter_SEK(){
...
@@ -200,8 +199,6 @@ void enter_SEK(){
SEK
=
""
;
SEK
=
""
;
std
::
cin
>>
SEK
;
std
::
cin
>>
SEK
;
}
}
// if (DEBUG_PRINT)
// std::cerr << "your key is " << SEK << std::endl;
status
=
trustedSetSEK_backup
(
eid
,
&
err_status
,
errMsg
.
data
(),
encr_SEK
.
data
(),
&
enc_len
,
SEK
.
c_str
());
status
=
trustedSetSEK_backup
(
eid
,
&
err_status
,
errMsg
.
data
(),
encr_SEK
.
data
(),
&
enc_len
,
SEK
.
c_str
());
if
(
status
!=
SGX_SUCCESS
){
if
(
status
!=
SGX_SUCCESS
){
...
...
secure_enclave/secure_enclave.c
View file @
07538aef
...
@@ -408,7 +408,6 @@ void trustedEncryptKey(int *errStatus, char *errString, const char *key,
...
@@ -408,7 +408,6 @@ void trustedEncryptKey(int *errStatus, char *errString, const char *key,
return
;
return
;
}
}
memset
(
encryptedPrivateKey
,
0
,
BUF_LEN
);
memset
(
encryptedPrivateKey
,
0
,
BUF_LEN
);
sgx_status_t
status
=
sgx_seal_data
(
0
,
NULL
,
MAX_KEY_LENGTH
,
(
uint8_t
*
)
key
,
sealedLen
,
sgx_status_t
status
=
sgx_seal_data
(
0
,
NULL
,
MAX_KEY_LENGTH
,
(
uint8_t
*
)
key
,
sealedLen
,
...
@@ -438,7 +437,6 @@ void trustedEncryptKey(int *errStatus, char *errString, const char *key,
...
@@ -438,7 +437,6 @@ void trustedEncryptKey(int *errStatus, char *errString, const char *key,
return
;
return
;
}
}
*
errStatus
=
-
8
;
*
errStatus
=
-
8
;
if
(
strncmp
(
key
,
decryptedKey
,
MAX_KEY_LENGTH
)
!=
0
)
{
if
(
strncmp
(
key
,
decryptedKey
,
MAX_KEY_LENGTH
)
!=
0
)
{
...
@@ -451,7 +449,6 @@ void trustedEncryptKey(int *errStatus, char *errString, const char *key,
...
@@ -451,7 +449,6 @@ void trustedEncryptKey(int *errStatus, char *errString, const char *key,
void
trustedDecryptKey
(
int
*
errStatus
,
char
*
errString
,
uint8_t
*
encryptedPrivateKey
,
void
trustedDecryptKey
(
int
*
errStatus
,
char
*
errString
,
uint8_t
*
encryptedPrivateKey
,
uint32_t
enc_len
,
char
*
key
)
{
uint32_t
enc_len
,
char
*
key
)
{
LOG_DEBUG
(
__FUNCTION__
);
LOG_DEBUG
(
__FUNCTION__
);
uint32_t
decLen
;
uint32_t
decLen
;
...
@@ -467,8 +464,6 @@ void trustedDecryptKey(int *errStatus, char *errString, uint8_t *encryptedPrivat
...
@@ -467,8 +464,6 @@ void trustedDecryptKey(int *errStatus, char *errString, uint8_t *encryptedPrivat
return
;
return
;
}
}
//snprintf(errString, BUF_LEN, "decr key is %s", key);
if
(
decLen
>
MAX_KEY_LENGTH
)
{
if
(
decLen
>
MAX_KEY_LENGTH
)
{
snprintf
(
errString
,
BUF_LEN
,
"wrong decLen"
);
//"decLen != MAX_KEY_LENGTH");
snprintf
(
errString
,
BUF_LEN
,
"wrong decLen"
);
//"decLen != MAX_KEY_LENGTH");
return
;
return
;
...
@@ -476,10 +471,8 @@ void trustedDecryptKey(int *errStatus, char *errString, uint8_t *encryptedPrivat
...
@@ -476,10 +471,8 @@ void trustedDecryptKey(int *errStatus, char *errString, uint8_t *encryptedPrivat
*
errStatus
=
-
10
;
*
errStatus
=
-
10
;
uint64_t
keyLen
=
strnlen
(
key
,
MAX_KEY_LENGTH
);
uint64_t
keyLen
=
strnlen
(
key
,
MAX_KEY_LENGTH
);
if
(
keyLen
==
MAX_KEY_LENGTH
)
{
if
(
keyLen
==
MAX_KEY_LENGTH
)
{
snprintf
(
errString
,
BUF_LEN
,
"Key is not null terminated"
);
snprintf
(
errString
,
BUF_LEN
,
"Key is not null terminated"
);
return
;
return
;
...
@@ -487,23 +480,17 @@ void trustedDecryptKey(int *errStatus, char *errString, uint8_t *encryptedPrivat
...
@@ -487,23 +480,17 @@ void trustedDecryptKey(int *errStatus, char *errString, uint8_t *encryptedPrivat
*
errStatus
=
0
;
*
errStatus
=
0
;
return
;
return
;
}
}
void
trustedBlsSignMessage
(
int
*
errStatus
,
char
*
errString
,
uint8_t
*
encryptedPrivateKey
,
void
trustedBlsSignMessage
(
int
*
errStatus
,
char
*
errString
,
uint8_t
*
encryptedPrivateKey
,
uint32_t
enc_len
,
char
*
_hashX
,
uint32_t
enc_len
,
char
*
_hashX
,
char
*
_hashY
,
char
*
signature
)
{
char
*
_hashY
,
char
*
signature
)
{
LOG_DEBUG
(
__FUNCTION__
);
LOG_DEBUG
(
__FUNCTION__
);
char
key
[
BUF_LEN
];
char
key
[
BUF_LEN
];
char
*
sig
=
(
char
*
)
calloc
(
BUF_LEN
,
1
);
char
*
sig
=
(
char
*
)
calloc
(
BUF_LEN
,
1
);
trustedDecryptKey
(
errStatus
,
errString
,
encryptedPrivateKey
,
enc_len
,
key
);
trustedDecryptKey
(
errStatus
,
errString
,
encryptedPrivateKey
,
enc_len
,
key
);
if
(
*
errStatus
!=
0
)
{
if
(
*
errStatus
!=
0
)
{
...
@@ -524,7 +511,6 @@ void trustedBlsSignMessage(int *errStatus, char *errString, uint8_t *encryptedPr
...
@@ -524,7 +511,6 @@ void trustedBlsSignMessage(int *errStatus, char *errString, uint8_t *encryptedPr
}
}
void
trustedGenDkgSecret
(
int
*
errStatus
,
char
*
errString
,
uint8_t
*
encrypted_dkg_secret
,
uint32_t
*
enc_len
,
size_t
_t
)
{
void
trustedGenDkgSecret
(
int
*
errStatus
,
char
*
errString
,
uint8_t
*
encrypted_dkg_secret
,
uint32_t
*
enc_len
,
size_t
_t
)
{
LOG_DEBUG
(
__FUNCTION__
);
LOG_DEBUG
(
__FUNCTION__
);
char
dkg_secret
[
DKG_BUFER_LENGTH
];
char
dkg_secret
[
DKG_BUFER_LENGTH
];
...
@@ -549,15 +535,12 @@ void trustedGenDkgSecret(int *errStatus, char *errString, uint8_t *encrypted_dkg
...
@@ -549,15 +535,12 @@ void trustedGenDkgSecret(int *errStatus, char *errString, uint8_t *encrypted_dkg
}
}
*
enc_len
=
sealedLen
;
*
enc_len
=
sealedLen
;
//free(dkg_secret);
}
}
void
trustedDecryptDkgSecret
(
int
*
errStatus
,
char
*
errString
,
uint8_t
*
encrypted_dkg_secret
,
uint8_t
*
decrypted_dkg_secret
,
void
trustedDecryptDkgSecret
(
int
*
errStatus
,
char
*
errString
,
uint8_t
*
encrypted_dkg_secret
,
uint8_t
*
decrypted_dkg_secret
,
uint32_t
*
dec_len
)
{
uint32_t
*
dec_len
)
{
LOG_DEBUG
(
__FUNCTION__
);
LOG_DEBUG
(
__FUNCTION__
);
uint32_t
decr_len
;
uint32_t
decr_len
;
sgx_status_t
status
=
sgx_unseal_data
(
sgx_status_t
status
=
sgx_unseal_data
(
(
const
sgx_sealed_data_t
*
)
encrypted_dkg_secret
,
NULL
,
0
,
decrypted_dkg_secret
,
&
decr_len
);
(
const
sgx_sealed_data_t
*
)
encrypted_dkg_secret
,
NULL
,
0
,
decrypted_dkg_secret
,
&
decr_len
);
...
@@ -574,7 +557,6 @@ void trustedDecryptDkgSecret(int *errStatus, char *errString, uint8_t *encrypted
...
@@ -574,7 +557,6 @@ void trustedDecryptDkgSecret(int *errStatus, char *errString, uint8_t *encrypted
void
trustedGetSecretShares
(
int
*
errStatus
,
char
*
errString
,
uint8_t
*
encrypted_dkg_secret
,
uint32_t
*
dec_len
,
void
trustedGetSecretShares
(
int
*
errStatus
,
char
*
errString
,
uint8_t
*
encrypted_dkg_secret
,
uint32_t
*
dec_len
,
char
*
secret_shares
,
char
*
secret_shares
,
unsigned
_t
,
unsigned
_n
)
{
unsigned
_t
,
unsigned
_n
)
{
LOG_DEBUG
(
__FUNCTION__
);
LOG_DEBUG
(
__FUNCTION__
);
char
decrypted_dkg_secret
[
DKG_BUFER_LENGTH
];
char
decrypted_dkg_secret
[
DKG_BUFER_LENGTH
];
...
@@ -589,15 +571,12 @@ void trustedGetSecretShares(int *errStatus, char *errString, uint8_t *encrypted_
...
@@ -589,15 +571,12 @@ void trustedGetSecretShares(int *errStatus, char *errString, uint8_t *encrypted_
*
dec_len
=
decr_len
;
*
dec_len
=
decr_len
;
// strncpy(errString, decrypted_dkg_secret, 1024);
calc_secret_shares
(
decrypted_dkg_secret
,
secret_shares
,
_t
,
_n
);
calc_secret_shares
(
decrypted_dkg_secret
,
secret_shares
,
_t
,
_n
);
//free(decrypted_dkg_secret);
}
}
void
trustedGetPublicShares
(
int
*
errStatus
,
char
*
errString
,
uint8_t
*
encrypted_dkg_secret
,
uint32_t
enc_len
,
void
trustedGetPublicShares
(
int
*
errStatus
,
char
*
errString
,
uint8_t
*
encrypted_dkg_secret
,
uint32_t
enc_len
,
char
*
public_shares
,
char
*
public_shares
,
unsigned
_t
,
unsigned
_n
)
{
unsigned
_t
,
unsigned
_n
)
{
LOG_DEBUG
(
__FUNCTION__
);
LOG_DEBUG
(
__FUNCTION__
);
char
*
decrypted_dkg_secret
=
(
char
*
)
calloc
(
DKG_MAX_SEALED_LEN
,
1
);
char
*
decrypted_dkg_secret
=
(
char
*
)
calloc
(
DKG_MAX_SEALED_LEN
,
1
);
...
@@ -607,8 +586,7 @@ void trustedGetPublicShares(int *errStatus, char *errString, uint8_t *encrypted_
...
@@ -607,8 +586,7 @@ void trustedGetPublicShares(int *errStatus, char *errString, uint8_t *encrypted_
snprintf
(
errString
,
BUF_LEN
,
"trustedDecryptDkgSecret failed with status %d"
,
*
errStatus
);
snprintf
(
errString
,
BUF_LEN
,
"trustedDecryptDkgSecret failed with status %d"
,
*
errStatus
);
return
;
return
;
}
}
//strncpy(errString, decrypted_dkg_secret, 1024);
// strncpy(errString, "before calc_public_shares ", 1024);
if
(
calc_public_shares
(
decrypted_dkg_secret
,
public_shares
,
_t
)
!=
0
)
{
if
(
calc_public_shares
(
decrypted_dkg_secret
,
public_shares
,
_t
)
!=
0
)
{
*
errStatus
=
-
1
;
*
errStatus
=
-
1
;
snprintf
(
errString
,
BUF_LEN
,
"t does not match polynomial in db"
);
snprintf
(
errString
,
BUF_LEN
,
"t does not match polynomial in db"
);
...
@@ -629,12 +607,10 @@ void trustedSetEncryptedDkgPoly(int *errStatus, char *errString, uint8_t *encryp
...
@@ -629,12 +607,10 @@ void trustedSetEncryptedDkgPoly(int *errStatus, char *errString, uint8_t *encryp
snprintf
(
errString
,
BUF_LEN
,
"sgx_unseal_data - encrypted_poly failed with status %d"
,
status
);
snprintf
(
errString
,
BUF_LEN
,
"sgx_unseal_data - encrypted_poly failed with status %d"
,
status
);
return
;
return
;
}
}
}
}
void
trustedGetEncryptedSecretShare
(
int
*
errStatus
,
char
*
errString
,
uint8_t
*
encrypted_skey
,
uint32_t
*
dec_len
,
void
trustedGetEncryptedSecretShare
(
int
*
errStatus
,
char
*
errString
,
uint8_t
*
encrypted_skey
,
uint32_t
*
dec_len
,
char
*
result_str
,
char
*
s_shareG2
,
char
*
pub_keyB
,
uint8_t
_t
,
uint8_t
_n
,
uint8_t
ind
)
{
char
*
result_str
,
char
*
s_shareG2
,
char
*
pub_keyB
,
uint8_t
_t
,
uint8_t
_n
,
uint8_t
ind
)
{
LOG_DEBUG
(
__FUNCTION__
);
LOG_DEBUG
(
__FUNCTION__
);
char
skey
[
ECDSA_SKEY_LEN
];
char
skey
[
ECDSA_SKEY_LEN
];
...
@@ -692,18 +668,15 @@ void trustedGetEncryptedSecretShare(int *errStatus, char *errString, uint8_t *en
...
@@ -692,18 +668,15 @@ void trustedGetEncryptedSecretShare(int *errStatus, char *errString, uint8_t *en
strncpy
(
result_str
,
cypher
,
strlen
(
cypher
));
strncpy
(
result_str
,
cypher
,
strlen
(
cypher
));
strncpy
(
result_str
+
strlen
(
cypher
),
pub_key_x
,
strlen
(
pub_key_x
));
strncpy
(
result_str
+
strlen
(
cypher
),
pub_key_x
,
strlen
(
pub_key_x
));
strncpy
(
result_str
+
strlen
(
pub_key_x
)
+
strlen
(
pub_key_y
),
pub_key_y
,
strlen
(
pub_key_y
));
strncpy
(
result_str
+
strlen
(
pub_key_x
)
+
strlen
(
pub_key_y
),
pub_key_y
,
strlen
(
pub_key_y
));
}
}
void
trustedComplaintResponse
(
int
*
errStatus
,
char
*
errString
,
uint8_t
*
encryptedDHKey
,
uint8_t
*
encrypted_dkg_secret
,
void
trustedComplaintResponse
(
int
*
errStatus
,
char
*
errString
,
uint8_t
*
encryptedDHKey
,
uint8_t
*
encrypted_dkg_secret
,
uint32_t
*
dec_len
,
uint32_t
*
dec_len
,
char
*
DH_key
,
char
*
s_shareG2
,
uint8_t
_t
,
uint8_t
_n
,
uint8_t
ind1
)
{
char
*
DH_key
,
char
*
s_shareG2
,
uint8_t
_t
,
uint8_t
_n
,
uint8_t
ind1
)
{
LOG_DEBUG
(
__FUNCTION__
);
LOG_DEBUG
(
__FUNCTION__
);
uint32_t
enc_len
;
uint32_t
enc_len
;
char
decrypted_dkg_secret
[
DKG_BUFER_LENGTH
];
char
decrypted_dkg_secret
[
DKG_BUFER_LENGTH
];
uint32_t
decr_len
;
uint32_t
decr_len
;
trustedDecryptDkgSecret
(
errStatus
,
errString
,
encrypted_dkg_secret
,
(
uint8_t
*
)
decrypted_dkg_secret
,
&
decr_len
);
trustedDecryptDkgSecret
(
errStatus
,
errString
,
encrypted_dkg_secret
,
(
uint8_t
*
)
decrypted_dkg_secret
,
&
decr_len
);
...
@@ -713,13 +686,10 @@ void trustedComplaintResponse(int *errStatus, char *errString, uint8_t *encrypte
...
@@ -713,13 +686,10 @@ void trustedComplaintResponse(int *errStatus, char *errString, uint8_t *encrypte
}
}
calc_secret_shareG2_old
(
decrypted_dkg_secret
,
s_shareG2
,
_t
,
ind1
);
calc_secret_shareG2_old
(
decrypted_dkg_secret
,
s_shareG2
,
_t
,
ind1
);
}
}
void
trustedDkgVerify
(
int
*
errStatus
,
char
*
errString
,
const
char
*
public_shares
,
const
char
*
s_share
,
void
trustedDkgVerify
(
int
*
errStatus
,
char
*
errString
,
const
char
*
public_shares
,
const
char
*
s_share
,
uint8_t
*
encryptedPrivateKey
,
uint64_t
key_len
,
unsigned
_t
,
int
_ind
,
int
*
result
)
{
uint8_t
*
encryptedPrivateKey
,
uint64_t
key_len
,
unsigned
_t
,
int
_ind
,
int
*
result
)
{
LOG_DEBUG
(
__FUNCTION__
);
LOG_DEBUG
(
__FUNCTION__
);
char
skey
[
ECDSA_SKEY_LEN
];
char
skey
[
ECDSA_SKEY_LEN
];
...
@@ -768,12 +738,10 @@ void trustedDkgVerify(int *errStatus, char *errString, const char *public_shares
...
@@ -768,12 +738,10 @@ void trustedDkgVerify(int *errStatus, char *errString, const char *public_shares
*
result
=
Verification
(
public_shares
,
s
,
_t
,
_ind
);
*
result
=
Verification
(
public_shares
,
s
,
_t
,
_ind
);
snprintf
(
errString
,
BUF_LEN
,
"common_key in verification is %s"
,
common_key
);
snprintf
(
errString
,
BUF_LEN
,
"common_key in verification is %s"
,
common_key
);
}
}
void
trustedCreateBlsKey
(
int
*
errStatus
,
char
*
errString
,
const
char
*
s_shares
,
void
trustedCreateBlsKey
(
int
*
errStatus
,
char
*
errString
,
const
char
*
s_shares
,
uint8_t
*
encryptedPrivateKey
,
uint64_t
key_len
,
uint8_t
*
encr_bls_key
,
uint32_t
*
enc_bls_key_len
)
{
uint8_t
*
encryptedPrivateKey
,
uint64_t
key_len
,
uint8_t
*
encr_bls_key
,
uint32_t
*
enc_bls_key_len
)
{
LOG_DEBUG
(
__FUNCTION__
);
LOG_DEBUG
(
__FUNCTION__
);
char
skey
[
ECDSA_SKEY_LEN
];
char
skey
[
ECDSA_SKEY_LEN
];
...
@@ -862,14 +830,12 @@ void trustedCreateBlsKey(int *errStatus, char *errString, const char *s_shares,
...
@@ -862,14 +830,12 @@ void trustedCreateBlsKey(int *errStatus, char *errString, const char *s_shares,
}
}
*
enc_bls_key_len
=
sealedLen
;
*
enc_bls_key_len
=
sealedLen
;
mpz_clear
(
bls_key
);
mpz_clear
(
bls_key
);
mpz_clear
(
sum
);
mpz_clear
(
sum
);
mpz_clear
(
q
);
mpz_clear
(
q
);
}
}
void
trustedGetBlsPubKey
(
int
*
errStatus
,
char
*
errString
,
uint8_t
*
encryptedPrivateKey
,
uint64_t
key_len
,
char
*
bls_pub_key
)
{
void
trustedGetBlsPubKey
(
int
*
errStatus
,
char
*
errString
,
uint8_t
*
encryptedPrivateKey
,
uint64_t
key_len
,
char
*
bls_pub_key
)
{
LOG_DEBUG
(
__FUNCTION__
);
LOG_DEBUG
(
__FUNCTION__
);
char
skey_hex
[
ECDSA_SKEY_LEN
];
char
skey_hex
[
ECDSA_SKEY_LEN
];
...
@@ -893,7 +859,6 @@ void trustedGetBlsPubKey(int *errStatus, char *errString, uint8_t *encryptedPriv
...
@@ -893,7 +859,6 @@ void trustedGetBlsPubKey(int *errStatus, char *errString, uint8_t *encryptedPriv
void
trustedGenerateSEK
(
int
*
errStatus
,
char
*
errString
,
void
trustedGenerateSEK
(
int
*
errStatus
,
char
*
errString
,
uint8_t
*
encrypted_SEK
,
uint32_t
*
enc_len
,
char
*
SEK_hex
)
{
uint8_t
*
encrypted_SEK
,
uint32_t
*
enc_len
,
char
*
SEK_hex
)
{
LOG_DEBUG
(
__FUNCTION__
);
LOG_DEBUG
(
__FUNCTION__
);
uint8_t
SEK_raw
[
SGX_AESGCM_KEY_SIZE
];
uint8_t
SEK_raw
[
SGX_AESGCM_KEY_SIZE
];
...
@@ -917,9 +882,7 @@ void trustedGenerateSEK(int *errStatus, char *errString,
...
@@ -917,9 +882,7 @@ void trustedGenerateSEK(int *errStatus, char *errString,
return
;
return
;
}
}
*
enc_len
=
sealedLen
;
*
enc_len
=
sealedLen
;
}
}
void
trustedSetSEK
(
int
*
errStatus
,
char
*
errString
,
uint8_t
*
encrypted_SEK
,
uint64_t
encr_len
)
{
void
trustedSetSEK
(
int
*
errStatus
,
char
*
errString
,
uint8_t
*
encrypted_SEK
,
uint64_t
encr_len
)
{
...
@@ -942,7 +905,6 @@ void trustedSetSEK(int *errStatus, char *errString, uint8_t *encrypted_SEK, uint
...
@@ -942,7 +905,6 @@ void trustedSetSEK(int *errStatus, char *errString, uint8_t *encrypted_SEK, uint
void
trustedSetSEK_backup
(
int
*
errStatus
,
char
*
errString
,
void
trustedSetSEK_backup
(
int
*
errStatus
,
char
*
errString
,
uint8_t
*
encrypted_SEK
,
uint32_t
*
enc_len
,
const
char
*
SEK_hex
)
{
uint8_t
*
encrypted_SEK
,
uint32_t
*
enc_len
,
const
char
*
SEK_hex
)
{
LOG_DEBUG
(
__FUNCTION__
);
LOG_DEBUG
(
__FUNCTION__
);
uint64_t
len
;
uint64_t
len
;
...
@@ -963,7 +925,6 @@ void trustedSetSEK_backup(int *errStatus, char *errString,
...
@@ -963,7 +925,6 @@ void trustedSetSEK_backup(int *errStatus, char *errString,
void
trustedGenerateEcdsaKeyAES
(
int
*
errStatus
,
char
*
errString
,
void
trustedGenerateEcdsaKeyAES
(
int
*
errStatus
,
char
*
errString
,
uint8_t
*
encryptedPrivateKey
,
uint32_t
*
enc_len
,
char
*
pub_key_x
,
char
*
pub_key_y
)
{
uint8_t
*
encryptedPrivateKey
,
uint32_t
*
enc_len
,
char
*
pub_key_x
,
char
*
pub_key_y
)
{
LOG_DEBUG
(
__FUNCTION__
);
LOG_DEBUG
(
__FUNCTION__
);
domain_parameters
curve
=
domain_parameters_init
();
domain_parameters
curve
=
domain_parameters_init
();
...
@@ -1037,7 +998,6 @@ void trustedGenerateEcdsaKeyAES(int *errStatus, char *errString,
...
@@ -1037,7 +998,6 @@ void trustedGenerateEcdsaKeyAES(int *errStatus, char *errString,
void
trustedGetPublicEcdsaKeyAES
(
int
*
errStatus
,
char
*
errString
,
void
trustedGetPublicEcdsaKeyAES
(
int
*
errStatus
,
char
*
errString
,
uint8_t
*
encryptedPrivateKey
,
uint32_t
enc_len
,
char
*
pub_key_x
,
char
*
pub_key_y
)
{
uint8_t
*
encryptedPrivateKey
,
uint32_t
enc_len
,
char
*
pub_key_x
,
char
*
pub_key_y
)
{
LOG_DEBUG
(
__FUNCTION__
);
LOG_DEBUG
(
__FUNCTION__
);
domain_parameters
curve
=
domain_parameters_init
();
domain_parameters
curve
=
domain_parameters_init
();
...
@@ -1059,7 +1019,6 @@ void trustedGetPublicEcdsaKeyAES(int *errStatus, char *errString,
...
@@ -1059,7 +1019,6 @@ void trustedGetPublicEcdsaKeyAES(int *errStatus, char *errString,
mpz_t
privateKeyMpz
;
mpz_t
privateKeyMpz
;
mpz_init
(
privateKeyMpz
);
mpz_init
(
privateKeyMpz
);
// mpz_import(privateKeyMpz, 32, 1, sizeof(skey[0]), 0, 0, skey);
if
(
mpz_set_str
(
privateKeyMpz
,
skey
,
ECDSA_SKEY_BASE
)
==
-
1
)
{
if
(
mpz_set_str
(
privateKeyMpz
,
skey
,
ECDSA_SKEY_BASE
)
==
-
1
)
{
snprintf
(
errString
,
BUF_LEN
,
"wrong string to init private key - %s"
,
skey
);
snprintf
(
errString
,
BUF_LEN
,
"wrong string to init private key - %s"
,
skey
);
*
errStatus
=
-
10
;
*
errStatus
=
-
10
;
...
@@ -1086,7 +1045,7 @@ void trustedGetPublicEcdsaKeyAES(int *errStatus, char *errString,
...
@@ -1086,7 +1045,7 @@ void trustedGetPublicEcdsaKeyAES(int *errStatus, char *errString,
int
len
=
mpz_sizeinbase
(
Pkey
->
x
,
base
)
+
2
;
int
len
=
mpz_sizeinbase
(
Pkey
->
x
,
base
)
+
2
;
char
arr_x
[
len
];
char
arr_x
[
len
];
char
*
px
=
mpz_get_str
(
arr_x
,
base
,
Pkey
->
x
);
mpz_get_str
(
arr_x
,
base
,
Pkey
->
x
);
int
n_zeroes
=
64
-
strlen
(
arr_x
);
int
n_zeroes
=
64
-
strlen
(
arr_x
);
for
(
int
i
=
0
;
i
<
n_zeroes
;
i
++
)
{
for
(
int
i
=
0
;
i
<
n_zeroes
;
i
++
)
{
...
@@ -1096,7 +1055,7 @@ void trustedGetPublicEcdsaKeyAES(int *errStatus, char *errString,
...
@@ -1096,7 +1055,7 @@ void trustedGetPublicEcdsaKeyAES(int *errStatus, char *errString,
strncpy
(
pub_key_x
+
n_zeroes
,
arr_x
,
1024
-
n_zeroes
);
strncpy
(
pub_key_x
+
n_zeroes
,
arr_x
,
1024
-
n_zeroes
);
char
arr_y
[
mpz_sizeinbase
(
Pkey
->
y
,
base
)
+
2
];
char
arr_y
[
mpz_sizeinbase
(
Pkey
->
y
,
base
)
+
2
];
char
*
py
=
mpz_get_str
(
arr_y
,
base
,
Pkey
->
y
);
mpz_get_str
(
arr_y
,
base
,
Pkey
->
y
);
n_zeroes
=
64
-
strlen
(
arr_y
);
n_zeroes
=
64
-
strlen
(
arr_y
);
for
(
int
i
=
0
;
i
<
n_zeroes
;
i
++
)
{
for
(
int
i
=
0
;
i
<
n_zeroes
;
i
++
)
{
pub_key_y
[
i
]
=
'0'
;
pub_key_y
[
i
]
=
'0'
;
...
@@ -1110,7 +1069,6 @@ void trustedGetPublicEcdsaKeyAES(int *errStatus, char *errString,
...
@@ -1110,7 +1069,6 @@ void trustedGetPublicEcdsaKeyAES(int *errStatus, char *errString,
void
trustedEcdsaSignAES
(
int
*
errStatus
,
char
*
errString
,
uint8_t
*
encryptedPrivateKey
,
uint32_t
enc_len
,
void
trustedEcdsaSignAES
(
int
*
errStatus
,
char
*
errString
,
uint8_t
*
encryptedPrivateKey
,
uint32_t
enc_len
,
unsigned
char
*
hash
,
char
*
sigR
,
char
*
sigS
,
uint8_t
*
sig_v
,
int
base
)
{
unsigned
char
*
hash
,
char
*
sigR
,
char
*
sigS
,
uint8_t
*
sig_v
,
int
base
)
{
LOG_DEBUG
(
__FUNCTION__
);
LOG_DEBUG
(
__FUNCTION__
);
domain_parameters
curve
=
domain_parameters_init
();
domain_parameters
curve
=
domain_parameters_init
();
...
@@ -1123,6 +1081,7 @@ void trustedEcdsaSignAES(int *errStatus, char *errString, uint8_t *encryptedPriv
...
@@ -1123,6 +1081,7 @@ void trustedEcdsaSignAES(int *errStatus, char *errString, uint8_t *encryptedPriv
if
(
status
!=
0
)
{
if
(
status
!=
0
)
{
*
errStatus
=
status
;
*
errStatus
=
status
;
snprintf
(
errString
,
BUF_LEN
,
"aes decrypt failed with status %d"
,
status
);
snprintf
(
errString
,
BUF_LEN
,
"aes decrypt failed with status %d"
,
status
);
domain_parameters_clear
(
curve
);
return
;
return
;
}
}
...
@@ -1135,16 +1094,18 @@ void trustedEcdsaSignAES(int *errStatus, char *errString, uint8_t *encryptedPriv
...
@@ -1135,16 +1094,18 @@ void trustedEcdsaSignAES(int *errStatus, char *errString, uint8_t *encryptedPriv
*
errStatus
=
-
1
;
*
errStatus
=
-
1
;
snprintf
(
errString
,
BUF_LEN
,
"invalid secret key"
);
snprintf
(
errString
,
BUF_LEN
,
"invalid secret key"
);
mpz_clear
(
privateKeyMpz
);
mpz_clear
(
privateKeyMpz
);
domain_parameters_clear
(
curve
);
return
;
return
;
}
}
mpz_t
msgMpz
;
mpz_t
msgMpz
;
mpz_init
(
msgMpz
);
mpz_init
(
msgMpz
);
if
(
mpz_set_str
(
msgMpz
,
hash
,
16
)
==
-
1
)
{
if
(
mpz_set_str
(
msgMpz
,
hash
,
16
)
==
-
1
)
{
*
errStatus
=
-
1
;
*
errStatus
=
-
1
;
snprintf
(
errString
,
BUF_LEN
,
"invalid message hash"
);
snprintf
(
errString
,
BUF_LEN
,
"invalid message hash"
);
mpz_clear
(
privateKeyMpz
);
mpz_clear
(
msgMpz
);
mpz_clear
(
msgMpz
);
domain_parameters_clear
(
curve
);
return
;
return
;
}
}
...
@@ -1159,20 +1120,25 @@ void trustedEcdsaSignAES(int *errStatus, char *errString, uint8_t *encryptedPriv
...
@@ -1159,20 +1120,25 @@ void trustedEcdsaSignAES(int *errStatus, char *errString, uint8_t *encryptedPriv
if
(
!
signature_verify
(
msgMpz
,
sign
,
Pkey
,
curve
))
{
if
(
!
signature_verify
(
msgMpz
,
sign
,
Pkey
,
curve
))
{
*
errStatus
=
-
2
;
*
errStatus
=
-
2
;
snprintf
(
errString
,
BUF_LEN
,
"signature is not verified! "
);
snprintf
(
errString
,
BUF_LEN
,
"signature is not verified! "
);
mpz_clear
(
privateKeyMpz
);
mpz_clear
(
msgMpz
);
domain_parameters_clear
(
curve
);
signature_free
(
sign
);
point_clear
(
Pkey
);
return
;
return
;
}
}
char
arrM
[
mpz_sizeinbase
(
msgMpz
,
16
)
+
2
];
char
arrM
[
mpz_sizeinbase
(
msgMpz
,
16
)
+
2
];
char
*
msg
=
mpz_get_str
(
arrM
,
16
,
msgMpz
);
mpz_get_str
(
arrM
,
16
,
msgMpz
);
snprintf
(
errString
,
BUF_LEN
,
"message is %s "
,
arrM
);
snprintf
(
errString
,
BUF_LEN
,
"message is %s "
,
arrM
);
char
arrR
[
mpz_sizeinbase
(
sign
->
r
,
base
)
+
2
];
char
arrR
[
mpz_sizeinbase
(
sign
->
r
,
base
)
+
2
];
char
*
r
=
mpz_get_str
(
arrR
,
base
,
sign
->
r
);
mpz_get_str
(
arrR
,
base
,
sign
->
r
);
strncpy
(
sigR
,
arrR
,
1024
);
strncpy
(
sigR
,
arrR
,
1024
);
char
arrS
[
mpz_sizeinbase
(
sign
->
s
,
base
)
+
2
];
char
arrS
[
mpz_sizeinbase
(
sign
->
s
,
base
)
+
2
];
char
*
s
=
mpz_get_str
(
arrS
,
base
,
sign
->
s
);
mpz_get_str
(
arrS
,
base
,
sign
->
s
);
strncpy
(
sigS
,
arrS
,
1024
);
strncpy
(
sigS
,
arrS
,
1024
);
*
sig_v
=
sign
->
v
;
*
sig_v
=
sign
->
v
;
...
@@ -1182,7 +1148,6 @@ void trustedEcdsaSignAES(int *errStatus, char *errString, uint8_t *encryptedPriv
...
@@ -1182,7 +1148,6 @@ void trustedEcdsaSignAES(int *errStatus, char *errString, uint8_t *encryptedPriv
domain_parameters_clear
(
curve
);
domain_parameters_clear
(
curve
);
signature_free
(
sign
);
signature_free
(
sign
);
point_clear
(
Pkey
);
point_clear
(
Pkey
);
}
}
void
trustedEncryptKeyAES
(
int
*
errStatus
,
char
*
errString
,
const
char
*
key
,
void
trustedEncryptKeyAES
(
int
*
errStatus
,
char
*
errString
,
const
char
*
key
,
...
...
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