Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1388394ybz; Thu, 16 Apr 2020 08:18:39 -0700 (PDT) X-Google-Smtp-Source: APiQypKgxvARMCYqsJdXOFCRc0glw8hpOZjbdpCmAdGLayHYPWIOEbjjjkD6Lkh+J5lu3DT1l0Uf X-Received: by 2002:a17:907:214d:: with SMTP id rk13mr10322066ejb.220.1587050318835; Thu, 16 Apr 2020 08:18:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587050318; cv=none; d=google.com; s=arc-20160816; b=Xv8RwBeQwHEfxAy8m55MYFzVKV7iBadP8seo4SD4o/1P/yxsXFO/qF6YtDnG8m/eUf HV7Toq5CDqC3jAUMsZnwb2tAdEBtFqktt3agAVnPXUjmoqQdEI99tygSqDw6PjYTeaUg IpltQVQdyDXt+UkI9b3wxTrfvienToMoiG5YOgLuTLXGdiNPA/HybHdGw/4aU9yRP/8C V+DwyHFi/7bd3fqQ70Aqk++2JjvwDb24rx5Pa6EUE5Bq/yOd3udzp2k/yHCn6WQ3fyOG Y2mw0R8QVHwCL2nfakD4Xl2sPeT7wyClcfi5kqQtxvMaWsZrq0MhCK/Yx6p+mjqhAPtP 5DBA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=7b1G+x6DxPnfDIYHPVhGnWwBsFdtK//BytUELBWtSo8=; b=sra70qgD6uohUshDDFExx9y/+TARn6QLibb93uDAwhKFG/2UxQJR7hUrw5Rh9EdCDx dkQzpWneSmG/JHEDTy1H5kqvexxX/feBdfjvZr3/rDD8tBTNwLINLDGzDR5nGaUXVOzl 9/rCjBpE5D7LbTZYDuB0vE0rE0cIcazlVrh8BIZvZH6ZOpPLDA1ZARyxXfev+LFZ6YY1 OZ0kuzRx38vIQRF3nVGHPVqzc7v2EzV66eRk3tjRq1dUIQ/T6ebet9LCYRhYuCTkoyrX 13IwzV4ZolpT4G2BnZV9iqWb39sNbkk1Z/V/Y2UjLrirHR4j4vIRNs+/VGfNwR5KUaV9 +g9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Mbc1gpIa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h23si11827982ejq.206.2020.04.16.08.18.15; Thu, 16 Apr 2020 08:18:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Mbc1gpIa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2503837AbgDPPQb (ORCPT + 99 others); Thu, 16 Apr 2020 11:16:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:35820 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2441583AbgDPNuC (ORCPT ); Thu, 16 Apr 2020 09:50:02 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D010A2222C; Thu, 16 Apr 2020 13:49:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587044953; bh=HgRYTwaT0K3i6R4yyE0ffxtTm8sNUE/pRjIWBN7QiJ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Mbc1gpIasdm7OfBlVQvIjr+M/9j35IIepcqBHOGv3NQlGqVsUN3lTmH3Y8B6+refj v/WjCCf6TZXBuq3RRD1r5KJSQDi1T5Y9raYoIP726EhZlpZbH3G/O2q36/b1OMB5Az P9AP3Xt15bzz03pKJN1UgF8acoz4ZFQO8Nq6pxcI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Horia=20Geant=C4=83?= , Valentin Ciocoi Radulescu , Herbert Xu Subject: [PATCH 5.4 168/232] crypto: caam/qi2 - fix chacha20 data size error Date: Thu, 16 Apr 2020 15:24:22 +0200 Message-Id: <20200416131336.009875806@linuxfoundation.org> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200416131316.640996080@linuxfoundation.org> References: <20200416131316.640996080@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Horia Geantă commit 3a5a9e1ef37b030b836d92df8264f840988f4a38 upstream. 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ă Tested-by: Valentin Ciocoi Radulescu Signed-off-by: Herbert Xu Signed-off-by: Greg Kroah-Hartman --- drivers/crypto/caam/caamalg_desc.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) --- a/drivers/crypto/caam/caamalg_desc.c +++ b/drivers/crypto/caam/caamalg_desc.c @@ -1379,6 +1379,9 @@ void cnstr_shdsc_skcipher_encap(u32 * co 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 * co 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 * co 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 * co 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));