Switch to RustCrypto for pbkdf2.

This commit is contained in:
Emmanuel Gil Peyrot 2019-01-17 23:59:31 +01:00
parent 288a2a0489
commit 511eb47be9
2 changed files with 4 additions and 4 deletions

View file

@ -24,6 +24,7 @@ rand_os = "0.1"
sha-1 = "0.8" sha-1 = "0.8"
sha2 = "0.8" sha2 = "0.8"
hmac = "0.7" hmac = "0.7"
pbkdf2 = { version = "0.3", default-features = false }
[dependencies.openssl] [dependencies.openssl]
version = "0.10.7" version = "0.10.7"

View file

@ -1,9 +1,8 @@
use openssl::pkcs5::pbkdf2_hmac;
use openssl::hash::MessageDigest;
use rand_os::{OsRng, rand_core::{RngCore, Error as RngError}}; use rand_os::{OsRng, rand_core::{RngCore, Error as RngError}};
use sha1::{Sha1 as Sha1_hash, Digest}; use sha1::{Sha1 as Sha1_hash, Digest};
use sha2::Sha256 as Sha256_hash; use sha2::Sha256 as Sha256_hash;
use hmac::{Hmac, Mac}; use hmac::{Hmac, Mac};
use pbkdf2::pbkdf2;
use crate::common::Password; use crate::common::Password;
@ -66,7 +65,7 @@ impl ScramProvider for Sha1 { // TODO: look at all these unwraps
match *password { match *password {
Password::Plain(ref plain) => { Password::Plain(ref plain) => {
let mut result = vec![0; 20]; let mut result = vec![0; 20];
pbkdf2_hmac(plain.as_bytes(), salt, iterations, MessageDigest::sha1(), &mut result).unwrap(); pbkdf2::<Hmac<Sha1_hash>>(plain.as_bytes(), salt, iterations, &mut result);
Ok(result) Ok(result)
}, },
Password::Pbkdf2 { ref method, salt: ref my_salt, iterations: my_iterations, ref data } => { Password::Pbkdf2 { ref method, salt: ref my_salt, iterations: my_iterations, ref data } => {
@ -116,7 +115,7 @@ impl ScramProvider for Sha256 { // TODO: look at all these unwraps
match *password { match *password {
Password::Plain(ref plain) => { Password::Plain(ref plain) => {
let mut result = vec![0; 32]; let mut result = vec![0; 32];
pbkdf2_hmac(plain.as_bytes(), salt, iterations, MessageDigest::sha256(), &mut result).unwrap(); pbkdf2::<Hmac<Sha256_hash>>(plain.as_bytes(), salt, iterations, &mut result);
Ok(result) Ok(result)
}, },
Password::Pbkdf2 { ref method, salt: ref my_salt, iterations: my_iterations, ref data } => { Password::Pbkdf2 { ref method, salt: ref my_salt, iterations: my_iterations, ref data } => {