BearSSL: br_hash_class Struct Reference

BearSSL

Loading...
Searching...
No Matches
Data Fields
br_hash_class Struct Reference

Class type for hash function implementations. More...

`#include <bearssl_hash.h>`

## Data Fields
size_t | context_size
| Size (in bytes) of the context structure appropriate for computing this hash function.
uint32_t | desc
| Descriptor word that contains information about the hash function.
void(* | init )(const br_hash_class **ctx)
| Initialisation method.
void(* | update )(const br_hash_class **ctx, const void *data, size_t len)
| Data injection method.
void(* | out )(const br_hash_class *const *ctx, void *dst)
| Produce hash output.
uint64_t(* | state )(const br_hash_class *const *ctx, void *dst)
| Get running state.
void(* | set_state )(const br_hash_class **ctx, const void *stb, uint64_t count)
| Set running state.

## Detailed Description

Class type for hash function implementations.

A `br_hash_class` instance references the methods implementing a hash function. Constant instances of this structure are defined for each implemented hash function. Such instances are also called "vtables".

Vtables are used to support object-oriented programming, as described on the BearSSL Web site.

## Field Documentation

## ◆ context_size

size_t br_hash_class::context_size

Size (in bytes) of the context structure appropriate for computing this hash function.

## ◆ desc

uint32_t br_hash_class::desc

Descriptor word that contains information about the hash function.

For each word `xxx` described below, use `BR_HASHDESC_xxx_OFF` and `BR_HASHDESC_xxx_MASK` to access the specific value, as follows:

    (hf->desc >> BR_HASHDESC_xxx_OFF) & BR_HASHDESC_xxx_MASK

The defined elements are:

- `ID`: the symbolic identifier for the function, as defined in TLS (MD5 = 1, SHA-1 = 2,...).
- `OUT`: hash output size, in bytes.
- `STATE`: internal running state size, in bytes.
- `LBLEN`: base-2 logarithm for the internal block size, as defined for HMAC processing (this is 6 for MD5, SHA-1, SHA-224 and SHA-256, since these functions use 64-byte blocks; for SHA-384 and SHA-512, this is 7, corresponding to their 128-byte blocks).

The descriptor may contain a few other flags.

## ◆ init

void(* br_hash_class::init) (const br_hash_class **ctx)

Initialisation method.

This method takes as parameter a pointer to a context area, that it initialises. The first field of the context is set to this vtable; other elements are initialised for a new hash computation.

Parameters

  ctx | pointer to (the first field of) the context.

## ◆ out

void(* br_hash_class::out) (const br_hash_class *const *ctx, void *dst)

Produce hash output.

The hash output corresponding to all data bytes injected in the context since the last `init()` call is computed, and written in the buffer pointed to by `dst`. The hash output size depends on the implemented hash function (e.g. 16 bytes for MD5). The context is not modified by this call, so further bytes may be afterwards injected to continue the current computation.

Parameters

  ctx | pointer to (the first field of) the context.
  dst | destination buffer for the hash output.

## ◆ set_state

void(* br_hash_class::set_state) (const br_hash_class **ctx, const void *stb, uint64_t count)

Set running state.

This methods replaces the running state for the function.

Parameters

  ctx | pointer to (the first field of) the context.
  stb | source buffer for the state.
  count | injected total byte length.

## ◆ state

uint64_t(* br_hash_class::state) (const br_hash_class *const *ctx, void *dst)

Get running state.

This method saves the current running state into the `dst` buffer. What constitutes the "running state" depends on the hash function; for Merkle-Damgård hash functions (like MD5 or SHA-1), this is the output obtained after processing each block. The number of bytes injected so far is returned. The context is not modified by this call.

Parameters

  ctx | pointer to (the first field of) the context.
  dst | destination buffer for the state.

Returns
  the injected total byte length.

## ◆ update

void(* br_hash_class::update) (const br_hash_class **ctx, const void *data, size_t len)

Data injection method.

The `len` bytes starting at address `data` are injected into the running hash computation incarnated by the specified context. The context is updated accordingly. It is allowed to have `len == 0`, in which case `data` is ignored (and could be `NULL`), and nothing happens. on the input data.

Parameters

  ctx | pointer to (the first field of) the context.
  data | pointer to the first data byte to inject.
  len | number of bytes to inject.

The documentation for this struct was generated from the following file:

- bearssl_hash.h