Skip to content

Commit 0e4c086

Browse files
committed
Merge branch 'fix/mbedtls_port_sanity_checks_and_return_values_v4.4' into 'release/v4.4'
mbedtls/port: refactor sanity checks and their return values (v4.4) See merge request espressif/esp-idf!22128
2 parents 11277bf + ecdd202 commit 0e4c086

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

components/mbedtls/port/aes/dma/esp_aes.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,11 @@ int esp_aes_crypt_ctr(esp_aes_context *ctx,
991991
return -1;
992992
}
993993

994+
if (!stream_block) {
995+
ESP_LOGE(TAG, "No stream supplied");
996+
return -1;
997+
}
998+
994999
if (!nonce_counter) {
9951000
ESP_LOGE(TAG, "No nonce supplied");
9961001
return -1;

components/mbedtls/port/aes/esp_aes_gcm.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "esp_heap_caps.h"
4141
#include "soc/soc_memory_layout.h"
4242

43+
#include "mbedtls/error.h"
4344
#include <string.h>
4445

4546
#define ESP_PUT_BE64(a, val) \
@@ -257,6 +258,11 @@ int esp_aes_gcm_setkey( esp_gcm_context *ctx,
257258
const unsigned char *key,
258259
unsigned int keybits )
259260
{
261+
#if !SOC_AES_SUPPORT_AES_192
262+
if (keybits == 192) {
263+
return MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED;
264+
}
265+
#endif
260266
if (keybits != 128 && keybits != 192 && keybits != 256) {
261267
return MBEDTLS_ERR_AES_INVALID_KEY_LENGTH;
262268
}
@@ -471,6 +477,7 @@ int esp_aes_gcm_finish( esp_gcm_context *ctx,
471477
{
472478
size_t nc_off = 0;
473479
uint8_t len_block[AES_BLOCK_BYTES] = {0};
480+
uint8_t stream[AES_BLOCK_BYTES] = {0};
474481

475482
if ( tag_len > 16 || tag_len < 4 ) {
476483
return ( MBEDTLS_ERR_GCM_BAD_INPUT );
@@ -482,7 +489,7 @@ int esp_aes_gcm_finish( esp_gcm_context *ctx,
482489
esp_gcm_ghash(ctx, len_block, AES_BLOCK_BYTES, ctx->ghash);
483490

484491
/* Tag T = GCTR(J0, ) where T is truncated to tag_len */
485-
esp_aes_crypt_ctr(&ctx->aes_ctx, tag_len, &nc_off, ctx->ori_j0, 0, ctx->ghash, tag);
492+
esp_aes_crypt_ctr(&ctx->aes_ctx, tag_len, &nc_off, ctx->ori_j0, stream, ctx->ghash, tag);
486493

487494
return 0;
488495
}

0 commit comments

Comments
 (0)