Hashed Message Authentication Codes (HMAC)


Message authentication codes are a way of asserting that a particular message did in fact come from a properly authorized originator.

  • some messaging apps sequentially number each message
    • when combined with sending date, time, originator ID, and other information, gives reasonably unique and verifiable way to prevent spoofing traffic

Hashed message authentication code (HMAC) is a MAC that uses a symmetric key together with a cryptographic hash function.

  • aka hash-based authentication code
  • similar to generating a digital signature for the message contents
  • sender and receiver need to agree on a protocol
  • first published in 1996 paper by Bellare, Canetti, Krawczyk
  • used in
    • IPsec, TLS, JSON Web Tokens
  • included in FIPS 198-1
  • denoted by the hash function used with the HMAC
    • e.g., HMAC-MD5
  • size is equal to the size of the underlying hash function
    • e.g., HMAC-SHA256 generates a 256-bit HMAC
  • KMAC (Keccak MAC) is based on Keccak algorithm used in SHA-3

Usage

  • sender uses a hash function to compute a message digest
  • sender encrypts a message digest with a symmetric key shared with the message receiver

How It Works

  • HMAC first breaks the key into two halves
    • the inner and outer keys
  • then hashes the message first with the inner key, and then hashes that result with the outer key
    • this double-hash leads to HMAC having greater immunity against length-extension attacks
      • which systems with only one pass through the hash function can be susceptible to
  • HMAC breaks the message (or file) into fixed-length blocks and iteratively applies a compression function to them
    • similar to SHA-256
  • does not encrypt the message
  • original version of the file or message used to generate the signature must accompany the signature so that the recipient (or later reader) can repeat signature generation process and compare results to demonstrate authenticity

Attacks

  • generic attacks against MAC:
    1. Recover the key
      • is a brute force attack
      • security depends on the length of the secret key
    2. Append fake information to the end of the original message
    3. Substitute a fake message for the original one
    4. Existential forgery
      • the ability of the adversary to create a message and its MAC that have not been generated in the past by the legitimate sender