mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-11 10:50:01 +01:00
Move cipher parsing outside LUKS2 header generator function.
Let's make LUKS2_generate_hdr as clean as possible. Cipher specification string can be constructed in upper layers. This will make future LUKS2_generate_hdr extension easier.
This commit is contained in:
@@ -378,8 +378,7 @@ int LUKS2_generate_hdr(
|
|||||||
struct crypt_device *cd,
|
struct crypt_device *cd,
|
||||||
struct luks2_hdr *hdr,
|
struct luks2_hdr *hdr,
|
||||||
const struct volume_key *vk,
|
const struct volume_key *vk,
|
||||||
const char *cipherName,
|
const char *cipher_spec,
|
||||||
const char *cipherMode,
|
|
||||||
const char *integrity,
|
const char *integrity,
|
||||||
const char *uuid,
|
const char *uuid,
|
||||||
unsigned int sector_size,
|
unsigned int sector_size,
|
||||||
|
|||||||
@@ -204,8 +204,7 @@ int LUKS2_generate_hdr(
|
|||||||
struct crypt_device *cd,
|
struct crypt_device *cd,
|
||||||
struct luks2_hdr *hdr,
|
struct luks2_hdr *hdr,
|
||||||
const struct volume_key *vk,
|
const struct volume_key *vk,
|
||||||
const char *cipherName,
|
const char *cipher_spec,
|
||||||
const char *cipherMode,
|
|
||||||
const char *integrity,
|
const char *integrity,
|
||||||
const char *uuid,
|
const char *uuid,
|
||||||
unsigned int sector_size, /* in bytes */
|
unsigned int sector_size, /* in bytes */
|
||||||
@@ -214,7 +213,6 @@ int LUKS2_generate_hdr(
|
|||||||
uint64_t keyslots_size_bytes)
|
uint64_t keyslots_size_bytes)
|
||||||
{
|
{
|
||||||
struct json_object *jobj_segment, *jobj_keyslots, *jobj_segments, *jobj_config;
|
struct json_object *jobj_segment, *jobj_keyslots, *jobj_segments, *jobj_config;
|
||||||
char cipher[128];
|
|
||||||
uuid_t partitionUuid;
|
uuid_t partitionUuid;
|
||||||
int r, digest;
|
int r, digest;
|
||||||
|
|
||||||
@@ -245,13 +243,6 @@ int LUKS2_generate_hdr(
|
|||||||
|
|
||||||
uuid_unparse(partitionUuid, hdr->uuid);
|
uuid_unparse(partitionUuid, hdr->uuid);
|
||||||
|
|
||||||
if (*cipherMode != '\0')
|
|
||||||
r = snprintf(cipher, sizeof(cipher), "%s-%s", cipherName, cipherMode);
|
|
||||||
else
|
|
||||||
r = snprintf(cipher, sizeof(cipher), "%s", cipherName);
|
|
||||||
if (r < 0 || (size_t)r >= sizeof(cipher))
|
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
hdr->jobj = json_object_new_object();
|
hdr->jobj = json_object_new_object();
|
||||||
if (!hdr->jobj) {
|
if (!hdr->jobj) {
|
||||||
r = -ENOMEM;
|
r = -ENOMEM;
|
||||||
@@ -293,7 +284,7 @@ int LUKS2_generate_hdr(
|
|||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
jobj_segment = json_segment_create_crypt(data_offset, 0, NULL, cipher, integrity, sector_size, 0);
|
jobj_segment = json_segment_create_crypt(data_offset, 0, NULL, cipher_spec, integrity, sector_size, 0);
|
||||||
if (!jobj_segment) {
|
if (!jobj_segment) {
|
||||||
r = -EINVAL;
|
r = -EINVAL;
|
||||||
goto err;
|
goto err;
|
||||||
|
|||||||
12
lib/setup.c
12
lib/setup.c
@@ -1822,6 +1822,7 @@ static int _crypt_format_luks2(struct crypt_device *cd,
|
|||||||
unsigned long required_alignment = DEFAULT_DISK_ALIGNMENT;
|
unsigned long required_alignment = DEFAULT_DISK_ALIGNMENT;
|
||||||
unsigned long alignment_offset = 0;
|
unsigned long alignment_offset = 0;
|
||||||
unsigned int sector_size;
|
unsigned int sector_size;
|
||||||
|
char cipher_spec[128];
|
||||||
const char *integrity = params ? params->integrity : NULL;
|
const char *integrity = params ? params->integrity : NULL;
|
||||||
uint64_t data_offset_bytes, dev_size, metadata_size_bytes, keyslots_size_bytes;
|
uint64_t data_offset_bytes, dev_size, metadata_size_bytes, keyslots_size_bytes;
|
||||||
uint32_t dmc_flags;
|
uint32_t dmc_flags;
|
||||||
@@ -1974,13 +1975,22 @@ static int _crypt_format_luks2(struct crypt_device *cd,
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (*cipher_mode != '\0')
|
||||||
|
r = snprintf(cipher_spec, sizeof(cipher_spec), "%s-%s", cipher, cipher_mode);
|
||||||
|
else
|
||||||
|
r = snprintf(cipher_spec, sizeof(cipher_spec), "%s", cipher);
|
||||||
|
if (r < 0 || (size_t)r >= sizeof(cipher_spec)) {
|
||||||
|
r = -EINVAL;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
r = LUKS2_hdr_get_storage_params(cd, alignment_offset, required_alignment,
|
r = LUKS2_hdr_get_storage_params(cd, alignment_offset, required_alignment,
|
||||||
&metadata_size_bytes, &keyslots_size_bytes, &data_offset_bytes);
|
&metadata_size_bytes, &keyslots_size_bytes, &data_offset_bytes);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
r = LUKS2_generate_hdr(cd, &cd->u.luks2.hdr, cd->volume_key,
|
r = LUKS2_generate_hdr(cd, &cd->u.luks2.hdr, cd->volume_key,
|
||||||
cipher, cipher_mode,
|
cipher_spec,
|
||||||
integrity, uuid,
|
integrity, uuid,
|
||||||
sector_size,
|
sector_size,
|
||||||
data_offset_bytes,
|
data_offset_bytes,
|
||||||
|
|||||||
Reference in New Issue
Block a user