Cryptography Stack Exchange is a question and answer site for software developers, mathematicians and others interested in cryptography. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Why not just apply hash function on the whole message? Why convert that message into blocks and hash those blocks? To avoid collisions?

share|improve this question
1) Hash != MAC 2) Most hash functions divide the message into blocks internally 3) MACs don't need to be collision resistant, and CBC-MAC isn't. 4) I don't get your questions – CodesInChaos Jan 7 '14 at 15:57
possible duplicate of Can I jettison MAC if I already have SHA1(M)? – Trina Jan 7 '14 at 20:38
up vote 2 down vote accepted

A hash function is not a MAC, although you can turn it into a MAC (see e.g. HMAC).

The purpose of a MAC is message authenticity / integrity -- to prevent attackers (i.e. people who don't know the secret key) from modifying the message or forging fake messages. A hash function trivially cannot fulfill the function of a MAC, because hash functions are unkeyed -- thus an attacker can always forge fake messages because they can calculate the digest of any message as easily as the legitimate parties.

With a MAC, such as CBC-MAC or HMAC, only the people who know the secret key can easily calculate the authentication 'Tag' for a given message, so if a message is sent accompanied by the correct Tag for that message then the receiver knows the message was almost certainly sent by someone who knew the key, and has not been altered (i.e. changed to a different message) in transit.

share|improve this answer
Thanks, I understand it better now. What if an attacker gets the key? He still can't really forge the signature, right? But he now can send a message, so there'd be no origin authenticity (if there were no CBC-MAC or HMAC), right? – evening Jan 7 '14 at 16:10
That's what forging is (i.e. sending a message of the attacker's choice with the correct Tag). If the attacker gets the key somehow then he can forge any message he likes. – J.D. Jan 7 '14 at 16:18
J.D. Yeah, okay, I meant he can't tamper with Alice's and Bob's messages they sent. – evening Jan 7 '14 at 16:21
@evening - you are correct, if the attacker gets the key at time T then he cannot tamper with messages sent and received prior to time T. Doing so would require both the key and a time machine. – J.D. Jan 7 '14 at 16:30
I am idiot. :D In this picture:…, by E, they mean a hash function or a block cipher encryption function? – evening Jan 7 '14 at 17:07

Hash (message digest) and MAC (message authentication code) are a different thing.

CBC-MAC turns block cipher into MAC. HMAC turns hash function into MAC.

A good reason to use CBC-MAC would be that a MAC is needed and there is a suitable implementation of sufficiently secure block cipher available.

For instance, many of recent Intel-based processors have AES implemented in instruction set. Such hardware implementation is very fast, yet relatively secure.

CBC-MAC is mainly for fixed length messages

(Important note on using CBC-MAC.)

CBC-MAC is secure for fixed-length messages (or other prefix free messages). This is restriction which is occasionally overlooked by implementors and may result in significant security hole(s). There exists a newer cipher-based MAC, known as CMAC, which does not have this restriction. CMAC is introduced in NIST Special Publication 800-38B.

share|improve this answer
CBC-MAC is secure for prefix free messages. Fixed length is a sufficient condition, but not necessary. – CodesInChaos Jan 7 '14 at 17:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.