Speedup DTLS max fragment size calculation for MTU limits#10323
Open
julek-wolfssl wants to merge 4 commits intowolfSSL:masterfrom
Open
Speedup DTLS max fragment size calculation for MTU limits#10323julek-wolfssl wants to merge 4 commits intowolfSSL:masterfrom
julek-wolfssl wants to merge 4 commits intowolfSSL:masterfrom
Conversation
Contributor
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.
rizlik
requested changes
Apr 27, 2026
|
a26a840 to
7a83f0a
Compare
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.
7a83f0a to
6fc100b
Compare
…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.
Member
Author
|
retest this please |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.