Skip to content

Cache AEAD record overhead on WOLFSSL#10476

Open
julek-wolfssl wants to merge 1 commit into
wolfSSL:masterfrom
julek-wolfssl:cache-overhead
Open

Cache AEAD record overhead on WOLFSSL#10476
julek-wolfssl wants to merge 1 commit into
wolfSSL:masterfrom
julek-wolfssl:cache-overhead

Conversation

@julek-wolfssl
Copy link
Copy Markdown
Member

wolfssl_local_GetRecordSize() runs BuildMessage(sizeOnly=1) on every
wolfSSL_write hot path. For AEAD ciphers the overhead is constant per
connection framing state, so cache (recordSz - payloadSz) on WOLFSSL
and invalidate in SetKeysSide(), at cidInfo->tx assignment, and in
wolfSSL_clear(). BuildMessage stays the single source of truth.

Add test_record_size_matches_build_message (cross-checks every built
cipher over TLS/DTLS +/- CID against BuildMessage) and
test_record_size_cache_invalidated_on_renegotiation.

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

This PR optimizes the wolfSSL_write hot path by caching AEAD record framing overhead (derived from BuildMessage(sizeOnly=1)) per-connection, avoiding repeated BuildMessage() calls when the overhead is constant. The cache is invalidated on key/state transitions where record framing could change, and new API tests are added to cross-check sizing behavior against BuildMessage().

Changes:

  • Add WOLFSSL::recordSzOverhead to cache AEAD (recordSz - payloadSz) overhead and use it in wolfssl_local_GetRecordSize().
  • Invalidate the cache on cipher/key activation (SetKeysSide()), wolfSSL_clear(), and DTLS CID TX assignment.
  • Add API tests that cross-check wolfssl_local_GetRecordSize() against BuildMessage(sizeOnly=1) across cipher suites and protocols.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
wolfssl/internal.h Adds recordSzOverhead field to WOLFSSL for AEAD record overhead caching.
src/internal.c Uses cached AEAD overhead in wolfssl_local_GetRecordSize() and populates cache on successful BuildMessage().
src/keys.c Clears the cache in SetKeysSide() to invalidate on key/cipher activation.
src/dtls.c Clears the cache when TX CID is assigned (record framing changes).
src/ssl.c Clears the cache in wolfSSL_clear().
tests/api/test_tls.h Registers new test declarations.
tests/api/test_tls.c Adds record-size cross-check test and renegotiation invalidation test.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/api/test_tls.c
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 13, 2026

MemBrowse Memory Report

gcc-arm-cortex-m4

  • FLASH: .text +64 B (+0.0%, 198,081 B / 262,144 B, total: 76% used)

gcc-arm-cortex-m4-tls12

wolfssl_local_GetRecordSize() runs BuildMessage(sizeOnly=1) on every
wolfSSL_write hot path. For AEAD ciphers the overhead is constant per
connection framing state, so cache (recordSz - payloadSz) on WOLFSSL
and invalidate in SetKeysSide(), at cidInfo->tx assignment, and in
wolfSSL_clear(). BuildMessage stays the single source of truth.

Add test_record_size_matches_build_message (cross-checks every built
cipher over TLS/DTLS +/- CID against BuildMessage) and
test_record_size_cache_invalidated_on_renegotiation.
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.

2 participants