mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-06 00:10:04 +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 luks2_hdr *hdr,
|
||||
const struct volume_key *vk,
|
||||
const char *cipherName,
|
||||
const char *cipherMode,
|
||||
const char *cipher_spec,
|
||||
const char *integrity,
|
||||
const char *uuid,
|
||||
unsigned int sector_size,
|
||||
|
||||
@@ -204,8 +204,7 @@ int LUKS2_generate_hdr(
|
||||
struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
const struct volume_key *vk,
|
||||
const char *cipherName,
|
||||
const char *cipherMode,
|
||||
const char *cipher_spec,
|
||||
const char *integrity,
|
||||
const char *uuid,
|
||||
unsigned int sector_size, /* in bytes */
|
||||
@@ -214,7 +213,6 @@ int LUKS2_generate_hdr(
|
||||
uint64_t keyslots_size_bytes)
|
||||
{
|
||||
struct json_object *jobj_segment, *jobj_keyslots, *jobj_segments, *jobj_config;
|
||||
char cipher[128];
|
||||
uuid_t partitionUuid;
|
||||
int r, digest;
|
||||
|
||||
@@ -245,13 +243,6 @@ int LUKS2_generate_hdr(
|
||||
|
||||
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();
|
||||
if (!hdr->jobj) {
|
||||
r = -ENOMEM;
|
||||
@@ -293,7 +284,7 @@ int LUKS2_generate_hdr(
|
||||
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) {
|
||||
r = -EINVAL;
|
||||
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 alignment_offset = 0;
|
||||
unsigned int sector_size;
|
||||
char cipher_spec[128];
|
||||
const char *integrity = params ? params->integrity : NULL;
|
||||
uint64_t data_offset_bytes, dev_size, metadata_size_bytes, keyslots_size_bytes;
|
||||
uint32_t dmc_flags;
|
||||
@@ -1974,13 +1975,22 @@ static int _crypt_format_luks2(struct crypt_device *cd,
|
||||
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,
|
||||
&metadata_size_bytes, &keyslots_size_bytes, &data_offset_bytes);
|
||||
if (r < 0)
|
||||
goto out;
|
||||
|
||||
r = LUKS2_generate_hdr(cd, &cd->u.luks2.hdr, cd->volume_key,
|
||||
cipher, cipher_mode,
|
||||
cipher_spec,
|
||||
integrity, uuid,
|
||||
sector_size,
|
||||
data_offset_bytes,
|
||||
|
||||
Reference in New Issue
Block a user