]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
91e023d8 ZJS |
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 | |
91e023d8 ZJS |
8 | ***/ |
9 | ||
bd944e6e ZJS |
10 | #pragma once |
11 | ||
b68f10bf | 12 | #include <errno.h> |
91e023d8 | 13 | #include <stdbool.h> |
b68f10bf ZJS |
14 | #include <stddef.h> |
15 | ||
349cc4a5 | 16 | #if HAVE_GCRYPT |
b68f10bf | 17 | #include <gcrypt.h> |
91e023d8 | 18 | |
bd944e6e ZJS |
19 | #include "macro.h" |
20 | ||
91e023d8 | 21 | void initialize_libgcrypt(bool secmem); |
4ac2ca1b | 22 | int string_hashsum(const char *s, size_t len, int md_algorithm, char **out); |
bd944e6e ZJS |
23 | |
24 | DEFINE_TRIVIAL_CLEANUP_FUNC(gcry_md_hd_t, gcry_md_close); | |
b68f10bf ZJS |
25 | #endif |
26 | ||
27 | static inline int string_hashsum_sha224(const char *s, size_t len, char **out) { | |
349cc4a5 | 28 | #if HAVE_GCRYPT |
b68f10bf ZJS |
29 | return string_hashsum(s, len, GCRY_MD_SHA224, out); |
30 | #else | |
31 | return -EOPNOTSUPP; | |
32 | #endif | |
33 | } | |
a60f4d0b SS |
34 | |
35 | static inline int string_hashsum_sha256(const char *s, size_t len, char **out) { | |
349cc4a5 | 36 | #if HAVE_GCRYPT |
a60f4d0b SS |
37 | return string_hashsum(s, len, GCRY_MD_SHA256, out); |
38 | #else | |
39 | return -EOPNOTSUPP; | |
40 | #endif | |
41 | } |