diff --git a/tor-llcrypto/Cargo.toml b/tor-llcrypto/Cargo.toml index d0172c52d..e7997daf1 100644 --- a/tor-llcrypto/Cargo.toml +++ b/tor-llcrypto/Cargo.toml @@ -29,8 +29,8 @@ version = "*" # Why do I have to use this one? version = "1.0.0-pre.3" -[dependencies.sha1] -version = "0.6.0" +[dependencies.sha-1] +version = "*" [dependencies.sha2] version = "0.8.1" diff --git a/tor-llcrypto/src/d.rs b/tor-llcrypto/src/d.rs index 42badb222..fde11d5aa 100644 --- a/tor-llcrypto/src/d.rs +++ b/tor-llcrypto/src/d.rs @@ -4,52 +4,11 @@ //! SHA3, and SHAKE. We re-export them all here, implementing //! the Digest trait. //! -//! Other code should access these digests via the Digest trait. +//! Other code should access these digests via the Digest trait and +//! its friends. -// These implement Digest, so we can just use them as-is. +pub use sha1::Sha1; pub use sha2::{Sha256, Sha512}; pub use sha3::{Sha3_256, Shake128, Shake256}; -/// A Sha1 implementation that implements the Digest trait. -/// -/// (This is just a thin wrapper around the Sha1 crate.) -#[derive(Clone, Default)] -pub struct Sha1(sha1::Sha1); -use generic_array::GenericArray; - -impl digest::Digest for Sha1 { - type OutputSize = typenum::U20; - - fn new() -> Self { - Sha1(sha1::Sha1::new()) - } - fn output_size() -> usize { - sha1::DIGEST_LENGTH - } - - fn input>(&mut self, data: B) { - self.0.update(data.as_ref()) - } - - fn chain>(mut self, data: B) -> Self { - self.0.update(data.as_ref()); - self - } - fn reset(&mut self) { - self.0.reset(); - } - fn result(self) -> GenericArray { - self.0.digest().bytes().into() - } - - fn result_reset(&mut self) -> GenericArray { - let res = self.0.digest().bytes(); - self.0.reset(); - res.into() - } - - fn digest(data: &[u8]) -> GenericArray { - sha1::Sha1::from(data).digest().bytes().into() - } -} diff --git a/tor-proto/src/crypto/ll/kdf.rs b/tor-proto/src/crypto/ll/kdf.rs index 6be324965..4bf67abc6 100644 --- a/tor-proto/src/crypto/ll/kdf.rs +++ b/tor-proto/src/crypto/ll/kdf.rs @@ -1,5 +1,5 @@ use crate::{Error, Result, SecretBytes}; -use digest::{Digest, ExtendableOutput, Input}; +use digest::{ExtendableOutput, Digest}; use tor_llcrypto::d::{Sha1, Sha256, Shake256}; use zeroize::Zeroizing; @@ -67,6 +67,7 @@ impl ShakeKDF { impl KDF for ShakeKDF { fn derive(&self, seed: &[u8], n_bytes: usize) -> Result { // XXX mark as zero-on-free? + use digest::Input; let mut xof = Shake256::default(); xof.input(seed); Ok(Zeroizing::new(xof.vec_result(n_bytes)))