Using WIFI and AES128 simultaneously in ESP-IDF v 4.4

andrej32
Posts: 28
Joined: Fri Apr 19, 2019 8:22 am

Using WIFI and AES128 simultaneously in ESP-IDF v 4.4

Postby andrej32 » Wed Apr 05, 2023 10:37 am

There is a project on ESP32 that simultaneously uses Wi-Fi and AES 128 encryption of the recorded data (which are later stored on the SD card). Everything works fine in ESP-IDF 4.0. But when the same project in ESP-IDF v4.4 does not work. If we initialize AES128, then an error occurs later when trying to connect to WIFI (even if we do not encrypt during WIFI operation).

What should I do to use AES128 and WI-FI simultaneously in ESP-IDF v4.4?

Initialization AES128:

Code: Select all

mbedtls_aes_init(&ctx);
    mbedtls_aes_setkey_enc(&ctx, Crypto_Key, 128);
or (we get the same result)

Code: Select all

esp_aes_init(&ctx);
    esp_aes_setkey(&ctx, Crypto_Key, 128);
Error:
  • connect to: sensor : Gu9-Za6=Ti3
    I (18460) wifi:mode : sta (7c:9e:bd:c7:bb:ec)
    I (18460) wifi:enable tsf
    connect to the AP
    I (19680) wifi:new:<11,0>, old:<1,0>, ap:<255,255>, sta:<11,0>, prof:1
    I (21160) wifi:state: init -> auth (b0)
    I (21170) wifi:state: auth -> assoc (0)
    I (21180) wifi:state: assoc -> run (10)
    Guru Meditation Error: Core 0 panic'ed (InstructionFetchError). Exception was unhandled.

    Core 0 register dump:
    PC : 0x3ffb5b54 PS : 0x00060030 A0 : 0x8012ecd8 A1 : 0x3ffd2050
    A2 : 0xffffffff A3 : 0x3ffdb4d4 A4 : 0x00000009 A5 : 0x0000000b
    A6 : 0x00000080 A7 : 0x00000008 A8 : 0x80133194 A9 : 0x3ffb5b54
    A10 : 0x3ffdb4bc A11 : 0x3ffdb4d4 A12 : 0x00000009 A13 : 0x0000000b
    A14 : 0x000000bb A15 : 0x000000ec SAR : 0x00000010 EXCCAUSE: 0x00000002
    EXCVADDR: 0x3ffb5b54 LBEG : 0x4000c46c LEND : 0x4000c477 LCOUNT : 0x00000000


    Backtrace:0x3ffb5b51:0x3ffd2050 |<-CORRUPTED




    ELF file SHA256: 1b451c9f1888427c

    Rebooting...
    I (12) boot: ESP-IDF v4.4.1-dirty 2nd stage bootloader
    I (12) boot: compile time 16:41:11
    I (13) boot: chip revision: 1
    I (15) boot_comm: chip revision: 1, min. bootloader chip revision: 0
    I (22) boot.esp32: SPI Speed : 40MHz
    I (26) boot.esp32: SPI Mode : DIO
    I (31) boot.esp32: SPI Flash Size : 4MB
    I (35) boot: Enabling RNG early entropy source...
    I (41) boot: Partition Table:
    I (44) boot: ## Label Usage Type ST Offset Length
    I (52) boot: 0 nvs WiFi data 01 02 00009000 00004000
    I (59) boot: 1 otadata OTA data 01 00 0000d000 00002000
    I (67) boot: 2 phy_init RF data 01 01 0000f000 00001000
    I (74) boot: 3 factory factory app 00 00 00010000 00100000
    I (82) boot: 4 ota_0 OTA app 00 10 00110000 00100000
    I (89) boot: 5 ota_1 OTA app 00 11 00210000 00100000
    I (97) boot: End of partition table
    I (101) boot: Defaulting to factory image
    I (105) boot_comm: chip revision: 1, min. application chip revision: 0
    I (113) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=2bf40h (180032) map
    I (186) esp_image: segment 1: paddr=0003bf68 vaddr=3ffb0000 size=03c94h ( 15508) load
    I (193) esp_image: segment 2: paddr=0003fc04 vaddr=40080000 size=00414h ( 1044) load
    I (193) esp_image: segment 3: paddr=00040020 vaddr=400d0020 size=91e5ch (597596) map
    I (417) esp_image: segment 4: paddr=000d1e84 vaddr=40080414 size=16af0h ( 92912) load
    I (455) esp_image: segment 5: paddr=000e897c vaddr=400c0000 size=00064h ( 100) load
    I (456) esp_image: segment 6: paddr=000e89e8 vaddr=50000000 size=00010h ( 16) load
    I (472) boot: Loaded app from partition at offset 0x10000
    I (472) boot: Disabling RNG early entropy source...
    I (486) cpu_start: Pro cpu up.
    I (487) cpu_start: Starting app cpu, entry point is 0x400813fc
    0x400813fc: call_start_cpu1 at C:/esp-idf-v4.4.1/components/esp_system/port/cpu_start.c:160

    I (481) cpu_start: App cpu up.
    I (519) cpu_start: Pro cpu start user code
    I (519) cpu_start: cpu freq: 160000000
    I (519) cpu_start: Application information:
    I (522) cpu_start: Project name: voca-esp
    I (527) cpu_start: App version: 2.5.0
    I (532) cpu_start: Compile time: Apr 4 2023 16:40:43
    I (538) cpu_start: ELF file SHA256: 1b451c9f1888427c...
    I (544) cpu_start: ESP-IDF: v4.4.1-dirty
    I (550) heap_init: Initializing. RAM available for dynamic allocation:
    I (557) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
    I (563) heap_init: At 3FFC3700 len 0001C900 (114 KiB): DRAM
    I (569) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
    I (575) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
    I (582) heap_init: At 40096F04 len 000090FC (36 KiB): IRAM
    I (589) spi_flash: detected chip: generic
    I (593) spi_flash: flash io: dio
    I (608) cpu_start: Starting scheduler on PRO CPU.
    I (0) cpu_start: Starting scheduler on APP CPU.

andrej32
Posts: 28
Joined: Fri Apr 19, 2019 8:22 am

Re: Using WIFI and AES128 simultaneously in ESP-IDF v 4.4

Postby andrej32 » Fri Apr 07, 2023 11:32 am

The problem is solved. In ESP-IDF v4.4.x, you cannot use the name "ctx" of the encryption context variable. If you use a different name, then everything works.

axellin
Posts: 200
Joined: Mon Sep 17, 2018 9:09 am

Re: Using WIFI and AES128 simultaneously in ESP-IDF v 4.4

Postby axellin » Wed Apr 12, 2023 2:54 am

andrej32 wrote:
Fri Apr 07, 2023 11:32 am
The problem is solved. In ESP-IDF v4.4.x, you cannot use the name "ctx" of the encryption context variable. If you use a different name, then everything works.
Why? Is ctx a global variable?

Who is online

Users browsing this forum: Bing [Bot], Bryght-Richard, Google [Bot] and 120 guests