From 13d63402983eb18af54174f616ec8d8f5416a150 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Thu, 17 Jan 2019 23:32:39 +0100 Subject: [PATCH] Switch to RustCrypto for hashes. --- sasl/Cargo.toml | 2 ++ sasl/src/common/scram.rs | 13 ++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/sasl/Cargo.toml b/sasl/Cargo.toml index 225e9f7d..8fc9bfc5 100644 --- a/sasl/Cargo.toml +++ b/sasl/Cargo.toml @@ -20,6 +20,8 @@ scram = ["openssl"] [dependencies] base64 = "0.10" +sha-1 = "0.8" +sha2 = "0.8" [dependencies.openssl] version = "0.10.7" diff --git a/sasl/src/common/scram.rs b/sasl/src/common/scram.rs index 2ccba1fc..ab5dd94c 100644 --- a/sasl/src/common/scram.rs +++ b/sasl/src/common/scram.rs @@ -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 { - 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 { @@ -112,7 +116,10 @@ impl ScramProvider for Sha256 { } fn hash(data: &[u8]) -> Vec { - 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 {