sha3
Embeddable C11 SHA-3 implementation.
Data Structures | Functions
sha3.h File Reference

C11 implementation of FIPS 202, NIST SP 800-185, and the draft KangarooTwelve and TurboSHAKE specification. More...

#include <stddef.h>
#include <stdint.h>
Include dependency graph for sha3.h:

Go to the source code of this file.

Data Structures

union  sha3_state_t
 Internal SHA-3 state (all members are private). More...
 
struct  sha3_t
 Iterative SHA-3 context (all members are private). More...
 
struct  sha3_xof_t
 Iterative XOF context (all members are private). More...
 
struct  hmac_sha3_t
 HMAC-SHA3 (Hash-based Message Authentication Code) context (all members are private). More...
 
struct  cshake_params_t
 cSHAKE parameters. More...
 
struct  kmac_params_t
 KMAC configuration parameters (key and customization string). More...
 
struct  tuplehash_str_t
 Individual element of TupleHash tuple. More...
 
struct  tuplehash_params_t
 TupleHash configuration parameters. More...
 
struct  parallelhash_params_t
 ParallelHash configuration parameters. More...
 
struct  parallelhash_t
 ParallelHash context (all members are private). More...
 
struct  turboshake_t
 TurboShake XOF context (all members are private). More...
 
struct  k12_t
 KangarooTwelve XOF context (all members are private). More...
 

Functions

void sha3_224 (const uint8_t *src, size_t len, uint8_t dst[static 28])
 Calculate SHA3-224 hash of input data. More...
 
void sha3_224_init (sha3_t *hash)
 Initialize SHA3-224 hash context. More...
 
_Bool sha3_224_absorb (sha3_t *hash, const uint8_t *src, const size_t len)
 Initialize SHA3-224 hash context. More...
 
void sha3_224_final (sha3_t *hash, uint8_t dst[28])
 Finalize SHA3-224 hash context and write 28 bytes of output to destination buffer dst. More...
 
void sha3_256 (const uint8_t *src, size_t len, uint8_t dst[static 32])
 Calculate SHA3-256 hash of input data. More...
 
void sha3_256_init (sha3_t *hash)
 Initialize SHA3-256 hash context. More...
 
_Bool sha3_256_absorb (sha3_t *hash, const uint8_t *src, const size_t len)
 Absorb input data into SHA3-256 hash context. More...
 
void sha3_256_final (sha3_t *hash, uint8_t dst[32])
 Finalize SHA3-256 hash context and write 32 bytes of output to destination buffer dst. More...
 
void sha3_384 (const uint8_t *src, size_t len, uint8_t dst[static 48])
 Calculate SHA3-384 hash of input data. More...
 
void sha3_384_init (sha3_t *hash)
 Initialize SHA3-384 hash context. More...
 
_Bool sha3_384_absorb (sha3_t *hash, const uint8_t *src, const size_t len)
 Absorb input data into SHA3-384 hash context. More...
 
void sha3_384_final (sha3_t *hash, uint8_t dst[48])
 Finalize SHA3-384 hash context and write 48 bytes of output to destination buffer dst. More...
 
void sha3_512 (const uint8_t *src, size_t len, uint8_t dst[static 64])
 Calculate SHA3-512 hash of input data. More...
 
void sha3_512_init (sha3_t *hash)
 Initialize SHA3-512 hash context. More...
 
_Bool sha3_512_absorb (sha3_t *hash, const uint8_t *src, const size_t len)
 Absorb input data into SHA3-512 hash context. More...
 
void sha3_512_final (sha3_t *hash, uint8_t dst[64])
 Finalize SHA3-512 hash context and write 64 bytes of output to destination buffer dst. More...
 
void shake128_init (sha3_xof_t *const xof)
 Initialize SHAKE128 extendable-output function (XOF) context. More...
 
_Bool shake128_absorb (sha3_xof_t *xof, const uint8_t *msg, const size_t len)
 Absorb data into SHAKE128 XOF context. More...
 
void shake128_squeeze (sha3_xof_t *xof, uint8_t *dst, const size_t len)
 Squeeze bytes from SHAKE128 XOF context. More...
 
void shake128 (const uint8_t *src, const size_t src_len, uint8_t *dst, const size_t dst_len)
 Absorb data into SHAKE128 XOF, then squeeze bytes out. More...
 
void shake256_init (sha3_xof_t *xof)
 Initialize SHAKE256 extendable-output function (XOF) context. More...
 
_Bool shake256_absorb (sha3_xof_t *xof, const uint8_t *msg, const size_t len)
 Absorb data into SHAKE256 XOF context. More...
 
