From patchwork Tue Jan 10 13:50:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Whitchurch X-Patchwork-Id: 641021 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63017C678D7 for ; Tue, 10 Jan 2023 13:51:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233241AbjAJNv0 (ORCPT ); Tue, 10 Jan 2023 08:51:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238352AbjAJNu7 (ORCPT ); Tue, 10 Jan 2023 08:50:59 -0500 Received: from smtp2.axis.com (smtp2.axis.com [195.60.68.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF81D14D3D; Tue, 10 Jan 2023 05:50:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; q=dns/txt; s=axis-central1; t=1673358658; x=1704894658; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=imTnDMnDHu3Au0k4Q8/xix4gLYf+kdvkY3vppCY1wrw=; b=JMjJ0U59I01d/2qkjigFdDLuh+Y2aqC0XKc7rcJCis3BR5wiE6Zmx12w FYVThwmkBg9xHoU9QPBK1Ao6fd436ilarcvtpIWUrEJd+ckmjbEdjjj/m Zj5Rz2Ek/nLv9VKi4djITF0I+SinjGLRK8c3eAqVK4aa6hV98GeFgyGx+ h6hfmqpTHQvkTIlNcbpT9BKS/a4WGgpCZy0xyPeAfxZoU1ih14p3dHMFS SnwH67IEMQh0Go2cszGYN/LtgaBJJ6ZLXlkYf68bOfzEwTv1kY2NZk7vM irzArzYfymXEtFhM6yt5PBytSGz7lK7yYfNQjfIxwgoAoRzDVwyMTHLLV Q==; From: Vincent Whitchurch To: , , , CC: , Vincent Whitchurch , , , Lars Persson Subject: [PATCH 01/12] crypto: axis - do not DMA to ahash_request.result Date: Tue, 10 Jan 2023 14:50:31 +0100 Message-ID: <20230110135042.2940847-2-vincent.whitchurch@axis.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230110135042.2940847-1-vincent.whitchurch@axis.com> References: <20230110135042.2940847-1-vincent.whitchurch@axis.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org From: Lars Persson The crypto API does not promise that the result pointer is suitable for DMA. Use an intermediate result buffer and let the CPU copy the digest to the ahash_request. Signed-off-by: Lars Persson Signed-off-by: Vincent Whitchurch --- drivers/crypto/axis/artpec6_crypto.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/crypto/axis/artpec6_crypto.c b/drivers/crypto/axis/artpec6_crypto.c index 51c66afbe677..87af44ac3e64 100644 --- a/drivers/crypto/axis/artpec6_crypto.c +++ b/drivers/crypto/axis/artpec6_crypto.c @@ -276,6 +276,7 @@ enum artpec6_crypto_hash_flags { HASH_FLAG_FINALIZE = 8, HASH_FLAG_HMAC = 16, HASH_FLAG_UPDATE_KEY = 32, + HASH_FLAG_FINALIZED = 64, }; struct artpec6_crypto_req_common { @@ -1493,12 +1494,15 @@ static int artpec6_crypto_prepare_hash(struct ahash_request *areq) return error; /* Descriptor for the final result */ - error = artpec6_crypto_setup_in_descr(common, areq->result, + error = artpec6_crypto_setup_in_descr(common, + req_ctx->digeststate, digestsize, true); if (error) return error; + req_ctx->hash_flags |= HASH_FLAG_FINALIZED; + } else { /* This is not the final operation for this request */ if (!run_hw) return ARTPEC6_CRYPTO_PREPARE_HASH_NO_START; @@ -2216,6 +2220,14 @@ static void artpec6_crypto_complete_aead(struct crypto_async_request *req) static void artpec6_crypto_complete_hash(struct crypto_async_request *req) { + struct ahash_request *areq = container_of(req, struct ahash_request, base); + struct artpec6_hash_request_context *ctx = ahash_request_ctx(areq); + struct crypto_ahash *ahash = crypto_ahash_reqtfm(areq); + size_t digestsize = crypto_ahash_digestsize(ahash); + + if (ctx->hash_flags & HASH_FLAG_FINALIZED) + memcpy(areq->result, ctx->digeststate, digestsize); + req->complete(req, 0); } From patchwork Tue Jan 10 13:50:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Whitchurch X-Patchwork-Id: 642757 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BBAB0C46467 for ; Tue, 10 Jan 2023 13:51:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233014AbjAJNvV (ORCPT ); Tue, 10 Jan 2023 08:51:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238321AbjAJNu6 (ORCPT ); Tue, 10 Jan 2023 08:50:58 -0500 Received: from smtp2.axis.com (smtp2.axis.com [195.60.68.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B9DE64EE; Tue, 10 Jan 2023 05:50:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; q=dns/txt; s=axis-central1; t=1673358657; x=1704894657; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YBWPPr1+kqTd4bU3Mi91t3NpLL6yLU7kv9iml0RWA0w=; b=cSmKa9qjjsnjdPUeeXCfU3LJGnsMVCPkTtz9FYcRTS5ReqDGUC21jvmt BqRXGb8TM7Q+Cmd8W04/g+V5otzsJTkV0bzhjUtl1T94YhP/NR9eXgmbW sYJ8Siu+DnFKnOqowc5g0w2wEBJaSJnKrMW6YMgI/8deN1iIzZ2UbV0S1 FuKmPm9Hbf3KTcGGiaksEYVQ2WvHki+XTTNHq+hUV+RJ8M6m2azRfANCm fScmTcQAJvT/vDZE/LH05Kw4cICYI7hF9MoZcphu9GfojoxwRr3+jZRas xfn+7930u5uv3LF6WPIRbXFEVdyNdja7WqnfgoKbhzRhaM9btjVAmc+Rr A==; From: Vincent Whitchurch To: , , , CC: , Vincent Whitchurch , , Subject: [PATCH 02/12] crypto: axis - do not DMA to IV Date: Tue, 10 Jan 2023 14:50:32 +0100 Message-ID: <20230110135042.2940847-3-vincent.whitchurch@axis.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230110135042.2940847-1-vincent.whitchurch@axis.com> References: <20230110135042.2940847-1-vincent.whitchurch@axis.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The crypto API does not promise that the IV buffer is suitable for DMA. Use an intermediate buffer instead. Signed-off-by: Vincent Whitchurch --- drivers/crypto/axis/artpec6_crypto.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/crypto/axis/artpec6_crypto.c b/drivers/crypto/axis/artpec6_crypto.c index 87af44ac3e64..d3b6ee065a81 100644 --- a/drivers/crypto/axis/artpec6_crypto.c +++ b/drivers/crypto/axis/artpec6_crypto.c @@ -321,6 +321,7 @@ struct artpec6_crypto_request_context { u32 cipher_md; bool decrypt; struct artpec6_crypto_req_common common; + unsigned char iv_bounce[AES_BLOCK_SIZE] CRYPTO_MINALIGN_ATTR; }; struct artpec6_cryptotfm_context { @@ -1779,7 +1780,8 @@ static int artpec6_crypto_prepare_crypto(struct skcipher_request *areq) return ret; if (iv_len) { - ret = artpec6_crypto_setup_out_descr(common, areq->iv, iv_len, + memcpy(req_ctx->iv_bounce, areq->iv, iv_len); + ret = artpec6_crypto_setup_out_descr(common, req_ctx->iv_bounce, iv_len, false, false); if (ret) return ret; From patchwork Tue Jan 10 13:50:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Whitchurch X-Patchwork-Id: 641025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B07FC46467 for ; Tue, 10 Jan 2023 13:51:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231974AbjAJNu5 (ORCPT ); Tue, 10 Jan 2023 08:50:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238252AbjAJNu4 (ORCPT ); Tue, 10 Jan 2023 08:50:56 -0500 Received: from smtp2.axis.com (smtp2.axis.com [195.60.68.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B228A640E; Tue, 10 Jan 2023 05:50:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; q=dns/txt; s=axis-central1; t=1673358654; x=1704894654; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Ba6MyrEzcdHDm3pPgaIKXEToqVrbCHSG8Ev/nxX8HMo=; b=ec1CG//8jBN74mOQIbxYfMKiUOYn6scM3jBoiLLnyNBnvPu/h3PSjrB2 sWjzzQKMW3Cnurywa8p2c8HBk+jbA6cRhGRhF+yAFzwjJfuw48zF68Xnb /ObCWTzOwBx4UaMCZSYUAcmUQyOhIfmnzWFKOxSOHWDZyKLgmFDIuI3M5 0WlUnXSJazIk919R/Lt4nKRBYLSXpz3HsiyKtmGyJ23A5V6Nz7dJiczAj C2smhZD0Dof+FdjLNuwaJ6xeWOkOzp/Kro7sKQtsFOpIlD1zhIqBncbUK kbFgsMC4Uu+SlMSIFBGrlqemvmWmXKlOLb+AQJd5FdQGm6w4DbEPXV0Al A==; From: Vincent Whitchurch To: , , , CC: , Vincent Whitchurch , , Subject: [PATCH 03/12] crypto: axis - fix CTR output IV Date: Tue, 10 Jan 2023 14:50:33 +0100 Message-ID: <20230110135042.2940847-4-vincent.whitchurch@axis.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230110135042.2940847-1-vincent.whitchurch@axis.com> References: <20230110135042.2940847-1-vincent.whitchurch@axis.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Write the updated counter value to the IV with software since the hardware does not do it. Fixes this self test: alg: skcipher: artpec6-ctr-aes encryption test failed (wrong output IV) on test vector 0, cfg="in-place (one sglist)" Signed-off-by: Vincent Whitchurch --- drivers/crypto/axis/artpec6_crypto.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/drivers/crypto/axis/artpec6_crypto.c b/drivers/crypto/axis/artpec6_crypto.c index d3b6ee065a81..67f510c497f2 100644 --- a/drivers/crypto/axis/artpec6_crypto.c +++ b/drivers/crypto/axis/artpec6_crypto.c @@ -370,6 +370,8 @@ artpec6_crypto_complete_cbc_encrypt(struct crypto_async_request *req); static void artpec6_crypto_complete_cbc_decrypt(struct crypto_async_request *req); static void +artpec6_crypto_complete_ctr(struct crypto_async_request *req); +static void artpec6_crypto_complete_aead(struct crypto_async_request *req); static void artpec6_crypto_complete_hash(struct crypto_async_request *req); @@ -1109,6 +1111,9 @@ static int artpec6_crypto_encrypt(struct skcipher_request *req) case ARTPEC6_CRYPTO_CIPHER_AES_CBC: complete = artpec6_crypto_complete_cbc_encrypt; break; + case ARTPEC6_CRYPTO_CIPHER_AES_CTR: + complete = artpec6_crypto_complete_ctr; + break; default: complete = artpec6_crypto_complete_crypto; break; @@ -1155,6 +1160,9 @@ static int artpec6_crypto_decrypt(struct skcipher_request *req) case ARTPEC6_CRYPTO_CIPHER_AES_CBC: complete = artpec6_crypto_complete_cbc_decrypt; break; + case ARTPEC6_CRYPTO_CIPHER_AES_CTR: + complete = artpec6_crypto_complete_ctr; + break; default: complete = artpec6_crypto_complete_crypto; break; @@ -2158,6 +2166,20 @@ static void artpec6_crypto_complete_crypto(struct crypto_async_request *req) req->complete(req, 0); } +static void artpec6_crypto_complete_ctr(struct crypto_async_request *req) +{ + struct skcipher_request *cipher_req = container_of(req, + struct skcipher_request, base); + unsigned int nblks = ALIGN(cipher_req->cryptlen, AES_BLOCK_SIZE) / + AES_BLOCK_SIZE; + __be32 *iv = (void *)cipher_req->iv; + unsigned int counter = be32_to_cpu(iv[3]); + + iv[3] = cpu_to_be32(counter + nblks); + + req->complete(req, 0); +} + static void artpec6_crypto_complete_cbc_decrypt(struct crypto_async_request *req) { From patchwork Tue Jan 10 13:50:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Whitchurch X-Patchwork-Id: 642755 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4420BC678D8 for ; Tue, 10 Jan 2023 13:51:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232085AbjAJNvZ (ORCPT ); Tue, 10 Jan 2023 08:51:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238268AbjAJNvD (ORCPT ); Tue, 10 Jan 2023 08:51:03 -0500 Received: from smtp1.axis.com (smtp1.axis.com [195.60.68.17]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEE8717040; Tue, 10 Jan 2023 05:50:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; q=dns/txt; s=axis-central1; t=1673358658; x=1704894658; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kt3TYeUvcM4crKR3SNIuzYGknA7sW073R9rphDOt/eU=; b=eIrpeflUif06kYBWPYgaG3u4YDO0brpeHaalvygw4q+trJmL5yYBI9bG QFwTLpgZwtXkwItZ7V+DCbO/OkLHAtsi5uF8GnWYi31sK6IxDuIsfJVO0 31stF0cChEPMAWZx+f4rlXuMkLMR9AoC8S4OsNYfmInHsnBFCpd3T1wZl aVuxthTYCTUyWUAXkUpcdvmIcFO5NRlllmuv54Anbgi42gXZWfdVVEQHB H0jnyNC8qkY7n8SjWXdoHZlL2cbDnjUfQ5OVk3DONH1PyeT46d3DXmNm2 LcTnsl4+VUB51hYrgzPBI0NNoaRiPQu2YGvNgO3oYbH1IgsYo9VtX21bE w==; From: Vincent Whitchurch To: , , , CC: , Vincent Whitchurch , , Subject: [PATCH 04/12] crypto: axis - fix in-place CBC output IV Date: Tue, 10 Jan 2023 14:50:34 +0100 Message-ID: <20230110135042.2940847-5-vincent.whitchurch@axis.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230110135042.2940847-1-vincent.whitchurch@axis.com> References: <20230110135042.2940847-1-vincent.whitchurch@axis.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org When CBC is done in-place, the ->src is overwritten by the time the operation is done, so the output IV must be based on a backup of the ciphertext. Signed-off-by: Vincent Whitchurch --- drivers/crypto/axis/artpec6_crypto.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/crypto/axis/artpec6_crypto.c b/drivers/crypto/axis/artpec6_crypto.c index 67f510c497f2..87f82c314e48 100644 --- a/drivers/crypto/axis/artpec6_crypto.c +++ b/drivers/crypto/axis/artpec6_crypto.c @@ -321,6 +321,7 @@ struct artpec6_crypto_request_context { u32 cipher_md; bool decrypt; struct artpec6_crypto_req_common common; + unsigned char last_ciphertext[AES_BLOCK_SIZE]; unsigned char iv_bounce[AES_BLOCK_SIZE] CRYPTO_MINALIGN_ATTR; }; @@ -1158,6 +1159,10 @@ static int artpec6_crypto_decrypt(struct skcipher_request *req) switch (ctx->crypto_type) { case ARTPEC6_CRYPTO_CIPHER_AES_CBC: + scatterwalk_map_and_copy(req_ctx->last_ciphertext, req->src, + req->cryptlen - sizeof(req_ctx->last_ciphertext), + sizeof(req_ctx->last_ciphertext), 0); + complete = artpec6_crypto_complete_cbc_decrypt; break; case ARTPEC6_CRYPTO_CIPHER_AES_CTR: @@ -2185,10 +2190,10 @@ artpec6_crypto_complete_cbc_decrypt(struct crypto_async_request *req) { struct skcipher_request *cipher_req = container_of(req, struct skcipher_request, base); + struct artpec6_crypto_request_context *req_ctx = skcipher_request_ctx(cipher_req); + + memcpy(cipher_req->iv, req_ctx->last_ciphertext, sizeof(req_ctx->last_ciphertext)); - scatterwalk_map_and_copy(cipher_req->iv, cipher_req->src, - cipher_req->cryptlen - AES_BLOCK_SIZE, - AES_BLOCK_SIZE, 0); req->complete(req, 0); } From patchwork Tue Jan 10 13:50:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Whitchurch X-Patchwork-Id: 641024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2FABBC54EBC for ; Tue, 10 Jan 2023 13:51:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230266AbjAJNvV (ORCPT ); Tue, 10 Jan 2023 08:51:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238347AbjAJNu6 (ORCPT ); Tue, 10 Jan 2023 08:50:58 -0500 Received: from smtp1.axis.com (smtp1.axis.com [195.60.68.17]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A159A13D3B; Tue, 10 Jan 2023 05:50:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; q=dns/txt; s=axis-central1; t=1673358657; x=1704894657; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Bw++1q/WpttUTFptagdBASo7vbIKLpApNOLAXVx9xOg=; b=i8SZIszvcwraT16On8nD778GL02WCVhXiFQ49kbURaOw90e75UyindVf t3OWdq+6LrVdmk12WTpOfKzBqPz3SYLYYKo/fDnNbOwYFjaIanTReVrtC MvILVSDs9Xaooj5cbfczWgWo6jDdVpWDiea9QNFgukDo8Q/7ICQKu4Fiz GRGG/ajjCHeI844TnK4NnAlHHKG0/2sYMW6of6PSug6Qyz4aFIikmBPkZ P+FM7FDu0bj2sL0rna+D4FKPpqHrCsI3UptB7H24jMA1oFLz3tXcvJFnK +qPRYFXePB6l/wJeMj14AbU5iLVkpYMBUDRUpAPQvpzFckRappEMyQ7B7 g==; From: Vincent Whitchurch To: , , , CC: , Vincent Whitchurch , , Subject: [PATCH 05/12] crypto: axis - validate AEAD authsize Date: Tue, 10 Jan 2023 14:50:35 +0100 Message-ID: <20230110135042.2940847-6-vincent.whitchurch@axis.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230110135042.2940847-1-vincent.whitchurch@axis.com> References: <20230110135042.2940847-1-vincent.whitchurch@axis.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Validate the AEAD authsize to fix errors like this with CRYPTO_MANAGER_EXTRA_TESTS: alg: aead: artpec-gcm-aes setauthsize unexpectedly succeeded on test vector "random: alen=0 plen=60 authsize=6 klen=17 novrfy=0"; expected_error=-22 Signed-off-by: Vincent Whitchurch --- drivers/crypto/axis/artpec6_crypto.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/crypto/axis/artpec6_crypto.c b/drivers/crypto/axis/artpec6_crypto.c index 87f82c314e48..0ffe6e0045aa 100644 --- a/drivers/crypto/axis/artpec6_crypto.c +++ b/drivers/crypto/axis/artpec6_crypto.c @@ -1274,6 +1274,12 @@ static int artpec6_crypto_aead_set_key(struct crypto_aead *tfm, const u8 *key, return 0; } +static int artpec6_crypto_aead_setauthsize(struct crypto_aead *tfm, + unsigned int authsize) +{ + return crypto_gcm_check_authsize(authsize); +} + static int artpec6_crypto_aead_encrypt(struct aead_request *req) { int ret; @@ -2829,6 +2835,7 @@ static struct aead_alg aead_algos[] = { { .init = artpec6_crypto_aead_init, .setkey = artpec6_crypto_aead_set_key, + .setauthsize = artpec6_crypto_aead_setauthsize, .encrypt = artpec6_crypto_aead_encrypt, .decrypt = artpec6_crypto_aead_decrypt, .ivsize = GCM_AES_IV_SIZE, From patchwork Tue Jan 10 13:50:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Whitchurch X-Patchwork-Id: 642754 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8EC5CC678D9 for ; Tue, 10 Jan 2023 13:51:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238268AbjAJNv1 (ORCPT ); Tue, 10 Jan 2023 08:51:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238403AbjAJNvE (ORCPT ); Tue, 10 Jan 2023 08:51:04 -0500 Received: from smtp2.axis.com (smtp2.axis.com [195.60.68.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1439CA45C; Tue, 10 Jan 2023 05:51:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; q=dns/txt; s=axis-central1; t=1673358662; x=1704894662; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=aLzM1DqrhyrQcK4KEJ/Hu+9Ne9qneBcLpxAgA6Jk/n8=; b=Yhvk8/Lwf0TTW//K06FShn0nKFZRo7wAi4oEconRPllfGI+cTNvmmBub U6eH5vro7Kkv4yF+64FTkb12ykjZc8ONyN63Lf9rzYhV0Ul+VmeAG50ot hlk2EepWKMfcR+e9CzBqtuGlafyAAaagujN+Jdj5L5DBu2cwVb1VF1ZpK bLCul3r1qHajg2L0eN+ZTRO/oIWWPogndnnJmT86oyGZKyM++jAhJvjXO YKtqBGGq1aLkuIsITW23qtuTy4DdkWoF6KzQu5/CupnmZPj3+L93OWUaE pmvbofEvwGhQPyeXVscge+mZLoc1crjudxIK44nXqX5gSmK8Ls5loLa11 Q==; From: Vincent Whitchurch To: , , , CC: , Vincent Whitchurch , , Subject: [PATCH 06/12] crypto: axis - reject invalid sizes Date: Tue, 10 Jan 2023 14:50:36 +0100 Message-ID: <20230110135042.2940847-7-vincent.whitchurch@axis.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230110135042.2940847-1-vincent.whitchurch@axis.com> References: <20230110135042.2940847-1-vincent.whitchurch@axis.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Reject invalid sizes in block ciphers to fix hangs in CRYPTO_MANAGER_EXTRA_TESTS like this: artpec6-ecb-aes "random: len=55 klen=32" decryption random: inplace_one_sglist use_final nosimd src_divs=[87.4%@+1524, 12.96%@+3553] key_offset=84 Signed-off-by: Vincent Whitchurch --- drivers/crypto/axis/artpec6_crypto.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/drivers/crypto/axis/artpec6_crypto.c b/drivers/crypto/axis/artpec6_crypto.c index 0ffe6e0045aa..78d067ce4138 100644 --- a/drivers/crypto/axis/artpec6_crypto.c +++ b/drivers/crypto/axis/artpec6_crypto.c @@ -1188,6 +1188,22 @@ static int artpec6_crypto_decrypt(struct skcipher_request *req) return artpec6_crypto_submit(&req_ctx->common); } +static int artpec6_crypto_block_encrypt(struct skcipher_request *req) +{ + if (!IS_ALIGNED(req->cryptlen, AES_BLOCK_SIZE)) + return -EINVAL; + + return artpec6_crypto_encrypt(req); +} + +static int artpec6_crypto_block_decrypt(struct skcipher_request *req) +{ + if (!IS_ALIGNED(req->cryptlen, AES_BLOCK_SIZE)) + return -EINVAL; + + return artpec6_crypto_decrypt(req); +} + static int artpec6_crypto_ctr_crypt(struct skcipher_request *req, bool encrypt) { @@ -2757,8 +2773,8 @@ static struct skcipher_alg crypto_algos[] = { .min_keysize = AES_MIN_KEY_SIZE, .max_keysize = AES_MAX_KEY_SIZE, .setkey = artpec6_crypto_cipher_set_key, - .encrypt = artpec6_crypto_encrypt, - .decrypt = artpec6_crypto_decrypt, + .encrypt = artpec6_crypto_block_encrypt, + .decrypt = artpec6_crypto_block_decrypt, .init = artpec6_crypto_aes_ecb_init, .exit = artpec6_crypto_aes_exit, }, @@ -2802,8 +2818,8 @@ static struct skcipher_alg crypto_algos[] = { .max_keysize = AES_MAX_KEY_SIZE, .ivsize = AES_BLOCK_SIZE, .setkey = artpec6_crypto_cipher_set_key, - .encrypt = artpec6_crypto_encrypt, - .decrypt = artpec6_crypto_decrypt, + .encrypt = artpec6_crypto_block_encrypt, + .decrypt = artpec6_crypto_block_decrypt, .init = artpec6_crypto_aes_cbc_init, .exit = artpec6_crypto_aes_exit }, From patchwork Tue Jan 10 13:50:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Whitchurch X-Patchwork-Id: 641023 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DD956C67871 for ; Tue, 10 Jan 2023 13:51:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238368AbjAJNvY (ORCPT ); Tue, 10 Jan 2023 08:51:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238372AbjAJNvD (ORCPT ); Tue, 10 Jan 2023 08:51:03 -0500 Received: from smtp2.axis.com (smtp2.axis.com [195.60.68.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF93D2F7A7; Tue, 10 Jan 2023 05:50:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; q=dns/txt; s=axis-central1; t=1673358660; x=1704894660; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lvf8Py85+laCpLifVy0ksENVI/hrPFpksg+ojS6TM10=; b=h0JmM4T/fLgrBeEcYwca5bXVSFqSPvY8i58kSVV6oCmQFc+al+6CMS0h jBEeWwVgPRtGbRbSQvLLB4YlhhyfSCZ9tbKleOABR4JGSXaddiJETasrX B1CXZ72A7/Bb9PfIEisBHtoItweD10MXpx0KQTMiBzAGNas5S+rbQiUGS 419pWsRA6UftGuLD4PM1D0qu+QngKc1TsEts16RIYA8J8BHKdnEjF2JBP 1jIhWHrgWfF/9VneHGN8PwzNGxAVwD+F4B2/vw1tJvMpGUHhXg2G4FovJ Jqd3R4Ky+hZ78Lp+ClWqhgrwhfJc2xJy4katrBnRwaq43ksDUkw/MnedH Q==; From: Vincent Whitchurch To: , , , CC: , Vincent Whitchurch , , Subject: [PATCH 07/12] crypto: axis - fix XTS blocksize Date: Tue, 10 Jan 2023 14:50:37 +0100 Message-ID: <20230110135042.2940847-8-vincent.whitchurch@axis.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230110135042.2940847-1-vincent.whitchurch@axis.com> References: <20230110135042.2940847-1-vincent.whitchurch@axis.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Use the correct XTS blocksize to fix this warning with CRYPTO_MANAGER_EXTRA_TESTS: skcipher: blocksize for artpec6-xts-aes (1) doesn't match generic impl (16) Signed-off-by: Vincent Whitchurch --- drivers/crypto/axis/artpec6_crypto.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/crypto/axis/artpec6_crypto.c b/drivers/crypto/axis/artpec6_crypto.c index 78d067ce4138..5f30f3d0315f 100644 --- a/drivers/crypto/axis/artpec6_crypto.c +++ b/drivers/crypto/axis/artpec6_crypto.c @@ -2831,7 +2831,7 @@ static struct skcipher_alg crypto_algos[] = { .cra_priority = 300, .cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY, - .cra_blocksize = 1, + .cra_blocksize = AES_BLOCK_SIZE, .cra_ctxsize = sizeof(struct artpec6_cryptotfm_context), .cra_alignmask = 3, .cra_module = THIS_MODULE, From patchwork Tue Jan 10 13:50:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Whitchurch X-Patchwork-Id: 642753 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1154C678DB for ; Tue, 10 Jan 2023 13:51:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238384AbjAJNv3 (ORCPT ); Tue, 10 Jan 2023 08:51:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238405AbjAJNvE (ORCPT ); Tue, 10 Jan 2023 08:51:04 -0500 Received: from smtp2.axis.com (smtp2.axis.com [195.60.68.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34F9B1A064; Tue, 10 Jan 2023 05:51:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; q=dns/txt; s=axis-central1; t=1673358663; x=1704894663; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OHusmXIRIHHHFddqyEz1DJQNr7nvVO78UPiDQuxU384=; b=L0uNsxZ+6KtsRZ4lbQvx4nEVyNQa+zsU4aAXgRHYO/zE65agHlSAeMnV jkp9iRzO7px4NNNuit9AWkkJlBRmK4YIk5QlykXxPhdXoN6QbYZUcjEYq uYvM83KfsNFtxbJs0PIczj5GZtzZq5U95uOQcBmJkeBlaeiX2+uwQ7DLd FBVmW+qAp84ujOhWNcQo2ipMgvzqMD4ALfUptAO2j/KqtjmE+CzRJsVf6 o24K4Liy2m884h2Z19VkENzu8j1b0NBOnc1oIp449ubG2ggHUwe8wb7AO 43xiQsCgJndsAmlkI0VwysVs8bFQ7nIhwDfgyjMZGMN6AKFamzsA/uYb3 Q==; From: Vincent Whitchurch To: , , , CC: , Vincent Whitchurch , , Subject: [PATCH 08/12] crypto: axis - add skcipher fallback Date: Tue, 10 Jan 2023 14:50:38 +0100 Message-ID: <20230110135042.2940847-9-vincent.whitchurch@axis.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230110135042.2940847-1-vincent.whitchurch@axis.com> References: <20230110135042.2940847-1-vincent.whitchurch@axis.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The hardware has a limit of 64 DMA descriptors. If we hit the limit we currently just fail the crypto operation, but this could result in failures higher up in the stack such as in CIFS. Use software fallbacks for all skcipher algos to handle this case. Signed-off-by: Vincent Whitchurch --- drivers/crypto/Kconfig | 3 + drivers/crypto/axis/artpec6_crypto.c | 110 ++++++++++++++++++--------- 2 files changed, 75 insertions(+), 38 deletions(-) diff --git a/drivers/crypto/Kconfig b/drivers/crypto/Kconfig index dfb103f81a64..5aa4bfb648ec 100644 --- a/drivers/crypto/Kconfig +++ b/drivers/crypto/Kconfig @@ -770,11 +770,14 @@ config CRYPTO_DEV_ARTPEC6 select CRYPTO_AES select CRYPTO_ALGAPI select CRYPTO_SKCIPHER + select CRYPTO_CBC select CRYPTO_CTR + select CRYPTO_ECB select CRYPTO_HASH select CRYPTO_SHA1 select CRYPTO_SHA256 select CRYPTO_SHA512 + select CRYPTO_XTS help Enables the driver for the on-chip crypto accelerator of Axis ARTPEC SoCs. diff --git a/drivers/crypto/axis/artpec6_crypto.c b/drivers/crypto/axis/artpec6_crypto.c index 5f30f3d0315f..a05f0927f753 100644 --- a/drivers/crypto/axis/artpec6_crypto.c +++ b/drivers/crypto/axis/artpec6_crypto.c @@ -1088,7 +1088,7 @@ artpec6_crypto_common_destroy(struct artpec6_crypto_req_common *common) /* * Ciphering functions. */ -static int artpec6_crypto_encrypt(struct skcipher_request *req) +static int __artpec6_crypto_encrypt(struct skcipher_request *req) { struct crypto_skcipher *cipher = crypto_skcipher_reqtfm(req); struct artpec6_cryptotfm_context *ctx = crypto_skcipher_ctx(cipher); @@ -1136,7 +1136,7 @@ static int artpec6_crypto_encrypt(struct skcipher_request *req) return artpec6_crypto_submit(&req_ctx->common); } -static int artpec6_crypto_decrypt(struct skcipher_request *req) +static int __artpec6_crypto_decrypt(struct skcipher_request *req) { int ret; struct crypto_skcipher *cipher = crypto_skcipher_reqtfm(req); @@ -1188,6 +1188,53 @@ static int artpec6_crypto_decrypt(struct skcipher_request *req) return artpec6_crypto_submit(&req_ctx->common); } +static int artpec6_crypto_crypt_fallback(struct skcipher_request *req, + bool encrypt) +{ + struct crypto_skcipher *cipher = crypto_skcipher_reqtfm(req); + struct artpec6_cryptotfm_context *ctx = crypto_skcipher_ctx(cipher); + SYNC_SKCIPHER_REQUEST_ON_STACK(subreq, ctx->fallback); + int ret; + + ret = crypto_sync_skcipher_setkey(ctx->fallback, ctx->aes_key, + ctx->key_length); + if (ret) + return ret; + + skcipher_request_set_sync_tfm(subreq, ctx->fallback); + skcipher_request_set_callback(subreq, req->base.flags, + NULL, NULL); + skcipher_request_set_crypt(subreq, req->src, req->dst, + req->cryptlen, req->iv); + ret = encrypt ? crypto_skcipher_encrypt(subreq) + : crypto_skcipher_decrypt(subreq); + skcipher_request_zero(subreq); + + return ret; +} + +static int artpec6_crypto_encrypt(struct skcipher_request *req) +{ + int ret; + + ret = __artpec6_crypto_encrypt(req); + if (ret != -ENOSPC) + return ret; + + return artpec6_crypto_crypt_fallback(req, true); +} + +static int artpec6_crypto_decrypt(struct skcipher_request *req) +{ + int ret; + + ret = __artpec6_crypto_decrypt(req); + if (ret != -ENOSPC) + return ret; + + return artpec6_crypto_crypt_fallback(req, false); +} + static int artpec6_crypto_block_encrypt(struct skcipher_request *req) { if (!IS_ALIGNED(req->cryptlen, AES_BLOCK_SIZE)) @@ -1570,18 +1617,7 @@ static int artpec6_crypto_prepare_hash(struct ahash_request *areq) return ARTPEC6_CRYPTO_PREPARE_HASH_START; } - -static int artpec6_crypto_aes_ecb_init(struct crypto_skcipher *tfm) -{ - struct artpec6_cryptotfm_context *ctx = crypto_skcipher_ctx(tfm); - - tfm->reqsize = sizeof(struct artpec6_crypto_request_context); - ctx->crypto_type = ARTPEC6_CRYPTO_CIPHER_AES_ECB; - - return 0; -} - -static int artpec6_crypto_aes_ctr_init(struct crypto_skcipher *tfm) +static int artpec6_crypto_aes_init(struct crypto_skcipher *tfm, int crypto_type) { struct artpec6_cryptotfm_context *ctx = crypto_skcipher_ctx(tfm); @@ -1592,44 +1628,39 @@ static int artpec6_crypto_aes_ctr_init(struct crypto_skcipher *tfm) return PTR_ERR(ctx->fallback); tfm->reqsize = sizeof(struct artpec6_crypto_request_context); - ctx->crypto_type = ARTPEC6_CRYPTO_CIPHER_AES_CTR; + ctx->crypto_type = crypto_type; return 0; } -static int artpec6_crypto_aes_cbc_init(struct crypto_skcipher *tfm) +static int artpec6_crypto_aes_ecb_init(struct crypto_skcipher *tfm) { - struct artpec6_cryptotfm_context *ctx = crypto_skcipher_ctx(tfm); + return artpec6_crypto_aes_init(tfm, ARTPEC6_CRYPTO_CIPHER_AES_ECB); +} - tfm->reqsize = sizeof(struct artpec6_crypto_request_context); - ctx->crypto_type = ARTPEC6_CRYPTO_CIPHER_AES_CBC; +static int artpec6_crypto_aes_ctr_init(struct crypto_skcipher *tfm) +{ + return artpec6_crypto_aes_init(tfm, ARTPEC6_CRYPTO_CIPHER_AES_CTR); +} - return 0; +static int artpec6_crypto_aes_cbc_init(struct crypto_skcipher *tfm) +{ + return artpec6_crypto_aes_init(tfm, ARTPEC6_CRYPTO_CIPHER_AES_CBC); } static int artpec6_crypto_aes_xts_init(struct crypto_skcipher *tfm) { - struct artpec6_cryptotfm_context *ctx = crypto_skcipher_ctx(tfm); - - tfm->reqsize = sizeof(struct artpec6_crypto_request_context); - ctx->crypto_type = ARTPEC6_CRYPTO_CIPHER_AES_XTS; - - return 0; + return artpec6_crypto_aes_init(tfm, ARTPEC6_CRYPTO_CIPHER_AES_XTS); } static void artpec6_crypto_aes_exit(struct crypto_skcipher *tfm) { struct artpec6_cryptotfm_context *ctx = crypto_skcipher_ctx(tfm); - memset(ctx, 0, sizeof(*ctx)); -} + if (ctx->fallback) + crypto_free_sync_skcipher(ctx->fallback); -static void artpec6_crypto_aes_ctr_exit(struct crypto_skcipher *tfm) -{ - struct artpec6_cryptotfm_context *ctx = crypto_skcipher_ctx(tfm); - - crypto_free_sync_skcipher(ctx->fallback); - artpec6_crypto_aes_exit(tfm); + memset(ctx, 0, sizeof(*ctx)); } static int @@ -2764,7 +2795,8 @@ static struct skcipher_alg crypto_algos[] = { .cra_driver_name = "artpec6-ecb-aes", .cra_priority = 300, .cra_flags = CRYPTO_ALG_ASYNC | - CRYPTO_ALG_ALLOCATES_MEMORY, + CRYPTO_ALG_ALLOCATES_MEMORY | + CRYPTO_ALG_NEED_FALLBACK, .cra_blocksize = AES_BLOCK_SIZE, .cra_ctxsize = sizeof(struct artpec6_cryptotfm_context), .cra_alignmask = 3, @@ -2799,7 +2831,7 @@ static struct skcipher_alg crypto_algos[] = { .encrypt = artpec6_crypto_ctr_encrypt, .decrypt = artpec6_crypto_ctr_decrypt, .init = artpec6_crypto_aes_ctr_init, - .exit = artpec6_crypto_aes_ctr_exit, + .exit = artpec6_crypto_aes_exit, }, /* AES - CBC */ { @@ -2808,7 +2840,8 @@ static struct skcipher_alg crypto_algos[] = { .cra_driver_name = "artpec6-cbc-aes", .cra_priority = 300, .cra_flags = CRYPTO_ALG_ASYNC | - CRYPTO_ALG_ALLOCATES_MEMORY, + CRYPTO_ALG_ALLOCATES_MEMORY | + CRYPTO_ALG_NEED_FALLBACK, .cra_blocksize = AES_BLOCK_SIZE, .cra_ctxsize = sizeof(struct artpec6_cryptotfm_context), .cra_alignmask = 3, @@ -2830,7 +2863,8 @@ static struct skcipher_alg crypto_algos[] = { .cra_driver_name = "artpec6-xts-aes", .cra_priority = 300, .cra_flags = CRYPTO_ALG_ASYNC | - CRYPTO_ALG_ALLOCATES_MEMORY, + CRYPTO_ALG_ALLOCATES_MEMORY | + CRYPTO_ALG_NEED_FALLBACK, .cra_blocksize = AES_BLOCK_SIZE, .cra_ctxsize = sizeof(struct artpec6_cryptotfm_context), .cra_alignmask = 3, From patchwork Tue Jan 10 13:50:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Whitchurch X-Patchwork-Id: 641020 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A0E67C678DC for ; Tue, 10 Jan 2023 13:51:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238285AbjAJNv1 (ORCPT ); Tue, 10 Jan 2023 08:51:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238404AbjAJNvE (ORCPT ); Tue, 10 Jan 2023 08:51:04 -0500 Received: from smtp2.axis.com (smtp2.axis.com [195.60.68.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBE2118E27; Tue, 10 Jan 2023 05:51:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; q=dns/txt; s=axis-central1; t=1673358662; x=1704894662; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XiDCiRkia9wTJveMuFF7NAesdt6ils+FDUKpwJh0mik=; b=gpbupfxiqCrldgXEX/gBrSdz6P3r0iCTFEd99nWiYHJxPqVzU/q7HnKt 5rT33PockQ83RCkjWrxy4OZyLkuKJfDpoV/2yTwzoBoXyBceG0CSTG+Dv HtzAhsGvIgvhR9o6gu4WqDIqfRBvKo9Tdxia8zNSP6oTkuYsjyPBuuZeH bfZvVuCSf/GUH3h5wFXpTiG6TtkYPAUm1a6kFI142u0qXxz1sotDW/ko5 xoM/OTN6qHBhY2Uw4W/AqOFEfIciBvIvNFxZ2wq4Ap0JdQmVrZiEOp9Nw i0nyK5WrepJNEO92kqb3B0lfrbmXcU6sd6XoNKIvVLG66WuoHvpCtxsIG w==; From: Vincent Whitchurch To: , , , CC: , Vincent Whitchurch , , Subject: [PATCH 09/12] crypto: axis - add fallback for AEAD Date: Tue, 10 Jan 2023 14:50:39 +0100 Message-ID: <20230110135042.2940847-10-vincent.whitchurch@axis.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230110135042.2940847-1-vincent.whitchurch@axis.com> References: <20230110135042.2940847-1-vincent.whitchurch@axis.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The hardware has a limit of 64 DMA descriptors. If we hit the limit we currently just fail the crypto operation, but this could result in failures higher up in the stack such as in CIFS. Add a fallback for the gcm(aes) AEAD algorithm. The fallback handling is based on drivers/crypto/amcc/crypto4xx_{algo,core}.c Signed-off-by: Vincent Whitchurch --- drivers/crypto/Kconfig | 1 + drivers/crypto/axis/artpec6_crypto.c | 58 +++++++++++++++++++++++++++- 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/drivers/crypto/Kconfig b/drivers/crypto/Kconfig index 5aa4bfb648ec..5615c9f2641e 100644 --- a/drivers/crypto/Kconfig +++ b/drivers/crypto/Kconfig @@ -773,6 +773,7 @@ config CRYPTO_DEV_ARTPEC6 select CRYPTO_CBC select CRYPTO_CTR select CRYPTO_ECB + select CRYPTO_GCM select CRYPTO_HASH select CRYPTO_SHA1 select CRYPTO_SHA256 diff --git a/drivers/crypto/axis/artpec6_crypto.c b/drivers/crypto/axis/artpec6_crypto.c index a05f0927f753..3b47faa06606 100644 --- a/drivers/crypto/axis/artpec6_crypto.c +++ b/drivers/crypto/axis/artpec6_crypto.c @@ -331,6 +331,7 @@ struct artpec6_cryptotfm_context { u32 key_md; int crypto_type; struct crypto_sync_skcipher *fallback; + struct crypto_aead *aead_fallback; }; struct artpec6_crypto_aead_hw_ctx { @@ -1317,20 +1318,54 @@ static int artpec6_crypto_aead_init(struct crypto_aead *tfm) memset(tfm_ctx, 0, sizeof(*tfm_ctx)); + tfm_ctx->aead_fallback = crypto_alloc_aead(crypto_tfm_alg_name(&tfm->base), + 0, + CRYPTO_ALG_ASYNC | + CRYPTO_ALG_NEED_FALLBACK); + if (IS_ERR(tfm_ctx->aead_fallback)) + return PTR_ERR(tfm_ctx->aead_fallback); + crypto_aead_set_reqsize(tfm, - sizeof(struct artpec6_crypto_aead_req_ctx)); + max(sizeof(struct aead_request) + 32 + + crypto_aead_reqsize(tfm_ctx->aead_fallback), + sizeof(struct artpec6_crypto_aead_req_ctx))); return 0; } +static void artpec6_crypto_aead_exit(struct crypto_aead *tfm) +{ + struct artpec6_cryptotfm_context *ctx = crypto_aead_ctx(tfm); + + crypto_free_aead(ctx->aead_fallback); +} + +static int artpec6_crypto_aead_fallback_set_key(struct artpec6_cryptotfm_context *ctx, + struct crypto_aead *tfm, + const u8 *key, + unsigned int keylen) +{ + struct crypto_aead *fallback = ctx->aead_fallback; + + crypto_aead_clear_flags(fallback, CRYPTO_TFM_REQ_MASK); + crypto_aead_set_flags(fallback, + crypto_aead_get_flags(tfm) & CRYPTO_TFM_REQ_MASK); + return crypto_aead_setkey(fallback, key, keylen); +} + static int artpec6_crypto_aead_set_key(struct crypto_aead *tfm, const u8 *key, unsigned int len) { struct artpec6_cryptotfm_context *ctx = crypto_tfm_ctx(&tfm->base); + int ret; if (len != 16 && len != 24 && len != 32) return -EINVAL; + ret = artpec6_crypto_aead_fallback_set_key(ctx, tfm, key, len); + if (ret < 0) + return ret; + ctx->key_length = len; memcpy(ctx->aes_key, key, len); @@ -1343,6 +1378,21 @@ static int artpec6_crypto_aead_setauthsize(struct crypto_aead *tfm, return crypto_gcm_check_authsize(authsize); } +static int artpec6_crypto_aead_fallback(struct aead_request *req, bool encrypt) +{ + struct artpec6_cryptotfm_context *tfm_ctx = crypto_tfm_ctx(req->base.tfm); + struct aead_request *subreq = aead_request_ctx(req); + + aead_request_set_tfm(subreq, tfm_ctx->aead_fallback); + aead_request_set_callback(subreq, req->base.flags, + req->base.complete, req->base.data); + aead_request_set_crypt(subreq, req->src, req->dst, req->cryptlen, + req->iv); + aead_request_set_ad(subreq, req->assoclen); + return encrypt ? crypto_aead_encrypt(subreq) : + crypto_aead_decrypt(subreq); +} + static int artpec6_crypto_aead_encrypt(struct aead_request *req) { int ret; @@ -1358,6 +1408,8 @@ static int artpec6_crypto_aead_encrypt(struct aead_request *req) ret = artpec6_crypto_prepare_aead(req); if (ret) { artpec6_crypto_common_destroy(&req_ctx->common); + if (ret == -ENOSPC) + return artpec6_crypto_aead_fallback(req, true); return ret; } @@ -1383,6 +1435,8 @@ static int artpec6_crypto_aead_decrypt(struct aead_request *req) ret = artpec6_crypto_prepare_aead(req); if (ret) { artpec6_crypto_common_destroy(&req_ctx->common); + if (ret == -ENOSPC) + return artpec6_crypto_aead_fallback(req, false); return ret; } @@ -2884,6 +2938,7 @@ static struct skcipher_alg crypto_algos[] = { static struct aead_alg aead_algos[] = { { .init = artpec6_crypto_aead_init, + .exit = artpec6_crypto_aead_exit, .setkey = artpec6_crypto_aead_set_key, .setauthsize = artpec6_crypto_aead_setauthsize, .encrypt = artpec6_crypto_aead_encrypt, @@ -2897,6 +2952,7 @@ static struct aead_alg aead_algos[] = { .cra_priority = 300, .cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY | + CRYPTO_ALG_NEED_FALLBACK | CRYPTO_ALG_KERN_DRIVER_ONLY, .cra_blocksize = 1, .cra_ctxsize = sizeof(struct artpec6_cryptotfm_context), From patchwork Tue Jan 10 13:50:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Whitchurch X-Patchwork-Id: 641022 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 11F97C63797 for ; Tue, 10 Jan 2023 13:51:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231532AbjAJNvZ (ORCPT ); Tue, 10 Jan 2023 08:51:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231409AbjAJNvD (ORCPT ); Tue, 10 Jan 2023 08:51:03 -0500 Received: from smtp1.axis.com (smtp1.axis.com [195.60.68.17]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DEB08CC5; Tue, 10 Jan 2023 05:50:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; q=dns/txt; s=axis-central1; t=1673358659; x=1704894659; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=TG79sBPQXvKwaZ2EoZ5EqQSwgfOpv/hMs1+X6I6t1ts=; b=NZyte1ViAxLyCInRm2Pq3J4l7ZdoA86ieq0Ffq598yeGaDpDR12uDL+U I+Gxl73y+gUUkVV+nX3mvfNmfyg4fnF8O/TpgSmpw19GNvtfKyAP2w2Jh GhMEkn6InvQxPI61fG3u9XIRGM5IXoJLfFMRBUAcTMCukfyg0L7ij+fyT TR36Ve78Cg/7FijK5+dtmbQ1xuJRxb1a9r/mUsJnXcozlwiQ7mP3uUena XbgD01moGQ8AYM/KODhKndeKRZWON9mSMOtb+td5xerIONhZKn0QtKxEY 3uAa9qQmqYeyYA6fWYUOCAklY/XixS4pdNbUq+QSeuyADtDS8MXFYRo7P w==; From: Vincent Whitchurch To: , , , CC: , Vincent Whitchurch , , Subject: [PATCH 10/12] crypto: axis - fix XTS unaligned block size handling Date: Tue, 10 Jan 2023 14:50:40 +0100 Message-ID: <20230110135042.2940847-11-vincent.whitchurch@axis.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230110135042.2940847-1-vincent.whitchurch@axis.com> References: <20230110135042.2940847-1-vincent.whitchurch@axis.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The hardware does not implement ciphertext stealing so fallback to software if the data length is not aligned to the block size. Fixes this kind of errors with CRYPTO_MANAGER_EXTRA_TESTS: alg: skcipher: artpec6-xts-aes encryption test failed (wrong result) on test vector "random: len=151 klen=64", cfg="random: inplace_two_sglists use_digest nosimd src_divs=[96.95%@+1949, 3.5%@+30]" Signed-off-by: Vincent Whitchurch --- drivers/crypto/axis/artpec6_crypto.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/drivers/crypto/axis/artpec6_crypto.c b/drivers/crypto/axis/artpec6_crypto.c index 3b47faa06606..5eccb5a3a52e 100644 --- a/drivers/crypto/axis/artpec6_crypto.c +++ b/drivers/crypto/axis/artpec6_crypto.c @@ -1309,6 +1309,24 @@ static int artpec6_crypto_ctr_decrypt(struct skcipher_request *req) return artpec6_crypto_ctr_crypt(req, false); } +static int artpec6_crypto_xts_encrypt(struct skcipher_request *req) +{ + /* Hardware does not implement ciphertext stealing */ + if (!IS_ALIGNED(req->cryptlen, AES_BLOCK_SIZE)) + return artpec6_crypto_crypt_fallback(req, true); + + return artpec6_crypto_encrypt(req); +} + +static int artpec6_crypto_xts_decrypt(struct skcipher_request *req) +{ + /* Hardware does not implement ciphertext stealing */ + if (!IS_ALIGNED(req->cryptlen, AES_BLOCK_SIZE)) + return artpec6_crypto_crypt_fallback(req, false); + + return artpec6_crypto_decrypt(req); +} + /* * AEAD functions */ @@ -2928,8 +2946,8 @@ static struct skcipher_alg crypto_algos[] = { .max_keysize = 2*AES_MAX_KEY_SIZE, .ivsize = 16, .setkey = artpec6_crypto_xts_set_key, - .encrypt = artpec6_crypto_encrypt, - .decrypt = artpec6_crypto_decrypt, + .encrypt = artpec6_crypto_xts_encrypt, + .decrypt = artpec6_crypto_xts_decrypt, .init = artpec6_crypto_aes_xts_init, .exit = artpec6_crypto_aes_exit, }, From patchwork Tue Jan 10 13:50:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Whitchurch X-Patchwork-Id: 642758 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5570C54EBC for ; Tue, 10 Jan 2023 13:51:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237872AbjAJNu6 (ORCPT ); Tue, 10 Jan 2023 08:50:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238265AbjAJNu4 (ORCPT ); Tue, 10 Jan 2023 08:50:56 -0500 Received: from smtp1.axis.com (smtp1.axis.com [195.60.68.17]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32DFD64FC; Tue, 10 Jan 2023 05:50:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; q=dns/txt; s=axis-central1; t=1673358654; x=1704894654; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=L3n+a/Akf31LqdGtqVeh15ZwJJgKE8dO8ZqotT6yTI8=; b=dfT7RTJROkP2UoyzCX2YLtwK2DUf0RPeqNlUkJJj17utqsxd/cYjLild /EYTajF4aPbN7cq3w7JiSapuK08qeGNkAlNFKe470CYyitTOJVRdRC4xj +Th/srrLUYa74s94k+JaYE5QsuLjTh5X3dqJSbOSVAG6xSLsfi4ZSoUAz h7B0SVTwowqEGlePI80+63/qkpgmBUeH8Q0BvaaWwgJJKaJIbWIBjkiIb 73/jRtbSAEI/2fALajg5mIyKrIaZnom1B0jnixl6SCd47t0Owk31zxcH+ 5F+valQRPPk7dm6ci6CF7Ea1bZCu/f3WX83gpEiWRtHeA6f5aRtTl04EH w==; From: Vincent Whitchurch To: , , , CC: , Vincent Whitchurch , , Subject: [PATCH 11/12] crypto: axis - handle zero cryptlen Date: Tue, 10 Jan 2023 14:50:41 +0100 Message-ID: <20230110135042.2940847-12-vincent.whitchurch@axis.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230110135042.2940847-1-vincent.whitchurch@axis.com> References: <20230110135042.2940847-1-vincent.whitchurch@axis.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Succeed zero length operations to prevent hangs/failures with various CRYPTO_MANAGER_EXTRA_TESTS such as: artpec6-ecb-aes "random: len=0 klen=32" encryption random: inplace_two_sglists may_sleep use_finup src_divs=[100.0%@+2743] key_offset=93 For XTS, sizes lesser than the block size need to be explicitly rejected to prevent errors like this: alg: skcipher: artpec6-xts-aes encryption unexpectedly succeeded on test vector "random: len=0 klen=64"; expected_error=-22, cfg="rando m: use_final nosimd src_divs=[100.0%@+3991] dst_divs=[73.80%@+4003, 26.20%@+16] iv_offset=68" Signed-off-by: Vincent Whitchurch --- drivers/crypto/axis/artpec6_crypto.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/crypto/axis/artpec6_crypto.c b/drivers/crypto/axis/artpec6_crypto.c index 5eccb5a3a52e..938faf3afa69 100644 --- a/drivers/crypto/axis/artpec6_crypto.c +++ b/drivers/crypto/axis/artpec6_crypto.c @@ -1097,6 +1097,9 @@ static int __artpec6_crypto_encrypt(struct skcipher_request *req) void (*complete)(struct crypto_async_request *req); int ret; + if (!req->cryptlen) + return 0; + req_ctx = skcipher_request_ctx(req); switch (ctx->crypto_type) { @@ -1145,6 +1148,9 @@ static int __artpec6_crypto_decrypt(struct skcipher_request *req) struct artpec6_crypto_request_context *req_ctx = NULL; void (*complete)(struct crypto_async_request *req); + if (!req->cryptlen) + return 0; + req_ctx = skcipher_request_ctx(req); switch (ctx->crypto_type) { @@ -1311,6 +1317,9 @@ static int artpec6_crypto_ctr_decrypt(struct skcipher_request *req) static int artpec6_crypto_xts_encrypt(struct skcipher_request *req) { + if (req->cryptlen < AES_BLOCK_SIZE) + return -EINVAL; + /* Hardware does not implement ciphertext stealing */ if (!IS_ALIGNED(req->cryptlen, AES_BLOCK_SIZE)) return artpec6_crypto_crypt_fallback(req, true); @@ -1320,6 +1329,9 @@ static int artpec6_crypto_xts_encrypt(struct skcipher_request *req) static int artpec6_crypto_xts_decrypt(struct skcipher_request *req) { + if (req->cryptlen < AES_BLOCK_SIZE) + return -EINVAL; + /* Hardware does not implement ciphertext stealing */ if (!IS_ALIGNED(req->cryptlen, AES_BLOCK_SIZE)) return artpec6_crypto_crypt_fallback(req, false); From patchwork Tue Jan 10 13:50:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Whitchurch X-Patchwork-Id: 641019 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D03F4C678DD for ; Tue, 10 Jan 2023 13:51:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238437AbjAJNvb (ORCPT ); Tue, 10 Jan 2023 08:51:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238381AbjAJNvE (ORCPT ); Tue, 10 Jan 2023 08:51:04 -0500 Received: from smtp2.axis.com (smtp2.axis.com [195.60.68.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2661138AEC; Tue, 10 Jan 2023 05:50:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; q=dns/txt; s=axis-central1; t=1673358661; x=1704894661; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0o6C4Z0fqkBE+QbzIuVUWhJF6tXZkBBn8amIrYpgsE4=; b=eKXy+xQVwCBCX6t2xBW3l2KdBQ6wmn9gCPW25aAMe2t1SLCJ6kzTAOAD iVd+MBXn+/oYxP2zkvpmujAE/4+37pDG82jFXVchoWEIp/xbENNOHRo8S xUvK0EYLvRTGwTVX1pKyQ0wEnoxMXFSSWCtBBcx5Oy3RGLSX22Do+RePz sHp+shW1c6MLddkqVL2UNYhNUOkcC80tc9xHAilqSS11UIHcLX7K4m+Za +I/8CDbq66mQyrkjlJ5YTXxv++hGiVYJyu4upslD6EDIRFkLdrVS6hstx yeh1OhLe5yVyd5F/k3IT5sW3nNCsLTB/axmdDcIvpKkdKH/C8jVPsWp+R g==; From: Vincent Whitchurch To: , , , CC: , Vincent Whitchurch , , Subject: [PATCH 12/12] crypto: axis - allow small size for AEAD Date: Tue, 10 Jan 2023 14:50:42 +0100 Message-ID: <20230110135042.2940847-13-vincent.whitchurch@axis.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230110135042.2940847-1-vincent.whitchurch@axis.com> References: <20230110135042.2940847-1-vincent.whitchurch@axis.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Allow sizes smaller than the AES block size to fix this failure with CRYPTO_MANAGER_EXTRA_TESTS: alg: aead: artpec-gcm-aes decryption failed on test vector "random: alen=0 plen=1 authsize=4 klen=32 novrfy=0"; expected_error=0, actual_error=-22, cfg="random: inplace_one_sglist may_sleep use_final src_divs=[9.71%@+778, 23.43%@+2818, 52.69%@+6, 11.98%@+1030, 2.19%@+3986] iv_offset=40 key_offset=32" Signed-off-by: Vincent Whitchurch --- drivers/crypto/axis/artpec6_crypto.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/crypto/axis/artpec6_crypto.c b/drivers/crypto/axis/artpec6_crypto.c index 938faf3afa69..b6fa2af42cd0 100644 --- a/drivers/crypto/axis/artpec6_crypto.c +++ b/drivers/crypto/axis/artpec6_crypto.c @@ -1452,8 +1452,6 @@ static int artpec6_crypto_aead_decrypt(struct aead_request *req) struct artpec6_crypto_aead_req_ctx *req_ctx = aead_request_ctx(req); req_ctx->decrypt = true; - if (req->cryptlen < AES_BLOCK_SIZE) - return -EINVAL; ret = artpec6_crypto_common_init(&req_ctx->common, &req->base,