My program periodically saves encrypted data. I use Argon2id
to derive the key from a password. When doing so repeatedly one should not reuse the nonce
as that's what the word nonce
stands for.
However is it safe to reuse the derived key when saving the data after the data has been modified? This somehow seems wrong as it would be the same as generating this key repeatedly by reusing a nonce which one should not do. However, regenerating new keys from the password when saving requires the password to be stored during the entire session and requires a lot of computation.
You are using Argon2 as a password-based key derivation function. In this case, its role is to generate a key from a password in a computationally difficult way so that an attacker cannot simply try multiple candidate passwords. The role of the salt is to ensure that two different users who pick the same password don't end up with the same key. It also protects against attack since our attacker cannot pre-compute anything useful from their directory of candidate passwords since they have to mix in the salt in each computation.
So, you should use a random salt for each user, but it is OK to re-use that user's salt.
If you are concerned about using the derived key for the encryption of multiple plaintexts, you could generate a random key for each plaintext, wrap that key in the derived key and store the wrapped key with the ciphertext. Alternatively, you could use, for example, HKDF to derive a new key for each plaintext with some unique or random message id.