liveBook · Manning

Kmac

As explained in Real-World Cryptography

KMAC is a standardized message authentication code based on the SHA-3 sponge construction and a secret key.

KMAC is a standardized message authentication code for protecting message integrity and authenticity with a shared secret key. It is the SHA-3-oriented alternative to HMAC when using SHA-3. section 3.5 section 3.6

KMAC works by:

  • Encoding the key, message, and requested output length unambiguously. section 3.5.2
  • Giving that encoding to cSHAKE, customized with the function name “KMAC” and optionally a user-defined customization string. section 3.5.2
  • Producing different results for different requested tag lengths, making KMAC versatile. section 3.5.2

Avoid the homemade cookie MAC

A web page that hashes a cookie directly can accept an attacker’s tampered cookie. SHA-2-based constructions can also suffer length-extension attacks; use HMAC with SHA-2 or KMAC with SHA-3 instead. section 3.6

Figure 3.8 KMAC is simply a wrapper around cSHAKE. To use a key, it encodes (in a unambiguous way) the key, the input, and the output length as the input to cSHAKE.

Follow the wrapper diagram from KMAC’s encoded inputs into cSHAKE. section 3.5.2

How Real-World Cryptography covers it

How deep it goes
Explains KMAC’s cSHAKE wrapper and encoded inputs, but stops short of implementation-level details.
Examples
Uses cookie tampering, forged hashes, and length-extension attacks as concrete failure scenarios.
What it assumes
Assumes shared-key MAC basics and familiarity with cSHAKE as a customizable SHAKE function.
What you can do after
Apply KMAC for SHA-3-based authentication, while comparing received and computed tags in constant time.
How it connects
Connects MACs with cSHAKE, SHAKE, SHA-3, HMAC, SHA-2, and length-extension attacks.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Real-World Cryptography. The section links point to the parts of the book it draws on.