]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/basic/gcrypt-util.h
port string_hashsum from libgcrypt to openssl^gcrypt
[thirdparty/systemd.git] / src / basic / gcrypt-util.h
CommitLineData
db9ecf05 1/* SPDX-License-Identifier: LGPL-2.1-or-later */
91e023d8 2
bd944e6e
ZJS
3#pragma once
4
b68f10bf 5#include <errno.h>
91e023d8 6#include <stdbool.h>
b68f10bf
ZJS
7#include <stddef.h>
8
349cc4a5 9#if HAVE_GCRYPT
b68f10bf 10#include <gcrypt.h>
91e023d8 11
bd944e6e
ZJS
12#include "macro.h"
13
91e023d8 14void initialize_libgcrypt(bool secmem);
bd944e6e 15
fd421c4a 16DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(gcry_md_hd_t, gcry_md_close, NULL);
b68f10bf
ZJS
17#endif
18
7e8facb3
ZJS
19#if !PREFER_OPENSSL
20# if HAVE_GCRYPT
21int string_hashsum(const char *s, size_t len, int md_algorithm, char **out);
22# endif
23
b68f10bf 24static inline int string_hashsum_sha224(const char *s, size_t len, char **out) {
7e8facb3 25# if HAVE_GCRYPT
b68f10bf 26 return string_hashsum(s, len, GCRY_MD_SHA224, out);
7e8facb3 27# else
b68f10bf 28 return -EOPNOTSUPP;
7e8facb3 29# endif
b68f10bf 30}
a60f4d0b
SS
31
32static inline int string_hashsum_sha256(const char *s, size_t len, char **out) {
7e8facb3 33# if HAVE_GCRYPT
a60f4d0b 34 return string_hashsum(s, len, GCRY_MD_SHA256, out);
7e8facb3 35# else
a60f4d0b 36 return -EOPNOTSUPP;
7e8facb3 37# endif
a60f4d0b 38}
7e8facb3 39#endif