Skip to content

Commit 99bd133

Browse files
committed
Fail fast when ML-KEM KEY_EXCHANGE exceeds responder DataTransferSize (no CHUNK_SEND)
1 parent d00a06b commit 99bd133

2 files changed

Lines changed: 29 additions & 8 deletions

File tree

docs/Message-Chunking.md

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,21 @@ The mechanism has two directions, controlled by different endpoints:
7979
the requester decides to chunk its own outbound request; a responder cannot
8080
force it.
8181

82-
Every request wolfSPDM builds (GET_VERSION through GET_MEASUREMENTS,
83-
KEY_EXCHANGE, FINISH) is small and fixed, well under any responder's
84-
`DataTransferSize`, so `CHUNK_SEND` is never needed — it is not applicable to
85-
this library's traffic rather than missing. `CHUNK_CAP` advertises support for
86-
the large-message mechanism; it does not obligate an endpoint to chunk requests
87-
it never sends, so a requester that only emits small requests is fully
88-
conformant supporting `CHUNK_GET` alone. `CHUNK_SEND` / `CHUNK_SEND_ACK` are
89-
defined in `spdm_types.h` for completeness but intentionally unimplemented.
82+
Almost every request wolfSPDM builds (GET_VERSION through GET_MEASUREMENTS,
83+
FINISH) is small and fixed, well under any responder's `DataTransferSize`. The
84+
one exception is an **ML-KEM** KEY_EXCHANGE, whose `ExchangeData` carries the
85+
encapsulation key `ek` (800/1184/1568 B for ML-KEM-512/768/1024) — a request of
86+
~870–1640 B. This still fits common responders (e.g. spdm-emu advertises
87+
4608 B), but a constrained responder could advertise a smaller
88+
`DataTransferSize`. Because `CHUNK_SEND` is unimplemented, `wolfSPDM_KeyExchange`
89+
**fails fast** (`WOLFSPDM_E_BUFFER_SMALL`) when the built request exceeds the
90+
responder's `DataTransferSize` rather than emit a non-conformant oversized
91+
message — so the library never sends something it cannot chunk.
92+
93+
`CHUNK_CAP` advertises support for the large-message mechanism; it does not
94+
obligate an endpoint to chunk requests it never sends. `CHUNK_SEND` /
95+
`CHUNK_SEND_ACK` are defined in `spdm_types.h` for completeness but intentionally
96+
unimplemented; the fail-fast guard keeps that conformant.
9097

9198
## References
9299

src/spdm_session.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,20 @@ int wolfSPDM_KeyExchange(WOLFSPDM_CTX* ctx)
306306
return rc;
307307
}
308308

309+
/* An ML-KEM encapsulation key makes this request large (up to ~1.6 KB for
310+
* ML-KEM-1024), unlike the ~158-byte ECDHE request. wolfSPDM implements
311+
* CHUNK_GET (response reassembly) but not CHUNK_SEND (request
312+
* fragmentation), so if the request exceeds the responder's advertised
313+
* DataTransferSize, fail fast with a clear error rather than transmit a
314+
* non-conformant oversized request (DSP0274 Sec. 10.27). */
315+
if (ctx->dataTransferSize != 0 && txSz > ctx->dataTransferSize) {
316+
wolfSPDM_DebugPrint(ctx,
317+
"KEY_EXCHANGE %u B exceeds responder DataTransferSize %u "
318+
"(no CHUNK_SEND)\n",
319+
(unsigned)txSz, (unsigned)ctx->dataTransferSize);
320+
return WOLFSPDM_E_BUFFER_SMALL;
321+
}
322+
309323
rc = wolfSPDM_TranscriptAdd(ctx, txBuf, txSz);
310324
if (rc != WOLFSPDM_SUCCESS) {
311325
return rc;

0 commit comments

Comments
 (0)