The wolfSSL C Standard Library Abstraction Layer

With the release of wolfSSL 1.8.0 we have made wolfSSL even more portable with the addition of a C Standard Library Abstraction Layer.  This means that wolfSSL may now be built without parts of the C Standard Library and user-defined functions may be used instead.

The C Standard Library consists of a set of sections of the ISO C standard which describe a collection of headers and library routines used to implement common operations such as I/O, math operations, string handling, and much more.  wolfSSL allows you to override functions in the following areas:

A. Memory Use

Most C programs use malloc() and free() for dynamic memory allocation. wolfSSL uses XMALLOC() and XFREE() instead. By default, these point to the C runtime versions. By defining XMALLOC_USER, the user can provide their own hooks. Each memory function takes two additional arguments over the standard ones, a heap hint, and an allocation type. The user is free to ignore these or use them in any way they like.  You can find the wolfSSL memory functions in types.h.

B. string.h

wolfSSL uses several functions that behave like string.h’s memcpy(), memset(), and memcmp() amongst others. They are abstracted to XMEMCPY()XMEMSET(), and XMEMCMP() respectively.  And by default, they point to the C standard library versions. Defining XSTRING_USER allows the user to provide their own hooks in types.h. For an example of this, please see the wolfSSL document wolfSSL Extensions Reference, Section XII or download the wolfSSL Manual.

C. math.h

wolfSSL uses two functions that behave like math.h’s pow() and log(). They are only required by Diffie-Hellman, so if you exclude DH from the build, then you don’t have to provide your own. They are abstracted to XPOW() and XLOG() and found in dh.c.

D. File System Use

By default, wolfSSL uses the system’s file system for the purpose of loading keys and certificates. This can be turned off by defining NO_FILESYSTEM (see the wolfSSL Extensions Reference, Section V). If instead, you’d like to use a file system but not the system one, you can use the XFILE() layer in ssl.c to point the file system calls to the ones you’d like to use.  See the example provided by the MICRIUM define.

For more information regarding the wolfSSL C Standard Library Abstraction Layer or if you have any questions or comments, please contact