SharkSSL C/C++ Reference
TLS, cryptography, certificates, and PSA integration
Build the OpenSSL compatibility adapter

Choose the smallest component set that supplies your application's APIs, then compile those adapter sources with matching definitions. Crypto and TLS also need one native SharkSSL implementation, built from compatible headers, configuration and backend objects. You do not link a separate OpenSSL library.

Choose components

Start with the example closest to your application. Its Make target or Visual Studio project lists the adapter sources and their component setting. Apply the same SHARKSSL_OSSL_COMPONENTS setting to the adapter and its callers. It controls both the available declarations and the implementation.

Component Provides Adapter dependencies
err Per-thread diagnostics None
params Typed OSSL_PARAM values None
bio Memory and custom BIOs; application buffers err
evp_gcm AES-128/256-GCM streaming err, params
evp_hash SHA-2, HMAC, HKDF, PBKDF2 and RNG wrappers err, params
pkey PEM key import and RSA/ECDSA signatures bio, evp_hash
tls TLS connections, credentials and certificate metadata bio
pem_files TLS credential and trust loading through stdio tls
dispatcher Optional SoDispCon BIO attachment bio

Algorithm availability follows the native SharkSSL configuration. Selecting a wrapper does not enable a disabled native algorithm. The default mask for a manual build is 0xFF; pkey must be selected explicitly. For a custom selection, include the dependencies shown above and use the bits in SharkSslOsslConfig.h.

Source checkout and release package

The source checkout includes the adapter, headers, guides and example C files. The prepared release includes three direct builds in compat/openssl/examples. Use make bio, make crypto or make tls on Linux. On Windows, open the corresponding Bio.vcxproj, Crypto.vcxproj or Tls.vcxproj. The example guide includes run commands. The release's ThreadX-NetX/README.md in the example directory explains how to add the client to a board project.

Compile each selected adapter C file once. Use a matching native library for an assembler backend, or add the native sources and backend objects required by your port. Keep the native target headers ahead of unrelated SDK headers. In an application that already links SharkSSL, reuse that implementation.

Select a transport

  • Memory or custom BIO: use the portable bio component. Your application moves bytes or supplies the I/O callbacks.
  • Connected POSIX/Winsock socket: enable the Boolean option SHARKSSL_OSSL_ENABLE_SOCKET=1 (default 0) and compile transport/SharkSslOsslSocket.c. See socket attachment.
  • Dispatcher attachment: select dispatcher and compile transport/SharkSslOsslBioDisp.c. A standalone release supplies the selected networking sources under transport/bas/. An SDK application reuses the dispatcher and port objects it already owns; do not link a second copy. See dispatcher lifetime and locking.

Supply platform services

For TLS and random/signature operations, initialize the native RNG before use and before starting worker threads. TLS also needs initialized, advancing UTC time for certificate checks. See RNG startup. Constructing an adapter context does not initialize either service.

The optional SHARKSSL_OSSL_PORT_HEADER macro names an application header. It may supply the following hooks and their declarations:

Hook Contract
SO_MALLOC(size_t size) Return owned storage as void*, or NULL on failure. Default: malloc.
SO_REALLOC(void* ptr, size_t size) Resize storage using realloc semantics. Default: realloc.
SO_FREE(void* ptr) Release an allocation from those hooks; return void. Default: free.
SO_ATOMIC_ADD(volatile long* ptr, long delta) Atomically add and return the resulting long value. MSVC/GCC supply defaults; other toolchains must provide it.
SHARKSSL_OSSL_ERR_STATE() Return the calling thread's live SharkSslOsslErrorState*. See error storage.

Supply all three allocation hooks together. The hook header can be included before the full error-state type is visible; declare its accessor using struct SharkSslOsslErrorState*. Unsupported atomic or error-storage ports fail compilation rather than silently sharing unsafe state.

Mutable BIO, EVP, TLS and context operations require application serialization. Keep the port definitions consistent across the selected adapter objects and callers. SharkSslOsslBioDisp.h and SharkSslOsslErrPort.h are the extension headers; SharkSslOpenSslBio.h and sharkssl_ossl_err.h remain forwarding headers.