5 #include <openssl/evp.h>
7 #include "libcryptsetup.h"
15 int hash(const char *backend_name
, const char *hash_name
,
16 char *result
, size_t size
,
17 const char *passphrase
, size_t sizep
)
24 OpenSSL_add_all_digests();
25 md
= EVP_get_digestbyname(hash_name
);
27 set_error("Unknown hash type %s", hash_name
);
31 if (EVP_MD_size(md
) > size
) {
32 set_error("requested hash length (%zd) > key length (%zd)", EVP_MD_size(md
), size
);
36 pad
= size
- EVP_MD_size(md
);
38 EVP_DigestInit(&mdctx
, md
);
39 EVP_DigestUpdate(&mdctx
, passphrase
, sizep
);
40 r
= !EVP_DigestFinal(&mdctx
, result
, NULL
);
43 memset(result
+size
, 0, pad
);