1 /* SPDX-License-Identifier: LGPL-2.1+ */
6 #include "gcrypt-util.h"
9 void initialize_libgcrypt(bool secmem
) {
11 if (gcry_control(GCRYCTL_INITIALIZATION_FINISHED_P
))
14 p
= gcry_check_version("1.4.5");
17 /* Turn off "secmem". Clients which wish to make use of this
18 * feature should initialize the library manually */
20 gcry_control(GCRYCTL_DISABLE_SECMEM
);
21 gcry_control(GCRYCTL_INITIALIZATION_FINISHED
, 0);
24 int string_hashsum(const char *s
, size_t len
, int md_algorithm
, char **out
) {
25 _cleanup_(gcry_md_closep
) gcry_md_hd_t md
= NULL
;
30 initialize_libgcrypt(false);
32 hash_size
= gcry_md_get_algo_dlen(md_algorithm
);
33 assert(hash_size
> 0);
35 gcry_md_open(&md
, md_algorithm
, 0);
39 gcry_md_write(md
, s
, len
);
41 hash
= gcry_md_read(md
, 0);
45 enc
= hexmem(hash
, hash_size
);