digestpp 1.0
C++11 header-only message digest library
Loading...
Searching...
No Matches
KMAC

KMAC Algorithms More...

Typedefs

typedef hasher< detail::kmac_provider< 128, false >, mixin::kmac_mixindigestpp::kmac128
 KMAC128 in hash mode.
 
typedef hasher< detail::kmac_provider< 256, false >, mixin::kmac_mixindigestpp::kmac256
 KMAC256 in hash mode.
 
typedef hasher< detail::kmac_provider< 128, true >, mixin::kmac_mixindigestpp::kmac128_xof
 KMAC128 in XOF mode (KMACXOF128)
 
typedef hasher< detail::kmac_provider< 256, true >, mixin::kmac_mixindigestpp::kmac256_xof
 KMAC256 in XOF mode (KMACXOF256)
 
template<size_t N>
using digestpp::static_size::kmac128 = hasher<detail::kmac_provider<128, false, N>, mixin::kmac_mixin>
 KMAC128 in hash mode (static-size version)
 
template<size_t N>
using digestpp::static_size::kmac256 = hasher<detail::kmac_provider<256, false, N>, mixin::kmac_mixin>
 KMAC256 in hash mode (static-size version)
 

Detailed Description

KMAC Algorithms

Typedef Documentation

◆ kmac128 [1/2]

KMAC128 in hash mode.

Keccak Message Authentication Code with 128-bit security. Specified in NIST SP 800-185.

KMAC is a PRF and keyed hash function based on Keccak, designed to provide variable-length output with improved security properties.

Use this variant when the required hash size is known in advance. For unknown output size (streaming output), use kmac128_xof

While primary usage of KMAC is message authentication with a key (MAC/PRF), it can also be used without a key as a regular hash function.

When used without a key as a regular hash function, KMAC has an important advantage over SHAKE128: different output lengths produce independent digests (shorter output is NOT a prefix of longer output). For example: kmac128(256) ≠ prefix(kmac128(512)). This property can be important for security in protocols where variable-length hashes are used in different contexts.

Type:
Cryptographic hash function.
Output size:
arbitrary (any number of bits divisible by 8)
Default size:
none (must be specified)
Exceptions
std::runtime_errorif the requested digest size is not divisible by 8 (full bytes)

Optional parameters:

Optional parameters:
customization, key

See mixin::kmac_mixin for the description of optional parameters.

Example:
// Set key and output a 256-bit KMAC128 of a string
hasher.set_key(R"(@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_)");
hasher.absorb("The quick brown fox jumps over the lazy dog");
std::cout << hasher.hexdigest() << '\n';
Main class template implementing the public API for hashing.
Definition hasher.hpp:38
std::string hexdigest() const
Return hex digest of absorbed data.
Definition hasher.hpp:372
hasher & absorb(const T *data, size_t len)
Absorbs bytes from a C-style pointer to character buffer.
Definition hasher.hpp:86
Example output:
bbd4ebf20aacc8e4dfd2cc91f2b6cbf33e2a45d805996b48a17b8d3e42b4b010
See also
hasher, kmac128_xof, kmac256, mixin::kmac_mixin, digestpp::static_size::kmac128

◆ kmac128 [2/2]

KMAC128 in hash mode (static-size version)

Variant of KMAC128 with output size specified as template parameter.

While primary usage of KMAC is message authentication, it can also be used without a key as a regular hash function with the advantage that different output lengths produce independent digests.

Type:
Cryptographic hash function.
Output size:
arbitrary

Optional parameters:

Optional parameters:
customization, key

See mixin::kmac_mixin for the description of optional parameters.

Example:
// Set key and output a 256-bit KMAC128 of a string
hasher.set_key(R"(@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_)");
hasher.absorb("The quick brown fox jumps over the lazy dog");
std::cout << hasher.hexdigest() << '\n';
Example output:
bbd4ebf20aacc8e4dfd2cc91f2b6cbf33e2a45d805996b48a17b8d3e42b4b010
See also
hasher, digestpp::kmac128, kmac128_xof, mixin::kmac_mixin, digestpp::kmac128

◆ kmac128_xof

KMAC128 in XOF mode (KMACXOF128)

Specified in NIST SP 800-185.

Extendable Output Function mode of KMAC128. Use when the required output length is not known in advance or when streaming output is needed.

For fixed-length output known in advance, use kmac128 (provides independent outputs for different lengths)

