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
