mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-12 11:20:10 +01:00
TCRYPT: move all header handling into library.
Add warning about unsupported modes.
This commit is contained in:
18
lib/setup.c
18
lib/setup.c
@@ -46,6 +46,10 @@ struct crypt_device {
|
||||
int password_verify;
|
||||
int rng_type;
|
||||
|
||||
// FIXME: switch to union
|
||||
// FIXME: privatre binary headers and access it properly
|
||||
// through sub-library (LUKS1, TCRYPT)
|
||||
|
||||
/* used in CRYPT_LUKS1 */
|
||||
struct luks_phdr hdr;
|
||||
uint64_t PBKDF2_per_sec;
|
||||
@@ -2426,11 +2430,8 @@ uint64_t crypt_get_data_offset(struct crypt_device *cd)
|
||||
if (isLOOPAES(cd->type))
|
||||
return cd->loopaes_hdr.offset;
|
||||
|
||||
if (isTCRYPT(cd->type)) { // FIXME: system vol.
|
||||
if (!cd->tcrypt_hdr.d.mk_offset)
|
||||
return 1;
|
||||
return (cd->tcrypt_hdr.d.mk_offset / cd->tcrypt_hdr.d.sector_size);
|
||||
}
|
||||
if (isTCRYPT(cd->type))
|
||||
return TCRYPT_get_data_offset(&cd->tcrypt_hdr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -2446,11 +2447,8 @@ uint64_t crypt_get_iv_offset(struct crypt_device *cd)
|
||||
if (isLOOPAES(cd->type))
|
||||
return cd->loopaes_hdr.skip;
|
||||
|
||||
if (isTCRYPT(cd->type)) {
|
||||
if (!cd->tcrypt_hdr.d.mk_offset)
|
||||
return 0;
|
||||
return (cd->tcrypt_hdr.d.mk_offset / cd->tcrypt_hdr.d.sector_size);
|
||||
}
|
||||
if (isTCRYPT(cd->type))
|
||||
return TCRYPT_get_iv_offset(&cd->tcrypt_hdr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -519,6 +519,17 @@ int TCRYPT_activate(struct crypt_device *cd,
|
||||
}
|
||||
};
|
||||
|
||||
if (!hdr->d.version) {
|
||||
log_dbg("TCRYPT: this function is not supported without encrypted header load.");
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
if (hdr->d.sector_size && hdr->d.sector_size != SECTOR_SIZE) {
|
||||
log_err(cd, _("Activation is not supported for %d sector size.\n"),
|
||||
hdr->d.sector_size);
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
if (strstr(params->mode, "-tcrypt")) {
|
||||
log_err(cd, _("Kernel doesn't support activation for this TCRYPT legacy mode.\n"));
|
||||
return -ENOTSUP;
|
||||
@@ -698,3 +709,18 @@ int TCRYPT_init_by_name(struct crypt_device *cd, const char *name,
|
||||
tcrypt_params->cipher = strdup(cipher);
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint64_t TCRYPT_get_data_offset(struct tcrypt_phdr *hdr)
|
||||
{
|
||||
// FIXME: system vol.
|
||||
if (!hdr->d.mk_offset)
|
||||
return 1;
|
||||
return (hdr->d.mk_offset / hdr->d.sector_size);
|
||||
}
|
||||
|
||||
uint64_t TCRYPT_get_iv_offset(struct tcrypt_phdr *hdr)
|
||||
{
|
||||
if (!hdr->d.mk_offset)
|
||||
return 0;
|
||||
return (hdr->d.mk_offset / hdr->d.sector_size);
|
||||
}
|
||||
|
||||
@@ -84,4 +84,7 @@ int TCRYPT_activate(struct crypt_device *cd,
|
||||
int TCRYPT_deactivate(struct crypt_device *cd,
|
||||
const char *name);
|
||||
|
||||
uint64_t TCRYPT_get_data_offset(struct tcrypt_phdr *hdr);
|
||||
uint64_t TCRYPT_get_iv_offset(struct tcrypt_phdr *hdr);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user