In XOF mode without a key, there are no advantages over cshake128, as squeezed outputs share the same prefix property (longer output = shorter output + more bytes).

Primary usage: MAC/PRF with variable or unknown output length

Type:
Extendable output function (XOF).

Optional parameters:

Optional parameters:
customization, key

See mixin::kmac_mixin for the description of optional parameters.

Example:
// Set key, absorb a string and squeeze 32 bytes of output
hasher.set_key(R"(@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_)");
hasher.absorb("The quick brown fox jumps over the lazy dog");
std::cout << hasher.hexsqueeze(32) << '\n';
std::string hexsqueeze(size_t len)
Squeeze bytes and return them as a hex string.
Definition hasher.hpp:296
Example output:
a5dd2e2c92e4fe5d203ab7cc4e05df888b021390ba08a00dcb39a94ed07bd364
See also
hasher, kmac128, mixin::kmac_mixin

◆ kmac256 [1/2]

KMAC256 in hash mode.

Keccak Message Authentication Code with 256-bit security. Specified in NIST SP 800-185.

KMAC is a PRF and keyed hash function based on Keccak, designed to provide variable-length output with improved security properties.

Use this variant when the required hash size is known in advance. For unknown output size (streaming output), use kmac256_xof

While primary usage of KMAC is message authentication with a key (MAC/PRF), it can also be used without a key as a regular hash function.

When used without a key as a regular hash function, KMAC has an important advantage over SHAKE256: different output lengths produce independent digests (shorter output is NOT a prefix of longer output). For example: kmac256(256) ≠ prefix(kmac256(512)). This property can be important for security in protocols where variable-length hashes are used in different contexts.

Type:
Cryptographic hash function.
Output size:
arbitrary (any number of bits divisible by 8)
Default size:
none (must be specified)
Exceptions
std::runtime_errorif the requested digest size is not divisible by 8 (full bytes)

Optional parameters:

Optional parameters:
customization, key

See mixin::kmac_mixin for the description of optional parameters.

Example:
// Set key and output a 256-bit KMAC256 of a string
hasher.set_key(R("@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_"));
hasher.absorb("The quick brown fox jumps over the lazy dog");
std::cout << hasher.hexdigest() << '\n';
Example output:
bbe7d65fe0e7574254a13e0f3f79482275b96887287fc8b620a92ed5e5de3bce
See also
hasher, kmac256_xof, kmac128, mixin::kmac_mixin, digestpp::static_size::kmac256

◆ kmac256 [2/2]

KMAC256 in hash mode (static-size version)

Variant of KMAC256 with output size specified as template parameter.

While primary usage of KMAC is message authentication, it can also be used without a key as a regular hash function with the advantage that different output lengths produce independent digests.

Type:
Cryptographic hash function.
Exceptions
std::runtime_errorif the requested digest size is not divisible by 8 (full bytes)

Optional parameters:

Optional parameters:
customization, key

See mixin::kmac_mixin for the description of optional parameters.

Example:
// Set key and output a 256-bit KMAC256 of a string
hasher.set_key(R("@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_"));
hasher.absorb("The quick brown fox jumps over the lazy dog");
std::cout << hasher.hexdigest() << '\n';
Example output:
bbe7d65fe0e7574254a13e0f3f79482275b96887287fc8b620a92ed5e5de3bce
See also
hasher, kmac256_xof, mixin::kmac_mixin, digestpp::kmac256

◆ kmac256_xof

KMAC256 in XOF mode (KMACXOF256)

Specified in NIST SP 800-185.

Extendable Output Function mode of KMAC256. Higher security variant with 256-bit security level. Use when the required output length is not known in advance or when streaming output is needed.

For fixed-length output known in advance, use kmac256 (provides independent outputs for different lengths)

In XOF mode without a key, there are no advantages over cshake256, as squeezed outputs share the same prefix property (longer output = shorter output + more bytes).

Primary usage: MAC/PRF with variable or unknown output length

Type:
Extendable output function (XOF).

Optional parameters:

Optional parameters:
customization, key

See mixin::kmac_mixin for the description of optional parameters.

Example:
// Set key, absorb a string and squeeze 32 bytes of output
hasher.set_key(R"(@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_)");
hasher.absorb("The quick brown fox jumps over the lazy dog");
std::cout << hasher.hexsqueeze(32) << '\n';
Example output:
81ce507692e27fb404e4a765c3be3450ce5c090a61b8311f93eb4e35604877ad
See also
hasher, kmac256, mixin::kmac_mixin