[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v6 01/12] luks2: Add slot_key member to struct grub_luks2_keyslot
From: |
Glenn Washburn |
Subject: |
[PATCH v6 01/12] luks2: Add slot_key member to struct grub_luks2_keyslot/segment/digest |
Date: |
Fri, 27 Nov 2020 03:03:33 -0600 |
This allows code using these structs to know the named key associated with
these json data structures. In the future we can use these to provide better
error messages to the user.
Get rid of idx variable in luks2_get_keyslot which was overloaded to be used
for both keyslot and segment slot keys.
Signed-off-by: Glenn Washburn <development@efficientek.com>
---
grub-core/disk/luks2.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/grub-core/disk/luks2.c b/grub-core/disk/luks2.c
index d96764a02..ab2c31dcd 100644
--- a/grub-core/disk/luks2.c
+++ b/grub-core/disk/luks2.c
@@ -65,6 +65,7 @@ typedef struct grub_luks2_header grub_luks2_header_t;
struct grub_luks2_keyslot
{
+ grub_uint64_t slot_key;
grub_int64_t key_size;
grub_int64_t priority;
struct
@@ -103,6 +104,7 @@ typedef struct grub_luks2_keyslot grub_luks2_keyslot_t;
struct grub_luks2_segment
{
+ grub_uint64_t slot_key;
grub_uint64_t offset;
const char *size;
const char *encryption;
@@ -112,6 +114,7 @@ typedef struct grub_luks2_segment grub_luks2_segment_t;
struct grub_luks2_digest
{
+ grub_uint64_t slot_key;
/* Both keyslots and segments are interpreted as bitfields here */
grub_uint64_t keyslots;
grub_uint64_t segments;
@@ -259,12 +262,11 @@ luks2_get_keyslot (grub_luks2_keyslot_t *k,
grub_luks2_digest_t *d, grub_luks2_s
{
grub_json_t keyslots, keyslot, digests, digest, segments, segment;
grub_size_t i, size;
- grub_uint64_t idx;
/* Get nth keyslot */
if (grub_json_getvalue (&keyslots, root, "keyslots") ||
grub_json_getchild (&keyslot, &keyslots, keyslot_idx) ||
- grub_json_getuint64 (&idx, &keyslot, NULL) ||
+ grub_json_getuint64 (&k->slot_key, &keyslot, NULL) ||
grub_json_getchild (&keyslot, &keyslot, 0) ||
luks2_parse_keyslot (k, &keyslot))
return grub_error (GRUB_ERR_BAD_ARGUMENT, "Could not parse keyslot
%"PRIuGRUB_SIZE, keyslot_idx);
@@ -276,11 +278,12 @@ luks2_get_keyslot (grub_luks2_keyslot_t *k,
grub_luks2_digest_t *d, grub_luks2_s
for (i = 0; i < size; i++)
{
if (grub_json_getchild (&digest, &digests, i) ||
+ grub_json_getuint64 (&d->slot_key, &digest, NULL) ||
grub_json_getchild (&digest, &digest, 0) ||
luks2_parse_digest (d, &digest))
return grub_error (GRUB_ERR_BAD_ARGUMENT, "Could not parse digest
%"PRIuGRUB_SIZE, i);
- if ((d->keyslots & (1 << idx)))
+ if ((d->keyslots & (1 << k->slot_key)))
break;
}
if (i == size)
@@ -293,12 +296,12 @@ luks2_get_keyslot (grub_luks2_keyslot_t *k,
grub_luks2_digest_t *d, grub_luks2_s
for (i = 0; i < size; i++)
{
if (grub_json_getchild (&segment, &segments, i) ||
- grub_json_getuint64 (&idx, &segment, NULL) ||
+ grub_json_getuint64 (&s->slot_key, &segment, NULL) ||
grub_json_getchild (&segment, &segment, 0) ||
luks2_parse_segment (s, &segment))
return grub_error (GRUB_ERR_BAD_ARGUMENT, "Could not parse segment
%"PRIuGRUB_SIZE, i);
- if ((d->segments & (1 << idx)))
+ if ((d->segments & (1 << s->slot_key)))
break;
}
if (i == size)
--
2.27.0
- [PATCH v5 03/11] cryptodisk: Replace some literals with constants in grub_cryptodisk_endecrypt, (continued)
- [PATCH v5 03/11] cryptodisk: Replace some literals with constants in grub_cryptodisk_endecrypt, Glenn Washburn, 2020/11/23
- [PATCH v5 04/11] luks2: grub_cryptodisk_t->total_sectors is the max number of device native sectors, Glenn Washburn, 2020/11/23
- [PATCH v5 05/11] cryptodisk: Properly handle non-512 byte sized sectors, Glenn Washburn, 2020/11/23
- [PATCH v5 06/11] luks2: Better error handling when setting up the cryptodisk, Glenn Washburn, 2020/11/23
- [PATCH v5 08/11] whitespace: convert 8 spaces to tabs., Glenn Washburn, 2020/11/23
- [PATCH v5 07/11] luks2: Error check segment.sector_size, Glenn Washburn, 2020/11/23
- [PATCH v5 09/11] mips: Enable __clzdi2(), Glenn Washburn, 2020/11/23
- [PATCH v5 10/11] misc: Add grub_log2ull macro for calculating log base 2 of 64-bit integers, Glenn Washburn, 2020/11/23
- [PATCH v5 11/11] luks2: Use grub_log2ull to calculate log_sector_size and improve readability, Glenn Washburn, 2020/11/23
- [PATCH v6 00/12] Cryptodisk fixes for v2.06 redux, Glenn Washburn, 2020/11/27
- [PATCH v6 01/12] luks2: Add slot_key member to struct grub_luks2_keyslot/segment/digest,
Glenn Washburn <=
- [PATCH v6 02/12] luks2: Use more intuitive slot key instead of index in user messages., Glenn Washburn, 2020/11/27
- [PATCH v6 03/12] luks2: Remove unused argument in grub_error, Glenn Washburn, 2020/11/27
- [PATCH v6 04/12] cryptodisk: Replace some literals with constants in grub_cryptodisk_endecrypt, Glenn Washburn, 2020/11/27
- [PATCH v6 05/12] luks2: grub_cryptodisk_t->total_sectors is the max number of device native sectors, Glenn Washburn, 2020/11/27
- [PATCH v6 06/12] cryptodisk: Properly handle non-512 byte sized sectors, Glenn Washburn, 2020/11/27
- [PATCH v6 07/12] luks2: Better error handling when setting up the cryptodisk, Glenn Washburn, 2020/11/27
- [PATCH v6 08/12] luks2: Error check segment.sector_size, Glenn Washburn, 2020/11/27
- [PATCH v6 09/12] whitespace: convert 8 spaces to tabs., Glenn Washburn, 2020/11/27
- [PATCH v6 10/12] mips: Enable __clzdi2(), Glenn Washburn, 2020/11/27
- [PATCH v6 11/12] misc: Add grub_log2ull macro for calculating log base 2 of 64-bit integers, Glenn Washburn, 2020/11/27