test(mbedtls): add more tests for alignment, buffer size related

- Also, enabled Flash Encryption enabled tests for ESP32-C5
- Removed ESP32-P4 specific configs, as those configs are set as default now
This commit is contained in:
harshal.patil
2025-12-11 16:48:25 +05:30
parent bb0354aecf
commit b2dabf6f86
7 changed files with 587 additions and 145 deletions
@@ -6,11 +6,8 @@ components/mbedtls/test_apps:
- if: CONFIG_NAME == "psram_all_ext" and SOC_SPIRAM_SUPPORTED != 1
- if: CONFIG_NAME == "ecdsa_sign" and SOC_ECDSA_SUPPORTED != 1
- if: CONFIG_NAME == "psram_all_ext_flash_enc" and SOC_SPIRAM_SUPPORTED != 1
- if: IDF_TARGET == "esp32p4"
temporary: true
reason: p4 rev3 migration # TODO: IDF-14367
disable_test:
- if: CONFIG_NAME == "psram_all_ext_flash_enc" and IDF_TARGET not in ["esp32"]
- if: CONFIG_NAME == "psram_all_ext_flash_enc" and IDF_TARGET not in ["esp32", "esp32p4", "esp32c5"]
reason: lack of runners
depends_components:
- efuse
+2 -2
View File
@@ -1,2 +1,2 @@
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-H21 | ESP32-H4 | ESP32-S2 | ESP32-S3 |
| ----------------- | ----- | -------- | -------- | -------- | -------- | --------- | -------- | --------- | -------- | -------- | -------- |
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-H21 | ESP32-H4 | ESP32-P4 | ESP32-S2 | ESP32-S3 |
| ----------------- | ----- | -------- | -------- | -------- | -------- | --------- | -------- | --------- | -------- | -------- | -------- | -------- |
+574 -84
View File
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
@@ -23,6 +23,18 @@
#include "esp_memory_utils.h"
#include "soc/lldesc.h"
#define INTERNAL_DMA_CAPS (MALLOC_CAP_8BIT | MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL)
#define PSRAM_DMA_CAPS (MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM)
#define TEST_AES_CBC_DMA_MODE_LEN 1600
#define TEST_AES_CTR_DMA_MODE_LEN 1000
#define TEST_AES_OFB_DMA_MODE_LEN 1000
#define TEST_AES_CFB8_DMA_MODE_LEN 1000
#define TEST_AES_CFB128_DMA_MODE_LEN 1000
#define TEST_AES_CTR_STREAM_DMA_MODE_LEN 1000
#define TEST_AES_OFB_STREAM_DMA_MODE_LEN 1000
#define TEST_AES_CFB8_STREAM_DMA_MODE_LEN 1000
#define TEST_AES_CFB128_STREAM_DMA_MODE_LEN 1000
static const uint8_t key_256[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
@@ -69,9 +81,9 @@ static const uint8_t iv[] = {
print("Ciphertext: {}".format(as_c_array(ct)))
*/
TEST_CASE("mbedtls CBC AES-256 test", "[aes]")
static void aes_cbc_test(unsigned int SZ)
{
const unsigned SZ = 1600;
mbedtls_aes_context ctx;
uint8_t nonce[16];
@@ -85,9 +97,9 @@ TEST_CASE("mbedtls CBC AES-256 test", "[aes]")
memcpy(nonce, iv, 16);
// allocate internal memory
uint8_t *ciphertext = heap_caps_malloc(SZ, MALLOC_CAP_8BIT|MALLOC_CAP_INTERNAL);
uint8_t *plaintext = heap_caps_malloc(SZ, MALLOC_CAP_8BIT|MALLOC_CAP_INTERNAL);
uint8_t *decryptedtext = heap_caps_malloc(SZ, MALLOC_CAP_8BIT|MALLOC_CAP_INTERNAL);
uint8_t *ciphertext = heap_caps_malloc(SZ, INTERNAL_DMA_CAPS);
uint8_t *plaintext = heap_caps_malloc(SZ, INTERNAL_DMA_CAPS);
uint8_t *decryptedtext = heap_caps_malloc(SZ, INTERNAL_DMA_CAPS);
TEST_ASSERT_NOT_NULL(ciphertext);
TEST_ASSERT_NOT_NULL(plaintext);
@@ -116,6 +128,11 @@ TEST_CASE("mbedtls CBC AES-256 test", "[aes]")
free(decryptedtext);
}
TEST_CASE("mbedtls CBC AES-256 test", "[aes]")
{
aes_cbc_test(TEST_AES_CBC_DMA_MODE_LEN);
}
TEST_CASE("mbedtls CBC AES-256 DMA buffer align test", "[aes]")
{
#define ALIGN_DOWN(val, align) ((val) & ~((align) - 1))
@@ -134,9 +151,9 @@ TEST_CASE("mbedtls CBC AES-256 DMA buffer align test", "[aes]")
memcpy(nonce, iv, 16);
// allocate internal memory
uint8_t *ciphertext = heap_caps_malloc(SZ, MALLOC_CAP_8BIT|MALLOC_CAP_INTERNAL);
uint8_t *plaintext = heap_caps_malloc(SZ, MALLOC_CAP_8BIT|MALLOC_CAP_INTERNAL);
uint8_t *decryptedtext = heap_caps_malloc(SZ, MALLOC_CAP_8BIT|MALLOC_CAP_INTERNAL);
uint8_t *ciphertext = heap_caps_malloc(SZ, INTERNAL_DMA_CAPS);
uint8_t *plaintext = heap_caps_malloc(SZ, INTERNAL_DMA_CAPS);
uint8_t *decryptedtext = heap_caps_malloc(SZ, INTERNAL_DMA_CAPS);
TEST_ASSERT_NOT_NULL(ciphertext);
TEST_ASSERT_NOT_NULL(plaintext);
@@ -165,9 +182,8 @@ TEST_CASE("mbedtls CBC AES-256 DMA buffer align test", "[aes]")
free(decryptedtext);
}
TEST_CASE("mbedtls CTR AES-256 test", "[aes]")
static void aes_ctr_test(unsigned int SZ)
{
const unsigned SZ = 1000;
mbedtls_aes_context ctx;
uint8_t nonce[16];
uint8_t stream_block[16];
@@ -183,9 +199,9 @@ TEST_CASE("mbedtls CTR AES-256 test", "[aes]")
memcpy(nonce, iv, 16);
// allocate internal memory
uint8_t *ciphertext = heap_caps_malloc(SZ, MALLOC_CAP_8BIT|MALLOC_CAP_INTERNAL);
uint8_t *plaintext = heap_caps_malloc(SZ, MALLOC_CAP_8BIT|MALLOC_CAP_INTERNAL);
uint8_t *decryptedtext = heap_caps_malloc(SZ, MALLOC_CAP_8BIT|MALLOC_CAP_INTERNAL);
uint8_t *ciphertext = heap_caps_malloc(SZ, INTERNAL_DMA_CAPS);
uint8_t *plaintext = heap_caps_malloc(SZ, INTERNAL_DMA_CAPS);
uint8_t *decryptedtext = heap_caps_malloc(SZ, INTERNAL_DMA_CAPS);
TEST_ASSERT_NOT_NULL(ciphertext);
TEST_ASSERT_NOT_NULL(plaintext);
@@ -214,9 +230,13 @@ TEST_CASE("mbedtls CTR AES-256 test", "[aes]")
free(decryptedtext);
}
TEST_CASE("mbedtls OFB AES-256 test", "[aes]")
TEST_CASE("mbedtls CTR AES-256 test", "[aes]")
{
aes_ctr_test(TEST_AES_CTR_DMA_MODE_LEN);
}
static void aes_ofb_test(unsigned int SZ)
{
const unsigned SZ = 1000;
mbedtls_aes_context ctx;
uint8_t nonce[16];
size_t nc_off = 0;
@@ -231,9 +251,9 @@ TEST_CASE("mbedtls OFB AES-256 test", "[aes]")
memcpy(nonce, iv, 16);
// allocate internal memory
uint8_t *ciphertext = heap_caps_malloc(SZ, MALLOC_CAP_8BIT|MALLOC_CAP_INTERNAL);
uint8_t *plaintext = heap_caps_malloc(SZ, MALLOC_CAP_8BIT|MALLOC_CAP_INTERNAL);
uint8_t *decryptedtext = heap_caps_malloc(SZ, MALLOC_CAP_8BIT|MALLOC_CAP_INTERNAL);
uint8_t *ciphertext = heap_caps_malloc(SZ, INTERNAL_DMA_CAPS);
uint8_t *plaintext = heap_caps_malloc(SZ, INTERNAL_DMA_CAPS);
uint8_t *decryptedtext = heap_caps_malloc(SZ, INTERNAL_DMA_CAPS);
TEST_ASSERT_NOT_NULL(ciphertext);
TEST_ASSERT_NOT_NULL(plaintext);
@@ -262,9 +282,13 @@ TEST_CASE("mbedtls OFB AES-256 test", "[aes]")
free(decryptedtext);
}
TEST_CASE("mbedtls CFB-8 AES-256 test", "[aes]")
TEST_CASE("mbedtls OFB AES-256 test", "[aes]")
{
aes_ofb_test(TEST_AES_OFB_DMA_MODE_LEN);
}
static void aes_cfb8_test(unsigned int SZ)
{
const unsigned SZ = 1000;
mbedtls_aes_context ctx;
uint8_t nonce[16];
@@ -278,9 +302,9 @@ TEST_CASE("mbedtls CFB-8 AES-256 test", "[aes]")
memcpy(nonce, iv, 16);
// allocate internal memory
uint8_t *ciphertext = heap_caps_malloc(SZ, MALLOC_CAP_8BIT|MALLOC_CAP_INTERNAL);
uint8_t *plaintext = heap_caps_malloc(SZ, MALLOC_CAP_8BIT|MALLOC_CAP_INTERNAL);
uint8_t *decryptedtext = heap_caps_malloc(SZ, MALLOC_CAP_8BIT|MALLOC_CAP_INTERNAL);
uint8_t *ciphertext = heap_caps_malloc(SZ, INTERNAL_DMA_CAPS);
uint8_t *plaintext = heap_caps_malloc(SZ, INTERNAL_DMA_CAPS);
uint8_t *decryptedtext = heap_caps_malloc(SZ, INTERNAL_DMA_CAPS);
TEST_ASSERT_NOT_NULL(ciphertext);
TEST_ASSERT_NOT_NULL(plaintext);
@@ -308,9 +332,13 @@ TEST_CASE("mbedtls CFB-8 AES-256 test", "[aes]")
free(decryptedtext);
}
TEST_CASE("mbedtls CFB-128 AES-256 test", "[aes]")
TEST_CASE("mbedtls CFB-8 AES-256 test", "[aes]")
{
aes_cfb8_test(TEST_AES_CFB8_DMA_MODE_LEN);
}
static void aes_cfb128_test(unsigned int SZ)
{
const unsigned SZ = 1000;
mbedtls_aes_context ctx;
uint8_t nonce[16];
size_t nc_off = 0;
@@ -325,9 +353,9 @@ TEST_CASE("mbedtls CFB-128 AES-256 test", "[aes]")
memcpy(nonce, iv, 16);
// allocate internal memory
uint8_t *ciphertext = heap_caps_malloc(SZ, MALLOC_CAP_8BIT|MALLOC_CAP_INTERNAL);
uint8_t *plaintext = heap_caps_malloc(SZ, MALLOC_CAP_8BIT|MALLOC_CAP_INTERNAL);
uint8_t *decryptedtext = heap_caps_malloc(SZ, MALLOC_CAP_8BIT|MALLOC_CAP_INTERNAL);
uint8_t *ciphertext = heap_caps_malloc(SZ, INTERNAL_DMA_CAPS);
uint8_t *plaintext = heap_caps_malloc(SZ, INTERNAL_DMA_CAPS);
uint8_t *decryptedtext = heap_caps_malloc(SZ, INTERNAL_DMA_CAPS);
TEST_ASSERT_NOT_NULL(ciphertext);
TEST_ASSERT_NOT_NULL(plaintext);
@@ -356,9 +384,13 @@ TEST_CASE("mbedtls CFB-128 AES-256 test", "[aes]")
free(decryptedtext);
}
static void aes_ctr_stream_test(void)
TEST_CASE("mbedtls CFB-128 AES-256 test", "[aes]")
{
aes_cfb128_test(TEST_AES_CFB128_DMA_MODE_LEN);
}
static void aes_ctr_stream_test(uint32_t input_buf_caps, uint32_t output_buf_caps, unsigned int SZ)
{
const unsigned SZ = 100;
mbedtls_aes_context ctx;
uint8_t nonce[16];
uint8_t key[16];
@@ -372,12 +404,12 @@ static void aes_ctr_stream_test(void)
nonce = b'\xee' * 16
cipher = Cipher(algorithms.AES(key), modes.CTR(nonce), backend=default_backend())
encryptor = cipher.encryptor()
ct = encryptor.update(b'\xaa' * 100) + encryptor.finalize()
ct = encryptor.update(b'\xaa' * 1000) + encryptor.finalize()
ct_arr = ""
for idx, b in enumerate(ct):
if idx % 8 == 0:
ct_arr += '\n'
ct_arr += "0x{}, ".format(binascii.hexlify(b))
ct_arr += "0x{}, ".format(format(b, '02x'))
print(ct_arr)
*/
const uint8_t expected_cipher[] = {
@@ -393,17 +425,128 @@ static void aes_ctr_stream_test(void)
0xd0, 0x5e, 0xe5, 0x3f, 0xc5, 0xed, 0x5c, 0x18,
0xa7, 0x84, 0xd8, 0xdf, 0x9d, 0xb5, 0x06, 0xb1,
0xa7, 0xcf, 0x2e, 0x7a, 0x51, 0xfc, 0x44, 0xc5,
0xb9, 0x5f, 0x22, 0x47,
0xb9, 0x5f, 0x22, 0x47, 0x91, 0xbd, 0x67, 0x89,
0x15, 0xcd, 0x6a, 0xac, 0xa7, 0x8f, 0x6c, 0xff,
0x64, 0xc4, 0xbd, 0x53, 0xb6, 0x24, 0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x30, 0xbb, 0x1f, 0x93, 0x30, 0x4e, 0x99,
0xad, 0x4f, 0xce, 0x0b, 0xa1, 0x7f, 0xdf, 0x66,
0x44, 0xb0, 0x49, 0x2c, 0x16, 0x9e, 0x22, 0x9b,
0x88, 0xf0, 0x2b, 0x7d, 0xdd, 0x46, 0x50, 0x27,
0xef, 0x61, 0x7b, 0xe2, 0xd8, 0xfd, 0x42, 0x10,
0xeb, 0x07, 0xdf, 0x31, 0xf2, 0xb9, 0xab, 0xba,
0x04, 0x95, 0xa7, 0xb3, 0x74, 0x71, 0xa8, 0x34,
0x31, 0x95, 0xd6, 0x9a, 0x01, 0xd8, 0xab, 0x94,
0xcc, 0x38, 0x8d, 0xb1, 0xa2, 0xe4, 0xeb, 0x86,
0xbc, 0x84, 0x22, 0x23, 0xc2, 0xf3, 0x48, 0xaa,
0xb9, 0x70, 0xd4, 0x20, 0x3c, 0xef, 0x61, 0xe2,
0x10, 0x7c, 0x03, 0x6a, 0x8b, 0xab, 0x6b, 0xce,
0xa2, 0x38, 0xaa, 0xc1, 0x43, 0x5c, 0x9b, 0x06,
0x1e, 0x55, 0x13, 0x49, 0x36, 0x35, 0x6e, 0x10,
0x56, 0xe2, 0x0c, 0xe2, 0x2f, 0xb9, 0x67, 0xc6,
0xb0, 0x61, 0xd9, 0x1d, 0x81, 0xb9, 0x47, 0x64,
0xd3, 0x7a, 0x55, 0x56, 0x6c, 0xf5, 0x15, 0xc8,
0x23, 0xdc, 0x5f, 0xf9, 0xff, 0xba, 0x28, 0xe4,
};
memset(nonce, 0xEE, 16);
memset(key, 0x44, 16);
// allocate internal memory
uint8_t *ciphertext = heap_caps_malloc(SZ, MALLOC_CAP_DMA | MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL);
uint8_t *plaintext = heap_caps_malloc(SZ, MALLOC_CAP_DMA | MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL);
uint8_t *decryptedtext = heap_caps_malloc(SZ, MALLOC_CAP_DMA | MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL);
uint8_t *ciphertext = heap_caps_malloc(SZ, input_buf_caps);
uint8_t *plaintext = heap_caps_malloc(SZ, output_buf_caps);
uint8_t *decryptedtext = heap_caps_malloc(SZ, INTERNAL_DMA_CAPS);
TEST_ASSERT_NOT_NULL(ciphertext);
TEST_ASSERT_NOT_NULL(plaintext);
@@ -458,13 +601,11 @@ static void aes_ctr_stream_test(void)
TEST_CASE("mbedtls CTR stream test", "[aes]")
{
aes_ctr_stream_test();
aes_ctr_stream_test(INTERNAL_DMA_CAPS, INTERNAL_DMA_CAPS, TEST_AES_CTR_STREAM_DMA_MODE_LEN);
}
TEST_CASE("mbedtls OFB stream test", "[aes]")
static void aes_ofb_stream_test(unsigned int SZ)
{
const unsigned SZ = 100;
mbedtls_aes_context ctx;
uint8_t iv[16];
uint8_t key[16];
@@ -477,12 +618,12 @@ TEST_CASE("mbedtls OFB stream test", "[aes]")
iv = b'\xee' * 16
cipher = Cipher(algorithms.AES(key), modes.OFB(iv), backend=default_backend())
encryptor = cipher.encryptor()
ct = encryptor.update(b'\xaa' * 100) + encryptor.finalize()
ct = encryptor.update(b'\xaa' * 1000) + encryptor.finalize()
ct_arr = ""
for idx, b in enumerate(ct):
if idx % 8 == 0:
ct_arr += '\n'
ct_arr += "0x{}, ".format(binascii.hexlify(b))
ct_arr += "0x{}, ".format(format(b, '02x'))
print(ct_arr)
*/
const uint8_t expected_cipher[] = {
@@ -498,16 +639,127 @@ TEST_CASE("mbedtls OFB stream test", "[aes]")
0x2a, 0x76, 0x80, 0x20, 0x82, 0x39, 0xa2, 0x21,
0xf8, 0x7a, 0xec, 0xae, 0x82, 0x6a, 0x5c, 0xd3,
0x04, 0xd9, 0xbd, 0xe4, 0x53, 0xc9, 0xdf, 0x67,
0xaa, 0x5c, 0xaf, 0xa6,
0xaa, 0x5c, 0xaf, 0xa6, 0x95, 0x84, 0x01, 0xae,
0x62, 0x24, 0xc7, 0xf5, 0x44, 0x30, 0x9b, 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d, 0x63, 0x85, 0x46, 0x43, 0x10, 0xc2, 0xa7,
0x05, 0x8c, 0x41, 0x14, 0x0c, 0xa1, 0xdf, 0x26,
0xee, 0xd3, 0xc7, 0x06, 0x45, 0x54, 0xe3, 0xc5,
0x7f, 0xfd, 0x52, 0xc3, 0xe8, 0xf9, 0x3a, 0x96,
0xd7, 0x32, 0x38, 0xa9, 0xd3, 0x7e, 0x15, 0x16,
0x3e, 0xcd, 0xcf, 0xd2, 0xea, 0x01, 0xd4, 0xc6,
0x3a, 0x01, 0x4d, 0x0f, 0x64, 0xf9, 0xc1, 0xe0,
0xf4, 0xcd, 0xc0, 0xe8, 0x50, 0x4f, 0x79, 0xb9,
0x79, 0xae, 0x15, 0x1e, 0x6d, 0xf9, 0x2a, 0xca,
0x37, 0x79, 0x34, 0x2b, 0x96, 0x18, 0x2c, 0x88,
0x3f, 0x2b, 0xf1, 0x8d, 0x6d, 0x56, 0x60, 0xe8,
0x36, 0x48, 0x0c, 0x0b, 0x78, 0x79, 0x71, 0x67,
0xf2, 0x35, 0x2d, 0x4c, 0xf2, 0x9f, 0xc7, 0xce,
0x4d, 0x36, 0x92, 0xeb, 0x81, 0x30, 0xac, 0xcf,
0xbc, 0x34, 0x13, 0x42, 0x39, 0x74, 0x8f, 0x23,
0x77, 0xd3, 0x2b, 0x7e, 0xd3, 0x5d, 0x0c, 0x36,
0x73, 0x4b, 0x09, 0xb2, 0xc9, 0xd2, 0xd2, 0x07,
0xda, 0xbd, 0x8f, 0x78, 0xb8, 0xdf, 0x29, 0xdb,
0xe4, 0xbf, 0xcd, 0x23, 0x2f, 0x7a, 0x58, 0x86,
};
memset(key, 0x44, 16);
// allocate internal memory
uint8_t *ciphertext = heap_caps_malloc(SZ, MALLOC_CAP_DMA | MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL);
uint8_t *plaintext = heap_caps_malloc(SZ, MALLOC_CAP_DMA | MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL);
uint8_t *decryptedtext = heap_caps_malloc(SZ, MALLOC_CAP_DMA | MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL);
uint8_t *ciphertext = heap_caps_malloc(SZ, INTERNAL_DMA_CAPS);
uint8_t *plaintext = heap_caps_malloc(SZ, INTERNAL_DMA_CAPS);
uint8_t *decryptedtext = heap_caps_malloc(SZ, INTERNAL_DMA_CAPS);
TEST_ASSERT_NOT_NULL(ciphertext);
TEST_ASSERT_NOT_NULL(plaintext);
@@ -552,9 +804,13 @@ TEST_CASE("mbedtls OFB stream test", "[aes]")
free(decryptedtext);
}
TEST_CASE("mbedtls CFB8 stream test", "[aes]")
TEST_CASE("mbedtls OFB stream test", "[aes]")
{
aes_ofb_stream_test(TEST_AES_OFB_STREAM_DMA_MODE_LEN);
}
static void aes_cfb8_stream_test(unsigned int SZ)
{
const unsigned SZ = 32;
mbedtls_aes_context ctx;
uint8_t iv[16];
uint8_t key[16];
@@ -567,12 +823,12 @@ TEST_CASE("mbedtls CFB8 stream test", "[aes]")
iv = b'\xee' * 16
cipher = Cipher(algorithms.AES(key), modes.CFB8(iv), backend=default_backend())
encryptor = cipher.encryptor()
ct = encryptor.update(b'\xaa' * 100) + encryptor.finalize()
ct = encryptor.update(b'\xaa' * 1000) + encryptor.finalize()
ct_arr = ""
for idx, b in enumerate(ct):
if idx % 8 == 0:
ct_arr += '\n'
ct_arr += "0x{}, ".format(binascii.hexlify(b))
ct_arr += "0x{}, ".format(format(b, '02x'))
print(ct_arr)
*/
const uint8_t expected_cipher[] = {
@@ -588,16 +844,127 @@ TEST_CASE("mbedtls CFB8 stream test", "[aes]")
0xa6, 0xac, 0x0b, 0x54, 0x25, 0x24, 0x67, 0xd6,
0x09, 0xb1, 0x8f, 0x91, 0x63, 0xbd, 0xdf, 0xa1,
0x8a, 0xa3, 0x2e, 0xeb, 0x15, 0x7d, 0xe5, 0x37,
0xe5, 0x5a, 0x9f, 0xa5,
0xe5, 0x5a, 0x9f, 0xa5, 0x21, 0xc2, 0xbd, 0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0x1e, 0xb8, 0x7a, 0xf2, 0x7d, 0x31, 0x1d, 0x83,
0xce, 0x3b, 0x5c, 0x5a, 0x03, 0xe3, 0xfc, 0x9a,
0xfe, 0xaa, 0x3c, 0xf9, 0x9f, 0x60, 0x7c, 0x54,
0x02, 0x70, 0x23, 0xdb, 0x23, 0xe7, 0x4d, 0x5b,
0x41, 0x8c, 0x1b, 0x01, 0xc9, 0x8e, 0x41, 0xb3,
0xb9, 0x61, 0x90, 0xc1, 0x2b, 0xc5, 0xfa, 0xcf,
0x05, 0x4d, 0xe0, 0x1a, 0x9f, 0xc3, 0xa3, 0x6c,
0x81, 0x4c, 0x6a, 0x33, 0x8f, 0x74, 0x71, 0x79,
0x5d, 0x30, 0x62, 0x03, 0xaa, 0x52, 0x61, 0x0d,
0xaf, 0xf7, 0xe1, 0x80, 0x5b, 0x97, 0x30, 0x6d,
0x31, 0x21, 0xc1, 0x02, 0x43, 0x99, 0x2b, 0x49,
0xe9, 0x83, 0x5d, 0x24, 0x40, 0x5a, 0xcd, 0x2f,
0x20, 0xe4, 0x69, 0x7a, 0x22, 0xcf, 0x1d, 0xb2,
0x90, 0x2d, 0xda, 0x42, 0xf8, 0xb3, 0x8a, 0x3d,
0x55, 0x5a, 0xc5, 0x0f, 0x12, 0x25, 0x3d, 0x98,
0xa1, 0x83, 0xd3, 0x3b, 0xa5, 0xe1, 0x36, 0x2f,
0x85, 0xe1, 0x4b, 0x48, 0x5e, 0xe7, 0xc1, 0x57,
0x19, 0xca, 0xc0, 0xc0, 0x23, 0x59, 0x06, 0xb6,
0x32, 0xeb, 0x9e, 0x2b, 0xf5, 0x23, 0x5a, 0x90,
0xfc, 0x6d, 0xd1, 0xcd, 0x3a, 0x93, 0xdd, 0xc2,
};
memset(key, 0x44, 16);
// allocate internal memory
uint8_t *ciphertext = heap_caps_malloc(SZ, MALLOC_CAP_DMA | MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL);
uint8_t *plaintext = heap_caps_malloc(SZ, MALLOC_CAP_DMA | MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL);
uint8_t *decryptedtext = heap_caps_malloc(SZ, MALLOC_CAP_DMA | MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL);
uint8_t *ciphertext = heap_caps_malloc(SZ, INTERNAL_DMA_CAPS);
uint8_t *plaintext = heap_caps_malloc(SZ, INTERNAL_DMA_CAPS);
uint8_t *decryptedtext = heap_caps_malloc(SZ, INTERNAL_DMA_CAPS);
TEST_ASSERT_NOT_NULL(ciphertext);
TEST_ASSERT_NOT_NULL(plaintext);
@@ -637,9 +1004,13 @@ TEST_CASE("mbedtls CFB8 stream test", "[aes]")
free(decryptedtext);
}
TEST_CASE("mbedtls CFB128 stream test", "[aes]")
TEST_CASE("mbedtls CFB8 stream test", "[aes]")
{
aes_cfb8_stream_test(TEST_AES_CFB8_STREAM_DMA_MODE_LEN);
}
static void aes_cfb128_stream_test(unsigned int SZ)
{
const unsigned SZ = 32;
mbedtls_aes_context ctx;
uint8_t iv[16];
uint8_t key[16];
@@ -652,12 +1023,12 @@ TEST_CASE("mbedtls CFB128 stream test", "[aes]")
iv = b'\xee' * 16
cipher = Cipher(algorithms.AES(key), modes.CFB(iv), backend=default_backend())
encryptor = cipher.encryptor()
ct = encryptor.update(b'\xaa' * 100) + encryptor.finalize()
ct = encryptor.update(b'\xaa' * 1000) + encryptor.finalize()
ct_arr = ""
for idx, b in enumerate(ct):
if idx % 8 == 0:
ct_arr += '\n'
ct_arr += "0x{}, ".format(binascii.hexlify(b))
ct_arr += "0x{}, ".format(format(b, '02x'))
print(ct_arr)
*/
const uint8_t expected_cipher[] = {
@@ -673,16 +1044,127 @@ TEST_CASE("mbedtls CFB128 stream test", "[aes]")
0xf4, 0x23, 0x61, 0x12, 0x71, 0xbe, 0x03, 0x74,
0x99, 0x81, 0x9d, 0x65, 0x48, 0xd9, 0xd4, 0x67,
0xd1, 0x31, 0xe8, 0x44, 0x27, 0x17, 0xd4, 0x2d,
0x3d, 0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x22,
0x5e, 0xd4, 0x31, 0x10, 0xf6, 0xf6, 0xd8, 0x44,
0xe3, 0xbc, 0x85, 0xd4, 0xf7, 0x2c, 0x0d, 0x7b,
0x88, 0xd0, 0x15, 0x5f, 0x0a, 0x8a, 0x29, 0x01,
0x29, 0x27, 0x26, 0xf1, 0xa3, 0x0b, 0x53, 0x8f,
0xed, 0xad, 0x5e, 0xec, 0xb5, 0x1a, 0x3c, 0x7e,
0x14, 0xaa, 0x47, 0x11, 0xc9, 0x48, 0x32, 0xfe,
0xa6, 0x58, 0xe1, 0x38, 0x76, 0x90, 0x32, 0x5a,
0x5b, 0x13, 0x2d, 0x34, 0x14, 0x00, 0x3f, 0xcc,
0xd7, 0xe8, 0x48, 0x13, 0xe6, 0xfe, 0x8c, 0xd1,
0x33, 0xfe, 0xf8, 0xa6, 0x75, 0xff, 0x2c, 0xb7,
0xfc, 0x18, 0x4c, 0x7c, 0x39, 0x48, 0x88, 0xb1,
0x35, 0x06, 0xfa, 0xad, 0x88, 0xd9, 0xae, 0x42,
0x1b, 0x0b, 0x54, 0x95, 0x44, 0x5d, 0x39, 0xb6,
0xda, 0xe5, 0x2d, 0xeb, 0x1b, 0xca, 0x8f, 0xab,
0xd0, 0xb3, 0x7c, 0xdb, 0x5b, 0x00, 0x92, 0xfb,
0x27, 0x26, 0x46, 0x84, 0xe9, 0xfe, 0x64, 0x0e,
0x80, 0x07, 0x48, 0xf6, 0x44, 0x2f, 0xad, 0x94,
0x54, 0xa0, 0x91, 0x96, 0xc8, 0xf6, 0x55, 0xbd,
0xd5, 0x59, 0xe0, 0xf3, 0xae, 0x2a, 0xee, 0xd6,
0x12, 0xec, 0xd7, 0x90, 0x0f, 0x5f, 0x7c, 0x34,
0x31, 0xdb, 0x42, 0x4d, 0xe4, 0x82, 0x6d, 0xe5,
};
memset(key, 0x44, 16);
// allocate internal memory
uint8_t *ciphertext = heap_caps_malloc(SZ, MALLOC_CAP_DMA | MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL);
uint8_t *plaintext = heap_caps_malloc(SZ, MALLOC_CAP_DMA | MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL);
uint8_t *decryptedtext = heap_caps_malloc(SZ, MALLOC_CAP_DMA | MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL);
uint8_t *ciphertext = heap_caps_malloc(SZ, INTERNAL_DMA_CAPS);
uint8_t *plaintext = heap_caps_malloc(SZ, INTERNAL_DMA_CAPS);
uint8_t *decryptedtext = heap_caps_malloc(SZ, INTERNAL_DMA_CAPS);
TEST_ASSERT_NOT_NULL(ciphertext);
TEST_ASSERT_NOT_NULL(plaintext);
@@ -724,6 +1206,11 @@ TEST_CASE("mbedtls CFB128 stream test", "[aes]")
free(decryptedtext);
}
TEST_CASE("mbedtls CFB128 stream test", "[aes]")
{
aes_cfb128_stream_test(TEST_AES_CFB128_DMA_MODE_LEN);
}
/* Cipher produced via this Python:
import os, binascii
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
@@ -732,12 +1219,12 @@ TEST_CASE("mbedtls CFB128 stream test", "[aes]")
nonce = b'\xee' * 16
cipher = Cipher(algorithms.AES(key), modes.CTR(nonce), backend=default_backend())
encryptor = cipher.encryptor()
ct = encryptor.update(b'\xaa' * 100) + encryptor.finalize()
ct = encryptor.update(b'\xaa' * 1000) + encryptor.finalize()
ct_arr = ""
for idx, b in enumerate(ct):
if idx % 8 == 0:
ct_arr += '\n'
ct_arr += "0x{}, ".format(binascii.hexlify(b))
ct_arr += "0x{}, ".format(format(b, '02x'))
print(ct_arr)
*/
@@ -760,7 +1247,7 @@ TEST_CASE("mbedtls CTR, input buf = output buf", "[aes]")
memcpy(nonce, iv, 16);
// allocate internal memory
uint8_t *buf = heap_caps_malloc(SZ, MALLOC_CAP_8BIT|MALLOC_CAP_INTERNAL);
uint8_t *buf = heap_caps_malloc(SZ, INTERNAL_DMA_CAPS);
TEST_ASSERT_NOT_NULL(buf);
@@ -804,9 +1291,9 @@ TEST_CASE("mbedtls OFB, chained DMA descriptors", "[aes]")
memcpy(nonce, iv, 16);
// allocate internal memory
uint8_t *ciphertext = heap_caps_malloc(SZ, MALLOC_CAP_8BIT|MALLOC_CAP_INTERNAL);
uint8_t *plaintext = heap_caps_malloc(SZ, MALLOC_CAP_8BIT|MALLOC_CAP_INTERNAL);
uint8_t *decryptedtext = heap_caps_malloc(SZ, MALLOC_CAP_8BIT|MALLOC_CAP_INTERNAL);
uint8_t *ciphertext = heap_caps_malloc(SZ, INTERNAL_DMA_CAPS);
uint8_t *plaintext = heap_caps_malloc(SZ, INTERNAL_DMA_CAPS);
uint8_t *decryptedtext = heap_caps_malloc(SZ, INTERNAL_DMA_CAPS);
TEST_ASSERT_NOT_NULL(ciphertext);
TEST_ASSERT_NOT_NULL(plaintext);
@@ -860,7 +1347,7 @@ void aes_ctr_alignment_test(uint32_t input_buf_caps, uint32_t output_buf_caps)
// allocate memory according the requested caps
uint8_t *ciphertext = heap_caps_malloc(SZ + ALIGNMENT_SIZE_BYTES, output_buf_caps);
uint8_t *plaintext = heap_caps_malloc(SZ + ALIGNMENT_SIZE_BYTES, input_buf_caps);
uint8_t *decryptedtext = heap_caps_malloc(SZ, MALLOC_CAP_DMA | MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL);
uint8_t *decryptedtext = heap_caps_malloc(SZ, INTERNAL_DMA_CAPS);
TEST_ASSERT_NOT_NULL(ciphertext);
TEST_ASSERT_NOT_NULL(plaintext);
@@ -898,7 +1385,7 @@ void aes_ctr_alignment_test(uint32_t input_buf_caps, uint32_t output_buf_caps)
TEST_CASE("mbedtls AES internal mem alignment tests", "[aes]")
{
uint32_t internal_dma_caps = MALLOC_CAP_DMA | MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL;
uint32_t internal_dma_caps = INTERNAL_DMA_CAPS;
aes_ctr_alignment_test(internal_dma_caps, internal_dma_caps);
}
@@ -917,7 +1404,7 @@ void aes_psram_one_buf_ctr_test(void)
memset(key, 0x1E, 16);
// allocate external memory
uint8_t *buf = heap_caps_malloc(SZ + ALIGNMENT_SIZE_BYTES, MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM);
uint8_t *buf = heap_caps_malloc(SZ + ALIGNMENT_SIZE_BYTES, PSRAM_DMA_CAPS);
TEST_ASSERT_NOT_NULL(buf);
@@ -1484,7 +1971,7 @@ void aes_ext_flash_ctr_test(uint32_t output_buf_caps)
memset(key, 0x1E, 16);
uint8_t *ciphertext = heap_caps_malloc(SZ, output_buf_caps);
uint8_t *decryptedtext = heap_caps_malloc(SZ, MALLOC_CAP_8BIT | MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL);
uint8_t *decryptedtext = heap_caps_malloc(SZ, INTERNAL_DMA_CAPS);
TEST_ASSERT_NOT_NULL(ciphertext);
TEST_ASSERT_NOT_NULL(decryptedtext);
@@ -1516,17 +2003,20 @@ void aes_ext_flash_ctr_test(uint32_t output_buf_caps)
/* Tests how crypto DMA handles data in external memory */
TEST_CASE("mbedtls AES PSRAM tests", "[aes]")
{
aes_ctr_alignment_test(MALLOC_CAP_DMA | MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL, MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM);
aes_ctr_alignment_test(MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM, MALLOC_CAP_DMA | MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL);
aes_ctr_alignment_test(MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM, MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM);
aes_ctr_alignment_test(INTERNAL_DMA_CAPS, PSRAM_DMA_CAPS);
aes_ctr_alignment_test(PSRAM_DMA_CAPS, INTERNAL_DMA_CAPS);
aes_ctr_alignment_test(PSRAM_DMA_CAPS, PSRAM_DMA_CAPS);
aes_psram_one_buf_ctr_test();
aes_ctr_stream_test(INTERNAL_DMA_CAPS, PSRAM_DMA_CAPS, TEST_AES_CTR_STREAM_DMA_MODE_LEN);
aes_ctr_stream_test(PSRAM_DMA_CAPS, INTERNAL_DMA_CAPS, TEST_AES_CTR_STREAM_DMA_MODE_LEN);
aes_ctr_stream_test(PSRAM_DMA_CAPS, PSRAM_DMA_CAPS, TEST_AES_CTR_STREAM_DMA_MODE_LEN);
}
/* Tests how crypto DMA handles data from external flash */
TEST_CASE("mbedtls AES external flash tests", "[aes]")
{
aes_ext_flash_ctr_test(MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM);
aes_ext_flash_ctr_test(MALLOC_CAP_DMA | MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL);
aes_ext_flash_ctr_test(PSRAM_DMA_CAPS);
aes_ext_flash_ctr_test(INTERNAL_DMA_CAPS);
}
#endif // CONFIG_SPIRAM_USE_MALLOC
@@ -1535,7 +2025,7 @@ static SemaphoreHandle_t done_sem;
static void __attribute__((unused)) aes_ctr_stream_test_task(void *pv)
{
aes_ctr_stream_test();
aes_ctr_stream_test(INTERNAL_DMA_CAPS, INTERNAL_DMA_CAPS, TEST_AES_CTR_STREAM_DMA_MODE_LEN);
xSemaphoreGive(done_sem);
vTaskDelete(NULL);
}
@@ -1571,7 +2061,7 @@ TEST_CASE("mbedtls AES stack in PSRAM", "[mbedtls]")
done_sem = xSemaphoreCreateBinary();
static StaticTask_t psram_task;
size_t STACK_SIZE = 3072;
uint8_t *psram_stack = heap_caps_calloc(STACK_SIZE, 1, MALLOC_CAP_SPIRAM);
uint8_t *psram_stack = heap_caps_calloc(STACK_SIZE, 1, PSRAM_DMA_CAPS);
TEST_ASSERT(esp_ptr_external_ram(psram_stack));
@@ -3,6 +3,7 @@
import pytest
from pytest_embedded import Dut
from pytest_embedded_idf.utils import idf_parametrize
from pytest_embedded_idf.utils import soc_filtered_targets
@pytest.mark.generic
@@ -34,7 +35,7 @@ def test_mbedtls_esp32_compiler_perf_opt(dut: Dut) -> None:
)
@idf_parametrize('target', ['esp32', 'esp32s2', 'esp32s3', 'esp32c3', 'esp32c5'], indirect=['target'])
def test_mbedtls_aes_no_hw(dut: Dut) -> None:
dut.run_all_single_board_cases()
dut.run_all_single_board_cases(timeout=180)
@pytest.mark.generic
@@ -46,9 +47,9 @@ def test_mbedtls_aes_no_hw(dut: Dut) -> None:
],
indirect=True,
)
@idf_parametrize('target', ['esp32', 'esp32s2', 'esp32s3', 'esp32c5', 'esp32c61'], indirect=['target'])
@idf_parametrize('target', soc_filtered_targets('SOC_SPIRAM_SUPPORTED == 1'), indirect=['target'])
def test_mbedtls_psram(dut: Dut) -> None:
dut.run_all_single_board_cases()
dut.run_all_single_board_cases(timeout=180)
@pytest.mark.flash_encryption_psram
@@ -60,32 +61,21 @@ def test_mbedtls_psram(dut: Dut) -> None:
indirect=True,
)
@idf_parametrize('target', ['esp32'], indirect=['target'])
def test_mbedtls_psram_all_ext_flash_enc(dut: Dut) -> None:
dut.run_all_single_board_cases()
@pytest.mark.generic
@pytest.mark.parametrize(
'config',
['psram_esp32p4_200m', 'psram_all_ext_esp32p4_200m'],
indirect=True,
)
@idf_parametrize('target', ['esp32p4'], indirect=['target'])
def test_mbedtls_psram_esp32p4(dut: Dut) -> None:
dut.run_all_single_board_cases()
def test_mbedtls_psram_all_ext_flash_enc_esp32(dut: Dut) -> None:
dut.run_all_single_board_cases(timeout=180)
@pytest.mark.flash_encryption
@pytest.mark.parametrize(
'config',
[
'psram_all_ext_flash_enc_esp32p4_200m',
'psram_all_ext_flash_enc',
],
indirect=True,
)
@idf_parametrize('target', ['esp32p4'], indirect=['target'])
def test_mbedtls_psram_all_ext_flash_enc_esp32p4_200m(dut: Dut) -> None:
dut.run_all_single_board_cases()
@idf_parametrize('target', ['esp32p4', 'esp32c5'], indirect=['target'])
def test_mbedtls_psram_all_ext_flash_enc(dut: Dut) -> None:
dut.run_all_single_board_cases(timeout=180)
@pytest.mark.ecdsa_efuse
@@ -1,8 +0,0 @@
CONFIG_IDF_TARGET="esp32p4"
CONFIG_SPIRAM=y
CONFIG_ESP_INT_WDT_TIMEOUT_MS=800
CONFIG_FREERTOS_TASK_CREATE_ALLOW_EXT_MEM=y
CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=0
CONFIG_IDF_EXPERIMENTAL_FEATURES=y
CONFIG_SPIRAM_SPEED_200M=y
@@ -1,21 +0,0 @@
CONFIG_IDF_TARGET="esp32p4"
CONFIG_SPIRAM=y
CONFIG_ESP_INT_WDT_TIMEOUT_MS=800
CONFIG_FREERTOS_TASK_CREATE_ALLOW_EXT_MEM=y
CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=0
CONFIG_IDF_EXPERIMENTAL_FEATURES=y
CONFIG_SPIRAM_SPEED_200M=y
# Default settings for testing this example in CI.
# This configuration is not secure, don't use it in production!
# See Flash Encryption API Guide for more details.
CONFIG_SECURE_FLASH_ENC_ENABLED=y
CONFIG_SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT=y
CONFIG_SECURE_BOOT_ALLOW_ROM_BASIC=y
CONFIG_SECURE_BOOT_ALLOW_JTAG=y
CONFIG_SECURE_FLASH_UART_BOOTLOADER_ALLOW_ENC=y
CONFIG_SECURE_FLASH_UART_BOOTLOADER_ALLOW_DEC=y
CONFIG_SECURE_FLASH_UART_BOOTLOADER_ALLOW_CACHE=y
CONFIG_SECURE_FLASH_REQUIRE_ALREADY_ENABLED=y
@@ -1,6 +0,0 @@
CONFIG_IDF_TARGET="esp32p4"
CONFIG_SPIRAM=y
CONFIG_ESP_INT_WDT_TIMEOUT_MS=800
CONFIG_IDF_EXPERIMENTAL_FEATURES=y
CONFIG_SPIRAM_SPEED_200M=y