From 80fc493a600972b6875e3e66f9a048273c26830f Mon Sep 17 00:00:00 2001 From: Kevin Lewi Date: Thu, 11 Jun 2020 14:56:34 -0700 Subject: [PATCH] Adding slow-hash feature --- Cargo.toml | 5 ++++- src/slow_hash.rs | 11 +++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 534fffe..f6bd789 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,9 @@ license = "MIT" edition = "2018" readme = "README.md" +[features] +slow-hash = ["scrypt"] + [dependencies] aead = "0.2.0" curve25519-dalek = "2.0.0" @@ -16,7 +19,7 @@ generic-array = "0.12.3" hkdf = "0.8.0" hmac = "0.7.1" rand_core = "0.5.1" -scrypt = "0.2.0" +scrypt = {version = "0.2.0", optional = true} sha2 = "0.8" thiserror = "1" x25519-dalek = "0.6.0" diff --git a/src/slow_hash.rs b/src/slow_hash.rs index 6fac563..ce71545 100644 --- a/src/slow_hash.rs +++ b/src/slow_hash.rs @@ -6,7 +6,6 @@ use crate::errors::InternalPakeError; use generic_array::GenericArray; -use scrypt::{scrypt, ScryptParams}; use sha2::{Digest, Sha256}; pub trait SlowHash { @@ -25,15 +24,15 @@ impl SlowHash for NoOpHash { } } -pub struct Scrypt; - -impl SlowHash for Scrypt { +#[cfg(feature = "slow-hash")] +impl SlowHash for scrypt::ScryptParams { fn hash( input: GenericArray::OutputSize>, ) -> Result, InternalPakeError> { - let params = ScryptParams::new(15, 8, 1).unwrap(); + let params = scrypt::ScryptParams::new(15, 8, 1).unwrap(); let mut output = [0u8; 32]; - scrypt(&input, &[], ¶ms, &mut output).map_err(|_| InternalPakeError::SlowHashError)?; + scrypt::scrypt(&input, &[], ¶ms, &mut output) + .map_err(|_| InternalPakeError::SlowHashError)?; Ok(output.to_vec()) } }