Skip to content

crypto: fix chacha constants under GCC 15 - #20199

Merged
acassis merged 1 commit into
apache:masterfrom
royzah:crypto-chacha-gcc15
Sep 20, 2026
Merged

acassis merged 1 commit into
apache:masterfrom
royzah:crypto-chacha-gcc15

Conversation

@royzah

@royzah royzah commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Why

GCC 15 added -Wunterminated-string-initialization. Both ChaCha constants fill their array exactly, leaving no room for the terminator, and crypto/Makefile turns warnings into errors:

chacha_private.h:61:31: error: initializer-string for array of 'char' truncates
NUL terminator but destination lacks 'nonstring' attribute (17 chars into 16
available)

Any build of https://github.com/apache/nuttx/blob/master/crypto/chachapoly.c with that compiler stops there.

How

Neither constant is a string. Both are read as sixteen bytes through U8TO32_LITTLE(), and nothing looks past index 15. Letting the size follow the literal costs one byte each and needs no attribute that only some compilers have.

__attribute__((nonstring)) is narrower, but https://github.com/apache/nuttx/blob/master/include/nuttx/compiler.h has no macro for it and adding one across every compiler block is more than this warrants. Happy to go that way instead.

Tested

GCC 15.3.0, aarch64-none-elf, same file:

diagnostics
before 2
after 0

chacha_keysetup() then chacha_ivsetup() give a byte-identical input[16] at 256 and 128 bits. tools/nxstyle clean.

GCC 15 added -Wunterminated-string-initialization, and both constants fill
their array exactly, leaving no room for the terminator. Every build with
that compiler fails, since crypto/Makefile treats warnings as errors.

Neither is used as a string: they are read as sixteen bytes through
U8TO32_LITTLE(). Letting the array size follow the literal keeps them
readable, costs one byte each, and needs no attribute that only some
compilers have.

The cipher state is unchanged for both key sizes.

Signed-off-by: Royyan Zahir <royzah@gmail.com>
@github-actions github-actions Bot added Size: XS The size of the change in this PR is very small Area: Crypto labels Sep 20, 2026
@github-actions

Copy link
Copy Markdown

MemBrowse Memory Report

No memory changes detected for:

@acassis
acassis merged commit 0cb7945 into apache:master Sep 20, 2026
53 checks passed
royzah added a commit to tiiuae/nuttx that referenced this pull request Sep 21, 2026
Both strings fill their array exactly, leaving no room for the
terminator, so GCC 15 rejects the initialiser and crypto/ will not
build. Dropping the explicit bound lets the compiler size them.

Merged upstream as apache#20199; carried
here until the submodule pin catches up.

Signed-off-by: Royyan Zahir <royzah@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Crypto Size: XS The size of the change in this PR is very small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants