BearSSL
Data Fields
br_hash_class Struct Reference

Class type for hash function implementations. More...

Data Fields

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

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
ctxpointer 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
ctxpointer to (the first field of) the context.
dstdestination 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
ctxpointer to (the first field of) the context.
stbsource buffer for the state.
countinjected 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
ctxpointer to (the first field of) the context.
dstdestination 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
ctxpointer to (the first field of) the context.
datapointer to the first data byte to inject.
lennumber of bytes to inject.

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