What is the Difference between a Hash and MAC (Message Authentication code)?

Robben_Ford_Fan_boy picture Robben_Ford_Fan_boy · May 14, 2010 · Viewed 75.6k times · Source

What is the Difference between a Hash and MAC (Message Authentication code)?

By their definitions they seem to serve the same function.

Can someone explain what the difference is?

Answer

Jack picture Jack · May 14, 2010

The main difference is conceptual: while hashes are used to guarantee the integrity of data, a MAC guarantees integrity AND authentication.

This means that a hashcode is blindly generated from the message without any kind of external input: what you obtain is something that can be used to check if the message got any alteration during its travel.

A MAC instead uses a private key as the seed to the hash function it uses when generating the code: this should assure the receiver that, not only the message hasn't been modified, but also who sent it is what we were expecting: otherwise an attacker couldn't know the private key used to generate the code.

According to wikipedia you have that:

While MAC functions are similar to cryptographic hash functions, they possess different security requirements. To be considered secure, a MAC function must resist existential forgery under chosen-plaintext attacks. This means that even if an attacker has access to an oracle which possesses the secret key and generates MACs for messages of the attacker's choosing, the attacker cannot guess the MAC for other messages without performing infeasible amounts of computation.

Of course, although their similarities, they are implemented in a different way: usually a MAC generation algorithm is based upon a hash code generation algorithm with the extension that cares about using a private key.