Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
7d6409a
F-15487 - Mark the requester connected after FINISH
aidangarske Nov 23, 2026
780ec90
F-14777 - Retire handshake secrets when no longer needed
aidangarske Nov 23, 2026
8e23e48
F-14790 - Restore the transcript on failed key exchange
aidangarske Nov 23, 2026
39b9dc7
F-14791 - Restore the transcript on failed FINISH
aidangarske Nov 23, 2026
0203d0e
F-14792 - Reset the connection before negotiating VERSION
aidangarske Nov 23, 2026
83dfcac
F-14795 - Preserve the peer error from encrypted FINISH replies
aidangarske Nov 23, 2026
3ad2fd2
F-15489 - Preserve the peer error from encrypted PSK_FINISH replies
aidangarske Nov 23, 2026
8f83a30
F-15491 - Preserve the peer error through END_SESSION teardown
aidangarske Nov 23, 2026
7277eaf
F-15490 - Preserve peer errors in TCG negotiation and vendor replies
aidangarske Nov 23, 2026
eb513ff
F-15494 - Recognize clear peer errors during PSK_FINISH
aidangarske Nov 23, 2026
51f58f2
F-14812 - Wipe measurement records when resetting a session
aidangarske Nov 23, 2026
fb3d24b
F-15493 - Keep certificate retrieval outside active sessions
aidangarske Nov 23, 2026
a4811de
F-15597 - Retire provisional keys when a PSK connection fails
aidangarske Nov 23, 2026
5cdccbb
F-15517 - Retire PSK-derived secrets after a rejected exchange
aidangarske Nov 23, 2026
813fd3f
F-18793 - Keep computed PSK verification data out of debug logs
aidangarske Nov 23, 2026
f9a3886
F-15512 - Correct the documented PSK connection sequence
aidangarske Nov 23, 2026
c0dcf1a
F-17861 - Clarify when the requester PSK must be set again
aidangarske Nov 23, 2026
0bc50d4
F-15513 - Document the versioned BinConcat prefix
aidangarske Nov 23, 2026
16c214b
F-17862 - Document ML-KEM verification during key exchange
aidangarske Nov 23, 2026
40132e6
F-17863 - Clarify running attestation hash states
aidangarske Nov 23, 2026
8e86e04
F-15594 - Wipe the handshake root when key expansion fails
aidangarske Nov 23, 2026
e8a04d3
F-15596 - Clear provisional keys when a TCG connection fails
aidangarske Nov 23, 2026
6968f2d
F-14809 - Clear provisional keys when standard FINISH fails
aidangarske Nov 23, 2026
2ed7fd8
F-17870 - Retire the session if an acknowledged key update fails
aidangarske Nov 23, 2026
23f2e10
F-17875 - Guard the capacity of pinned responder keys
aidangarske Nov 23, 2026
89b8560
F-14810 - Clear per-record IVs after AES-GCM
aidangarske Nov 23, 2026
c29e818
F-14811 - Wipe the decrypted measurement response
aidangarske Nov 23, 2026
a665920
F-15488 - Commit responder sessions after FINISH succeeds
aidangarske Nov 23, 2026
4785a9a
F-17895 - Require an explicit responder pin for TCG handshakes
aidangarske Nov 23, 2026
da173aa
F-17896 - Clear AES state after freeing secured-record contexts
aidangarske Nov 23, 2026
d4188ae
F-15549 - Validate CHALLENGE measurement summary requests
aidangarske Nov 23, 2026
6d29865
F-15495 - Validate responder control headers before state changes
aidangarske Nov 23, 2026
6a880f1
F-17871 - Require an exact TCG secured record length
aidangarske Nov 23, 2026
8f41769
F-15568 - Check TCG clear frame capacity before adding lengths
aidangarske Nov 23, 2026
0a4f158
F-15555 - Ignore reserved OtherParamsSelection bits
aidangarske Nov 23, 2026
c51600f
F-17897 - Wipe HMAC state on verification data errors
aidangarske Nov 23, 2026
bc93c9f
F-15553 - Reject nested MCTP secured messages
aidangarske Nov 23, 2026
145d2fd
F-17853 - Use the request version for pre-negotiation vendor replies
aidangarske Nov 23, 2026
ff24012
F-15557 - Zero unused requester context in attestation messages
aidangarske Nov 23, 2026
7edc109
F-18792 - Wipe local SHA-384 state after hashing
aidangarske Nov 23, 2026
7feba1f
F-15593 - Retire responder sessions after accepted END SESSION
aidangarske Nov 23, 2026
c21d169
F-17864 - Name the TCG opaque data format support field
aidangarske Nov 23, 2026
7576b0d
F-18803 - Omit unsupported requester signing from negotiation
aidangarske Nov 23, 2026
6434494
F-15556 - Ignore reserved END_SESSION_ACK parameters
aidangarske Nov 23, 2026
c393a60
F-18777 - Document the supported SPDM protocol modes
aidangarske Nov 23, 2026
d075533
F-15592 - Retire responder PSK sessions when clearing the credential
aidangarske Nov 23, 2026
a9f4612
F-15554 - Limit the legacy VERSION count layout to TCG
aidangarske Nov 23, 2026
1fd4b24
F-17854 - Roll back the responder transcript on clear exchange failure
aidangarske Nov 23, 2026
79a51e8
F-18775 - Limit signature negotiation to the configured pin
aidangarske Nov 23, 2026
a4073dc
F-18774 - Keep rejected clear commands out of the responder transcript
aidangarske Nov 23, 2026
dbfb8da
F-17865 - Match the PSK exchange response minimum to its fields
aidangarske Nov 23, 2026
65de24c
F-18817 - Validate the responder secured request version
aidangarske Nov 23, 2026
cd53179
F-15497 - Report Nations SPDM-only pending disable
aidangarske Nov 23, 2026
dac7520
F-18805 - Size the VERSION reply buffer for the minimum transfer
aidangarske Nov 23, 2026
ec55083
F-17852 - Keep one certificate hash in the handshake transcript
aidangarske Nov 23, 2026
c059335
F-15496 - Validate TCG vendor command acknowledgments
aidangarske Nov 23, 2026
7bd0104
F-15537 - Enforce certificate validity and usage in chain validation
aidangarske Nov 23, 2026
ec7efa8
F-15547 - Carry SPDM 1.4 OpaqueDataLength in PSK_FINISH messages
aidangarske Nov 23, 2026
13ddec5
F-15548 - Skip PSK_FINISH when the responder returns no context
aidangarske Nov 23, 2026
9992560
F-15567 - Clear the negotiated version on responder reset
aidangarske Nov 23, 2026
fbe5ccf
F-15570 - Require the KEY_EXCHANGE opaque data length field
aidangarske Nov 23, 2026
303bc72
F-18823 - Clear responder handshake state when an exchange fails
aidangarske Nov 23, 2026
04eb6ef
F-14808 - Reject responses that do not carry the negotiated SPDM version
aidangarske Nov 23, 2026
0198b4a
F-15538 - Replace the cached FIPS indicator on every TCG exchange
aidangarske Nov 23, 2026
006cf34
F-15551 - Require a retrieved chain before KEY_EXCHANGE names a slot …
aidangarske Nov 23, 2026
0714593
F-18802 - End the session when the peer reports DecryptError in a sec…
aidangarske Nov 23, 2026
7ed143a
F-18773 - Detect cleartext ERROR replies on every secured exchange
aidangarske Nov 23, 2026
3c8761b
F-17855 - End an open measurement run whenever an SPDM request is sealed
aidangarske Nov 23, 2026
1b100d5
F-15569 - Refuse secured records too long for the 16-bit Length field
aidangarske Nov 23, 2026
7ac5e17
F-15550 - Track full MCTP sequence numbers across 16-bit rollover
aidangarske Nov 23, 2026
439a44e
F-15518 - Require ECC timing resistance for builds that sign with ide…
aidangarske Nov 23, 2026
98fbb50
F-15552 - End the session when KEY_UPDATE VerifyNewKey fails
aidangarske Nov 23, 2026
f2ec190
Clear the cppcheck and scan-build findings raised by the Ubuntu 26.04…
aidangarske Nov 23, 2026
f431f9e
Pin the multi-compiler workflow to Ubuntu 24.04
aidangarske Nov 23, 2026
9739b45
Share response checks and session teardown across message handlers
aidangarske Dec 3, 2026
3b20381
Explain why every certificate in the chain parses as CA_TYPE
aidangarske Dec 3, 2026
64ae4c4
Add WOLFSPDM_NO_CERT_DATE_CHECK to skip certificate date checks
aidangarske Dec 3, 2026
c553b92
Bound TCG clear frames by the largest SPDM message
aidangarske Dec 3, 2026
2eb6858
Document the timing resistance requirement for signing builds
aidangarske Dec 3, 2026
5df40ae
Declare the KEY_UPDATE reject flag only in key update test builds
aidangarske Dec 3, 2026
f91b10e
Compare certificate exchange counts as word32 in the portion test
aidangarske Dec 3, 2026
7a28bec
Clear failed exchange keys and handle SPDM peer errors and CA rollover
aidangarske Dec 3, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ jobs:
- variant: tcg-pure
configure: '--enable-nuvoton --enable-nations --enable-responder --disable-mctp'
forbid: std
- variant: tpm-profile
configure: '--disable-mctp --enable-tcg --enable-psk --enable-nuvoton --enable-nations CFLAGS=-DWOLFSPDM_PROFILE_TPM'
forbid: std
- variant: no-session-ext
configure: '--disable-heartbeat --disable-key-update'
forbid: tpm
Expand All @@ -115,6 +118,9 @@ jobs:
- variant: no-app-data
configure: '--disable-app-data'
forbid: tpm
- variant: no-cert-date
configure: 'CFLAGS=-DWOLFSPDM_NO_CERT_DATE_CHECK'
forbid: tpm
- variant: lean
configure: '--disable-cert --disable-heartbeat --disable-key-update --disable-app-data'
forbid: tpm
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/multi-compiler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ concurrency:
jobs:
compiler_test:
name: ${{ matrix.cc }}
runs-on: ubuntu-latest
# 26.04 dropped the older gcc and clang packages this matrix installs
runs-on: ubuntu-24.04
timeout-minutes: 10
strategy:
fail-fast: false
Expand All @@ -41,7 +42,7 @@ jobs:
uses: actions/cache@v4
with:
path: ~/wolfssl-install
key: wolfssl-ubuntu-latest-v1
key: wolfssl-ubuntu-24.04-v1

