wolfSSL’s OpenSSL compatibility layer lets software written for OpenSSL build against wolfSSL, usually with very few code changes. It is a big part of how projects such as nginx, OpenVPN and HAProxy run on wolfSSL. It has also had a reputation for costing quite a bit more RAM than you would expect the moment you turn it on, which really matters when the target is a microcontroller with a few hundred KB of SRAM.
We have made several changes to our source code recently that will be in the next version of wolfSSL to optimize all these things. So, it is time to benchmark them to see what an improvement they have made.
How I measured
Everything here was measured on the wolfDemo board: an STM32U585 running at 160MHz, using newlib-nano’s malloc and built with GCC 15.3 at -O2. The wolfSSL configuration is a typical embedded one, with TLS 1.2 and 1.3, ECC and RSA, AES-GCM, ChaCha20-Poly1305, WOLFSSL_SMALL_STACK and the SP math Cortex-M assembly.
The test harness runs a TLS 1.3 client and server in the same process, talking over memory buffers. A counting allocator tags every allocation as client or server. For each phase it records allocations, peak heap, memory still held at the end of the phase, and time from the DWT cycle counter. The phases are loading the CA, creating the SSL objects, the full handshake, a 1KB echo that also collects the session ticket, and a resumption. Unless I say otherwise, the figures are for an ECC P-256 leaf with two intermediate CAs and no verify callback.
I built four configurations: no compatibility layer at all, OPENSSL_EXTRA_X509_SMALL, OPENSSL_EXTRA and OPENSSL_ALL. “Before” is without the performance patches that have been merged. “After” is the current master. Flash and static RAM come from the linker map and count only wolfSSL’s own code and data, including its string literals.
Results
First up, the client side of a full handshake. Without the compatibility layer it takes 116.7ms, makes 485 allocations and peaks at 12.9KB of heap. Each row shows before and after.
| Build | Allocations | Peak heap | Time added by the compat layer |
|---|---|---|---|
| OPENSSL_EXTRA_X509_SMALL | 984 to 484 | 19.1KB to 13.1KB | 4.6ms to 0.0ms |
| OPENSSL_EXTRA | 1,147 to 523 | 20.8KB to 15.4KB | 7.3ms to 1.5ms |
| OPENSSL_ALL | 1,338 to 541 | 38.6KB to 18.2KB | 13.5ms to 2.1ms |
OPENSSL_EXTRA_X509_SMALL now costs almost nothing over a build without the compatibility layer: one allocation fewer, 256 bytes more heap and no extra time. Most OpenSSL applications set a verify callback, and that case improved the most. With one set, the OPENSSL_ALL handshake goes from 1,806 allocations and 29.4ms of added time to 628 allocations and 4.5ms.
Next, what stays in memory. The client figure counts its SSL_CTX and loaded CA as well as the connection; the server figure is just the connection.
| Build | Flash | Static RAM | Client, connected | Server, connected |
|---|---|---|---|---|
| No compat layer | 275.5KB | 15.0KB | 3.8KB | 2.3KB |
| OPENSSL_EXTRA_X509_SMALL | 291.6KB to 293.7KB | 15.4KB | 3.9KB | 2.3KB |
| OPENSSL_EXTRA | 349.2KB to 350.8KB | 17.6KB | 13.6KB to 10.1KB | 6.7KB to 3.3KB |
| OPENSSL_ALL | 367.3KB to 365.2KB | 84.5KB to 18.5KB | 34.6KB to 13.8KB | 12.1KB to 5.9KB |
The static RAM saving under OPENSSL_ALL is the session cache, whose entries are now a fifth of the size. The flash changes are within about 2KB either way: the shared name objects add a little, and the code that is no longer needed takes a little away.
Across the whole test, with client and server running together, the heap high-water mark under OPENSSL_ALL fell from 94.1KB to 50.0KB, and under OPENSSL_EXTRA from 52.2KB to 39.2KB. For comparison, the same test without the compatibility layer peaks at 30.4KB.
Against OpenSSL itself
The U585 has 2MB of flash, so I wondered if OpenSSL would fit. To find out, I wrote a second version of the test that only uses the OpenSSL API. It uses SSL_CTX_new(), a BIO pair for the transport, PEM_read_bio_X509(), d2i_PrivateKey() and so on. The same source builds against OpenSSL or against wolfSSL’s compatibility layer. Both are pinned to TLS 1.3, a P-256 key share and AES-128-GCM, and both send one session ticket.
OpenSSL 4.1.0 needed a little porting to run on bare metal. I built it without threads, sockets, stdio or DSO support, added a getentropy() backed by the STM32’s RNG, and stubbed out a few POSIX calls. Its ARM assembly targets the A-profile cores, so it is built with no-asm and OPENSSL_SMALL_FOOTPRINT, and the algorithms the wolfSSL build doesn’t have are turned off. It does fit, taking 1.2MB of the 2MB.
| Same application, after the changes | OpenSSL 4.1.0 | wolfSSL OPENSSL_EXTRA | wolfSSL OPENSSL_ALL |
|---|---|---|---|
| Library flash | 1,156KB | 363.7KB | 378.1KB |
| Static RAM | 14.8KB | 18.2KB | 19.1KB |
| Client handshake allocations | 2,758 | 463 | 481 |
| Client handshake peak heap | 87.0KB | 15.4KB | 18.2KB |
| Client, connected | 70.4KB | 10.5KB | 14.3KB |
| Server, connected | 47.7KB | 3.8KB | 6.3KB |
| Peak stack | 4.7KB | 2.4KB | 2.4KB |
OpenSSL also pulls in an extra 6KB of the C library. Its static RAM is a little lower, because the wolfSSL build includes a static session cache. Everything that grows with the number of connections is roughly five to twelve times smaller with wolfSSL. Built against the old wolfSSL, the same application peaked at 20.8KB (OPENSSL_EXTRA) and 38.5KB (OPENSSL_ALL) in the handshake, so the changes above carry straight over to code written for OpenSSL.
Speed is a bit more nuanced, because most of the handshake time is the public key maths. So I timed wolfSSL with three different maths builds:
| Build | Client handshake | Whole test | Library flash |
|---|---|---|---|
| OpenSSL 4.1.0, portable C | 534ms | 1,339ms | 1,156KB |
| wolfSSL, SP math in C, WOLFSSL_SP_SMALL | 784ms | 1,586ms | 361.6KB |
| wolfSSL, SP math in C | 181ms | 465ms | 404.8KB |
| wolfSSL, SP math with Cortex-M assembly | 111ms | 303ms | 363.7KB |
The whole test is client and server together: handshake, echo, and resumption. wolfSSL’s size-optimised C maths is slower than OpenSSL’s, which is the trade it is designed to make. Without the small option, wolfSSL’s C maths is nearly 3x faster than OpenSSL. With the Cortex-M assembly it is about 4.8x faster, for about the same flash as the small C build.
Wrapping up
All of the optimization work is now in master, so all of this will be in the next wolfSSL release. You do not need to change anything to get the savings, just rebuild. If you only need the X509 parts of the compatibility layer, OPENSSL_EXTRA_X509_SMALL is now basically free on top of a normal build.
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

