Add an accumulating SHA256 API (SHA256State, UpdateSHA256, UpdateSHA256File) - #6509
Open
fingolfin wants to merge 2 commits into
Open
Add an accumulating SHA256 API (SHA256State, UpdateSHA256, UpdateSHA256File)#6509fingolfin wants to merge 2 commits into
SHA256State, UpdateSHA256, UpdateSHA256File)#6509fingolfin wants to merge 2 commits into
Conversation
GAP can hash a string, a stream, or a file, but not a concatenation of those without building it in memory first. Git object hashes are exactly that shape -- a header followed by a file's contents -- and packages computing them have to fall back on the IO package, on piping through sha256sum, or on reading the whole file into a string. s := SHA256State(); UpdateSHA256( s, "blob 15\000" ); UpdateSHA256File( s, name, false ); HexSHA256( s ); The kernel already had the accumulator; it was undocumented, could not consume a file, and its FINAL pads the state in place, so reading a digest twice silently gave a wrong answer. GAP_SHA256_DIGEST finalizes a copy instead, which makes reading a digest an ordinary operation rather than one the caller must know is destructive. HexSHA256 gains a state as its third case; HexSHA256File is unchanged. Also: - give the state a category and a print method, so it can be tested for and does not display as <object>; - fix the state bag being allocated 4 bytes short of what it addresses, masked until now by GASMAN rounding bag sizes up; - take the state by value when building the result list, since allocating it may move bags. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
SHA256State, UpdateSHA256, UpdateSHA256File)
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #6509 +/- ##
==========================================
- Coverage 78.87% 78.66% -0.21%
==========================================
Files 685 685
Lines 294150 294164 +14
Branches 8646 8669 +23
==========================================
- Hits 232001 231395 -606
- Misses 60348 60941 +593
- Partials 1801 1828 +27 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
fingolfin
commented
Aug 14, 2026
fingolfin
commented
Aug 14, 2026
fingolfin
commented
Aug 14, 2026
fingolfin
commented
Aug 14, 2026
Addresses review: the kernel one-shot GAP_SHA256_FILE is gone, and HexSHA256File is three lines of GAP over SHA256State, UpdateSHA256File and HexSHA256. Its argument checking goes too, since UpdateSHA256File already raises the same errors. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
GAP can hash a string, a stream, or a file, but not a concatenation of those without building it in memory first. Git object hashes are exactly that shape:
"blob <size>\0"followed by a file's contentsThis PR adds functionality to allow handling that within GAP:
Two drive-by fixes:
sizeof(UInt4) + sizeof(sha256_state_t)but addressed fromADDR_OBJ(result)[1], i.e. 4 bytes short. Masked by GASMAN rounding bag sizes up to whole words.UInt4is always an immediate integer, which is why this has never bitten.Written with Claude Opus 5 via Claude Code; reviewed by me. The commit lists
the tool as co-author.