- name: Build wolfSSL
if: steps.cache-wolfssl.outputs.cache-hit != 'true'
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ sudo ldconfig

`--enable-sp` enables Single Precision math with optimized ECC P-384, required for SPDM Algorithm Set B on ARM64 and other constrained targets. `--enable-all` works as a superset.

The responder and TCG builds sign with long-term identity keys, so they also require wolfSSL's default `--enable-harden` (`ECC_TIMING_RESISTANT`). Configure and the build reject a wolfSSL built with `--disable-harden`.

For post-quantum support, build wolfSSL with `--enable-mldsa` (FIPS 204) and/or `--enable-mlkem` (FIPS 203). Use wolfSSL master or a release carrying the `wc_MlDsaKey` and `wc_MlKemKey` APIs. wolfSPDM auto-enables each when the linked wolfSSL provides it (`--disable-mldsa` / `--disable-mlkem` force them off); enabling both gives a fully post-quantum handshake (ML-KEM key exchange + ML-DSA authentication).

## Build
Expand Down
15 changes: 15 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,21 @@ if test "x$enable_responder" = "xyes"; then
AC_DEFINE([WOLFSPDM_RESPONDER], [1], [Enable the SPDM responder])
fi

# The responder and TCG mutual auth sign with long-term identity keys
if test "x$enable_responder" = "xyes" || test "x$enable_tcg" = "xyes"; then
AC_MSG_CHECKING([for wolfSSL ECC timing resistance])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <wolfssl/options.h>
#include <wolfssl/wolfcrypt/settings.h>
#ifndef ECC_TIMING_RESISTANT
#error "no ECC timing resistance"
#endif
]], [[]])],
[AC_MSG_RESULT([yes])],
[AC_MSG_RESULT([no])
AC_MSG_ERROR([--enable-responder and --enable-tcg require wolfSSL built with --enable-harden (ECC_TIMING_RESISTANT)])])
fi

