Skip to content

Commit 1ab33b8

Browse files
committed
Zephyr: wolfSSL module support for the wolfPSA provider and native RTOS use
Extend the wolfSSL Zephyr module for the wolfPSA-provider and secure-sockets efforts: - Native RTOS threading: wolfCrypt's Zephyr port uses k_mutex/k_thread/ k_condvar directly (no CONFIG_POSIX_THREADS), with k_condvar gated on the kernel version, covered by a native-threading ztest wired into CI. - Config interface: a user-supplied CONFIG_WOLFSSL_SETTINGS_FILE is authoritative and the module never layers Kconfig #defines over it. The module-default block is shaped by build-profile knobs (WOLFSSL_CRYPTO_ONLY, WOLFSSL_SINGLE_THREADED, which now defaults from !MULTITHREADING) plus new classic-crypto/TLS/PQC feature knobs (RSA/ECC/ChaCha-Poly/Curve25519/SNI/ session-cache/session-ticket and ML-KEM/ML-DSA/LMS/XMSS/Falcon, each with its memory-reduction "small" options). A consumer such as wolfPSA validates its own requirements rather than the module injecting them. - DRBG seeding: wc_GenerateSeed() on Zephyr draws seed material from the hardware entropy driver when present (chunked to the entropy API's uint16_t length, DT_HAS_CHOSEN-guarded) and falls back to sys_rand_get() otherwise; HAVE_HASHDRBG stays guarded by WC_NO_HASHDRBG. - z_time(): read the native_sim simulator RTC for a real wall clock on the native targets regardless of libc. Verified on native_sim/native/64 and nucleo_h743zi.
1 parent 8e26bce commit 1ab33b8

16 files changed

Lines changed: 640 additions & 65 deletions

File tree

