Cache AEAD record overhead on WOLFSSL#10476
Open
julek-wolfssl wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
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::recordSzOverheadto cache AEAD(recordSz - payloadSz)overhead and use it inwolfssl_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()againstBuildMessage(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.
|
3ecfafe to
6dcc5a8
Compare
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.
6dcc5a8 to
9e052cd
Compare
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.
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.