AM_CONDITIONAL([BUILD_TCG], [test "x$enable_tcg" = "xyes"])
AM_CONDITIONAL([BUILD_PSK], [test "x$enable_psk" = "xyes"])
AM_CONDITIONAL([BUILD_NUVOTON], [test "x$enable_nuvoton" = "xyes"])
Expand Down
4 changes: 2 additions & 2 deletions docs/API-Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ otherwise; failures are negative error codes from `wolfspdm/spdm_error.h`.

- `wolfSPDM_SetIO` / `wolfSPDM_HasIO`
- `wolfSPDM_SetMode` / `wolfSPDM_GetMode` *(`WOLFSPDM_MODE_AUTO` / `_NUVOTON` / `_NATIONS` / `_NATIONS_PSK`, alias `_PSK` / `_TCG`)*. `_TCG` is the TCG binding with no vendor commands, which is what the SLB9678 uses; `_AUTO` is the standard DMTF requester, so a TPM caller sets the mode explicitly.
- `wolfSPDM_SetResponderPubKey`: pin the responder key (96-byte P-384 X‖Y) for cert-less operation
- `wolfSPDM_SetResponderPubKey`: pin the responder key (96-byte P-384 X‖Y). The TCG binding uses it without a certificate (SlotID 0xFF); the standard binding matches it against the leaf of the retrieved chain, so `KEY_EXCHANGE` returns `WOLFSPDM_E_BAD_STATE` until `GET_CERTIFICATE` has run
- `wolfSPDM_SetRequesterKeyPair` *(`WOLFSPDM_MUTUAL_AUTH` builds, TCG or TPM profile)*
- `wolfSPDM_SetMaxVersion`: cap the negotiated version (0x12-0x14)
- `wolfSPDM_SetRequesterSessionId`: rejects `0x0000`, `0xFFFF`, and low bytes `0x10`-`0x1F`
Expand Down Expand Up @@ -65,7 +65,7 @@ otherwise; failures are negative error codes from `wolfspdm/spdm_error.h`.
## Session maintenance

- `wolfSPDM_Heartbeat` *(`WOLFSPDM_HAS_HEARTBEAT`)*
- `wolfSPDM_KeyUpdate` *(`WOLFSPDM_HAS_KEY_UPDATE`)*
- `wolfSPDM_KeyUpdate` *(`WOLFSPDM_HAS_KEY_UPDATE`)*: if `VerifyNewKey` fails after the responder acknowledged the update, the session ends and must be re-established

## TCG SPDM binding (`wolfspdm/spdm_tcg.h`, `WOLFSPDM_TCG`)

Expand Down
4 changes: 3 additions & 1 deletion docs/Attestation-Notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ exchanges: each call restarts the hash at the VCA transcript unless the
previous `GET_MEASUREMENTS` left it open (`WOLFSPDM_RUN_OPEN`, i.e. the prior
call was unsigned). A signed request closes the run and verifies the
signature over it; an unsigned request adds itself to the hash and leaves the
run open for the next call.
run open for the next call. Any other SPDM request sealed in the session ends
an open run, including `KEY_UPDATE` and messages sealed with
`wolfSPDM_EncryptMessage`.

Signature verification (measurements and `CHALLENGE_AUTH`) uses whichever
asymmetric algorithm was negotiated: ECDSA P-384 or, on SPDM 1.4 with ML-DSA
Expand Down
12 changes: 12 additions & 0 deletions docs/Configuration-and-Macros.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ From `configure.ac`:
(42 to `WOLFSPDM_MAX_MSG_SIZE`); smaller values shrink transport buffers and
rely more on chunking.

Certificate validity dates are checked against the wolfCrypt clock. On a
target without a clock, or before time sync, define
`CFLAGS=-DWOLFSPDM_NO_CERT_DATE_CHECK` to skip the date checks; wolfSSL's
`NO_ASN_TIME` or `NO_ASN_TIME_CHECK` skips them too. Chain signature, Key
Usage, and CA path length checks still apply.

Builds that sign with a long-term identity key (`WOLFSPDM_RESPONDER`, and
`WOLFSPDM_MUTUAL_AUTH`, which TCG and the wolfTPM profile turn on) require
wolfSSL's `ECC_TIMING_RESISTANT`. wolfSSL's default `--enable-harden` sets
it. A `user_settings.h` build must define it, or the build stops with an
`#error`.

