Skip to content

Commit

Permalink
Upgrade hmac to 0.11 (#1443)
Browse files Browse the repository at this point in the history
  • Loading branch information
paolobarbolini authored Sep 23, 2021
1 parent 8b30f30 commit c2e04a1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sqlx-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ futures-intrusive = "0.4.0"
futures-util = { version = "0.3.5", default-features = false, features = ["alloc", "sink"] }
generic-array = { version = "0.14.4", default-features = false, optional = true }
hex = "0.4.2"
hmac = { version = "0.10.1", default-features = false, optional = true }
hmac = { version = "0.11.0", default-features = false, optional = true }
itoa = "0.4.5"
ipnetwork = { version = "0.17.0", default-features = false, optional = true }
mac_address = { version = "1.1", default-features = false, optional = true }
Expand Down
12 changes: 6 additions & 6 deletions sqlx-core/src/postgres/connection/sasl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub(crate) async fn authenticate(
)?;

// ClientKey := HMAC(SaltedPassword, "Client Key")
let mut mac = Hmac::<Sha256>::new_varkey(&salted_password).map_err(Error::protocol)?;
let mut mac = Hmac::<Sha256>::new_from_slice(&salted_password).map_err(Error::protocol)?;
mac.update(b"Client Key");

let client_key = mac.finalize().into_bytes();
Expand All @@ -122,7 +122,7 @@ pub(crate) async fn authenticate(
);

// ClientSignature := HMAC(StoredKey, AuthMessage)
let mut mac = Hmac::<Sha256>::new_varkey(&stored_key).map_err(Error::protocol)?;
let mut mac = Hmac::<Sha256>::new_from_slice(&stored_key).map_err(Error::protocol)?;
mac.update(&auth_message.as_bytes());

let client_signature = mac.finalize().into_bytes();
Expand All @@ -135,13 +135,13 @@ pub(crate) async fn authenticate(
.collect();

// ServerKey := HMAC(SaltedPassword, "Server Key")
let mut mac = Hmac::<Sha256>::new_varkey(&salted_password).map_err(Error::protocol)?;
let mut mac = Hmac::<Sha256>::new_from_slice(&salted_password).map_err(Error::protocol)?;
mac.update(b"Server Key");

let server_key = mac.finalize().into_bytes();

// ServerSignature := HMAC(ServerKey, AuthMessage)
let mut mac = Hmac::<Sha256>::new_varkey(&server_key).map_err(Error::protocol)?;
let mut mac = Hmac::<Sha256>::new_from_slice(&server_key).map_err(Error::protocol)?;
mac.update(&auth_message.as_bytes());

// client-final-message = client-final-message-without-proof "," proof
Expand Down Expand Up @@ -197,7 +197,7 @@ fn gen_nonce() -> String {

// Hi(str, salt, i):
fn hi<'a>(s: &'a str, salt: &'a [u8], iter_count: u32) -> Result<[u8; 32], Error> {
let mut mac = Hmac::<Sha256>::new_varkey(s.as_bytes()).map_err(Error::protocol)?;
let mut mac = Hmac::<Sha256>::new_from_slice(s.as_bytes()).map_err(Error::protocol)?;

mac.update(&salt);
mac.update(&1u32.to_be_bytes());
Expand All @@ -206,7 +206,7 @@ fn hi<'a>(s: &'a str, salt: &'a [u8], iter_count: u32) -> Result<[u8; 32], Error
let mut hi = u;

for _ in 1..iter_count {
let mut mac = Hmac::<Sha256>::new_varkey(s.as_bytes()).map_err(Error::protocol)?;
let mut mac = Hmac::<Sha256>::new_from_slice(s.as_bytes()).map_err(Error::protocol)?;
mac.update(u.as_slice());
u = mac.finalize().into_bytes();
hi = hi.iter().zip(u.iter()).map(|(&a, &b)| a ^ b).collect();
Expand Down

0 comments on commit c2e04a1

Please sign in to comment.