Skip to content

Commit

Permalink
postgres-protocol: use RustCrypto md-5 crate
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
benesch committed Jan 8, 2021
1 parent e29439a commit 7537e8a
Showing 2 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion postgres-protocol/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
17 changes: 8 additions & 9 deletions postgres-protocol/src/authentication/mod.rs
Original file line number Diff line number Diff line change
@@ -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)]

0 comments on commit 7537e8a

Please sign in to comment.