1//! Digests and XOFs used to implement the Tor protocol.
2//!
3//! In various places, for legacy reasons, Tor uses SHA1, SHA2, SHA3,
4//! and SHAKE. We re-export them all here, in forms implementing the
5//! the [`digest::Digest`] traits.
6//!
7//! Other code should access these digests via the traits in the
8//! [`digest`] crate.
910#[cfg(feature = "with-openssl")]
11pub use openssl_compat::Sha1;
12#[cfg(not(feature = "with-openssl"))]
13pub use sha1::Sha1;
1415pub use sha2::{Sha256, Sha512};
16pub use sha3::{Sha3_256, Shake128, Shake256, Shake256Reader};
1718/// Compatibility layer between OpenSSL and `digest`
19#[cfg(feature = "with-openssl")]
20mod openssl_compat {
21use openssl::sha::Sha1 as OpenSslSha1;
2223use digest::{FixedOutput, HashMarker, Output, OutputSizeUser, Update};
2425/// Wrapper around OpenSSL Sha1 to make it compatible with `digest`
26#[derive(Default, Clone)]
27pub struct Sha1(OpenSslSha1);
2829impl Update for Sha1 {
30fn update(&mut self, data: &[u8]) {
31self.0.update(data);
32 }
33 }
3435impl OutputSizeUser for Sha1 {
36type OutputSize = typenum::consts::U20;
37 }
3839impl FixedOutput for Sha1 {
40fn finalize_into(self, out: &mut Output<Self>) {
41*out = self.0.finish().into();
42 }
43 }
4445impl HashMarker for Sha1 {}
46}