Skip to main content
1 of 2
Z.T.
  • 8.7k
  • 1
  • 25
  • 41

No, you should use Authenticated Encryption or AEAD.

My suggestion:

Generate another 128 bits from the KDF, use that as the key to HMAC-SHA-256, compute HMAC of IV and ciphertext, store the HMAC result (called authentication tag) with the ciphertext.

When decrypting, pass the password through KDF to generate IV and HMAC key, compute HMAC over IV and ciphertext, compare with stored authentication tag. If they don't match, the password was bad or the ciphertext was tampered with. Do not decrypt. Decrypt only if the authentication tag is good.

CBC is slow, because it has to work one block at a time and cannot encrypt blocks in parallel. CTR would be better.

HMAC is a strong MAC but is slow.

Modern AEAD modes like AES-GCM or even ChaCha20-Polt1305 are faster than AES-CBC or AES-CBC+HMAC.

Using age would be much better than rolling your own. For example, age uses modern chunked AEADs and scrypt.

Z.T.
  • 8.7k
  • 1
  • 25
  • 41