From e7247de6461c130c7ce9b3e666b5c627e331a68e Mon Sep 17 00:00:00 2001
From: librelois <elois@ifee.fr>
Date: Thu, 2 Apr 2020 23:38:11 +0200
Subject: [PATCH] [feat] scrypt KDF can be optional

---
 CHANGELOG.md        | 4 ++++
 Cargo.toml          | 5 +++--
 src/keys/ed25519.rs | 8 +++++++-
 3 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1aa9c9d..f9b6c99 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ## [Unreleased] - ReleaseDate
 
+### Added
+
+- Scrypt KDF can be optional
+
 ## [0.14.0] - 2020-04-02
 
 ### Fixed
diff --git a/Cargo.toml b/Cargo.toml
index 9d7135c..4e0cb0f 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -20,7 +20,7 @@ bs58 = "0.3.0"
 byteorder = "1.3.2"
 curve25519-dalek = "2.0.0"
 ring = "0.16.9"
-scrypt = { version = "0.2", default-features = false }
+scrypt = { version = "0.2", default-features = false, optional = true }
 serde = { version = "1.0.*", features = ["derive"], optional = true }
 thiserror = "1.0.11"
 unwrap = "1.2.1"
@@ -42,8 +42,9 @@ required-features = ["criterion"]
 default = ["dewif", "private_message", "rand", "ser"]
 
 aes256 = ["aes"]
-dewif = ["aes256", "arrayvec"]
+dewif = ["aes256", "arrayvec", "scrypt_feature"]
 x25519 = []
 private_message = ["arrayvec", "x25519", "rand"]
 rand = []
+scrypt_feature = ["scrypt"]
 ser = ["serde"]
diff --git a/src/keys/ed25519.rs b/src/keys/ed25519.rs
index 455aa4a..86df55b 100644
--- a/src/keys/ed25519.rs
+++ b/src/keys/ed25519.rs
@@ -42,6 +42,7 @@ use std::hash::{Hash, Hasher};
 #[cfg(feature = "ser")]
 use std::marker::PhantomData;
 use unwrap::unwrap;
+#[cfg(feature = "scrypt_feature")]
 use zeroize::Zeroize;
 
 /// Size of a public key in bytes
@@ -361,6 +362,7 @@ impl KeyPairFromSeed32Generator {
     }
 }
 
+#[cfg(feature = "scrypt_feature")]
 #[derive(Zeroize)]
 #[zeroize(drop)]
 /// Salted password
@@ -369,19 +371,21 @@ pub struct SaltedPassword {
     password: String,
 }
 
+#[cfg(feature = "scrypt_feature")]
 impl SaltedPassword {
     /// Create new salted password
     pub fn new(salt: String, password: String) -> SaltedPassword {
         SaltedPassword { salt, password }
     }
 }
-
+#[cfg(feature = "scrypt_feature")]
 /// Keypair generator with given parameters for `scrypt` keypair function.
 #[derive(Copy, Clone)]
 pub struct KeyPairFromSaltedPasswordGenerator {
     scrypt_params: scrypt::ScryptParams,
 }
 
+#[cfg(feature = "scrypt_feature")]
 impl KeyPairFromSaltedPasswordGenerator {
     /// Create a `KeyPairGenerator` with default arguments `(log_n: 12, r: 16, p: 1)`
     pub fn with_default_parameters() -> KeyPairFromSaltedPasswordGenerator {
@@ -688,6 +692,7 @@ Timestamp: 0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855
     }
 
     #[test]
+    #[cfg(feature = "scrypt_feature")]
     fn keypair_generate() {
         let key_pair1 = KeyPairFromSaltedPasswordGenerator::with_default_parameters().generate(
             SaltedPassword::new(
@@ -723,6 +728,7 @@ Timestamp: 0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855
 
     #[test]
     #[cfg(feature = "ser")]
+    #[cfg(feature = "scrypt_feature")]
     fn keypair_generate_sign_and_verify() {
         let keypair = KeyPairFromSaltedPasswordGenerator::with_default_parameters().generate(
             SaltedPassword::new("password".to_owned(), "salt".to_owned()),
-- 
GitLab