SharkSSL C/C++ Reference
TLS, cryptography, certificates, and PSA integration
SharkSSL examples on Zephyr

Connect a Zephyr device to an HTTPS server or control an onboard LED from your browser. These examples show how to use SharkSSL for TLS connections and certificate validation while using the board's PSA Crypto services for cryptographic operations.

The supplied integration targets the NXP FRDM-RW612. SharkSSL runs in the nonsecure application and calls Trusted Firmware-M (TF-M) through the PSA (Platform Security Architecture) Crypto API. TF-M provides the cryptographic services in the secure firmware. Networking uses Ethernet, and stacks and heap use internal SRAM. No application filesystem or external PSRAM is needed.

Choose the example that matches what you want to try:

Example What you can do
CertCheck Inspect server certificates and see whether they pass certificate-chain, hostname, and date checks.
LED-SMQ Use a browser to control the board's green LED over a TLS-protected SMQ connection.

Both use the shared C examples supplied with SharkSSL. The board setup and Zephyr adapters are kept separate, giving you a starting point for your own application or another board.

Requirements

You need the FRDM-RW612 board, a USB debug connection, and an Ethernet network with DHCP, DNS, and Internet access. The examples also need access to an SNTP time server so they can check certificate validity dates.

For building, use a Linux shell with CMake, Ninja, west, and an existing NXP ZSDK nxp-v4.4.1.1 workspace, including its modules and Python environment. Use a compatible Zephyr SDK toolchain; the paths below show Zephyr SDK 1.0.0. These commands build the application using your installed dependencies.

RW612 prerequisite: the NXP workspace must include the FlexSPI receive-buffer boundary fix required by this SDK. It is a change to the external SDK and is not supplied by this SharkSSL build directory.

For board connections and debug-probe setup, see the Zephyr FRDM-RW612 board guide. Use the SDK version and board target specified here for these examples.

Build and program the board

Build an example

Run the following from the SharkSSL root directory. Adjust the first three paths to match your installed Python environment, NXP workspace, and toolchain. Set example=LED-SMQ if you want to try the browser-controlled LED.

source "$HOME/zephyrproject/.venv/bin/activate"
export ZEPHYR_BASE="$HOME/rw612-psa-ws/zephyr"
export ZEPHYR_SDK_INSTALL_DIR="$HOME/zephyr-sdk-1.0.0"
# Keep generated files inside this checkout.
mkdir -p build/zephyr/out/cache/tmp
export TMPDIR="$PWD/build/zephyr/out/cache/tmp"
export XDG_CACHE_HOME="$PWD/build/zephyr/out/cache"
export ZEPHYR_USER_CACHE_DIR="$PWD/build/zephyr/out/cache/zephyr"
export PYTHONDONTWRITEBYTECODE=1 CCACHE_DISABLE=1
# Select CertCheck or LED-SMQ. Use a separate output directory for each.
example=CertCheck
cmake -S build/zephyr -B "build/zephyr/out/frdm_rw612/$example" -GNinja \
-DBOARD=frdm_rw612/rw612/ns -DSHARKSSL_EXAMPLE="$example" \
-DCMAKE_FIND_USE_PACKAGE_REGISTRY=OFF
cmake --build "build/zephyr/out/frdm_rw612/$example" -j 8

SHARKSSL_EXAMPLE defaults to CertCheck. Each example has its own output directory. Program the resulting build/zephyr/out/frdm_rw612/<example>/zephyr/tfm_merged.hex, which combines the bootloader, TF-M secure firmware, and SharkSSL application.

The vendor development profile uses dummy boot keys. Before deploying a product, replace these through the board's production provisioning process.

Program the RW612

Connect Ethernet and the J10 debug USB port, leave JP3 open, and monitor the serial console at 115200 baud, 8 data bits, no parity, and one stop bit.

Choose the programming method that matches your debug probe's firmware. For MCU-Link running LinkServer firmware, use the installed LinkServer runner from the same shell as the build:

west flash -d "build/zephyr/out/frdm_rw612/$example" --runner linkserver

For MCU-Link running J-Link firmware, select device RW612, interface SWD, and speed 4000 kHz in J-Link Commander. Replace the image path below with your selected example's absolute path. The r0 and r1 commands reset the board through its reset pin so the complete secure boot chain runs:

r0
sleep 200
r1
connect
h
loadfile /absolute/path/to/SharkSSL/build/zephyr/out/frdm_rw612/CertCheck/zephyr/tfm_merged.hex
r0
sleep 200
r1

Use normal sector programming to retain TF-M persistent keys. Avoid a whole-chip erase when you need to keep stored keys.

Run an example

At startup, both examples initialize PSA Crypto and synchronize the clock with an SNTP time server. TLS connections start only after these steps succeed. The clock then advances locally for certificate-date checks. If startup reports No initialized UTC clock, check the Ethernet connection, DNS settings, and access to the time servers.

CertCheck: see how a server is authenticated

Watch the serial console. CertCheck connects to the servers listed in examples/CertCheck.c, prints each server's certificate chain and trust result, and sends an HTTP request only when the certificate chain, hostname, and date checks pass. It finishes without waiting for keyboard input.

