Skip to content

Commit e56ebd2

Browse files
committed
fix(esp_encrypted_img): address some review comments
1 parent 7e6b372 commit e56ebd2

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

esp_encrypted_img/private_include/esp_encrypted_img_priv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ typedef struct {
8686
#define HEADER_DATA_SIZE sizeof(pre_enc_bin_header)
8787

8888
// Magic Byte is created using command: echo -n "esp_encrypted_img" | sha256sum
89-
static uint32_t esp_enc_img_magic = 0x0788b6cf;
89+
static const uint32_t esp_enc_img_magic = 0x0788b6cf;
9090

9191
#if defined(CONFIG_PRE_ENCRYPTED_OTA_USE_ECIES)
9292
#define HMAC_OUTPUT_SIZE 32

esp_encrypted_img/src/esp_encrypted_img.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "mbedtls/version.h"
1717
#include "mbedtls/pk.h"
18+
#include "sdkconfig.h"
1819

1920
#if !defined(CONFIG_MBEDTLS_VER_4_X_SUPPORT)
2021
#include "mbedtls/entropy.h"
@@ -74,6 +75,7 @@ static esp_err_t gcm_init_and_set_key(esp_encrypted_img_t *handle, const unsigne
7475
status = psa_aead_decrypt_setup(&handle->psa_aead_op, handle->psa_gcm_key_id, PSA_ALG_GCM);
7576
if (status != PSA_SUCCESS) {
7677
ESP_LOGE(TAG, "psa_aead_decrypt_setup failed: %d", (int)status);
78+
psa_aead_abort(&handle->psa_aead_op);
7779
psa_destroy_key(handle->psa_gcm_key_id);
7880
return ESP_FAIL;
7981
}

esp_encrypted_img/test_apps/main/esp_encrypted_img_test.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,20 @@ void setUp(void)
2828
uint8_t ciphertext[16];
2929
const uint8_t key[16] = { 0 };
3030
#if defined(CONFIG_MBEDTLS_VER_4_X_SUPPORT)
31-
psa_crypto_init();
31+
psa_status_t status = psa_crypto_init();
32+
TEST_ASSERT_EQUAL(PSA_SUCCESS, status);
3233
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
3334
psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_ENCRYPT);
3435
psa_set_key_algorithm(&attributes, PSA_ALG_ECB_NO_PADDING);
3536
psa_set_key_type(&attributes, PSA_KEY_TYPE_AES);
3637
psa_set_key_bits(&attributes, 128);
3738
psa_key_id_t key_id;
38-
psa_import_key(&attributes, key, sizeof(key), &key_id);
39+
status = psa_import_key(&attributes, key, sizeof(key), &key_id);
40+
TEST_ASSERT_EQUAL(PSA_SUCCESS, status);
3941
size_t output_length;
40-
psa_cipher_encrypt(key_id, PSA_ALG_ECB_NO_PADDING, plaintext, sizeof(plaintext),
41-
ciphertext, sizeof(ciphertext), &output_length);
42+
status = psa_cipher_encrypt(key_id, PSA_ALG_ECB_NO_PADDING, plaintext, sizeof(plaintext),
43+
ciphertext, sizeof(ciphertext), &output_length);
44+
TEST_ASSERT_EQUAL(PSA_SUCCESS, status);
4245
psa_destroy_key(key_id);
4346
#else
4447
mbedtls_aes_context ctx;

0 commit comments

Comments
 (0)