Debian Codegraph @

src/shared/cryptsetup-util.h

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include "sd-dlopen.h"
5
6 #include "dlfcn-util.h"
7 #include "shared-forward.h"
8
9 #if HAVE_LIBCRYPTSETUP
10 #include <libcryptsetup.h> /* IWYU pragma: export */
11
12 /* Available since libcryptsetup 2.7. Always redeclare so DLSYM_PROTOTYPE's typeof() resolves on older
13 * headers; suppress the warning when newer libcryptsetup already declares them. */
14 DISABLE_WARNING_REDUNDANT_DECLS;
15 /* NOLINTBEGIN(readability-redundant-declaration) */
16 extern int crypt_set_keyring_to_link(struct crypt_device *cd,
17 const char *key_description,
18 const char *old_key_description,
19 const char *key_type_desc,
20 const char *keyring_to_link_vk);
21 extern int crypt_token_set_external_path(const char *path);
22 /* NOLINTEND(readability-redundant-declaration) */
23 REENABLE_WARNING;
24
25 extern DLSYM_PROTOTYPE(crypt_activate_by_passphrase);
26 extern DLSYM_PROTOTYPE(crypt_activate_by_signed_key);
27 extern DLSYM_PROTOTYPE(crypt_activate_by_token_pin);
28 extern DLSYM_PROTOTYPE(crypt_activate_by_volume_key);
29 extern DLSYM_PROTOTYPE(crypt_deactivate);
30 extern DLSYM_PROTOTYPE(crypt_deactivate_by_name);
31 extern DLSYM_PROTOTYPE(crypt_format);
32 extern DLSYM_PROTOTYPE(crypt_free);
33 extern DLSYM_PROTOTYPE(crypt_get_cipher);
34 extern DLSYM_PROTOTYPE(crypt_get_cipher_mode);
35 extern DLSYM_PROTOTYPE(crypt_get_data_offset);
36 extern DLSYM_PROTOTYPE(crypt_get_device_name);
37 extern DLSYM_PROTOTYPE(crypt_get_dir);
38 extern DLSYM_PROTOTYPE(crypt_get_type);
39 extern DLSYM_PROTOTYPE(crypt_get_uuid);
40 extern DLSYM_PROTOTYPE(crypt_get_verity_info);
41 extern DLSYM_PROTOTYPE(crypt_get_volume_key_size);
42 extern DLSYM_PROTOTYPE(crypt_header_restore);
43 extern DLSYM_PROTOTYPE(crypt_init);
44 extern DLSYM_PROTOTYPE(crypt_init_by_name);
45 extern DLSYM_PROTOTYPE(crypt_init_data_device);
46 extern DLSYM_PROTOTYPE(crypt_keyslot_add_by_volume_key);
47 extern DLSYM_PROTOTYPE(crypt_keyslot_destroy);
48 extern DLSYM_PROTOTYPE(crypt_keyslot_max);
49 extern DLSYM_PROTOTYPE(crypt_keyslot_status);
50 extern DLSYM_PROTOTYPE(crypt_load);
51 extern DLSYM_PROTOTYPE(crypt_logf);
52 extern DLSYM_PROTOTYPE(crypt_metadata_locking);
53 extern DLSYM_PROTOTYPE(crypt_persistent_flags_get);
54 extern DLSYM_PROTOTYPE(crypt_persistent_flags_set);
55 extern DLSYM_PROTOTYPE(crypt_reencrypt_init_by_passphrase);
56 extern DLSYM_PROTOTYPE(crypt_reencrypt_run);
57 extern DLSYM_PROTOTYPE(crypt_resize);
58 extern DLSYM_PROTOTYPE(crypt_resume_by_volume_key);
59 extern DLSYM_PROTOTYPE(crypt_set_data_device);
60 extern DLSYM_PROTOTYPE(crypt_set_data_offset);
61 extern DLSYM_PROTOTYPE(crypt_set_debug_level);
62 extern DLSYM_PROTOTYPE(crypt_set_keyring_to_link);
63 extern DLSYM_PROTOTYPE(crypt_set_log_callback);
64 extern DLSYM_PROTOTYPE(crypt_set_metadata_size);
65 extern DLSYM_PROTOTYPE(crypt_set_pbkdf_type);
66 extern DLSYM_PROTOTYPE(crypt_status);
67 extern DLSYM_PROTOTYPE(crypt_suspend);
68 extern DLSYM_PROTOTYPE(crypt_token_external_path);
69 extern DLSYM_PROTOTYPE(crypt_token_json_get);
70 extern DLSYM_PROTOTYPE(crypt_token_json_set);
71 extern DLSYM_PROTOTYPE(crypt_token_max);
72 extern DLSYM_PROTOTYPE(crypt_token_set_external_path);
73 extern DLSYM_PROTOTYPE(crypt_token_status);
74 extern DLSYM_PROTOTYPE(crypt_volume_key_get);
75 extern DLSYM_PROTOTYPE(crypt_volume_key_keyring);
76 extern DLSYM_PROTOTYPE(crypt_wipe);
77 extern DLSYM_PROTOTYPE(crypt_get_integrity_info);
78
79 /* Be careful, these work with dlopen_cryptsetup(), that is, they call sym_crypt_free() instead of
80 * crypt_free() and hence depend on dlopen_cryptsetup() having been called. */
81 DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_RENAME(struct crypt_device *, sym_crypt_free, crypt_freep, NULL);
82 #define crypt_free_and_replace(a, b) \
83 free_and_replace_full(a, b, sym_crypt_free)
84
85 void cryptsetup_enable_logging(struct crypt_device *cd);
86
87 int cryptsetup_set_minimal_pbkdf(struct crypt_device *cd);
88
89 int cryptsetup_get_token_as_json(struct crypt_device *cd, int idx, const char *verify_type, sd_json_variant **ret);
90 int cryptsetup_add_token_json(struct crypt_device *cd, sd_json_variant *v);
91 int cryptsetup_get_volume_key_prefix(struct crypt_device *cd, const char *volume_name, char **ret);
92 int cryptsetup_get_volume_key_id(struct crypt_device *cd, const char *volume_name, const void *volume_key,
93 size_t volume_key_size, char **ret);
94
95 #define CRYPTSETUP_NOTE(priority) \
96 SD_ELF_NOTE_DLOPEN("cryptsetup", \
97 "Support for disk encryption, integrity, and authentication", \
98 priority, \
99 "libcryptsetup.so.12")
100
101 #define DLOPEN_CRYPTSETUP(log_level, priority) \
102 ({ \
103 CRYPTSETUP_NOTE(priority); \
104 dlopen_cryptsetup(log_level); \
105 })
106 #else
107 #define DLOPEN_CRYPTSETUP(log_level, priority) dlopen_cryptsetup(log_level)
108 #endif
109
110 int dlopen_cryptsetup(int log_level);
111
112 int cryptsetup_get_keyslot_from_token(sd_json_variant *v);
113
114 const char* mangle_none(const char *s);