Scenario
The following bash commands create an empty file test.txt
, encrypt it using a default algorithm to test1.gpg
, then append the line new line
to the original file and encrypt it again to test2.gpg
. Each of the gpg
commands prompts the user to enter an encryption key, which is not printed to the terminal.
$ touch test.txt
$ gpg --output test1.gpg -c test.txt
$ echo "new line" >> test.txt
$ gpg --output test2.gpg -c test.txt
$ ls
test1.gpg test2.gpg test.txt
Suppose that an attacker has obtained the encrypted files test1.gpg
and test2.gpg
, and also has obtained access to my shell history—that is, they know exactly how the decrypted versions of these files differ, namely, by the addition of the line new line
.
Furthermore, suppose that the attacker knows (or guesses) that I entered the same encryption key at the prompt both times, but does not know the value of the key itself.
Is this information enough to enable the attacker to recover test.txt
in its entirety?
Scope of this question
I am interested if encryption algorithms in general are designed to anticipate this sort of attack, but if there are differences among the various encryption algorithms out there, you may note that in your answer.
Alternatively, you may respond with respect to the default algorithm invoked by the shell commands above, which is described in man gpg
as follows:
-c Encrypt with a symmetric cipher using a passphrase. The default symmetric cipher
used is AES-128, but may be chosen with the --cipher-algo option. ...
Why I think this question has merit
Many cloud storage services offer some form of encryption, but there are also many common file-manipulation tasks, such as as updating a date, that could enable an attacker to guess exactly what changes were made.
Follow-up questions
Does the vulnerability change depending on the type of edit, e.g. appending versus prepending versus modifying content in the middle of the file versus something else?
What if many sample edits are available—say, 10, 10 thousand, or a million?
Additional info
$ gpg --version
gpg (GnuPG) 2.2.19
libgcrypt 1.8.5
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Home: ~/.gnupg
Supported algorithms:
Pubkey: RSA, ELG, DSA, ECDH, ECDSA, EDDSA
Cipher: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH,
CAMELLIA128, CAMELLIA192, CAMELLIA256
Hash: SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224
Compression: Uncompressed, ZIP, ZLIB, BZIP2