Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1636765ybv; Fri, 21 Feb 2020 00:45:18 -0800 (PST) X-Google-Smtp-Source: APXvYqzqKpt5CyDnDJXN+n3wBJT1A6xe4Zl36+vXCsPdczyJBsRCI5U6r2MeUzUa4UKowX3Jde6q X-Received: by 2002:a54:4396:: with SMTP id u22mr1084096oiv.128.1582274718436; Fri, 21 Feb 2020 00:45:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582274718; cv=none; d=google.com; s=arc-20160816; b=tvTT2QXWauPOpl1yf/VKA3A4b6Tup8yS86KqdFuAJH5dZ/oVcLNdwBZ+rCNpYqbGOW 2xAnjuQLkyTfY4fIPHM+hvILVJV3W80kNLL1N7pHeGt7WKoQ19RovmOxkMKI8f4s5rS7 ++gnaq4Nao+SB4lyZzF72y5+wOBev9CtVBOtsQrwNQeG2nLmN3djFFIR1wZstAZVJNA+ OhaIXNWHclPfrHyNcjW9ZLNXwl9K0cH0uV6rtXVjWUvWtr+u5yKJjIgxhiMbR9XjPK3B PJnEpty1kdcX6CWSefcQuoRh5fPRG/4E5Pb70HtPq5wLq87D104afL+tmjAp/TgLlfOW Dytg== 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=peSzpWuXMA1/n50CljgK7ueGS8rtIkAkPwGg8hltlIw=; b=NsOONprrWPBh4QqHy1Vf6lElrcf4kl8/dLmkCvsO5OeHqp9ivEWA7+mZXqPYz3/mOc uc3v4oMjWcbtstHedRz0Ka+zGShht9LtN+tqO3lXAslRdkq4PocF402c1cY2hh/tOlI8 Gmn0aSNLPpBOQz54HZ/+7q2YeNEDcBmwh8XKGEA18i8sgv5ecjbxa7CTUAs6tZnNwBD4 wFCzvuSGsUB14Zb1jHzyFFfb/2W5KzozlKGwQraKeUf9PDIgpWpzYn6+5m+dkq0VoA+2 QbeiXVDqsqWbNlrQL1sqoG3652Vw6Ja8uLJXrzykuwSxpQUsOas1Nqz01lL3WJUnJK1s Orbw== 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 o18si1126930otk.80.2020.02.21.00.45.06; Fri, 21 Feb 2020 00:45:18 -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 S1728496AbgBUHwU (ORCPT + 99 others); Fri, 21 Feb 2020 02:52:20 -0500 Received: from inva020.nxp.com ([92.121.34.13]:51524 "EHLO inva020.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729892AbgBUHwS (ORCPT ); Fri, 21 Feb 2020 02:52:18 -0500 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id C36801A6F35; Fri, 21 Feb 2020 08:52:17 +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 B70431A6F4B; Fri, 21 Feb 2020 08:52:17 +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 70998202D2; Fri, 21 Feb 2020 08:52:17 +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] crypto: caam/qi2 - fix chacha20 data size error Date: Fri, 21 Feb 2020 09:52:01 +0200 Message-Id: <20200221075201.5725-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..372d3d4ed6c5 100644 --- a/drivers/crypto/caam/caamalg_desc.c +++ b/drivers/crypto/caam/caamalg_desc.c @@ -1379,6 +1379,8 @@ void cnstr_shdsc_skcipher_encap(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 */ @@ -1417,14 +1419,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 +1454,9 @@ void cnstr_shdsc_skcipher_decap(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 */ @@ -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