mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
Switch to RustCrypto for Hmac.
This commit is contained in:
parent
13d6340298
commit
392b1c66b1
2 changed files with 16 additions and 10 deletions
|
@ -22,6 +22,7 @@ scram = ["openssl"]
|
|||
base64 = "0.10"
|
||||
sha-1 = "0.8"
|
||||
sha2 = "0.8"
|
||||
hmac = "0.7"
|
||||
|
||||
[dependencies.openssl]
|
||||
version = "0.10.7"
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
use hmac::{Hmac, Mac};
|
||||
use openssl::error::ErrorStack;
|
||||
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;
|
||||
|
||||
|
@ -57,10 +56,13 @@ impl ScramProvider for Sha1 {
|
|||
}
|
||||
|
||||
fn hmac(data: &[u8], key: &[u8]) -> Vec<u8> {
|
||||
let pkey = PKey::hmac(key).unwrap();
|
||||
let mut signer = Signer::new(MessageDigest::sha1(), &pkey).unwrap();
|
||||
signer.update(data).unwrap();
|
||||
signer.sign_to_vec().unwrap()
|
||||
type HmacSha1 = Hmac<Sha1_hash>;
|
||||
let mut mac = HmacSha1::new_varkey(key).unwrap();
|
||||
mac.input(data);
|
||||
let result = mac.result();
|
||||
let mut vec = Vec::with_capacity(Sha1_hash::output_size());
|
||||
vec.extend_from_slice(result.code().as_slice());
|
||||
vec
|
||||
}
|
||||
|
||||
fn derive(password: &Password, salt: &[u8], iterations: usize) -> Result<Vec<u8>, String> {
|
||||
|
@ -123,10 +125,13 @@ impl ScramProvider for Sha256 {
|
|||
}
|
||||
|
||||
fn hmac(data: &[u8], key: &[u8]) -> Vec<u8> {
|
||||
let pkey = PKey::hmac(key).unwrap();
|
||||
let mut signer = Signer::new(MessageDigest::sha256(), &pkey).unwrap();
|
||||
signer.update(data).unwrap();
|
||||
signer.sign_to_vec().unwrap()
|
||||
type HmacSha256 = Hmac<Sha256_hash>;
|
||||
let mut mac = HmacSha256::new_varkey(key).unwrap();
|
||||
mac.input(data);
|
||||
let result = mac.result();
|
||||
let mut vec = Vec::with_capacity(Sha256_hash::output_size());
|
||||
vec.extend_from_slice(result.code().as_slice());
|
||||
vec
|
||||
}
|
||||
|
||||
fn derive(password: &Password, salt: &[u8], iterations: usize) -> Result<Vec<u8>, String> {
|
||||
|
|
Loading…
Reference in a new issue