I'm writing a client-server encryption scheme for homework, and I've stumbled upon what might be a fatal blow to my current implementation.
When using AES-256-CBC on the two sides, it's important that the client's encrypt context and the server's decrypt context remain in sync. However, my protocol allows for rejection of messages if they fail an HMAC test.
If a message were to fail the HMAC test, then the two contexts fall out of sync because the state of the context was polluted by the garbage ciphertext. All subsequent decrypts will fail. Is there any way to rollback a decryption, i.e. bring it back to the state in which it was before the decrypt happened? Alternatively, is there any way to copy an decrypt context?
The same goes for the client when it receives word of the failure. It's going to want to roll back its encryption.
Should I use something other than CBC mode?
EVP_CIPHER_CTX_copy
to create a copy of the previous context in the respective applications and maybe use that to do the subsequent crypto procedures, when a MAC fails. I haven't tested it, but please do :) The documentation is here: openssl.org/docs/manmaster/man3/EVP_CIPHER_CTX_copy.html $\endgroup$