void shake256_squeeze (sha3_xof_t *xof, uint8_t *dst, const size_t len)
 Squeeze bytes from SHAKE256 XOF context. More...
 
void shake256 (const uint8_t *src, const size_t src_len, uint8_t *dst, const size_t dst_len)
 Absorb data into SHAKE256 XOF, then squeeze bytes out. More...
 
void hmac_sha3_224 (const uint8_t *key, const size_t key_len, const uint8_t *msg, const size_t msg_len, uint8_t mac[28])
 Calculate HMAC-SHA3-224 of given key and data. More...
 
void hmac_sha3_256 (const uint8_t *key, const size_t key_len, const uint8_t *msg, const size_t msg_len, uint8_t mac[32])
 Calculate HMAC-SHA3-256 given key and data. More...
 
void hmac_sha3_384 (const uint8_t *key, const size_t key_len, const uint8_t *msg, const size_t msg_len, uint8_t mac[48])
 Calculate HMAC-SHA3-384 of given key and data. More...
 
void hmac_sha3_512 (const uint8_t *key, const size_t key_len, const uint8_t *msg, const size_t msg_len, uint8_t mac[64])
 Calculate HMAC-SHA3-512 of given key and data. More...
 
void hmac_sha3_224_init (hmac_sha3_t *ctx, const uint8_t *key, const size_t key_len)
 Initialize HMAC-SHA3-224 (FIPS 202, Section 7) context. More...
 
_Bool hmac_sha3_224_absorb (hmac_sha3_t *ctx, const uint8_t *src, const size_t len)
 Absorb data into HMAC-SHA3-224 context. More...
 
void hmac_sha3_224_final (hmac_sha3_t *ctx, uint8_t mac[28])
 Finalize HMAC-SHA3-224 context and write 28 byte MAC to destination buffer. More...
 
void hmac_sha3_256_init (hmac_sha3_t *ctx, const uint8_t *key, const size_t key_len)
 Initialize HMAC-SHA3-256 (FIPS 202, Section 7) context. More...
 
_Bool hmac_sha3_256_absorb (hmac_sha3_t *ctx, const uint8_t *src, const size_t len)
 Absorb data into HMAC-SHA3-256 context. More...
 
void hmac_sha3_256_final (hmac_sha3_t *ctx, uint8_t mac[32])
 Finalize HMAC-SHA3-256 context and write 32 byte MAC to destination buffer. More...
 
void hmac_sha3_384_init (hmac_sha3_t *ctx, const uint8_t *key, const size_t key_len)
 Initialize HMAC-SHA3-384 (FIPS 202, Section 7) context. More...
 
_Bool hmac_sha3_384_absorb (hmac_sha3_t *ctx, const uint8_t *src, const size_t len)
 Absorb data into HMAC-SHA3-384 context. More...
 
void hmac_sha3_384_final (hmac_sha3_t *ctx, uint8_t mac[48])
 Finalize HMAC-SHA3-384 context and write 48 byte MAC to destination buffer. More...
 
void hmac_sha3_512_init (hmac_sha3_t *ctx, const uint8_t *key, const size_t key_len)
 Initialize HMAC-SHA3-512 (FIPS 202, Section 7) context. More...
 
_Bool hmac_sha3_512_absorb (hmac_sha3_t *ctx, const uint8_t *src, const size_t len)
 Absorb data into HMAC-SHA3-512 context. More...
 
void hmac_sha3_512_final (hmac_sha3_t *ctx, uint8_t mac[64])
 Finalize HMAC-SHA3-512 context and write 64 byte MAC to destination buffer. More...
 
void cshake128 (const cshake_params_t params, const uint8_t *src, const size_t src_len, uint8_t *dst, const size_t dst_len)
 Initialize cSHAKE128, absorb data, then squeeze bytes out. More...
 
void cshake256 (const cshake_params_t params, const uint8_t *src, const size_t src_len, uint8_t *dst, const size_t dst_len)
 Initialize cSHAKE256, absorb data, then squeeze bytes out. More...
 
void cshake128_xof_init (sha3_xof_t *xof, const cshake_params_t params)
 Initialize cSHAKE128 XOF context. More...
 
_Bool cshake128_xof_absorb (sha3_xof_t *xof, const uint8_t *src, const size_t len)
 Absorb data into cSHAKE128 XOF context. More...
 
void cshake128_xof_squeeze (sha3_xof_t *xof, uint8_t *dst, const size_t len)
 Squeeze bytes from cSHAKE128 XOF context. More...
 
