Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp5962501ybi; Wed, 31 Jul 2019 06:09:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqzh6MEHdRR7JOEVGvKu5KxBHN3xuDoFec60IU5xRKbz4JLJd3RFo6cLBeOWAI5VpaJUD6ny X-Received: by 2002:aa7:957c:: with SMTP id x28mr47190327pfq.42.1564578599213; Wed, 31 Jul 2019 06:09:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564578599; cv=none; d=google.com; s=arc-20160816; b=Y5LiBUgpN1oPfizNtnXzFBdhLJyz2/lySb2K2CDHEhr7JuMMfbvM7IyeYYoe5N2AYr 4zQqOBGP1FnjamvWseH8fcyvhGLessm1UMqP2tqE1NywkVEt6Dj+63j3gSRF8W3sVU4d ls8ghoY6MtFvo5AvZzItpmpLGzAvB6nlYBy6mQTFpy8nvl9budgOvU6eG7XUbRGv1Wgl qNOAhs/c0SnzeWN1hA1KBxdDa1TtZGlw3NbEZml5t1CaxvZrmrPbHNIV3yaWRqJAcQeO icU0wNMhqqMpiEaVpCOhUaZKO3Q1EfV1G8vXKAFglArpoR5cE72triNeePK9X/7ddWUc 1f9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=eRR0P4477c7NEYlg9VvNA4b6X8w8Q7D876blL2t/Mlo=; b=os/Uodpvsp5DC2ssKhLkXEDlyXKACISK7FbfO0s8uaZZCbtat/kZMB2rlcOKUQC+VT 3Sq8UP82u12EMaDyoo2YnLqJso2g/SogjP0LUDTD2D+4sbxYLy7mVcoGdvU94bbEvYT1 Jt/xlffFvp9aVQzvyyYLy8P2qmpsz/R8jqaDy7p7HdbkTOIMwgeNB0NgtlV+J8+BoMuX ZDXnAy08Chw+IbXAAeI4W3IsKD0yEBooojm02N+V/NmVAmLD2g1aKruxd9Ec3Gp0C41/ lRCa/jJN6LTHDDfy+EWbY01HA4Uh63STWObtowStTmgX4L21BcDjKOVU0uSHfqVSK5tC c72g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 64si28548700ply.15.2019.07.31.06.09.45; Wed, 31 Jul 2019 06:09:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388301AbfGaNJG (ORCPT + 99 others); Wed, 31 Jul 2019 09:09:06 -0400 Received: from inva021.nxp.com ([92.121.34.21]:42728 "EHLO inva021.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729215AbfGaNIY (ORCPT ); Wed, 31 Jul 2019 09:08:24 -0400 Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 1E6EE200A1F; Wed, 31 Jul 2019 15:08:22 +0200 (CEST) Received: from inva024.eu-rdc02.nxp.com (inva024.eu-rdc02.nxp.com [134.27.226.22]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 10E1E200A1E; Wed, 31 Jul 2019 15:08:22 +0200 (CEST) Received: from lorenz.ea.freescale.net (lorenz.ea.freescale.net [10.171.71.5]) by inva024.eu-rdc02.nxp.com (Postfix) with ESMTP id A8590205F3; Wed, 31 Jul 2019 15:08:21 +0200 (CEST) From: Iuliana Prodan To: Herbert Xu , Horia Geanta , Aymen Sghaier Cc: "David S. Miller" , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-imx Subject: [PATCH v5 03/14] crypto: caam - update IV only when crypto operation succeeds Date: Wed, 31 Jul 2019 16:08:04 +0300 Message-Id: <1564578495-9883-4-git-send-email-iuliana.prodan@nxp.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1564578495-9883-1-git-send-email-iuliana.prodan@nxp.com> References: <1564578495-9883-1-git-send-email-iuliana.prodan@nxp.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org From: Horia Geantă skcipher encryption might fail and in some cases, like (invalid) input length smaller then block size, updating the IV would lead to a useless IV copy in case hardware issued an error. Signed-off-by: Horia Geantă Signed-off-by: Iuliana Prodan --- drivers/crypto/caam/caamalg.c | 5 ++--- drivers/crypto/caam/caamalg_qi.c | 4 +++- drivers/crypto/caam/caamalg_qi2.c | 8 ++++++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/drivers/crypto/caam/caamalg.c b/drivers/crypto/caam/caamalg.c index 06b4f2d..28d55a0 100644 --- a/drivers/crypto/caam/caamalg.c +++ b/drivers/crypto/caam/caamalg.c @@ -990,10 +990,9 @@ static void skcipher_encrypt_done(struct device *jrdev, u32 *desc, u32 err, * ciphertext block (CBC mode) or last counter (CTR mode). * This is used e.g. by the CTS mode. */ - if (ivsize) { + if (ivsize && !ecode) { memcpy(req->iv, (u8 *)edesc->sec4_sg + edesc->sec4_sg_bytes, ivsize); - print_hex_dump_debug("dstiv @"__stringify(__LINE__)": ", DUMP_PREFIX_ADDRESS, 16, 4, req->iv, edesc->src_nents > 1 ? 100 : ivsize, 1); @@ -1030,7 +1029,7 @@ static void skcipher_decrypt_done(struct device *jrdev, u32 *desc, u32 err, * ciphertext block (CBC mode) or last counter (CTR mode). * This is used e.g. by the CTS mode. */ - if (ivsize) { + if (ivsize && !ecode) { memcpy(req->iv, (u8 *)edesc->sec4_sg + edesc->sec4_sg_bytes, ivsize); diff --git a/drivers/crypto/caam/caamalg_qi.c b/drivers/crypto/caam/caamalg_qi.c index ab263b1..66531d6 100644 --- a/drivers/crypto/caam/caamalg_qi.c +++ b/drivers/crypto/caam/caamalg_qi.c @@ -1201,7 +1201,9 @@ static void skcipher_done(struct caam_drv_req *drv_req, u32 status) * ciphertext block (CBC mode) or last counter (CTR mode). * This is used e.g. by the CTS mode. */ - memcpy(req->iv, (u8 *)&edesc->sgt[0] + edesc->qm_sg_bytes, ivsize); + if (!ecode) + memcpy(req->iv, (u8 *)&edesc->sgt[0] + edesc->qm_sg_bytes, + ivsize); qi_cache_free(edesc); skcipher_request_complete(req, ecode); diff --git a/drivers/crypto/caam/caamalg_qi2.c b/drivers/crypto/caam/caamalg_qi2.c index 2681581..bc370af 100644 --- a/drivers/crypto/caam/caamalg_qi2.c +++ b/drivers/crypto/caam/caamalg_qi2.c @@ -1358,7 +1358,9 @@ static void skcipher_encrypt_done(void *cbk_ctx, u32 status) * ciphertext block (CBC mode) or last counter (CTR mode). * This is used e.g. by the CTS mode. */ - memcpy(req->iv, (u8 *)&edesc->sgt[0] + edesc->qm_sg_bytes, ivsize); + if (!ecode) + memcpy(req->iv, (u8 *)&edesc->sgt[0] + edesc->qm_sg_bytes, + ivsize); qi_cache_free(edesc); skcipher_request_complete(req, ecode); @@ -1394,7 +1396,9 @@ static void skcipher_decrypt_done(void *cbk_ctx, u32 status) * ciphertext block (CBC mode) or last counter (CTR mode). * This is used e.g. by the CTS mode. */ - memcpy(req->iv, (u8 *)&edesc->sgt[0] + edesc->qm_sg_bytes, ivsize); + if (!ecode) + memcpy(req->iv, (u8 *)&edesc->sgt[0] + edesc->qm_sg_bytes, + ivsize); qi_cache_free(edesc); skcipher_request_complete(req, ecode); -- 2.1.0