mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-05 16:00:05 +01:00
Simplify LUKS2 sector_size helpers.
This commit is contained in:
@@ -377,7 +377,7 @@ int LUKS2_wipe_header_areas(struct crypt_device *cd,
|
|||||||
|
|
||||||
uint64_t LUKS2_get_data_offset(struct luks2_hdr *hdr);
|
uint64_t LUKS2_get_data_offset(struct luks2_hdr *hdr);
|
||||||
int LUKS2_get_data_size(struct luks2_hdr *hdr, uint64_t *size, bool *dynamic);
|
int LUKS2_get_data_size(struct luks2_hdr *hdr, uint64_t *size, bool *dynamic);
|
||||||
int LUKS2_get_sector_size(struct luks2_hdr *hdr);
|
uint32_t LUKS2_get_sector_size(struct luks2_hdr *hdr);
|
||||||
const char *LUKS2_get_cipher(struct luks2_hdr *hdr, int segment);
|
const char *LUKS2_get_cipher(struct luks2_hdr *hdr, int segment);
|
||||||
const char *LUKS2_get_integrity(struct luks2_hdr *hdr, int segment);
|
const char *LUKS2_get_integrity(struct luks2_hdr *hdr, int segment);
|
||||||
int LUKS2_keyslot_params_default(struct crypt_device *cd, struct luks2_hdr *hdr,
|
int LUKS2_keyslot_params_default(struct crypt_device *cd, struct luks2_hdr *hdr,
|
||||||
|
|||||||
@@ -288,7 +288,7 @@ const char *json_segment_type(json_object *jobj_segment);
|
|||||||
uint64_t json_segment_get_iv_offset(json_object *jobj_segment);
|
uint64_t json_segment_get_iv_offset(json_object *jobj_segment);
|
||||||
uint64_t json_segment_get_size(json_object *jobj_segment, unsigned blockwise);
|
uint64_t json_segment_get_size(json_object *jobj_segment, unsigned blockwise);
|
||||||
const char *json_segment_get_cipher(json_object *jobj_segment);
|
const char *json_segment_get_cipher(json_object *jobj_segment);
|
||||||
int json_segment_get_sector_size(json_object *jobj_segment);
|
uint32_t json_segment_get_sector_size(json_object *jobj_segment);
|
||||||
bool json_segment_is_backup(json_object *jobj_segment);
|
bool json_segment_is_backup(json_object *jobj_segment);
|
||||||
json_object *json_segments_get_segment(json_object *jobj_segments, int segment);
|
json_object *json_segments_get_segment(json_object *jobj_segments, int segment);
|
||||||
unsigned json_segments_count(json_object *jobj_segments);
|
unsigned json_segments_count(json_object *jobj_segments);
|
||||||
|
|||||||
@@ -2235,15 +2235,9 @@ int LUKS2_get_volume_key_size(struct luks2_hdr *hdr, int segment)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int LUKS2_get_sector_size(struct luks2_hdr *hdr)
|
uint32_t LUKS2_get_sector_size(struct luks2_hdr *hdr)
|
||||||
{
|
{
|
||||||
json_object *jobj_segment;
|
return json_segment_get_sector_size(LUKS2_get_segment_jobj(hdr, CRYPT_DEFAULT_SEGMENT));
|
||||||
|
|
||||||
jobj_segment = LUKS2_get_segment_jobj(hdr, CRYPT_DEFAULT_SEGMENT);
|
|
||||||
if (!jobj_segment)
|
|
||||||
return SECTOR_SIZE;
|
|
||||||
|
|
||||||
return json_segment_get_sector_size(jobj_segment) ?: SECTOR_SIZE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int LUKS2_assembly_multisegment_dmd(struct crypt_device *cd,
|
int LUKS2_assembly_multisegment_dmd(struct crypt_device *cd,
|
||||||
|
|||||||
@@ -102,12 +102,12 @@ static const char *reencrypt_segment_cipher_old(struct luks2_hdr *hdr)
|
|||||||
return json_segment_get_cipher(reencrypt_segment(hdr, 0));
|
return json_segment_get_cipher(reencrypt_segment(hdr, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int reencrypt_get_sector_size_new(struct luks2_hdr *hdr)
|
static uint32_t reencrypt_get_sector_size_new(struct luks2_hdr *hdr)
|
||||||
{
|
{
|
||||||
return json_segment_get_sector_size(reencrypt_segment(hdr, 1));
|
return json_segment_get_sector_size(reencrypt_segment(hdr, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int reencrypt_get_sector_size_old(struct luks2_hdr *hdr)
|
static uint32_t reencrypt_get_sector_size_old(struct luks2_hdr *hdr)
|
||||||
{
|
{
|
||||||
return json_segment_get_sector_size(reencrypt_segment(hdr, 0));
|
return json_segment_get_sector_size(reencrypt_segment(hdr, 0));
|
||||||
}
|
}
|
||||||
@@ -705,15 +705,14 @@ void LUKS2_reencrypt_free(struct crypt_device *cd, struct luks2_reencrypt *rh)
|
|||||||
static size_t reencrypt_get_alignment(struct crypt_device *cd,
|
static size_t reencrypt_get_alignment(struct crypt_device *cd,
|
||||||
struct luks2_hdr *hdr)
|
struct luks2_hdr *hdr)
|
||||||
{
|
{
|
||||||
int ss;
|
size_t ss, alignment = device_block_size(cd, crypt_data_device(cd));
|
||||||
size_t alignment = device_block_size(cd, crypt_data_device(cd));
|
|
||||||
|
|
||||||
ss = reencrypt_get_sector_size_old(hdr);
|
ss = reencrypt_get_sector_size_old(hdr);
|
||||||
if (ss > 0 && (size_t)ss > alignment)
|
if (ss > alignment)
|
||||||
alignment = ss;
|
alignment = ss;
|
||||||
ss = reencrypt_get_sector_size_new(hdr);
|
ss = reencrypt_get_sector_size_new(hdr);
|
||||||
if (ss > 0 && (size_t)ss > alignment)
|
if (ss > alignment)
|
||||||
alignment = (size_t)ss;
|
alignment = ss;
|
||||||
|
|
||||||
return alignment;
|
return alignment;
|
||||||
}
|
}
|
||||||
@@ -2768,12 +2767,13 @@ static int reencrypt_load_by_passphrase(struct crypt_device *cd,
|
|||||||
struct volume_key **vks,
|
struct volume_key **vks,
|
||||||
const struct crypt_params_reencrypt *params)
|
const struct crypt_params_reencrypt *params)
|
||||||
{
|
{
|
||||||
int r, old_ss, new_ss, reencrypt_slot;
|
int r, reencrypt_slot;
|
||||||
struct luks2_hdr *hdr;
|
struct luks2_hdr *hdr;
|
||||||
struct crypt_lock_handle *reencrypt_lock;
|
struct crypt_lock_handle *reencrypt_lock;
|
||||||
struct luks2_reencrypt *rh;
|
struct luks2_reencrypt *rh;
|
||||||
const struct volume_key *vk;
|
const struct volume_key *vk;
|
||||||
size_t alignment;
|
size_t alignment;
|
||||||
|
uint32_t old_ss, new_ss;
|
||||||
struct crypt_dm_active_device dmd_target, dmd_source = {
|
struct crypt_dm_active_device dmd_target, dmd_source = {
|
||||||
.uuid = crypt_get_uuid(cd),
|
.uuid = crypt_get_uuid(cd),
|
||||||
.flags = CRYPT_ACTIVATE_SHARED /* turn off exclusive open checks */
|
.flags = CRYPT_ACTIVATE_SHARED /* turn off exclusive open checks */
|
||||||
|
|||||||
@@ -103,15 +103,17 @@ const char *json_segment_get_cipher(json_object *jobj_segment)
|
|||||||
return json_object_get_string(jobj);
|
return json_object_get_string(jobj);
|
||||||
}
|
}
|
||||||
|
|
||||||
int json_segment_get_sector_size(json_object *jobj_segment)
|
uint32_t json_segment_get_sector_size(json_object *jobj_segment)
|
||||||
{
|
{
|
||||||
json_object *jobj;
|
json_object *jobj;
|
||||||
|
int i;
|
||||||
|
|
||||||
if (!jobj_segment ||
|
if (!jobj_segment ||
|
||||||
!json_object_object_get_ex(jobj_segment, "sector_size", &jobj))
|
!json_object_object_get_ex(jobj_segment, "sector_size", &jobj))
|
||||||
return 0;
|
return SECTOR_SIZE;
|
||||||
|
|
||||||
return json_object_get_int(jobj);
|
i = json_object_get_int(jobj);
|
||||||
|
return i < 0 ? SECTOR_SIZE : i;
|
||||||
}
|
}
|
||||||
|
|
||||||
static json_object *json_segment_get_flags(json_object *jobj_segment)
|
static json_object *json_segment_get_flags(json_object *jobj_segment)
|
||||||
|
|||||||
Reference in New Issue
Block a user