Skip to content

Commit 2682341

Browse files
authored
yescrypt: use subtle for password hash comparisons (#742)
For rationale, see: https://docs.rs/password-hash/0.6.0-rc.2/password_hash/struct.Output.html#constant-time-comparisons
1 parent 47c5308 commit 2682341

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

yescrypt/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ hmac = { version = "0.13.0-rc.3", default-features = false }
1818
pbkdf2 = { version = "0.13.0-rc.1", path = "../pbkdf2" }
1919
salsa20 = { version = "0.11.0-rc.2", default-features = false }
2020
sha2 = { version = "0.11.0-rc.3", default-features = false }
21+
subtle = { version = "2", default-features = false }
2122

2223
# optional dependencies
2324
mcf = { version = "0.2", optional = true, default-features = false, features = ["alloc", "base64"] }

yescrypt/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,7 @@ pub fn yescrypt_verify(passwd: &[u8], hash: &str) -> Result<()> {
160160
let mut actual = vec![0u8; expected.len()];
161161
yescrypt_kdf(passwd, &salt, &params, &mut actual)?;
162162

163-
// TODO(tarcieri): constant-time comparison?
164-
if expected != actual {
163+
if subtle::ConstantTimeEq::ct_ne(actual.as_slice(), &expected).into() {
165164
return Err(Error::Password);
166165
}
167166

0 commit comments

Comments
 (0)