From patchwork Thu Apr 3 07:19:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 878297 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E1F3E241136 for ; Thu, 3 Apr 2025 07:20:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743664811; cv=none; b=NAFeNaiOTiSiHt8zFrsL/oq1TH5dieqxoJ6BOCepMmoIXn2Jm+lLG8UGcB5z+cJ3ocGX1dYtByvRf2Bno25xjjgoFuh7LtNzt5SK6MsQaCIpBPs+6HvOv4sEFJm3ygCNEWy3XiSouqgymPAZAQ1z6N2ryYtUHwPXvCYL4jWO8uc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743664811; c=relaxed/simple; bh=wBnjVuJa9QUtHkXEjuy7xmOkDM8zSKZ8lNKp975ENlQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=WbyPrC/ja0AngZJcOshBcYzr14Kv+SJ+Zpd2awH7uwWOdbIlMpU7AXPPLk0ARqXbp2lEGh+X51FGL1eNTUVMl+B+UnUI2zigOyMpnqobKbXDjP6cLJ+JjOl/+ZzuXF8Wsy8vT1scLdFRTZEixQ0eb1AL/utv0vwdVshrTmlrOqA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=NvVtpiRN; arc=none smtp.client-ip=209.85.221.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="NvVtpiRN" Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-39c184b20a2so286172f8f.1 for ; Thu, 03 Apr 2025 00:20:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1743664808; x=1744269608; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=PcFZk+cTBpCiBUySXbXFUd4zh3qawFC29H5nrbpKhJc=; b=NvVtpiRNHVw1TAf1fsunSO9puz0vFlBIp/4xEPjGmOpdo4pk3pFBioEC2NGMmpt0bm p3gkTe/4/Yq/NGWoIYsk17gBGrAzfyxIqDVbuJEXJKrL1xaMgTdIaU2NkG8NgyU1LyBa qX85lJbTq+NPL7cOCxNjgAZRSiJqt4g5XW3cwTLDdIVkCroryZ5mAVISiZ2BB5IiTUvp mpCMuQ470uemoklo0lj32qBsVH5LaD52I3YZEax9ukVr1aURc90ZTYfV/QC7TSgA7G/i kbdLkwjTSD9JzsOgoroP6AEzJ59gCD/QKOzjvyE274alVXDUlA7XilAzZHyGP+aZriAs Zb+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743664808; x=1744269608; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=PcFZk+cTBpCiBUySXbXFUd4zh3qawFC29H5nrbpKhJc=; b=Jic8iJPT2Nvpf1tMevbdlhnIqE3hoJKla5rNrBDxpzN2mgioOZkGh4Q7JKVMp7Fllc F8eC4Hhoj7Qoxt4kjK+I7+HJFc53t0qAVqW8tvlkowRiZ5MudW689T2B4Gb+r6+FboqZ xzGsYS3l/y2mUgXh0W9mSD6+pixftpKkNriO9YzzBBYb4ludoaS47SnkX0kRR075VLkj qC7EYzkxLKxExM8m6YleHtxsC3cbq7FE8lntKDk61X+2KZpLwnX4Kxv09nxP0LCuAm73 OC4ipfGmlhy6GhQPi4We2L3mjUnCamk2gy11B/KKGfx0Px6umV644dX+dy7gaw2hNCuh g+kA== X-Gm-Message-State: AOJu0YytXCzxExse1N7e7Z1MNn9d8Ojkf1NkKuXqNAOF6P8KRelPf+zw SWUSYAEjXvwxIY9P9UrW4sNvd0Gnbw26aXB8Y2k32Qib/9Pg+jD/jYk5pdYIph+JUvm4YcXAru7 7Zq0+Ez02bybMbmWsoTqMCAI3NXp25CDLDCVwha2YEpCO173lbkjhlipB6Vxe4boRGUffCY/s6/ D/I36hNtxYagkw5LNKfHjHaOiAPEd9FQ== X-Google-Smtp-Source: AGHT+IE+UGU2lxSa+0dYxVwsac6dAuqnT+W910JV+Ov6KJP2ZKeedHZ4gtKXHLmEunkrrWcgfGdBr+Q4 X-Received: from wmbfl9.prod.google.com ([2002:a05:600c:b89:b0:43c:f03d:18aa]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6000:2287:b0:39c:11c0:eb95 with SMTP id ffacd0b85a97d-39c2f8d28cbmr1045995f8f.17.1743664808229; Thu, 03 Apr 2025 00:20:08 -0700 (PDT) Date: Thu, 3 Apr 2025 09:19:55 +0200 In-Reply-To: <20250403071953.2296514-5-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250403071953.2296514-5-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=6600; i=ardb@kernel.org; h=from:subject; bh=2nAo/Tnu187qbmrnZyKTrYR/qO/zBrfZ9e5zFBj1pIc=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIf2d2TyPr1cWfpE4sWfK+9vbW2KufdjYeehn/6fCWzbrj ffJOX2401HKwiDGwSArpsgiMPvvu52nJ0rVOs+ShZnDygQyhIGLUwAmUq3G8L9qslLLwy8t6l7/ WQ5/F1x1wOnM5dw/JTF3f6nviuD7/lyf4a+YVHL81zi/mNQHmyM43i0y2vyP42h8nkDoz9SQSUY JBZwA X-Mailer: git-send-email 2.49.0.472.ge94155a9ec-goog Message-ID: <20250403071953.2296514-6-ardb+git@google.com> Subject: [PATCH v2 1/3] crypto: arm/aes-ce - stop using the SIMD helper From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, herbert@gondor.apana.org.au, ebiggers@kernel.org, Ard Biesheuvel From: Ard Biesheuvel Now that ARM permits use of the NEON unit in softirq context as well as task context, there is no longer a need to rely on the SIMD helper module to construct async skciphers wrapping the sync ones, as the latter can always be called directly. So remove these wrappers and the dependency on the SIMD helper. This permits the use of these algorithms by callers that only support synchronous use. Signed-off-by: Ard Biesheuvel --- arch/arm/crypto/Kconfig | 1 - arch/arm/crypto/aes-ce-glue.c | 104 +++----------------- 2 files changed, 11 insertions(+), 94 deletions(-) diff --git a/arch/arm/crypto/Kconfig b/arch/arm/crypto/Kconfig index 23e4ea067ddb..2e73200b930a 100644 --- a/arch/arm/crypto/Kconfig +++ b/arch/arm/crypto/Kconfig @@ -200,7 +200,6 @@ config CRYPTO_AES_ARM_CE depends on KERNEL_MODE_NEON select CRYPTO_SKCIPHER select CRYPTO_LIB_AES - select CRYPTO_SIMD help Length-preserving ciphers: AES cipher algorithms (FIPS-197) with block cipher modes: diff --git a/arch/arm/crypto/aes-ce-glue.c b/arch/arm/crypto/aes-ce-glue.c index 1cf61f51e766..00591895d540 100644 --- a/arch/arm/crypto/aes-ce-glue.c +++ b/arch/arm/crypto/aes-ce-glue.c @@ -10,8 +10,6 @@ #include #include #include -#include -#include #include #include #include @@ -418,29 +416,6 @@ static int ctr_encrypt(struct skcipher_request *req) return err; } -static void ctr_encrypt_one(struct crypto_skcipher *tfm, const u8 *src, u8 *dst) -{ - struct crypto_aes_ctx *ctx = crypto_skcipher_ctx(tfm); - unsigned long flags; - - /* - * Temporarily disable interrupts to avoid races where - * cachelines are evicted when the CPU is interrupted - * to do something else. - */ - local_irq_save(flags); - aes_encrypt(ctx, dst, src); - local_irq_restore(flags); -} - -static int ctr_encrypt_sync(struct skcipher_request *req) -{ - if (!crypto_simd_usable()) - return crypto_ctr_encrypt_walk(req, ctr_encrypt_one); - - return ctr_encrypt(req); -} - static int xts_encrypt(struct skcipher_request *req) { struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); @@ -586,10 +561,9 @@ static int xts_decrypt(struct skcipher_request *req) } static struct skcipher_alg aes_algs[] = { { - .base.cra_name = "__ecb(aes)", - .base.cra_driver_name = "__ecb-aes-ce", + .base.cra_name = "ecb(aes)", + .base.cra_driver_name = "ecb-aes-ce", .base.cra_priority = 300, - .base.cra_flags = CRYPTO_ALG_INTERNAL, .base.cra_blocksize = AES_BLOCK_SIZE, .base.cra_ctxsize = sizeof(struct crypto_aes_ctx), .base.cra_module = THIS_MODULE, @@ -600,10 +574,9 @@ static struct skcipher_alg aes_algs[] = { { .encrypt = ecb_encrypt, .decrypt = ecb_decrypt, }, { - .base.cra_name = "__cbc(aes)", - .base.cra_driver_name = "__cbc-aes-ce", + .base.cra_name = "cbc(aes)", + .base.cra_driver_name = "cbc-aes-ce", .base.cra_priority = 300, - .base.cra_flags = CRYPTO_ALG_INTERNAL, .base.cra_blocksize = AES_BLOCK_SIZE, .base.cra_ctxsize = sizeof(struct crypto_aes_ctx), .base.cra_module = THIS_MODULE, @@ -615,10 +588,9 @@ static struct skcipher_alg aes_algs[] = { { .encrypt = cbc_encrypt, .decrypt = cbc_decrypt, }, { - .base.cra_name = "__cts(cbc(aes))", - .base.cra_driver_name = "__cts-cbc-aes-ce", + .base.cra_name = "cts(cbc(aes))", + .base.cra_driver_name = "cts-cbc-aes-ce", .base.cra_priority = 300, - .base.cra_flags = CRYPTO_ALG_INTERNAL, .base.cra_blocksize = AES_BLOCK_SIZE, .base.cra_ctxsize = sizeof(struct crypto_aes_ctx), .base.cra_module = THIS_MODULE, @@ -631,10 +603,9 @@ static struct skcipher_alg aes_algs[] = { { .encrypt = cts_cbc_encrypt, .decrypt = cts_cbc_decrypt, }, { - .base.cra_name = "__ctr(aes)", - .base.cra_driver_name = "__ctr-aes-ce", + .base.cra_name = "ctr(aes)", + .base.cra_driver_name = "ctr-aes-ce", .base.cra_priority = 300, - .base.cra_flags = CRYPTO_ALG_INTERNAL, .base.cra_blocksize = 1, .base.cra_ctxsize = sizeof(struct crypto_aes_ctx), .base.cra_module = THIS_MODULE, @@ -647,25 +618,9 @@ static struct skcipher_alg aes_algs[] = { { .encrypt = ctr_encrypt, .decrypt = ctr_encrypt, }, { - .base.cra_name = "ctr(aes)", - .base.cra_driver_name = "ctr-aes-ce-sync", - .base.cra_priority = 300 - 1, - .base.cra_blocksize = 1, - .base.cra_ctxsize = sizeof(struct crypto_aes_ctx), - .base.cra_module = THIS_MODULE, - - .min_keysize = AES_MIN_KEY_SIZE, - .max_keysize = AES_MAX_KEY_SIZE, - .ivsize = AES_BLOCK_SIZE, - .chunksize = AES_BLOCK_SIZE, - .setkey = ce_aes_setkey, - .encrypt = ctr_encrypt_sync, - .decrypt = ctr_encrypt_sync, -}, { - .base.cra_name = "__xts(aes)", - .base.cra_driver_name = "__xts-aes-ce", + .base.cra_name = "xts(aes)", + .base.cra_driver_name = "xts-aes-ce", .base.cra_priority = 300, - .base.cra_flags = CRYPTO_ALG_INTERNAL, .base.cra_blocksize = AES_BLOCK_SIZE, .base.cra_ctxsize = sizeof(struct crypto_aes_xts_ctx), .base.cra_module = THIS_MODULE, @@ -679,51 +634,14 @@ static struct skcipher_alg aes_algs[] = { { .decrypt = xts_decrypt, } }; -static struct simd_skcipher_alg *aes_simd_algs[ARRAY_SIZE(aes_algs)]; - static void aes_exit(void) { - int i; - - for (i = 0; i < ARRAY_SIZE(aes_simd_algs) && aes_simd_algs[i]; i++) - simd_skcipher_free(aes_simd_algs[i]); - crypto_unregister_skciphers(aes_algs, ARRAY_SIZE(aes_algs)); } static int __init aes_init(void) { - struct simd_skcipher_alg *simd; - const char *basename; - const char *algname; - const char *drvname; - int err; - int i; - - err = crypto_register_skciphers(aes_algs, ARRAY_SIZE(aes_algs)); - if (err) - return err; - - for (i = 0; i < ARRAY_SIZE(aes_algs); i++) { - if (!(aes_algs[i].base.cra_flags & CRYPTO_ALG_INTERNAL)) - continue; - - algname = aes_algs[i].base.cra_name + 2; - drvname = aes_algs[i].base.cra_driver_name + 2; - basename = aes_algs[i].base.cra_driver_name; - simd = simd_skcipher_create_compat(aes_algs + i, algname, drvname, basename); - err = PTR_ERR(simd); - if (IS_ERR(simd)) - goto unregister_simds; - - aes_simd_algs[i] = simd; - } - - return 0; - -unregister_simds: - aes_exit(); - return err; + return crypto_register_skciphers(aes_algs, ARRAY_SIZE(aes_algs)); } module_cpu_feature_match(AES, aes_init); From patchwork Thu Apr 3 07:19:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 878024 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D08C723FC4C for ; Thu, 3 Apr 2025 07:20:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743664813; cv=none; b=ohrBmCQtAyK1mui6KLvfiHFGTnxBanhmQo5TBXf27G90RE+L84HPbJp0LyxaNZ3E+ZpH9dg/EW4q1oORHFY6HgTjr76AWdjamziZQjEM7qaD3vWJcw5z6D7W26R979MkGiuvQPIXxn6P3yz1keXJLHcf4RWCuzTXVDwOlgKqLxA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743664813; c=relaxed/simple; bh=xjM3zizhYZsahcZ0A2cWxxfz53Nu9XMOconnezav8Ew=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=YZPzJh1HHUbcKOq8hWFDYy2Qp+q9oDLUMMdUNemrLv7mgBCNJzhfxbsHnwGeMfYgku27UgXNTbAn3xwZmQkH/phxTLP5ODqsCx6hbl1ru+9o02XGA7lbe/SWmz/b2WPBsftsczJLofLLN/0RExTdxCHmByyAKQgG5Pe60g+NgQo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=nux8ogtK; arc=none smtp.client-ip=209.85.128.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="nux8ogtK" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-43ceeaf1524so2905865e9.1 for ; Thu, 03 Apr 2025 00:20:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1743664810; x=1744269610; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=t2UnQ4G/+gHzGrXeVaDXpkuH48Bw4a/mXiFKlx5qVxo=; b=nux8ogtKyCGcX8gySQ7ks0RgnoPFKT3fIeNYU3fwWbve98uWtbIH9tAiAAYFTHOU2q TFTP/EutR3JGbXX3EIko7FKrGuXXscFXWhRCda4Bmz4wlsXp67aR+DaKA4Rd+z/5jrJ2 eUfEumPn4NA64oKLLUOeXjOeF6qNCp3Yg7CCII8tx+LVcuhfsUzrl1qTs6CkV9hy+IQ6 bC4HFHyLv9uAq8CKulqspoyzjsCut58+ILP8qMuMDgXJhQnTuASTHPzwnfZ/LW/kiW0R 8ufUr8Pp20/xIVXXcGsF84nFy4cL6ldhN438wHJfURyRKzYBfR1slKbqqK6mcCqJoMpF WzSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743664810; x=1744269610; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=t2UnQ4G/+gHzGrXeVaDXpkuH48Bw4a/mXiFKlx5qVxo=; b=IOO1wKgtOaP3SKNfwKqFAdUVfd3gUbR1DHCu8Hyh3By0ZOZ2BreMOWj482Y8LfXeqv ldekxs762fUOre5jsR5xKErWlmWhcxrJAoUxp2RnJToL33iqgF0EWhi24LopmSbOoA7z DZoRNnnGbq0SX93bS1o6UDh0vpBBhaP9WNNh4KnBoSm7P5EPgmiT3OoRTJ3n/mUTLhwk lQ55xg2NE7wj5ReSQ54J/XkNA8InG3WUB5kQGtwDk17il+ZYJ20Me6NGTIai5qwiIcvw d5VpHlI9R32dLQy4MSvMfS10bILdxbAx4ACz0rTRXnB3ChBRsiS+3wE6LGpXNqySMA2X ITIg== X-Gm-Message-State: AOJu0YwM5HqIRKLDQ0q8SMEooLV4y8Km596ntGZnFpMHTjyFMw23jZOe LtYFoKSWXbPTEOq+PPGXLfjPv5SXNd/FP+SdYK4sD/qnsU6xRWhVT34h6+rQxlWM36TjLzuNWl3 GA0SDaurETB2SYD/1rormOsJNRMYqhXjsTNj48G4nmNiNeC1z9as0q2BU0eAcr/C6e8fBIt4awH jVce+rURfioma+KYI/hEDDrGlSFjKgRA== X-Google-Smtp-Source: AGHT+IFqW2eXKW5f/47sIYrkOzRPQpjoGIGrgHwL14ChBg+Q1Svb3rcjGXfzkypcL7MULwG7PjS2sAVh X-Received: from wmby10.prod.google.com ([2002:a05:600c:c04a:b0:43d:522a:45e8]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a7b:c398:0:b0:43d:5264:3cf0 with SMTP id 5b1f17b1804b1-43ebef8f615mr17183885e9.11.1743664810197; Thu, 03 Apr 2025 00:20:10 -0700 (PDT) Date: Thu, 3 Apr 2025 09:19:56 +0200 In-Reply-To: <20250403071953.2296514-5-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250403071953.2296514-5-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=7307; i=ardb@kernel.org; h=from:subject; bh=GsLrQ5TXtyTFuOhOU+w0HAICvkykb8sb2tr8+zm5hMA=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIf2d2fwshs+MtlVxM0wiJrGJm2mseRb+2tjb66lq6yLeg rn8DDM6SlkYxDgYZMUUWQRm/3238/REqVrnWbIwc1iZQIYwcHEKwES+bWT4X6W3Nnun8v0otUM7 NjNL/zJY7FYmse0Dh6HmkTeGlQrvLjP8M0xfqRY+4dZ5S+XrN5tb9n3w+Pgl8d7x5ww3rv7cmcS /hxMA X-Mailer: git-send-email 2.49.0.472.ge94155a9ec-goog Message-ID: <20250403071953.2296514-7-ardb+git@google.com> Subject: [PATCH v2 2/3] crypto: arm/aes-neonbs - stop using the SIMD helper From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, herbert@gondor.apana.org.au, ebiggers@kernel.org, Ard Biesheuvel From: Ard Biesheuvel Now that ARM permits use of the NEON unit in softirq context as well as task context, there is no longer a need to rely on the SIMD helper module to construct async skciphers wrapping the sync ones, as the latter can always be called directly. So remove these wrappers and the dependency on the SIMD helper. This permits the use of these algorithms by callers that only support synchronous use. Signed-off-by: Ard Biesheuvel --- arch/arm/crypto/Kconfig | 1 - arch/arm/crypto/aes-neonbs-glue.c | 116 ++------------------ 2 files changed, 9 insertions(+), 108 deletions(-) diff --git a/arch/arm/crypto/Kconfig b/arch/arm/crypto/Kconfig index 2e73200b930a..be9c2e19f976 100644 --- a/arch/arm/crypto/Kconfig +++ b/arch/arm/crypto/Kconfig @@ -172,7 +172,6 @@ config CRYPTO_AES_ARM_BS select CRYPTO_AES_ARM select CRYPTO_SKCIPHER select CRYPTO_LIB_AES - select CRYPTO_SIMD help Length-preserving ciphers: AES cipher algorithms (FIPS-197) with block cipher modes: diff --git a/arch/arm/crypto/aes-neonbs-glue.c b/arch/arm/crypto/aes-neonbs-glue.c index f6be80b5938b..95418df97fb4 100644 --- a/arch/arm/crypto/aes-neonbs-glue.c +++ b/arch/arm/crypto/aes-neonbs-glue.c @@ -8,8 +8,6 @@ #include #include #include -#include -#include #include #include #include @@ -59,11 +57,6 @@ struct aesbs_xts_ctx { struct crypto_aes_ctx tweak_key; }; -struct aesbs_ctr_ctx { - struct aesbs_ctx key; /* must be first member */ - struct crypto_aes_ctx fallback; -}; - static int aesbs_setkey(struct crypto_skcipher *tfm, const u8 *in_key, unsigned int key_len) { @@ -200,25 +193,6 @@ static int cbc_decrypt(struct skcipher_request *req) return err; } -static int aesbs_ctr_setkey_sync(struct crypto_skcipher *tfm, const u8 *in_key, - unsigned int key_len) -{ - struct aesbs_ctr_ctx *ctx = crypto_skcipher_ctx(tfm); - int err; - - err = aes_expandkey(&ctx->fallback, in_key, key_len); - if (err) - return err; - - ctx->key.rounds = 6 + key_len / 4; - - kernel_neon_begin(); - aesbs_convert_key(ctx->key.rk, ctx->fallback.key_enc, ctx->key.rounds); - kernel_neon_end(); - - return 0; -} - static int ctr_encrypt(struct skcipher_request *req) { struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); @@ -254,21 +228,6 @@ static int ctr_encrypt(struct skcipher_request *req) return err; } -static void ctr_encrypt_one(struct crypto_skcipher *tfm, const u8 *src, u8 *dst) -{ - struct aesbs_ctr_ctx *ctx = crypto_skcipher_ctx(tfm); - - __aes_arm_encrypt(ctx->fallback.key_enc, ctx->key.rounds, src, dst); -} - -static int ctr_encrypt_sync(struct skcipher_request *req) -{ - if (!crypto_simd_usable()) - return crypto_ctr_encrypt_walk(req, ctr_encrypt_one); - - return ctr_encrypt(req); -} - static int aesbs_xts_setkey(struct crypto_skcipher *tfm, const u8 *in_key, unsigned int key_len) { @@ -374,13 +333,12 @@ static int xts_decrypt(struct skcipher_request *req) } static struct skcipher_alg aes_algs[] = { { - .base.cra_name = "__ecb(aes)", - .base.cra_driver_name = "__ecb-aes-neonbs", + .base.cra_name = "ecb(aes)", + .base.cra_driver_name = "ecb-aes-neonbs", .base.cra_priority = 250, .base.cra_blocksize = AES_BLOCK_SIZE, .base.cra_ctxsize = sizeof(struct aesbs_ctx), .base.cra_module = THIS_MODULE, - .base.cra_flags = CRYPTO_ALG_INTERNAL, .min_keysize = AES_MIN_KEY_SIZE, .max_keysize = AES_MAX_KEY_SIZE, @@ -389,13 +347,12 @@ static struct skcipher_alg aes_algs[] = { { .encrypt = ecb_encrypt, .decrypt = ecb_decrypt, }, { - .base.cra_name = "__cbc(aes)", - .base.cra_driver_name = "__cbc-aes-neonbs", + .base.cra_name = "cbc(aes)", + .base.cra_driver_name = "cbc-aes-neonbs", .base.cra_priority = 250, .base.cra_blocksize = AES_BLOCK_SIZE, .base.cra_ctxsize = sizeof(struct aesbs_cbc_ctx), .base.cra_module = THIS_MODULE, - .base.cra_flags = CRYPTO_ALG_INTERNAL, .min_keysize = AES_MIN_KEY_SIZE, .max_keysize = AES_MAX_KEY_SIZE, @@ -405,13 +362,12 @@ static struct skcipher_alg aes_algs[] = { { .encrypt = cbc_encrypt, .decrypt = cbc_decrypt, }, { - .base.cra_name = "__ctr(aes)", - .base.cra_driver_name = "__ctr-aes-neonbs", + .base.cra_name = "ctr(aes)", + .base.cra_driver_name = "ctr-aes-neonbs", .base.cra_priority = 250, .base.cra_blocksize = 1, .base.cra_ctxsize = sizeof(struct aesbs_ctx), .base.cra_module = THIS_MODULE, - .base.cra_flags = CRYPTO_ALG_INTERNAL, .min_keysize = AES_MIN_KEY_SIZE, .max_keysize = AES_MAX_KEY_SIZE, @@ -422,29 +378,12 @@ static struct skcipher_alg aes_algs[] = { { .encrypt = ctr_encrypt, .decrypt = ctr_encrypt, }, { - .base.cra_name = "ctr(aes)", - .base.cra_driver_name = "ctr-aes-neonbs-sync", - .base.cra_priority = 250 - 1, - .base.cra_blocksize = 1, - .base.cra_ctxsize = sizeof(struct aesbs_ctr_ctx), - .base.cra_module = THIS_MODULE, - - .min_keysize = AES_MIN_KEY_SIZE, - .max_keysize = AES_MAX_KEY_SIZE, - .chunksize = AES_BLOCK_SIZE, - .walksize = 8 * AES_BLOCK_SIZE, - .ivsize = AES_BLOCK_SIZE, - .setkey = aesbs_ctr_setkey_sync, - .encrypt = ctr_encrypt_sync, - .decrypt = ctr_encrypt_sync, -}, { - .base.cra_name = "__xts(aes)", - .base.cra_driver_name = "__xts-aes-neonbs", + .base.cra_name = "xts(aes)", + .base.cra_driver_name = "xts-aes-neonbs", .base.cra_priority = 250, .base.cra_blocksize = AES_BLOCK_SIZE, .base.cra_ctxsize = sizeof(struct aesbs_xts_ctx), .base.cra_module = THIS_MODULE, - .base.cra_flags = CRYPTO_ALG_INTERNAL, .min_keysize = 2 * AES_MIN_KEY_SIZE, .max_keysize = 2 * AES_MAX_KEY_SIZE, @@ -455,54 +394,17 @@ static struct skcipher_alg aes_algs[] = { { .decrypt = xts_decrypt, } }; -static struct simd_skcipher_alg *aes_simd_algs[ARRAY_SIZE(aes_algs)]; - static void aes_exit(void) { - int i; - - for (i = 0; i < ARRAY_SIZE(aes_simd_algs); i++) - if (aes_simd_algs[i]) - simd_skcipher_free(aes_simd_algs[i]); - crypto_unregister_skciphers(aes_algs, ARRAY_SIZE(aes_algs)); } static int __init aes_init(void) { - struct simd_skcipher_alg *simd; - const char *basename; - const char *algname; - const char *drvname; - int err; - int i; - if (!(elf_hwcap & HWCAP_NEON)) return -ENODEV; - err = crypto_register_skciphers(aes_algs, ARRAY_SIZE(aes_algs)); - if (err) - return err; - - for (i = 0; i < ARRAY_SIZE(aes_algs); i++) { - if (!(aes_algs[i].base.cra_flags & CRYPTO_ALG_INTERNAL)) - continue; - - algname = aes_algs[i].base.cra_name + 2; - drvname = aes_algs[i].base.cra_driver_name + 2; - basename = aes_algs[i].base.cra_driver_name; - simd = simd_skcipher_create_compat(aes_algs + i, algname, drvname, basename); - err = PTR_ERR(simd); - if (IS_ERR(simd)) - goto unregister_simds; - - aes_simd_algs[i] = simd; - } - return 0; - -unregister_simds: - aes_exit(); - return err; + return crypto_register_skciphers(aes_algs, ARRAY_SIZE(aes_algs)); } late_initcall(aes_init); From patchwork Thu Apr 3 07:19:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 878296 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0877C24061B for ; Thu, 3 Apr 2025 07:20:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743664815; cv=none; b=tj3P+ddES2/6sENGFStUM5jHsk1kLVLKKuSM1CEoXYaE2st3Orkxt0932TGzW7GaZUDGbwjFeRhkhWmq5iClHnExN3t/4VxffsxKD++DxWpPddP/cVANak40NauJl4ONIb+L+SwmaZHId2kkxOL5y+V4qKaurwrwh1fVN+yIwrU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743664815; c=relaxed/simple; bh=gPgLHWdwggi9HajjGjzwjlJ3I72lmM3bOriec5GPE6A=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=m2sBZboLs3MS3O6jxOkBXrNOKlghIk7YK2KUqWIwevEgIutiWpMusoHSS5qmJmVU/5+raaANDr1+HKVUGDVvy2nmSY84dYgHEVbLttuUFW59BtlKx66rIgQzOQxTmc3Ofl8GVNC5Jg1iOfJ67W6MF18Iru8dyrnJvBNY9Bsp3Wc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ylJ++cM5; arc=none smtp.client-ip=209.85.221.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ylJ++cM5" Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-3912fc9861cso241636f8f.1 for ; Thu, 03 Apr 2025 00:20:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1743664812; x=1744269612; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=RUzKvb5TvRx6Fh/lfVibG4+MdYfgWiVJxFmOU7Qv3Gc=; b=ylJ++cM5P5Kkyqw09k63im6V3EYSfQPRfd6wbe10sBBszaoldasfeWWTwbLzkQmEL5 3Ehp+Z+guZzJ5a8rNojFFSzAHoE8YsMfO9KlUZRC58H/OnKo/y739boUXHwuYxYEB9FJ EtiJhMNskzZE98wK93Lr52P42B0uX/wWI21Jat07ZUaJk0g1t6Cdpw3XWUjmp2lCCWO3 EYjCdJ9QMRkp6JxjKCwjB+R7cXV7V7am/yLY5vCEA6vaXOKFYg21RQhgeJ+aTvD2t/Hy 7cxXenojZhiKn1Hwsch0ARKKN4tzICdnV5BSfG9MEW1n/xx2jUIEB7aPZZE9kVduKvRq PMWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743664812; x=1744269612; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=RUzKvb5TvRx6Fh/lfVibG4+MdYfgWiVJxFmOU7Qv3Gc=; b=gdOLVh2hDPsTutOnmOx2MfzOteOnGKKCfQl46hMrPuFy7MEg8/LheyjTz1fQ0TnzEa 8Mk74PhvUYxVftWsez3sNj2QNUeXjYGrlVRdimGJwVmW5H//GimEduNCY6+DOQlsMcMG jp9vHUft7RHqSSy8xlVeB5ts2iY6QmxMJ9ez5aHPskyfs7EImeX8HtXegzJD9VsPvIZr Xg1oE3RHDJGpquPLXgjWwCRaF82kH73img4o58yTY0RLVVLlHHnrXLtsJ1PUx7mRZsVl WoVXg3pHZZ3c7VFX2K8B13pOpqgidujeS/rtElo+aAwLpvjfbw18/+3LA/X23RKx1s+H lPLA== X-Gm-Message-State: AOJu0YxgyqgSrrtQQRtFSnmfTaZNEvvQeP5XTUQvJNLfbuV3A4rpI7Sz 99cOcku1pOVycT+EL8bNp326R5Eso5bi9SCCH+pz+dihksq+zT9Ncrl4JoQF55OiHKHlu0UOYEQ hki1Z6X916XekQs/BoiXxBYa2THi0CR2j4k03GzVzMvpPkIQe/Li2IZAMgzRNpj/GA55XHrwkE2 hiujvTTUFvz272TaWuQT94EXDqAxaKgA== X-Google-Smtp-Source: AGHT+IHCRTzzAmaHj71ujYKp+6dY6zspnecNvz85zvBYMg2Wpc0MY3Se5dOynzqdS7ZkhAERQdC4iVFF X-Received: from wrtx7.prod.google.com ([2002:a5d:60c7:0:b0:39a:bcee:e7a1]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a5d:5f8c:0:b0:390:eebc:6f32 with SMTP id ffacd0b85a97d-39c1211c6cemr17627581f8f.48.1743664812405; Thu, 03 Apr 2025 00:20:12 -0700 (PDT) Date: Thu, 3 Apr 2025 09:19:57 +0200 In-Reply-To: <20250403071953.2296514-5-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250403071953.2296514-5-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=1940; i=ardb@kernel.org; h=from:subject; bh=sXgJMqJU5B13l3xARHILiOCuMf8ZrNcROv+DWkjDfzw=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIf2d2QLJt3K/10yX3hczIffyuq1TXUovy1Vf6Pow9W2VZ 4XZzVy9jlIWBjEOBlkxRRaB2X/f7Tw9UarWeZYszBxWJpAhDFycAjCRe08YGU4vWvxzS1krC6/N yWkizSxe783bVmxyeFi5XyHywwnTuHBGhlfrOuYaX5Nwv526oul+Rdwrry07OQ1XL3th//3bt0b W1+wA X-Mailer: git-send-email 2.49.0.472.ge94155a9ec-goog Message-ID: <20250403071953.2296514-8-ardb+git@google.com> Subject: [PATCH v2 3/3] crypto: ctr - remove unused crypto_ctr_encrypt_walk() From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, herbert@gondor.apana.org.au, ebiggers@kernel.org, Ard Biesheuvel From: Ard Biesheuvel crypto_ctr_encrypt_walk() is no longer used so remove it. Note that some existing drivers currently rely on the transitive includes of some other crypto headers so retain those for the time being. Signed-off-by: Ard Biesheuvel --- include/crypto/ctr.h | 47 -------------------- 1 file changed, 47 deletions(-) diff --git a/include/crypto/ctr.h b/include/crypto/ctr.h index da1ee73e9ce9..c41685874f00 100644 --- a/include/crypto/ctr.h +++ b/include/crypto/ctr.h @@ -10,56 +10,9 @@ #include #include -#include -#include #define CTR_RFC3686_NONCE_SIZE 4 #define CTR_RFC3686_IV_SIZE 8 #define CTR_RFC3686_BLOCK_SIZE 16 -static inline int crypto_ctr_encrypt_walk(struct skcipher_request *req, - void (*fn)(struct crypto_skcipher *, - const u8 *, u8 *)) -{ - struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); - int blocksize = crypto_skcipher_chunksize(tfm); - u8 buf[MAX_CIPHER_BLOCKSIZE]; - struct skcipher_walk walk; - int err; - - /* avoid integer division due to variable blocksize parameter */ - if (WARN_ON_ONCE(!is_power_of_2(blocksize))) - return -EINVAL; - - err = skcipher_walk_virt(&walk, req, false); - - while (walk.nbytes > 0) { - const u8 *src = walk.src.virt.addr; - u8 *dst = walk.dst.virt.addr; - int nbytes = walk.nbytes; - int tail = 0; - - if (nbytes < walk.total) { - tail = walk.nbytes & (blocksize - 1); - nbytes -= tail; - } - - do { - int bsize = min(nbytes, blocksize); - - fn(tfm, walk.iv, buf); - - crypto_xor_cpy(dst, src, buf, bsize); - crypto_inc(walk.iv, blocksize); - - dst += bsize; - src += bsize; - nbytes -= bsize; - } while (nbytes > 0); - - err = skcipher_walk_done(&walk, tail); - } - return err; -} - #endif /* _CRYPTO_CTR_H */