]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/gcrypt-util.h
Merge pull request #8575 from keszybz/non-absolute-paths
[thirdparty/systemd.git] / src / basic / gcrypt-util.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
3
4 /***
5 This file is part of systemd.
6
7 Copyright 2016 Zbigniew Jędrzejewski-Szmek
8 ***/
9
10 #pragma once
11
12 #include <errno.h>
13 #include <stdbool.h>
14 #include <stddef.h>
15
16 #if HAVE_GCRYPT
17 #include <gcrypt.h>
18
19 #include "macro.h"
20
21 void initialize_libgcrypt(bool secmem);
22 int string_hashsum(const char *s, size_t len, int md_algorithm, char **out);
23
24 DEFINE_TRIVIAL_CLEANUP_FUNC(gcry_md_hd_t, gcry_md_close);
25 #endif
26
27 static inline int string_hashsum_sha224(const char *s, size_t len, char **out) {
28 #if HAVE_GCRYPT
29 return string_hashsum(s, len, GCRY_MD_SHA224, out);
30 #else
31 return -EOPNOTSUPP;
32 #endif
33 }
34
35 static inline int string_hashsum_sha256(const char *s, size_t len, char **out) {
36 #if HAVE_GCRYPT
37 return string_hashsum(s, len, GCRY_MD_SHA256, out);
38 #else
39 return -EOPNOTSUPP;
40 #endif
41 }