AES benchmark

Browse source code on GitHub

Overview

This sample benchmarks crypto cipher API throughput (cycles/byte, MB/s) and CPU load for AES-256-CBC across a range of message sizes, on top of whichever crypto cipher driver is enabled on the board. It is meant to illustrate what a hardware AES accelerator brings compared to a software-only implementation, and to compare polling vs. interrupt-driven driver implementations.

On drivers with an interrupt-driven mode (e.g. STM32 CRYP), the fixed cost of an interrupt round trip is paid on every call regardless of message size: negligible for large messages (freed-up CPU time with no throughput cost), but a measurable throughput hit for small ones (a few tens of bytes) where that fixed cost dominates.

Building and Running

This project outputs to the console. It can be built and executed as follows, replacing <board> with a board that has a crypto cipher driver enabled (for example stm32mp135f_dk):

west build -b <board> samples/drivers/aes_bench
west flash

To benchmark the software-only (mbedTLS) implementation instead of a hardware accelerator, build with the prj_mtls_shim.conf overlay. This also works on native_sim, to compare against a board with a hardware accelerator. On a platform that provides a PSA crypto driver for a hardware AES accelerator, mbedTLS may route the operations to it: disable that driver to measure a pure software implementation:

west build -b native_sim samples/drivers/aes_bench -- -DEXTRA_CONF_FILE=prj_mtls_shim.conf
west build -t run

The console banner is the same for every implementation.

Sample Output

AES benchmark
BENCH AES256-CBC len=64 loops=2000 cycles=... cpb=... MBps=...
...
BENCH AES256-CBC len=65520 loops=40 cycles=... cpb=... MBps=...

See also

Cipher