postgres-protocol: use RustCrypto md-5 crate

Swap the md5 crate for the md-5 crate.  Despite the latter's somewhat
more suspicious name, it is part of the wider RustCrypto ecosystem, and
shares code with the sha2 crate that postgres-protocol already uses.
This commit is contained in:
Nikhil Benesch 2021-01-08 13:35:45 -05:00
parent e29439a559
commit 7537e8a918
2 changed files with 9 additions and 10 deletions

View File

@ -14,7 +14,7 @@ byteorder = "1.0"
bytes = "1.0"
fallible-iterator = "0.2"
hmac = "0.10"
md5 = "0.7"
md-5 = "0.9"
memchr = "2.0"
rand = "0.8"
sha2 = "0.9"

View File

@ -1,5 +1,5 @@
//! Authentication protocol support.
use md5::Context;
use md5::{Digest, Md5};
pub mod sasl;
@ -10,14 +10,13 @@ pub mod sasl;
/// `PasswordMessage` message.
#[inline]
pub fn md5_hash(username: &[u8], password: &[u8], salt: [u8; 4]) -> String {
let mut context = Context::new();
context.consume(password);
context.consume(username);
let output = context.compute();
context = Context::new();
context.consume(format!("{:x}", output));
context.consume(&salt);
format!("md5{:x}", context.compute())
let mut md5 = Md5::new();
md5.update(password);
md5.update(username);
let output = md5.finalize_reset();
md5.update(format!("{:x}", output));
md5.update(&salt);
format!("md5{:x}", md5.finalize())
}
#[cfg(test)]