]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/basic/gcrypt-util.h
util: introduce memcmp_safe()
[thirdparty/systemd.git] / src / basic / gcrypt-util.h
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
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);
4ac2ca1b 15int string_hashsum(const char *s, size_t len, int md_algorithm, char **out);
bd944e6e
ZJS
16
17DEFINE_TRIVIAL_CLEANUP_FUNC(gcry_md_hd_t, gcry_md_close);
b68f10bf
ZJS
18#endif
19
20static inline int string_hashsum_sha224(const char *s, size_t len, char **out) {
349cc4a5 21#if HAVE_GCRYPT
b68f10bf
ZJS
22 return string_hashsum(s, len, GCRY_MD_SHA224, out);
23#else
24 return -EOPNOTSUPP;
25#endif
26}
a60f4d0b
SS
27
28static inline int string_hashsum_sha256(const char *s, size_t len, char **out) {
349cc4a5 29#if HAVE_GCRYPT
a60f4d0b
SS
30 return string_hashsum(s, len, GCRY_MD_SHA256, out);
31#else
32 return -EOPNOTSUPP;
33#endif
34}