]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/gcrypt-util.h
tree-wide: beautify remaining copyright statements
[thirdparty/systemd.git] / src / basic / gcrypt-util.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2
3 /***
4 Copyright © 2016 Zbigniew Jędrzejewski-Szmek
5 ***/
6
7 #pragma once
8
9 #include <errno.h>
10 #include <stdbool.h>
11 #include <stddef.h>
12
13 #if HAVE_GCRYPT
14 #include <gcrypt.h>
15
16 #include "macro.h"
17
18 void initialize_libgcrypt(bool secmem);
19 int string_hashsum(const char *s, size_t len, int md_algorithm, char **out);
20
21 DEFINE_TRIVIAL_CLEANUP_FUNC(gcry_md_hd_t, gcry_md_close);
22 #endif
23
24 static inline int string_hashsum_sha224(const char *s, size_t len, char **out) {
25 #if HAVE_GCRYPT
26 return string_hashsum(s, len, GCRY_MD_SHA224, out);
27 #else
28 return -EOPNOTSUPP;
29 #endif
30 }
31
32 static inline int string_hashsum_sha256(const char *s, size_t len, char **out) {
33 #if HAVE_GCRYPT
34 return string_hashsum(s, len, GCRY_MD_SHA256, out);
35 #else
36 return -EOPNOTSUPP;
37 #endif
38 }