mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-13 11:50:10 +01:00
Refactor json_segment_create_crypt helper.
Refactor crypt segment json helper body into separate routine so that it can be reused later in future hw-opal-crypt segment helper.
This commit is contained in:
@@ -245,37 +245,50 @@ json_object *json_segment_create_linear(uint64_t offset, const uint64_t *length,
|
|||||||
return jobj;
|
return jobj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool json_add_crypt_fields(json_object *jobj_segment, uint64_t iv_offset,
|
||||||
|
const char *cipher, const char *integrity,
|
||||||
|
uint32_t sector_size, unsigned reencryption)
|
||||||
|
{
|
||||||
|
json_object *jobj_integrity;
|
||||||
|
|
||||||
|
assert(cipher);
|
||||||
|
|
||||||
|
json_object_object_add(jobj_segment, "iv_tweak", crypt_jobj_new_uint64(iv_offset));
|
||||||
|
json_object_object_add(jobj_segment, "encryption", json_object_new_string(cipher));
|
||||||
|
json_object_object_add(jobj_segment, "sector_size", json_object_new_int(sector_size));
|
||||||
|
|
||||||
|
if (integrity) {
|
||||||
|
jobj_integrity = json_object_new_object();
|
||||||
|
if (!jobj_integrity)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
json_object_object_add(jobj_integrity, "type", json_object_new_string(integrity));
|
||||||
|
json_object_object_add(jobj_integrity, "journal_encryption", json_object_new_string("none"));
|
||||||
|
json_object_object_add(jobj_integrity, "journal_integrity", json_object_new_string("none"));
|
||||||
|
json_object_object_add(jobj_segment, "integrity", jobj_integrity);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reencryption)
|
||||||
|
LUKS2_segment_set_flag(jobj_segment, "in-reencryption");
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
json_object *json_segment_create_crypt(uint64_t offset,
|
json_object *json_segment_create_crypt(uint64_t offset,
|
||||||
uint64_t iv_offset, const uint64_t *length,
|
uint64_t iv_offset, const uint64_t *length,
|
||||||
const char *cipher, const char *integrity,
|
const char *cipher, const char *integrity,
|
||||||
uint32_t sector_size, unsigned reencryption)
|
uint32_t sector_size, unsigned reencryption)
|
||||||
{
|
{
|
||||||
json_object *jobj_integrity, *jobj = _segment_create_generic("crypt", offset, length);
|
json_object *jobj = _segment_create_generic("crypt", offset, length);
|
||||||
|
|
||||||
if (!jobj)
|
if (!jobj)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
json_object_object_add(jobj, "iv_tweak", crypt_jobj_new_uint64(iv_offset));
|
if (json_add_crypt_fields(jobj, iv_offset, cipher, integrity, sector_size, reencryption))
|
||||||
json_object_object_add(jobj, "encryption", json_object_new_string(cipher));
|
return jobj;
|
||||||
json_object_object_add(jobj, "sector_size", json_object_new_int(sector_size));
|
|
||||||
|
|
||||||
if (integrity) {
|
|
||||||
jobj_integrity = json_object_new_object();
|
|
||||||
if (!jobj_integrity) {
|
|
||||||
json_object_put(jobj);
|
json_object_put(jobj);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
json_object_object_add(jobj_integrity, "type", json_object_new_string(integrity));
|
|
||||||
json_object_object_add(jobj_integrity, "journal_encryption", json_object_new_string("none"));
|
|
||||||
json_object_object_add(jobj_integrity, "journal_integrity", json_object_new_string("none"));
|
|
||||||
json_object_object_add(jobj, "integrity", jobj_integrity);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (reencryption)
|
|
||||||
LUKS2_segment_set_flag(jobj, "in-reencryption");
|
|
||||||
|
|
||||||
return jobj;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t LUKS2_segment_offset(struct luks2_hdr *hdr, int segment, unsigned blockwise)
|
uint64_t LUKS2_segment_offset(struct luks2_hdr *hdr, int segment, unsigned blockwise)
|
||||||
|
|||||||
Reference in New Issue
Block a user