void cshake256_xof_init (sha3_xof_t *xof, const cshake_params_t params)
 Initialize cSHAKE256 XOF context. More...
 
_Bool cshake256_xof_absorb (sha3_xof_t *xof, const uint8_t *src, const size_t len)
 Absorb data into cSHAKE256 XOF context. More...
 
void cshake256_xof_squeeze (sha3_xof_t *xof, uint8_t *dst, const size_t len)
 Squeeze bytes from cSHAKE256 XOF context. More...
 
void kmac128 (const kmac_params_t params, const uint8_t *src, const size_t src_len, uint8_t *dst, const size_t dst_len)
 Absorb data into KMAC128, then squeeze bytes out. More...
 
void kmac256 (const kmac_params_t params, const uint8_t *src, const size_t src_len, uint8_t *dst, const size_t dst_len)
 Absorb data into KMAC256, then squeeze bytes out. More...
 
void kmac128_xof_init (sha3_xof_t *xof, const kmac_params_t params)
 Initialize KMAC128 XOF context. More...
 
_Bool kmac128_xof_absorb (sha3_xof_t *xof, const uint8_t *src, const size_t len)
 Absorb data into KMAC128 XOF context. More...
 
void kmac128_xof_squeeze (sha3_xof_t *xof, uint8_t *dst, const size_t len)
 Squeeze data from KMAC128 XOF context. More...
 
void kmac128_xof_once (const kmac_params_t params, const uint8_t *src, const size_t src_len, uint8_t *dst, const size_t dst_len)
 Absorb data into KMAC128 XOF context, then squeeze bytes out. More...
 
void kmac256_xof_init (sha3_xof_t *xof, const kmac_params_t params)
 Initialize KMAC256 XOF context. More...
 
_Bool kmac256_xof_absorb (sha3_xof_t *xof, const uint8_t *src, const size_t len)
 Absorb data into KMAC256 XOF context. More...
 
void kmac256_xof_squeeze (sha3_xof_t *xof, uint8_t *dst, const size_t len)
 Squeeze data from KMAC256 XOF context. More...
 
void kmac256_xof_once (const kmac_params_t params, const uint8_t *src, const size_t src_len, uint8_t *dst, const size_t dst_len)
 Absorb data into KMAC256 XOF context, then squeeze bytes out. More...
 
void tuplehash128 (const tuplehash_params_t params, uint8_t *dst, const size_t len)
 Absorb tuple and customization string into TupleHash128, then squeeze bytes out. More...
 
void tuplehash256 (const tuplehash_params_t params, uint8_t *dst, const size_t len)
 Absorb tuple and customization string into TupleHash256, then squeeze bytes out. More...
 
void tuplehash128_xof_init (sha3_xof_t *xof, const tuplehash_params_t params)
 Initialize a TupleHash128 XOF context. More...
 
void tuplehash128_xof_squeeze (sha3_xof_t *xof, uint8_t *dst, const size_t len)
 Squeeze data from TupleHash128 XOF context. More...
 
void tuplehash128_xof_once (const tuplehash_params_t params, uint8_t *dst, const size_t len)
 Absorb data into TupleHash128 XOF, then squeeze bytes out. More...
 
void tuplehash256_xof_init (sha3_xof_t *xof, const tuplehash_params_t params)
 Initialize a TupleHash256 XOF context. More...
 
void tuplehash256_xof_squeeze (sha3_xof_t *xof, uint8_t *dst, const size_t len)
 Squeeze bytes from a TupleHash256 XOF context. More...
 
void tuplehash256_xof_once (const tuplehash_params_t params, uint8_t *dst, const size_t len)
 Absorb data into TupleHash256 XOF, then squeeze bytes out. More...
 
void parallelhash128 (const parallelhash_params_t params, const uint8_t *src, const size_t src_len, uint8_t *dst, const size_t dst_len)
 Absorb data into ParallelHash128, then squeeze bytes out. More...
 
void parallelhash256 (const parallelhash_params_t params, const uint8_t *src, const size_t src_len, uint8_t *dst, const size_t dst_len)
 Absorb data into ParallelHash256, then squeeze bytes out. More...
 
void parallelhash128_xof_init (parallelhash_t *xof, const parallelhash_params_t params)
 Initialize a ParallelHash128 XOF context. More...
 
void parallelhash128_xof_absorb (parallelhash_t *hash, const uint8_t *src, const size_t len)
 Absorb data into a ParallelHash128 XOF context. More...
 
