mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
hashsum: Add BLAKE3 to Hashing Algorithms
Signed-off-by: Shreyans Jain <shreyansthebest2007@gmail.com>
This commit is contained in:
parent
e5be9c1aaf
commit
30d7a4b167
7 changed files with 66 additions and 1 deletions
30
Cargo.lock
generated
30
Cargo.lock
generated
|
@ -50,6 +50,12 @@ version = "0.5.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
|
checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "arrayvec"
|
||||||
|
version = "0.7.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "atty"
|
name = "atty"
|
||||||
version = "0.2.14"
|
version = "0.2.14"
|
||||||
|
@ -123,10 +129,24 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "afa748e348ad3be8263be728124b24a24f268266f6f5d58af9d75f6a40b5c587"
|
checksum = "afa748e348ad3be8263be728124b24a24f268266f6f5d58af9d75f6a40b5c587"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrayref",
|
"arrayref",
|
||||||
"arrayvec",
|
"arrayvec 0.5.2",
|
||||||
"constant_time_eq",
|
"constant_time_eq",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "blake3"
|
||||||
|
version = "1.3.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a08e53fc5a564bb15bfe6fae56bd71522205f1f91893f9c0116edad6496c183f"
|
||||||
|
dependencies = [
|
||||||
|
"arrayref",
|
||||||
|
"arrayvec 0.7.2",
|
||||||
|
"cc",
|
||||||
|
"cfg-if 1.0.0",
|
||||||
|
"constant_time_eq",
|
||||||
|
"digest",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "block-buffer"
|
name = "block-buffer"
|
||||||
version = "0.10.0"
|
version = "0.10.0"
|
||||||
|
@ -670,6 +690,7 @@ dependencies = [
|
||||||
"block-buffer",
|
"block-buffer",
|
||||||
"crypto-common",
|
"crypto-common",
|
||||||
"generic-array",
|
"generic-array",
|
||||||
|
"subtle",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1850,6 +1871,12 @@ dependencies = [
|
||||||
"syn",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "subtle"
|
||||||
|
version = "2.4.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "1.0.86"
|
version = "1.0.86"
|
||||||
|
@ -2375,6 +2402,7 @@ name = "uu_hashsum"
|
||||||
version = "0.0.12"
|
version = "0.0.12"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"blake2b_simd",
|
"blake2b_simd",
|
||||||
|
"blake3",
|
||||||
"clap 3.0.10",
|
"clap 3.0.10",
|
||||||
"digest",
|
"digest",
|
||||||
"hex",
|
"hex",
|
||||||
|
|
|
@ -27,6 +27,7 @@ sha1 = "0.6.0"
|
||||||
sha2 = "0.10.1"
|
sha2 = "0.10.1"
|
||||||
sha3 = "0.10.0"
|
sha3 = "0.10.0"
|
||||||
blake2b_simd = "0.5.11"
|
blake2b_simd = "0.5.11"
|
||||||
|
blake3 = "1.3.1"
|
||||||
uucore = { version=">=0.0.11", package="uucore", path="../../uucore" }
|
uucore = { version=">=0.0.11", package="uucore", path="../../uucore" }
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
|
|
|
@ -81,6 +81,29 @@ impl Digest for blake2b_simd::State {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Digest for blake3::Hasher {
|
||||||
|
fn new() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn input(&mut self, input: &[u8]) {
|
||||||
|
self.update(input);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn result(&mut self, out: &mut [u8]) {
|
||||||
|
let hash_result = &self.finalize();
|
||||||
|
out.copy_from_slice(hash_result.as_bytes());
|
||||||
|
}
|
||||||
|
|
||||||
|
fn reset(&mut self) {
|
||||||
|
*self = Self::new();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn output_bits(&self) -> usize {
|
||||||
|
256
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Digest for sha1::Sha1 {
|
impl Digest for sha1::Sha1 {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
Self::new()
|
Self::new()
|
||||||
|
|
|
@ -70,6 +70,7 @@ fn is_custom_binary(program: &str) -> bool {
|
||||||
| "shake128sum"
|
| "shake128sum"
|
||||||
| "shake256sum"
|
| "shake256sum"
|
||||||
| "b2sum"
|
| "b2sum"
|
||||||
|
| "b3sum"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,6 +94,11 @@ fn detect_algo(
|
||||||
Box::new(blake2b_simd::State::new()) as Box<dyn Digest>,
|
Box::new(blake2b_simd::State::new()) as Box<dyn Digest>,
|
||||||
512,
|
512,
|
||||||
),
|
),
|
||||||
|
"b3sum" => (
|
||||||
|
"BLAKE3",
|
||||||
|
Box::new(blake3::Hasher::new()) as Box<dyn Digest>,
|
||||||
|
256,
|
||||||
|
),
|
||||||
"sha3sum" => match matches.value_of("bits") {
|
"sha3sum" => match matches.value_of("bits") {
|
||||||
Some(bits_str) => match (bits_str).parse::<usize>() {
|
Some(bits_str) => match (bits_str).parse::<usize>() {
|
||||||
Ok(224) => (
|
Ok(224) => (
|
||||||
|
@ -196,6 +202,9 @@ fn detect_algo(
|
||||||
if matches.is_present("b2sum") {
|
if matches.is_present("b2sum") {
|
||||||
set_or_crash("BLAKE2", Box::new(blake2b_simd::State::new()), 512);
|
set_or_crash("BLAKE2", Box::new(blake2b_simd::State::new()), 512);
|
||||||
}
|
}
|
||||||
|
if matches.is_present("b3sum") {
|
||||||
|
set_or_crash("BLAKE3", Box::new(blake3::Hasher::new()), 256);
|
||||||
|
}
|
||||||
if matches.is_present("sha3") {
|
if matches.is_present("sha3") {
|
||||||
match matches.value_of("bits") {
|
match matches.value_of("bits") {
|
||||||
Some(bits_str) => match (bits_str).parse::<usize>() {
|
Some(bits_str) => match (bits_str).parse::<usize>() {
|
||||||
|
@ -433,6 +442,7 @@ pub fn uu_app_custom<'a>() -> App<'a> {
|
||||||
"work with SHAKE256 using BITS for the output size",
|
"work with SHAKE256 using BITS for the output size",
|
||||||
),
|
),
|
||||||
("b2sum", "work with BLAKE2"),
|
("b2sum", "work with BLAKE2"),
|
||||||
|
("b3sum", "work with BLAKE3"),
|
||||||
];
|
];
|
||||||
|
|
||||||
for (name, desc) in algorithms {
|
for (name, desc) in algorithms {
|
||||||
|
|
|
@ -80,4 +80,5 @@ test_digest! {
|
||||||
shake128_256 shake128 256
|
shake128_256 shake128 256
|
||||||
shake256_512 shake256 512
|
shake256_512 shake256 512
|
||||||
b2sum b2sum 512
|
b2sum b2sum 512
|
||||||
|
b3sum b3sum 256
|
||||||
}
|
}
|
||||||
|
|
1
tests/fixtures/hashsum/b3sum.checkfile
vendored
Normal file
1
tests/fixtures/hashsum/b3sum.checkfile
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
a1a55887535397bf461902491c8779188a5dd1f8c3951b3d9cf6ecba194e87b0 input.txt
|
1
tests/fixtures/hashsum/b3sum.expected
vendored
Normal file
1
tests/fixtures/hashsum/b3sum.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
a1a55887535397bf461902491c8779188a5dd1f8c3951b3d9cf6ecba194e87b0
|
Loading…
Add table
Add a link
Reference in a new issue