mirror of
https://github.com/espressif/esp-idf.git
synced 2025-07-30 10:47:19 +02:00
ble_mesh: stack: Fix mbedtls aes ctx not deallocated
This commit is contained in:
@ -1883,6 +1883,7 @@ int bt_mesh_encrypt_le(const uint8_t key[16], const uint8_t plaintext[16],
|
|||||||
sys_memcpy_swap(tmp, key, 16);
|
sys_memcpy_swap(tmp, key, 16);
|
||||||
|
|
||||||
if (mbedtls_aes_setkey_enc(&ctx, tmp, 128) != 0) {
|
if (mbedtls_aes_setkey_enc(&ctx, tmp, 128) != 0) {
|
||||||
|
mbedtls_aes_free(&ctx);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1890,8 +1891,11 @@ int bt_mesh_encrypt_le(const uint8_t key[16], const uint8_t plaintext[16],
|
|||||||
|
|
||||||
if (mbedtls_aes_crypt_ecb(&ctx, MBEDTLS_AES_ENCRYPT,
|
if (mbedtls_aes_crypt_ecb(&ctx, MBEDTLS_AES_ENCRYPT,
|
||||||
tmp, enc_data) != 0) {
|
tmp, enc_data) != 0) {
|
||||||
|
mbedtls_aes_free(&ctx);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mbedtls_aes_free(&ctx);
|
||||||
#else /* CONFIG_MBEDTLS_HARDWARE_AES */
|
#else /* CONFIG_MBEDTLS_HARDWARE_AES */
|
||||||
struct tc_aes_key_sched_struct s = {0};
|
struct tc_aes_key_sched_struct s = {0};
|
||||||
|
|
||||||
@ -1926,13 +1930,17 @@ int bt_mesh_encrypt_be(const uint8_t key[16], const uint8_t plaintext[16],
|
|||||||
mbedtls_aes_init(&ctx);
|
mbedtls_aes_init(&ctx);
|
||||||
|
|
||||||
if (mbedtls_aes_setkey_enc(&ctx, key, 128) != 0) {
|
if (mbedtls_aes_setkey_enc(&ctx, key, 128) != 0) {
|
||||||
|
mbedtls_aes_free(&ctx);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mbedtls_aes_crypt_ecb(&ctx, MBEDTLS_AES_ENCRYPT,
|
if (mbedtls_aes_crypt_ecb(&ctx, MBEDTLS_AES_ENCRYPT,
|
||||||
plaintext, enc_data) != 0) {
|
plaintext, enc_data) != 0) {
|
||||||
|
mbedtls_aes_free(&ctx);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mbedtls_aes_free(&ctx);
|
||||||
#else /* CONFIG_MBEDTLS_HARDWARE_AES */
|
#else /* CONFIG_MBEDTLS_HARDWARE_AES */
|
||||||
struct tc_aes_key_sched_struct s = {0};
|
struct tc_aes_key_sched_struct s = {0};
|
||||||
|
|
||||||
|
@ -1864,6 +1864,7 @@ int bt_mesh_encrypt_le(const uint8_t key[16], const uint8_t plaintext[16],
|
|||||||
sys_memcpy_swap(tmp, key, 16);
|
sys_memcpy_swap(tmp, key, 16);
|
||||||
|
|
||||||
if (mbedtls_aes_setkey_enc(&ctx, tmp, 128) != 0) {
|
if (mbedtls_aes_setkey_enc(&ctx, tmp, 128) != 0) {
|
||||||
|
mbedtls_aes_free(&ctx);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1871,8 +1872,11 @@ int bt_mesh_encrypt_le(const uint8_t key[16], const uint8_t plaintext[16],
|
|||||||
|
|
||||||
if (mbedtls_aes_crypt_ecb(&ctx, MBEDTLS_AES_ENCRYPT,
|
if (mbedtls_aes_crypt_ecb(&ctx, MBEDTLS_AES_ENCRYPT,
|
||||||
tmp, enc_data) != 0) {
|
tmp, enc_data) != 0) {
|
||||||
|
mbedtls_aes_free(&ctx);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mbedtls_aes_free(&ctx);
|
||||||
#else /* CONFIG_MBEDTLS_HARDWARE_AES */
|
#else /* CONFIG_MBEDTLS_HARDWARE_AES */
|
||||||
struct tc_aes_key_sched_struct s = {0};
|
struct tc_aes_key_sched_struct s = {0};
|
||||||
|
|
||||||
@ -1907,13 +1911,17 @@ int bt_mesh_encrypt_be(const uint8_t key[16], const uint8_t plaintext[16],
|
|||||||
mbedtls_aes_init(&ctx);
|
mbedtls_aes_init(&ctx);
|
||||||
|
|
||||||
if (mbedtls_aes_setkey_enc(&ctx, key, 128) != 0) {
|
if (mbedtls_aes_setkey_enc(&ctx, key, 128) != 0) {
|
||||||
|
mbedtls_aes_free(&ctx);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mbedtls_aes_crypt_ecb(&ctx, MBEDTLS_AES_ENCRYPT,
|
if (mbedtls_aes_crypt_ecb(&ctx, MBEDTLS_AES_ENCRYPT,
|
||||||
plaintext, enc_data) != 0) {
|
plaintext, enc_data) != 0) {
|
||||||
|
mbedtls_aes_free(&ctx);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mbedtls_aes_free(&ctx);
|
||||||
#else /* CONFIG_MBEDTLS_HARDWARE_AES */
|
#else /* CONFIG_MBEDTLS_HARDWARE_AES */
|
||||||
struct tc_aes_key_sched_struct s = {0};
|
struct tc_aes_key_sched_struct s = {0};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user