| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588 |
- /*
- * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
- *
- * SPDX-License-Identifier: Unlicense OR CC0-1.0
- */
- /* mbedTLS AES test
- */
- #include <string.h>
- #include <stdio.h>
- #include <stdbool.h>
- #include <esp_system.h>
- #include "mbedtls/aes.h"
- #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"
- #include "freertos/FreeRTOS.h"
- #include "freertos/task.h"
- #include "freertos/semphr.h"
- #include "esp_memory_utils.h"
- #include "soc/lldesc.h"
- static const uint8_t key_256[] = {
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
- 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
- 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
- };
- static const uint8_t iv[] = {
- 0x10, 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09,
- 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01,
- };
- /* Cipher produced via this Python:
- from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
- from cryptography.hazmat.backends import default_backend
- def as_c_array(byte_arr):
- hex_str = ''
- for idx, byte in enumerate(byte_arr):
- hex_str += "0x{:02x}, ".format(byte)
- bytes_per_line = 8
- if idx % bytes_per_line == bytes_per_line - 1:
- hex_str += '\n'
- return hex_str
- key = bytearray(range(32))
- iv = bytearray(range(16, 0, -1))
- print("Key: \n{}".format(as_c_array(key)))
- print("IV: \n{}".format(as_c_array(iv)))
- # Replace CTR with desired mode
- cipher = Cipher(algorithms.AES(key), modes.CTR(iv), backend=default_backend())
- encryptor = cipher.encryptor()
- input_len = 1000
- plain = b'\x3A'*input_len
- print(as_c_array(plain))
- ct = encryptor.update(plain) + encryptor.finalize()
- print("Chipertext: {}".format(as_c_array(ct)))
- */
- TEST_CASE("mbedtls CBC AES-256 test", "[aes]")
- {
- const unsigned SZ = 1600;
- mbedtls_aes_context ctx;
- uint8_t nonce[16];
- const uint8_t expected_cipher_end[] = {
- 0x3e, 0x68, 0x8a, 0x02, 0xe6, 0xf2, 0x6a, 0x9e,
- 0x9b, 0xb2, 0xc0, 0xc4, 0x63, 0x63, 0xd9, 0x25,
- 0x51, 0xdc, 0xc2, 0x71, 0x96, 0xb3, 0xe5, 0xcd,
- 0xbd, 0x0e, 0xf2, 0xef, 0xa9, 0xab, 0xab, 0x2d,
- };
- memcpy(nonce, iv, 16);
- // allocate internal memory
- uint8_t *chipertext = 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);
- TEST_ASSERT_NOT_NULL(chipertext);
- TEST_ASSERT_NOT_NULL(plaintext);
- TEST_ASSERT_NOT_NULL(decryptedtext);
- mbedtls_aes_init(&ctx);
- mbedtls_aes_setkey_enc(&ctx, key_256, 256);
- memset(plaintext, 0x3A, SZ);
- memset(decryptedtext, 0x0, SZ);
- // Encrypt
- mbedtls_aes_crypt_cbc(&ctx, MBEDTLS_AES_ENCRYPT, SZ, nonce, plaintext, chipertext);
- TEST_ASSERT_EQUAL_HEX8_ARRAY(expected_cipher_end, chipertext + SZ - 32, 32);
- // Decrypt
- memcpy(nonce, iv, 16);
- mbedtls_aes_setkey_dec(&ctx, key_256, 256);
- mbedtls_aes_crypt_cbc(&ctx, MBEDTLS_AES_DECRYPT, SZ, nonce, chipertext, decryptedtext);
- TEST_ASSERT_EQUAL_HEX8_ARRAY(plaintext, decryptedtext, SZ);
- mbedtls_aes_free(&ctx);
- free(plaintext);
- free(chipertext);
- free(decryptedtext);
- }
- TEST_CASE("mbedtls CBC AES-256 DMA buffer align test", "[aes]")
- {
- #define ALIGN_DOWN(val, align) ((val) & ~((align) - 1))
- // Size is taken considering the maximum DMA buffer size
- const unsigned SZ = ALIGN_DOWN((2*LLDESC_MAX_NUM_PER_DESC), 16);
- mbedtls_aes_context ctx;
- uint8_t nonce[16];
- const uint8_t expected_cipher_end[] = {
- 0x9e, 0xcb, 0x1d, 0x24, 0x01, 0xc8, 0x3f, 0xba,
- 0xde, 0x76, 0xea, 0x9c, 0xf3, 0x64, 0x23, 0x19,
- 0x8c, 0x67, 0xd4, 0x1a, 0xd1, 0xe0, 0xbf, 0xc3,
- 0xd2, 0xb8, 0x40, 0x95, 0x89, 0x41, 0x09, 0xdb,
- };
- memcpy(nonce, iv, 16);
- // allocate internal memory
- uint8_t *chipertext = 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);
- TEST_ASSERT_NOT_NULL(chipertext);
- TEST_ASSERT_NOT_NULL(plaintext);
- TEST_ASSERT_NOT_NULL(decryptedtext);
- mbedtls_aes_init(&ctx);
- mbedtls_aes_setkey_enc(&ctx, key_256, 256);
- memset(plaintext, 0x3A, SZ);
- memset(decryptedtext, 0x0, SZ);
- // Encrypt
- mbedtls_aes_crypt_cbc(&ctx, MBEDTLS_AES_ENCRYPT, SZ, nonce, plaintext, chipertext);
- TEST_ASSERT_EQUAL_HEX8_ARRAY(expected_cipher_end, chipertext + SZ - 32, 32);
- // Decrypt
- memcpy(nonce, iv, 16);
- mbedtls_aes_setkey_dec(&ctx, key_256, 256);
- mbedtls_aes_crypt_cbc(&ctx, MBEDTLS_AES_DECRYPT, SZ, nonce, chipertext, decryptedtext);
- TEST_ASSERT_EQUAL_HEX8_ARRAY(plaintext, decryptedtext, SZ);
- mbedtls_aes_free(&ctx);
- free(plaintext);
- free(chipertext);
- free(decryptedtext);
- }
- TEST_CASE("mbedtls CTR AES-256 test", "[aes]")
- {
- const unsigned SZ = 1000;
- mbedtls_aes_context ctx;
- uint8_t nonce[16];
- uint8_t stream_block[16];
- size_t nc_off = 0;
- const uint8_t expected_cipher_end[] = {
- 0xd4, 0xdc, 0x4f, 0x8f, 0xfe, 0x86, 0xee, 0xb5,
- 0x14, 0x7f, 0xba, 0x30, 0x25, 0xa6, 0x7f, 0x6c,
- 0xb5, 0x73, 0xaf, 0x90, 0xd7, 0xff, 0x36, 0xba,
- 0x2b, 0x1d, 0xec, 0xb9, 0x38, 0xfa, 0x0d, 0xeb,
- };
- memcpy(nonce, iv, 16);
- // allocate internal memory
- uint8_t *chipertext = 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);
- TEST_ASSERT_NOT_NULL(chipertext);
- TEST_ASSERT_NOT_NULL(plaintext);
- TEST_ASSERT_NOT_NULL(decryptedtext);
- mbedtls_aes_init(&ctx);
- mbedtls_aes_setkey_enc(&ctx, key_256, 256);
- memset(plaintext, 0x3A, SZ);
- memset(decryptedtext, 0x0, SZ);
- // Encrypt
- mbedtls_aes_crypt_ctr(&ctx, SZ, &nc_off, nonce, stream_block, plaintext, chipertext);
- TEST_ASSERT_EQUAL_HEX8_ARRAY(expected_cipher_end, chipertext + SZ - 32, 32);
- // Decrypt
- nc_off = 0;
- memcpy(nonce, iv, 16);
- mbedtls_aes_crypt_ctr(&ctx, SZ, &nc_off, nonce, stream_block, chipertext, decryptedtext);
- TEST_ASSERT_EQUAL_HEX8_ARRAY(plaintext, decryptedtext, SZ);
- mbedtls_aes_free(&ctx);
- free(plaintext);
- free(chipertext);
- free(decryptedtext);
- }
- TEST_CASE("mbedtls OFB AES-256 test", "[aes]")
- {
- const unsigned SZ = 1000;
- mbedtls_aes_context ctx;
- uint8_t nonce[16];
- size_t nc_off = 0;
- const uint8_t expected_cipher_end[] = {
- 0xca, 0xc3, 0x05, 0x77, 0xae, 0xb9, 0x38, 0xd6,
- 0x03, 0x0a, 0xad, 0x90, 0x6e, 0xdd, 0xf3, 0x9a,
- 0x41, 0x4d, 0x71, 0x30, 0x04, 0x9f, 0xd3, 0x53,
- 0xb7, 0x5e, 0xb4, 0xfd, 0x93, 0xf8, 0x31, 0x6a,
- };
- memcpy(nonce, iv, 16);
- // allocate internal memory
- uint8_t *chipertext = 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);
- TEST_ASSERT_NOT_NULL(chipertext);
- TEST_ASSERT_NOT_NULL(plaintext);
- TEST_ASSERT_NOT_NULL(decryptedtext);
- mbedtls_aes_init(&ctx);
- mbedtls_aes_setkey_enc(&ctx, key_256, 256);
- memset(plaintext, 0x3A, SZ);
- memset(decryptedtext, 0x0, SZ);
- // Encrypt
- mbedtls_aes_crypt_ofb(&ctx, SZ, &nc_off, nonce, plaintext, chipertext);
- TEST_ASSERT_EQUAL_HEX8_ARRAY(expected_cipher_end, chipertext + SZ - 32, 32);
- // Decrypt
- nc_off = 0;
- memcpy(nonce, iv, 16);
- mbedtls_aes_crypt_ofb(&ctx, SZ, &nc_off, nonce, chipertext, decryptedtext);
- TEST_ASSERT_EQUAL_HEX8_ARRAY(plaintext, decryptedtext, SZ);
- mbedtls_aes_free(&ctx);
- free(plaintext);
- free(chipertext);
- free(decryptedtext);
- }
- TEST_CASE("mbedtls CFB-8 AES-256 test", "[aes]")
- {
- const unsigned SZ = 1000;
- mbedtls_aes_context ctx;
- uint8_t nonce[16];
- const uint8_t expected_cipher_end[] = {
- 0x69, 0xdc, 0x1d, 0x8a, 0x0b, 0x9e, 0xbc, 0x84,
- 0x29, 0xa2, 0x04, 0xb6, 0x91, 0x6b, 0xb2, 0x83,
- 0x13, 0x23, 0x54, 0xcb, 0xf9, 0x6d, 0xcc, 0x53,
- 0x04, 0x59, 0xd1, 0xc9, 0xff, 0xab, 0xe2, 0x37,
- };
- memcpy(nonce, iv, 16);
- // allocate internal memory
- uint8_t *chipertext = 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);
- TEST_ASSERT_NOT_NULL(chipertext);
- TEST_ASSERT_NOT_NULL(plaintext);
- TEST_ASSERT_NOT_NULL(decryptedtext);
- mbedtls_aes_init(&ctx);
- mbedtls_aes_setkey_enc(&ctx, key_256, 256);
- memset(plaintext, 0x3A, SZ);
- memset(decryptedtext, 0x0, SZ);
- // Encrypt
- mbedtls_aes_crypt_cfb8(&ctx, MBEDTLS_AES_ENCRYPT, SZ, nonce, plaintext, chipertext);
- TEST_ASSERT_EQUAL_HEX8_ARRAY(expected_cipher_end, chipertext + SZ - 32, 32);
- // Decrypt
- memcpy(nonce, iv, 16);
- mbedtls_aes_crypt_cfb8(&ctx, MBEDTLS_AES_DECRYPT, SZ, nonce, chipertext, decryptedtext);
- TEST_ASSERT_EQUAL_HEX8_ARRAY(plaintext, decryptedtext, SZ);
- mbedtls_aes_free(&ctx);
- free(plaintext);
- free(chipertext);
- free(decryptedtext);
- }
- TEST_CASE("mbedtls CFB-128 AES-256 test", "[aes]")
- {
- const unsigned SZ = 1000;
- mbedtls_aes_context ctx;
- uint8_t nonce[16];
- size_t nc_off = 0;
- const uint8_t expected_cipher_end[] = {
- 0xf3, 0x64, 0x20, 0xa1, 0x70, 0x2a, 0xd9, 0x3f,
- 0xb7, 0x48, 0x8c, 0x2c, 0x1f, 0x65, 0x53, 0xc2,
- 0xac, 0xfd, 0x82, 0xe5, 0x31, 0x24, 0x1f, 0x30,
- 0xaf, 0xcc, 0x8d, 0xb3, 0xf3, 0x63, 0xe1, 0xa0,
- };
- memcpy(nonce, iv, 16);
- // allocate internal memory
- uint8_t *chipertext = 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);
- TEST_ASSERT_NOT_NULL(chipertext);
- TEST_ASSERT_NOT_NULL(plaintext);
- TEST_ASSERT_NOT_NULL(decryptedtext);
- mbedtls_aes_init(&ctx);
- mbedtls_aes_setkey_enc(&ctx, key_256, 256);
- memset(plaintext, 0x3A, SZ);
- memset(decryptedtext, 0x0, SZ);
- // Encrypt
- mbedtls_aes_crypt_cfb128(&ctx, MBEDTLS_AES_ENCRYPT, SZ, &nc_off, nonce, plaintext, chipertext);
- TEST_ASSERT_EQUAL_HEX8_ARRAY(expected_cipher_end, chipertext + SZ - 32, 32);
- // Decrypt
- nc_off = 0;
- memcpy(nonce, iv, 16);
- mbedtls_aes_crypt_cfb128(&ctx, MBEDTLS_AES_DECRYPT, SZ, &nc_off, nonce, chipertext, decryptedtext);
- TEST_ASSERT_EQUAL_HEX8_ARRAY(plaintext, decryptedtext, SZ);
- mbedtls_aes_free(&ctx);
- free(plaintext);
- free(chipertext);
- free(decryptedtext);
- }
- static void aes_ctr_stream_test(void)
- {
- const unsigned SZ = 100;
- mbedtls_aes_context ctx;
- uint8_t nonce[16];
- uint8_t key[16];
- uint8_t stream_block[16];
- /* Cipher produced via this Python:
- import os, binascii
- from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
- from cryptography.hazmat.backends import default_backend
- key = b'\x44' * 16
- 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_arr = ""
- for idx, b in enumerate(ct):
- if idx % 8 == 0:
- ct_arr += '\n'
- ct_arr += "0x{}, ".format(binascii.hexlify(b))
- print(ct_arr)
- */
- const uint8_t expected_cipher[] = {
- 0xc5, 0x78, 0xa7, 0xb4, 0xf3, 0xb9, 0xcb, 0x8b,
- 0x09, 0xe0, 0xd6, 0x89, 0x14, 0x6a, 0x19, 0x09,
- 0xde, 0xaf, 0x37, 0x19, 0x32, 0x4d, 0xca, 0xf6,
- 0xff, 0x6e, 0xd2, 0x5d, 0x87, 0x51, 0xaa, 0x8c,
- 0x1c, 0xe3, 0x3b, 0xbb, 0x18, 0xf5, 0xa0, 0x1b,
- 0xdc, 0x29, 0x52, 0x63, 0xf6, 0x5d, 0x49, 0x85,
- 0x29, 0xf1, 0xf0, 0x69, 0x8f, 0xa6, 0x9f, 0x38,
- 0x5c, 0xdd, 0x26, 0xf8, 0x9d, 0x40, 0xa1, 0xff,
- 0x52, 0x46, 0xe1, 0x72, 0x70, 0x39, 0x73, 0xff,
- 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,
- };
- memset(nonce, 0xEE, 16);
- memset(key, 0x44, 16);
- // allocate internal memory
- uint8_t *chipertext = 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);
- TEST_ASSERT_NOT_NULL(chipertext);
- TEST_ASSERT_NOT_NULL(plaintext);
- TEST_ASSERT_NOT_NULL(decryptedtext);
- mbedtls_aes_init(&ctx);
- mbedtls_aes_setkey_enc(&ctx, key, 128);
- memset(plaintext, 0xAA, SZ);
- /* Test that all the end results are the same
- 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);
- size_t offset = 0;
- // Encrypt
- for (int idx = 0; idx < SZ; idx = idx + bytes_to_process) {
- // Limit length of last call to avoid exceeding buffer size
- size_t length = (idx + bytes_to_process > SZ) ? (SZ - idx) : bytes_to_process;
- 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
- size_t length = (idx + bytes_to_process > SZ) ? (SZ - idx) : bytes_to_process;
- 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);
- }
- mbedtls_aes_free(&ctx);
- free(plaintext);
- free(chipertext);
- free(decryptedtext);
- }
- TEST_CASE("mbedtls CTR stream test", "[aes]")
- {
- aes_ctr_stream_test();
- }
- TEST_CASE("mbedtls OFB stream test", "[aes]")
- {
- const unsigned SZ = 100;
- mbedtls_aes_context ctx;
- uint8_t iv[16];
- uint8_t key[16];
- /* Cipher produced via this Python:
- import os, binascii
- from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
- from cryptography.hazmat.backends import default_backend
- key = b'\x44' * 16
- 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_arr = ""
- for idx, b in enumerate(ct):
- if idx % 8 == 0:
- ct_arr += '\n'
- ct_arr += "0x{}, ".format(binascii.hexlify(b))
- print(ct_arr)
- */
- const uint8_t expected_cipher[] = {
- 0xc5, 0x78, 0xa7, 0xb4, 0xf3, 0xb9, 0xcb, 0x8b,
- 0x09, 0xe0, 0xd6, 0x89, 0x14, 0x6a, 0x19, 0x09,
- 0x0a, 0x33, 0x8b, 0xab, 0x82, 0xcb, 0x20, 0x8f,
- 0x74, 0x2a, 0x6c, 0xb3, 0xc6, 0xe8, 0x18, 0x89,
- 0x09, 0xb6, 0xaf, 0x20, 0xcd, 0xea, 0x74, 0x14,
- 0x48, 0x61, 0xe8, 0x4d, 0x50, 0x12, 0x9f, 0x5e,
- 0xb8, 0x10, 0x53, 0x3b, 0x74, 0xd9, 0xd0, 0x95,
- 0x13, 0xdc, 0x14, 0xcf, 0x0c, 0xa1, 0x90, 0xfd,
- 0xa2, 0x58, 0x12, 0xb2, 0x00, 0x2c, 0x5b, 0x7a,
- 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,
- };
- memset(key, 0x44, 16);
- // allocate internal memory
- uint8_t *chipertext = 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);
- TEST_ASSERT_NOT_NULL(chipertext);
- TEST_ASSERT_NOT_NULL(plaintext);
- TEST_ASSERT_NOT_NULL(decryptedtext);
- mbedtls_aes_init(&ctx);
- mbedtls_aes_setkey_enc(&ctx, key, 128);
- memset(plaintext, 0xAA, SZ);
- /* Test that all the end results are the same
- 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);
- // Encrypt
- memset(iv, 0xEE, 16);
- size_t offset = 0;
- for (int idx = 0; idx < SZ; idx = idx + bytes_to_process) {
- // Limit length of last call to avoid exceeding buffer size
- size_t length = ( (idx + bytes_to_process) > SZ) ? (SZ - idx) : bytes_to_process;
- mbedtls_aes_crypt_ofb(&ctx, length, &offset, iv, plaintext + idx, chipertext + idx);
- }
- TEST_ASSERT_EQUAL_HEX8_ARRAY(expected_cipher, chipertext, SZ);
- // 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
- size_t length = (idx + bytes_to_process > SZ) ? (SZ - idx) : bytes_to_process;
- mbedtls_aes_crypt_ofb(&ctx, length, &offset, iv, chipertext + idx, decryptedtext + idx);
- }
- TEST_ASSERT_EQUAL_HEX8_ARRAY(plaintext, decryptedtext, SZ);
- }
- mbedtls_aes_free(&ctx);
- free(plaintext);
- free(chipertext);
- free(decryptedtext);
- }
- TEST_CASE("mbedtls CFB8 stream test", "[aes]")
- {
- const unsigned SZ = 32;
- mbedtls_aes_context ctx;
- uint8_t iv[16];
- uint8_t key[16];
- /* Cipher produced via this Python:
- import os, binascii
- from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
- from cryptography.hazmat.backends import default_backend
- key = b'\x44' * 16
- 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_arr = ""
- for idx, b in enumerate(ct):
- if idx % 8 == 0:
- ct_arr += '\n'
- ct_arr += "0x{}, ".format(binascii.hexlify(b))
- print(ct_arr)
- */
- const uint8_t expected_cipher[] = {
- 0xc5, 0x2f, 0xb0, 0x9b, 0x94, 0x9c, 0xa4, 0x5c,
- 0x0f, 0x4d, 0xa1, 0x9d, 0xd1, 0x19, 0xfc, 0x04,
- 0xe2, 0x7f, 0x04, 0x82, 0x6a, 0xa3, 0x61, 0xbb,
- 0x07, 0x6f, 0xac, 0xb9, 0xdf, 0x00, 0xf9, 0xa8,
- 0xc4, 0xbe, 0x9d, 0x4d, 0xd9, 0x42, 0x8a, 0x83,
- 0x12, 0x8b, 0xeb, 0xd7, 0x88, 0x70, 0x8a, 0xed,
- 0x46, 0x81, 0x5b, 0x4c, 0x14, 0x67, 0xe0, 0xfb,
- 0xab, 0x34, 0x90, 0x85, 0x24, 0xd2, 0x6b, 0x64,
- 0xdf, 0x1d, 0x04, 0xfd, 0x69, 0xf6, 0x30, 0xbe,
- 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,
- };
- memset(key, 0x44, 16);
- // allocate internal memory
- uint8_t *chipertext = 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);
- TEST_ASSERT_NOT_NULL(chipertext);
- TEST_ASSERT_NOT_NULL(plaintext);
- TEST_ASSERT_NOT_NULL(decryptedtext);
- mbedtls_aes_init(&ctx);
- mbedtls_aes_setkey_enc(&ctx, key, 128);
- memset(plaintext, 0xAA, SZ);
- /* Test that all the end results are the same
- no matter how many bytes we encrypt each call
- */
- for (int bytes_to_process = 1; bytes_to_process < SZ; bytes_to_process++) {
- memset(iv, 0xEE, 16);
- for (int idx = 0; idx < SZ; idx = idx + bytes_to_process) {
- // Limit length of last call to avoid exceeding buffer size
- size_t length = ( (idx + bytes_to_process) > SZ) ? (SZ - idx) : bytes_to_process;
- mbedtls_aes_crypt_cfb8(&ctx, MBEDTLS_AES_ENCRYPT, length, iv, plaintext + idx, chipertext + idx);
- }
- TEST_ASSERT_EQUAL_HEX8_ARRAY(expected_cipher, chipertext, SZ);
- memset(iv, 0xEE, 16);
- for (int idx = 0; idx < SZ; idx = idx + bytes_to_process) {
- // Limit length of last call to avoid exceeding buffer size
- size_t length = ( (idx + bytes_to_process) > SZ) ? (SZ - idx) : bytes_to_process;
- mbedtls_aes_crypt_cfb8(&ctx, MBEDTLS_AES_DECRYPT, length, iv, chipertext + idx, decryptedtext + idx);
- }
- TEST_ASSERT_EQUAL_HEX8_ARRAY(plaintext, decryptedtext, SZ);
- }
- mbedtls_aes_free(&ctx);
- free(plaintext);
- free(chipertext);
- free(decryptedtext);
- }
- TEST_CASE("mbedtls CFB128 stream test", "[aes]")
- {
- const unsigned SZ = 32;
- mbedtls_aes_context ctx;
- uint8_t iv[16];
- uint8_t key[16];
- /* Cipher produced via this Python:
- import os, binascii
- from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
- from cryptography.hazmat.backends import default_backend
- key = b'\x44' * 16
- 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_arr = ""
- for idx, b in enumerate(ct):
- if idx % 8 == 0:
- ct_arr += '\n'
- ct_arr += "0x{}, ".format(binascii.hexlify(b))
- print(ct_arr)
- */
- const uint8_t expected_cipher[] = {
- 0xc5, 0x78, 0xa7, 0xb4, 0xf3, 0xb9, 0xcb, 0x8b,
- 0x09, 0xe0, 0xd6, 0x89, 0x14, 0x6a, 0x19, 0x09,
- 0xf9, 0x08, 0x7e, 0xe1, 0x92, 0x8a, 0x7c, 0xa4,
- 0x25, 0xa5, 0xa7, 0x43, 0x24, 0x8d, 0x85, 0x3e,
- 0x99, 0x28, 0xeb, 0x36, 0x59, 0x74, 0x69, 0x0e,
- 0x09, 0x9f, 0x4e, 0xc0, 0x6d, 0xc3, 0x2b, 0x80,
- 0x01, 0xad, 0xa1, 0x0c, 0x99, 0x90, 0x8b, 0x07,
- 0xd6, 0x00, 0xf0, 0x32, 0xd7, 0x6b, 0xa1, 0xf1,
- 0x4d, 0x14, 0xd0, 0x28, 0xde, 0x64, 0x23, 0x71,
- 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, 0x59, 0xf7, 0xd3,
- };
- memset(key, 0x44, 16);
- // allocate internal memory
- uint8_t *chipertext = 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);
- TEST_ASSERT_NOT_NULL(chipertext);
- TEST_ASSERT_NOT_NULL(plaintext);
- TEST_ASSERT_NOT_NULL(decryptedtext);
- mbedtls_aes_init(&ctx);
- mbedtls_aes_setkey_enc(&ctx, key, 128);
- memset(plaintext, 0xAA, SZ);
- /* Test that all the end results are the same
- no matter how many bytes we encrypt each call
- */
- //for (int bytes_to_process = 1; bytes_to_process < SZ; bytes_to_process++) {
- int bytes_to_process = 17;
- size_t offset = 0;
- memset(iv, 0xEE, 16);
- for (int idx = 0; idx < SZ; idx = idx + bytes_to_process) {
- // Limit length of last call to avoid exceeding buffer size
- size_t length = ( (idx + bytes_to_process) > SZ) ? (SZ - idx) : bytes_to_process;
- mbedtls_aes_crypt_cfb128(&ctx, MBEDTLS_AES_ENCRYPT, length, &offset, iv, plaintext + idx, chipertext + idx);
- }
- TEST_ASSERT_EQUAL_HEX8_ARRAY(expected_cipher, chipertext, SZ);
- offset = 0;
- memset(iv, 0xEE, 16);
- for (int idx = 0; idx < SZ; idx = idx + bytes_to_process) {
- // Limit length of last call to avoid exceeding buffer size
- size_t length = ( (idx + bytes_to_process) > SZ) ? (SZ - idx) : bytes_to_process;
- mbedtls_aes_crypt_cfb128(&ctx, MBEDTLS_AES_DECRYPT, length, &offset, iv, chipertext + idx, decryptedtext + idx);
- }
- TEST_ASSERT_EQUAL_HEX8_ARRAY(plaintext, decryptedtext, SZ);
- mbedtls_aes_free(&ctx);
- free(plaintext);
- free(chipertext);
- free(decryptedtext);
- }
- /* Cipher produced via this Python:
- import os, binascii
- from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
- from cryptography.hazmat.backends import default_backend
- key = b'\x44' * 16
- 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_arr = ""
- for idx, b in enumerate(ct):
- if idx % 8 == 0:
- ct_arr += '\n'
- ct_arr += "0x{}, ".format(binascii.hexlify(b))
- print(ct_arr)
- */
- /* Test the case where the input and output buffers point to the same location */
- TEST_CASE("mbedtls CTR, input buf = output buf", "[aes]")
- {
- const unsigned SZ = 1000;
- mbedtls_aes_context ctx;
- uint8_t nonce[16];
- uint8_t stream_block[16];
- size_t nc_off = 0;
- const uint8_t expected_cipher_end[] = {
- 0xd4, 0xdc, 0x4f, 0x8f, 0xfe, 0x86, 0xee, 0xb5,
- 0x14, 0x7f, 0xba, 0x30, 0x25, 0xa6, 0x7f, 0x6c,
- 0xb5, 0x73, 0xaf, 0x90, 0xd7, 0xff, 0x36, 0xba,
- 0x2b, 0x1d, 0xec, 0xb9, 0x38, 0xfa, 0x0d, 0xeb,
- };
- memcpy(nonce, iv, 16);
- // allocate internal memory
- uint8_t *buf = heap_caps_malloc(SZ, MALLOC_CAP_8BIT|MALLOC_CAP_INTERNAL);
- TEST_ASSERT_NOT_NULL(buf);
- mbedtls_aes_init(&ctx);
- mbedtls_aes_setkey_enc(&ctx, key_256, 256);
- memset(buf, 0x3A, SZ);
- // Encrypt
- mbedtls_aes_crypt_ctr(&ctx, SZ, &nc_off, nonce, stream_block, buf, buf);
- TEST_ASSERT_EQUAL_HEX8_ARRAY(expected_cipher_end, buf + SZ - 32, 32);
- // Decrypt
- nc_off = 0;
- memcpy(nonce, iv, 16);
- mbedtls_aes_crypt_ctr(&ctx, SZ, &nc_off, nonce, stream_block, buf, buf);
- for (int i = 0; i < SZ; i++) {
- TEST_ASSERT_EQUAL_HEX8(0x3A, buf[i]);
- }
- mbedtls_aes_free(&ctx);
- free(buf);
- }
- TEST_CASE("mbedtls OFB, chained DMA descriptors", "[aes]")
- {
- // Max bytes in a single DMA descriptor is 4095
- const unsigned SZ = 6000;
- mbedtls_aes_context ctx;
- uint8_t nonce[16];
- size_t nc_off = 0;
- const uint8_t expected_cipher_end[] = {
- 0xfe, 0xfa, 0xc9, 0x26, 0xb5, 0xc9, 0xea, 0xb0,
- 0xdd, 0x1e, 0xe7, 0x0e, 0xfa, 0x5b, 0x4b, 0x94,
- 0xaa, 0x5f, 0x60, 0x1e, 0xb2, 0x19, 0x3c, 0x2e,
- 0xf6, 0x73, 0x56, 0x9f, 0xa7, 0xd5, 0xb7, 0x21,
- };
- memcpy(nonce, iv, 16);
- // allocate internal memory
- uint8_t *chipertext = 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);
- TEST_ASSERT_NOT_NULL(chipertext);
- TEST_ASSERT_NOT_NULL(plaintext);
- TEST_ASSERT_NOT_NULL(decryptedtext);
- mbedtls_aes_init(&ctx);
- mbedtls_aes_setkey_enc(&ctx, key_256, 256);
- memset(plaintext, 0x3A, SZ);
- memset(decryptedtext, 0x0, SZ);
- // Encrypt
- mbedtls_aes_crypt_ofb(&ctx, SZ, &nc_off, nonce, plaintext, chipertext);
- TEST_ASSERT_EQUAL_HEX8_ARRAY(expected_cipher_end, chipertext + SZ - 32, 32);
- // Decrypt
- nc_off = 0;
- memcpy(nonce, iv, 16);
- mbedtls_aes_crypt_ofb(&ctx, SZ, &nc_off, nonce, chipertext, decryptedtext);
- TEST_ASSERT_EQUAL_HEX8_ARRAY(plaintext, decryptedtext, SZ);
- mbedtls_aes_free(&ctx);
- free(plaintext);
- free(chipertext);
- free(decryptedtext);
- }
- const uint8_t expected_cipher_ctr_end[] = {
- 0x93, 0xca, 0xe0, 0x44, 0x96, 0x6d, 0xcb, 0xb2,
- 0xcf, 0x8a, 0x8d, 0x73, 0x8c, 0x6b, 0xfa, 0x4d,
- 0xd6, 0xc4, 0x18, 0x49, 0xdd, 0xc6, 0xbf, 0xc2,
- 0xb9, 0xf0, 0x09, 0x69, 0x45, 0x42, 0xc6, 0x05,
- };
- void aes_ctr_alignment_test(uint32_t input_buf_caps, uint32_t output_buf_caps)
- {
- mbedtls_aes_context ctx;
- uint8_t nonce[16];
- uint8_t key[16];
- uint8_t stream_block[16];
- size_t SZ = 32*200;
- size_t ALIGNMENT_SIZE_BYTES = 64;
- memset(nonce, 0x2F, 16);
- memset(key, 0x1E, 16);
- // allocate memory according the requested caps
- uint8_t *chipertext = 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);
- TEST_ASSERT_NOT_NULL(chipertext);
- TEST_ASSERT_NOT_NULL(plaintext);
- TEST_ASSERT_NOT_NULL(decryptedtext);
- mbedtls_aes_init(&ctx);
- mbedtls_aes_setkey_enc(&ctx, key, 128);
- memset(plaintext, 0x26, SZ + ALIGNMENT_SIZE_BYTES);
- size_t offset;
- /* Shift buffers and test for all different misalignments */
- for (int i = 0; i < ALIGNMENT_SIZE_BYTES; i++ ) {
- // Encrypt with input buffer in external ram
- offset = 0;
- memset(nonce, 0x2F, 16);
- mbedtls_aes_crypt_ctr(&ctx, SZ, &offset, nonce, stream_block, plaintext + i, chipertext + i);
- TEST_ASSERT_EQUAL_HEX8_ARRAY(expected_cipher_ctr_end, chipertext + i + SZ - 32, 32);
- // Decrypt
- offset = 0;
- memset(nonce, 0x2F, 16);
- // Decrypt with input buffer in instruction memory, the crypto DMA can't access this
- mbedtls_aes_crypt_ctr(&ctx, SZ, &offset, nonce, stream_block, chipertext + i, decryptedtext);
- TEST_ASSERT_EQUAL_HEX8_ARRAY(plaintext, decryptedtext, SZ);
- }
- mbedtls_aes_free(&ctx);
- free(plaintext);
- free(chipertext);
- free(decryptedtext);
- }
- TEST_CASE("mbedtls AES internal mem alignment tests", "[aes]")
- {
- uint32_t internal_dma_caps = MALLOC_CAP_DMA | MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL;
- aes_ctr_alignment_test(internal_dma_caps, internal_dma_caps);
- }
- #ifdef CONFIG_SPIRAM_USE_MALLOC
- void aes_psram_one_buf_ctr_test(void)
- {
- mbedtls_aes_context ctx;
- uint8_t nonce[16];
- uint8_t key[16];
- uint8_t stream_block[16];
- size_t SZ = 32*200;
- size_t ALIGNMENT_SIZE_BYTES = 32;
- memset(nonce, 0x2F, 16);
- memset(key, 0x1E, 16);
- // allocate external memory
- uint8_t *buf = heap_caps_malloc(SZ + ALIGNMENT_SIZE_BYTES, MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM);
- TEST_ASSERT_NOT_NULL(buf);
- mbedtls_aes_init(&ctx);
- mbedtls_aes_setkey_enc(&ctx, key, 128);
- memset(buf, 0x26, SZ + ALIGNMENT_SIZE_BYTES);
- size_t offset;
- /* Shift buffers and test for all different misalignments */
- for (int i = 0; i < ALIGNMENT_SIZE_BYTES; i++ ) {
- // Encrypt with input buffer in external ram
- offset = 0;
- memset(buf, 0x26, SZ + ALIGNMENT_SIZE_BYTES);
- memset(nonce, 0x2F, 16);
- mbedtls_aes_crypt_ctr(&ctx, SZ, &offset, nonce, stream_block, buf + i, buf + i);
- TEST_ASSERT_EQUAL_HEX8_ARRAY(expected_cipher_ctr_end, buf + i + SZ - 32, 32);
- // Decrypt
- offset = 0;
- memset(nonce, 0x2F, 16);
- // Decrypt with input buffer in instruction memory, the crypto DMA can't access this
- mbedtls_aes_crypt_ctr(&ctx, SZ, &offset, nonce, stream_block, buf + i, buf);
- TEST_ASSERT_EACH_EQUAL_HEX8(0x26, buf + i, SZ - i);
- }
- mbedtls_aes_free(&ctx);
- free(buf);
- }
- const uint8_t long_input[] = {
- 0xf7, 0xe6, 0x6b, 0x8d, 0x2e, 0xbf, 0x88, 0xd6,
- 0xb0, 0x77, 0xdf, 0x72, 0xbf, 0xa8, 0x0, 0x55,
- 0xd5, 0xd1, 0x49, 0xa3, 0x2c, 0xc, 0xfe, 0xdb,
- 0x17, 0x37, 0xa4, 0x1d, 0x70, 0x6b, 0x99, 0xf5,
- 0x9e, 0x6, 0xad, 0x6c, 0xe0, 0x3b, 0xfa, 0x50,
-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, 0x93, 0xf9, 0xe1, 0x41, 0x4b,
- 0x18, 0x42, 0x6f, 0x8f, 0x96, 0x3d, 0x2b, 0x28,
- 0xd5, 0x53, 0x62, 0xdd, 0x6b, 0xd0, 0xf8, 0x2e,
- 0xa6, 0x97, 0xe5, 0x87, 0xc5, 0xf6, 0x96, 0x7b,
- 0xc4, 0x3e, 0x84, 0xc9, 0xf6, 0x34, 0x63, 0x46,
- 0xe1, 0x10, 0xa5, 0x91, 0x6b, 0xff, 0x10, 0x3f,
- 0x50, 0x2e, 0xd7, 0x39, 0x12, 0x7a, 0x15, 0x85,
- 0xed, 0x99, 0xdb, 0x9b, 0x99, 0x6b, 0xfa, 0xfa,
- 0x93, 0x7, 0x44, 0xbe, 0xbe, 0x60, 0x23, 0xc1,
- 0xec, 0x5c, 0xf6, 0x93, 0x38, 0xf9, 0x89, 0x0,
- 0xc5, 0x5f, 0x5b, 0xe2, 0x9d, 0x2b, 0xea, 0x6b,
- 0x2e, 0xee, 0xb7, 0x4a, 0x4e, 0x8d, 0xd0, 0x35,
- 0xe9, 0xc1, 0x5, 0x2b, 0x83, 0xb7, 0x72, 0x25,
- 0xbb, 0xbe, 0xe8, 0x15, 0xf4, 0x74, 0x69, 0x69,
- 0x67, 0x8c, 0x5c, 0x31, 0x79, 0x78, 0x2e, 0x43,
- 0x83, 0xd1, 0xdd, 0x9, 0xc3, 0xa1, 0x0, 0x13,
- 0x31, 0x4b, 0x86, 0xce, 0xee, 0xd7, 0xec, 0xb1,
- 0x2c, 0x38, 0x46, 0x68, 0x62, 0xd9, 0x84, 0xdb,
- 0x24, 0x62, 0x82, 0xc, 0x12, 0xb7, 0x4f, 0x86,
- 0x54, 0x18, 0xc6, 0xd7, 0x94, 0x8b, 0xf2, 0x4c,
- 0x17, 0x98, 0xaa, 0xe0,
- };
- const uint8_t expected_cipher_long_input_end[] = {
- 0x05, 0x95, 0x58, 0x7b, 0xb4, 0x60, 0x15,
- 0x32, 0x9f, 0x38, 0xcc, 0x98, 0x1b, 0xbe, 0x10, 0xa5, 0x06, 0x67, 0xae, 0x38,
- 0xbd, 0x7d, 0xb5, 0xcd, 0x58, 0x32, 0xdd, 0x9e,
- 0x6a, 0xde, 0xe3, 0x53,
- };
- void aes_ext_flash_ctr_test(uint32_t output_buf_caps)
- {
- mbedtls_aes_context ctx;
- uint8_t nonce[16];
- uint8_t key[16];
- uint8_t stream_block[16];
- size_t SZ = sizeof(long_input);
- memset(nonce, 0x2F, 16);
- memset(key, 0x1E, 16);
- uint8_t *chipertext = heap_caps_malloc(SZ, output_buf_caps);
- uint8_t *decryptedtext = heap_caps_malloc(SZ, MALLOC_CAP_8BIT | MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL);
- TEST_ASSERT_NOT_NULL(chipertext);
- TEST_ASSERT_NOT_NULL(decryptedtext);
- mbedtls_aes_init(&ctx);
- mbedtls_aes_setkey_enc(&ctx, key, 128);
- size_t offset;
- // Encrypt with input buffer in external flash
- offset = 0;
- memset(nonce, 0x2F, 16);
- mbedtls_aes_crypt_ctr(&ctx, SZ, &offset, nonce, stream_block, long_input, chipertext);
- TEST_ASSERT_EQUAL_HEX8_ARRAY(expected_cipher_long_input_end, chipertext + SZ - 32, 32);
- // Decrypt
- offset = 0;
- memset(nonce, 0x2F, 16);
- // Decrypt with input buffer in external flash, the crypto DMA can't access this
- mbedtls_aes_crypt_ctr(&ctx, SZ, &offset, nonce, stream_block, chipertext, decryptedtext);
- TEST_ASSERT_EQUAL_HEX8_ARRAY(long_input, decryptedtext, SZ);
- mbedtls_aes_free(&ctx);
- free(chipertext);
- free(decryptedtext);
- }
- /* 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_psram_one_buf_ctr_test();
- }
- /* 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);
- }
- #endif // CONFIG_SPIRAM_USE_MALLOC
- static SemaphoreHandle_t done_sem;
- static void __attribute__((unused)) aes_ctr_stream_test_task(void *pv)
- {
- aes_ctr_stream_test();
- xSemaphoreGive(done_sem);
- vTaskDelete(NULL);
- }
- #if CONFIG_ESP_SYSTEM_RTC_FAST_MEM_AS_HEAP_DEPCHECK
- TEST_CASE("mbedtls AES stack in RTC RAM", "[mbedtls]")
- {
- done_sem = xSemaphoreCreateBinary();
- static StaticTask_t rtc_task;
- size_t STACK_SIZE = 3072;
- uint8_t *rtc_stack = heap_caps_calloc(STACK_SIZE, 1, MALLOC_CAP_RTCRAM);
- TEST_ASSERT(esp_ptr_in_rtc_dram_fast(rtc_stack));
- TEST_ASSERT_NOT_NULL(xTaskCreateStatic(aes_ctr_stream_test_task, "aes_ctr_task", STACK_SIZE, NULL,
- 3, rtc_stack, &rtc_task));
- TEST_ASSERT_TRUE(xSemaphoreTake(done_sem, 10000 / portTICK_PERIOD_MS));
- /* Give task time to cleanup before freeing stack */
- vTaskDelay(1000 / portTICK_PERIOD_MS);
- free(rtc_stack);
- vSemaphoreDelete(done_sem);
- }
- #endif //CONFIG_ESP_SYSTEM_RTC_FAST_MEM_AS_HEAP_DEPCHECK
- #if CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY && CONFIG_SPIRAM_USE_MALLOC
- 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);
- TEST_ASSERT(esp_ptr_external_ram(psram_stack));
- TEST_ASSERT_NOT_NULL(xTaskCreateStatic(aes_ctr_stream_test_task, "aes_ctr_task", STACK_SIZE, NULL,
- 3, psram_stack, &psram_task));
- TEST_ASSERT_TRUE(xSemaphoreTake(done_sem, 10000 / portTICK_PERIOD_MS));
- /* Give task time to cleanup before freeing stack */
- vTaskDelay(1000 / portTICK_PERIOD_MS);
- free(psram_stack);
- vSemaphoreDelete(done_sem);
- }
- #endif //CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY && CONFIG_SPIRAM_USE_MALLOC
|