Commit e7247de6 authored by Éloïs's avatar Éloïs

[feat] scrypt KDF can be optional

parent 69aafdb7
......@@ -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
......
......@@ -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"]
......@@ -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()),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment