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: aes-cmac: Hide selection mask value from compilers
Date: Fri, 30 Oct 2026 22:20:53 -0700 [thread overview]
Message-ID: <20261031052053.201779-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.
Since the selected values are only 0x87 and 0 here, change the type of
the mask to 'unsigned long' so that the compiler is not forced to
materialize it in a register pair on 32-bit architectures.
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
---
lib/crypto/aes.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/lib/crypto/aes.c b/lib/crypto/aes.c
index e1c191551736..1d26fd8be028 100644
--- a/lib/crypto/aes.c
+++ b/lib/crypto/aes.c
@@ -578,7 +578,7 @@ static void aes_cbcmac_blocks(u8 h[AES_BLOCK_SIZE],
int aes_cmac_preparekey(struct aes_cmac_key *key, const u8 *in_key,
size_t key_len)
{
- u64 hi, lo, mask;
+ u64 hi, lo;
int err;
/* Prepare the AES key. */
@@ -596,9 +596,11 @@ int aes_cmac_preparekey(struct aes_cmac_key *key, const u8 *in_key,
hi = be64_to_cpu(key->k_final[0].w[0]);
lo = be64_to_cpu(key->k_final[0].w[1]);
for (int i = 0; i < 2; i++) {
- mask = ((s64)hi >> 63) & 0x87;
+ unsigned long mask = (s64)hi >> 63;
+
+ OPTIMIZER_HIDE_VAR(mask);
hi = (hi << 1) ^ (lo >> 63);
- lo = (lo << 1) ^ mask;
+ lo = (lo << 1) ^ (mask & 0x87);
key->k_final[i].w[0] = cpu_to_be64(hi);
key->k_final[i].w[1] = cpu_to_be64(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=20261031052053.201779-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.