void parallelhash128_xof_squeeze (parallelhash_t *xof, uint8_t *dst, const size_t len)
 Squeeze bytes from a ParallelHash128 XOF context. More...
 
void parallelhash128_xof_once (const parallelhash_params_t params, const uint8_t *src, const size_t src_len, uint8_t *dst, const size_t dst_len)
 Absorb bytes into ParallelHash128 XOF, then squeeze bytes out. More...
 
void parallelhash256_xof_init (parallelhash_t *xof, const parallelhash_params_t params)
 Initialize a ParallelHash256 XOF context. More...
 
void parallelhash256_xof_absorb (parallelhash_t *xof, const uint8_t *src, const size_t len)
 Absorb data into a ParallelHash256 XOF context. More...
 
void parallelhash256_xof_squeeze (parallelhash_t *xof, uint8_t *dst, const size_t len)
 Squeeze bytes from a ParallelHash256 XOF context. More...
 
void parallelhash256_xof_once (const parallelhash_params_t params, const uint8_t *src, const size_t src_len, uint8_t *dst, const size_t dst_len)
 Absorb bytes into ParallelHash256 XOF, then squeeze bytes out. More...
 
void turboshake128 (const uint8_t *src, const size_t src_len, uint8_t *dst, const size_t dst_len)
 Absorb bytes into TurboSHAKE128 XOF, then squeeze bytes out. More...
 
void turboshake128_custom (const uint8_t pad, const uint8_t *src, const size_t src_len, uint8_t *dst, const size_t dst_len)
 Absorb bytes into TurboSHAKE128 XOF with custom padding byte, then squeeze bytes out. More...
 
void turboshake256 (const uint8_t *src, const size_t src_len, uint8_t *dst, const size_t dst_len)
 Absorb bytes into TurboSHAKE256 XOF, then squeeze bytes out. More...
 
void turboshake256_custom (const uint8_t pad, const uint8_t *src, const size_t src_len, uint8_t *dst, const size_t dst_len)
 Absorb bytes into TurboSHAKE256 XOF with custom padding byte, then squeeze bytes out. More...
 
void turboshake128_init (turboshake_t *ts)
 Initialize TurboSHAKE128 XOF context. More...
 
_Bool turboshake128_init_custom (turboshake_t *ts, const uint8_t pad)
 Initialize TurboSHAKE128 XOF context with custom padding byte. More...
 
_Bool turboshake128_absorb (turboshake_t *ts, const uint8_t *src, const size_t len)
 Absorb data into TurboSHAKE128 XOF context. More...
 
void turboshake128_squeeze (turboshake_t *ts, uint8_t *dst, const size_t len)
 Squeeze bytes from TurboSHAKE128 XOF context. More...
 
void turboshake256_init (turboshake_t *ts)
 Initialize TurboSHAKE256 XOF context. More...
 
_Bool turboshake256_init_custom (turboshake_t *ts, const uint8_t pad)
 Initialize TurboSHAKE256 XOF context with custom padding byte. More...
 
_Bool turboshake256_absorb (turboshake_t *ts, const uint8_t *src, const size_t len)
 Absorb data into TurboSHAKE256 XOF context. More...
 
void turboshake256_squeeze (turboshake_t *ts, uint8_t *dst, const size_t len)
 Squeeze bytes from TurboSHAKE256 XOF context. More...
 
void k12_once (const uint8_t *src, const size_t src_len, uint8_t *dst, const size_t dst_len)
 Absorb data into KangarooTwelve, then squeeze bytes out. More...
 
void k12_custom_once (const uint8_t *src, const size_t src_len, const uint8_t *custom, const size_t custom_len, uint8_t *dst, const size_t dst_len)
 Absorb data into KangarooTwelve with customization string, then squeeze bytes out. More...
 
void k12_init (k12_t *k12, const uint8_t *src, const size_t src_len, const uint8_t *custom, const size_t custom_len)
 Initialize KangarooTwelve context. More...
 
void k12_squeeze (k12_t *k12, uint8_t *dst, const size_t len)
 Squeeze bytes from KangarooTwelve context. More...
 
const char * sha3_backend (void)
 Get name of backend. More...
 

Detailed Description

C11 implementation of FIPS 202, NIST SP 800-185, and the draft KangarooTwelve and TurboSHAKE specification.

Author
Paul Duncan

sha3 https://pablotron.org/sha3

Copyright (c) 2023, 2024 Paul Duncan SPDX-License-Identifier: MIT-0

Embeddable, dependency-free, MIT-0-licensed C11 implementation of the following SHA-3 hash functions, XOFs, and HMACs: