File sha3.h

This file contains SHA-3 definitions and functions.

The Secure Hash Algorithms cryptographic hash functions are defined in FIPS 202: SHA-3 Standard: Permutation-Based Hash and Extendable-Output Functions .

Defines

MBEDTLS_ERR_SHA3_BAD_INPUT_DATA

SHA-3 input data was malformed.

Enums

enum mbedtls_sha3_id

SHA-3 family id.

It identifies the family (SHA3-256, SHA3-512, etc.)

Values:

enumerator MBEDTLS_SHA3_NONE

Operation not defined.

enumerator MBEDTLS_SHA3_224

SHA3-224

enumerator MBEDTLS_SHA3_256

SHA3-256

enumerator MBEDTLS_SHA3_384

SHA3-384

enumerator MBEDTLS_SHA3_512

SHA3-512

Functions

void mbedtls_sha3_init(mbedtls_sha3_context *ctx)

This function initializes a SHA-3 context.

Parameters:

ctx – The SHA-3 context to initialize. This must not be NULL.

void mbedtls_sha3_free(mbedtls_sha3_context *ctx)

This function clears a SHA-3 context.

Parameters:

ctx – The SHA-3 context to clear. This may be NULL, in which case this function returns immediately. If it is not NULL, it must point to an initialized SHA-3 context.

void mbedtls_sha3_clone(mbedtls_sha3_context *dst, const mbedtls_sha3_context *src)

This function clones the state of a SHA-3 context.

Parameters:
  • dst – The destination context. This must be initialized.

  • src – The context to clone. This must be initialized.

int mbedtls_sha3_starts(mbedtls_sha3_context *ctx, mbedtls_sha3_id id)

This function starts a SHA-3 checksum calculation.

Parameters:
  • ctx – The context to use. This must be initialized.

  • id – The id of the SHA-3 family.

Returns:

0 on success.

Returns:

A negative error code on failure.

int mbedtls_sha3_update(mbedtls_sha3_context *ctx, const uint8_t *input, size_t ilen)

This function feeds an input buffer into an ongoing SHA-3 checksum calculation.

Parameters:
  • ctx – The SHA-3 context. This must be initialized and have a hash operation started.

  • input – The buffer holding the data. This must be a readable buffer of length ilen Bytes.

  • ilen – The length of the input data in Bytes.

Returns:

0 on success.

Returns:

A negative error code on failure.

int mbedtls_sha3_finish(mbedtls_sha3_context *ctx, uint8_t *output, size_t olen)

This function finishes the SHA-3 operation, and writes the result to the output buffer.

Parameters:
  • ctx – The SHA-3 context. This must be initialized and have a hash operation started.

  • output – The SHA-3 checksum result. This must be a writable buffer of length olen bytes.

  • olen – Defines the length of output buffer (in bytes). For SHA-3 224, SHA-3 256, SHA-3 384 and SHA-3 512 olen must equal to 28, 32, 48 and 64, respectively.

Returns:

0 on success.

Returns:

A negative error code on failure.

int mbedtls_sha3(mbedtls_sha3_id id, const uint8_t *input, size_t ilen, uint8_t *output, size_t olen)

This function calculates the SHA-3 checksum of a buffer.

The function allocates the context, performs the calculation, and frees the context.

The SHA-3 result is calculated as output = SHA-3(id, input buffer, d).

Parameters:
  • id – The id of the SHA-3 family.

  • input – The buffer holding the data. This must be a readable buffer of length ilen Bytes.

  • ilen – The length of the input data in Bytes.

  • output – The SHA-3 checksum result. This must be a writable buffer of length olen bytes.

  • olen – Defines the length of output buffer (in bytes). For SHA-3 224, SHA-3 256, SHA-3 384 and SHA-3 512 olen must equal to 28, 32, 48 and 64, respectively.

Returns:

0 on success.

Returns:

A negative error code on failure.

int mbedtls_sha3_self_test(int verbose)

Checkup routine for the algorithms implemented by this module: SHA3-224, SHA3-256, SHA3-384, SHA3-512.

Returns:

0 if successful, or 1 if the test failed.

struct mbedtls_sha3_context
#include <sha3.h>

The SHA-3 context structure.

            The structure is used SHA-3 checksum calculations.

Public Members

uint64_t private_state[25]
uint32_t private_index
uint16_t private_olen
uint16_t private_max_block_size