Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/2183186/?format=api
{ "id": 2183186, "url": "http://patchwork.ozlabs.org/api/patches/2183186/?format=api", "web_url": "http://patchwork.ozlabs.org/project/linuxppc-dev/patch/20260112192035.10427-13-ebiggers@kernel.org/", "project": { "id": 2, "url": "http://patchwork.ozlabs.org/api/projects/2/?format=api", "name": "Linux PPC development", "link_name": "linuxppc-dev", "list_id": "linuxppc-dev.lists.ozlabs.org", "list_email": "linuxppc-dev@lists.ozlabs.org", "web_url": "https://github.com/linuxppc/wiki/wiki", "scm_url": "https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git", "webscm_url": "https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git/", "list_archive_url": "https://lore.kernel.org/linuxppc-dev/", "list_archive_url_format": "https://lore.kernel.org/linuxppc-dev/{}/", "commit_url_format": "https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git/commit/?id={}" }, "msgid": "<20260112192035.10427-13-ebiggers@kernel.org>", "list_archive_url": "https://lore.kernel.org/linuxppc-dev/20260112192035.10427-13-ebiggers@kernel.org/", "date": "2026-01-12T19:20:10", "name": "[v2,12/35] lib/crypto: powerpc/aes: Migrate SPE optimized code into library", "commit_ref": null, "pull_url": null, "state": "handled-elsewhere", "archived": false, "hash": "581795744051ae2b7bf603a93324895bd851b4f4", "submitter": { "id": 74690, "url": "http://patchwork.ozlabs.org/api/people/74690/?format=api", "name": "Eric Biggers", "email": "ebiggers@kernel.org" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/linuxppc-dev/patch/20260112192035.10427-13-ebiggers@kernel.org/mbox/", "series": [ { "id": 488089, "url": "http://patchwork.ozlabs.org/api/series/488089/?format=api", "web_url": "http://patchwork.ozlabs.org/project/linuxppc-dev/list/?series=488089", "date": "2026-01-12T19:19:58", "name": "AES library improvements", "version": 2, "mbox": "http://patchwork.ozlabs.org/series/488089/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/2183186/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/2183186/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "\n <linuxppc-dev+bounces-15558-incoming=patchwork.ozlabs.org@lists.ozlabs.org>", "X-Original-To": [ "incoming@patchwork.ozlabs.org", "linuxppc-dev@lists.ozlabs.org" ], "Delivered-To": "patchwork-incoming@legolas.ozlabs.org", "Authentication-Results": [ "legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256\n header.s=k20201202 header.b=balRicSf;\n\tdkim-atps=neutral", "legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org\n (client-ip=2404:9400:21b9:f100::1; helo=lists.ozlabs.org;\n envelope-from=linuxppc-dev+bounces-15558-incoming=patchwork.ozlabs.org@lists.ozlabs.org;\n receiver=patchwork.ozlabs.org)", "lists.ozlabs.org;\n arc=none smtp.remote-ip=172.234.252.31", "lists.ozlabs.org;\n dmarc=pass (p=quarantine dis=none) header.from=kernel.org", "lists.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256\n header.s=k20201202 header.b=balRicSf;\n\tdkim-atps=neutral", "lists.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=kernel.org\n (client-ip=172.234.252.31; helo=sea.source.kernel.org;\n envelope-from=ebiggers@kernel.org; receiver=lists.ozlabs.org)" ], "Received": [ "from lists.ozlabs.org (lists.ozlabs.org\n [IPv6:2404:9400:21b9:f100::1])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4dqj3Z4fHKz1xpk\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 13 Jan 2026 06:23:54 +1100 (AEDT)", "from boromir.ozlabs.org (localhost [127.0.0.1])\n\tby lists.ozlabs.org (Postfix) with ESMTP id 4dqj332dV4z2yZ5;\n\tTue, 13 Jan 2026 06:23:27 +1100 (AEDT)", "from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519)\n\t(No client certificate requested)\n\tby lists.ozlabs.org (Postfix) with ESMTPS id 4dqj321Smkz2yY9\n\tfor <linuxppc-dev@lists.ozlabs.org>; Tue, 13 Jan 2026 06:23:26 +1100 (AEDT)", "from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58])\n\tby sea.source.kernel.org (Postfix) with ESMTP id 96F954437B;\n\tMon, 12 Jan 2026 19:23:24 +0000 (UTC)", "by smtp.kernel.org (Postfix) with ESMTPSA id 07AB2C2BC9E;\n\tMon, 12 Jan 2026 19:23:24 +0000 (UTC)" ], "ARC-Seal": "i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1768245807;\n\tcv=none;\n b=RZY48DxtwDrtujSh4WAvTlJmUcEh6T3/ElQCzYOtAHMbo3FBIgQH6Vu/45dJfSkPkcNlgEpAduhmoL2Rd1MRcsId3dT7SDD8BGucNeVYxZyyonwFmPJq/DsXHFHVTzsGoaCm5eJhN/Tq/e+LkSCeXG5/QnxsE0sGw7/2/I06B6+QTkgB/0zk8udPshKLcLxZdDfpLPY8z135nqR0MzWWMw0VAtOg6g4422O3zNBXQ8xxIQ8vhNFL8vXcMQ2aoJNs84LnIVhBJ3sAYV9HjHCzBH/oKYxaDX1/9Hm268FtJtbXCTCjnDGCDoJOPVASnHGFaCyq55WUd1VNkDI2R1kM6A==", "ARC-Message-Signature": "i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707;\n\tt=1768245807; c=relaxed/relaxed;\n\tbh=zu1MVvxDMya5cYztKUFcl/O0aMDjSFT+eSqR4qGbIk8=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=G50rcB6qpvtDY6LMFXGt85lyBjxc0SgM/ZAiZbCaiVrtrPc5870yGKQElFbTvDREDiO+FIcmFtq5IQjWDoOQiCM6FOcvkOndmjdNhNkIXayq0JlczqQu+3tWtoiGrl5thY8Aa20TrjcPIbz+jGevmU13JyZqcFLMb9GD1IwQe1USLrTuMKyMl1JDqeyFzVY4/rbiKZ640wssk/GFJi+fgVpiNNVEvNDQfGJ7YUIN5H/JpVddysEwnVQg+M5PP2iwHnC7ssCkQ0hW5TeOe+pvXJ5DX/PhT7EeftzXaVq80UxvUp1NPdujmsjkaErVKxNEL8SrOcO7RfTRQvcYrMWnZw==", "ARC-Authentication-Results": "i=1; lists.ozlabs.org;\n dmarc=pass (p=quarantine dis=none) header.from=kernel.org;\n dkim=pass (2048-bit key;\n unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256\n header.s=k20201202 header.b=balRicSf; dkim-atps=neutral;\n spf=pass (client-ip=172.234.252.31; helo=sea.source.kernel.org;\n envelope-from=ebiggers@kernel.org;\n receiver=lists.ozlabs.org) smtp.mailfrom=kernel.org", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;\n\ts=k20201202; t=1768245804;\n\tbh=g5MvkBPONwRVRzJT68NyeO2krV6zGm/Kyvj5zIP7ZvE=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=balRicSfSJLDd+OQNdcwFspAZKFQ0vMK7Jrh+QBLAMP98qACHJ/mV5f4axBUki0YF\n\t eQGho1v4+Am7kHyW5HQODAE9JIHoDqKwU6EFGsBMZHfJuXXgsVTiYsZ6ow7ZVuDqMY\n\t 01GaPkrgKYrbVp4p1pjyTIl5wiP71iHuphmb4AJiqxtNm1bohr/viimMvMB16Z9knD\n\t RM/K5YZ/7/aJz8A+/O1x/X4AIkQJEYHgG2lqTC7+PhcMf9IMGZpfkM38pnK6Z/CotM\n\t cQV9ooDK/YJbmZCH7Ge0nJwI+rlonGxTLs4x+P1EvAYwOIPjuT1hMqGPSUu78GRCkp\n\t Ydui6sw9YEG2Q==", "From": "Eric Biggers <ebiggers@kernel.org>", "To": "linux-crypto@vger.kernel.org", "Cc": "linux-kernel@vger.kernel.org,\n\tArd Biesheuvel <ardb@kernel.org>,\n\t\"Jason A . Donenfeld\" <Jason@zx2c4.com>,\n\tHerbert Xu <herbert@gondor.apana.org.au>,\n\tlinux-arm-kernel@lists.infradead.org,\n\tlinuxppc-dev@lists.ozlabs.org,\n\tlinux-riscv@lists.infradead.org,\n\tlinux-s390@vger.kernel.org,\n\tsparclinux@vger.kernel.org,\n\tx86@kernel.org,\n\tHolger Dengler <dengler@linux.ibm.com>,\n\tHarald Freudenberger <freude@linux.ibm.com>,\n\tEric Biggers <ebiggers@kernel.org>", "Subject": "[PATCH v2 12/35] lib/crypto: powerpc/aes: Migrate SPE optimized code\n into library", "Date": "Mon, 12 Jan 2026 11:20:10 -0800", "Message-ID": "<20260112192035.10427-13-ebiggers@kernel.org>", "X-Mailer": "git-send-email 2.52.0", "In-Reply-To": "<20260112192035.10427-1-ebiggers@kernel.org>", "References": "<20260112192035.10427-1-ebiggers@kernel.org>", "X-Mailing-List": "linuxppc-dev@lists.ozlabs.org", "List-Id": "<linuxppc-dev.lists.ozlabs.org>", "List-Help": "<mailto:linuxppc-dev+help@lists.ozlabs.org>", "List-Owner": "<mailto:linuxppc-dev+owner@lists.ozlabs.org>", "List-Post": "<mailto:linuxppc-dev@lists.ozlabs.org>", "List-Archive": "<https://lore.kernel.org/linuxppc-dev/>,\n <https://lists.ozlabs.org/pipermail/linuxppc-dev/>", "List-Subscribe": "<mailto:linuxppc-dev+subscribe@lists.ozlabs.org>,\n <mailto:linuxppc-dev+subscribe-digest@lists.ozlabs.org>,\n <mailto:linuxppc-dev+subscribe-nomail@lists.ozlabs.org>", "List-Unsubscribe": "<mailto:linuxppc-dev+unsubscribe@lists.ozlabs.org>", "Precedence": "list", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "X-Spam-Status": "No, score=-0.2 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED,\n\tDKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS\n\tautolearn=disabled version=4.0.1 OzLabs 8", "X-Spam-Checker-Version": "SpamAssassin 4.0.1 (2024-03-25) on lists.ozlabs.org" }, "content": "Move the PowerPC SPE AES assembly code into lib/crypto/, wire the key\nexpansion and single-block en/decryption functions up to the AES library\nAPI, and remove the superseded \"aes-ppc-spe\" crypto_cipher algorithm.\n\nThe result is that both the AES library and crypto_cipher APIs are now\noptimized with SPE, whereas previously only crypto_cipher was (and\noptimizations weren't enabled by default, which this commit fixes too).\n\nNote that many of the functions in the PowerPC SPE assembly code are\nstill used by the AES mode implementations in arch/powerpc/crypto/. For\nnow, just export these functions. These exports will go away once the\nAES modes are migrated to the library as well. (Trying to split up the\nassembly files seemed like much more trouble than it would be worth.)\n\nAcked-by: Ard Biesheuvel <ardb@kernel.org>\nSigned-off-by: Eric Biggers <ebiggers@kernel.org>\n---\n arch/powerpc/crypto/Kconfig | 2 +-\n arch/powerpc/crypto/Makefile | 2 +-\n arch/powerpc/crypto/aes-spe-glue.c | 88 ++-----------------\n include/crypto/aes.h | 31 +++++++\n lib/crypto/Kconfig | 1 +\n lib/crypto/Makefile | 9 ++\n .../crypto/powerpc}/aes-spe-core.S | 0\n .../crypto/powerpc}/aes-spe-keys.S | 0\n .../crypto/powerpc}/aes-spe-modes.S | 0\n .../crypto/powerpc}/aes-spe-regs.h | 0\n .../crypto/powerpc}/aes-tab-4k.S | 0\n lib/crypto/powerpc/aes.h | 74 ++++++++++++++++\n 12 files changed, 122 insertions(+), 85 deletions(-)\n rename {arch/powerpc/crypto => lib/crypto/powerpc}/aes-spe-core.S (100%)\n rename {arch/powerpc/crypto => lib/crypto/powerpc}/aes-spe-keys.S (100%)\n rename {arch/powerpc/crypto => lib/crypto/powerpc}/aes-spe-modes.S (100%)\n rename {arch/powerpc/crypto => lib/crypto/powerpc}/aes-spe-regs.h (100%)\n rename {arch/powerpc/crypto => lib/crypto/powerpc}/aes-tab-4k.S (100%)\n create mode 100644 lib/crypto/powerpc/aes.h", "diff": "diff --git a/arch/powerpc/crypto/Kconfig b/arch/powerpc/crypto/Kconfig\nindex 662aed46f9c7..2d056f1fc90f 100644\n--- a/arch/powerpc/crypto/Kconfig\n+++ b/arch/powerpc/crypto/Kconfig\n@@ -3,13 +3,13 @@\n menu \"Accelerated Cryptographic Algorithms for CPU (powerpc)\"\n \n config CRYPTO_AES_PPC_SPE\n \ttristate \"Ciphers: AES, modes: ECB/CBC/CTR/XTS (SPE)\"\n \tdepends on SPE\n+\tselect CRYPTO_LIB_AES\n \tselect CRYPTO_SKCIPHER\n \thelp\n-\t Block ciphers: AES cipher algorithms (FIPS-197)\n \t Length-preserving ciphers: AES with ECB, CBC, CTR, and XTS modes\n \n \t Architecture: powerpc using:\n \t - SPE (Signal Processing Engine) extensions\n \ndiff --git a/arch/powerpc/crypto/Makefile b/arch/powerpc/crypto/Makefile\nindex 5960e5300db7..e22310da86b5 100644\n--- a/arch/powerpc/crypto/Makefile\n+++ b/arch/powerpc/crypto/Makefile\n@@ -7,11 +7,11 @@\n \n obj-$(CONFIG_CRYPTO_AES_PPC_SPE) += aes-ppc-spe.o\n obj-$(CONFIG_CRYPTO_AES_GCM_P10) += aes-gcm-p10-crypto.o\n obj-$(CONFIG_CRYPTO_DEV_VMX_ENCRYPT) += vmx-crypto.o\n \n-aes-ppc-spe-y := aes-spe-core.o aes-spe-keys.o aes-tab-4k.o aes-spe-modes.o aes-spe-glue.o\n+aes-ppc-spe-y := aes-spe-glue.o\n aes-gcm-p10-crypto-y := aes-gcm-p10-glue.o aes-gcm-p10.o ghashp10-ppc.o aesp10-ppc.o\n vmx-crypto-objs := vmx.o aesp8-ppc.o ghashp8-ppc.o aes.o aes_cbc.o aes_ctr.o aes_xts.o ghash.o\n \n ifeq ($(CONFIG_CPU_LITTLE_ENDIAN),y)\n override flavour := linux-ppc64le\ndiff --git a/arch/powerpc/crypto/aes-spe-glue.c b/arch/powerpc/crypto/aes-spe-glue.c\nindex efab78a3a8f6..7d2827e65240 100644\n--- a/arch/powerpc/crypto/aes-spe-glue.c\n+++ b/arch/powerpc/crypto/aes-spe-glue.c\n@@ -49,34 +49,10 @@ struct ppc_xts_ctx {\n \tu32 key_dec[AES_MAX_KEYLENGTH_U32];\n \tu32 key_twk[AES_MAX_KEYLENGTH_U32];\n \tu32 rounds;\n };\n \n-extern void ppc_encrypt_aes(u8 *out, const u8 *in, u32 *key_enc, u32 rounds);\n-extern void ppc_decrypt_aes(u8 *out, const u8 *in, u32 *key_dec, u32 rounds);\n-extern void ppc_encrypt_ecb(u8 *out, const u8 *in, u32 *key_enc, u32 rounds,\n-\t\t\t u32 bytes);\n-extern void ppc_decrypt_ecb(u8 *out, const u8 *in, u32 *key_dec, u32 rounds,\n-\t\t\t u32 bytes);\n-extern void ppc_encrypt_cbc(u8 *out, const u8 *in, u32 *key_enc, u32 rounds,\n-\t\t\t u32 bytes, u8 *iv);\n-extern void ppc_decrypt_cbc(u8 *out, const u8 *in, u32 *key_dec, u32 rounds,\n-\t\t\t u32 bytes, u8 *iv);\n-extern void ppc_crypt_ctr (u8 *out, const u8 *in, u32 *key_enc, u32 rounds,\n-\t\t\t u32 bytes, u8 *iv);\n-extern void ppc_encrypt_xts(u8 *out, const u8 *in, u32 *key_enc, u32 rounds,\n-\t\t\t u32 bytes, u8 *iv, u32 *key_twk);\n-extern void ppc_decrypt_xts(u8 *out, const u8 *in, u32 *key_dec, u32 rounds,\n-\t\t\t u32 bytes, u8 *iv, u32 *key_twk);\n-\n-extern void ppc_expand_key_128(u32 *key_enc, const u8 *key);\n-extern void ppc_expand_key_192(u32 *key_enc, const u8 *key);\n-extern void ppc_expand_key_256(u32 *key_enc, const u8 *key);\n-\n-extern void ppc_generate_decrypt_key(u32 *key_dec,u32 *key_enc,\n-\t\t\t\t unsigned int key_len);\n-\n static void spe_begin(void)\n {\n \t/* disable preemption and save users SPE registers if required */\n \tpreempt_disable();\n \tenable_kernel_spe();\n@@ -87,14 +63,14 @@ static void spe_end(void)\n \tdisable_kernel_spe();\n \t/* reenable preemption */\n \tpreempt_enable();\n }\n \n-static int ppc_aes_setkey(struct crypto_tfm *tfm, const u8 *in_key,\n-\t\tunsigned int key_len)\n+static int ppc_aes_setkey_skcipher(struct crypto_skcipher *tfm,\n+\t\t\t\t const u8 *in_key, unsigned int key_len)\n {\n-\tstruct ppc_aes_ctx *ctx = crypto_tfm_ctx(tfm);\n+\tstruct ppc_aes_ctx *ctx = crypto_skcipher_ctx(tfm);\n \n \tswitch (key_len) {\n \tcase AES_KEYSIZE_128:\n \t\tctx->rounds = 4;\n \t\tppc_expand_key_128(ctx->key_enc, in_key);\n@@ -114,16 +90,10 @@ static int ppc_aes_setkey(struct crypto_tfm *tfm, const u8 *in_key,\n \tppc_generate_decrypt_key(ctx->key_dec, ctx->key_enc, key_len);\n \n \treturn 0;\n }\n \n-static int ppc_aes_setkey_skcipher(struct crypto_skcipher *tfm,\n-\t\t\t\t const u8 *in_key, unsigned int key_len)\n-{\n-\treturn ppc_aes_setkey(crypto_skcipher_tfm(tfm), in_key, key_len);\n-}\n-\n static int ppc_xts_setkey(struct crypto_skcipher *tfm, const u8 *in_key,\n \t\t unsigned int key_len)\n {\n \tstruct ppc_xts_ctx *ctx = crypto_skcipher_ctx(tfm);\n \tint err;\n@@ -157,28 +127,10 @@ static int ppc_xts_setkey(struct crypto_skcipher *tfm, const u8 *in_key,\n \tppc_generate_decrypt_key(ctx->key_dec, ctx->key_enc, key_len);\n \n \treturn 0;\n }\n \n-static void ppc_aes_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)\n-{\n-\tstruct ppc_aes_ctx *ctx = crypto_tfm_ctx(tfm);\n-\n-\tspe_begin();\n-\tppc_encrypt_aes(out, in, ctx->key_enc, ctx->rounds);\n-\tspe_end();\n-}\n-\n-static void ppc_aes_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)\n-{\n-\tstruct ppc_aes_ctx *ctx = crypto_tfm_ctx(tfm);\n-\n-\tspe_begin();\n-\tppc_decrypt_aes(out, in, ctx->key_dec, ctx->rounds);\n-\tspe_end();\n-}\n-\n static int ppc_ecb_crypt(struct skcipher_request *req, bool enc)\n {\n \tstruct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);\n \tstruct ppc_aes_ctx *ctx = crypto_skcipher_ctx(tfm);\n \tstruct skcipher_walk walk;\n@@ -408,30 +360,10 @@ static int ppc_xts_decrypt(struct skcipher_request *req)\n * This improves IPsec thoughput by another few percent. Additionally we assume\n * that AES context is always aligned to at least 8 bytes because it is created\n * with kmalloc() in the crypto infrastructure\n */\n \n-static struct crypto_alg aes_cipher_alg = {\n-\t.cra_name\t\t=\t\"aes\",\n-\t.cra_driver_name\t=\t\"aes-ppc-spe\",\n-\t.cra_priority\t\t=\t300,\n-\t.cra_flags\t\t=\tCRYPTO_ALG_TYPE_CIPHER,\n-\t.cra_blocksize\t\t=\tAES_BLOCK_SIZE,\n-\t.cra_ctxsize\t\t=\tsizeof(struct ppc_aes_ctx),\n-\t.cra_alignmask\t\t=\t0,\n-\t.cra_module\t\t=\tTHIS_MODULE,\n-\t.cra_u\t\t\t=\t{\n-\t\t.cipher = {\n-\t\t\t.cia_min_keysize\t=\tAES_MIN_KEY_SIZE,\n-\t\t\t.cia_max_keysize\t=\tAES_MAX_KEY_SIZE,\n-\t\t\t.cia_setkey\t\t=\tppc_aes_setkey,\n-\t\t\t.cia_encrypt\t\t=\tppc_aes_encrypt,\n-\t\t\t.cia_decrypt\t\t=\tppc_aes_decrypt\n-\t\t}\n-\t}\n-};\n-\n static struct skcipher_alg aes_skcipher_algs[] = {\n \t{\n \t\t.base.cra_name\t\t=\t\"ecb(aes)\",\n \t\t.base.cra_driver_name\t=\t\"ecb-ppc-spe\",\n \t\t.base.cra_priority\t=\t300,\n@@ -486,26 +418,16 @@ static struct skcipher_alg aes_skcipher_algs[] = {\n \t}\n };\n \n static int __init ppc_aes_mod_init(void)\n {\n-\tint err;\n-\n-\terr = crypto_register_alg(&aes_cipher_alg);\n-\tif (err)\n-\t\treturn err;\n-\n-\terr = crypto_register_skciphers(aes_skcipher_algs,\n-\t\t\t\t\tARRAY_SIZE(aes_skcipher_algs));\n-\tif (err)\n-\t\tcrypto_unregister_alg(&aes_cipher_alg);\n-\treturn err;\n+\treturn crypto_register_skciphers(aes_skcipher_algs,\n+\t\t\t\t\t ARRAY_SIZE(aes_skcipher_algs));\n }\n \n static void __exit ppc_aes_mod_fini(void)\n {\n-\tcrypto_unregister_alg(&aes_cipher_alg);\n \tcrypto_unregister_skciphers(aes_skcipher_algs,\n \t\t\t\t ARRAY_SIZE(aes_skcipher_algs));\n }\n \n module_init(ppc_aes_mod_init);\ndiff --git a/include/crypto/aes.h b/include/crypto/aes.h\nindex 18af1acbde58..c893c9214cb7 100644\n--- a/include/crypto/aes.h\n+++ b/include/crypto/aes.h\n@@ -18,14 +18,26 @@\n #define AES_MAX_KEYLENGTH\t(15 * 16)\n #define AES_MAX_KEYLENGTH_U32\t(AES_MAX_KEYLENGTH / sizeof(u32))\n \n union aes_enckey_arch {\n \tu32 rndkeys[AES_MAX_KEYLENGTH_U32];\n+#ifdef CONFIG_CRYPTO_LIB_AES_ARCH\n+#if defined(CONFIG_PPC) && defined(CONFIG_SPE)\n+\t/* Used unconditionally (when SPE AES code is enabled in kconfig) */\n+\tu32 spe_enc_key[AES_MAX_KEYLENGTH_U32] __aligned(8);\n+#endif\n+#endif /* CONFIG_CRYPTO_LIB_AES_ARCH */\n };\n \n union aes_invkey_arch {\n \tu32 inv_rndkeys[AES_MAX_KEYLENGTH_U32];\n+#ifdef CONFIG_CRYPTO_LIB_AES_ARCH\n+#if defined(CONFIG_PPC) && defined(CONFIG_SPE)\n+\t/* Used unconditionally (when SPE AES code is enabled in kconfig) */\n+\tu32 spe_dec_key[AES_MAX_KEYLENGTH_U32] __aligned(8);\n+#endif\n+#endif /* CONFIG_CRYPTO_LIB_AES_ARCH */\n };\n \n /**\n * struct aes_enckey - An AES key prepared for encryption\n * @len: Key length in bytes: 16 for AES-128, 24 for AES-192, 32 for AES-256.\n@@ -122,10 +134,29 @@ int aes_expandkey(struct crypto_aes_ctx *ctx, const u8 *in_key,\n * that code is migrated into lib/crypto/.\n */\n #ifdef CONFIG_ARM64\n int ce_aes_expandkey(struct crypto_aes_ctx *ctx, const u8 *in_key,\n \t\t unsigned int key_len);\n+#elif defined(CONFIG_PPC)\n+void ppc_expand_key_128(u32 *key_enc, const u8 *key);\n+void ppc_expand_key_192(u32 *key_enc, const u8 *key);\n+void ppc_expand_key_256(u32 *key_enc, const u8 *key);\n+void ppc_generate_decrypt_key(u32 *key_dec, u32 *key_enc, unsigned int key_len);\n+void ppc_encrypt_ecb(u8 *out, const u8 *in, u32 *key_enc, u32 rounds,\n+\t\t u32 bytes);\n+void ppc_decrypt_ecb(u8 *out, const u8 *in, u32 *key_dec, u32 rounds,\n+\t\t u32 bytes);\n+void ppc_encrypt_cbc(u8 *out, const u8 *in, u32 *key_enc, u32 rounds, u32 bytes,\n+\t\t u8 *iv);\n+void ppc_decrypt_cbc(u8 *out, const u8 *in, u32 *key_dec, u32 rounds, u32 bytes,\n+\t\t u8 *iv);\n+void ppc_crypt_ctr(u8 *out, const u8 *in, u32 *key_enc, u32 rounds, u32 bytes,\n+\t\t u8 *iv);\n+void ppc_encrypt_xts(u8 *out, const u8 *in, u32 *key_enc, u32 rounds, u32 bytes,\n+\t\t u8 *iv, u32 *key_twk);\n+void ppc_decrypt_xts(u8 *out, const u8 *in, u32 *key_dec, u32 rounds, u32 bytes,\n+\t\t u8 *iv, u32 *key_twk);\n #endif\n \n /**\n * aes_preparekey() - Prepare an AES key for encryption and decryption\n * @key: (output) The key structure to initialize\ndiff --git a/lib/crypto/Kconfig b/lib/crypto/Kconfig\nindex ead47b2a7db6..cfc6171203d0 100644\n--- a/lib/crypto/Kconfig\n+++ b/lib/crypto/Kconfig\n@@ -14,10 +14,11 @@ config CRYPTO_LIB_AES\n config CRYPTO_LIB_AES_ARCH\n \tbool\n \tdepends on CRYPTO_LIB_AES && !UML && !KMSAN\n \tdefault y if ARM\n \tdefault y if ARM64\n+\tdefault y if PPC && SPE\n \n config CRYPTO_LIB_AESCFB\n \ttristate\n \tselect CRYPTO_LIB_AES\n \tselect CRYPTO_LIB_UTILS\ndiff --git a/lib/crypto/Makefile b/lib/crypto/Makefile\nindex 1b690c63fafb..d68fde004104 100644\n--- a/lib/crypto/Makefile\n+++ b/lib/crypto/Makefile\n@@ -27,10 +27,19 @@ libaes-$(CONFIG_ARM) += arm/aes-cipher-core.o\n ifeq ($(CONFIG_ARM64),y)\n libaes-y += arm64/aes-cipher-core.o\n libaes-$(CONFIG_KERNEL_MODE_NEON) += arm64/aes-ce-core.o\n endif\n \n+ifeq ($(CONFIG_PPC),y)\n+ifeq ($(CONFIG_SPE),y)\n+libaes-y += powerpc/aes-spe-core.o \\\n+\t powerpc/aes-spe-keys.o \\\n+\t powerpc/aes-spe-modes.o \\\n+\t powerpc/aes-tab-4k.o\n+endif\n+endif # CONFIG_PPC\n+\n endif # CONFIG_CRYPTO_LIB_AES_ARCH\n \n ################################################################################\n \n obj-$(CONFIG_CRYPTO_LIB_AESCFB)\t\t\t+= libaescfb.o\ndiff --git a/arch/powerpc/crypto/aes-spe-core.S b/lib/crypto/powerpc/aes-spe-core.S\nsimilarity index 100%\nrename from arch/powerpc/crypto/aes-spe-core.S\nrename to lib/crypto/powerpc/aes-spe-core.S\ndiff --git a/arch/powerpc/crypto/aes-spe-keys.S b/lib/crypto/powerpc/aes-spe-keys.S\nsimilarity index 100%\nrename from arch/powerpc/crypto/aes-spe-keys.S\nrename to lib/crypto/powerpc/aes-spe-keys.S\ndiff --git a/arch/powerpc/crypto/aes-spe-modes.S b/lib/crypto/powerpc/aes-spe-modes.S\nsimilarity index 100%\nrename from arch/powerpc/crypto/aes-spe-modes.S\nrename to lib/crypto/powerpc/aes-spe-modes.S\ndiff --git a/arch/powerpc/crypto/aes-spe-regs.h b/lib/crypto/powerpc/aes-spe-regs.h\nsimilarity index 100%\nrename from arch/powerpc/crypto/aes-spe-regs.h\nrename to lib/crypto/powerpc/aes-spe-regs.h\ndiff --git a/arch/powerpc/crypto/aes-tab-4k.S b/lib/crypto/powerpc/aes-tab-4k.S\nsimilarity index 100%\nrename from arch/powerpc/crypto/aes-tab-4k.S\nrename to lib/crypto/powerpc/aes-tab-4k.S\ndiff --git a/lib/crypto/powerpc/aes.h b/lib/crypto/powerpc/aes.h\nnew file mode 100644\nindex 000000000000..cf22020f9050\n--- /dev/null\n+++ b/lib/crypto/powerpc/aes.h\n@@ -0,0 +1,74 @@\n+/* SPDX-License-Identifier: GPL-2.0-only */\n+/*\n+ * Copyright (c) 2015 Markus Stockhausen <stockhausen@collogia.de>\n+ * Copyright 2026 Google LLC\n+ */\n+#include <asm/simd.h>\n+#include <asm/switch_to.h>\n+#include <linux/cpufeature.h>\n+#include <linux/jump_label.h>\n+#include <linux/preempt.h>\n+#include <linux/uaccess.h>\n+\n+EXPORT_SYMBOL_GPL(ppc_expand_key_128);\n+EXPORT_SYMBOL_GPL(ppc_expand_key_192);\n+EXPORT_SYMBOL_GPL(ppc_expand_key_256);\n+EXPORT_SYMBOL_GPL(ppc_generate_decrypt_key);\n+EXPORT_SYMBOL_GPL(ppc_encrypt_ecb);\n+EXPORT_SYMBOL_GPL(ppc_decrypt_ecb);\n+EXPORT_SYMBOL_GPL(ppc_encrypt_cbc);\n+EXPORT_SYMBOL_GPL(ppc_decrypt_cbc);\n+EXPORT_SYMBOL_GPL(ppc_crypt_ctr);\n+EXPORT_SYMBOL_GPL(ppc_encrypt_xts);\n+EXPORT_SYMBOL_GPL(ppc_decrypt_xts);\n+\n+void ppc_encrypt_aes(u8 *out, const u8 *in, const u32 *key_enc, u32 rounds);\n+void ppc_decrypt_aes(u8 *out, const u8 *in, const u32 *key_dec, u32 rounds);\n+\n+static void spe_begin(void)\n+{\n+\t/* disable preemption and save users SPE registers if required */\n+\tpreempt_disable();\n+\tenable_kernel_spe();\n+}\n+\n+static void spe_end(void)\n+{\n+\tdisable_kernel_spe();\n+\t/* reenable preemption */\n+\tpreempt_enable();\n+}\n+\n+static void aes_preparekey_arch(union aes_enckey_arch *k,\n+\t\t\t\tunion aes_invkey_arch *inv_k,\n+\t\t\t\tconst u8 *in_key, int key_len, int nrounds)\n+{\n+\tif (key_len == AES_KEYSIZE_128)\n+\t\tppc_expand_key_128(k->spe_enc_key, in_key);\n+\telse if (key_len == AES_KEYSIZE_192)\n+\t\tppc_expand_key_192(k->spe_enc_key, in_key);\n+\telse\n+\t\tppc_expand_key_256(k->spe_enc_key, in_key);\n+\n+\tif (inv_k)\n+\t\tppc_generate_decrypt_key(inv_k->spe_dec_key, k->spe_enc_key,\n+\t\t\t\t\t key_len);\n+}\n+\n+static void aes_encrypt_arch(const struct aes_enckey *key,\n+\t\t\t u8 out[AES_BLOCK_SIZE],\n+\t\t\t const u8 in[AES_BLOCK_SIZE])\n+{\n+\tspe_begin();\n+\tppc_encrypt_aes(out, in, key->k.spe_enc_key, key->nrounds / 2 - 1);\n+\tspe_end();\n+}\n+\n+static void aes_decrypt_arch(const struct aes_key *key,\n+\t\t\t u8 out[AES_BLOCK_SIZE],\n+\t\t\t const u8 in[AES_BLOCK_SIZE])\n+{\n+\tspe_begin();\n+\tppc_decrypt_aes(out, in, key->inv_k.spe_dec_key, key->nrounds / 2 - 1);\n+\tspe_end();\n+}\n", "prefixes": [ "v2", "12/35" ] }