1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 12:07:46 +00:00

Merge pull request #3175 from alextibbles/hashsum-update-md5

Hashsum consolidate md5 with RustCrypto Hashes
This commit is contained in:
Sylvestre Ledru 2022-02-22 20:38:38 +01:00 committed by GitHub
commit e95a8e2ec9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 73 deletions

33
Cargo.lock generated
View file

@ -652,11 +652,12 @@ dependencies = [
[[package]] [[package]]
name = "crypto-common" name = "crypto-common"
version = "0.1.1" version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "683d6b536309245c849479fba3da410962a43ed8e51c26b729208ec0ac2798d0" checksum = "57952ca27b5e3606ff4dd79b0020231aaf9d6aa76dc05fd30137538c50bd3ce8"
dependencies = [ dependencies = [
"generic-array", "generic-array",
"typenum",
] ]
[[package]] [[package]]
@ -719,13 +720,12 @@ checksum = "0e25ea47919b1560c4e3b7fe0aaab9becf5b84a10325ddf7db0f0ba5e1026499"
[[package]] [[package]]
name = "digest" name = "digest"
version = "0.10.1" version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b697d66081d42af4fba142d56918a3cb21dc8eb63372c6b85d14f44fb9c5979b" checksum = "f2fb860ca6fafa5552fb6d0e816a69c8e49f0908bf524e30a90d97c85892d506"
dependencies = [ dependencies = [
"block-buffer", "block-buffer",
"crypto-common", "crypto-common",
"generic-array",
"subtle", "subtle",
] ]
@ -1128,10 +1128,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f"
[[package]] [[package]]
name = "md5" name = "md-5"
version = "0.3.8" version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79c56d6a0b07f9e19282511c83fc5b086364cbae4ba8c7d5f190c3d9b0425a48" checksum = "658646b21e0b72f7866c7038ab086d3d5e1cd6271f060fd37defb241949d0582"
dependencies = [
"digest",
]
[[package]] [[package]]
name = "memchr" name = "memchr"
@ -1886,9 +1889,9 @@ dependencies = [
[[package]] [[package]]
name = "sha1" name = "sha1"
version = "0.10.0" version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04cc229fb94bcb689ffc39bd4ded842f6ff76885efede7c6d1ffb62582878bea" checksum = "c77f4e7f65455545c2153c1253d25056825e77ee2533f0e41deb65a93a34852f"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
"cpufeatures", "cpufeatures",
@ -1897,9 +1900,9 @@ dependencies = [
[[package]] [[package]]
name = "sha2" name = "sha2"
version = "0.10.1" version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99c3bd8169c58782adad9290a9af5939994036b76187f7b4f0e6de91dbbfc0ec" checksum = "55deaec60f81eefe3cce0dc50bda92d6d8e88f2a27df7c5033b42afeb1ed2676"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
"cpufeatures", "cpufeatures",
@ -1908,9 +1911,9 @@ dependencies = [
[[package]] [[package]]
name = "sha3" name = "sha3"
version = "0.10.0" version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "31f935e31cf406e8c0e96c2815a5516181b7004ae8c5f296293221e9b1e356bd" checksum = "881bf8156c87b6301fc5ca6b27f11eeb2761224c7081e69b409d5a1951a70c86"
dependencies = [ dependencies = [
"digest", "digest",
"keccak", "keccak",
@ -2624,7 +2627,7 @@ dependencies = [
"digest", "digest",
"hex", "hex",
"libc", "libc",
"md5", "md-5",
"memchr 2.4.1", "memchr 2.4.1",
"regex", "regex",
"regex-syntax", "regex-syntax",

View file

@ -20,12 +20,12 @@ clap = { version = "3.0", features = ["wrap_help", "cargo"] }
hex = "0.4.3" hex = "0.4.3"
libc = "0.2.42" libc = "0.2.42"
memchr = "2" memchr = "2"
md5 = "0.3.5" md-5 = "0.10.1"
regex = "1.0.1" regex = "1.0.1"
regex-syntax = "0.6.7" regex-syntax = "0.6.7"
sha1 = "0.10.0" sha1 = "0.10.1"
sha2 = "0.10.1" sha2 = "0.10.2"
sha3 = "0.10.0" sha3 = "0.10.1"
blake2b_simd = "0.5.11" blake2b_simd = "0.5.11"
blake3 = "1.3.1" blake3 = "1.3.1"
uucore = { version=">=0.0.11", package="uucore", path="../../uucore" } uucore = { version=">=0.0.11", package="uucore", path="../../uucore" }

View file

@ -36,28 +36,6 @@ pub trait Digest {
} }
} }
impl Digest for md5::Context {
fn new() -> Self {
Self::new()
}
fn input(&mut self, input: &[u8]) {
self.consume(input);
}
fn result(&mut self, out: &mut [u8]) {
out.copy_from_slice(&*self.compute());
}
fn reset(&mut self) {
*self = Self::new();
}
fn output_bits(&self) -> usize {
128
}
}
impl Digest for blake2b_simd::State { impl Digest for blake2b_simd::State {
fn new() -> Self { fn new() -> Self {
Self::new() Self::new()
@ -104,30 +82,8 @@ impl Digest for blake3::Hasher {
} }
} }
impl Digest for sha1::Sha1 {
fn new() -> Self {
Self::default()
}
fn input(&mut self, input: &[u8]) {
digest::Digest::update(self, input);
}
fn result(&mut self, out: &mut [u8]) {
digest::Digest::finalize_into_reset(self, out.into());
}
fn reset(&mut self) {
*self = Self::new();
}
fn output_bits(&self) -> usize {
160
}
}
// Implements the Digest trait for sha2 / sha3 algorithms with fixed output // Implements the Digest trait for sha2 / sha3 algorithms with fixed output
macro_rules! impl_digest_sha { macro_rules! impl_digest_common {
($type: ty, $size: expr) => { ($type: ty, $size: expr) => {
impl Digest for $type { impl Digest for $type {
fn new() -> Self { fn new() -> Self {
@ -180,15 +136,17 @@ macro_rules! impl_digest_shake {
}; };
} }
impl_digest_sha!(sha2::Sha224, 224); impl_digest_common!(md5::Md5, 128);
impl_digest_sha!(sha2::Sha256, 256); impl_digest_common!(sha1::Sha1, 160);
impl_digest_sha!(sha2::Sha384, 384); impl_digest_common!(sha2::Sha224, 224);
impl_digest_sha!(sha2::Sha512, 512); impl_digest_common!(sha2::Sha256, 256);
impl_digest_common!(sha2::Sha384, 384);
impl_digest_common!(sha2::Sha512, 512);
impl_digest_sha!(sha3::Sha3_224, 224); impl_digest_common!(sha3::Sha3_224, 224);
impl_digest_sha!(sha3::Sha3_256, 256); impl_digest_common!(sha3::Sha3_256, 256);
impl_digest_sha!(sha3::Sha3_384, 384); impl_digest_common!(sha3::Sha3_384, 384);
impl_digest_sha!(sha3::Sha3_512, 512); impl_digest_common!(sha3::Sha3_512, 512);
impl_digest_shake!(sha3::Shake128); impl_digest_shake!(sha3::Shake128);
impl_digest_shake!(sha3::Shake256); impl_digest_shake!(sha3::Shake256);

View file

@ -22,7 +22,7 @@ use self::digest::DigestWriter;
use clap::{App, AppSettings, Arg, ArgMatches}; use clap::{App, AppSettings, Arg, ArgMatches};
use hex::encode; use hex::encode;
use md5::Context as Md5; use md5::Md5;
use regex::Regex; use regex::Regex;
use sha1::Sha1; use sha1::Sha1;
use sha2::{Sha224, Sha256, Sha384, Sha512}; use sha2::{Sha224, Sha256, Sha384, Sha512};