NimBLE: Free the AES context after use by calling mbetls_aes_free

* ESP32C3 allocates DMA channel when using HW AES accelerator.
* Deallocate the DMA channel properly i.e. call `mbedtls_aes_free` after using HW
  AES encryption.

Fixes BT-1435
This commit is contained in:
Prasad Alatkar
2021-07-08 15:03:32 +05:30
parent 4442393400
commit 0d65f4d2b0
2 changed files with 7 additions and 0 deletions
+3
View File
@@ -133,13 +133,16 @@ bt_encrypt_be(const uint8_t *key, const uint8_t *plaintext, uint8_t *enc_data)
mbedtls_aes_init(&s);
if (mbedtls_aes_setkey_enc(&s, key, 128) != 0) {
mbedtls_aes_free(&s);
return BLE_HS_EUNKNOWN;
}
if (mbedtls_aes_crypt_ecb(&s, MBEDTLS_AES_ENCRYPT, plaintext, enc_data) != 0) {
mbedtls_aes_free(&s);
return BLE_HS_EUNKNOWN;
}
mbedtls_aes_free(&s);
return 0;
}
+4
View File
@@ -87,14 +87,18 @@ ble_sm_alg_encrypt(uint8_t *key, uint8_t *plaintext, uint8_t *enc_data)
mbedtls_aes_init(&s);
if (mbedtls_aes_setkey_enc(&s, tmp, 128) != 0) {
mbedtls_aes_free(&s);
return BLE_HS_EUNKNOWN;
}
swap_buf(tmp, plaintext, 16);
if (mbedtls_aes_crypt_ecb(&s, MBEDTLS_AES_ENCRYPT, tmp, enc_data) != 0) {
mbedtls_aes_free(&s);
return BLE_HS_EUNKNOWN;
}
mbedtls_aes_free(&s);
#else
struct tc_aes_key_sched_struct s;