.github/scripts/zephyr-4.x/zephyr-test.sh

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
# -b, --branch <branch> wolfSSL branch/revision
1111
# -z, --zephyr <version> Zephyr version tag
1212
# -t, --target <board> Board target
13-
# -s, --sample <name> Sample to build
13+
# -s, --sample <name> Sample/test app to build
14+
# -d, --subdir <dir> App subdir under zephyr/ (samples or tests; default samples)
1415
# -v, --verbose Verbose compile output (show full compiler commands)
1516
# -W, --werror Build with -Werror (treat warnings as errors)
1617
# --commit <sha> Checkout specific commit after fetching branch
@@ -49,6 +50,7 @@ WOLFSSL_BRANCH="master"
4950
ZEPHYR_VERSION="v4.1.0"
5051
BOARD_TARGET="native_sim"
5152
SAMPLE_NAME="wolfssl_tls_sock"
53+
SUBDIR="samples"
5254
INTERACTIVE=0
5355
VERBOSE=0
5456
WERROR=0
@@ -92,6 +94,7 @@ while [[ $# -gt 0 ]]; do
9294
-z|--zephyr) ZEPHYR_VERSION="$2"; shift 2 ;;
9395
-t|--target) BOARD_TARGET="$2"; shift 2 ;;
9496
-s|--sample) SAMPLE_NAME="$2"; shift 2 ;;
97+
-d|--subdir) SUBDIR="$2"; shift 2 ;;
9598
-v|--verbose) VERBOSE=1; shift ;;
9699
-W|--werror) WERROR=1; shift ;;
97100
--commit) WOLFSSL_COMMIT="$2"; shift 2 ;;
@@ -123,7 +126,7 @@ echo "==> wolfSSL repo: ${WOLFSSL_REPO}"
123126
echo "==> wolfSSL branch: ${WOLFSSL_BRANCH}"
124127
echo "==> Zephyr version: ${ZEPHYR_VERSION}"
125128
echo "==> Board target: ${BOARD_TARGET}"
126-
echo "==> Sample: ${SAMPLE_NAME}"
129+
echo "==> Sample: ${SUBDIR}/${SAMPLE_NAME}"
127130
echo "==> Docker image: ${DOCKER_IMAGE}"
128131
[[ -n "$WOLFSSL_COMMIT" ]] && echo "==> Commit: ${WOLFSSL_COMMIT}"
129132
[[ "$WERROR" == "1" ]] && echo "==> Werror: enabled"
@@ -144,6 +147,7 @@ set -euo pipefail
144147
ZEPHYR_VERSION="__ZEPHYR_VERSION__"
145148
BOARD_TARGET="__BOARD_TARGET__"
146149
SAMPLE_NAME="__SAMPLE_NAME__"
150+
SUBDIR="__SUBDIR__"
147151
WOLFSSL_REPO="__WOLFSSL_REPO__"
148152
WOLFSSL_BRANCH="__WOLFSSL_BRANCH__"
149153
WOLFSSL_COMMIT="__WOLFSSL_COMMIT__"
@@ -224,11 +228,11 @@ if [[ "$INTERACTIVE" == "1" ]]; then
224228
echo " wolfSSL: modules/crypto/wolfssl"
225229
echo ""
226230
echo " Example build commands:"
227-
echo " west build -p always -b ${BOARD_TARGET} modules/crypto/wolfssl/zephyr/samples/${SAMPLE_NAME}"
231+
echo " west build -p always -b ${BOARD_TARGET} modules/crypto/wolfssl/zephyr/${SUBDIR}/${SAMPLE_NAME}"
228232
echo " west build -t run"
229233
echo ""
230234
echo " To run twister tests:"
231-
echo " ./zephyr/scripts/twister -T modules/crypto/wolfssl/zephyr/samples/${SAMPLE_NAME} -vvv"
235+
echo " ./zephyr/scripts/twister -T modules/crypto/wolfssl/zephyr/${SUBDIR}/${SAMPLE_NAME} -vvv"
232236
echo "=========================================="
233237
echo ""
234238
exec /bin/bash
@@ -256,7 +260,7 @@ else
256260
fi
257261
258262
west build -p always -b "${BOARD_TARGET}" \
259-
"modules/crypto/wolfssl/zephyr/samples/${SAMPLE_NAME}" \
263+
"modules/crypto/wolfssl/zephyr/${SUBDIR}/${SAMPLE_NAME}" \
260264
${CMAKE_ARGS:+-- $CMAKE_ARGS}
261265
262266
echo ""
@@ -300,7 +304,7 @@ else
300304
exit 1
301305
fi
302306
# Check for success strings
303-
if grep -q "Benchmark complete\|Test complete\|Client Return: 0" "${RUN_LOG}" 2>/dev/null; then
307+
if grep -q "Benchmark complete\|Test complete\|Client Return: 0\|PROJECT EXECUTION SUCCESSFUL" "${RUN_LOG}" 2>/dev/null; then
304308
echo "==> [container] App completed successfully!"
305309
APP_RC=0
306310
kill "${RUN_PID}" 2>/dev/null || true
@@ -315,7 +319,7 @@ else
315319
316320
if [[ $APP_RC -ne 0 ]]; then
317321
# Process exited on its own - check if it printed a success string
318-
if grep -q "Benchmark complete\|Test complete\|Client Return: 0" "${RUN_LOG}" 2>/dev/null; then
322+
if grep -q "Benchmark complete\|Test complete\|Client Return: 0\|PROJECT EXECUTION SUCCESSFUL" "${RUN_LOG}" 2>/dev/null; then
319323
APP_RC=0
320324
else
321325
echo "==> [container] App exited without a success string"
@@ -336,6 +340,7 @@ INNER_SCRIPT
336340
BUILD_SCRIPT="${BUILD_SCRIPT//__ZEPHYR_VERSION__/$ZEPHYR_VERSION}"
337341
BUILD_SCRIPT="${BUILD_SCRIPT//__BOARD_TARGET__/$BOARD_TARGET}"
338342
BUILD_SCRIPT="${BUILD_SCRIPT//__SAMPLE_NAME__/$SAMPLE_NAME}"
343+
BUILD_SCRIPT="${BUILD_SCRIPT//__SUBDIR__/$SUBDIR}"
339344
BUILD_SCRIPT="${BUILD_SCRIPT//__WOLFSSL_REPO__/$WOLFSSL_REPO}"
340345
BUILD_SCRIPT="${BUILD_SCRIPT//__WOLFSSL_BRANCH__/$WOLFSSL_BRANCH}"
341346
BUILD_SCRIPT="${BUILD_SCRIPT//__WOLFSSL_COMMIT__/$WOLFSSL_COMMIT}"

