Skip to content

fix: correct calculation of extensions bitfield size#5719

Merged
WesleyRosenblum merged 8 commits intomainfrom
WesleyRosenblum/extensionlen
Feb 6, 2026
Merged

fix: correct calculation of extensions bitfield size#5719
WesleyRosenblum merged 8 commits intomainfrom
WesleyRosenblum/extensionlen

Conversation

@WesleyRosenblum
Copy link
Copy Markdown
Contributor

@WesleyRosenblum WesleyRosenblum commented Feb 3, 2026

Goal

Reduce the extension bitfield size to the actual size needed to hold all supported extensions

Why

S2N_SUPPORTED_EXTENSIONS_BITFIELD_LEN is intended to hold the number of bytes required to assign one bit to each of the TLS extensions supported by s2n-tls. It does this by dividing the number of supported extensions (S2N_SUPPORTED_EXTENSIONS_COUNT) by the size of a char type (sizeof(char)). sizeof(char) always equals 1, so given S2N_SUPPORTED_EXTENSIONS_COUNT=21, this calculation results in 21 / 1 + 1 = 22 bytes.

The actual number of bytes needed to hold 21 extensions would be 21 / (number of bits in a byte) + 1 = 3.

How

Instead of dividing by sizeof(char) (1), divide by CHAR_BIT (8)

Callouts

Since s2n_connection has 3 uses of extension bitfields, that was resulting in a total allocation of 22 * 3 = 66 bytes for each connection. With the updated calculation of 3 bytes, that results in 9 bytes allocated for extensions, a savings of 57 bytes. Therefore, the max_connection_size in s2n_connection_size_test has been decreased by 57 bytes.

Testing

Existing tests pass

Related

release summary: each connection now uses 57 less bytes

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@github-actions github-actions bot added the s2n-core team label Feb 3, 2026
@WesleyRosenblum WesleyRosenblum marked this pull request as ready for review February 3, 2026 20:04
@WesleyRosenblum WesleyRosenblum added this pull request to the merge queue Feb 6, 2026
Merged via the queue into main with commit fdb78da Feb 6, 2026
56 checks passed
@WesleyRosenblum WesleyRosenblum deleted the WesleyRosenblum/extensionlen branch February 6, 2026 06:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants