Chapter 8 MACUpdated10June25
Chapter 8 MACUpdated10June25
• However, to allow the receiver to be able to detect replay attacks, the message
itself must contain data that assures that this same message can only be sent
once (e.g. time stamp, sequence number or use of a one-time MAC).
• Otherwise an attacker could – without even understanding its content – record
this message and play it back at a later time, producing the same result as the
original sender.
Properties of MAC
• Compression. A MAC does condense arbitrary long inputs into a fixed length output
since it produces a fixed length digest of a message, regardless of how long the input
message is.
• Easy to compute. In hash functions, this applies to anyone; however, this property is
highly restricted for MACs. A MAC must be easy to compute for anyone who knows the
symmetric MAC key, which is normally only the legitimate sender and receiver of a MAC.
However, it must be hard to compute the correct MAC on a message for anyone who
does not know the MAC key.
• Preimage/second preimage/collision resistance. These properties are important for
the security of hash functions since, without them, it might be possible for an attacker to
manipulate the ‘commitment’ properties of a hash function.
Security Strength of MAC
1. The security of MAC function depends on the security strength of
the underlying hash function.
2. The security of the keys.
3. The length of the MAC output.
Message Authentication Code (MAC)
• Practically, MACs are constructed in essentially two
different ways by using
• cryptographic hash functions (e.g. HMAC) or
• block cipher (e.g. CMAC)
Common MAC Algorithms
• HMAC (Hash-based Message Authentication Code): Utilizes a hash
function combined with a secret key for authentication.
• CMAC (Cipher-based Message Authentication Code): Based on block
ciphers, providing a secure method for generating MACs.
• KMAC (Keccak-based Message Authentication Code): A newer
algorithm derived from SHA-3 standards, offering enhanced security
features.
Hash based Message Authentication Code (HMAC)
• HMAC involving a cryptographic hash function and a secret cryptographic key.
• HMAC can provide authentication using a symmetric key, whereas digital signatures
providing authentication using asymmetric cryptography.
• Using HMAC, the communicating parties are responsible for establishing and using a
trusted channel to agree on the key prior to communication.
• Any cryptographic hash function, such as SHA-2 or SHA-3, may be used in the calculation
of an HMAC; the resulting MAC algorithm is termed HMAC-x, where x is the hash
function used (e.g. HMAC-SHA256 or HMAC-SHA3-512).
• The cryptographic strength of the HMAC depends upon the cryptographic strength of the
underlying hash function, the size of its hash output, and the size and quality of the key.
• HMAC does not encrypt the message. Instead, the message (encrypted or not) must be
concatenated with the hash. Parties with the secret key will hash the message again
themselves, and if it is authentic, the received and computed hashes will match.
Security of HMAC
1. The security of HMAC function depends on the security strength of
the underlying hash function. Thus, it should be deployed using
secure hash functions which have been approved for use by
recognised experts.
2. HMAC is not secure if the attacker finds collisions in the hash function
even when the IV is random and secret.
3. The security of the keys. HMAC employs two symmetric keys. Thus,
the length of an HMAC key can be regarded as the sum of the lengths
of these two keys.
4. The length of the MAC output.
Cipher-based Message Authentication Code (CMAC)
• There are two MACs that are based on the use of a block cipher mode of
operation:
• the Data Authentication Algorithm (DAA), which is now obsolete, and
• the Cipher-Based Message Authentication Code (CMAC), which is designed to
overcome the deficiencies of the DAA.
• CMAC is based on the use of a block cipher mode of operations for use
with AES or triple DES.
• The CMAC overcomes the limitations of the DAA which is based on DES.
• CMACs are calculating MAC codes using a block cipher coupled with a
secret key. You can use an CMAC to verify both the integrity and
authenticity of a message.
KMAC: KECCAK Message Authentication Code
• KMAC algorithm is a variable-length keyed hash function described in
NIST SP800-185 [SP800185]. It is based on KECCAK, the core SHA-3
algorithm.
• There are two variants, KMAC128 and KMAC256, which have expected
security strengths of 128 and 256 bits, respectively. The "standard" output
lengths for KMAC128 and KMAC256 are 256 bits (32 bytes) and 512 bits
(64 bytes), respectively.
• The KMAC algorithm can theoretically output an infinitely-long stream of
bytes, so it can also be used as a Pseudorandom function (PRF). Note
that you cannot truncate a KMAC output value when used as a message
authentication code.
• To obtain the expected security strength you must use keys of length at
least 128 and 256 bits respectively.
MACs Based on Block Cipher: CBC-MAC
• An early banking standard defined CBC-MAC using DES, so the MAC
operated on blocks of 64 bits. Any block cipher, such as AES, could be
used.
• Assume the sender and receiver have both agreed in advance upon a
symmetric key K.
• Assume the message M has been split into blocks of the same length as
the block length of the block cipher (64 bits for DES or 128 bits for AES) in
order to process it. If the message does not fit neatly into blocks, then we
pad the last block.
• The output length of the MAC is determined by the block size of the
cipher used.
• The security of CBC-MAC relies on the security of the symmetric key K MAC Verification:
shared by the sender and receiver. • The computation of MAC can be performed
The figure shown the MAC generation: by anyone who knows the MAC key K.
• The receiver received the message and the
MAC value, and then simply repeat the
computation as in figure above and checks
that the output of this computation is the
same as the received value .
• If it is, then the message is authenticated,
otherwise it is rejected.
Security Requirement of MAC
Assume that an opponent knows the MAC function but does not know the key K.
Then, the MAC function should satisfy the following requirements.
• If an opponent observes message M and MAC(K, M), it should be computationally
infeasible for the opponent to construct a message M′ such that
MAC(K, M′) = MAC(K, M) where M M’
• MAC(K, M) should be uniformly distributed in the sense that for randomly chosen
messages, M and M′, the probability that
MAC(K, M) = MAC(K, M′) is 2-n ,
where n is the number of bits in the hash tag and M M’
Hash, MAC and Digital Signature
• MAC is different from hash functions because MAC require the use of secret key.
• MACs differ from digital signatures as MAC values are both generated and verified using
the same secret symmetric key. This implies that the sender and receiver of a message
must agree on the same key before initiating communications. For the same reason,
MACs do not provide the property of non-repudiation as offered by digital signatures. This
is because any user who can verify a MAC is also capable of generating MACs for other
messages.
• In contrast, digital signatures offer non-repudiation. The signature is generated using the
private key of a sender. Since this private key is only accessible to its holder, a digital
signature proves that a document was signed by none other than that holder i.e. non-
repudiation.
Application Key Security Service
Hash function None Integrity
MAC Symmetric key Authentication, Integrity
Digital Signature Private and public key Authentication, Integrity,
Non-repudiation
MAC with Encryption – Authenticated Encryption
• Combination security services namely authenticated encryption.
• Practically, some applications requiring authenticated encryption. Some message require not to be
encrypted, but should be authenticated only.
• MAC-then-encrypt:
1. the MAC is computed on the full message;
2. the message and the MAC are encrypted (but not the associated data); and
3. the ciphertext and the associated data are sent to the receiver.
• Encrypt-then-MAC:
1. the message is encrypted;
2. the MAC is computed on the combination of the ciphertext and the associated data; and
3. the ciphertext, the associated data, and the MAC are sent to the receiver.
Note: regardless of which order is used, the encryption operation and the MAC operation should be computed using
different cryptographic keys. This is because they are different cryptographic operations, providing different security
services. Using different keys follows the best-practice principle of key separation.
Confidentiality & Authentication
(a) AUTHENTICATION ONLY: The message
and MAC are transmitted in the communication
channel
(b) AUTHENTICITY AND ENCRYPTION:
• MAC concatenated to the message.
• The concatenated message is an input to
encryption algorithm.
• Then, the entire block is then encrypted.
• Two separate keys are needed, each of
which is shared by the sender and the
receiver.
Attackers try to find the valid MAC code for a message x. Two lines of attack is possible:
• Attack the key space
• If an attacker can determine the MAC key then it is possible to generate a valid MAC value for
any input x
• Attack the MAC value
• Objective is to generate a valid tag for a given message or to find a message that matches a
given tag
Cryptanalysis
• Cryptanalytic attacks seek to exploit some property of the algorithm
to perform some attack other than an exhaustive search
• There is much more variety in the structure of MACs than in hash
functions, so it is difficult to generalize about the cryptanalysis of
MACs
Attacks and Countermeasures
1. Disclosure - Release of message contents to any person
2. Traffic analysis - Discovery of the pattern of traffic between parties
3. Masquerade - Insertion of messages into the network from a fraudulent source
4. Content modification - Changes to the contents of a message, including insertion, deletion,
transposition, and modification
5. Sequence modification - Any modification to a sequence of messages between parties, including
insertion, deletion, and reordering
6. Timing modification - Delay or replay of messages
7. Source repudiation - Denial of transmission of message by source
8. Destination repudiation - Denial of receipt of message by destination