libGimbal 0.1.0
C17-Based Extended Standard Library and Cross-Language Runtime Framework
Loading...
Searching...
No Matches
gimbal_sha1.h
Go to the documentation of this file.
1/*! \file
2 * \brief SHA1 cryptographic hashing algorithm and API
3 * \ingroup hashing
4 *
5 * This file contains the libGimbal API providing the
6 * SHA1 cryptographic hashing algorithm.
7 *
8 * \warning
9 * Even though the implementation has been validated via
10 * unit testing, it has never been validated by NIST, so
11 * it cannot be said to be in official compliance with the
12 * standard.
13 *
14 * \author 1998 Steve Reid
15 * \author 1998 James H. Brown
16 * \author 2001 Saul Kravitz
17 * \author 2002 Ralph giles
18 * \author 2023 Falco Girgis
19 *
20 * \copyright Public Domain
21 */
22#ifndef GIMBAL_SHA1_H
23#define GIMBAL_SHA1_H
24
25#include "../core/gimbal_decls.h"
26
27#define GBL_SHA1_DIGEST_SIZE 20 //!< Size of a SHA1 digest
28#define GBL_SHA1_DIGEST_STRING_SIZE 80 //!< Buffer sized required for GblSha1_string()
29
30#define GBL_SELF_TYPE GblSha1Context
31
33
34/*! Context structure used for maintaining SHA1 hashing state
35 * \ingroup hashing
36 */
37typedef struct GblSha1Context {
38 uint32_t state[5]; //!< Current accumulated hash state
39 uint32_t count[2]; //!< Running counter of # of hashed blocks
40 unsigned char buffer[64]; //!< Buffer containing current 512-bit block of data
41} GblSha1Context;
42
43/*! \name Incremental hashing
44 * \brief Methods for operating on an SHA1 context
45 * \relatesalso GblSha1Context
46 * @{
47 */
48//! Initializes the given SHA1 context
50
51//! Adds the data in \p pData of \p length bytes to the running SHA1 hash context
53 const void* pData,
54 size_t length) GBL_NOEXCEPT;
55//! Finalizes the running SHA1 hash context, returning its digest
57 uint8_t digest[GBL_SHA1_DIGEST_SIZE]) GBL_NOEXCEPT;
58//! @}
59
60//! Returns the display-friendly hexadecimal form of the given digest, with each 32-bit word separated by a space
61GBL_EXPORT const char* GblSha1_string (const uint8_t digest[GBL_SHA1_DIGEST_SIZE],
63
65
66#undef GBL_SELF_TYPE
67
68#endif // GIMBAL_SHA1_H
#define GBL_NOEXCEPT
#define GBL_DECLS_BEGIN
#define GBL_EXPORT
#define GBL_SHA1_DIGEST_SIZE
Size of a SHA1 digest.
Definition gimbal_sha1.h:27
#define GBL_SHA1_DIGEST_STRING_SIZE
Buffer sized required for GblSha1_string()
Definition gimbal_sha1.h:28
Context structure used for maintaining SHA1 hashing state.
Definition gimbal_sha1.h:37
void GblSha1_final(GblSha1Context *pSelf, uint8_t digest[20])
Finalizes the running SHA1 hash context, returning its digest.
uint32_t count[2]
Running counter of # of hashed blocks.
Definition gimbal_sha1.h:39
uint32_t state[5]
Current accumulated hash state.
Definition gimbal_sha1.h:38
unsigned char buffer[64]
Buffer containing current 512-bit block of data.
Definition gimbal_sha1.h:40
const char * GblSha1_string(const uint8_t digest[20], char buffer[80])
Returns the display-friendly hexadecimal form of the given digest, with each 32-bit word separated by...
void GblSha1_init(GblSha1Context *pSelf)
Initializes the given SHA1 context.
void GblSha1_update(GblSha1Context *pSelf, const void *pData, size_t length)
Adds the data in pData of length bytes to the running SHA1 hash context.