Information Security Stack Exchange is a question and answer site for information security professionals. 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

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
up vote 2 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
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 – Aleksandr Reznik Jan 26 '11 at 12:37
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
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

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
As you mentioned, a hash function can form the basis for a MAC. Block ciphers are the other building block of MACs and are called a CBC-MAC. The blocker cipher used in these functions can differ between implementations--DES, AES, etc. – freb Jan 21 '15 at 4:50

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
HMAC is one of the algorithms which allows us to calculate MAC. – Aleksandr Reznik Jan 26 '11 at 12:16

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.