|
CX Framework
Cross-platform C utility framework
|
Data Structures | |
| struct | Digest |
Macros | |
| #define | DIGEST_BLOCKSIZE 64 |
| Internal block size in bytes used by all supported digest algorithms. | |
Typedefs | |
| typedef struct Digest | Digest |
Enumerations | |
| enum | DigestType { DIGEST_MD5 , DIGEST_SHA1 , DIGEST_SHA256 , DIGEST_COUNT } |
| Supported message digest algorithms. More... | |
Functions | |
| void | digestInit (Digest *digest, DigestType type) |
| void | digestUpdate (Digest *digest, uint8 *data, uint32 size) |
| void | digestFinish (Digest *digest, uint8 *out) |
Variables | |
| uint32 | DigestSize [DIGEST_COUNT] |
Cryptographic hash functions including MD5, SHA-1, and SHA-256.
The digest API provides incremental hashing through a simple three-step process:
All supported algorithms use a 64-byte internal block size and can process data of any length. Contexts can be reused by calling digestInit() again.
Example:
Digest context structure.
Contains the state for computing a message digest incrementally. All fields are internal and should not be accessed directly.
| enum DigestType |
| void digestFinish | ( | Digest * | digest, |
| uint8 * | out | ||
| ) |
Finalizes the digest computation and outputs the hash.
Completes the digest computation by adding padding and length as required by the algorithm specification, then outputs the final hash value. After calling this function, digestInit() must be called again to reuse the context.
| digest | Digest context that has been updated with data |
| out | Buffer to receive the hash output, must be at least DigestSize[type] bytes |
Example:
| void digestInit | ( | Digest * | digest, |
| DigestType | type | ||
| ) |
Initializes a digest context for computing a message digest.
Must be called before using digestUpdate() or digestFinish(). The context can be reused after digestFinish() by calling digestInit() again.
| digest | Digest context to initialize |
| type | Algorithm to use (DIGEST_MD5, DIGEST_SHA1, or DIGEST_SHA256) |
Example:
| void digestUpdate | ( | Digest * | digest, |
| uint8 * | data, | ||
| uint32 | size | ||
| ) |
Incrementally processes data for the message digest.
Can be called multiple times to hash data in chunks. All data passed to digestUpdate() is accumulated until digestFinish() is called to produce the final hash.
| digest | Initialized digest context |
| data | Data to process |
| size | Number of bytes to process |
Example:
|
extern |
Size in bytes of the resulting digest for each algorithm. Index with DigestType: DigestSize[DIGEST_MD5] = 16, DigestSize[DIGEST_SHA1] = 20, DigestSize[DIGEST_SHA256] = 32