.github/workflows/zephyr-4.x.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,69 @@ jobs:
103103
.github/scripts/zephyr-4.x/artifacts/${{ matrix.board == 'native_sim' && 'native_sim' || 'frdm_rw612-rw612' }}-wolfssl_test/zephyr.map
104104
if-no-files-found: warn
105105
retention-days: 1
106+
107+
# Native k_mutex/k_thread/k_condvar threading ztest (no POSIX). native_sim
108+
# only - it reads the native_sim simulator RTC - so it lives on this 4.x
109+
# matrix rather than the legacy zephyr.yml (v2.7.4/v3.4.0/v3.5.0), where
110+
# native_sim is unavailable or its POSIX headers clash with ztest.
111+
condvar:
112+
name: ${{ matrix.zephyr-ref }} | native_sim | wolfssl_condvar${{ matrix.crypto-only == 'y' && ' | crypto-only' || '' }}
113+
if: ${{ (github.repository_owner == 'wolfssl') && (github.event_name != 'pull_request' || github.event.pull_request.draft == false) }}
114+
runs-on: ubuntu-22.04
115+
timeout-minutes: 60
116+
strategy:
117+
fail-fast: false
118+
matrix:
119+
zephyr-ref: [ v4.1.0, v4.3.0, v4.4.0 ]
120+
# Both build profiles the testcase.yaml exercises: default (TLS + crypto)
121+
# and the WOLFCRYPT_ONLY build-profile knob.
122+
crypto-only: [ 'n', 'y' ]
123+
steps:
124+
- name: Checkout test driver
125+
uses: actions/checkout@v5
126+
with:
127+
sparse-checkout: .github/scripts/zephyr-4.x
128+
fetch-depth: 1
129+
130+
- name: Free disk space
131+
run: |
132+
sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc \
133+
/opt/hostedtoolcache/CodeQL "$AGENT_TOOLSDIRECTORY" || true
134+
docker system prune -af || true
135+
df -h /
136+
137+
- name: Resolve wolfSSL repo and branch
138+
id: src
139+
run: |
140+
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
141+
echo "repo=https://github.com/${{ github.repository }}" >> "$GITHUB_OUTPUT"
142+
echo "branch=refs/pull/${{ github.event.pull_request.number }}/merge" >> "$GITHUB_OUTPUT"
143+
else
144+
echo "repo=https://github.com/${{ github.repository }}" >> "$GITHUB_OUTPUT"
145+
echo "branch=${{ github.ref_name }}" >> "$GITHUB_OUTPUT"
146+
fi
147+
148+
- name: Build and run condvar ztest
149+
working-directory: .github/scripts/zephyr-4.x
150+
run: |
151+
CRYPTO_ONLY_ARG=""
152+
if [[ "${{ matrix.crypto-only }}" == "y" ]]; then
153+
CRYPTO_ONLY_ARG="--cmake-args -DCONFIG_WOLFSSL_CRYPTO_ONLY=y"
154+
fi
155+
bash ./zephyr-test.sh \
156+
-r "${{ steps.src.outputs.repo }}" \
157+
-b "${{ steps.src.outputs.branch }}" \
158+
-z "${{ matrix.zephyr-ref }}" \
159+
-t native_sim \
160+
-d tests \
161+
-s wolfssl_condvar \
162+
$CRYPTO_ONLY_ARG
163+
164+
- name: Upload logs on failure
165+
if: failure()
166+
uses: actions/upload-artifact@v6
167+
with:
168+
name: zephyr-4.x-condvar-${{ matrix.zephyr-ref }}-${{ matrix.crypto-only }}-${{ strategy.job-index }}
169+
path: .github/scripts/zephyr-4.x/logs/
170+
retention-days: 5
171+
if-no-files-found: ignore

.github/workflows/zephyr.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,13 @@ jobs:
9292
- name: Run wolfssl test
9393
id: wolfssl-test
9494
working-directory: zephyr
95+
# Scope -T to the sample directory (not the whole module) so twister does
96+
# not load zephyr/tests/*/testcase.yaml. The condvar test's modern
97+
# list-form platform_allow is rejected by the 2.7.4 twister schema, and
98+
# this is the only sample step that runs on 2.7.4. Runs both scenarios
99+
# (wolfssl_test and wolfssl_test_no_malloc).
95100
run: |
96-
./zephyr/scripts/twister -T modules/crypto/wolfssl --test zephyr/samples/wolfssl_test/sample.crypto.wolfssl_test -vvv
97-
rm -rf zephyr/twister-out
98-
./zephyr/scripts/twister -T modules/crypto/wolfssl --test zephyr/samples/wolfssl_test/sample.crypto.wolfssl_test_no_malloc -vvv
101+
./zephyr/scripts/twister -T modules/crypto/wolfssl/zephyr/samples/wolfssl_test -vvv
99102
rm -rf zephyr/twister-out
100103
101104
- name: Run wolfssl TLS sock test

