Skip to main content

kmac

Function kmac 

Source
fn kmac<const RATE: usize>(
    key: &[u8],
    key_length: u32,
    message: &[u8],
    output_length: u32,
    customization: &[u8],
) -> Vec<u8> 
Expand description

A shared implementation for both the KMAC128 function and KMAC256 function defined in Section 4 of [NIST-SP800-185], using key as the K input parameter, message as the X input parameter, output_length as the L input parameter, and customization as the S input parameter, where key_length is the key length in bits. https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-185.pdf

To be specific, this function implements the following algorithm, where RATE must be either 168 or 136 for KMAC128 and KMAC256 respectively.

  1. newX = bytepad(encode_string(K), RATE) || X || right_encode(L).
  2. return cSHAKE128(newX, L, “KMAC”, S).

Since the key is represented as a byte sequence, and the key length in bits might not be a muliple of 8, callers need to provide the actual key length in bits via the function argument key_length, and the excess bits at the end of the byte sequence must be zeros.