From: Eric Biggers <ebiggers@kernel.org>
To: linux-crypto@vger.kernel.org
Cc: Ard Biesheuvel <ardb@kernel.org>,
"Jason A . Donenfeld" <Jason@zx2c4.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
Eric Biggers <ebiggers@kernel.org>
Subject: [PATCH] lib/crypto: gf128hash: Hide selection mask values from compilers
Date: Fri, 30 Oct 2026 22:21:49 -0700 [thread overview]
Message-ID: <20261031052149.201983-1-ebiggers@kernel.org> (raw)
Hide selection mask values from compilers, so that they cannot see that
they are used to select between two values and potentially generate a
secret-dependent branch. This is not known to be happening here, but we
might as well be extra careful.
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
---
lib/crypto/gf128hash.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/lib/crypto/gf128hash.c b/lib/crypto/gf128hash.c
index 8dcdf5ec98be..5b8ae98cafed 100644
--- a/lib/crypto/gf128hash.c
+++ b/lib/crypto/gf128hash.c
@@ -88,10 +88,18 @@ static void clmul64(u64 a, u64 b, u64 *out_lo, u64 *out_hi)
(a2 * (u128)b1) ^ (a3 * (u128)b0);
/* Multiply the low 4 bits of @a by @b. */
- u64 e0 = -(a & 1) & b;
- u64 e1 = -((a >> 1) & 1) & b;
- u64 e2 = -((a >> 2) & 1) & b;
- u64 e3 = -((a >> 3) & 1) & b;
+ u64 e0 = -(a & 1);
+ u64 e1 = -((a >> 1) & 1);
+ u64 e2 = -((a >> 2) & 1);
+ u64 e3 = -((a >> 3) & 1);
+ OPTIMIZER_HIDE_VAR(e0);
+ OPTIMIZER_HIDE_VAR(e1);
+ OPTIMIZER_HIDE_VAR(e2);
+ OPTIMIZER_HIDE_VAR(e3);
+ e0 &= b;
+ e1 &= b;
+ e2 &= b;
+ e3 &= b;
u64 extra_lo = e0 ^ (e1 << 1) ^ (e2 << 2) ^ (e3 << 3);
u64 extra_hi = (e1 >> 63) ^ (e2 >> 62) ^ (e3 >> 61);
@@ -245,6 +253,7 @@ static void __maybe_unused ghash_key_to_polyval(const u8 in[GHASH_BLOCK_SIZE],
u64 lo = get_unaligned_be64(&in[8]);
u64 mask = (s64)hi >> 63;
+ OPTIMIZER_HIDE_VAR(mask);
hi = (hi << 1) ^ (lo >> 63) ^ (mask & ((u64)0xc2 << 56));
lo = (lo << 1) ^ (mask & 1);
out->lo = cpu_to_le64(lo);
base-commit: 2a500a04d6f969318c05f46aedb6e73fc1963a00
--
2.56.0
reply other threads:[~2026-10-31 5:21 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261031052149.201983-1-ebiggers@kernel.org \
--to=ebiggers@kernel.org \
--cc=Jason@zx2c4.com \
--cc=ardb@kernel.org \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.