had a try in the AES Accelerator. just in time only in code, compile and link. we waiting for the release modul.
Using Espressif IoT Development Framework with the ESP32. For more Information about read in developer preview thread.
because its preview state, it can be, there are small mistake in this demo code, not sure how to handle the AES_IDLE_REG,
so if i know more, i will then update here. my try workaround you can read here i changed here in this demo to uint32_t
what was done:
we have one task for simple "ping"
and we have one plaintext/cleartext cyphering and one decyphering crypttext
read in the esp32 technical reference manual there is a AES Accelerator chapter.
the functions was found in components folder for esp32, there are headers for ROM, here used ROM/aes256.h
be sure you have change the line for AES_ENDIAN_REG from "ets_set_endian" to "ets_aes_set_endian"
i used for this demo devF .
devF is a Flowchart design programm, that can do flowchart to code, its a flowchart to code generator.
it is a small application for creating program flowchart, source code generation, and compilation.
Its main goal is to be straightforward, educational tool for use during structural programming classes.
devF is freeware and the src code is on github. there comes an own webside for devF and demos for esp asap,
also the links to repo, help, programm leader and so on. btw: devF was written in delphi you can use d7 personal example.
now the AES256 demo:
start with main_app, task, Vars and Function:
here is it:
the enc function: the dec function: after we call the code editor and press code generat, we get this code:
Code: Select all
#include <stdint.h>
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "rom/aes.h"
const uint8_t key[32] = "ola_not_public_viewed_here_;-)_!";
const uint8_t cryptText[16] = "esp32 aes done !";
uint8_t cryptOuttext[16] = "";
uint8_t clearOuttext[16] = "";
uint8_t i;
bool key_word_swap;
bool key_byte_swap;
bool in_word_swap;
bool in_byte_swap;
bool out_word_swap;
bool out_byte_swap;
extern uint32_t AES_IDLE_REG;
/******************************************************************************
* FunctionName : pingTask
* Description : Task for outprint "ping" as example
* Parameters : void* pvParameters
* Returns : void
*******************************************************************************/
void pingTask(void* pvParameters)
{
while (1)
{
vTaskDelay(1000 / portTICK_PERIOD_MS);
printf("ping\n");
}
}
/******************************************************************************
* FunctionName : decr_ciphertext
* Description : decrypt the cipher text to cleartext
* Parameters :
* Returns : void
*******************************************************************************/
void decr_ciphertext()
{
ets_aes_setkey_dec( (uint8_t *) key, AES256);
key_word_swap = false;
key_byte_swap = false;
in_word_swap = false;
in_byte_swap = false;
out_word_swap = false;
out_byte_swap = false;
ets_aes_set_endian( key_word_swap, key_byte_swap,
in_word_swap, in_byte_swap,
out_word_swap, out_byte_swap);
ets_aes_enable();
ets_aes_crypt( (uint8_t *) cryptOuttext, (uint8_t *) clearOuttext);
while (AES_IDLE_REG !=1)
{
// we wait for AES_IDLE
}
ets_aes_disable();
printf(" our cleartext as string : ");
printf("%s", clearOuttext);
printf("\n done!\n");
}
/******************************************************************************
* FunctionName : enc_plaintext
* Description : encrypt cleartext to ciphertext
* Parameters :
* Returns : void
*******************************************************************************/
void enc_plaintext()
{
ets_aes_setkey_enc( (uint8_t *) key, AES256);
key_word_swap = false;
key_byte_swap = false;
in_word_swap = false;
in_byte_swap = false;
out_word_swap = false;
out_byte_swap = false;
ets_aes_set_endian( key_word_swap, key_byte_swap,
in_word_swap, in_byte_swap,
out_word_swap, out_byte_swap);
ets_aes_enable();
ets_aes_crypt( (uint8_t *) cryptText, (uint8_t *) cryptOuttext);
while (AES_IDLE_REG !=1)
{
// we wait for AES_IDLE
}
ets_aes_disable();
printf(" our ciphertext in hex: ");
for (i = 0; i < 16; i++)
{
printf("%2x ", cryptOuttext[i]);
}
printf("\n done!\n");
}
/******************************************************************************
* FunctionName : app_main
* Description : ESP32 app main - first called function
* Parameters :
* Returns : void
*******************************************************************************/
void app_main()
{
enc_plaintext();
decr_ciphertext();
xTaskCreatePinnedToCore(&pingTask, "pingTask", 2048, NULL, 5, NULL, 0);
}
after press compile, devF calls the "Windows script" from esp-idf, compile and link it.
i used in this demo - single app and bootloader. the menuconfig in esp-idf is amazing!
To flash all build output, must run 'make flash' in devF or on console:
( for your folder / paths - you must use your folder / paths )
python c:/sdk32/esp-idf/bin/esptool.py --chip esp32 --port COM20 --baud 230400 write_flash
0x1000 /c/sdk32devF/esp-devF/build/bootloader/bootloader.bin
0x10000 /c/sdk32devF/esp-devF/build/app-template.bin
0x4000 /c/sdk32devF/esp-devF/build/partitions_singleapp.bin
perhabs someone has a esp32 release, he can use the code and have a try.
because the limit is 3 attachment in this - i will push one thread with bin files.
let me know, if something wrong - because i can not flash just in time,
i am waiting for the released modul.
have phun!
best wishes
rudi