## wolfTPM build profile

Built inside wolfTPM (`WOLFTPM_SPDM`), `WOLFSPDM_PROFILE_TPM` is implied, and
Expand Down
6 changes: 3 additions & 3 deletions docs/Post-Quantum-ML-KEM.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ post-quantum SPDM handshake**.
(§12.2). TH1/TH2 and all downstream derivation are unchanged from the
ECDHE path.

Per FIPS 203 implicit rejection, a `K′ ≠ K` mismatch surfaces only as a FINISH
integrity-check failure and is handled like any other session-message
failure.
With FIPS 203 implicit rejection, decapsulation returns a fallback shared
secret. The requester detects the mismatch when checking `ResponderVerifyData`
in `KEY_EXCHANGE_RSP` and returns `WOLFSPDM_E_BAD_HMAC`.

## How negotiation works

Expand Down
2 changes: 1 addition & 1 deletion examples/spdm_demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ static byte* load_der(const char* path, word32* outSz)
if (fseek(f, 0, SEEK_END) != 0) { fclose(f); return NULL; }
sz = ftell(f);
if (sz <= 0) { fclose(f); return NULL; }
rewind(f);
if (fseek(f, 0, SEEK_SET) != 0) { fclose(f); return NULL; }

buf = (byte*)malloc((size_t)sz);
if (buf == NULL) { fclose(f); return NULL; }
Expand Down
26 changes: 18 additions & 8 deletions src/spdm_attest.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ int wolfSPDM_BuildGetMeasurements(WOLFSPDM_CTX* ctx, byte* buf,
rc = wolfSPDM_GetRandom(ctx, &buf[4], SPDM_NONCE_SZ);
buf[4 + SPDM_NONCE_SZ] = ctx->currentSlotId;
}
if (rc == WOLFSPDM_SUCCESS && ctxSz > 0) {
rc = wolfSPDM_GetRandom(ctx, &buf[sz - ctxSz], ctxSz);
}
if (rc == WOLFSPDM_SUCCESS) {
if (ctxSz > 0) {
XMEMSET(&buf[sz - ctxSz], 0, ctxSz);
}
*bufSz = sz;
}
return rc;
Expand Down Expand Up @@ -271,6 +271,7 @@ int wolfSPDM_GetMeasurements(WOLFSPDM_CTX* ctx, byte measOperation,
ctx->measRecordLen = recLen;
ctx->measBlockCount = rsp[4];
}
wc_ForceZero(rsp, sizeof(rsp));
return rc;
}

