mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
fix(cksum): correct CRC32B implementation to match GNU cksum
- Implement correct CRC32B algorithm with proper polynomial and initialization - Add comprehensive test fixtures for CRC32B validation - Support raw output format for CRC32B checksums - Update dependencies and lock files for compatibility - Fix code formatting and style issues
This commit is contained in:
Generated
-1
@@ -4318,7 +4318,6 @@ dependencies = [
|
||||
"clap",
|
||||
"codspeed-divan-compat",
|
||||
"crc-fast",
|
||||
"crc32fast",
|
||||
"data-encoding",
|
||||
"data-encoding-macro",
|
||||
"digest",
|
||||
|
||||
@@ -390,7 +390,6 @@ sha3 = "0.10.8"
|
||||
blake2b_simd = "1.0.2"
|
||||
blake3 = "1.5.1"
|
||||
sm3 = "0.4.2"
|
||||
crc32fast = "1.4.2"
|
||||
crc-fast = "1.5.0"
|
||||
digest = "0.10.7"
|
||||
|
||||
|
||||
Generated
+125
-103
File diff suppressed because it is too large
Load Diff
@@ -236,7 +236,9 @@ where
|
||||
match options.output_format {
|
||||
OutputFormat::Raw => {
|
||||
let bytes = match options.algo_name {
|
||||
ALGORITHM_OPTIONS_CRC => sum_hex.parse::<u32>().unwrap().to_be_bytes().to_vec(),
|
||||
ALGORITHM_OPTIONS_CRC | ALGORITHM_OPTIONS_CRC32B => {
|
||||
sum_hex.parse::<u32>().unwrap().to_be_bytes().to_vec()
|
||||
}
|
||||
ALGORITHM_OPTIONS_SYSV | ALGORITHM_OPTIONS_BSD => {
|
||||
sum_hex.parse::<u16>().unwrap().to_be_bytes().to_vec()
|
||||
}
|
||||
|
||||
@@ -65,7 +65,6 @@ sha3 = { workspace = true, optional = true }
|
||||
blake2b_simd = { workspace = true, optional = true }
|
||||
blake3 = { workspace = true, optional = true }
|
||||
sm3 = { workspace = true, optional = true }
|
||||
crc32fast = { workspace = true, optional = true }
|
||||
crc-fast = { workspace = true, optional = true }
|
||||
bigdecimal = { workspace = true, optional = true }
|
||||
num-traits = { workspace = true, optional = true }
|
||||
@@ -170,7 +169,6 @@ sum = [
|
||||
"blake2b_simd",
|
||||
"blake3",
|
||||
"sm3",
|
||||
"crc32fast",
|
||||
"crc-fast",
|
||||
]
|
||||
update-control = ["parser"]
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// For the full copyright and license information, please view the LICENSE
|
||||
// file that was distributed with this source code.
|
||||
|
||||
// spell-checker:ignore memmem algo PCLMULQDQ refin xorout
|
||||
// spell-checker:ignore memmem algo PCLMULQDQ refin xorout Hdlc
|
||||
|
||||
//! Implementations of digest functions, like md5 and sha1.
|
||||
//!
|
||||
@@ -183,24 +183,31 @@ impl Digest for Crc {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct CRC32B(crc32fast::Hasher);
|
||||
pub struct CRC32B {
|
||||
digest: crc_fast::Digest,
|
||||
}
|
||||
|
||||
impl Digest for CRC32B {
|
||||
fn new() -> Self {
|
||||
Self(crc32fast::Hasher::new())
|
||||
Self {
|
||||
digest: crc_fast::Digest::new(crc_fast::CrcAlgorithm::Crc32IsoHdlc),
|
||||
}
|
||||
}
|
||||
|
||||
fn hash_update(&mut self, input: &[u8]) {
|
||||
self.0.update(input);
|
||||
self.digest.update(input);
|
||||
}
|
||||
|
||||
fn hash_finalize(&mut self, out: &mut [u8]) {
|
||||
let result = self.0.clone().finalize();
|
||||
let slice = result.to_be_bytes();
|
||||
out.copy_from_slice(&slice);
|
||||
let result = self.digest.finalize();
|
||||
// crc_fast returns a 64-bit value, but CRC32B should be 32-bit
|
||||
// Take the lower 32 bits and convert to big-endian bytes
|
||||
let crc32_value = (result & 0xffffffff) as u32;
|
||||
out.copy_from_slice(&crc32_value.to_be_bytes());
|
||||
}
|
||||
|
||||
fn reset(&mut self) {
|
||||
self.0.reset();
|
||||
self.digest.reset();
|
||||
}
|
||||
|
||||
fn output_bits(&self) -> usize {
|
||||
|
||||
@@ -10,8 +10,9 @@ use uutests::util::TestScenario;
|
||||
use uutests::util::log_info;
|
||||
use uutests::util_name;
|
||||
|
||||
const ALGOS: [&str; 11] = [
|
||||
"sysv", "bsd", "crc", "md5", "sha1", "sha224", "sha256", "sha384", "sha512", "blake2b", "sm3",
|
||||
const ALGOS: [&str; 12] = [
|
||||
"sysv", "bsd", "crc", "crc32b", "md5", "sha1", "sha224", "sha256", "sha384", "sha512",
|
||||
"blake2b", "sm3",
|
||||
];
|
||||
const SHA_LENGTHS: [u32; 4] = [224, 256, 384, 512];
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
1136995542 772 lorem_ipsum.txt
|
||||
@@ -0,0 +1,2 @@
|
||||
1136995542 772 lorem_ipsum.txt
|
||||
2801993020 302 alice_in_wonderland.txt
|
||||
@@ -0,0 +1 @@
|
||||
1136995542 772 lorem_ipsum.txt
|
||||
+1
@@ -0,0 +1 @@
|
||||
1136995542 772
|
||||
@@ -0,0 +1 @@
|
||||
C�,�
|
||||
@@ -0,0 +1,2 @@
|
||||
1136995542 772 lorem_ipsum.txt
|
||||
2801993020 302 alice_in_wonderland.txt
|
||||
@@ -0,0 +1 @@
|
||||
1136995542 772 lorem_ipsum.txt
|
||||
@@ -0,0 +1 @@
|
||||
1136995542 772
|
||||
Reference in New Issue
Block a user