From patchwork Tue Mar 28 19:56:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Wanner X-Patchwork-Id: 13191494 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 64E2BC761A6 for ; Tue, 28 Mar 2023 19:57:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=fPLBuKyXsIOBoZHP0P2vmHbg+gtiBbwJ8z1Sg8xQYWg=; b=Ct4Bf6E3FvbQuh g46pIU7riePwdXpG6VEKWsMv7FfTwpspuOwRAxPAypjQ2PvRjLQ7/V+rSbndLexMXQeU3FyW2s2bC DRe2kmbHcl8HN0/Ob37aeQek8F5vtxS2RyAQpPqUzrWo7j2UqF8iX9oI6swRCA/1MY5jx6dUTqCDq Rf1JvM2zlTmMzpKpNWnpj/9DR2Llb2LR3kaSyRdP3mptPbl1WdTcODEM62sOgNRNIFRAPo5ZEp/wU 7zbAaCeZugEQHr7bK0kY3t2JCSb1cMrD1U/+mrdrNDsfB3iigkeHo5/1R48T/W08XVTMZoA2oI+Md 9LBFGbDPnzok4v15fkzQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1phFQu-00FhtC-21; Tue, 28 Mar 2023 19:56:40 +0000 Received: from esa.microchip.iphmx.com ([68.232.154.123]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1phFQn-00FhoU-18 for linux-arm-kernel@lists.infradead.org; Tue, 28 Mar 2023 19:56:34 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1680033393; x=1711569393; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=B79al2p37wc0hLyQzNhdQMnWH/qY4G74yzTaZc4Qtqg=; b=G7Yzi2MWkcxplcPQFCoYlZYIeSTskHZ5OvXpFYWgDJYv+oKrR2jN865C JtRkLchtpLlc5glavmO1dy1dL9UFul7H7IG4+LLKm1CGpo185gnMWzO5v 9b5M2ZJeh7JnDYWafXqyTYeL9TWwdATqqjmgLWyBK/B1xuuHMULyiKuIe c3Y733FrIqsZC6Eg9rC20Kfz0wwYUQ83Jpm4yzoEOuD3TjpupbaxwAkzY m1HXRwTFy1uVEV5gYqCKTlaUPritQzfbcLdl6agnyZBasRcJsPZX1dik2 X5BJYSh12IZ9X1+o3hLDpq72Qc5h7M9oGaSWFS4G4Ah7gDH9PznyRi3q2 A==; X-IronPort-AV: E=Sophos;i="5.98,297,1673938800"; d="scan'208";a="144351915" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa6.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 28 Mar 2023 12:56:24 -0700 Received: from chn-vm-ex03.mchp-main.com (10.10.85.151) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Tue, 28 Mar 2023 12:56:22 -0700 Received: from ryan-Precision-3630-Tower.microchip.com (10.10.115.15) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server id 15.1.2507.21 via Frontend Transport; Tue, 28 Mar 2023 12:56:22 -0700 From: To: , , , , CC: , , , Ryan Wanner Subject: [PATCH 3/4] crypto: atmel-aes - Detecting in-place operations two sg lists Date: Tue, 28 Mar 2023 12:56:28 -0700 Message-ID: <74e969a12021b008d12d871d8d4d9162905f3c48.1680019905.git.Ryan.Wanner@microchip.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230328_125633_457665_052E695A X-CRM114-Status: GOOD ( 11.35 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Ryan Wanner Avoiding detecting finely in-place operations with different scatter lists. Copying the source data for decryption into rctx->lastc regardless if the operation is in-place or not. This allows in-place operations with different scatter lists. This approach takes less resources than parsing both scatter lists to check if they are equal. Signed-off-by: Ryan Wanner --- drivers/crypto/atmel-aes.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/drivers/crypto/atmel-aes.c b/drivers/crypto/atmel-aes.c index 063394cfa874..08a923c2a0eb 100644 --- a/drivers/crypto/atmel-aes.c +++ b/drivers/crypto/atmel-aes.c @@ -493,17 +493,11 @@ static void atmel_aes_set_iv_as_last_ciphertext_block(struct atmel_aes_dev *dd) if (req->cryptlen < ivsize) return; - if (rctx->mode & AES_FLAGS_ENCRYPT) { + if (rctx->mode & AES_FLAGS_ENCRYPT) scatterwalk_map_and_copy(req->iv, req->dst, req->cryptlen - ivsize, ivsize, 0); - } else { - if (req->src == req->dst) - memcpy(req->iv, rctx->lastc, ivsize); - else - scatterwalk_map_and_copy(req->iv, req->src, - req->cryptlen - ivsize, - ivsize, 0); - } + else + memcpy(req->iv, rctx->lastc, ivsize); } static inline struct atmel_aes_ctr_ctx * @@ -1146,7 +1140,7 @@ static int atmel_aes_crypt(struct skcipher_request *req, unsigned long mode) rctx->mode = mode; if (opmode != AES_FLAGS_ECB && - !(mode & AES_FLAGS_ENCRYPT) && req->src == req->dst) { + !(mode & AES_FLAGS_ENCRYPT)) { unsigned int ivsize = crypto_skcipher_ivsize(skcipher); if (req->cryptlen >= ivsize)