Skip to content

Speedup DTLS max fragment size calculation for MTU limits#10323

Open
julek-wolfssl wants to merge 4 commits intowolfSSL:masterfrom
julek-wolfssl:wolfssl_local_GetRecordSize-refactor
Open

Speedup DTLS max fragment size calculation for MTU limits#10323
julek-wolfssl wants to merge 4 commits intowolfSSL:masterfrom
julek-wolfssl:wolfssl_local_GetRecordSize-refactor

Conversation

@julek-wolfssl
Copy link
Copy Markdown
Member

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.

Copilot AI review requested due to automatic review settings April 27, 2026 16:34
@julek-wolfssl julek-wolfssl self-assigned this Apr 27, 2026
@julek-wolfssl julek-wolfssl requested a review from rizlik April 27, 2026 16:34
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread tests/api/test_tls.c Outdated
Comment thread tests/api/test_tls.c
Comment thread tests/api/test_tls.c
Comment thread tests/api/test_tls.c
Comment thread tests/api/test_tls.c
Comment thread wolfssl/internal.h
Comment thread wolfssl/internal.h
Comment thread src/internal.c
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 27, 2026

MemBrowse Memory Report

gcc-arm-cortex-m4

@julek-wolfssl julek-wolfssl force-pushed the wolfssl_local_GetRecordSize-refactor branch from a26a840 to 7a83f0a Compare April 28, 2026 11:50
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.
@julek-wolfssl julek-wolfssl force-pushed the wolfssl_local_GetRecordSize-refactor branch from 7a83f0a to 6fc100b Compare April 28, 2026 15:22
…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.
@julek-wolfssl
Copy link
Copy Markdown
Member Author

retest this please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants