mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-05 16:00:05 +01:00
Refactor reencrypt_length() function.
This commit is contained in:
@@ -842,8 +842,7 @@ static int reencrypt_offset(struct luks2_hdr *hdr,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static uint64_t reencrypt_length(struct crypt_device *cd,
|
static uint64_t reencrypt_length(struct crypt_device *cd,
|
||||||
struct luks2_hdr *hdr,
|
struct reenc_protection *rp,
|
||||||
struct luks2_reencrypt *rh,
|
|
||||||
uint64_t keyslot_area_length,
|
uint64_t keyslot_area_length,
|
||||||
uint64_t length_max,
|
uint64_t length_max,
|
||||||
size_t alignment)
|
size_t alignment)
|
||||||
@@ -851,12 +850,12 @@ static uint64_t reencrypt_length(struct crypt_device *cd,
|
|||||||
unsigned long dummy, optimal_alignment;
|
unsigned long dummy, optimal_alignment;
|
||||||
uint64_t length, soft_mem_limit;
|
uint64_t length, soft_mem_limit;
|
||||||
|
|
||||||
if (rh->rp.type == REENC_PROTECTION_NONE)
|
if (rp->type == REENC_PROTECTION_NONE)
|
||||||
length = length_max ?: LUKS2_DEFAULT_NONE_REENCRYPTION_LENGTH;
|
length = length_max ?: LUKS2_DEFAULT_NONE_REENCRYPTION_LENGTH;
|
||||||
else if (rh->rp.type == REENC_PROTECTION_CHECKSUM)
|
else if (rp->type == REENC_PROTECTION_CHECKSUM)
|
||||||
length = (keyslot_area_length / rh->rp.p.csum.hash_size) * rh->rp.p.csum.block_size;
|
length = (keyslot_area_length / rp->p.csum.hash_size) * rp->p.csum.block_size;
|
||||||
else if (rh->rp.type == REENC_PROTECTION_DATASHIFT)
|
else if (rp->type == REENC_PROTECTION_DATASHIFT)
|
||||||
return rh->rp.p.ds.data_shift;
|
return rp->p.ds.data_shift;
|
||||||
else
|
else
|
||||||
length = keyslot_area_length;
|
length = keyslot_area_length;
|
||||||
|
|
||||||
@@ -942,7 +941,7 @@ static int reencrypt_context_init(struct crypt_device *cd,
|
|||||||
} else
|
} else
|
||||||
rh->fixed_length = false;
|
rh->fixed_length = false;
|
||||||
|
|
||||||
rh->length = reencrypt_length(cd, hdr, rh, area_length, max_hotzone_size << SECTOR_SHIFT, alignment);
|
rh->length = reencrypt_length(cd, &rh->rp, area_length, max_hotzone_size << SECTOR_SHIFT, alignment);
|
||||||
if (!rh->length) {
|
if (!rh->length) {
|
||||||
log_dbg(cd, "Invalid reencryption length.");
|
log_dbg(cd, "Invalid reencryption length.");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|||||||
Reference in New Issue
Block a user