Skip to content

Commit e56719c

Browse files
committed
Add full SPDM nuvoton and spdm-emu support as wolfTPM/spdm
1 parent 25466a9 commit e56719c

40 files changed

+10818
-20
lines changed

.github/workflows/make-test-swtpm.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,24 @@ jobs:
7575
# STMicro ST33KTPM2
7676
- name: st33ktpm2 firmware
7777
wolftpm_config: --enable-st33 --enable-firmware
78+
# SPDM (emulator mode, compile + unit test)
79+
- name: spdm
80+
wolfssl_config: --enable-wolftpm --enable-ecc --enable-sha384 --enable-aesgcm --enable-hkdf --enable-sp
81+
wolftpm_config: --enable-spdm --enable-swtpm
82+
# SPDM + Nuvoton (compile-only, no hardware in CI)
83+
- name: spdm-nuvoton
84+
wolfssl_config: --enable-wolftpm --enable-ecc --enable-sha384 --enable-aesgcm --enable-hkdf --enable-sp
85+
wolftpm_config: --enable-spdm --enable-nuvoton
86+
needs_swtpm: false
87+
# SPDM dynamic memory
88+
- name: spdm-dynamic-mem
89+
wolfssl_config: --enable-wolftpm --enable-ecc --enable-sha384 --enable-aesgcm --enable-hkdf --enable-sp
90+
wolftpm_config: --enable-spdm --enable-swtpm --enable-spdm-dynamic-mem
91+
# SPDM debug
92+
- name: spdm-debug
93+
wolfssl_config: --enable-wolftpm --enable-ecc --enable-sha384 --enable-aesgcm --enable-hkdf --enable-sp
94+
wolftpm_config: --enable-spdm --enable-nuvoton --enable-debug
95+
needs_swtpm: false
7896
# Microchip
7997
- name: microchip
8098
wolftpm_config: --enable-microchip
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: SPDM Emulator Integration Test
2+
3+
on:
4+
push:
5+
branches: [ 'master', 'main', 'release/**' ]
6+
paths: [ 'spdm/**', 'src/tpm2_spdm.c', 'examples/spdm/**' ]
7+
pull_request:
8+
branches: [ '*' ]
9+
paths: [ 'spdm/**', 'src/tpm2_spdm.c', 'examples/spdm/**' ]
10+
11+
jobs:
12+
spdm-emu-test:
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
include:
17+
- os: ubuntu-22.04
18+
arch: x64
19+
- os: ubuntu-24.04
20+
arch: x64
21+
- os: ubuntu-24.04-arm
22+
arch: aarch64
23+
runs-on: ${{ matrix.os }}
24+
steps:
25+
- name: Checkout wolfTPM
26+
uses: actions/checkout@v4
27+
28+
- name: Cache wolfSSL
29+
id: cache-wolfssl
30+
uses: actions/cache@v4
31+
with:
32+
path: wolfssl
33+
key: wolfssl-spdm-${{ matrix.os }}-${{ hashFiles('.github/workflows/spdm-emu-test.yml') }}
34+
35+
- name: Build wolfSSL
36+
if: steps.cache-wolfssl.outputs.cache-hit != 'true'
37+
run: |
38+
git clone --depth 1 https://github.com/wolfSSL/wolfssl.git
39+
cd wolfssl
40+
./autogen.sh
41+
./configure --enable-wolftpm --enable-ecc --enable-sha384 --enable-aesgcm --enable-hkdf --enable-sp
42+
make -j$(nproc)
43+
44+
- name: Install wolfSSL
45+
run: |
46+
cd wolfssl
47+
sudo make install
48+
sudo ldconfig
49+
50+
- name: Cache spdm-emu
51+
id: cache-spdm-emu
52+
uses: actions/cache@v4
53+
with:
54+
path: spdm-emu/build/bin
55+
key: spdm-emu-${{ matrix.os }}-${{ hashFiles('.github/workflows/spdm-emu-test.yml') }}
56+
57+
- name: Build spdm-emu
58+
if: steps.cache-spdm-emu.outputs.cache-hit != 'true'
59+
run: |
60+
git clone --depth 1 --recursive https://github.com/DMTF/spdm-emu.git
61+
cd spdm-emu
62+
mkdir build && cd build
63+
cmake -DARCH=${{ matrix.arch }} -DTOOLCHAIN=GCC -DTARGET=Release -DCRYPTO=mbedtls ..
64+
make copy_sample_key
65+
make -j$(nproc)
66+
67+
- name: Build wolfTPM with SPDM
68+
run: |
69+
./autogen.sh
70+
./configure --enable-spdm --enable-swtpm --enable-debug
71+
make -j$(nproc)
72+
73+
- name: Run SPDM emulator tests
74+
run: |
75+
export SPDM_EMU_PATH=$PWD/spdm-emu/build/bin
76+
./examples/spdm/spdm_test.sh --emu

.gitignore

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ examples/firmware/ifx_fw_update
8787
examples/firmware/st33_fw_update
8888
examples/endorsement/get_ek_certs
8989
examples/endorsement/verify_ek_cert
90+
examples/spdm/spdm_demo
9091

9192
# Generated Cert Files
9293
certs/ca-*.pem
@@ -176,10 +177,18 @@ UpgradeLog.htm
176177
/IDE/Espressif/**/sdkconfig
177178
/IDE/Espressif/**/sdkconfig.old
178179

180+
# SPDM build artifacts
181+
spdm/wolfspdm/options.h
182+
spdm/config.h
183+
spdm/stamp-h1
184+
spdm/src/.libs/
185+
spdm/src/.deps/
186+
spdm/test/.libs/
187+
spdm/test/unit_test
188+
179189
# Firmware files
180190
examples/firmware/*.fi
181191
examples/firmware/*.BIN
182192
examples/firmware/*.DATA
183193
examples/firmware/*.MANIFEST
184194
examples/firmware/*.MANIFESTHASH
185-

Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ include tests/include.am
4646
include docs/include.am
4747
include wrapper/include.am
4848
include hal/include.am
49+
include spdm/include.am
4950
include cmake/include.am
5051
include zephyr/include.am
5152

configure.ac

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ AC_CANONICAL_HOST
2222
AC_CANONICAL_TARGET
2323
AC_CONFIG_MACRO_DIR([m4])
2424

25+
2526
AM_INIT_AUTOMAKE([1.11 -Wall -Werror -Wno-portability foreign tar-ustar subdir-objects no-define color-tests])
2627

2728
AC_ARG_PROGRAM
@@ -462,6 +463,52 @@ then
462463
AM_CFLAGS="$AM_CFLAGS -DWOLFTPM_PROVISIONING"
463464
fi
464465

466+
# SPDM Support
467+
AC_ARG_ENABLE([spdm],
468+
[AS_HELP_STRING([--enable-spdm],[Enable SPDM support (default: disabled)])],
469+
[ ENABLED_SPDM=$enableval ],
470+
[ ENABLED_SPDM=no ]
471+
)
472+
473+
AC_ARG_WITH([wolfspdm],
474+
[AS_HELP_STRING([--with-wolfspdm=PATH],[DEPRECATED: Use --enable-spdm instead.])],
475+
[AC_MSG_ERROR([--with-wolfspdm is no longer needed. Use --enable-spdm instead.])])
476+
477+
# SPDM dynamic memory (default: static/zero-malloc)
478+
AC_ARG_ENABLE([spdm-dynamic-mem],
479+
[AS_HELP_STRING([--enable-spdm-dynamic-mem],[SPDM: Use heap allocation for context (default: static)])],
480+
[ ENABLED_SPDM_DYNMEM=$enableval ],
481+
[ ENABLED_SPDM_DYNMEM=no ]
482+
)
483+
484+
if test "x$ENABLED_SPDM" = "xyes"
485+
then
486+
AC_DEFINE([WOLFTPM_SPDM], [1], [Enable SPDM support])
487+
488+
# Add spdm/ include path so all targets can find <wolfspdm/spdm.h>
489+
AM_CPPFLAGS="$AM_CPPFLAGS -I\$(srcdir)/spdm"
490+
491+
# Nuvoton SPDM support
492+
if test "x$ENABLED_NUVOTON" = "xyes"
493+
then
494+
if test "x$ENABLED_SWTPM" = "xyes"
495+
then
496+
AC_MSG_ERROR([Cannot enable both swtpm and nuvoton with SPDM. Use --enable-swtpm --enable-spdm for emulator testing, or --enable-nuvoton --enable-spdm for hardware.])
497+
fi
498+
AC_DEFINE([WOLFSPDM_NUVOTON], [1], [Enable SPDM Nuvoton TPM support])
499+
AC_MSG_NOTICE([Nuvoton SPDM vendor commands enabled])
500+
fi
501+
502+
if test "x$ENABLED_SPDM_DYNMEM" = "xyes"
503+
then
504+
AC_DEFINE([WOLFSPDM_DYNAMIC_MEMORY], [1], [SPDM: Enable dynamic memory allocation])
505+
fi
506+
507+
if test "x$ax_enable_debug" != "xno"
508+
then
509+
AC_DEFINE([WOLFSPDM_DEBUG], [1], [SPDM: Enable debug output])
510+
fi
511+
fi
465512

466513
# HARDEN FLAGS
467514
AX_HARDEN_CC_COMPILER_FLAGS
@@ -493,6 +540,7 @@ AM_CONDITIONAL([BUILD_CHECKWAITSTATE], [test "x$ENABLED_CHECKWAITSTATE" = "xyes"
493540
AM_CONDITIONAL([BUILD_AUTODETECT], [test "x$ENABLED_AUTODETECT" = "xyes"])
494541
AM_CONDITIONAL([BUILD_FIRMWARE], [test "x$ENABLED_FIRMWARE" = "xyes"])
495542
AM_CONDITIONAL([BUILD_HAL], [test "x$ENABLED_EXAMPLE_HAL" = "xyes" || test "x$ENABLED_MMIO" = "xyes"])
543+
AM_CONDITIONAL([BUILD_SPDM], [test "x$ENABLED_SPDM" = "xyes"])
496544

497545

498546
CREATE_HEX_VERSION
@@ -578,6 +626,10 @@ for option in $OPTION_FLAGS; do
578626
fi
579627
done
580628

629+
# Also capture SPDM defines from config.h (set via AC_DEFINE, not AM_CFLAGS)
630+
grep '^#define WOLFSPDM_' src/config.h >> $OPTION_FILE 2>/dev/null || true
631+
grep '^#define WOLFTPM_SPDM' src/config.h >> $OPTION_FILE 2>/dev/null || true
632+
581633
echo "" >> $OPTION_FILE
582634
echo "#ifdef __cplusplus" >> $OPTION_FILE
583635
echo "}" >> $OPTION_FILE
@@ -622,3 +674,7 @@ echo " * Nuvoton NPCT75x: $ENABLED_NUVOTON"
622674

623675
echo " * Runtime Module Detection: $ENABLED_AUTODETECT"
624676
echo " * Firmware Upgrade Support: $ENABLED_FIRMWARE"
677+
echo " * SPDM Support: $ENABLED_SPDM"
678+
if test "x$ENABLED_SPDM" = "xyes"; then
679+
echo " * SPDM Dynamic Mem: $ENABLED_SPDM_DYNMEM"
680+
fi

examples/include.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ include examples/seal/include.am
1818
include examples/attestation/include.am
1919
include examples/firmware/include.am
2020
include examples/endorsement/include.am
21+
include examples/spdm/include.am
2122

2223
if BUILD_EXAMPLES
2324
EXTRA_DIST += examples/run_examples.sh

examples/spdm/README.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# SPDM Examples
2+
3+
This directory contains examples demonstrating SPDM (Security Protocol and Data Model)
4+
functionality with wolfTPM.
5+
6+
## Overview
7+
8+
The SPDM demo (`spdm_demo`) shows how to establish an SPDM secure session between
9+
the host and a TPM using the built-in wolfSPDM library. It supports both the standard
10+
spdm-emu emulator and Nuvoton hardware TPMs.
11+
12+
For real SPDM support on hardware TPMs, contact **support@wolfssl.com**
13+
14+
## Example
15+
16+
### `spdm_demo.c` - SPDM Secure Session Demo
17+
18+
**Quick test (emulator — starts/stops automatically):**
19+
20+
```bash
21+
./examples/spdm/spdm_test.sh --emu
22+
```
23+
24+
Runs session establishment, signed measurements, unsigned measurements,
25+
challenge authentication, heartbeat, and key update.
26+
27+
**Quick test (Nuvoton hardware):**
28+
29+
```bash
30+
./examples/spdm/spdm_test.sh --nuvoton
31+
```
32+
33+
Runs connect, lock, caps-over-SPDM, unlock, and cleartext verification.
34+
35+
**Manual commands:**
36+
37+
```bash
38+
# Emulator (start spdm_responder_emu first, see spdm/README.md)
39+
./spdm_demo --emu # Session only
40+
./spdm_demo --meas # Session + signed measurements
41+
./spdm_demo --meas --no-sig # Session + unsigned measurements
42+
./spdm_demo --challenge # Sessionless challenge authentication
43+
./spdm_demo --emu --heartbeat # Session + heartbeat keep-alive
44+
./spdm_demo --emu --key-update # Session + key rotation
45+
46+
# Nuvoton hardware
47+
./spdm_demo --enable # Enable SPDM on TPM (one-time, requires reset)
48+
./spdm_demo --connect --status # Connect + get SPDM status
49+
./spdm_demo --connect --lock # Connect + lock SPDM-only mode
50+
./spdm_demo --connect --caps # Connect + run TPM commands over SPDM
51+
./spdm_demo --connect --unlock # Connect + unlock SPDM-only mode
52+
```
53+
54+
## Building
55+
56+
### Prerequisites
57+
58+
Build wolfSSL with the cryptographic algorithms required by SPDM:
59+
60+
```bash
61+
# wolfSSL (needs ECC P-384, SHA-384, AES-GCM, HKDF for SPDM)
62+
cd wolfssl
63+
./autogen.sh
64+
./configure --enable-wolftpm --enable-ecc --enable-sha384 --enable-aesgcm --enable-hkdf --enable-sp
65+
make && sudo make install && sudo ldconfig
66+
```
67+
68+
### wolfTPM with SPDM
69+
70+
SPDM support is built into wolfTPM (no external wolfSPDM needed):
71+
72+
```bash
73+
cd wolfTPM
74+
./autogen.sh
75+
./configure --enable-spdm
76+
make
77+
```
78+
79+
For Nuvoton hardware TPMs, add `--enable-nuvoton`:
80+
81+
```bash
82+
./configure --enable-spdm --enable-nuvoton
83+
make
84+
```
85+
86+
## Support
87+
88+
For production use with hardware TPMs and full SPDM protocol support, contact:
89+
90+
**support@wolfssl.com**

examples/spdm/include.am

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# vim:ft=automake
2+
# All paths should be given relative to the root
3+
4+
if BUILD_EXAMPLES
5+
if BUILD_SPDM
6+
noinst_PROGRAMS += examples/spdm/spdm_demo
7+
8+
examples_spdm_spdm_demo_SOURCES = examples/spdm/spdm_demo.c
9+
examples_spdm_spdm_demo_LDADD = src/libwolftpm.la $(LIB_STATIC_ADD)
10+
examples_spdm_spdm_demo_DEPENDENCIES = src/libwolftpm.la
11+
examples_spdm_spdm_demo_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/spdm
12+
endif
13+
endif
14+
15+
example_spdmdir = $(exampledir)/spdm
16+
dist_example_spdm_DATA = examples/spdm/spdm_demo.c
17+
18+
DISTCLEANFILES+= examples/spdm/.libs/spdm_demo

0 commit comments

Comments
 (0)