6 #include "libcryptsetup.h"
9 extern struct hash_backend hash_gcrypt_backend;
12 static void init_plugins(void)
15 #else /* USE_PLUGINS */
16 # define init_plugins() do { } while(0)
17 #endif /* USE_PLUGINS */
19 static struct hash_backend *hash_backends[] = {
26 struct hash_backend *get_hash_backend(const char *name)
28 struct hash_backend **backend;
32 for(backend = hash_backends; *backend; backend++)
33 if (!name || strcmp(name, (*backend)->name) == 0)
39 void put_hash_backend(struct hash_backend *backend)
43 int hash(const char *backend_name, const char *hash_name,
44 char *result, size_t size,
45 const char *passphrase, size_t sizep)
47 struct hash_backend *backend;
48 struct hash_type *hashes = NULL, *hash;
49 char hash_name_buf[256], *s;
53 if (strlen(hash_name) >= sizeof(hash_name_buf)) {
54 set_error("hash name too long: %s", hash_name);
58 if ((s = strchr(hash_name, ':'))) {
60 strcpy(hash_name_buf, hash_name);
61 hash_name_buf[s-hash_name] = '\0';
62 hash_name = hash_name_buf;
65 set_error("requested hash length (%zd) > key length (%zd)", hlen, size);
72 backend = get_hash_backend(backend_name);
74 set_error("No hash backend found");
78 hashes = backend->get_hashes();
80 set_error("No hash functions available");
84 for(hash = hashes; hash->name; hash++)
85 if (strcmp(hash->name, hash_name) == 0)
88 set_error("Unknown hash type %s", hash_name);
92 r = hash->fn(hash->private, size, result, sizep, passphrase);
94 set_error("Error hashing passphrase");
99 memset(result+size, 0, pad);
104 backend->free_hashes(hashes);
105 put_hash_backend(backend);