[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v5 04/11] luks2: grub_cryptodisk_t->total_sectors is the max numb
From: |
Glenn Washburn |
Subject: |
[PATCH v5 04/11] luks2: grub_cryptodisk_t->total_sectors is the max number of device native sectors |
Date: |
Sun, 22 Nov 2020 23:23:17 -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. And counter-intuitively, grub_disk_get_size
returns the total number of device native sectors.
Also, removed an empty statement.
Signed-off-by: Glenn Washburn <development@efficientek.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 c390ea3e6..e33df9803 100644
--- a/grub-core/disk/luks2.c
+++ b/grub-core/disk/luks2.c
@@ -426,7 +426,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;
@@ -612,9 +612,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
- Re: [PATCH v4 14/15] luks2: Better error handling when setting up the cryptodisk., (continued)
[PATCH v4 15/15] luks2: Error check segment.sector_size., Glenn Washburn, 2020/11/06
Re: [PATCH v4 00/15] Cryptodisk fixes for v2.06 redux, Daniel Kiper, 2020/11/17
[PATCH v5 00/11] Cryptodisk fixes for v2.06 redux, Glenn Washburn, 2020/11/23
- [PATCH v5 01/11] luks2: Add slot_key member to struct grub_luks2_keyslot/segment/digest, Glenn Washburn, 2020/11/23
- [PATCH v5 02/11] luks: Use more intuitive slot key instead of index in user messages., Glenn Washburn, 2020/11/23
- [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 <=
- [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