Switch to RustCrypto for hashes.

This commit is contained in:
Emmanuel Gil Peyrot 2019-01-17 23:32:39 +01:00
parent 9e9f09a9a5
commit 13d6340298
2 changed files with 12 additions and 3 deletions

View file

@ -20,6 +20,8 @@ scram = ["openssl"]
[dependencies]
base64 = "0.10"
sha-1 = "0.8"
sha2 = "0.8"
[dependencies.openssl]
version = "0.10.7"

View file

@ -1,10 +1,11 @@
use openssl::error::ErrorStack;
use openssl::hash::hash;
use openssl::hash::MessageDigest;
use openssl::pkcs5::pbkdf2_hmac;
use openssl::pkey::PKey;
use openssl::rand::rand_bytes;
use openssl::sign::Signer;
use sha1::{Digest, Sha1 as Sha1_hash};
use sha2::Sha256 as Sha256_hash;
use crate::common::Password;
@ -49,7 +50,10 @@ impl ScramProvider for Sha1 {
}
fn hash(data: &[u8]) -> Vec<u8> {
hash(MessageDigest::sha1(), data).unwrap().to_vec()
let hash = Sha1_hash::digest(data);
let mut vec = Vec::with_capacity(Sha1_hash::output_size());
vec.extend_from_slice(hash.as_slice());
vec
}
fn hmac(data: &[u8], key: &[u8]) -> Vec<u8> {
@ -112,7 +116,10 @@ impl ScramProvider for Sha256 {
}
fn hash(data: &[u8]) -> Vec<u8> {
hash(MessageDigest::sha256(), data).unwrap().to_vec()
let hash = Sha256_hash::digest(data);
let mut vec = Vec::with_capacity(Sha256_hash::output_size());
vec.extend_from_slice(hash.as_slice());
vec
}
fn hmac(data: &[u8], key: &[u8]) -> Vec<u8> {