Expand Down Expand Up @@ -351,14 +352,16 @@ int wolfSPDM_M1Add(WOLFSPDM_CTX* ctx, const byte* req, word32 reqSz,
int wolfSPDM_BuildChallenge(WOLFSPDM_CTX* ctx, byte* buf, word32* bufSz,
int slotId, byte measHashType)
{
word32 ctxSz;
word32 sz;
int rc;

if (ctx == NULL || buf == NULL || bufSz == NULL || slotId < 0 ||
slotId > 7) {
return WOLFSPDM_E_INVALID_ARG;
}
sz = 4 + SPDM_NONCE_SZ + wolfSPDM_ReqContextSz(ctx);
ctxSz = wolfSPDM_ReqContextSz(ctx);
sz = 4 + SPDM_NONCE_SZ + ctxSz;
if (*bufSz < sz) {
return WOLFSPDM_E_BUFFER_SMALL;
}
Expand All @@ -367,9 +370,11 @@ int wolfSPDM_BuildChallenge(WOLFSPDM_CTX* ctx, byte* buf, word32* bufSz,
buf[1] = SPDM_CHALLENGE;
buf[2] = (byte)slotId;
buf[3] = measHashType;
/* Nonce, then the 1.3+ RequesterContext */
rc = wolfSPDM_GetRandom(ctx, &buf[4], sz - 4);
rc = wolfSPDM_GetRandom(ctx, &buf[4], SPDM_NONCE_SZ);
if (rc == WOLFSPDM_SUCCESS) {
if (ctxSz > 0) {
XMEMSET(&buf[4 + SPDM_NONCE_SZ], 0, ctxSz);
}
*bufSz = sz;
}
return rc;
Expand Down Expand Up @@ -409,7 +414,9 @@ int wolfSPDM_Challenge(WOLFSPDM_CTX* ctx, int slotId, byte measHashType)
word32 sigOff = 0;
int rc;

if (ctx == NULL) {
if (ctx == NULL || (measHashType != SPDM_MEAS_SUMMARY_HASH_NONE &&
measHashType != SPDM_MEAS_SUMMARY_HASH_TCB &&
measHashType != SPDM_MEAS_SUMMARY_HASH_ALL)) {
return WOLFSPDM_E_INVALID_ARG;
}
/* M1 covers the chain fetched for this slot */
Expand All @@ -419,7 +426,10 @@ int wolfSPDM_Challenge(WOLFSPDM_CTX* ctx, int slotId, byte measHashType)
slotId != (int)ctx->currentSlotId) {
return WOLFSPDM_E_BAD_STATE;
}
if ((ctx->rspCaps & SPDM_CAP_CHAL_CAP) == 0) {
if ((ctx->rspCaps & SPDM_CAP_CHAL_CAP) == 0 ||
(measHashType != SPDM_MEAS_SUMMARY_HASH_NONE &&
(ctx->rspCaps & (SPDM_CAP_MEAS_CAP_NO_SIG |
SPDM_CAP_MEAS_CAP_SIG)) == 0)) {
return WOLFSPDM_E_CAPS_MISMATCH;
}

Expand Down
50 changes: 25 additions & 25 deletions src/spdm_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@
if (pubKeySz != WOLFSPDM_ECC_POINT_SIZE) {
return WOLFSPDM_E_INVALID_ARG;
}
if (pubKeySz > sizeof(ctx->rspPubKey)) {
return WOLFSPDM_E_BUFFER_SMALL;
}

XMEMCPY(ctx->rspPubKey, pubKey, pubKeySz);
ctx->rspPubKeyLen = pubKeySz;
Expand Down Expand Up @@ -420,8 +423,9 @@
return WOLFSPDM_E_INVALID_ARG;
}

/* Drop session state and wipe session-scoped secrets; configured identity
* keys, PSK and trust anchors stay for a later connection */
/* Drop session state and wipe session-scoped secrets. Configured identity
* keys, trust anchors and an unused PSK stay in the context. Set the PSK again
* with wolfSPDM_SetPSK when key derivation has consumed it. */
void wolfSPDM_ResetSession(WOLFSPDM_CTX* ctx)
{
ctx->state = WOLFSPDM_STATE_INIT;
Expand All @@ -432,26 +436,14 @@
ctx->mutAuthRequested = 0;
ctx->reqSlotIdParam = 0;
/* App data keys */
wc_ForceZero(ctx->reqDataKey, sizeof(ctx->reqDataKey));
wc_ForceZero(ctx->rspDataKey, sizeof(ctx->rspDataKey));
wc_ForceZero(ctx->reqDataIv, sizeof(ctx->reqDataIv));
wc_ForceZero(ctx->rspDataIv, sizeof(ctx->rspDataIv));
wolfSPDM_ClearTrafficKeys(ctx);
#ifndef WOLFSPDM_NO_KEY_UPDATE
wc_ForceZero(ctx->reqAppSecret, sizeof(ctx->reqAppSecret));
wc_ForceZero(ctx->rspAppSecret, sizeof(ctx->rspAppSecret));
#endif
/* Handshake keys */
wc_ForceZero(ctx->reqHsSecret, sizeof(ctx->reqHsSecret));
wc_ForceZero(ctx->rspHsSecret, sizeof(ctx->rspHsSecret));
wc_ForceZero(ctx->reqFinishedKey, sizeof(ctx->reqFinishedKey));
wc_ForceZero(ctx->rspFinishedKey, sizeof(ctx->rspFinishedKey));
/* Secrets and hashes */
wc_ForceZero(ctx->handshakeSecret, sizeof(ctx->handshakeSecret));
wc_ForceZero(ctx->sharedSecret, sizeof(ctx->sharedSecret));
ctx->sharedSecretSz = 0;
wolfSPDM_ClearHandshakeSecrets(ctx);
wc_ForceZero(ctx->th1, sizeof(ctx->th1));
wc_ForceZero(ctx->th2, sizeof(ctx->th2));
wolfSPDM_FreeEphemeralKey(ctx);
#ifndef WOLFSPDM_NO_CERT
ctx->rspCaps = 0;
ctx->dataTransferSize = 0;
Expand All @@ -460,12 +452,19 @@
#ifndef WOLFSPDM_NO_MEAS
ctx->measBlockCount = 0;
ctx->measRecordLen = 0;
wc_ForceZero(ctx->measRecord, sizeof(ctx->measRecord));
#endif
#if !defined(WOLFSPDM_NO_MEAS) || !defined(WOLFSPDM_NO_CHALLENGE)
wolfSPDM_AttestFree(ctx);
#endif
}

void wolfSPDM_RetireSession(WOLFSPDM_CTX* ctx)
{
wolfSPDM_ResetSession(ctx);
ctx->state = WOLFSPDM_STATE_ERROR;
}

int wolfSPDM_Disconnect(WOLFSPDM_CTX* ctx)
{
int rc = WOLFSPDM_E_NOT_CONNECTED;
Expand All @@ -480,6 +479,7 @@
byte rxBuf[16]; /* END_SESSION_ACK: 4 bytes */
word32 txSz = sizeof(txBuf);
word32 rxSz;
int peerError = 0;

rc = wolfSPDM_BuildEndSession(ctx, txBuf, &txSz);
if (rc == WOLFSPDM_SUCCESS) {
Expand All @@ -490,12 +490,12 @@
if (rxSz < 4) {
rc = WOLFSPDM_E_BUFFER_SMALL;
}
else if (wolfSPDM_CheckError(rxBuf, rxSz, NULL)) {
else if (wolfSPDM_CheckError(rxBuf, rxSz, &peerError)) {
ctx->lastPeerErrorCode = (byte)peerError;
rc = WOLFSPDM_E_PEER_ERROR;
}
else if (rxSz != 4 || rxBuf[0] != ctx->spdmVersion ||
rxBuf[1] != SPDM_END_SESSION_ACK ||
rxBuf[2] != 0 || rxBuf[3] != 0) {
rxBuf[1] != SPDM_END_SESSION_ACK) {
rc = WOLFSPDM_E_PEER_ERROR;
}
}
Expand Down Expand Up @@ -573,12 +573,6 @@
}
}
if (rc == WOLFSPDM_SUCCESS) {
/* Capture FIPS indicator from response if non-zero */
tag = SPDM_Get16BE(tcgRx + 10);
if (tag != 0) {
ctx->fipsIndicator = tag;
}

/* Extract payload (everything after 16-byte TCG header) */
msgSize = SPDM_Get32BE(tcgRx + 2);
if (msgSize < WOLFSPDM_TCG_HEADER_SIZE || msgSize > tcgRxSz) {
Expand All @@ -598,6 +592,12 @@
*rxSz = payloadSz;
}
}
/* Each exchange replaces the indicator; only an exact APPROVED counts */
ctx->fipsIndicator = WOLFSPDM_FIPS_NON_FIPS;
if (rc == WOLFSPDM_SUCCESS &&
SPDM_Get16BE(tcgRx + 10) == WOLFSPDM_FIPS_APPROVED) {
ctx->fipsIndicator = WOLFSPDM_FIPS_APPROVED;
}

/* Clear vendor messages carry PSK material */
wc_ForceZero(tcgTx, sizeof(tcgTx));
Expand Down
5 changes: 3 additions & 2 deletions src/spdm_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,9 @@ int wolfSPDM_GenerateMlKemKey(WOLFSPDM_CTX* ctx, byte* ek, word32* ekSz)
return rc;
}

/* Recover the shared secret from the responder's ciphertext; FIPS 203
* implicit rejection means a bad ciphertext only shows up at FINISH */
/* Recover the shared secret from the responder's ciphertext. After FIPS 203
* implicit rejection, the secret mismatch is detected when verifying
* ResponderVerifyData in KEY_EXCHANGE_RSP. */
int wolfSPDM_MlKemDecapsulate(WOLFSPDM_CTX* ctx, const byte* ct, word32 ctSz)
{
word32 expCtSz = 0;
Expand Down
Loading
Loading