"decrypt with -md sha1");
ok(compare_text($test, "md.clear") == 0,
"decrypted output matches the original");
+ # A mismatching digest derives a different key. The decryption
+ # usually fails on the padding check, but with a random salt the
+ # garbage last block occasionally happens to look like valid
+ # padding, in which case it succeeds and produces garbage instead.
ok(!run(app([$cmd, "enc", "-aes-128-cbc", "-md", "sha256", "-d", "-k", "test",
- "-in", "md.cipher", "-out", "md_mismatch.clear"])),
- "decrypt fails when -md does not match the one used to encrypt");
+ "-in", "md.cipher", "-out", "md_mismatch.clear"]))
+ || compare_text($test, "md_mismatch.clear") != 0,
+ "decrypt does not recover the plaintext when -md does not match");
};
subtest "-iter sets the PBKDF2 iteration count" => sub {
"decrypt with -iter 5");
ok(compare_text($test, "iter.clear") == 0,
"decrypted output matches the original");
+ # As with -md above, a mismatching iteration count derives a
+ # different key, so the decryption either fails on the padding check
+ # or, when the garbage happens to look like valid padding, succeeds
+ # and yields garbage.
ok(!run(app([$cmd, "enc", "-aes-128-cbc", "-iter", "6", "-d", "-k", "test",
- "-in", "iter.cipher", "-out", "iter_mismatch.clear"])),
- "decrypt fails when -iter does not match the one used to encrypt");
+ "-in", "iter.cipher", "-out", "iter_mismatch.clear"]))
+ || compare_text($test, "iter_mismatch.clear") != 0,
+ "decrypt does not recover the plaintext when -iter does not match");
};
}