From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1kUTKd-0000VI-7B for mharc-grub-devel@gnu.org; Mon, 19 Oct 2020 07:28:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44064) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kUTKb-0000V9-At for grub-devel@gnu.org; Mon, 19 Oct 2020 07:28:01 -0400 Received: from dibed.net-space.pl ([84.10.22.86]:37843) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_3DES_EDE_CBC_SHA1:192) (Exim 4.90_1) (envelope-from ) id 1kUTKX-0006Ci-Bp for grub-devel@gnu.org; Mon, 19 Oct 2020 07:28:00 -0400 Received: from router-fw.i.net-space.pl ([192.168.52.1]:52632 "EHLO tomti.i.net-space.pl") by router-fw-old.i.net-space.pl with ESMTP id S1970756AbgJSL1q (ORCPT ); Mon, 19 Oct 2020 13:27:46 +0200 X-Comment: RFC 2476 MSA function at dibed.net-space.pl logged sender identity as: dkiper Date: Mon, 19 Oct 2020 13:27:43 +0200 From: Daniel Kiper To: Glenn Washburn Cc: grub-devel@gnu.org, Patrick Steinhardt Subject: Re: [PATCH v2 07/10] cryptodisk: Replace some literals with constants in grub_cryptodisk_endecrypt. Message-ID: <20201019112743.g36dkp7736qj77qc@tomti.i.net-space.pl> References: <20201018132156.727d87c5@crass-HP-ZBook-15-G2> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201018132156.727d87c5@crass-HP-ZBook-15-G2> User-Agent: NeoMutt/20170113 (1.7.2) Received-SPF: pass client-ip=84.10.22.86; envelope-from=dkiper@net-space.pl; helo=dibed.net-space.pl X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/19 07:27:48 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Oct 2020 11:28:01 -0000 Hi Glenn, I will be looking at the patches on the grub-devel this week. I will send you my comments then. Daniel On Sun, Oct 18, 2020 at 01:23:25PM -0500, Glenn Washburn wrote: > Daniel, Patrick, > > Have either of you had a chance to review this patch? Daniel, this is > my interpretation of what you suggested earlier to remove constant > literals in this message: > https://lists.gnu.org/archive/html/grub-devel/2020-09/msg00069.html > > I'm going to make a v3 patchset with Patrick's suggested changes. > Please reply to that patch. > > Glenn > > On Sat, 3 Oct 2020 17:55:31 -0500 > Glenn Washburn wrote: > > > This should improve readability of code by providing clues as to what > > the value represents. > > > > Signed-off-by: Glenn Washburn > > --- > > grub-core/disk/cryptodisk.c | 12 +++++++----- > > include/grub/types.h | 3 +++ > > 2 files changed, 10 insertions(+), 5 deletions(-) > > > > diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c > > index 623f0f396..1a91c2d55 100644 > > --- a/grub-core/disk/cryptodisk.c > > +++ b/grub-core/disk/cryptodisk.c > > @@ -297,19 +297,21 @@ grub_cryptodisk_endecrypt (struct > > grub_cryptodisk *dev, } > > break; > > case GRUB_CRYPTODISK_MODE_IV_BYTECOUNT64: > > - iv[1] = grub_cpu_to_le32 (sector >> (32 - > > log_sector_size)); > > + /* The IV is the 64 bit byte offset of the sector. */ > > + iv[1] = grub_cpu_to_le32 (sector >> (GRUB_TYPE_BIT(iv[0]) > > + - log_sector_size)); > > iv[0] = grub_cpu_to_le32 ((sector << log_sector_size) > > - & 0xFFFFFFFF); > > + & GRUB_TYPE_MAX(iv[0])); > > break; > > case GRUB_CRYPTODISK_MODE_IV_BENBI: > > { > > grub_uint64_t num = (sector << dev->benbi_log) + 1; > > - iv[sz - 2] = grub_cpu_to_be32 (num >> 32); > > - iv[sz - 1] = grub_cpu_to_be32 (num & 0xFFFFFFFF); > > + iv[sz - 2] = grub_cpu_to_be32 (num >> > > GRUB_TYPE_BIT(iv[0])); > > + iv[sz - 1] = grub_cpu_to_be32 (num & > > GRUB_TYPE_MAX(iv[0])); } > > break; > > case GRUB_CRYPTODISK_MODE_IV_ESSIV: > > - iv[0] = grub_cpu_to_le32 (sector & 0xFFFFFFFF); > > + iv[0] = grub_cpu_to_le32 (sector & GRUB_TYPE_MAX(iv[0])); > > err = grub_crypto_ecb_encrypt (dev->essiv_cipher, iv, iv, > > dev->cipher->cipher->blocksize); > > if (err) > > diff --git a/include/grub/types.h b/include/grub/types.h > > index 035a4b528..8b4267ebd 100644 > > --- a/include/grub/types.h > > +++ b/include/grub/types.h > > @@ -319,4 +319,7 @@ static inline void grub_set_unaligned64 (void > > *ptr, grub_uint64_t val) > > #define GRUB_CHAR_BIT 8 > > > > +#define GRUB_TYPE_BIT(type) (sizeof(type) * GRUB_CHAR_BIT) > > +#define GRUB_TYPE_MAX(type) ((2 * ((1ULL << (GRUB_TYPE_BIT(type) - > > 1)) - 1)) + 1) + > > #endif /* ! GRUB_TYPES_HEADER */