From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1kmN1X-0000c1-FI for mharc-grub-devel@gnu.org; Mon, 07 Dec 2020 15:22:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:38622) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kmN1V-0000ZR-K7 for grub-devel@gnu.org; Mon, 07 Dec 2020 15:22:17 -0500 Received: from dibed.net-space.pl ([84.10.22.86]:44783) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_3DES_EDE_CBC_SHA1:192) (Exim 4.90_1) (envelope-from ) id 1kmN1T-000735-DV for grub-devel@gnu.org; Mon, 07 Dec 2020 15:22:16 -0500 Received: from router-fw.i.net-space.pl ([192.168.52.1]:56358 "EHLO tomti.i.net-space.pl") by router-fw-old.i.net-space.pl with ESMTP id S152274AbgLGUWM (ORCPT ); Mon, 7 Dec 2020 21:22:12 +0100 X-Comment: RFC 2476 MSA function at dibed.net-space.pl logged sender identity as: dkiper Date: Mon, 7 Dec 2020 21:22:09 +0100 From: Daniel Kiper To: Glenn Washburn Cc: grub-devel@gnu.org, Patrick Steinhardt Subject: Re: [PATCH v7 09/17] cryptodisk: Add macros GRUB_TYPE_U_MAX/MIN(type) to replace literals Message-ID: <20201207202209.uppujarbd4cscybd@tomti.i.net-space.pl> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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-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, 07 Dec 2020 20:22:17 -0000 On Fri, Dec 04, 2020 at 10:43:38AM -0600, Glenn Washburn wrote: > Add GRUB_TYPE_U_MAX/MIN(type) macros to get the max/min values for an > unsigned number with size of type. > > Signed-off-by: Glenn Washburn Reviewed-by: Daniel Kiper But one nit below... > --- > grub-core/disk/cryptodisk.c | 8 ++++---- > include/grub/types.h | 7 +++++++ > 2 files changed, 11 insertions(+), 4 deletions(-) > > diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c > index 0e955a020..5aa0c4720 100644 > --- a/grub-core/disk/cryptodisk.c > +++ b/grub-core/disk/cryptodisk.c > @@ -284,23 +284,23 @@ grub_cryptodisk_endecrypt (struct grub_cryptodisk *dev, > iv[1] = grub_cpu_to_le32 (sector >> GRUB_TYPE_BITS (iv[0])); > /* FALLTHROUGH */ > case GRUB_CRYPTODISK_MODE_IV_PLAIN: > - iv[0] = grub_cpu_to_le32 (sector & 0xFFFFFFFF); > + iv[0] = grub_cpu_to_le32 (sector & GRUB_TYPE_U_MAX (iv[0])); > break; > case GRUB_CRYPTODISK_MODE_IV_BYTECOUNT64: > iv[1] = grub_cpu_to_le32 (sector >> (GRUB_TYPE_BITS (iv[1]) > - dev->log_sector_size)); > iv[0] = grub_cpu_to_le32 ((sector << dev->log_sector_size) > - & 0xFFFFFFFF); > + & GRUB_TYPE_U_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 >> GRUB_TYPE_BITS (iv[0])); > - iv[sz - 1] = grub_cpu_to_be32 (num & 0xFFFFFFFF); > + iv[sz - 1] = grub_cpu_to_be32 (num & GRUB_TYPE_U_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_U_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 9989e3a16..0542011cc 100644 > --- a/include/grub/types.h > +++ b/include/grub/types.h > @@ -161,6 +161,13 @@ typedef grub_int32_t grub_ssize_t; > #endif > # define GRUB_LONG_MIN (-GRUB_LONG_MAX - 1) > > +/* > + Cast to unsigned long long so that the "return value" is always a consistent > + type and to ensure an unsigned value regardless of type parameter. > + */ Incorrect comment formatting... > +#define GRUB_TYPE_U_MAX(type) ((unsigned long long)((typeof (type))(~0))) > +#define GRUB_TYPE_U_MIN(type) 0ULL > + > typedef grub_uint64_t grub_properly_aligned_t; > > #define GRUB_PROPERLY_ALIGNED_ARRAY(name, size) grub_properly_aligned_t name[((size) + sizeof (grub_properly_aligned_t) - 1) / sizeof (grub_properly_aligned_t)] Daniel