mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 11:10:54 +03:00
fix(nvs_flash): Use h/w accelerated AES-ECB for XTS-AES operations
This commit is contained in:
@@ -7,4 +7,6 @@ idf_component_register(SRC_DIRS "."
|
||||
|
||||
if(CONFIG_NVS_ENCRYPTION OR CONFIG_SOC_HMAC_SUPPORTED)
|
||||
target_link_libraries(${COMPONENT_LIB} PUBLIC idf::mbedtls)
|
||||
# Add private_include directory from nvs_flash for accessing internal headers like nvs_xts_aes.h in the test app
|
||||
target_include_directories(${COMPONENT_LIB} PRIVATE "${CMAKE_CURRENT_LIST_DIR}/../../private_include")
|
||||
endif()
|
||||
|
||||
@@ -456,6 +456,7 @@ TEST_CASE("check for memory leaks in nvs_set_blob", "[nvs]")
|
||||
}
|
||||
|
||||
#ifdef CONFIG_NVS_ENCRYPTION
|
||||
#include "nvs_xts_aes.h"
|
||||
TEST_CASE("check underlying xts code for 32-byte size sector encryption", "[nvs]")
|
||||
{
|
||||
uint8_t eky_hex[2 * NVS_KEY_SIZE] = { /* Encryption key below*/
|
||||
@@ -484,16 +485,16 @@ TEST_CASE("check underlying xts code for 32-byte size sector encryption", "[nvs]
|
||||
0xab,0xf9,0x8e,0x22,0xdf,0x5b,0xdd,0x15,
|
||||
0xaf,0x47,0x1f,0x3d,0xb8,0x94,0x6a,0x85 };
|
||||
|
||||
mbedtls_aes_xts_context ectx[1];
|
||||
mbedtls_aes_xts_context dctx[1];
|
||||
XTS_CONTEXT ectx[1];
|
||||
XTS_CONTEXT dctx[1];
|
||||
|
||||
mbedtls_aes_xts_init(ectx);
|
||||
mbedtls_aes_xts_init(dctx);
|
||||
XTS_FUNC(xts_init)(ectx);
|
||||
XTS_FUNC(xts_init)(dctx);
|
||||
|
||||
TEST_ASSERT_TRUE(!mbedtls_aes_xts_setkey_enc(ectx, eky_hex, 2 * NVS_KEY_SIZE * 8));
|
||||
TEST_ASSERT_TRUE(!mbedtls_aes_xts_setkey_enc(dctx, eky_hex, 2 * NVS_KEY_SIZE * 8));
|
||||
TEST_ASSERT_TRUE(!XTS_FUNC(xts_setkey_enc)(ectx, eky_hex, 2 * NVS_KEY_SIZE * 8));
|
||||
TEST_ASSERT_TRUE(!XTS_FUNC(xts_setkey_enc)(dctx, eky_hex, 2 * NVS_KEY_SIZE * 8));
|
||||
|
||||
TEST_ASSERT_TRUE(!mbedtls_aes_crypt_xts(ectx, MBEDTLS_AES_ENCRYPT, 32, ba_hex, ptxt_hex, ptxt_hex));
|
||||
TEST_ASSERT_TRUE(!XTS_FUNC(crypt_xts)(ectx, XTS_MODE(ENCRYPT), 32, ba_hex, ptxt_hex, ptxt_hex));
|
||||
|
||||
TEST_ASSERT_TRUE(!memcmp(ptxt_hex, ctxt_hex, 32));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user