SharkSSL C/C++ Reference
TLS, cryptography, certificates, and PSA integration
SHA-3 and SHAKE sponge

Detailed Description

Byte-oriented native SHA3-256, SHA3-512, SHAKE128 and SHAKE256 operations.

See SharkSslKeccak.h for lifecycle, rate selection and output limits. For its role in ML-KEM and ML-DSA, see Post-quantum cryptography.

Files

file  SharkSslKeccak.h
 Byte-oriented SHA-3 and SHAKE sponge interface.
 

Data Structures

struct  SharkSslKeccak
 Caller-owned sponge storage; treat all members as implementation details. More...
 

Typedefs

typedef struct SharkSslKeccak SharkSslKeccak
 Caller-owned sponge storage; treat all members as implementation details. More...
 

Enumerations

enum  {
  SHARKSSL_KECCAK_RATE_SHAKE128 = 168 , SHARKSSL_KECCAK_RATE_SHAKE256 = 136 , SHARKSSL_KECCAK_RATE_SHA3_256 = 136 , SHARKSSL_KECCAK_RATE_SHA3_512 = 72 ,
  SHARKSSL_KECCAK_SUFFIX_SHA3 = 0x06 , SHARKSSL_KECCAK_SUFFIX_SHAKE = 0x1f
}
 Rate and domain-separation constants for the supported sponge algorithms. More...
 

Functions

void SharkSslKeccak_init (SharkSslKeccak *o, unsigned rate)
 Initialize or reset a FIPS 202 sponge for the selected algorithm. More...
 
void SharkSslKeccak_absorb (SharkSslKeccak *o, const uint8_t *data, size_t len)
 Append message bytes before finalization. More...
 
void SharkSslKeccak_finalize (SharkSslKeccak *o, uint8_t suffix)
 Apply padding and switch from message input to output. More...
 
void SharkSslKeccak_squeeze (SharkSslKeccak *o, uint8_t *out, size_t len)
 Read output bytes, continuing where the preceding call stopped. More...
 
void SharkSslKeccak_clear (SharkSslKeccak *o)
 Erase the complete context and leave it inactive. More...
 

Typedef Documentation

◆ SharkSslKeccak

Caller-owned sponge storage; treat all members as implementation details.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Rate and domain-separation constants for the supported sponge algorithms.

Enumerator
SHARKSSL_KECCAK_RATE_SHAKE128 

SHAKE128 rate in bytes.

SHARKSSL_KECCAK_RATE_SHAKE256 

SHAKE256 rate in bytes.

SHARKSSL_KECCAK_RATE_SHA3_256 

SHA3-256 rate in bytes.

SHARKSSL_KECCAK_RATE_SHA3_512 

SHA3-512 rate in bytes.

SHARKSSL_KECCAK_SUFFIX_SHA3 

SHA-3 domain suffix.

SHARKSSL_KECCAK_SUFFIX_SHAKE 

SHAKE domain suffix.

Function Documentation

◆ SharkSslKeccak_absorb()

void SharkSslKeccak_absorb ( SharkSslKeccak *  o,
const uint8_t *  data,
size_t  len 
)

Append message bytes before finalization.

Calls on an inactive or finalized context do nothing.

Parameters
oSharkSslKeccak *; required initialized context.
dataconst uint8_t *; borrowed input, not overlapping o; NULL only if len is 0.
lensize_t; input length in bytes; 0 is allowed.
Note
This function returns no status.

◆ SharkSslKeccak_clear()

void SharkSslKeccak_clear ( SharkSslKeccak *  o)

Erase the complete context and leave it inactive.

May be called at any phase, including on an already cleared context.

Parameters
oSharkSslKeccak *; required writable context.
Note
This function returns no status.

◆ SharkSslKeccak_finalize()

void SharkSslKeccak_finalize ( SharkSslKeccak *  o,
uint8_t  suffix 
)

Apply padding and switch from message input to output.

Repeated finalization, an inactive context, or an unsupported suffix does nothing.

Parameters
oSharkSslKeccak *; required initialized context.
suffixuint8_t; SHARKSSL_KECCAK_SUFFIX_SHA3 for SHA-3, or SHARKSSL_KECCAK_SUFFIX_SHAKE for SHAKE. Must match the selected algorithm.
Note
This function returns no status.

◆ SharkSslKeccak_init()

void SharkSslKeccak_init ( SharkSslKeccak *  o,
unsigned  rate 
)

Initialize or reset a FIPS 202 sponge for the selected algorithm.

Clears any previous state. An unsupported rate leaves the object inactive.

Parameters
oSharkSslKeccak *; required writable context; no prior initialization needed.
rateunsigned; rate in bytes: SHARKSSL_KECCAK_RATE_SHAKE128, SHARKSSL_KECCAK_RATE_SHAKE256, SHARKSSL_KECCAK_RATE_SHA3_256, or SHARKSSL_KECCAK_RATE_SHA3_512. There is no default.
Note
This function returns no status.

◆ SharkSslKeccak_squeeze()

void SharkSslKeccak_squeeze ( SharkSslKeccak *  o,
uint8_t *  out,
size_t  len 
)

Read output bytes, continuing where the preceding call stopped.

Before finalization or on an inactive context, this leaves out untouched. The caller limits total SHA-3 output to its fixed digest size.

Parameters
oSharkSslKeccak *; required initialized and finalized context.
outuint8_t *; caller-owned writable buffer of at least len bytes, not overlapping o; NULL only if len is 0.
lensize_t; requested output length in bytes; 0 is allowed.
Note
This function returns no status.