-
Notifications
You must be signed in to change notification settings - Fork 0
feat: standalone checksum-only integrity API (#13) #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
84fce62
feat: add standalone checksum/verify_checksum integrity primitive
27Bslash6 c482953
refactor: StorageEnvelope::new uses the canonical checksum() primitive
27Bslash6 e1e4c27
refactor: StorageEnvelope::extract verifies via verify_checksum()
27Bslash6 a219723
docs: document standalone checksum API in crate-level docs
27Bslash6 4c0f063
docs: list checksum.rs in README source tree
27Bslash6 20803be
test: assert ChecksumMismatch variant in extract corruption guard
27Bslash6 aec9510
test: pin canonical empty-input checksum value (de-tautologize)
27Bslash6 900aa86
fix: apply CodeRabbit auto-fixes
coderabbitai[bot] 6b14199
fix(deps): bump crossbeam-epoch 0.9.18 -> 0.9.20 (RUSTSEC-2026-0204)
27Bslash6 107dab2
Merge branch 'main' into feat/checksum-only-api
27Bslash6 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| //! Standalone xxHash3-64 integrity primitive. | ||
| //! | ||
| //! Non-cryptographic corruption detection, decoupled from compression. The same | ||
| //! function backs `StorageEnvelope`'s embedded checksum, so the wire value is | ||
| //! identical whether you compute it directly or via `ByteStorage::store`. | ||
|
|
||
| use xxhash_rust::xxh3::xxh3_64; | ||
|
|
||
| /// Compute the xxHash3-64 checksum of `data`, big-endian (xxhash canonical | ||
| /// byte order — the value embedded in every `StorageEnvelope`). | ||
| /// | ||
| /// Non-cryptographic: detects corruption, not tampering. For tamper-resistance | ||
| /// use AES-256-GCM (the auth tag), not this checksum. Intentionally unbounded — | ||
| /// a single-pass, allocation-free O(n) hash over caller-materialized bytes; the | ||
| /// `MAX_UNCOMPRESSED_SIZE` cap is `StorageEnvelope`'s decompression-bomb concern. | ||
| pub fn checksum(data: &[u8]) -> [u8; 8] { | ||
| xxh3_64(data).to_be_bytes() | ||
| } | ||
|
|
||
| /// Verify `data` against an expected xxHash3-64 checksum. | ||
| /// | ||
| /// Plain (non-constant-time) equality, consistent with the non-cryptographic | ||
| /// threat model — do NOT change to constant-time (would imply a security | ||
| /// property this primitive does not have). | ||
| pub fn verify_checksum(data: &[u8], expected: &[u8; 8]) -> bool { | ||
| &checksum(data) == expected | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn checksum_is_deterministic() { | ||
| let data = b"cachekit checksum determinism vector"; | ||
| assert_eq!(checksum(data), checksum(data)); | ||
| } | ||
|
|
||
| #[test] | ||
| fn checksum_handles_empty_input() { | ||
| // Pin the canonical xxHash3-64 of the empty input (big-endian); proves | ||
| // "handles empty" beyond just "doesn't panic", and locks the value. | ||
| assert_eq!( | ||
| checksum(b""), | ||
| [0x2D, 0x06, 0x80, 0x05, 0x38, 0xD3, 0x94, 0xC2] | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn verify_checksum_accepts_matching() { | ||
| let data = b"payload bytes"; | ||
| assert!(verify_checksum(data, &checksum(data))); | ||
| } | ||
|
|
||
| #[test] | ||
| fn verify_checksum_rejects_single_bit_flip() { | ||
| let data = b"payload bytes"; | ||
| let mut corrupted = checksum(data); | ||
| corrupted[0] ^= 0x01; | ||
| assert!(!verify_checksum(data, &corrupted)); | ||
| } | ||
|
|
||
| #[test] | ||
| fn verify_checksum_rejects_wrong_data() { | ||
| let expected = checksum(b"original"); | ||
| assert!(!verify_checksum(b"tampered", &expected)); | ||
| } | ||
|
|
||
| #[test] | ||
| fn checksum_known_answer_locks_endianness() { | ||
| // Captured from checksum(b"cachekit-kat"); pins algorithm + big-endian order. | ||
| assert_eq!( | ||
| checksum(b"cachekit-kat"), | ||
| [209u8, 35, 204, 155, 190, 157, 164, 177] | ||
| ); | ||
| } | ||
| } |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.