arch/xtensa/esp32: Remove the AES test from the driver.

Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
This commit is contained in:
Abdelatif Guettouche 2021-10-15 12:56:32 +02:00 committed by Gustavo Henrique Nihei
parent b99852872c
commit 8288a04a0b
3 changed files with 1 additions and 504 deletions

View File

@ -1364,15 +1364,6 @@ endmenu # Partition Configuration
endif
menu "AES accelerate"
depends on ESP32_AES_ACCELERATOR
config ESP32_AES_ACCELERATOR_TEST
bool "AES driver test"
default n
endmenu # ESP32_AES_ACCELERATOR
config ESP32_AUTO_SLEEP
bool "Auto-sleep"
default n

View File

@ -643,496 +643,3 @@ int aes_cypher(void *out, const void *in, uint32_t size,
#endif
/****************************************************************************
* Test Functions
****************************************************************************/
#ifdef CONFIG_ESP32_AES_ACCELERATOR_TEST
/****************************************************************************
* Name: esp32_aes_ecb_test
****************************************************************************/
static bool esp32_aes_ecb_test(void)
{
int ret;
int i;
int keybits;
uint8_t encrypt_buf[16];
uint8_t decrypt_buf[16];
struct esp32_aes_s aes;
const int size = 16;
const uint32_t input[8] =
{
0x740fdb34, 0x002defca, 0xb042437b, 0xc2f42cf9,
0xc64444be, 0x32365bc1, 0xb613cfa2, 0x15ce0d23
};
const uint32_t key[16] =
{
0x8ffdc2c5, 0x14d6c69d, 0x9cb7608f, 0x899b2472,
0xbf9e4372, 0x855290d0, 0xc62753da, 0xdeedeab7
};
const uint32_t result[3][4] =
{
/* keybits = 128 */
{
0xc810df2a, 0x8ae67e6e, 0x50c5e32c, 0xd535f3e4
},
/* keybits = 192 */
{
0x00d2f88e, 0x4e859ec6, 0x394e0af7, 0x965326d8
},
/* keybits = 256 */
{
0xa0714c2b, 0x356adb1f, 0xe905c243, 0x35195a7c
}
};
esp32_aes_init();
for (i = 0; i < 3; i++)
{
keybits = i * 64 + 128;
ret = esp32_aes_setkey(&aes, key, keybits);
if (ret < 0)
{
return false;
}
ret = esp32_aes_ecb_cypher(&aes, 1, input, encrypt_buf, size);
if (ret < 0)
{
return false;
}
ret = memcmp(encrypt_buf, result[i], size);
if (ret)
{
return false;
}
ret = esp32_aes_ecb_cypher(&aes, 0, encrypt_buf, decrypt_buf, size);
if (ret < 0)
{
return false;
}
ret = memcmp(decrypt_buf, input, size);
if (ret)
{
return false;
}
syslog(LOG_INFO, "ESP32 AES ECB key=%d bits test: PASS\n", keybits);
}
return true;
}
/****************************************************************************
* Name: esp32_aes_cbc_test
****************************************************************************/
static bool esp32_aes_cbc_test(void)
{
int ret;
int i;
int keybits;
uint8_t encrypt_buf[32];
uint8_t decrypt_buf[32];
uint8_t iv_buf[16];
struct esp32_aes_s aes;
const int size = 32;
const uint32_t input[8] =
{
0x740fdb34, 0x002defca, 0xb042437b, 0xc2f42cf9,
0xc64444be, 0x32365bc1, 0xb613cfa2, 0x15ce0d23
};
const uint32_t key[16] =
{
0x8ffdc2c5, 0x14d6c69d, 0x9cb7608f, 0x899b2472,
0xbf9e4372, 0x855290d0, 0xc62753da, 0xdeedeab7
};
const uint32_t iv[4] =
{
0xf53a50f2, 0x8aaf711d, 0x953bbbfa, 0x228d53cb
};
const uint32_t result[3][8] =
{
/* keybits = 128 */
{
0x04e27d12, 0x1a91e508, 0x01092431, 0x9d572184,
0xa39979e1, 0x5543e1bc, 0x7173b71d, 0x4e3be064
},
/* keybits = 192 */
{
0x9b894bd8, 0x7dc31ec6, 0xde40c3d5, 0xc2ed0679,
0xa8a857fc, 0x815db8ca, 0x33f18ab8, 0x752c1b8e
},
/* keybits = 256 */
{
0x6f36b8fe, 0x33bc1f37, 0x24fe659c, 0x0370def0,
0xb9a852f8, 0x64a79ae2, 0xd59f5045, 0x648a0f44
}
};
for (i = 0; i < 3; i++)
{
keybits = i * 64 + 128;
ret = esp32_aes_setkey(&aes, key, keybits);
if (ret < 0)
{
return false;
}
memcpy(iv_buf, iv, 16);
ret = esp32_aes_cbc_cypher(&aes, 1, iv_buf, input, encrypt_buf, size);
if (ret < 0)
{
return false;
}
ret = memcmp(encrypt_buf, result[i], size);
if (ret)
{
return false;
}
memcpy(iv_buf, iv, 16);
ret = esp32_aes_cbc_cypher(&aes, 0, iv_buf, encrypt_buf,
decrypt_buf, size);
if (ret < 0)
{
return false;
}
ret = memcmp(decrypt_buf, input, size);
if (ret)
{
return false;
}
syslog(LOG_INFO, "ESP32 AES CBC key=%d bits test: PASS\n", keybits);
}
return true;
}
/****************************************************************************
* Name: esp32_aes_ctr_test
****************************************************************************/
static bool esp32_aes_ctr_test(void)
{
int ret;
int i;
int keybits;
uint8_t encrypt_buf[32];
uint8_t decrypt_buf[32];
uint8_t cnt_buf[16];
uint8_t cache_buf[16];
uint32_t nc_off;
struct esp32_aes_s aes;
const int size = 32;
const uint32_t input[8] =
{
0x740fdb34, 0x002defca, 0xb042437b, 0xc2f42cf9,
0xc64444be, 0x32365bc1, 0xb613cfa2, 0x15ce0d23
};
const uint32_t key[16] =
{
0x8ffdc2c5, 0x14d6c69d, 0x9cb7608f, 0x899b2472,
0xbf9e4372, 0x855290d0, 0xc62753da, 0xdeedeab7
};
const uint32_t cnt[4] =
{
0xf53a50f2, 0x8aaf711d, 0x953bbbfa, 0x228d53cb
};
const uint32_t result[3][8] =
{
/* keybits = 128 */
{
0x5f922338, 0x5aff403d, 0x45fede3f, 0x616568c6,
0x3cd0ffc7, 0xa26cb704, 0x0aaa8b6a, 0x1d0b5e1c
},
/* keybits = 192 */
{
0xe1052003, 0x429823e2, 0x547e3f33, 0xbe55c832,
0x037f9f57, 0x1b3f025f, 0xc4c9a836, 0x164e2730
},
/* keybits = 256 */
{
0x70af4473, 0x597d2126, 0xd598ed09, 0x3fea540c,
0xfb5c743c, 0x0c1a39ca, 0xcbcf2d17, 0x341a7a0c
}
};
for (i = 0; i < 3; i++)
{
keybits = i * 64 + 128;
ret = esp32_aes_setkey(&aes, key, keybits);
if (ret < 0)
{
return false;
}
nc_off = 0;
memcpy(cnt_buf, cnt, 16);
ret = esp32_aes_ctr_cypher(&aes, &nc_off, cnt_buf, cache_buf,
input, encrypt_buf, size);
if (ret < 0)
{
return false;
}
ret = memcmp(encrypt_buf, result[i], size);
if (ret)
{
return false;
}
nc_off = 0;
memcpy(cnt_buf, cnt, 16);
ret = esp32_aes_ctr_cypher(&aes, &nc_off, cnt_buf, cache_buf,
encrypt_buf, decrypt_buf, size);
if (ret < 0)
{
return false;
}
ret = memcmp(decrypt_buf, input, size);
if (ret)
{
return false;
}
syslog(LOG_INFO, "ESP32 AES CTR key=%d bits test: PASS\n", keybits);
}
return true;
}
/****************************************************************************
* Name: esp32_aes_xts_test
****************************************************************************/
static bool esp32_aes_xts_test(void)
{
int ret;
int i;
int keybits;
uint8_t encrypt_buf[32];
uint8_t decrypt_buf[32];
uint8_t unit_buf[16];
struct esp32_aes_xts_s aes;
int size;
const uint32_t input[8] =
{
0x740fdb34, 0x002defca, 0xb042437b, 0xc2f42cf9,
0xc64444be, 0x32365bc1, 0xb613cfa2, 0x15ce0d23
};
const uint32_t key[16] =
{
0x8ffdc2c5, 0x14d6c69d, 0x9cb7608f, 0x899b2472,
0xbf9e4372, 0x855290d0, 0xc62753da, 0xdeedeab7,
0x7ac6c53b, 0xc94f0b81, 0xdd673fc9, 0x8c1b71a6,
0x1f99b728, 0x5e7af2eb, 0xcc7274a3, 0xf0005b23
};
const uint32_t unit[4] =
{
0xf53a50f2, 0x8aaf711d, 0x953bbbfa, 0x228d53cb
};
const uint32_t result_in32[2][8] =
{
/* keybits = 256 */
{
0xf70e05fd, 0x2791be41, 0x926ec006, 0xc76068f4,
0x01fd0843, 0xdf5e576a, 0xa4b1833d, 0x90502608
},
/* keybits = 512 */
{
0x164b4185, 0x4cb1cce7, 0xf285e523, 0x06a5923a,
0xae4fcb7b, 0x59ce9dc6, 0xed64546f, 0x5889cb17
}
};
const uint32_t result_in30[2][8] =
{
/* keybits = 256 */
{
0x26991fb6, 0x72e4a7bc, 0x97041d61, 0x9ec889af,
0xf70e05fd, 0x2791be41, 0x926ec006, 0x000068f4
},
/* keybits = 512 */
{
0x4b42dd86, 0xeee792c0, 0x1516ff95, 0x1f5fd9e6,
0x164b4185, 0x4cb1cce7, 0xf285e523, 0x0000923a
}
};
for (i = 0; i < 2; i++)
{
keybits = i * 256 + 256;
ret = esp32_aes_xts_setkey(&aes, key, keybits);
if (ret < 0)
{
return false;
}
/* Encrypt/Decrypt 32 bytes */
size = 32;
memcpy(unit_buf, unit, 16);
ret = esp32_aes_xts_cypher(&aes, true, unit_buf, input,
encrypt_buf, size);
if (ret < 0)
{
return false;
}
ret = memcmp(encrypt_buf, result_in32[i], size);
if (ret)
{
return false;
}
memcpy(unit_buf, unit, 16);
ret = esp32_aes_xts_cypher(&aes, false, unit_buf, encrypt_buf,
decrypt_buf, size);
if (ret < 0)
{
return false;
}
ret = memcmp(decrypt_buf, input, size);
if (ret)
{
return false;
}
/* Encrypt/Decrypt 30 bytes */
size = 30;
memcpy(unit_buf, unit, 16);
ret = esp32_aes_xts_cypher(&aes, true, unit_buf, input,
encrypt_buf, size);
if (ret < 0)
{
return false;
}
ret = memcmp(encrypt_buf, result_in30[i], size);
if (ret)
{
return false;
}
memcpy(unit_buf, unit, 16);
ret = esp32_aes_xts_cypher(&aes, false, unit_buf, encrypt_buf,
decrypt_buf, size);
if (ret < 0)
{
return false;
}
ret = memcmp(decrypt_buf, input, size);
if (ret)
{
DEBUGASSERT(0);
}
syslog(LOG_INFO, "ESP32 AES XTS key=%d bits test: PASS\n", keybits);
}
return true;
}
/****************************************************************************
* Name: esp32_aes_main
****************************************************************************/
int esp32_aes_main(int argc, char *argv[])
{
bool success;
syslog(LOG_INFO, "----- BEGIN TEST -----\n");
esp32_aes_init();
success = esp32_aes_ecb_test();
if (!success)
{
goto test_end;
}
success = esp32_aes_cbc_test();
if (!success)
{
goto test_end;
}
success = esp32_aes_ctr_test();
if (!success)
{
goto test_end;
}
success = esp32_aes_xts_test();
if (!success)
{
goto test_end;
}
test_end:
syslog(LOG_INFO, "----- END TEST -----\n");
syslog(LOG_INFO, "\n");
syslog(LOG_INFO, "----- RESULT: %s -----\n",
success ? "SUCCESS" : "FAILED");
return 0;
}
#endif

View File

@ -28,7 +28,6 @@ CONFIG_CRYPTO_SW_AES=y
CONFIG_DEBUG_ASSERTIONS=y
CONFIG_DEBUG_FEATURES=y
CONFIG_ESP32_AES_ACCELERATOR=y
CONFIG_ESP32_AES_ACCELERATOR_TEST=y
CONFIG_ESP32_UART0=y
CONFIG_FS_PROCFS=y
CONFIG_HAVE_CXX=y
@ -53,4 +52,4 @@ CONFIG_START_MONTH=12
CONFIG_START_YEAR=2011
CONFIG_SYSTEM_NSH=y
CONFIG_UART0_SERIAL_CONSOLE=y
CONFIG_USER_ENTRYPOINT="esp32_aes_main"
CONFIG_USER_ENTRYPOINT="nsh_main"