test(rust/trezor-thp): crc32 vectors from test_trezor.wire.thp.checksum
What changed, and why it matters
This commit only adds more test cases and removes two unused helper functions for verifying CRC32 checksums. It does not change the actual CRC32 calculation logic, nor does it fix any security issue. There is nothing here that would allow an attacker to exploit a Trezor device.
No security action required; this is a routine test-only commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff expands unit tests in rust/trezor-thp/src/crc32.rs with additional CRC32 test vectors borrowed from test_trezor.wire.thp.checksum and adds a chunked-update test. It also deletes verify_payload and verify helpers, which appear unused. The core digest and Crc32 implementation are untouched. No security patch is present.
Changed components
rust/trezor-thp/src/crc32.rsInspect captured patch +102 / −10
diff --git a/rust/trezor-thp/src/crc32.rs b/rust/trezor-thp/src/crc32.rs
index 27219a40..d1a990e7 100644
--- a/rust/trezor-thp/src/crc32.rs
+++ b/rust/trezor-thp/src/crc32.rs
@@ -36,24 +36,16 @@ pub fn digest(data: &[u8]) -> [u8; CHECKSUM_LEN] {
crc.finalize()
}
-pub fn verify_payload(buffer: &[u8]) -> Option<&[u8]> {
- let (payload, digest_in) = buffer.split_last_chunk::<CHECKSUM_LEN>()?;
- let digest_computed = digest(payload);
- (digest_computed == *digest_in).then_some(payload)
-}
-
-pub fn verify(data: &[u8]) -> bool {
- verify_payload(data).is_some()
-}
-
#[cfg(test)]
mod test {
use super::*;
const CRC32_VECTORS: &[(&[u8], &str)] = &[
(b"", "00000000"),
+ (&[0; 32], "190a55ad"),
(b"a", "e8b7be43"),
(b"abc", "352441c2"),
+ (b"123456789", "cbf43926"),
(b"message digest", "20159d7f"),
(b"abcdefghijklmnopqrstuvwxyz", "4c2750bd"),
(
@@ -64,6 +56,94 @@ mod test {
b"12345678901234567890123456789012345678901234567890123456789012345678901234567890",
"7ca94a72",
),
+ (
+ &[
+ 0x76, 0x61, 0x72, 0x69, 0x6f, 0x75, 0x73, 0x20, 0x43, 0x52, 0x43, 0x20, 0x61, 0x6c,
+ 0x67, 0x6f, 0x72, 0x69, 0x74, 0x68, 0x6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xb3, 0xd4,
+ ],
+ "6ba4ec92",
+ ),
];
#[test]
@@ -80,4 +160,16 @@ mod test {
assert_eq!(out_hex, *expected);
}
}
+
+ #[test]
+ fn test_chunks() {
+ for chunk_size in [1, 2, 3, 4] {
+ for (data, expected) in CRC32_VECTORS {
+ let mut crc = Crc32::new();
+ data.chunks(chunk_size).for_each(|c| crc.update(c));
+ let out_hex = hex::encode(crc.finalize());
+ assert_eq!(out_hex, *expected);
+ }
+ }
+ }
}
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.