Take the 2-minute tour ×
Information Security Stack Exchange is a question and answer site for Information security professionals. It's 100% free, no registration required.

What is the difference between the two algorithms?
One difference that I know of, is that MAC is keyed and hash is not.

share|improve this question

3 Answers 3

up vote 0 down vote accepted

To make it simple: usually a MAC is a Hash value encrypted with a secret key. For example, attackers can forge message and calculate a new hash, but he can't do so if the system requires hash to be encrypted with a secret key.

share|improve this answer
6  
This answer is not accurate. This is not a helpful way to think about a MAC, nor is it typically how a MAC algorithm works. –  D.W. Jan 26 '11 at 6:02
    
Hash is used to ensure message integrity, MAC is used for both integrity and authenticy. Most MAC alghoritms - is a combination of hash function with a secret key, which I call for simplicity "encryption" of hash value with a key en.wikipedia.org/wiki/File:MAC.svg –  Aleksandr Reznik Jan 26 '11 at 12:37
3  
I don't know that that's the best way of looking at it. I don't think there's much of a distinction between integrity vs authenticity, when we're dealing with an active attacker who might modify messages transmitted. As for calling it "encryption", that is highly misleading and I strongly encourage you to avoid using that terminology: it does not correspond to how cryptographers talk, and in my experience, it often misleads inexperienced listeners. –  D.W. Jan 30 '11 at 6:13
1  
MACs are rarely constructed by encrypting a hash. For many types of encryption that'd be very weak. For example it'd suck with stream ciphers. It'd require a 256 bit hash and a 256 bit block cipher to be as secure as a normal 128 bit MAC. –  CodesInChaos Feb 10 '13 at 10:38

They are two totally different primitives. A MAC is used for message authentication, and is a symmetrically keyed primitive. A hash function can be used for many purposes, and has no special key input. MAC is an acronym of "message authentication code".

Don't be confused by the fact that some MAC algorithms (e.g., SHA1-HMAC) work by using a hash function as a subroutine. They're very different beasts.

  • Some examples of MAC algorithms: CMAC, SHA1-HMAC, MD5-HMAC, UMAC, Poly1305-AES.
  • Some examples of cryptographic hash functions: SHA256, SHA1, MD5.
share|improve this answer
4  
HMAC is one of the algorithms which allows us to calculate MAC. –  Aleksandr Reznik Jan 26 '11 at 12:16

A cryptographic hash function is a completely public, deterministic hash function which everybody can compute over arbitrary inputs. It takes as input a sequence of bits (any sequence of bits; some hash functions are formally limited to inputs of, say, less 264 bits, aka "2 millions of terabytes") and outputs values in a rather small space, typically a sequence of bits with a fixed size (e.g. always 160 bits with the standard hash function SHA-1). Good cryptographic hash functions respect some conditions which boil down to, informally, that they mix input data so thoroughly that we cannot figure it out afterwards.

A message authentication code is an algorithm which takes as input a message and a secret key and produces a fixed-sized output which can be later on verified to match the message; the verification also requires the same secret key. Contrary to hash functions where everything is known and attackers are fighting against mathematics, MAC make sense in models where there are entities with knowledge of a secret. What we expect from a good MAC is unforgeability: it should be infeasible to compute a pair message+MAC value which successfully verifies with a given key K without knowing K exactly and in its entirety.

Hash functions and MAC are thus distinct kind of algorithms with distinct properties and used in really distinct situations.

Some MAC algorithms (but certainly not all of them) can be thought of as "hash functions with a key" but this is a restrictive view. HMAC is a well-known MAC construction, which itself builds on an underlying hash function in a smart way. Indeed, security properties and models for hash functions and MAC are sufficiently distinct from each other that slapping a hash function and a key together does not necessarily yield a secure MAC, even if the hash function is secure (see the length extension attack which illustrates that point).

To some extent, we can state that a MAC algorithm which can operate securely without an IV must exhibit some hash-like properties (that's the reason I like HMAC: without an IV, it is much harder to get it wrong when implementing it). However, the Devil is in the details.

share|improve this answer

Your Answer

 
discard

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.