1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 
3 #pragma once
4 
5 #include <errno.h>
6 #include <stdbool.h>
7 #include <stddef.h>
8 
9 #if HAVE_GCRYPT
10 #include <gcrypt.h>
11 
12 #include "macro.h"
13 
14 void initialize_libgcrypt(bool secmem);
15 
16 DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(gcry_md_hd_t, gcry_md_close, NULL);
17 #endif
18 
19 #if !PREFER_OPENSSL
20 #  if HAVE_GCRYPT
21 int string_hashsum(const char *s, size_t len, int md_algorithm, char **out);
22 #  endif
23 
string_hashsum_sha224(const char * s,size_t len,char ** out)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 
string_hashsum_sha256(const char * s,size_t len,char ** out)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 }
39 #endif
40