A file encrypted with OpenSSL (with, for example, AES 256-bit mode CBC) using the Linux command
openssl enc -aes-256-cbc -in texte -out encrypted_texte -k password
has a salt in the first 16 bytes — with the bytes 8-15 being the salt itself. When the file is decrypted, if the salt is modified, OpenSSL will throw a
bad decrypt 140338977786624:error:0606506D:digital envelope routines:EVP_DecryptFinal_ex:wrong final block length:evp_enc.c:520:
error, while if the file was encrypted in mode CFB doesn't give you that error.
Why does this happen? What is different about CFB so that it does not produce an error when the salt is modified, compared to the other blockcipher modes of encryption which bluntly fail? Has it something to do with the padding (CBC and ECB do use padding)?
Here's an example of what I'm trying to do: With dd
, just one byte is changed in the salt. When trying to decrypt, openssl
with throw the error.
echo 'spam' > food.txt
openssl enc -aes-256-cbc -in food.txt -out food.enc -k IDONTLIKENOSPAM!
printf '?' | dd of=food.enc bs=1 seek=12 count=1 conv=notrunc &> /dev/null
openssl enc -d -aes-256-cbc -in food.enc -out food.bad -k IDONTLIKENOSPAM!
03 03 03
sequences the padding mandates. $\endgroup$