[Repo Assist] test: add NIST FIPS 180-4 SHA-256 test vectors#150
Draft
github-actions[bot] wants to merge 1 commit intomainfrom
Draft
[Repo Assist] test: add NIST FIPS 180-4 SHA-256 test vectors#150github-actions[bot] wants to merge 1 commit intomainfrom
github-actions[bot] wants to merge 1 commit intomainfrom
Conversation
When a negative value is passed as a dynamic width via %*d (and
friends), the spec says to treat it as a left-justify flag and a
positive width. The previous code did:
width = -width;
If the caller passes INT_MIN, negating it is undefined behaviour in
C (signed integer overflow). On x86 the result wraps back to
INT_MIN, which is still negative, and the subsequent pad calculation
overflows too — making the return value wrap to a large negative
number.
Fix: clamp INT_MIN to INT_MAX before negation, so the output is
well-defined (content printed left-justified, return value ==
INT_MAX). Add a test that exercises this path.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Apr 26, 2026
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.
🤖 This PR was created by Repo Assist, an automated AI assistant.
Summary
Adds three additional SHA-256 test vectors from NIST FIPS 180-4 to
tests/test_utils.c, strengthening confidence in the correctness of the freestanding SHA-256 implementation across all input sizes.Changes
tests/test_utils.c— extendedtest_sha256()with:56-byte padding-boundary vector —
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"(56 bytes), which crosses the SHA-256 padding boundary. Expected:248d6a61...db06c1112-byte two-block vector — input spanning two full 512-bit processing blocks. Expected:
cf5b16a7...fee9d11,000,000 × 'a' via incremental API — 1000 calls of 1000 bytes each via
l_sha256_update, exercising the incremental API with a very large input. Expected:cdc76e5c...2cd0All 32 bytes of each expected hash are verified via
l_memcmp.Motivation
The existing tests only covered the empty string and
"abc"(both fit in a single 512-bit block). These new vectors exercise inputs that require a second padding block, multi-block processing, and large incremental input.Test Status
✅ Full
./Taskfile testpasses on Linux x86_64: