Tuning wolfSSL for Cortex-M: Build Options for Speed and Code Size

A wolfSSL build for Cortex-M defaults to the smallest public key math, which is also the slowest. Three configuration changes made a full TLS 1.3 handshake ten times faster, from 2800 ms down to 262 ms, and left the image smaller at the same time. Every figure below was measured on a NUCLEO-U385RG-Q (STM32U385, Cortex-M33).

  • WOLFSSL_SP_ARM_CORTEX_M_ASM is the one that matters. It routes the ECC and RSA math through Cortex-M assembly. ECDSA P-256 verify drops from 609 ms to 50 ms, and the handshake runs 10.7 times faster for 3.9 KB of flash.
  • Keep WOLFSSL_SP_SMALL when you enable that assembly. Removing it as well costs 44 KB and buys very little extra speed.
  • Turn off what TLS never negotiates. Define NO_DES3, since 3DES is built in unless you say otherwise, and leave WOLFSSL_SHA3, HAVE_CHACHA, HAVE_POLY1305, WOLFSSL_SHA224 and WOLFSSL_CMAC undefined. Those came to 18 KB on this build.

Those same changes left the image 7 percent smaller than the starting configuration. Ten times the speed for less flash is not the usual tradeoff, which is why the defaults are worth revisiting on any Cortex-M target.

Everything above applies to any Cortex-M part. Where the silicon has crypto engines there is more to gain: STM32U3 and STM32U5 carry a PKA and an AES engine, reached with WOLFSSL_STM32U3 or WOLFSSL_STM32U5 plus WOLFSSL_STM32_PKA. Driving both alongside the assembly brought the same handshake to 203 ms, and hardware AES-GCM measured 7.30 MiB/s against 281 KiB/s in software. The PKA accelerates ECDSA but not the ECDH key agreement, so it belongs alongside the assembly rather than instead of it.

Check out a configuration templates to start!

If you have questions about any of the above, please contact us at facts@wolfssl.com or call us at +1 425 245 8247.

Download wolfSSL Now