mirror of
https://github.com/espressif/esp-idf.git
synced 2025-07-31 19:24:33 +02:00
mbedtls tests: Add optional debug log output to AES stream tests
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
#include "mbedtls/gcm.h"
|
#include "mbedtls/gcm.h"
|
||||||
#include "unity.h"
|
#include "unity.h"
|
||||||
#include "sdkconfig.h"
|
#include "sdkconfig.h"
|
||||||
|
#include "esp_log.h"
|
||||||
#include "esp_timer.h"
|
#include "esp_timer.h"
|
||||||
#include "esp_heap_caps.h"
|
#include "esp_heap_caps.h"
|
||||||
#include "test_utils.h"
|
#include "test_utils.h"
|
||||||
@@ -356,7 +357,7 @@ TEST_CASE("mbedtls CTR stream test", "[aes]")
|
|||||||
no matter how many bytes we encrypt each call
|
no matter how many bytes we encrypt each call
|
||||||
*/
|
*/
|
||||||
for (int bytes_to_process = 1; bytes_to_process < SZ; bytes_to_process++) {
|
for (int bytes_to_process = 1; bytes_to_process < SZ; bytes_to_process++) {
|
||||||
|
ESP_LOGD("test", "bytes_to_process %d", bytes_to_process);
|
||||||
memset(nonce, 0xEE, 16);
|
memset(nonce, 0xEE, 16);
|
||||||
memset(chipertext, 0x0, SZ);
|
memset(chipertext, 0x0, SZ);
|
||||||
memset(decryptedtext, 0x0, SZ);
|
memset(decryptedtext, 0x0, SZ);
|
||||||
@@ -370,10 +371,14 @@ TEST_CASE("mbedtls CTR stream test", "[aes]")
|
|||||||
mbedtls_aes_crypt_ctr(&ctx, length, &offset, nonce,
|
mbedtls_aes_crypt_ctr(&ctx, length, &offset, nonce,
|
||||||
stream_block, plaintext + idx, chipertext + idx );
|
stream_block, plaintext + idx, chipertext + idx );
|
||||||
}
|
}
|
||||||
|
ESP_LOG_BUFFER_HEXDUMP("expected", expected_cipher, SZ, ESP_LOG_DEBUG);
|
||||||
|
ESP_LOG_BUFFER_HEXDUMP("actual ", chipertext, SZ, ESP_LOG_DEBUG);
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_HEX8_ARRAY(expected_cipher, chipertext, SZ);
|
TEST_ASSERT_EQUAL_HEX8_ARRAY(expected_cipher, chipertext, SZ);
|
||||||
|
|
||||||
// Decrypt
|
// Decrypt
|
||||||
memset(nonce, 0xEE, 16);
|
memset(nonce, 0xEE, 16);
|
||||||
|
memset(decryptedtext, 0x22, SZ);
|
||||||
offset = 0;
|
offset = 0;
|
||||||
for (int idx = 0; idx < SZ; idx = idx + bytes_to_process) {
|
for (int idx = 0; idx < SZ; idx = idx + bytes_to_process) {
|
||||||
// Limit length of last call to avoid exceeding buffer size
|
// Limit length of last call to avoid exceeding buffer size
|
||||||
@@ -381,6 +386,7 @@ TEST_CASE("mbedtls CTR stream test", "[aes]")
|
|||||||
mbedtls_aes_crypt_ctr(&ctx, length, &offset, nonce,
|
mbedtls_aes_crypt_ctr(&ctx, length, &offset, nonce,
|
||||||
stream_block, chipertext + idx, decryptedtext + idx );
|
stream_block, chipertext + idx, decryptedtext + idx );
|
||||||
}
|
}
|
||||||
|
ESP_LOG_BUFFER_HEXDUMP("decrypted", decryptedtext, SZ, ESP_LOG_DEBUG);
|
||||||
TEST_ASSERT_EQUAL_HEX8_ARRAY(plaintext, decryptedtext, SZ);
|
TEST_ASSERT_EQUAL_HEX8_ARRAY(plaintext, decryptedtext, SZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -451,6 +457,7 @@ TEST_CASE("mbedtls OFB stream test", "[aes]")
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
for (int bytes_to_process = 1; bytes_to_process < SZ; bytes_to_process++) {
|
for (int bytes_to_process = 1; bytes_to_process < SZ; bytes_to_process++) {
|
||||||
|
ESP_LOGD("test", "bytes_to_process %d", bytes_to_process);
|
||||||
// Encrypt
|
// Encrypt
|
||||||
memset(iv, 0xEE, 16);
|
memset(iv, 0xEE, 16);
|
||||||
size_t offset = 0;
|
size_t offset = 0;
|
||||||
@@ -464,6 +471,7 @@ TEST_CASE("mbedtls OFB stream test", "[aes]")
|
|||||||
|
|
||||||
// Decrypt
|
// Decrypt
|
||||||
memset(iv, 0xEE, 16);
|
memset(iv, 0xEE, 16);
|
||||||
|
memset(decryptedtext, 0x22, SZ);
|
||||||
offset = 0;
|
offset = 0;
|
||||||
for (int idx = 0; idx < SZ; idx = idx + bytes_to_process) {
|
for (int idx = 0; idx < SZ; idx = idx + bytes_to_process) {
|
||||||
// Limit length of last call to avoid exceeding buffer size
|
// Limit length of last call to avoid exceeding buffer size
|
||||||
|
Reference in New Issue
Block a user