1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
8 #include <libcryptsetup.h>
10 /* These next two are defined in libcryptsetup.h from cryptsetup version 2.3.4 forwards. */
11 #ifndef CRYPT_ACTIVATE_NO_READ_WORKQUEUE
12 #define CRYPT_ACTIVATE_NO_READ_WORKQUEUE (1 << 24)
14 #ifndef CRYPT_ACTIVATE_NO_WRITE_WORKQUEUE
15 #define CRYPT_ACTIVATE_NO_WRITE_WORKQUEUE (1 << 25)
18 extern int (*sym_crypt_activate_by_passphrase
)(struct crypt_device
*cd
, const char *name
, int keyslot
, const char *passphrase
, size_t passphrase_size
, uint32_t flags
);
19 #if HAVE_CRYPT_ACTIVATE_BY_SIGNED_KEY
20 extern int (*sym_crypt_activate_by_signed_key
)(struct crypt_device
*cd
, const char *name
, const char *volume_key
, size_t volume_key_size
, const char *signature
, size_t signature_size
, uint32_t flags
);
22 extern int (*sym_crypt_activate_by_volume_key
)(struct crypt_device
*cd
, const char *name
, const char *volume_key
, size_t volume_key_size
, uint32_t flags
);
23 extern int (*sym_crypt_deactivate_by_name
)(struct crypt_device
*cd
, const char *name
, uint32_t flags
);
24 extern int (*sym_crypt_format
)(struct crypt_device
*cd
, const char *type
, const char *cipher
, const char *cipher_mode
, const char *uuid
, const char *volume_key
, size_t volume_key_size
, void *params
);
25 extern void (*sym_crypt_free
)(struct crypt_device
*cd
);
26 extern const char *(*sym_crypt_get_dir
)(void);
27 extern int (*sym_crypt_get_verity_info
)(struct crypt_device
*cd
, struct crypt_params_verity
*vp
);
28 extern int (*sym_crypt_init
)(struct crypt_device
**cd
, const char *device
);
29 extern int (*sym_crypt_init_by_name
)(struct crypt_device
**cd
, const char *name
);
30 extern int (*sym_crypt_keyslot_add_by_volume_key
)(struct crypt_device
*cd
, int keyslot
, const char *volume_key
, size_t volume_key_size
, const char *passphrase
, size_t passphrase_size
);
31 extern int (*sym_crypt_load
)(struct crypt_device
*cd
, const char *requested_type
, void *params
);
32 extern int (*sym_crypt_resize
)(struct crypt_device
*cd
, const char *name
, uint64_t new_size
);
33 extern int (*sym_crypt_set_data_device
)(struct crypt_device
*cd
, const char *device
);
34 extern void (*sym_crypt_set_debug_level
)(int level
);
35 extern void (*sym_crypt_set_log_callback
)(struct crypt_device
*cd
, void (*log
)(int level
, const char *msg
, void *usrptr
), void *usrptr
);
36 extern int (*sym_crypt_set_pbkdf_type
)(struct crypt_device
*cd
, const struct crypt_pbkdf_type
*pbkdf
);
37 extern int (*sym_crypt_token_json_get
)(struct crypt_device
*cd
, int token
, const char **json
);
38 extern int (*sym_crypt_token_json_set
)(struct crypt_device
*cd
, int token
, const char *json
);
39 extern int (*sym_crypt_volume_key_get
)(struct crypt_device
*cd
, int keyslot
, char *volume_key
, size_t *volume_key_size
, const char *passphrase
, size_t passphrase_size
);
40 #if HAVE_CRYPT_TOKEN_MAX
41 extern int (*sym_crypt_token_max
)(const char *type
);
43 /* As a fallback, use the same hard-coded value libcryptsetup uses internally. */
44 static inline int sym_crypt_token_max(_unused_
const char *type
) {
45 assert(streq(type
, CRYPT_LUKS2
));
51 int dlopen_cryptsetup(void);
53 DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(struct crypt_device
*, crypt_free
, NULL
);
54 DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(struct crypt_device
*, sym_crypt_free
, NULL
);
56 void cryptsetup_enable_logging(struct crypt_device
*cd
);
58 int cryptsetup_set_minimal_pbkdf(struct crypt_device
*cd
);
60 int cryptsetup_get_token_as_json(struct crypt_device
*cd
, int idx
, const char *verify_type
, JsonVariant
**ret
);
61 int cryptsetup_get_keyslot_from_token(JsonVariant
*v
);
62 int cryptsetup_add_token_json(struct crypt_device
*cd
, JsonVariant
*v
);
66 /* If libcryptsetup is not available, let's at least define the basic type and NOP destructors for it, to
67 * make a little bit less #ifdeferry necessary in main programs. */
69 static inline void sym_crypt_free(struct crypt_device
* cd
) {}
70 static inline void sym_crypt_freep(struct crypt_device
** cd
) {}