Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp4898681rwl; Tue, 28 Mar 2023 12:58:23 -0700 (PDT) X-Google-Smtp-Source: AKy350YdZFJJXlH76VU1qVJpNnGAI5IRuZNRPIy5/zLsmOQOu/sXbRdpeVlI8lQ65q/vDRlRaR6l X-Received: by 2002:a17:902:e88a:b0:1a0:563e:b0c4 with SMTP id w10-20020a170902e88a00b001a0563eb0c4mr14372815plg.2.1680033503149; Tue, 28 Mar 2023 12:58:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680033503; cv=none; d=google.com; s=arc-20160816; b=K0n0icQHPzQKCE5esF6r7Wd7Ie0jUjWn2gSrV+o/1GDx3XXCLsKskjtkNj1Ia2PFNL O8XTTVU3fPkB0zdLqJ6IjACUuaMMKedIeWIL7LwN921Z8NQXYNEvGwm1rKIumQG24voG Y2U6pkxFQdHtwxmoWpZnpQ5c5UAMmBeB7ErhqLoWTMI8qrOyCGOTMTNCclVd4+dFnJWT 15beeIaZ3WhVT6HiQkF5dmljns9ke2J2GrlLdhPkS3AavclcaBbLA1aXv8XaqBF9+SHq boAvz7tDvge7ewmnvdCbMvG9PyqYctPJ2aTtRtgP+oh6LRlE9zJhbcBrv3jNZLxK6nyS 3Hwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=zDBBcnUNfvmw8b7bADTGhy2nAeyYeN1XHBISO0l+ulk=; b=XlSotT5hebPHcIZtP/JiX4OxpO3UhEEoqj45TViAIWh2AtE4Hy/nm2zR9dWw/hDATw Z9xWbMkAJbtTgkXm08342YooyazoivwxJaD956qCnj5BYBj5Ws64BZ2S6zKGBNaDXs0E jMQuEX46Pdma/oIyeJFVhGPrxSYnT7r2+tybnYJpP6RnbanQb/J9G63ZJvcP3+ivgzb3 iLIV4OYbHs/qspdIzsNINL4S6/b6mw0EG8bQOXOfec01oZB2QSEWAMd+is464dInsHRz 64GjdixOMEh1BYIAEiMmaj8Gl9sroeSffkUJhvUCu6IAl9L+JdGkKEenhnwuAFC4jbKN weTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=lDCtGG9a; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e16-20020a17090301d000b001a20679d548si12605127plh.183.2023.03.28.12.58.10; Tue, 28 Mar 2023 12:58:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=lDCtGG9a; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229710AbjC1T42 (ORCPT + 99 others); Tue, 28 Mar 2023 15:56:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229697AbjC1T41 (ORCPT ); Tue, 28 Mar 2023 15:56:27 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B6143AA2; Tue, 28 Mar 2023 12:56:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1680033386; x=1711569386; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=B79al2p37wc0hLyQzNhdQMnWH/qY4G74yzTaZc4Qtqg=; b=lDCtGG9aG8/HR4efU839qQZ04ThxubNmUC1iY2ZIlGybwZxGFRMKDCZG Kr+iy+ALaMlc1yLPbn2OTT1RSV+y6qkhbMq06SiLNLxFYWjlR8GCz23aY 7EWuVtCldWiasJt0o1yLLOaKx4sVEU5PfX1Fz5Za6JwMorTLJzvLcGDU0 xQRQAWR/sprUk4LP/QybdE8nt2Jhkry+d48XVnORIS/DHR2mC27lXkYqB IVMvoBGL7/U1/sTn/W7TztHDkN3mO09ykcHtNaQlXjHA9mY3XqIZTZNKC crVrPOdJ6QzIFgCK1munlUhdTvSfvfsDZP3JKErczO27RXRUjGRfQu6Jy g==; 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.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) -- 2.37.2