wolfSSL SP Math All and Integer Implementations

In our last blog, the multi-precision math implementations in wolfCrypt were discussed with a feature comparison. In this blog we compare the performance of the SP Math All and Integer implementations.

The SP Math All library can be compiled with WOLFSSL_SP_SMALL (--enable-sp-math-all=small) to be small in size, with lower performance, to suit embedded applications. The code is both smaller and faster than the Integer math library.

Let’s take a look at how much faster SP Math All is than Integer. (Note: SP Math All configured with –-enable-sp-math-all=small -–disable-asm C_EXTRA_FLAGS=-DWC_NO_HARDEN, Integer configured with –-disable-fastmath.)

x64Aarch64
RSA 2048 Sign81.43%50.46%
RSA 2048 Verify993.81%522.14%
DH 2048 Key Gen48.55%1.82%
DH 2048 Agree65.16%12.71%
ECC P-256 Key Gen45.22%112.74%
ECC P-256 Agree43.74%111.60%
ECC P-256 Sign55.01%118.90%
ECC P-256 Verify62.54%127.31%

The Elliptic Curve algorithms are consistently faster across the board – about 50% on x64 and 100% on Aarch64. The RSA and DH are variable but the RSA verify operation is much faster due to the optimized exponentiation implementation in SP Math All.

Now, code size is just as important if not more so! Let’s take ARM Cortex M4 as an example.

ARM Cortex-M4 (bytes)IntegerSP Math All
+RSA +DH +ECC2362518672-20.97%
+RSA +DH -ECC2249216836-25.15%
-RSA -DH +ECC2114918232-13.79%

All builds are smaller with a saving of up to 25% and the code is faster! Similar reductions are seen across all CPUs.

In the next blog, a comparison of the performance characteristics of sp_int.c and tfm.c. If you have any commentary or feedback please reach out to our team at facts@wolfssl.com or support@wolfssl.com!