Line data Source code
1 : /* SPDX-License-Identifier: LGPL-2.1+ */
2 : #pragma once
3 :
4 : #include <inttypes.h>
5 : #include <sys/types.h>
6 : #include <sys/uio.h>
7 :
8 : #include "macro.h"
9 :
10 : typedef struct khash khash;
11 :
12 : int khash_supported(void);
13 :
14 : /* For plain hash functions. Hash functions commonly supported on today's kernels are: crc32c, crct10dif, crc32,
15 : * sha224, sha256, sha512, sha384, sha1, md5, md4, sha3-224, sha3-256, sha3-384, sha3-512, and more. */
16 : int khash_new(khash **ret, const char *algorithm);
17 :
18 : /* For keyed hash functions. Hash functions commonly supported on today's kernels are: hmac(sha256), cmac(aes),
19 : * cmac(des3_ede), hmac(sha3-512), hmac(sha3-384), hmac(sha3-256), hmac(sha3-224), hmac(rmd160), hmac(rmd128),
20 : * hmac(sha224), hmac(sha512), hmac(sha384), hmac(sha1), hmac(md5), and more. */
21 : int khash_new_with_key(khash **ret, const char *algorithm, const void *key, size_t key_size);
22 :
23 : int khash_dup(khash *h, khash **ret);
24 : khash* khash_unref(khash *h);
25 :
26 : const char *khash_get_algorithm(khash *h);
27 : size_t khash_get_size(khash *h);
28 :
29 : int khash_reset(khash *h);
30 :
31 : int khash_put(khash *h, const void *buffer, size_t size);
32 : int khash_put_iovec(khash *h, const struct iovec *iovec, size_t n);
33 :
34 : int khash_digest_data(khash *h, const void **ret);
35 : int khash_digest_string(khash *h, char **ret);
36 :
37 14 : DEFINE_TRIVIAL_CLEANUP_FUNC(khash*, khash_unref);
|