[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v8 12/18] luks2: grub_cryptodisk_t->total_sectors is the max numb
From: |
Glenn Washburn |
Subject: |
[PATCH v8 12/18] luks2: grub_cryptodisk_t->total_sectors is the max number of device native sectors |
Date: |
Tue, 8 Dec 2020 16:45:43 -0600 |
We need to convert the sectors from the size of the underlying device to the
cryptodisk sector size; segment.size is in bytes which need to be converted
to cryptodisk sectors as well.
Also, removed an empty statement.
Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
---
grub-core/disk/luks2.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/grub-core/disk/luks2.c b/grub-core/disk/luks2.c
index ebf03e77b..429a4cfa1 100644
--- a/grub-core/disk/luks2.c
+++ b/grub-core/disk/luks2.c
@@ -429,7 +429,7 @@ luks2_decrypt_key (grub_uint8_t *out_key,
grub_uint8_t salt[GRUB_CRYPTODISK_MAX_KEYLEN];
grub_uint8_t *split_key = NULL;
grub_size_t saltlen = sizeof (salt);
- char cipher[32], *p;;
+ char cipher[32], *p;
const gcry_md_spec_t *hash;
gcry_err_code_t gcry_ret;
grub_err_t ret;
@@ -615,9 +615,10 @@ luks2_recover_key (grub_disk_t source,
crypt->log_sector_size = sizeof (unsigned int) * 8
- __builtin_clz ((unsigned int) segment.sector_size) - 1;
if (grub_strcmp (segment.size, "dynamic") == 0)
- crypt->total_sectors = grub_disk_get_size (source) -
crypt->offset_sectors;
+ crypt->total_sectors = (grub_disk_get_size (source) >>
(crypt->log_sector_size - source->log_sector_size))
+ - crypt->offset_sectors;
else
- crypt->total_sectors = grub_strtoull (segment.size, NULL, 10);
+ crypt->total_sectors = grub_strtoull (segment.size, NULL, 10) >>
crypt->log_sector_size;
ret = luks2_decrypt_key (candidate_key, source, crypt, &keyslot,
(const grub_uint8_t *) passphrase, grub_strlen
(passphrase));
--
2.27.0
- [PATCH v8 07/18] luks2: Use more intuitive object name instead of json index in user messages, (continued)
- [PATCH v8 07/18] luks2: Use more intuitive object name instead of json index in user messages, Glenn Washburn, 2020/12/08
- [PATCH v8 04/18] luks2: Remove unused argument in grub_error, Glenn Washburn, 2020/12/08
- [PATCH v8 08/18] luks2: Rename json index variables to names that they are obviously json indexes, Glenn Washburn, 2020/12/08
- [PATCH v8 11/18] cryptodisk: Add macros GRUB_TYPE_U_MAX/MIN(type) to replace literals, Glenn Washburn, 2020/12/08
- [PATCH v8 12/18] luks2: grub_cryptodisk_t->total_sectors is the max number of device native sectors,
Glenn Washburn <=
- [PATCH v8 05/18] luks2: Make sure all fields of output argument in luks2_parse_digest() are written to, Glenn Washburn, 2020/12/08
- [PATCH v8 13/18] cryptodisk: Properly handle non-512 byte sized sectors, Glenn Washburn, 2020/12/08
- [PATCH v8 06/18] luks2: Add idx member to struct grub_luks2_keyslot/segment/digest, Glenn Washburn, 2020/12/08
- [PATCH v8 17/18] misc: Add grub_log2ull macro for calculating log base 2 of 64-bit integers, Glenn Washburn, 2020/12/08
- [PATCH v8 02/18] misc: Add parentheses around ALIGN_UP and ALIGN_DOWN arguments, Glenn Washburn, 2020/12/08