Speedup DTLS max fragment size calculation for MTU limits#10323
Speedup DTLS max fragment size calculation for MTU limits#10323julek-wolfssl wants to merge 5 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Refactors wolfSSL’s record-size computation to avoid calling BuildMessage and adds a unit test to ensure the new direct calculation matches BuildMessage’s size-only behavior across cipher suites and protocol versions.
Changes:
- Reimplemented
wolfssl_local_GetRecordSize()to compute record size directly from negotiated cipher specs (including TLS 1.3 and DTLS(+CID) handling). - Exposed a few internal helpers (
BuildMessage,GetCipherNames*,wolfssl_local_GetRecordSize) with test visibility for unit testing. - Added an API test that cross-checks the new calculation vs
BuildMessage(sizeOnly)across versions/ciphers/payload sizes.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
src/internal.c |
Replaces BuildMessage call with direct record-size calculation logic. |
wolfssl/internal.h |
Marks internal functions as test-visible so the new unit test can call them. |
tests/api/test_tls.c |
Adds exhaustive cross-check test for record-size calculations across ciphers/versions. |
tests/api/test_tls.h |
Registers the new test in the TLS API test group list. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
7a83f0a to
6fc100b
Compare
|
retest this please.. |
Refactor wolfssl_local_GetRecordSize to compute the record size directly from cipher specs instead of calling BuildMessage. Add a unit test that compares the new calculation to BuildMessage's size-only output across every registered cipher suite and supported (D)TLS version.
RFC 8998 registers TLS_SM4_GCM_SM3 / TLS_SM4_CCM_SM3 (and the TLS 1.2 SM4 suites) with DTLS-OK: No and defines no record-number-mask construction for SM4. RFC 9147 Section 4.2.3 requires any non-AES / non-ChaCha20 cipher to define its own record sequence number encryption to be usable with DTLS. Drop SM cipher suites from the negotiable list in InitSuites when DTLS, and reject them defensively in VerifyServerSuite for the case where the user pins a cipher list explicitly. Update test_record_size_matches_build_message to set up an SM2 cert chain and SM2 key share for SM ciphers (so they actually handshake over TLS 1.2 / TLS 1.3) and to skip the DTLS variants with the RFC reason.
…M test test_record_size_matches_build_message loaded the embedded server_sm2_der buffer, which is generated from the stale certs/sm2/server-sm2.der (still the Feb 2023 / Nov 2025 cert). On a minimal SM build the SM TLS handshake aborts with -151 ASN_AFTER_DATE_E and the test fails. Switch the test to load server_sm2_cert_der, which tracks the current 2026-2028 SM2 server cert, and regenerate wolfssl/certs_test_sm.h via gencertbuf.pl so ca_sm2_der is also refreshed against the in-tree CA cert.
The new test_record_size_matches_build_message exposes BuildMessage, GetCipherNames and GetCipherNamesSize via WOLFSSL_TEST_VIS so the unit test can call them from outside the library. Without a prefix map, the WOLFSSL_API_PREFIX_MAP build (symbol-prefixes.yml) trips the unprefixed-public-symbols check because these names start with neither wc_ nor wolf/WOLF. Add the same #define remap that the other WOLFSSL_TEST_VIS internals (DoApplicationData, TLSX_Find, DeriveTls13Keys, ...) already use, so the exported symbols become wolfSSL_BuildMessage / wolfSSL_GetCipherNames(Size) under that build. wolfssl_local_GetRecordSize already starts with "wolf" and needs no remap.
df4b249 to
89c4a01
Compare
rizlik
left a comment
There was a problem hiding this comment.
I've doubts on this refactor.
I'm trying to understand what makes the sizeOnly=1 path in BuildMessage expensive enough to justify the duplication.
For non-SCR paths the overhead looks modest — XMEMSET(BuildMsgArgs) and the state-machine traversal.
That said, you measured this and added the safety net test, so I'm comfortable if you think the current shape is the right trade-off
| (byte*)server_sm2_cert_der, | ||
| (int)sizeof_server_sm2_cert_der, |
There was a problem hiding this comment.
Consider using path or load from path as it's less noiser for the version control system.
Refactor wolfssl_local_GetRecordSize to compute the record size directly
from cipher specs instead of calling BuildMessage. Add a unit test that
compares the new calculation to BuildMessage's size-only output across
every registered cipher suite and supported (D)TLS version.