This example uses TLS 1.3 with AES-GCM and RSA/ECDSA certificate verification. A server that supports only TLS 1.2 cannot connect with this example's configuration.

LED-SMQ: control the board from your browser

Once the board has connected, open the LED demo page, select SharkSSL FRDM-RW612, and toggle Green LED. Keep Ethernet connected so the board can reach the default broker at https://simplemq.com/smq.lsp.

The example uses examples/LED-SMQ.c and the SharkMQ client library in examples/SharkMQ.c. The green LED starts off. The serial console shows each requested state and GPIO readback; it also displays the device identity as SMQ ID: xx:xx:xx:xx:xx:xx. This board example provides remote LED control only; local button control and temperature reporting are disabled.

LED-SMQ uses TLS 1.2 with ECDHE-ECDSA/AES-128-GCM to connect to this demo broker. It checks the broker's certificate against the bundled RTL certificate authority (CA), verifies the hostname, and checks the certificate dates before starting SMQ communication.

The public demo lets anyone control the LED without signing in. For an application that needs access control, use a private broker with user authentication.

Adapt the integration

Find the relevant files

Paths in this guide are relative to the SharkSSL root unless stated otherwise. The source layout separates the reusable port from the board and examples:

inc/arch/Zephyr/
TargConfig.h Types, aligned allocation, mutexes, clock declaration
examples/arch/Zephyr/
selibplat.h Socket and console configuration
seZephyr.c Zephyr socket and console implementation
examples/
CertCheck.c Shared certificate example
LED-SMQ.c Shared LED application
SharkMQ.c SMQ client library
build/zephyr/
CMakeLists.txt
cmake/sharkssl.cmake Shared TLS sources and consumer configuration
common/ PSA initialization, UTC startup, shared settings
include/
example-runtime.h Startup and board-initialization declarations
boards/
frdm_rw612/
board.cmake Provider integration and board C source selection
prj.conf TF-M and Ethernet settings
led.c One-LED implementation of ledctrl.h
identity.c Stable Ethernet-MAC getUniqueId()
tfm/ Secure-provider configuration
examples/
CertCheck/ Entry point and example configuration
LED-SMQ/ Entry point and example configuration
out/<board>/<example>/ Generated build output

To add a board, create build/zephyr/boards/<board>/ with its configuration, PSA provider include paths, and required C sources. The top-level build/zephyr/CMakeLists.txt selects the board folder from the first component of BOARD, such as frdm_rw612 in frdm_rw612/rw612/ns.

To add an example, create its entry point, example.cmake, and prj.conf under build/zephyr/examples/<example>/, then extend the supported-example list in build/zephyr/CMakeLists.txt. Keep portable application code in the root examples/ directory and hardware-specific code in the board directory. Use a fresh output directory when changing board qualifiers or PSA providers.

Keep reusable Zephyr platform code in inc/arch/Zephyr/ and socket and console adapters in examples/arch/Zephyr/. Shared example startup belongs in build/zephyr/common/.

Keep the PSA and Zephyr settings consistent

build/zephyr/cmake/sharkssl.cmake selects the PSA consumer adapters and puts the provider's headers before SharkSSL's headers. This build uses TF-M as its crypto provider. Do not also compile native src/SharkSslCrypto.c, assembly backends, or SharkSSL's own src/psa provider into this target. For the shared integration rules, see the PSA consumer guide.

The supplied configuration disables ChaCha20, Poly1305, and Brainpool curves to match this provider profile. Review the algorithm selection when changing providers.

inc/arch/Zephyr/TargConfig.h supplies aligned allocation and Zephyr mutexes. examples/arch/Zephyr/seZephyr.c provides socket I/O with bounded connection and send waits. CMake selects both Zephyr port include directories and compiles seZephyr.c for both examples. Keep these configuration settings:

Setting Why it is needed
CONFIG_NET_CONTEXT_SNDTIMEO=y Enables socket send timeouts.
CONFIG_LOG_PRINTK=n Keeps CertCheck's character-by-character output out of the deferred log queue so certificate output is complete.
CONFIG_ARM_NONSECURE_PREEMPTIBLE_SECURE_CALLS=n On RW612, prevents thread switches during TF-M secure calls while leaving interrupts enabled.

The TF-M configuration in build/zephyr/boards/frdm_rw612/tfm/config.h uses the vendor large profile with 64 concurrent crypto operations and 64 key slots. It also enables HKDF Extract/Expand and PBKDF2-HMAC.

Preserve the board's LED and device identity

The LED adapter in build/zephyr/boards/frdm_rw612/led.c exposes one green LED, ID 1, using the board's led0 alias (HSGPIO0 pin 12, active low). Status messages go to the console so they do not interfere with remote LED control.

The getUniqueId() implementation in build/zephyr/boards/frdm_rw612/identity.c returns a validated, retained copy of the six binary bytes of the Ethernet MAC address. By default, this address comes from the chip's one-time-programmed hardware ID and stays the same across boots. Random MAC configuration is rejected at build time. If you provision MAC addresses yourself, give each board a distinct address. SMQ's broker-assigned routing ID is separate from this device identity.