Some lightweight TLS libraries are available. They are targeted at embedded markets such as Internet of Things (IoT) devices or other small devices that many people use but they aren’t considered computers. This includes payment terminals at your local grocery store, smartwatches, smart light bulbs, and industrial sensors of different kinds. Such devices usually have weak CPUs, low memory, and small storage space.
Lightweight TLS libraries usually become lightweight through modularity, the possibility to compile only the needed modules, support fewer cryptographic algorithms and protocols, and have less advanced APIs; that is, they expose fewer features and settings to application developers using the library.
The most well-known lightweight TLS libraries are wolfSSL (formerly yaSSL, also known as Yet Another SSL), Mbed TLS (formerly PolarSSL), and MatrixSSL.
The most advanced of the three libraries seems to be wolfSSL. It supports a lot of cryptographic algorithms, including new algorithms such as ChaCha20 and Poly1305.
The latest versions of wolfSSL have assembly optimizations and are very performant. According to the benchmarks on the wolfSSL website, woflSSL’s raw encryption performance is often on par and will in some cases even noticeably faster than OpenSSL – about 50% faster. Other information on the internet suggests that older versions of wolfSSL are noticeably slower than OpenSSL. If you are interested in performance, then I suggest that you run benchmarking on the target hardware and with the newest versions of the libraries. This is because both libraries are in constant development and newer versions may contain more optimizations.
Mbed TLS and MatrixSSL support noticeably fewer cryptographic algorithms.
WolfSSL and MatrixSSL are dual-licensed under GPL 2.0 and a commercial license. The GPL 2.0 license only allows users to use the library in GPL-compatible FOSS applications. The commercial license allows users to use the library in closed source applications.
Mbed TLS is licensed under Apache License 2.0, which allows users to use the library both in open source and closed source applications.
While the lightweight TLS libraries claim to be significantly smaller, approximately 20 times smaller than OpenSSL, they are not so small in their default configurations. Here are the sizes of the libraries, compiled for an Ubuntu 22.04 x86_64 machine:
- wolfSSL (
version 5.2.0, libwolfssl.so
): 1,768 KiB
- Mbed TLS (
version 2.28.0, libmbedtls.so + libmbedcrypto.so
): 664 KiB
- MatrixSSL (
version 4.5.1, libssl_s.a + libcrypt_s.a + libcore_s.a
): 1,772 KiB
- OpenSSL (
version 3.0.2, libssl.so + libcrypto.so
): 5,000 KiB
To cut down on the library’s size, the user of the library has to compile it themselves and disable all the modules that they do not need.
OpenSSL also has a modular design and allows you to exclude unneeded modules from the compilation. However, this is more difficult than with lightweight libraries. Some OpenSSL modules are hard to exclude because other modules have dependencies on them, even if they shouldn’t. And some OpenSSL modules are just very big, particularly the x509
module, since it contains the code for working with X.509 certificates. Thus, while it is possible to cut down the size of compiled OpenSSL, it is not possible to cut down as much as with the lightweight TLS libraries.
Use a lightweight TLS library if OpenSSL does not fit into your device. Otherwise, use a full-size TLS library, such as OpenSSL.
The last two TLS libraries that we will review originated from OpenSSL itself. Let’s find out why the pristine OpenSSL was not good enough for some.