BearSSL
|
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... | |
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.
size_t br_hash_class::context_size |
Size (in bytes) of the context structure appropriate for computing this hash function.
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.
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.
ctx | pointer to (the first field of) the context. |
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.
ctx | pointer to (the first field of) the context. |
dst | destination buffer for the hash output. |
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.
ctx | pointer to (the first field of) the context. |
stb | source buffer for the state. |
count | injected total byte length. |
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.
ctx | pointer to (the first field of) the context. |
dst | destination buffer for the state. |
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.
ctx | pointer to (the first field of) the context. |
data | pointer to the first data byte to inject. |
len | number of bytes to inject. |