Path: blob/master/Authenticated-Encryption/AE-with-MACs/Encrypt-then-MAC/README.md
1402 views
Encrypt-then-MAC
Prerequisites:
In this article we will:
Discuss Authenticated Encryption using Encrypt-then-MAC technique
Implement a simple Authenticated Encryption service using Encrypt-then-MAC technique
This method of authenticated encryption is the most secure method among the three techniques, reasons of which is discussed in the last section "Security Analysis of Encrypt-then-MAC". In this technique, ciphertext is generated independent of the MAC, and authentication tag is generated from the ciphertext instead of plaintext. This ensures that authentication tag reveals no information about the plaintext whatsoever.
To understand Encrypt-then-MAC clearly, have a look at this illustration from Wikipedia:
Sending messages securely using Encrypt-then-MAC
Consider Alice as the sender and Bob as the receiver. According to Encrypt-then-MAC technique, Alice sends the ciphertext as well as it's corresponding authentication tag to Bob. Bob then authenticates the ciphertext and accepts the message only if the authentication holds true. Let us see how Alice sends the message to Bob:
Let
M
be the message that is to be sent by Alice. Alice first pads the message to make it a multiple of blocksize. He then generates ciphertext corresponding toM
as:, where k1 is the key used for encryption and
E()
is any reasonably secure block cipher algorithm
Next, Alice computes the authentication tag
T
of the ciphertext generated. This is in accordance with Encrypt-then-MAC technique.T
is generated as:, where k2 is the key used for generating the authentication tag
Note that the algorithm used to generate authentication tag can either be a Hash based MAC (HMAC) or a block-cipher-mode based MAC (CBC-MAC)
Alice now concatenates ciphertext
C
and it's corresponding authentication tagT
using a separator. Sends the resultant string to Bob.
Let us implement the above process in python-2.7:
Authentication using Encrypt-then-MAC
After receiving Alice's message:
Bob splits the string received into two, first part is the ciphertext
C
and second part is the authentication tagT
.Authentication Step:
Bob checks if MAC of the ciphertext received is equal to the authentication tag received:
If they match, then the process moves onto the next step, otherwise Bob would send a VerificationError to Bob and will not move further.
After the ciphertext is authenticated, Bob decrypts the message
M
as:, where D() is the decryption function
Bob sends an acknowledgement to Alice that the message has been received and read
Let us implement the above authentication process in python-2.7:
You can check out the entire example script here
Security Analysis of MAC-then-Encrypt
MAC-then-Encrypt technique is the most secure technique for Authenticated Encryption with MACs among all the three techniques. This is because in other two techniques, the receiver will have to decrypt the message and authenticate only after decryption. This can be dangerous as it leaks corrupted plaintext to the receiver.
Also, the technique we have discussed is more efficient as the receiver does not have to worry about time taken to decrypt the ciphertext. This reduces time and computational power. The receiver will only decrypt ciphertext upon authentication, otherwise it simply will return a VerificationError.