objc

hash.h
Go to the documentation of this file.
1 
23 #pragma once
24 #include <stdbool.h>
25 #include <stddef.h>
26 #include <stdint.h>
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
39 #define SYS_HASH_SIZE 32
40 
48 #define SYS_HASH_CTX_SIZE 128
49 
56 typedef enum {
58  1,
62 
70 typedef struct {
71  sys_hash_algorithm_t
73  uint8_t hash[SYS_HASH_SIZE];
74  size_t size;
76  union {
77  void *ptr;
78  uint8_t ctx[SYS_HASH_CTX_SIZE];
79  } ctx;
81 } sys_hash_t;
82 
98 extern sys_hash_t sys_hash_init(sys_hash_algorithm_t algorithm);
99 
110 extern size_t sys_hash_size(sys_hash_t *hash);
111 
120 extern bool sys_hash_update(sys_hash_t *hash, const void *data, size_t size);
121 
132 extern const uint8_t *sys_hash_finalize(sys_hash_t *hash);
133 
140 extern uintptr_t sys_hash_djb2(const char *str);
141 
142 #ifdef __cplusplus
143 }
144 #endif
size_t sys_hash_size(sys_hash_t *hash)
Returns the size of the hash in bytes.
sys_hash_algorithm_t
Hash algorithm identifiers.
Definition: hash.h:56
void * ptr
Pointer to external hash context (e.g., OpenSSL EVP_MD_CTX)
Definition: hash.h:77
Hash context structure.
Definition: hash.h:70
MD5 hash algorithm (128-bit output, not cryptographically secure)
Definition: hash.h:57
#define SYS_HASH_SIZE
Size of the hash.
Definition: hash.h:39
sys_hash_t sys_hash_init(sys_hash_algorithm_t algorithm)
Initializes a new hash context for the specified algorithm.
SHA-256 hash algorithm (256-bit output, cryptographically secure)
Definition: hash.h:59
bool sys_hash_update(sys_hash_t *hash, const void *data, size_t size)
Updates the hash context with new data.
const uint8_t * sys_hash_finalize(sys_hash_t *hash)
Finalizes the hash computation and returns the hash value.
#define SYS_HASH_CTX_SIZE
Size of the hash context buffer.
Definition: hash.h:48
uintptr_t sys_hash_djb2(const char *str)
djb2 hash function for strings
sys_hash_algorithm_t algorithm
The hash algorithm being used for this context.
Definition: hash.h:72