summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2019-05-20 13:55:12 +0200
committerJustus Winter <justus@sequoia-pgp.org>2019-05-20 15:15:26 +0200
commit90c7e249c6667e48db42b3d6014176a2bfb82153 (patch)
tree4fc9ef20f7346bc21c0ac1542a74365fade14c31
parent29daf7d69ad1db704bb105f4f1fba2d0ca85ecab (diff)
openpgp: Fix special case.
-rw-r--r--openpgp/src/crypto/s2k.rs8
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;