.wolfssl_known_macro_extras

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ CONFIG_CRYPTO_SHA3
9595
CONFIG_CRYPTO_SHA512
9696
CONFIG_CRYPTO_XTS
9797
CONFIG_CSPRNG_ENABLED
98+
CONFIG_ENTROPY_HAS_DRIVER
9899
CONFIG_ESP32C2_DEFAULT_CPU_FREQ_MHZ
99100
CONFIG_ESP32C3_DEFAULT_CPU_FREQ_MHZ
100101
CONFIG_ESP32H2_DEFAULT_CPU_FREQ_MHZ
@@ -154,6 +155,7 @@ CONFIG_POSIX_THREADS
154155
CONFIG_PREEMPT_COUNT
155156
CONFIG_PREEMPT_RT
156157
CONFIG_PTHREAD_IPC
158+
CONFIG_RTC
157159
CONFIG_SCHED_INFO
158160
CONFIG_SMP
159161
CONFIG_SNTP_TIME_SYNC_METHOD_SMOOTH
@@ -166,6 +168,11 @@ CONFIG_USE_WOLFSSL_ESP_SDK_TIME
166168
CONFIG_USE_WOLFSSL_ESP_SDK_WIFI
167169
CONFIG_WOLFCRYPT_ARMASM
168170
CONFIG_WOLFCRYPT_FIPS
171+
CONFIG_WOLFCRYPT_FIPS_READY
172+
CONFIG_WOLFCRYPT_FIPS_V2
173+
CONFIG_WOLFCRYPT_FIPS_V5
174+
CONFIG_WOLFCRYPT_FIPS_V6
175+
CONFIG_WOLFCRYPT_FIPS_V7
169176
CONFIG_WOLFCRYPT_INTELASM
170177
CONFIG_WOLFSSL
171178
CONFIG_WOLFSSL_ALLOW_TLS13
@@ -176,7 +183,11 @@ CONFIG_WOLFSSL_APPLE_HOMEKIT
176183
CONFIG_WOLFSSL_ASN_ALLOW_0_SERIAL
177184
CONFIG_WOLFSSL_CERTIFICATE_BUNDLE
178185
CONFIG_WOLFSSL_CERTIFICATE_BUNDLE_DEFAULT_NONE
186+
CONFIG_WOLFSSL_CHACHA_POLY
187+
CONFIG_WOLFSSL_CRYPTO_ONLY
188+
CONFIG_WOLFSSL_CURVE25519
179189
CONFIG_WOLFSSL_DTLS
190+
CONFIG_WOLFSSL_ECC
180191
CONFIG_WOLFSSL_ENABLE_KYBER
181192
CONFIG_WOLFSSL_EXAMPLE_NAME_ESP32_SSH_SERVER
182193
CONFIG_WOLFSSL_EXAMPLE_NAME_ESP8266_SSH_SERVER
@@ -188,20 +199,30 @@ CONFIG_WOLFSSL_EXAMPLE_NAME_WOLFMQTT_AWS_IOT_MQTT
188199
CONFIG_WOLFSSL_EXAMPLE_NAME_WOLFMQTT_TEMPLATE
189200
CONFIG_WOLFSSL_EXAMPLE_NAME_WOLFSSH_ECHOSERVER
190201
CONFIG_WOLFSSL_EXAMPLE_NAME_WOLFSSH_TEMPLATE
202+
CONFIG_WOLFSSL_FALCON
191203
CONFIG_WOLFSSL_HKDF
192204
CONFIG_WOLFSSL_KEEP_PEER_CERT
205+
CONFIG_WOLFSSL_LMS
193206
CONFIG_WOLFSSL_MAX_FRAGMENT_LEN
207+
CONFIG_WOLFSSL_MLDSA
194208
CONFIG_WOLFSSL_MLKEM
195209
CONFIG_WOLFSSL_NO_ASN_STRICT
196210
CONFIG_WOLFSSL_OPENSSL_EXTRA_X509_SMALL
197211
CONFIG_WOLFSSL_PSK
212+
CONFIG_WOLFSSL_RSA
198213
CONFIG_WOLFSSL_RSA_PSS
214+
CONFIG_WOLFSSL_SESSION_CACHE
199215
CONFIG_WOLFSSL_SESSION_EXPORT
216+
CONFIG_WOLFSSL_SESSION_TICKET
217+
CONFIG_WOLFSSL_SETTINGS_FILE
218+
CONFIG_WOLFSSL_SINGLE_THREADED
219+
CONFIG_WOLFSSL_SNI
200220
CONFIG_WOLFSSL_TARGET_HOST
201221
CONFIG_WOLFSSL_TARGET_PORT
202222
CONFIG_WOLFSSL_TLS13_ENABLED
203223
CONFIG_WOLFSSL_TLS_VERSION_1_2
204224
CONFIG_WOLFSSL_TLS_VERSION_1_3
225+
CONFIG_WOLFSSL_XMSS
205226
CONFIG_WOLFTPM
206227
CONFIG_WOLFTPM_EXAMPLE_NAME_ESPRESSIF
207228
CONFIG_X86
@@ -839,15 +860,8 @@ WOLFSSL_EVP_PRINT
839860
WOLFSSL_EXPORT_INT
840861
WOLFSSL_EXPORT_SPC_SZ
841862
WOLFSSL_EXTRA
842-
WOLFSSL_FALCON_FFT_AVX2
843-
WOLFSSL_FALCON_FFT_NEON
844-
WOLFSSL_FALCON_FPR_ASM
845-
WOLFSSL_FALCON_FPR_DOUBLE
846863
WOLFSSL_FALCON_NO_NTT_DSP
847-
WOLFSSL_FALCON_NTT_DSP
848-
WOLFSSL_FALCON_SIGN_SMALL_MEM
849864
WOLFSSL_FALCON_SIGN_STATS
850-
WOLFSSL_FALCON_VERIFY_ONLY
851865
WOLFSSL_FORCE_OCSP_NONCE_CHECK
852866
WOLFSSL_FRDM_K64
853867
WOLFSSL_FRDM_K64_JENKINS

