Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp250334yba; Mon, 20 May 2019 08:07:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqzHMJLa1cOpCuTlGplYsnyBeroW/OVAAU6R1uQ21gH6zAMtAxo2UmEfu8U6PMVPO92+Ps+j X-Received: by 2002:aa7:8c1a:: with SMTP id c26mr80442441pfd.25.1558364856476; Mon, 20 May 2019 08:07:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558364856; cv=none; d=google.com; s=arc-20160816; b=HvPZd58j8WBs/JmfuwVoRyV8S1xTgSS13oc4fOj/OK1UP7gnbgpHS3h8jkqCBxIY2K NuRqQPQzuShWTcZapyNTVjP6LsNQulnMiCkvuA2YVzGjifKl9beU0r7BM6XsHdeUDGgW ZUpg01hmoQEtuzOueWxrAXV8cBpB5fjEEWn74sesF8pO1TMQMjfXZ/wogDGsoYCcKIog Do2bR0pPJECYPB0jKBifmYibIVkvtTMYWD7vs/70hklOYY0UWOIjY50mi4l9rhSUVX4B AnJempdhP9hwopupgqVszSFBvjB9Xtudn3L83xC1WdM/v+nIm4dalYsShs5F0SZNG6za 6Hbw== 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=kqMZIwkGdtZoNSfy2UKOpgNn3RLmf5UTpIPQYrxGZ9Y=; b=Wu0lfAlt1JfkG9sttCUXrxrwct4DbI24j+30xQ8MnZBYuytekFhZR6gEGDjN+c1o3I L94Dchi6gjKitUGjjOcUYo9egx5OaaqToUhlfeIxVcO7FM+2mZzpYISbK38oao1cWFFh WSNo3XBteKIpQIB6vOp6si1CoAL9WqQq5VwgHPuoyydAXaA876sPYSznFMci1RPYa8dt WHbbTo+2navoWKusws8ozwSl3AJB/5V34HIlJ0AdJUs8hFJaU5/4OUmipe50GOW5tw8w 0owEfeHX7+GCubBexuXh1s/96hOAoCqT8SHT/yBOgeS7l3dPwdaBdnmCLopsoLUOCfOo wPPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=G3zMNbuL; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c129si9046339pga.81.2019.05.20.08.07.20; Mon, 20 May 2019 08:07:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=G3zMNbuL; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730986AbfETMVh (ORCPT + 99 others); Mon, 20 May 2019 08:21:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:35222 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388174AbfETMVa (ORCPT ); Mon, 20 May 2019 08:21:30 -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 69F8720815; Mon, 20 May 2019 12:21:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558354889; bh=34pvu7oNa5wqsc3tntV2i9diO3rjJi8DbuOwL65B550=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G3zMNbuLdy5QBEFhKFzo73eB2lwCyqIYy1CjUtmTO9u+GYNHFvywWbiufM31WUueL XZ8M+abBs6QNo7OREafkFC6WMJSO71WY/EUXJeCycg+a/FqTH0wImmd+QPwhKSl688 wcFD32yuUcnZ0XYGEjVnIsp1hR6XTJWSkSKNLhU4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christian Lamparter , Herbert Xu Subject: [PATCH 4.19 018/105] crypto: crypto4xx - fix ctr-aes missing output IV Date: Mon, 20 May 2019 14:13:24 +0200 Message-Id: <20190520115248.277587088@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190520115247.060821231@linuxfoundation.org> References: <20190520115247.060821231@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: Christian Lamparter commit 25baaf8e2c93197d063b372ef7b62f2767c7ac0b upstream. Commit 8efd972ef96a ("crypto: testmgr - support checking skcipher output IV") caused the crypto4xx driver to produce the following error: | ctr-aes-ppc4xx encryption test failed (wrong output IV) | on test vector 0, cfg="in-place" This patch fixes this by reworking the crypto4xx_setkey_aes() function to: - not save the iv for ECB (as per 18.2.38 CRYP0_SA_CMD_0: "This bit mut be cleared for DES ECB mode or AES ECB mode, when no IV is used.") - instruct the hardware to save the generated IV for all other modes of operations that have IV and then supply it back to the callee in pretty much the same way as we do it for cbc-aes already. - make it clear that the DIR_(IN|OUT)BOUND is the important bit that tells the hardware to encrypt or decrypt the data. (this is cosmetic - but it hopefully prevents me from getting confused again). - don't load any bogus hash when we don't use any hash operation to begin with. Cc: stable@vger.kernel.org Fixes: f2a13e7cba9e ("crypto: crypto4xx - enable AES RFC3686, ECB, CFB and OFB offloads") Signed-off-by: Christian Lamparter Signed-off-by: Herbert Xu Signed-off-by: Greg Kroah-Hartman --- drivers/crypto/amcc/crypto4xx_alg.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) --- a/drivers/crypto/amcc/crypto4xx_alg.c +++ b/drivers/crypto/amcc/crypto4xx_alg.c @@ -141,9 +141,10 @@ static int crypto4xx_setkey_aes(struct c /* Setup SA */ sa = ctx->sa_in; - set_dynamic_sa_command_0(sa, SA_NOT_SAVE_HASH, (cm == CRYPTO_MODE_CBC ? - SA_SAVE_IV : SA_NOT_SAVE_IV), - SA_LOAD_HASH_FROM_SA, SA_LOAD_IV_FROM_STATE, + set_dynamic_sa_command_0(sa, SA_NOT_SAVE_HASH, (cm == CRYPTO_MODE_ECB ? + SA_NOT_SAVE_IV : SA_SAVE_IV), + SA_NOT_LOAD_HASH, (cm == CRYPTO_MODE_ECB ? + SA_LOAD_IV_FROM_SA : SA_LOAD_IV_FROM_STATE), SA_NO_HEADER_PROC, SA_HASH_ALG_NULL, SA_CIPHER_ALG_AES, SA_PAD_TYPE_ZERO, SA_OP_GROUP_BASIC, SA_OPCODE_DECRYPT, @@ -162,6 +163,11 @@ static int crypto4xx_setkey_aes(struct c memcpy(ctx->sa_out, ctx->sa_in, ctx->sa_len * 4); sa = ctx->sa_out; sa->sa_command_0.bf.dir = DIR_OUTBOUND; + /* + * SA_OPCODE_ENCRYPT is the same value as SA_OPCODE_DECRYPT. + * it's the DIR_(IN|OUT)BOUND that matters + */ + sa->sa_command_0.bf.opcode = SA_OPCODE_ENCRYPT; return 0; }