Explorar o código

mbedtls tests: Add optional debug log output to AES stream tests

Angus Gratton %!s(int64=5) %!d(string=hai) anos
pai
achega
89b6baf2b8
Modificáronse 1 ficheiros con 9 adicións e 1 borrados
  1. 9 1
      components/mbedtls/test/test_aes.c

+ 9 - 1
components/mbedtls/test/test_aes.c

@@ -8,6 +8,7 @@
 #include "mbedtls/gcm.h"
 #include "unity.h"
 #include "sdkconfig.h"
+#include "esp_log.h"
 #include "esp_timer.h"
 #include "esp_heap_caps.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
         */
     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(chipertext, 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,
                                   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);
 
         // Decrypt
         memset(nonce, 0xEE, 16);
+        memset(decryptedtext, 0x22, SZ);
         offset = 0;
         for (int idx = 0; idx < SZ; idx = idx + bytes_to_process) {
             // 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,
                                   stream_block, chipertext + idx, decryptedtext + idx );
         }
+        ESP_LOG_BUFFER_HEXDUMP("decrypted", decryptedtext, SZ, ESP_LOG_DEBUG);
         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++) {
+        ESP_LOGD("test", "bytes_to_process %d", bytes_to_process);
         // Encrypt
         memset(iv, 0xEE, 16);
         size_t offset = 0;
@@ -464,6 +471,7 @@ TEST_CASE("mbedtls OFB stream test", "[aes]")
 
         // Decrypt
         memset(iv, 0xEE, 16);
+        memset(decryptedtext, 0x22, SZ);
         offset = 0;
         for (int idx = 0; idx < SZ; idx = idx + bytes_to_process) {
             // Limit length of last call to avoid exceeding buffer size