wolfcrypt/src/random.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5322,10 +5322,53 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
53225322
#include <posix/time.h>
53235323
#endif
53245324

5325+
#if defined(CONFIG_ENTROPY_HAS_DRIVER) && DT_HAS_CHOSEN(zephyr_entropy)
5326+
/* Match the zephyr/-prefixed include layout used above: it did not
5327+
* exist before Zephyr 3.1. */
5328+
#if KERNEL_VERSION_NUMBER >= 0x30100
5329+
#include <zephyr/device.h>
5330+
#include <zephyr/drivers/entropy.h>
5331+
#else
5332+
#include <device.h>
5333+
#include <drivers/entropy.h>
5334+
#endif
5335+
#endif
5336+
53255337
int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
53265338
{
5339+
/* Seed the DRBG straight from the hardware entropy driver when the platform
5340+
* exposes one (a zephyr,entropy chosen node), so wolfCrypt gets
5341+
* cryptographic-quality seed material instead of the general-purpose
5342+
* sys_rand_get(). A dead source returns an error, which makes wc_InitRng()
5343+
* fail (RNG_FAILURE_E) rather than yield weak output. Boards that set
5344+
* CONFIG_ENTROPY_HAS_DRIVER without a chosen entropy node fall back to
5345+
* sys_rand_get() rather than failing the build. */
5346+
#if defined(CONFIG_ENTROPY_HAS_DRIVER) && DT_HAS_CHOSEN(zephyr_entropy)
5347+
const struct device *dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_entropy));
5348+
word32 off = 0;
5349+
word32 rem;
5350+
uint16_t chunk;
5351+
5352+
(void)os;
5353+
if (!device_is_ready(dev)) {
5354+
return RNG_FAILURE_E;
5355+
}
5356+
/* entropy_get_entropy() takes a uint16_t length; chunk the request so
5357+
* any word32 seed size is honored without silent truncation. */
5358+
while (off < sz) {
5359+
rem = sz - off;
5360+
chunk = (rem > 0xFFFFU) ? (uint16_t)0xFFFFU : (uint16_t)rem;
5361+
if (entropy_get_entropy(dev, (uint8_t *)output + off, chunk) != 0) {
5362+
return RNG_FAILURE_E;
5363+
}
5364+
off += chunk;
5365+
}
5366+
return 0;
5367+
#else
5368+
(void)os;
53275369
sys_rand_get(output, sz);
53285370
return 0;
5371+
#endif
53295372
}
53305373

53315374
#elif defined(WOLFSSL_TELIT_M2MB)

0 commit comments

Comments
 (0)