From cfcab0977a3267bfc7f52a0d26224753a491bbcb Mon Sep 17 00:00:00 2001 From: Thomas Karpiniec Date: Tue, 9 Aug 2022 22:02:30 +1000 Subject: [PATCH 1/1] Upgrade to maintained hashing libs --- Cargo.lock | 158 ++++++++++++++++++++++------------------------- Cargo.toml | 4 +- src/calculate.rs | 22 +++---- 3 files changed, 87 insertions(+), 97 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8d20390..9e33e6e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -40,6 +40,15 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" +[[package]] +name = "block-buffer" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf7fe51849ea569fd452f37822f606a5cabb684dc918707a0193fd4664ff324" +dependencies = [ + "generic-array", +] + [[package]] name = "cc" version = "1.0.73" @@ -91,6 +100,15 @@ dependencies = [ "x11-clipboard", ] +[[package]] +name = "cpufeatures" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59a6001667ab124aebae2a495118e11d30984c3a653e99d86d58971708cf5e4b" +dependencies = [ + "libc", +] + [[package]] name = "crossbeam-channel" version = "0.5.6" @@ -111,6 +129,26 @@ dependencies = [ "once_cell", ] +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "digest" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2fb860ca6fafa5552fb6d0e816a69c8e49f0908bf524e30a90d97c85892d506" +dependencies = [ + "block-buffer", + "crypto-common", +] + [[package]] name = "dlib" version = "0.5.0" @@ -127,16 +165,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" [[package]] -name = "fuchsia-cprng" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" - -[[package]] -name = "gcc" -version = "0.3.55" +name = "generic-array" +version = "0.14.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" +checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" +dependencies = [ + "typenum", + "version_check", +] [[package]] name = "hashgood" @@ -145,7 +181,9 @@ dependencies = [ "copypasta", "crossbeam-channel", "hex", - "rust-crypto", + "md-5", + "sha1", + "sha2", "structopt", "termcolor", ] @@ -220,6 +258,15 @@ dependencies = [ "libc", ] +[[package]] +name = "md-5" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "658646b21e0b72f7866c7038ab086d3d5e1cd6271f060fd37defb241949d0582" +dependencies = [ + "digest", +] + [[package]] name = "memchr" version = "2.5.0" @@ -377,77 +424,33 @@ dependencies = [ ] [[package]] -name = "rand" -version = "0.3.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64ac302d8f83c0c1974bf758f6b041c6c8ada916fbb44a609158ca8b064cc76c" -dependencies = [ - "libc", - "rand 0.4.6", -] - -[[package]] -name = "rand" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" -dependencies = [ - "fuchsia-cprng", - "libc", - "rand_core 0.3.1", - "rdrand", - "winapi", -] - -[[package]] -name = "rand_core" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" -dependencies = [ - "rand_core 0.4.2", -] - -[[package]] -name = "rand_core" -version = "0.4.2" +name = "scoped-tls" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" +checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" [[package]] -name = "rdrand" -version = "0.4.0" +name = "sha1" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" +checksum = "c77f4e7f65455545c2153c1253d25056825e77ee2533f0e41deb65a93a34852f" dependencies = [ - "rand_core 0.3.1", + "cfg-if", + "cpufeatures", + "digest", ] [[package]] -name = "rust-crypto" -version = "0.2.36" +name = "sha2" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f76d05d3993fd5f4af9434e8e436db163a12a9d40e1a58a726f27a01dfd12a2a" +checksum = "55deaec60f81eefe3cce0dc50bda92d6d8e88f2a27df7c5033b42afeb1ed2676" dependencies = [ - "gcc", - "libc", - "rand 0.3.23", - "rustc-serialize", - "time", + "cfg-if", + "cpufeatures", + "digest", ] -[[package]] -name = "rustc-serialize" -version = "0.3.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda" - -[[package]] -name = "scoped-tls" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" - [[package]] name = "smallvec" version = "1.9.0" @@ -542,15 +545,10 @@ dependencies = [ ] [[package]] -name = "time" -version = "0.1.44" +name = "typenum" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" -dependencies = [ - "libc", - "wasi", - "winapi", -] +checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" [[package]] name = "unicode-ident" @@ -582,12 +580,6 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" -[[package]] -name = "wasi" -version = "0.10.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" - [[package]] name = "wayland-client" version = "0.29.4" diff --git a/Cargo.toml b/Cargo.toml index 6e8afe3..026cf0a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,9 +7,11 @@ edition = "2021" [dependencies] structopt = "0.3.26" hex = "0.4.3" -rust-crypto = "0.2.36" crossbeam-channel = "0.5" termcolor = "1.1" +sha2 = "0.10.2" +sha1 = "0.10.1" +md-5 = "0.10.1" [dependencies.copypasta] version = "0.8.1" diff --git a/src/calculate.rs b/src/calculate.rs index efc3986..6f81e79 100644 --- a/src/calculate.rs +++ b/src/calculate.rs @@ -1,10 +1,9 @@ use super::Algorithm; use crossbeam_channel::bounded; use crossbeam_channel::Receiver; -use crypto::digest::Digest; -use crypto::md5::Md5; -use crypto::sha1::Sha1; -use crypto::sha2::Sha256; +use md5::{Digest, Md5}; +use sha1::Sha1; +use sha2::Sha256; use std::error::Error; use std::fs::File; use std::io::prelude::*; @@ -86,10 +85,9 @@ fn md5_digest(rx: Receiver>>) -> JoinHandle<(Algorithm, Vec)> { thread::spawn(move || { let mut md5 = Md5::new(); while let Ok(chunk) = rx.recv() { - md5.input(&chunk); + md5.update(&*chunk); } - let mut result = [0; 16]; - md5.result(&mut result); + let result = md5.finalize(); (Algorithm::Md5, result.to_vec()) }) } @@ -99,10 +97,9 @@ fn sha1_digest(rx: Receiver>>) -> JoinHandle<(Algorithm, Vec)> { thread::spawn(move || { let mut sha1 = Sha1::new(); while let Ok(chunk) = rx.recv() { - sha1.input(&chunk); + sha1.update(&*chunk); } - let mut result = [0; 20]; - sha1.result(&mut result); + let result = sha1.finalize(); (Algorithm::Sha1, result.to_vec()) }) } @@ -112,10 +109,9 @@ fn sha256_digest(rx: Receiver>>) -> JoinHandle<(Algorithm, Vec)> thread::spawn(move || { let mut sha256 = Sha256::new(); while let Ok(chunk) = rx.recv() { - sha256.input(&chunk); + sha256.update(&*chunk); } - let mut result = [0; 32]; - sha256.result(&mut result); + let result = sha256.finalize(); (Algorithm::Sha256, result.to_vec()) }) } -- 2.39.5