diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..4b2eab2 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "hashes"] + path = hashes + url = https://github.com/RustCrypto/hashes diff --git a/Cargo.lock b/Cargo.lock index 04d8605..bfff7ec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -52,6 +52,47 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "ascon-core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c90c8493a0b3bf8678a82f096821a2c527dd6344bbcef6265bfcc09745f44e24" + +[[package]] +name = "ascon-hash" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9a9c93d95a4f3344947e14ad2fd9c1d2ea789c8f8ecef6a906b9ac295301763" +dependencies = [ + "ascon-core", + "digest 0.10.7", +] + +[[package]] +name = "belt-block" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9aa1eef3994e2ccd304a78fe3fea4a73e5792007f85f09b79bb82143ca5f82b" + +[[package]] +name = "belt-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbc405b3b8472f6e019aedf942fdee9516a0546d12e053d3744416e8f21ddb8a" +dependencies = [ + "belt-block", + "digest 0.10.7", +] + +[[package]] +name = "blake2" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46502ad458c9a52b69d4d4d32775c788b7a1b85e8bc9d482d92250fc0e3f8efe" +dependencies = [ + "digest 0.10.7", +] + [[package]] name = "block-buffer" version = "0.10.4" @@ -61,6 +102,15 @@ dependencies = [ "generic-array", ] +[[package]] +name = "block-buffer" +version = "0.11.0-rc.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a229bfd78e4827c91b9b95784f69492c1b77c1ab75a45a8a037b139215086f94" +dependencies = [ + "hybrid-array", +] + [[package]] name = "cfg-if" version = "1.0.1" @@ -141,14 +191,44 @@ dependencies = [ "typenum", ] +[[package]] +name = "crypto-common" +version = "0.2.0-rc.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a23fa214dea9efd4dacee5a5614646b30216ae0f05d4bb51bafb50e9da1c5be" +dependencies = [ + "hybrid-array", +] + [[package]] name = "digest" version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ - "block-buffer", - "crypto-common", + "block-buffer 0.10.4", + "crypto-common 0.1.6", + "subtle", +] + +[[package]] +name = "digest" +version = "0.11.0-rc.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "460dd7f37e4950526b54a5a6b1f41b6c8e763c58eb9a8fc8fc05ba5c2f44ca7b" +dependencies = [ + "block-buffer 0.11.0-rc.4", + "crypto-common 0.2.0-rc.3", +] + +[[package]] +name = "fsb" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e54a22467e3d3e1b2d014c67cb074fe361d80e3293ffab4128918313eaf737c8" +dependencies = [ + "digest 0.10.7", + "whirlpool", ] [[package]] @@ -161,18 +241,88 @@ dependencies = [ "version_check", ] +[[package]] +name = "gost94" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f960e0ba8eb5e47a7d45097dc4159b5ef63d82e62dc85894bfcfd8e6b85526c" +dependencies = [ + "digest 0.10.7", +] + +[[package]] +name = "groestl" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "343cfc165f92a988fd60292f7a0bfde4352a5a0beff9fbec29251ca4e9676e4d" +dependencies = [ + "digest 0.10.7", +] + [[package]] name = "heck" version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" +[[package]] +name = "hex-literal" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" + +[[package]] +name = "hybrid-array" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "891d15931895091dea5c47afa5b3c9a01ba634b311919fd4d41388fa0e3d76af" +dependencies = [ + "typenum", +] + [[package]] name = "is_terminal_polyfill" version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" +[[package]] +name = "jh" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f65735f9e73adc203417d2e05352aef71d7e832ec090f65de26c96c9ec563aa5" +dependencies = [ + "digest 0.10.7", + "hex-literal", + "ppv-lite86", +] + +[[package]] +name = "k12" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4dc5fdb62af2f520116927304f15d25b3c2667b4817b90efdc045194c912c54" +dependencies = [ + "digest 0.10.7", + "sha3", +] + +[[package]] +name = "keccak" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecc2af9a1119c51f12a14607e783cb977bde58bc069ff0c3da1095e635d70654" +dependencies = [ + "cpufeatures", +] + +[[package]] +name = "kupyna" +version = "0.1.0" +dependencies = [ + "digest 0.11.0-rc.0", +] + [[package]] name = "libc" version = "0.2.174" @@ -186,7 +336,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf" dependencies = [ "cfg-if", - "digest", + "digest 0.10.7", +] + +[[package]] +name = "md2" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f4f0f3ed25ff4f8d8d102288d92f900efc202661c884cf67dfe4f0d07c43d1f" +dependencies = [ + "digest 0.10.7", +] + +[[package]] +name = "md4" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da5ac363534dce5fabf69949225e174fbf111a498bf0ff794c8ea1fba9f3dda" +dependencies = [ + "digest 0.10.7", ] [[package]] @@ -195,6 +363,15 @@ version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad" +[[package]] +name = "ppv-lite86" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy", +] + [[package]] name = "proc-macro2" version = "1.0.95" @@ -206,12 +383,32 @@ dependencies = [ [[package]] name = "psha" -version = "0.1.0" +version = "0.2.0" dependencies = [ + "ascon-hash", + "belt-hash", + "blake2", "clap", "colored", + "fsb", + "gost94", + "groestl", + "jh", + "k12", + "kupyna", "md-5", + "md2", + "md4", + "ripemd", + "sha1", "sha2", + "sha3", + "shabal", + "skein", + "sm3", + "streebog", + "tiger", + "whirlpool", ] [[package]] @@ -223,6 +420,26 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "ripemd" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd124222d17ad93a644ed9d011a40f4fb64aa54275c08cc216524a9ea82fb09f" +dependencies = [ + "digest 0.10.7", +] + +[[package]] +name = "sha1" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest 0.10.7", +] + [[package]] name = "sha2" version = "0.10.9" @@ -231,7 +448,54 @@ checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" dependencies = [ "cfg-if", "cpufeatures", - "digest", + "digest 0.10.7", +] + +[[package]] +name = "sha3" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60" +dependencies = [ + "digest 0.10.7", + "keccak", +] + +[[package]] +name = "shabal" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "990a6c7ff96ecc5664129bbf1f7b46a5a7c13f297d05af75e702f861cea6f08a" +dependencies = [ + "digest 0.10.7", +] + +[[package]] +name = "skein" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96a90a220ab98dbbfeabeae7c558a79f37839c10b9ef55c77082a741a463cab7" +dependencies = [ + "digest 0.10.7", + "threefish", +] + +[[package]] +name = "sm3" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebb9a3b702d0a7e33bc4d85a14456633d2b165c2ad839c5fd9a8417c1ab15860" +dependencies = [ + "digest 0.10.7", +] + +[[package]] +name = "streebog" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e7fe6ed8a42cec360e070309427bb7959e102849b0dbaa7de19d5b9860bd536" +dependencies = [ + "digest 0.10.7", ] [[package]] @@ -240,6 +504,12 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + [[package]] name = "syn" version = "2.0.104" @@ -251,6 +521,21 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "threefish" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a693d0c8cf16973fac5a93fbe47b8c6452e7097d4fcac49f3d7a18e39c76e62e" + +[[package]] +name = "tiger" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "579abbce4ad73b04386dbeb34369c9873a8f9b749c7b99cbf479a2949ff715ed" +dependencies = [ + "digest 0.10.7", +] + [[package]] name = "typenum" version = "1.18.0" @@ -275,6 +560,15 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" +[[package]] +name = "whirlpool" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1ae50671d985c15b3214c7d969b8b520759fb3c8682444bec15ef775335a05c" +dependencies = [ + "digest 0.10.7", +] + [[package]] name = "windows-sys" version = "0.59.0" @@ -347,3 +641,23 @@ name = "windows_x86_64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.8.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1039dd0d3c310cf05de012d8a39ff557cb0d23087fd44cad61df08fc31907a2f" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ecf5b4cc5364572d7f4c329661bcc82724222973f2cab6f050a4e5c22f75181" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] diff --git a/Cargo.toml b/Cargo.toml index b1cf634..70640ad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "psha" -version = "0.1.0" +version = "0.2.0" edition = "2021" [dependencies] @@ -8,3 +8,23 @@ sha2 = "0.10.9" clap = { version = "4.5.29", features = ["derive"] } colored = "3.0.0" md-5 = "0.10.6" +ascon-hash = "0.3.1" +belt-hash = "0.1.1" +blake2 = "0.10.6" +fsb = "0.1.3" +gost94 = "0.10.4" +groestl = "0.10.1" +jh = "0.1.0" +k12 = "0.3.0" +kupyna = { path = "./hashes/kupyna" } +md2 = "0.10.2" +md4 = "0.10.2" +ripemd = "0.1.3" +sha1 = "0.10.6" +sha3 = "0.10.8" +shabal = "0.4.1" +skein = "0.1.1" +sm3 = "0.4.2" +streebog = "0.10.2" +tiger = "0.2.1" +whirlpool = "0.10.4" diff --git a/hashes b/hashes new file mode 160000 index 0000000..57f5b8b --- /dev/null +++ b/hashes @@ -0,0 +1 @@ +Subproject commit 57f5b8b0cd38ad883a85e1b5d5a51168f24ed408 diff --git a/src/hashers.rs b/src/hashers.rs index 8bd4a9b..e964e34 100644 --- a/src/hashers.rs +++ b/src/hashers.rs @@ -1,7 +1,379 @@ -use sha2::{Digest, Sha256, Sha384, Sha512}; +use ascon_hash::AsconHash256; +use belt_hash::BeltHash; +use blake2::{Blake2b512, Blake2s256}; +use fsb::{Fsb160, Fsb224, Fsb256, Fsb384, Fsb512}; +use gost94::Gost94CryptoPro; +use groestl::{Groestl224, Groestl256, Groestl384, Groestl512}; +use jh::{ + // digest::{core_api::CoreWrapper, KeyInit}, + Jh224, + Jh256, + Jh384, + Jh512, +}; +// use k12::KangarooTwelve; +// use kupyna::{Kupyna224, Kupyna256, Kupyna384, Kupyna512}; +use md2::Md2; +use md4::Md4; use md5::Md5; +use ripemd::{Ripemd128, Ripemd160, Ripemd256, Ripemd320}; +use sha2::{Digest, Sha224, Sha256, Sha384, Sha512}; +// use sha3::{Sha3_224, Sha3_256, Sha3_384, Sha3_512, Shake128, Shake256}; +use sha3::{Sha3_224, Sha3_256, Sha3_384, Sha3_512}; +use shabal::{Shabal192, Shabal224, Shabal256, Shabal384, Shabal512}; +// use skein::{ +// digest::{core_api::CoreWrapper, KeyInit}, +// Skein1024, Skein256, Skein512, +// }; +use sm3::Sm3; use std::fs::File; use std::io; +use streebog::{Streebog256, Streebog512}; +use tiger::Tiger; +use whirlpool::Whirlpool; + +pub fn hash_streebog256(mut file: File) -> String { + let mut hasher = Streebog256::new(); + _ = io::copy(&mut file, &mut hasher); + + return format!("{:x}", hasher.finalize()); +} + +pub fn hash_streebog512(mut file: File) -> String { + let mut hasher = Streebog512::new(); + _ = io::copy(&mut file, &mut hasher); + + return format!("{:x}", hasher.finalize()); +} + +pub fn hash_tiger(mut file: File) -> String { + let mut hasher = Tiger::new(); + _ = io::copy(&mut file, &mut hasher); + + return format!("{:x}", hasher.finalize()); +} + +pub fn hash_whirlpool(mut file: File) -> String { + let mut hasher = Whirlpool::new(); + _ = io::copy(&mut file, &mut hasher); + + return format!("{:x}", hasher.finalize()); +} + +pub fn hash_sha224(mut file: File) -> String { + let mut hasher = Sha224::new(); + _ = io::copy(&mut file, &mut hasher); + + return format!("{:x}", hasher.finalize()); +} + +pub fn hash_sm3(mut file: File) -> String { + let mut hasher = Sm3::new(); + _ = io::copy(&mut file, &mut hasher); + + return format!("{:x}", hasher.finalize()); +} + +pub fn hash_sha3_224(mut file: File) -> String { + let mut hasher = Sha3_224::new(); + _ = io::copy(&mut file, &mut hasher); + + return format!("{:x}", hasher.finalize()); +} + +pub fn hash_sha3_256(mut file: File) -> String { + let mut hasher = Sha3_256::new(); + _ = io::copy(&mut file, &mut hasher); + + return format!("{:x}", hasher.finalize()); +} + +pub fn hash_sha3_384(mut file: File) -> String { + let mut hasher = Sha3_384::new(); + _ = io::copy(&mut file, &mut hasher); + + return format!("{:x}", hasher.finalize()); +} + +pub fn hash_sha3_512(mut file: File) -> String { + let mut hasher = Sha3_512::new(); + _ = io::copy(&mut file, &mut hasher); + + return format!("{:x}", hasher.finalize()); +} + +// pub fn hash_shake128(mut file: File) -> String { +// let mut hasher: CoreWrapper<_> = Shake128::new(); +// _ = io::copy(&mut file, &mut hasher); + +// return format!("{:x}", hasher.finalize()); +// } + +// pub fn hash_shake256(mut file: File) -> String { +// let mut hasher = Shake256::new(); +// _ = io::copy(&mut file, &mut hasher); + +// return format!("{:x}", hasher.finalize()); +// } + +pub fn hash_shabal192(mut file: File) -> String { + let mut hasher = Shabal192::new(); + _ = io::copy(&mut file, &mut hasher); + + return format!("{:x}", hasher.finalize()); +} + +pub fn hash_shabal224(mut file: File) -> String { + let mut hasher = Shabal224::new(); + _ = io::copy(&mut file, &mut hasher); + + return format!("{:x}", hasher.finalize()); +} + +pub fn hash_shabal256(mut file: File) -> String { + let mut hasher = Shabal256::new(); + _ = io::copy(&mut file, &mut hasher); + + return format!("{:x}", hasher.finalize()); +} + +pub fn hash_shabal384(mut file: File) -> String { + let mut hasher = Shabal384::new(); + _ = io::copy(&mut file, &mut hasher); + + return format!("{:x}", hasher.finalize()); +} + +pub fn hash_shabal512(mut file: File) -> String { + let mut hasher = Shabal512::new(); + _ = io::copy(&mut file, &mut hasher); + + return format!("{:x}", hasher.finalize()); +} + +// pub fn hash_skein256(mut file: File) -> String { +// let mut hasher = Skein256::new(); +// _ = io::copy(&mut file, &mut hasher); + +// return format!("{:x}", hasher.finalize()); +// } + +// pub fn hash_skein512(mut file: File) -> String { +// let mut hasher = Skein512::new(); +// _ = io::copy(&mut file, &mut hasher); + +// return format!("{:x}", hasher.finalize()); +// } + +// pub fn hash_skein1024(mut file: File) -> String { +// let mut hasher = Skein1024::new(); +// _ = io::copy(&mut file, &mut hasher); + +// return format!("{:x}", hasher.finalize()); +// } + +pub fn hash_gost94(mut file: File) -> String { + let mut hasher = Gost94CryptoPro::new(); + _ = io::copy(&mut file, &mut hasher); + + return format!("{:x}", hasher.finalize()); +} + +pub fn hash_groestl224(mut file: File) -> String { + let mut hasher = Groestl224::new(); + _ = io::copy(&mut file, &mut hasher); + + return format!("{:x}", hasher.finalize()); +} + +pub fn hash_groestl256(mut file: File) -> String { + let mut hasher = Groestl256::new(); + _ = io::copy(&mut file, &mut hasher); + + return format!("{:x}", hasher.finalize()); +} + +pub fn hash_groestl384(mut file: File) -> String { + let mut hasher = Groestl384::new(); + _ = io::copy(&mut file, &mut hasher); + + return format!("{:x}", hasher.finalize()); +} + +pub fn hash_groestl512(mut file: File) -> String { + let mut hasher = Groestl512::new(); + _ = io::copy(&mut file, &mut hasher); + + return format!("{:x}", hasher.finalize()); +} + +pub fn hash_jh224(mut file: File) -> String { + let mut hasher = Jh224::new(); + _ = io::copy(&mut file, &mut hasher); + + return format!("{:x}", hasher.finalize()); +} + +pub fn hash_jh256(mut file: File) -> String { + let mut hasher = Jh256::new(); + _ = io::copy(&mut file, &mut hasher); + + return format!("{:x}", hasher.finalize()); +} + +pub fn hash_jh384(mut file: File) -> String { + let mut hasher = Jh384::new(); + _ = io::copy(&mut file, &mut hasher); + + return format!("{:x}", hasher.finalize()); +} + +pub fn hash_jh512(mut file: File) -> String { + let mut hasher = Jh512::new(); + _ = io::copy(&mut file, &mut hasher); + + return format!("{:x}", hasher.finalize()); +} + +// pub fn hash_k12(mut file: File) -> String { +// let mut hasher = KangarooTwelve::new(); +// _ = io::copy(&mut file, &mut hasher); + +// return format!("{:x}", hasher.finalize()); +// } + +// pub fn hash_kupyna224(mut file: File) -> String { +// let mut hasher = Kupyna224::new(); +// _ = io::copy(&mut file, &mut hasher); + +// return format!("{:x}", hasher.finalize()); +// } + +// pub fn hash_kupyna256(mut file: File) -> String { +// let mut hasher = Kupyna256::new(); +// _ = io::copy(&mut file, &mut hasher); + +// return format!("{:x}", hasher.finalize()); +// } + +// pub fn hash_kupyna384(mut file: File) -> String { +// let mut hasher = Kupyna384::new(); +// _ = io::copy(&mut file, &mut hasher); + +// return format!("{:x}", hasher.finalize()); +// } + +// pub fn hash_kupyna512(mut file: File) -> String { +// let mut hasher = Kupyna512::new(); +// _ = io::copy(&mut file, &mut hasher); + +// return format!("{:x}", hasher.finalize()); +// } + +pub fn hash_md2(mut file: File) -> String { + let mut hasher = Md2::new(); + _ = io::copy(&mut file, &mut hasher); + + return format!("{:x}", hasher.finalize()); +} + +pub fn hash_md4(mut file: File) -> String { + let mut hasher = Md4::new(); + _ = io::copy(&mut file, &mut hasher); + + return format!("{:x}", hasher.finalize()); +} + +pub fn hash_ripemd128(mut file: File) -> String { + let mut hasher = Ripemd128::new(); + _ = io::copy(&mut file, &mut hasher); + + return format!("{:x}", hasher.finalize()); +} + +pub fn hash_ripemd160(mut file: File) -> String { + let mut hasher = Ripemd160::new(); + _ = io::copy(&mut file, &mut hasher); + + return format!("{:x}", hasher.finalize()); +} + +pub fn hash_ripemd256(mut file: File) -> String { + let mut hasher = Ripemd256::new(); + _ = io::copy(&mut file, &mut hasher); + + return format!("{:x}", hasher.finalize()); +} + +pub fn hash_ripemd320(mut file: File) -> String { + let mut hasher = Ripemd320::new(); + _ = io::copy(&mut file, &mut hasher); + + return format!("{:x}", hasher.finalize()); +} + +pub fn hash_ascon(mut file: File) -> String { + let mut hasher = AsconHash256::new(); + _ = io::copy(&mut file, &mut hasher); + + return format!("{:x}", hasher.finalize()); +} + +pub fn hash_belt(mut file: File) -> String { + let mut hasher = BeltHash::new(); + _ = io::copy(&mut file, &mut hasher); + + return format!("{:x}", hasher.finalize()); +} + +pub fn hash_blake2b512(mut file: File) -> String { + let mut hasher = Blake2b512::new(); + _ = io::copy(&mut file, &mut hasher); + + return format!("{:x}", hasher.finalize()); +} + +pub fn hash_blake2s256(mut file: File) -> String { + let mut hasher = Blake2s256::new(); + _ = io::copy(&mut file, &mut hasher); + + return format!("{:x}", hasher.finalize()); +} + +pub fn hash_fsb160(mut file: File) -> String { + let mut hasher = Fsb160::new(); + _ = io::copy(&mut file, &mut hasher); + + return format!("{:x}", hasher.finalize()); +} + +pub fn hash_fsb224(mut file: File) -> String { + let mut hasher = Fsb224::new(); + _ = io::copy(&mut file, &mut hasher); + + return format!("{:x}", hasher.finalize()); +} + +pub fn hash_fsb256(mut file: File) -> String { + let mut hasher = Fsb256::new(); + _ = io::copy(&mut file, &mut hasher); + + return format!("{:x}", hasher.finalize()); +} + +pub fn hash_fsb384(mut file: File) -> String { + let mut hasher = Fsb384::new(); + _ = io::copy(&mut file, &mut hasher); + + return format!("{:x}", hasher.finalize()); +} + +pub fn hash_fsb512(mut file: File) -> String { + let mut hasher = Fsb512::new(); + _ = io::copy(&mut file, &mut hasher); + + return format!("{:x}", hasher.finalize()); +} pub fn hash_md5(mut file: File) -> String { let mut hasher = Md5::new(); diff --git a/src/main.rs b/src/main.rs index ed7216d..a2dba18 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,8 +5,8 @@ use std::path::PathBuf; use std::sync::{Arc, Mutex}; use std::thread::{self, available_parallelism}; -mod hashers; mod common; +mod hashers; const ALGORITHMS: [&'static str; 3] = ["sha256", "sha384", "sha512"]; const UNSECURE_ALGORITHMS: [&'static str; 1] = ["md5"]; @@ -118,14 +118,23 @@ fn hash(info: ThreadInfo) -> Result<(), String> { common::error(format!("{}: {}", filename.as_path().display(), e)); continue; }, - Ok(f) => f + Ok(f) => f, }; let res = match &*info.algorithm.as_str() { + "ascon" => hashers::hash_ascon(file), + "belt" => hashers::hash_belt(file), + "blake2b512" => hashers::hash_blake2b512(file), + "blake2s256" => hashers::hash_blake2s256(file), + "fsb160" => hashers::hash_fsb160(file), + "fsb224" => hashers::hash_fsb224(file), + "fsb256" => hashers::hash_fsb256(file), + "fsb384" => hashers::hash_fsb384(file), + "fsb512" => hashers::hash_fsb512(file), + "md5" => hashers::hash_md5(file), "sha256" => hashers::hash_sha256(file), "sha384" => hashers::hash_sha384(file), "sha512" => hashers::hash_sha512(file), - "md5" => hashers::hash_md5(file), _ => panic!("Somehow did not pass a supported algorithm"), }; @@ -158,15 +167,21 @@ fn main() { let cpus = match args.threads { 0 => available_parallelism().unwrap().get(), - _ => args.threads + _ => args.threads, }; if args.debug { - common::debug(format!("Starting psha using algorithm {} with {} threads", args.algorithm, cpus)); + common::debug(format!( + "Starting psha using algorithm {} with {} threads", + args.algorithm, cpus + )); } if UNSECURE_ALGORITHMS.contains(&args.algorithm.as_str()) { - common::warning(format!("{} is an unsecure hashing algorithm!", &args.algorithm)); + common::warning(format!( + "{} is an unsecure hashing algorithm!", + &args.algorithm + )); } let arc_buf = Arc::new(Mutex::new(buffer)); @@ -191,5 +206,4 @@ fn main() { Ok(_) => (), } } - }