Incremental MD5 and SHA-256 hash generation, sometimes with hardware acceleration.
More...
Incremental MD5 and SHA-256 hash generation, sometimes with hardware acceleration.
MD5 is not considered secure, but it is still useful for checksums and other non-security purposes. SHA-256 is recommended for security-sensitive uses and may have hardware acceleration on some platforms.
◆ sys_hash_algorithm_t
Hash algorithm identifiers.
| Enumerator |
|---|
| sys_hash_md5 | MD5 digest.
|
| sys_hash_sha256 | SHA-256 digest.
|
Definition at line 54 of file hash.h.
sys_hash_algorithm_t
Hash algorithm identifiers.
◆ sys_hash_deinit()
Release a hash context.
- Parameters
-
| hash | Pointer to the hash context to release. |
Releases all resources associated with the hash context and renders it unusable. After this call, the handle must not be used again.
◆ sys_hash_djb2()
| uintptr_t sys_hash_djb2 |
( |
const char * |
str | ) |
|
Compute a djb2 hash for a NULL-terminated string.
- Parameters
-
| str | The NULL-terminated string to hash. |
- Returns
- The computed hash value.
◆ sys_hash_finalize()
| const uint8_t* sys_hash_finalize |
( |
sys_hash_t * |
hash | ) |
|
Finalize the hash computation.
- Parameters
-
| hash | Pointer to the hash context. |
- Returns
- Pointer to the computed digest stored inside the hash context, or
NULL on failure.
The returned pointer remains owned by the hash context and is valid until sys_hash_deinit() is called for that handle.
◆ sys_hash_init()
Initialize a new hash context.
- Parameters
-
| algorithm | The hash algorithm to use. |
- Returns
- Initialized hash context, or
NULL if the algorithm is unsupported or no implementation capacity remains.
Allocates and initializes a hash context from an implementation-defined static capacity. The returned handle is ready for use with sys_hash_update() and sys_hash_finalize(). Call sys_hash_deinit() to release the slot for reuse.
◆ sys_hash_size()
Return the digest size in bytes for a hash context.
- Parameters
-
| hash | Pointer to the hash context. |
- Returns
- The digest size in bytes, or 0 if the context is invalid.
◆ sys_hash_update()
Update a hash context by reading more data from a stream.
- Parameters
-
| hash | Pointer to the hash context. |
| stream | The stream to read from. |
| size | Number of bytes to read from stream and feed into the hash, or 0 to read until end of stream. Call this repeatedly (e.g. once per chunk as it becomes available, each with an explicit size) to hash a stream incrementally, or once with size 0 to hash all of its remaining bytes in one call. |
- Returns
- true on success, false on error - including a short read (stream had fewer than size bytes left, when size is nonzero).