1 /* SPDX-License-Identifier: LGPL-2.1+ */
6 #include "gcrypt-util.h"
9 void initialize_libgcrypt(bool secmem
) {
10 if (gcry_control(GCRYCTL_INITIALIZATION_FINISHED_P
))
13 assert_se(gcry_check_version("1.4.5"));
15 /* Turn off "secmem". Clients which wish to make use of this
16 * feature should initialize the library manually */
18 gcry_control(GCRYCTL_DISABLE_SECMEM
);
19 gcry_control(GCRYCTL_INITIALIZATION_FINISHED
, 0);
22 int string_hashsum(const char *s
, size_t len
, int md_algorithm
, char **out
) {
23 _cleanup_(gcry_md_closep
) gcry_md_hd_t md
= NULL
;
28 initialize_libgcrypt(false);
30 hash_size
= gcry_md_get_algo_dlen(md_algorithm
);
31 assert(hash_size
> 0);
33 gcry_md_open(&md
, md_algorithm
, 0);
37 gcry_md_write(md
, s
, len
);
39 hash
= gcry_md_read(md
, 0);
43 enc
= hexmem(hash
, hash_size
);