Skip to content
Snippets Groups Projects
Commit e7247de6 authored by Éloïs's avatar Éloïs
Browse files

[feat] scrypt KDF can be optional

parent 69aafdb7
No related branches found
No related tags found
No related merge requests found
...@@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] - ReleaseDate ## [Unreleased] - ReleaseDate
### Added
- Scrypt KDF can be optional
## [0.14.0] - 2020-04-02 ## [0.14.0] - 2020-04-02
### Fixed ### Fixed
......
...@@ -20,7 +20,7 @@ bs58 = "0.3.0" ...@@ -20,7 +20,7 @@ bs58 = "0.3.0"
byteorder = "1.3.2" byteorder = "1.3.2"
curve25519-dalek = "2.0.0" curve25519-dalek = "2.0.0"
ring = "0.16.9" 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 } serde = { version = "1.0.*", features = ["derive"], optional = true }
thiserror = "1.0.11" thiserror = "1.0.11"
unwrap = "1.2.1" unwrap = "1.2.1"
...@@ -42,8 +42,9 @@ required-features = ["criterion"] ...@@ -42,8 +42,9 @@ required-features = ["criterion"]
default = ["dewif", "private_message", "rand", "ser"] default = ["dewif", "private_message", "rand", "ser"]
aes256 = ["aes"] aes256 = ["aes"]
dewif = ["aes256", "arrayvec"] dewif = ["aes256", "arrayvec", "scrypt_feature"]
x25519 = [] x25519 = []
private_message = ["arrayvec", "x25519", "rand"] private_message = ["arrayvec", "x25519", "rand"]
rand = [] rand = []
scrypt_feature = ["scrypt"]
ser = ["serde"] ser = ["serde"]
...@@ -42,6 +42,7 @@ use std::hash::{Hash, Hasher}; ...@@ -42,6 +42,7 @@ use std::hash::{Hash, Hasher};
#[cfg(feature = "ser")] #[cfg(feature = "ser")]
use std::marker::PhantomData; use std::marker::PhantomData;
use unwrap::unwrap; use unwrap::unwrap;
#[cfg(feature = "scrypt_feature")]
use zeroize::Zeroize; use zeroize::Zeroize;
/// Size of a public key in bytes /// Size of a public key in bytes
...@@ -361,6 +362,7 @@ impl KeyPairFromSeed32Generator { ...@@ -361,6 +362,7 @@ impl KeyPairFromSeed32Generator {
} }
} }
#[cfg(feature = "scrypt_feature")]
#[derive(Zeroize)] #[derive(Zeroize)]
#[zeroize(drop)] #[zeroize(drop)]
/// Salted password /// Salted password
...@@ -369,19 +371,21 @@ pub struct SaltedPassword { ...@@ -369,19 +371,21 @@ pub struct SaltedPassword {
password: String, password: String,
} }
#[cfg(feature = "scrypt_feature")]
impl SaltedPassword { impl SaltedPassword {
/// Create new salted password /// Create new salted password
pub fn new(salt: String, password: String) -> SaltedPassword { pub fn new(salt: String, password: String) -> SaltedPassword {
SaltedPassword { salt, password } SaltedPassword { salt, password }
} }
} }
#[cfg(feature = "scrypt_feature")]
/// Keypair generator with given parameters for `scrypt` keypair function. /// Keypair generator with given parameters for `scrypt` keypair function.
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub struct KeyPairFromSaltedPasswordGenerator { pub struct KeyPairFromSaltedPasswordGenerator {
scrypt_params: scrypt::ScryptParams, scrypt_params: scrypt::ScryptParams,
} }
#[cfg(feature = "scrypt_feature")]
impl KeyPairFromSaltedPasswordGenerator { impl KeyPairFromSaltedPasswordGenerator {
/// Create a `KeyPairGenerator` with default arguments `(log_n: 12, r: 16, p: 1)` /// Create a `KeyPairGenerator` with default arguments `(log_n: 12, r: 16, p: 1)`
pub fn with_default_parameters() -> KeyPairFromSaltedPasswordGenerator { pub fn with_default_parameters() -> KeyPairFromSaltedPasswordGenerator {
...@@ -688,6 +692,7 @@ Timestamp: 0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855 ...@@ -688,6 +692,7 @@ Timestamp: 0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855
} }
#[test] #[test]
#[cfg(feature = "scrypt_feature")]
fn keypair_generate() { fn keypair_generate() {
let key_pair1 = KeyPairFromSaltedPasswordGenerator::with_default_parameters().generate( let key_pair1 = KeyPairFromSaltedPasswordGenerator::with_default_parameters().generate(
SaltedPassword::new( SaltedPassword::new(
...@@ -723,6 +728,7 @@ Timestamp: 0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855 ...@@ -723,6 +728,7 @@ Timestamp: 0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855
#[test] #[test]
#[cfg(feature = "ser")] #[cfg(feature = "ser")]
#[cfg(feature = "scrypt_feature")]
fn keypair_generate_sign_and_verify() { fn keypair_generate_sign_and_verify() {
let keypair = KeyPairFromSaltedPasswordGenerator::with_default_parameters().generate( let keypair = KeyPairFromSaltedPasswordGenerator::with_default_parameters().generate(
SaltedPassword::new("password".to_owned(), "salt".to_owned()), SaltedPassword::new("password".to_owned(), "salt".to_owned()),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment