diff options
-rw-r--r-- | openpgp/src/crypto/s2k.rs | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/openpgp/src/crypto/s2k.rs b/openpgp/src/crypto/s2k.rs index 1b962bd9..527b2a50 100644 --- a/openpgp/src/crypto/s2k.rs +++ b/openpgp/src/crypto/s2k.rs @@ -100,9 +100,15 @@ impl S2K { hash.update(salt); hash.update(string); } - &S2K::Iterated { ref salt, hash_bytes, .. } => { + &S2K::Iterated { ref salt, hash_bytes, .. } + if (hash_bytes as usize) < salt.len() + string.len() => + { // Independent of what the hash count is, we // always hash the whole salt and password once. + hash.update(&salt[..]); + hash.update(&string); + }, + &S2K::Iterated { ref salt, hash_bytes, .. } => { let octs_per_iter = salt.len() + string.len(); let mut data = vec![0u8; octs_per_iter]; let full = hash_bytes as usize / octs_per_iter; |