mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-11 10:50:01 +01:00
TCRYPT: add backup header option.
This commit is contained in:
@@ -389,9 +389,12 @@ struct crypt_params_verity {
|
|||||||
* @see crypt_format
|
* @see crypt_format
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
/** Include legacy modes ehn scannig for header*/
|
||||||
|
#define CRYPT_TCRYPT_LEGACY_MODES (1 << 0)
|
||||||
/** Try to load hidden header (describing hidden device) */
|
/** Try to load hidden header (describing hidden device) */
|
||||||
#define CRYPT_TCRYPT_HIDDEN_HEADER (1 << 0)
|
#define CRYPT_TCRYPT_HIDDEN_HEADER (1 << 1)
|
||||||
#define CRYPT_TCRYPT_LEGACY_MODES (1 << 1)
|
/** Try to load backup header */
|
||||||
|
#define CRYPT_TCRYPT_BACKUP_HEADER (1 << 2)
|
||||||
|
|
||||||
struct crypt_params_tcrypt {
|
struct crypt_params_tcrypt {
|
||||||
const char *passphrase;
|
const char *passphrase;
|
||||||
|
|||||||
@@ -528,7 +528,7 @@ int TCRYPT_read_phdr(struct crypt_device *cd,
|
|||||||
{
|
{
|
||||||
struct device *device = crypt_metadata_device(cd);
|
struct device *device = crypt_metadata_device(cd);
|
||||||
ssize_t hdr_size = sizeof(struct tcrypt_phdr);
|
ssize_t hdr_size = sizeof(struct tcrypt_phdr);
|
||||||
int devfd = 0, r = -EIO, bs;
|
int devfd = 0, r, bs;
|
||||||
|
|
||||||
assert(sizeof(struct tcrypt_phdr) == 512);
|
assert(sizeof(struct tcrypt_phdr) == 512);
|
||||||
|
|
||||||
@@ -545,7 +545,13 @@ int TCRYPT_read_phdr(struct crypt_device *cd,
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
r = -EIO;
|
||||||
if (params->flags & CRYPT_TCRYPT_HIDDEN_HEADER) {
|
if (params->flags & CRYPT_TCRYPT_HIDDEN_HEADER) {
|
||||||
|
if (params->flags & CRYPT_TCRYPT_BACKUP_HEADER) {
|
||||||
|
if (lseek(devfd, TCRYPT_HDR_HIDDEN_OFFSET_BCK, SEEK_END) >= 0 &&
|
||||||
|
read_blockwise(devfd, bs, hdr, hdr_size) == hdr_size)
|
||||||
|
r = TCRYPT_init_hdr(cd, hdr, params);
|
||||||
|
} else {
|
||||||
if (lseek(devfd, TCRYPT_HDR_HIDDEN_OFFSET, SEEK_SET) >= 0 &&
|
if (lseek(devfd, TCRYPT_HDR_HIDDEN_OFFSET, SEEK_SET) >= 0 &&
|
||||||
read_blockwise(devfd, bs, hdr, hdr_size) == hdr_size)
|
read_blockwise(devfd, bs, hdr, hdr_size) == hdr_size)
|
||||||
r = TCRYPT_init_hdr(cd, hdr, params);
|
r = TCRYPT_init_hdr(cd, hdr, params);
|
||||||
@@ -553,6 +559,11 @@ int TCRYPT_read_phdr(struct crypt_device *cd,
|
|||||||
lseek(devfd, TCRYPT_HDR_HIDDEN_OFFSET_OLD, SEEK_END) >= 0 &&
|
lseek(devfd, TCRYPT_HDR_HIDDEN_OFFSET_OLD, SEEK_END) >= 0 &&
|
||||||
read_blockwise(devfd, bs, hdr, hdr_size) == hdr_size)
|
read_blockwise(devfd, bs, hdr, hdr_size) == hdr_size)
|
||||||
r = TCRYPT_init_hdr(cd, hdr, params);
|
r = TCRYPT_init_hdr(cd, hdr, params);
|
||||||
|
}
|
||||||
|
} else if (params->flags & CRYPT_TCRYPT_BACKUP_HEADER) {
|
||||||
|
if (lseek(devfd, TCRYPT_HDR_OFFSET_BCK, SEEK_END) >= 0 &&
|
||||||
|
read_blockwise(devfd, bs, hdr, hdr_size) == hdr_size)
|
||||||
|
r = TCRYPT_init_hdr(cd, hdr, params);
|
||||||
} else if (read_blockwise(devfd, bs, hdr, hdr_size) == hdr_size)
|
} else if (read_blockwise(devfd, bs, hdr, hdr_size) == hdr_size)
|
||||||
r = TCRYPT_init_hdr(cd, hdr, params);
|
r = TCRYPT_init_hdr(cd, hdr, params);
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,9 @@
|
|||||||
#define TCRYPT_HDR_HIDDEN_OFFSET_OLD -1536
|
#define TCRYPT_HDR_HIDDEN_OFFSET_OLD -1536
|
||||||
#define TCRYPT_HDR_HIDDEN_OFFSET 65536
|
#define TCRYPT_HDR_HIDDEN_OFFSET 65536
|
||||||
|
|
||||||
|
#define TCRYPT_HDR_HIDDEN_OFFSET_BCK -65536
|
||||||
|
#define TCRYPT_HDR_OFFSET_BCK -131072
|
||||||
|
|
||||||
#define TCRYPT_LRW_IKEY_LEN 16
|
#define TCRYPT_LRW_IKEY_LEN 16
|
||||||
#define TCRYPT_KEY_POOL_LEN 64
|
#define TCRYPT_KEY_POOL_LEN 64
|
||||||
#define TCRYPT_KEYFILE_LEN 1048576
|
#define TCRYPT_KEYFILE_LEN 1048576
|
||||||
|
|||||||
Reference in New Issue
Block a user