From 80f0ce9d61514885cec232cdcca0c5be9e52777e Mon Sep 17 00:00:00 2001 From: Bryson Steck Date: Mon, 28 Jul 2025 21:15:14 -0600 Subject: [PATCH] add blake3 --- Cargo.lock | 47 +++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + src/hashers.rs | 8 ++++++++ src/main.rs | 4 +++- 4 files changed, 59 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index a138bd6..4bc3526 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -52,6 +52,18 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "arrayref" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76a2e8124351fda1ef8aaaa3bbd7ebbcb486bbcd4225aca0aa0d84bb2db8fecb" + +[[package]] +name = "arrayvec" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" + [[package]] name = "ascon-core" version = "0.5.1" @@ -93,6 +105,19 @@ dependencies = [ "digest 0.10.7", ] +[[package]] +name = "blake3" +version = "1.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3888aaa89e4b2a40fca9848e400f6a658a5a3978de7be858e209cafa8be9a4a0" +dependencies = [ + "arrayref", + "arrayvec", + "cc", + "cfg-if", + "constant_time_eq", +] + [[package]] name = "block-buffer" version = "0.10.4" @@ -111,6 +136,15 @@ dependencies = [ "hybrid-array", ] +[[package]] +name = "cc" +version = "1.2.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "deec109607ca693028562ed836a5f1c4b8bd77755c4e132fc5ce11b0b6211ae7" +dependencies = [ + "shlex", +] + [[package]] name = "cfg-if" version = "1.0.1" @@ -172,6 +206,12 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "constant_time_eq" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c74b8349d32d297c9134b8c88677813a227df8f779daa29bfc29c183fe3dca6" + [[package]] name = "cpufeatures" version = "0.2.17" @@ -370,6 +410,7 @@ dependencies = [ "ascon-hash", "belt-hash", "blake2", + "blake3", "clap", "colored", "fsb", @@ -470,6 +511,12 @@ dependencies = [ "digest 0.10.7", ] +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + [[package]] name = "skein" version = "0.1.1" diff --git a/Cargo.toml b/Cargo.toml index d295e97..b870b51 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,3 +28,4 @@ sm3 = "0.4.2" streebog = "0.10.2" tiger = "0.2.1" whirlpool = "0.10.4" +blake3 = "1.8.2" diff --git a/src/hashers.rs b/src/hashers.rs index 9a6234d..cfc3e1c 100644 --- a/src/hashers.rs +++ b/src/hashers.rs @@ -1,6 +1,7 @@ use ascon_hash::AsconHash256; use belt_hash::BeltHash; use blake2::{Blake2b512, Blake2s256}; +use blake3::Hasher as Blake3; use fsb::{Fsb160, Fsb224, Fsb256, Fsb384, Fsb512}; use gost94::Gost94CryptoPro; use groestl::{Groestl224, Groestl256, Groestl384, Groestl512}; @@ -327,6 +328,13 @@ pub fn hash_belt(mut file: File) -> String { return format!("{:x}", hasher.finalize()); } +pub fn hash_blake3(mut file: File) -> String { + let mut hasher = Blake3::default(); + _ = io::copy(&mut file, &mut hasher); + + return format!("{}", hasher.finalize().to_hex()); +} + pub fn hash_blake2b512(mut file: File) -> String { let mut hasher = Blake2b512::new(); _ = io::copy(&mut file, &mut hasher); diff --git a/src/main.rs b/src/main.rs index f8bb143..1e4cc23 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,9 +9,10 @@ use std::thread::{self, available_parallelism, JoinHandle}; mod common; mod hashers; -const ALGORITHMS: [&'static str; 37] = [ +const ALGORITHMS: [&'static str; 38] = [ "ascon", "belt", + "blake3", "blake2b512", "blake2s256", "fsb160", @@ -170,6 +171,7 @@ fn hash(info: ThreadInfo) -> Result<(), String> { "belt" => hashers::hash_belt(file), "blake2b512" => hashers::hash_blake2b512(file), "blake2s256" => hashers::hash_blake2s256(file), + "blake3" => hashers::hash_blake3(file), "fsb160" => hashers::hash_fsb160(file), "fsb224" => hashers::hash_fsb224(file), "fsb256" => hashers::hash_fsb256(file),