HMAC is an acronym for Hash-based Message Authentication Code
What would be an HMAC?
An HMAC is a type of MAC (message authentication code). A MAC is a code that you can add at the end of a message to protect the integrity of the message, ensuring that it was received by the recipient without accidental or malicious changes.
The simplest way to try to protect the integrity of a message would be to include a checksum at the end. This would protect against accidental modifications but would not protect against malicious modifications, as a malicious person could recalculate the checksum to make it match the modified message.
To protect against malicious modifications we can use an encrypted MAC. This MAC is like a checksum, but it also depends on a secret key that only the author of the message has, which theoretically prevents an opponent from recalculating the MAC from a modified message.
The HMAC is a a specific algorithm to generate a cryptographically secure MAC from a secret key and any message. It’s better to use this algorithm than to reinvent the wheel because many simple algorithms like hash(chave + mensagem)
are vulnerable to cryptographic attacks such as attack of size extension.
HMAC has something to do with the hash (md5, sha1, sha256)?
Yes, HMAC is a general algorithm that uses a hash function internally. This hash function can be any cryptographic hash such as md5, sha1 or sha256 and depending on the hash function you use you get a different version of HMAC (HMAC-MD5, HMAC-SHA1, HMAC-SHA256, etc).
Why do I always hear something like "HMAC calculation"? What would this "calculation be"?
HMAC is an algorithm and this calculation is simply the execution of this algorithm. Roughly, the HMAC function is defined by
HMAC(K, m) = hash(K1 + hash(K2 + m))
where:
K
is the secret key
m
is the message
hash
is the hash function chosen (md5, sha1, etc)
K1
and K2
are secret keys derived from the original key K
+
is the string concatenation operation.
For more details, I recommend reading RFC 2104 or the wikipedia article
Does it have any purpose for information security? If so, cite examples.
An example of MAC usage is that a web server can deliver cookies to its users that can be read but not modified (as any modification to the content would invalidate the MAC).
Great, man, very good... +1. Just missing pronunciation :>
– Wallace Maxters
In Portuguese I would say "maqui" even instead of "méqui". But I think it doesn’t matter.
– hugomg
Great explanation!
– v3rlly