From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1kmlks-00052C-9K for mharc-grub-devel@gnu.org; Tue, 08 Dec 2020 17:46:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36874) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kmlkj-0004qP-KQ for grub-devel@gnu.org; Tue, 08 Dec 2020 17:46:37 -0500 Received: from mail-ot1-x344.google.com ([2607:f8b0:4864:20::344]:45188) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kmlkX-0000kq-Ll for grub-devel@gnu.org; Tue, 08 Dec 2020 17:46:37 -0500 Received: by mail-ot1-x344.google.com with SMTP id h18so310908otq.12 for ; Tue, 08 Dec 2020 14:46:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficientek-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=e0jIEYsdjyfBlMxv9EJKuDyK4jCkCKzOREOe4yJ8R4g=; b=gKpit3i+Fo6eGNGCKzUtCo6CEHzbrQu037jRCcy7YgHE884z6cH2ezTALs6ugWWpPQ 47jM61dp+4Jr7OiL9URA/uEbAfi92Yw87lsR1W0klgpqfurrQ12TcXa+WyuHz9LAclUm rrc9KklGDkqZcaEY53NG5aFeoinc0YaR3qRs03g1W5XlWC9heVAYXAr42nkpJMJC3Awd v+O2SCqbvx5xnWjYffPYcQG94CWt1Gx0Zg2A/rRSR6qWm5ABCM5nO9PXDREBcp8TyfkU dK31+qaG+fr0IwDsua7kqajvOuZApdFrJ1GUyHNaSEWGE9cj84Yx9gjs397DOyK3qCMa jfFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=e0jIEYsdjyfBlMxv9EJKuDyK4jCkCKzOREOe4yJ8R4g=; b=HkpVPQGeZuTXBvFYmh2RfkVu6CeJmEB/AOc6+qOqm+8JIDq3KNiqVoZyMEY/jRba1z JvZJegrLAXi1aH340TyG5LB8pnSzr0f/xHafCYfMvm19xq//vmky9++AJXbgXPVlYJiX rvTyCxAjF+E/OU57fr2F5cxd54SXBHPLl+CedBzaCZvtI9j96EKSMK4VBwfWZSVwOYb+ ml2vg1DB4cfGyluUftcjqnhg14SmgqXYp2tdFw8F4q7Pn3Y7Kc641MeJcP/c01JuCQYy EA/9mzRdedmJFIFQ1EFemFq2QR854e7uqZDISPywMrNKGZz0NxNnaotkSSGBPw4kRhD7 eJ0A== X-Gm-Message-State: AOAM533hW6/DMa73fqL6jvuRpOYqyavtoINk6H8EH1YGrmTnj1lgWT+8 TDbjiQ5dUu3lSPcADnIxinprJDKBXBd7Ig== X-Google-Smtp-Source: ABdhPJyP/WiGTsabhMP8QgrEjyvhyNJLr0A+O+j0Q2YYUVbU10YsuVzJZx3LUoRWDRFuAs0lIJaZ3w== X-Received: by 2002:a9d:590c:: with SMTP id t12mr278826oth.308.1607467581953; Tue, 08 Dec 2020 14:46:21 -0800 (PST) Received: from crass-HP-ZBook-15-G2.attlocal.net ([136.49.211.192]) by smtp.gmail.com with ESMTPSA id v8sm45538otp.10.2020.12.08.14.46.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 14:46:21 -0800 (PST) From: Glenn Washburn To: grub-devel@gnu.org Cc: Patrick Steinhardt , Daniel Kiper , Glenn Washburn Subject: [PATCH v8 10/18] cryptodisk: Add macro GRUB_TYPE_BITS() to replace some literals Date: Tue, 8 Dec 2020 16:45:41 -0600 Message-Id: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::344; envelope-from=development@efficientek.com; helo=mail-ot1-x344.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: Tue, 08 Dec 2020 22:46:38 -0000 The new macro GRUB_TYPE_BITS(type) returns the number of bits allocated for type. Signed-off-by: Glenn Washburn --- grub-core/disk/cryptodisk.c | 7 ++++--- include/grub/types.h | 2 ++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c index 473c93976..0e955a020 100644 --- a/grub-core/disk/cryptodisk.c +++ b/grub-core/disk/cryptodisk.c @@ -281,20 +281,21 @@ grub_cryptodisk_endecrypt (struct grub_cryptodisk *dev, } break; case GRUB_CRYPTODISK_MODE_IV_PLAIN64: - iv[1] = grub_cpu_to_le32 (sector >> 32); + 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); break; case GRUB_CRYPTODISK_MODE_IV_BYTECOUNT64: - iv[1] = grub_cpu_to_le32 (sector >> (32 - dev->log_sector_size)); + 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); 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 - 2] = grub_cpu_to_be32 (num >> GRUB_TYPE_BITS (iv[0])); iv[sz - 1] = grub_cpu_to_be32 (num & 0xFFFFFFFF); } break; diff --git a/include/grub/types.h b/include/grub/types.h index f22055f98..9989e3a16 100644 --- a/include/grub/types.h +++ b/include/grub/types.h @@ -80,6 +80,8 @@ # define GRUB_CHAR_BIT __CHAR_BIT__ #endif +#define GRUB_TYPE_BITS(type) (sizeof(type) * GRUB_CHAR_BIT) + /* Define various wide integers. */ typedef signed char grub_int8_t; typedef short grub_int16_t; -- 2.27.0