Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp353998ybf; Thu, 27 Feb 2020 22:51:55 -0800 (PST) X-Google-Smtp-Source: APXvYqzbJe2+b8Z8vlGy+SkHIiqf6UwLB5oPtljDfI0Bp3EFOjDKyYBfgqf3knwA00R4+X5hyK37 X-Received: by 2002:a9d:7c95:: with SMTP id q21mr2231948otn.278.1582872715797; Thu, 27 Feb 2020 22:51:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582872715; cv=none; d=google.com; s=arc-20160816; b=N/DMpP93+6TlMsqWww507pSXwZzlrxyj5mCJ+NwO355f6tDDIAjfUHiUtVYadO1fVW n0+L+FBhW5AaHijuW4J19oUpV02sMnqkkT5vy6YDVbGPc6XPReyTUff0YpDHKgbSNXRd zjRxZJqM19FuDn5LiquZDYC6enXRQd4XRT8UzwmnfCbTVaw+YVgWku9cFcnFOvOGltcG VUY5OWOPp+zpDm1Q0iIg/ljybvkwEmomfuR2ktffs8jHCnYYsG7iiEolEEI3hs0zW5so x2Zlg7YYDzrZRwICpfYoAu44UstjcWeLIrYQTPARqiWb/qLYRwwOBerfwvDMM6H6Bbqx Rjgw== 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 :message-id:date:subject:cc:to:from; bh=sJI5q0pfXfcEoPnCnNN57DRsXhp6pMv/FvVrDHLgQig=; b=GvqhQH4GgxfbiFMxbT5fp/bhzzenDfSiUjNbgIdmC3Us0OXK1dhGOmCnozebUhZ4mb GwiuNU4But+mbitznqQ7xuBEtY4IlSOC+Kp1x/Ej6KlLPWzqEQHkGUksO0GH8GZNDm8U VXFPz79BTqIWfLgnMXwUXJnnaRN30hxgBRY+/zE1y7RYT+78epduTGIqV0Z6Gb5SWCCD wq4zmvk/3VjF0jcfMoupA5LBvG50AUNrRT0FsE2cPzxqmnYmlQlNuGiOsYXWOizf6SK+ ybdZHDPPddfxdMM53U+JE1AwYIO0TyOzoVueYHJB4uk10uygk4jhEEjoRlpiJK1KFtSy ekVg== 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 t192si1265925oif.75.2020.02.27.22.51.40; Thu, 27 Feb 2020 22:51:55 -0800 (PST) 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 S1726738AbgB1Gv2 (ORCPT + 99 others); Fri, 28 Feb 2020 01:51:28 -0500 Received: from inva020.nxp.com ([92.121.34.13]:39534 "EHLO inva020.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725943AbgB1Gv2 (ORCPT ); Fri, 28 Feb 2020 01:51:28 -0500 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id A60991A01A6; Fri, 28 Feb 2020 07:51:26 +0100 (CET) Received: from inva024.eu-rdc02.nxp.com (inva024.eu-rdc02.nxp.com [134.27.226.22]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 973DC1A004B; Fri, 28 Feb 2020 07:51:26 +0100 (CET) Received: from fsr-ub1864-014.ea.freescale.net (fsr-ub1864-014.ea.freescale.net [10.171.95.219]) by inva024.eu-rdc02.nxp.com (Postfix) with ESMTP id 51DA22056A; Fri, 28 Feb 2020 07:51:26 +0100 (CET) From: =?UTF-8?q?Horia=20Geant=C4=83?= To: Herbert Xu Cc: "David S. Miller" , Aymen Sghaier , Valentin Ciocoi Radulescu , linux-crypto@vger.kernel.org, NXP Linux Team Subject: [PATCH v2] crypto: caam/qi2 - fix chacha20 data size error Date: Fri, 28 Feb 2020 08:51:23 +0200 Message-Id: <20200228065123.13216-1-horia.geanta@nxp.com> X-Mailer: git-send-email 2.17.1 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 HW generates a Data Size error for chacha20 requests that are not a multiple of 64B, since algorithm state (AS) does not have the FINAL bit set. Since updating req->iv (for chaining) is not required, modify skcipher descriptors to set the FINAL bit for chacha20. [Note that for skcipher decryption we know that ctx1_iv_off is 0, which allows for an optimization by not checking algorithm type, since append_dec_op1() sets FINAL bit for all algorithms except AES.] Also drop the descriptor operations that save the IV. However, in order to keep code logic simple, things like S/G tables generation etc. are not touched. Cc: # v5.3+ Fixes: 334d37c9e263 ("crypto: caam - update IV using HW support") Signed-off-by: Horia Geantă --- drivers/crypto/caam/caamalg_desc.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/crypto/caam/caamalg_desc.c b/drivers/crypto/caam/caamalg_desc.c index aa9ccca67045..6171a8118b5a 100644 --- a/drivers/crypto/caam/caamalg_desc.c +++ b/drivers/crypto/caam/caamalg_desc.c @@ -1379,6 +1379,9 @@ void cnstr_shdsc_skcipher_encap(u32 * const desc, struct alginfo *cdata, const u32 ctx1_iv_off) { u32 *key_jump_cmd; + u32 options = cdata->algtype | OP_ALG_AS_INIT | OP_ALG_ENCRYPT; + bool is_chacha20 = ((cdata->algtype & OP_ALG_ALGSEL_MASK) == + OP_ALG_ALGSEL_CHACHA20); init_sh_desc(desc, HDR_SHARE_SERIAL | HDR_SAVECTX); /* Skip if already shared */ @@ -1417,14 +1420,15 @@ void cnstr_shdsc_skcipher_encap(u32 * const desc, struct alginfo *cdata, LDST_OFFSET_SHIFT)); /* Load operation */ - append_operation(desc, cdata->algtype | OP_ALG_AS_INIT | - OP_ALG_ENCRYPT); + if (is_chacha20) + options |= OP_ALG_AS_FINALIZE; + append_operation(desc, options); /* Perform operation */ skcipher_append_src_dst(desc); /* Store IV */ - if (ivsize) + if (!is_chacha20 && ivsize) append_seq_store(desc, ivsize, LDST_SRCDST_BYTE_CONTEXT | LDST_CLASS_1_CCB | (ctx1_iv_off << LDST_OFFSET_SHIFT)); @@ -1451,6 +1455,8 @@ void cnstr_shdsc_skcipher_decap(u32 * const desc, struct alginfo *cdata, const u32 ctx1_iv_off) { u32 *key_jump_cmd; + bool is_chacha20 = ((cdata->algtype & OP_ALG_ALGSEL_MASK) == + OP_ALG_ALGSEL_CHACHA20); init_sh_desc(desc, HDR_SHARE_SERIAL | HDR_SAVECTX); /* Skip if already shared */ @@ -1499,7 +1505,7 @@ void cnstr_shdsc_skcipher_decap(u32 * const desc, struct alginfo *cdata, skcipher_append_src_dst(desc); /* Store IV */ - if (ivsize) + if (!is_chacha20 && ivsize) append_seq_store(desc, ivsize, LDST_SRCDST_BYTE_CONTEXT | LDST_CLASS_1_CCB | (ctx1_iv_off << LDST_OFFSET_SHIFT)); -- 2.17.1