Upgrade to a modern version of "sha-1".
Apparently the "sha1" crate doesn't implement the RustCrypto API, but the "sha-1" crate does.
This commit is contained in:
parent
75a1269429
commit
f24ddf0682
|
@ -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"
|
||||
|
|
|
@ -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<B: AsRef<[u8]>>(&mut self, data: B) {
|
||||
self.0.update(data.as_ref())
|
||||
}
|
||||
|
||||
fn chain<B: AsRef<[u8]>>(mut self, data: B) -> Self {
|
||||
self.0.update(data.as_ref());
|
||||
self
|
||||
}
|
||||
fn reset(&mut self) {
|
||||
self.0.reset();
|
||||
}
|
||||
fn result(self) -> GenericArray<u8, Self::OutputSize> {
|
||||
self.0.digest().bytes().into()
|
||||
}
|
||||
|
||||
fn result_reset(&mut self) -> GenericArray<u8, Self::OutputSize> {
|
||||
let res = self.0.digest().bytes();
|
||||
self.0.reset();
|
||||
res.into()
|
||||
}
|
||||
|
||||
fn digest(data: &[u8]) -> GenericArray<u8, Self::OutputSize> {
|
||||
sha1::Sha1::from(data).digest().bytes().into()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<SecretBytes> {
|
||||
// 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)))
|
||||
|
|
Loading…
Reference in New Issue