2017-11-18 17:09:20 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1+ */
|
2016-01-29 00:24:27 +01:00
|
|
|
|
2018-02-05 09:54:57 +01:00
|
|
|
#pragma once
|
|
|
|
|
2016-03-27 23:33:54 +02:00
|
|
|
#include <errno.h>
|
2016-01-29 00:24:27 +01:00
|
|
|
#include <stdbool.h>
|
2016-03-27 23:33:54 +02:00
|
|
|
#include <stddef.h>
|
|
|
|
|
2017-10-03 10:41:51 +02:00
|
|
|
#if HAVE_GCRYPT
|
2016-03-27 23:33:54 +02:00
|
|
|
#include <gcrypt.h>
|
2016-01-29 00:24:27 +01:00
|
|
|
|
2018-02-05 09:54:57 +01:00
|
|
|
#include "macro.h"
|
|
|
|
|
2016-01-29 00:24:27 +01:00
|
|
|
void initialize_libgcrypt(bool secmem);
|
2016-01-29 00:24:27 +01:00
|
|
|
int string_hashsum(const char *s, size_t len, int md_algorithm, char **out);
|
2018-02-05 09:54:57 +01:00
|
|
|
|
|
|
|
DEFINE_TRIVIAL_CLEANUP_FUNC(gcry_md_hd_t, gcry_md_close);
|
2016-03-27 23:33:54 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static inline int string_hashsum_sha224(const char *s, size_t len, char **out) {
|
2017-10-03 10:41:51 +02:00
|
|
|
#if HAVE_GCRYPT
|
2016-03-27 23:33:54 +02:00
|
|
|
return string_hashsum(s, len, GCRY_MD_SHA224, out);
|
|
|
|
#else
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
#endif
|
|
|
|
}
|
2016-10-08 13:59:34 +02:00
|
|
|
|
|
|
|
static inline int string_hashsum_sha256(const char *s, size_t len, char **out) {
|
2017-10-03 10:41:51 +02:00
|
|
|
#if HAVE_GCRYPT
|
2016-10-08 13:59:34 +02:00
|
|
|
return string_hashsum(s, len, GCRY_MD_SHA256, out);
|
|
|
|
#else
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
#endif
|
|
|
|
}
|