Mbed TLS v3.6.3
Loading...
Searching...
No Matches
Data Structures | Macros | Enumerations | Functions
sha3.h File Reference

This file contains SHA-3 definitions and functions. More...

#include "mbedtls/private_access.h"
#include "mbedtls/build_info.h"
#include <stddef.h>
#include <stdint.h>
Include dependency graph for sha3.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  mbedtls_sha3_context
 The SHA-3 context structure. More...
 

Macros

#define MBEDTLS_ERR_SHA3_BAD_INPUT_DATA   -0x0076
 

Enumerations

enum  mbedtls_sha3_id {
  MBEDTLS_SHA3_NONE = 0 , MBEDTLS_SHA3_224 , MBEDTLS_SHA3_256 , MBEDTLS_SHA3_384 ,
  MBEDTLS_SHA3_512
}
 

Functions

void mbedtls_sha3_init (mbedtls_sha3_context *ctx)
 This function initializes a SHA-3 context.
 
void mbedtls_sha3_free (mbedtls_sha3_context *ctx)
 This function clears a 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.
 
int mbedtls_sha3_starts (mbedtls_sha3_context *ctx, mbedtls_sha3_id id)
 This function starts a SHA-3 checksum calculation.
 
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.
 
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.
 
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.
 
int mbedtls_sha3_self_test (int verbose)
 Checkup routine for the algorithms implemented by this module: SHA3-224, SHA3-256, SHA3-384, SHA3-512.
 

Detailed Description

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 .

Definition in file sha3.h.

Macro Definition Documentation

◆ MBEDTLS_ERR_SHA3_BAD_INPUT_DATA

#define MBEDTLS_ERR_SHA3_BAD_INPUT_DATA   -0x0076

SHA-3 input data was malformed.

Definition at line 29 of file sha3.h.

Enumeration Type Documentation

◆ mbedtls_sha3_id

SHA-3 family id.

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

Enumerator
MBEDTLS_SHA3_NONE 

Operation not defined.

MBEDTLS_SHA3_224 

SHA3-224

MBEDTLS_SHA3_256 

SHA3-256

MBEDTLS_SHA3_384 

SHA3-384

MBEDTLS_SHA3_512 

SHA3-512

Definition at line 37 of file sha3.h.

Function Documentation

◆ mbedtls_sha3()

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
idThe id of the SHA-3 family.
inputThe buffer holding the data. This must be a readable buffer of length ilen Bytes.
ilenThe length of the input data in Bytes.
outputThe SHA-3 checksum result. This must be a writable buffer of length olen bytes.
olenDefines 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.
A negative error code on failure.

◆ mbedtls_sha3_clone()

void mbedtls_sha3_clone ( mbedtls_sha3_context dst,
const mbedtls_sha3_context src 
)

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

Parameters
dstThe destination context. This must be initialized.
srcThe context to clone. This must be initialized.

◆ mbedtls_sha3_finish()

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
ctxThe SHA-3 context. This must be initialized and have a hash operation started.
outputThe SHA-3 checksum result. This must be a writable buffer of length olen bytes.
olenDefines 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.
A negative error code on failure.

◆ mbedtls_sha3_free()

void mbedtls_sha3_free ( mbedtls_sha3_context ctx)

This function clears a SHA-3 context.

Parameters
ctxThe 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.

◆ mbedtls_sha3_init()

void mbedtls_sha3_init ( mbedtls_sha3_context ctx)

This function initializes a SHA-3 context.

Parameters
ctxThe SHA-3 context to initialize. This must not be NULL.

◆ mbedtls_sha3_self_test()

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.

◆ mbedtls_sha3_starts()

int mbedtls_sha3_starts ( mbedtls_sha3_context ctx,
mbedtls_sha3_id  id 
)

This function starts a SHA-3 checksum calculation.

Parameters
ctxThe context to use. This must be initialized.
idThe id of the SHA-3 family.
Returns
0 on success.
A negative error code on failure.

◆ mbedtls_sha3_update()

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
ctxThe SHA-3 context. This must be initialized and have a hash operation started.
inputThe buffer holding the data. This must be a readable buffer of length ilen Bytes.
ilenThe length of the input data in Bytes.
Returns
0 on success.
A negative error code on failure.