Unverified Commit 0b4d1bc9 authored by kladko's avatar kladko

SKALE-3067-cleanup-sgx

parent 13ade9be
...@@ -1397,37 +1397,43 @@ void trustedEncryptKeyAES(int *errStatus, char *errString, const char *key, ...@@ -1397,37 +1397,43 @@ void trustedEncryptKeyAES(int *errStatus, char *errString, const char *key,
if (stat != 0) { if (stat != 0) {
*errStatus = stat; *errStatus = stat;
snprintf(errString, BUF_LEN, "AES encrypt failed with status %d", stat); snprintf(errString, BUF_LEN, "AES encrypt failed with status %d", stat);
return; LOG_ERROR(errString);
goto clean;
} }
*enc_len = strlen(key) + SGX_AESGCM_MAC_SIZE + SGX_AESGCM_IV_SIZE; *enc_len = strlen(key) + SGX_AESGCM_MAC_SIZE + SGX_AESGCM_IV_SIZE;
SAFE_CHAR_BUF(decryptedKey, BUF_LEN); SAFE_CHAR_BUF(decryptedKey, BUF_LEN);
stat = AES_decrypt(encryptedPrivateKey, *enc_len, decryptedKey, BUF_LEN); stat = AES_decrypt(encryptedPrivateKey, *enc_len, decryptedKey, BUF_LEN);
if (stat != 0) { if (stat != 0) {
*errStatus = stat; *errStatus = stat;
snprintf(errString, BUF_LEN, ":trustedDecryptKey failed with status %d", stat); snprintf(errString, BUF_LEN, "trustedDecryptKey failed with status %d", stat);
return; LOG_ERROR(errString);
goto clean;
} }
uint64_t decryptedKeyLen = strnlen(decryptedKey, MAX_KEY_LENGTH); uint64_t decryptedKeyLen = strnlen(decryptedKey, MAX_KEY_LENGTH);
if (decryptedKeyLen == MAX_KEY_LENGTH) { if (decryptedKeyLen == MAX_KEY_LENGTH) {
snprintf(errString, BUF_LEN, "Decrypted key is not null terminated"); snprintf(errString, BUF_LEN, "Decrypted key is not null terminated");
return; LOG_ERROR(errString);
goto clean;
} }
*errStatus = -8; *errStatus = -8;
if (strncmp(key, decryptedKey, MAX_KEY_LENGTH) != 0) { if (strncmp(key, decryptedKey, MAX_KEY_LENGTH) != 0) {
snprintf(errString, BUF_LEN, "Decrypted key does not match original key"); snprintf(errString, BUF_LEN, "Decrypted key does not match original key");
return; LOG_ERROR(errString);
goto clean;
} }
*errStatus = 0; *errStatus = 0;
clean:
;
} }
void trustedDecryptKeyAES(int *errStatus, char *errString, uint8_t *encryptedPrivateKey, void trustedDecryptKeyAES(int *errStatus, char *errString, uint8_t *encryptedPrivateKey,
...@@ -1441,7 +1447,6 @@ void trustedDecryptKeyAES(int *errStatus, char *errString, uint8_t *encryptedPri ...@@ -1441,7 +1447,6 @@ void trustedDecryptKeyAES(int *errStatus, char *errString, uint8_t *encryptedPri
CHECK_STATE(encryptedPrivateKey); CHECK_STATE(encryptedPrivateKey);
CHECK_STATE(key); CHECK_STATE(key);
*errStatus = -9; *errStatus = -9;
int status = AES_decrypt(encryptedPrivateKey, enc_len, key, 3072); int status = AES_decrypt(encryptedPrivateKey, enc_len, key, 3072);
...@@ -1449,7 +1454,8 @@ void trustedDecryptKeyAES(int *errStatus, char *errString, uint8_t *encryptedPri ...@@ -1449,7 +1454,8 @@ void trustedDecryptKeyAES(int *errStatus, char *errString, uint8_t *encryptedPri
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);
return; LOG_ERROR(errString);
goto clean;
} }
*errStatus = -10; *errStatus = -10;
...@@ -1458,12 +1464,15 @@ void trustedDecryptKeyAES(int *errStatus, char *errString, uint8_t *encryptedPri ...@@ -1458,12 +1464,15 @@ void trustedDecryptKeyAES(int *errStatus, char *errString, uint8_t *encryptedPri
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; LOG_ERROR(errString);
goto clean;
} }
memcpy(errString, AES_key, 1024);
*errStatus = 0; *errStatus = 0;
clean:
;
} }
void trustedBlsSignMessageAES(int *errStatus, char *errString, uint8_t *encryptedPrivateKey, void trustedBlsSignMessageAES(int *errStatus, char *errString, uint8_t *encryptedPrivateKey,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment