libhasha 2.2.2
Loading...
Searching...
No Matches
sha1.h File Reference

Header file for the SHA-1 cryptographic hash algorithm. More...

Include dependency graph for sha1.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ha_sha1_context
 SHA-1 context structure used to store the internal state during hashing. More...

Macros

#define HA_SHA1_BLOCK_SIZE   64
 The block size used in SHA-1 (in bytes).
#define HA_SHA1_DIGEST_SIZE   ha_bB(160)
 The size of the SHA-1 hash output (in bytes).

Typedefs

typedef struct ha_sha1_context ha_sha1_context

Functions

HA_PUBFUN void ha_sha1_transform (ha_sha1_context *ctx, const uint8_t *block)
 Performs the SHA-1 transformation step on a 512-bit data block.
HA_PUBFUN void ha_sha1_init (ha_sha1_context *ctx)
 Initializes the SHA-1 context for a new hash computation.
HA_PUBFUN void ha_sha1_update (ha_sha1_context *ctx, ha_inbuf_t data, size_t len)
 Updates the SHA-1 context with new data.
HA_PUBFUN void ha_sha1_final (ha_sha1_context *ctx, ha_digest_t digest)
 Finalizes the SHA-1 context and produces the resulting hash digest.
HA_PUBFUN void ha_sha1_hash (ha_inbuf_t data, size_t len, ha_digest_t digest)
 Computes the SHA-1 hash for the given input data in one-shot mode.

Detailed Description

Header file for the SHA-1 cryptographic hash algorithm.

This header file defines the interface for the SHA-1 hash function, including the context structure, constants, and function declarations required for computing a SHA-1 hash. SHA-1 is a widely-used cryptographic hash function that produces a 160-bit (20-byte) hash value, and is commonly used for data integrity verification.

The functions provided in this file allow for incremental hashing via context initialization, data updating, and finalization, as well as a one-shot function for computing the hash of an entire input in a single call.

Note
SHA-1 is considered weak for modern cryptographic applications and should be used only in legacy systems or non-critical applications.
See also
https://en.wikipedia.org/wiki/SHA-1 for further information on SHA-1.

Definition in file sha1.h.

Macro Definition Documentation

◆ HA_SHA1_BLOCK_SIZE

#define HA_SHA1_BLOCK_SIZE   64

The block size used in SHA-1 (in bytes).

Definition at line 32 of file sha1.h.

◆ HA_SHA1_DIGEST_SIZE

#define HA_SHA1_DIGEST_SIZE   ha_bB(160)

The size of the SHA-1 hash output (in bytes).

Definition at line 38 of file sha1.h.

Typedef Documentation

◆ ha_sha1_context

typedef struct ha_sha1_context ha_sha1_context

Function Documentation

◆ ha_sha1_final()

HA_PUBFUN void ha_sha1_final ( ha_sha1_context * ctx,
ha_digest_t digest )

Finalizes the SHA-1 context and produces the resulting hash digest.

This function finals the hash computation, pads the data if necessary, and produces the final 160-bit (20-byte) hash digest in the provided output buffer.

Parameters
ctxPointer to the SHA-1 context structure.
digestPointer to the output buffer where the 160-bit hash digest will be stored.

◆ ha_sha1_hash()

HA_PUBFUN void ha_sha1_hash ( ha_inbuf_t data,
size_t len,
ha_digest_t digest )

Computes the SHA-1 hash for the given input data in one-shot mode.

This function computes the SHA-1 hash for the entire input data in a single call, without requiring separate initialization, update, or final steps.

Parameters
dataPointer to the input data.
lenThe length of the input data.
digestPointer to the output buffer where the 160-bit hash digest will be stored.

◆ ha_sha1_init()

HA_PUBFUN void ha_sha1_init ( ha_sha1_context * ctx)

Initializes the SHA-1 context for a new hash computation.

This function initializes the SHA-1 context to its starting state with the default initial hash values (SHA1_H0) and prepares the context for the hashing process.

Parameters
ctxPointer to the SHA-1 context structure.

◆ ha_sha1_transform()

HA_PUBFUN void ha_sha1_transform ( ha_sha1_context * ctx,
const uint8_t * block )

Performs the SHA-1 transformation step on a 512-bit data block.

This function processes the given data block and updates the internal state of the SHA-1 context with the result.

Parameters
ctxPointer to the SHA-1 context structure.
blockPointer to the 512-bit (64-byte) input data block.

◆ ha_sha1_update()

HA_PUBFUN void ha_sha1_update ( ha_sha1_context * ctx,
ha_inbuf_t data,
size_t len )

Updates the SHA-1 context with new data.

This function updates the SHA-1 context with a portion of the input data. It processes the input data in 512-bit blocks and handles the internal state updates.

Parameters
ctxPointer to the SHA-1 context structure.
dataPointer to the input data.
lenThe length of the input data.