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>,
sparclinux@vger.kernel.org, Andreas Larsson <andreas@gaisler.com>,
"David S . Miller" <davem@davemloft.net>,
Stian Halseth <stian@itx.no>, Magnus Lindholm <linmag7@gmail.com>,
John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>,
Eric Biggers <ebiggers@kernel.org>
Subject: [PATCH 1/4] lib/crypto: sparc/aes: Add and use round key load helper
Date: Tue, 17 Nov 2026 20:10:30 -0800 [thread overview]
Message-ID: <20261118041033.50014-2-ebiggers@kernel.org> (raw)
In-Reply-To: <20261118041033.50014-1-ebiggers@kernel.org>
In preparation for migrating more SPARC-optimized AES modes into libaes,
add a helper function aes_sparc64_load_round_keys() that loads either
the encryption or decryption round keys.
Make aes_xts_crypt_sparc64() call it. (The AES-192 support is not used
yet, but the other modes will use it.)
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
---
lib/crypto/sparc/aes.h | 44 +++++++++++++++++++++++++++++-------------
1 file changed, 31 insertions(+), 13 deletions(-)
diff --git a/lib/crypto/sparc/aes.h b/lib/crypto/sparc/aes.h
index e1a060cf49539..8b8ab0820bb3e 100644
--- a/lib/crypto/sparc/aes.h
+++ b/lib/crypto/sparc/aes.h
@@ -133,6 +133,29 @@ static void aes_decrypt_arch(const struct aes_key *key,
}
}
+static __always_inline void aes_sparc64_load_round_keys(aes_encrypt_arg key_arg,
+ bool enc)
+{
+ const struct aes_enckey *key = key_arg.enc_key;
+ const u64 *rk = key->k.sparc_rndkeys;
+
+ if (enc) {
+ if (key->len == AES_KEYSIZE_128)
+ aes_sparc64_load_encrypt_keys_128(rk);
+ else if (key->len == AES_KEYSIZE_192)
+ aes_sparc64_load_encrypt_keys_192(rk);
+ else
+ aes_sparc64_load_encrypt_keys_256(rk);
+ } else {
+ if (key->len == AES_KEYSIZE_128)
+ aes_sparc64_load_decrypt_keys_128(rk);
+ else if (key->len == AES_KEYSIZE_192)
+ aes_sparc64_load_decrypt_keys_192(rk);
+ else
+ aes_sparc64_load_decrypt_keys_256(rk);
+ }
+}
+
#if IS_ENABLED(CONFIG_CRYPTO_LIB_AES_XTS)
void aes_sparc64_xts_encrypt_128(const u64 *key, const u64 *input, u64 *output,
size_t len, u64 tweak[2]);
@@ -167,22 +190,17 @@ aes_xts_crypt_sparc64(u8 *dst, const u8 *src, size_t len,
else
aes_encrypt_arch(&key->tweak_key, (u8 *)t, tweak);
- if (k->len == AES_KEYSIZE_128) {
- if (enc) {
- aes_sparc64_load_encrypt_keys_128(rk);
+ aes_sparc64_load_round_keys(k, enc);
+ if (enc) {
+ if (k->len == AES_KEYSIZE_128)
aes_sparc64_xts_encrypt_128(rk, in, out, len, t);
- } else {
- aes_sparc64_load_decrypt_keys_128(rk);
- aes_sparc64_xts_decrypt_128(rk_end, in, out, len, t);
- }
- } else {
- if (enc) {
- aes_sparc64_load_encrypt_keys_256(rk);
+ else
aes_sparc64_xts_encrypt_256(rk, in, out, len, t);
- } else {
- aes_sparc64_load_decrypt_keys_256(rk);
+ } else {
+ if (k->len == AES_KEYSIZE_128)
+ aes_sparc64_xts_decrypt_128(rk_end, in, out, len, t);
+ else
aes_sparc64_xts_decrypt_256(rk_end, in, out, len, t);
- }
}
fprs_write(0);
--
2.56.1
next prev parent reply other threads:[~2026-11-18 4:10 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 4:10 [PATCH 0/4] Migrate SPARC64 accelerated AES modes into library Eric Biggers
2026-11-18 4:10 ` Eric Biggers [this message]
2026-11-18 4:10 ` [PATCH 2/4] lib/crypto: sparc/aes-ctr: Migrate optimized code " Eric Biggers
2026-11-18 4:10 ` [PATCH 3/4] lib/crypto: sparc/aes-ecb: " Eric Biggers
2026-11-18 4:10 ` [PATCH 4/4] lib/crypto: sparc/aes-cbc: " Eric Biggers
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=20261118041033.50014-2-ebiggers@kernel.org \
--to=ebiggers@kernel.org \
--cc=Jason@zx2c4.com \
--cc=andreas@gaisler.com \
--cc=ardb@kernel.org \
--cc=davem@davemloft.net \
--cc=glaubitz@physik.fu-berlin.de \
--cc=herbert@gondor.apana.org.au \
--cc=linmag7@gmail.com \
--cc=linux-crypto@vger.kernel.org \
--cc=sparclinux@vger.kernel.org \
--cc=stian@itx.no \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox