From patchwork Tue Aug 15 06:26:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gilad Ben-Yossef X-Patchwork-Id: 110109 Delivered-To: patch@linaro.org Received: by 10.182.109.195 with SMTP id hu3csp5115752obb; Mon, 14 Aug 2017 23:28:51 -0700 (PDT) X-Received: by 10.98.75.148 with SMTP id d20mr27878835pfj.48.1502778531743; Mon, 14 Aug 2017 23:28:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1502778531; cv=none; d=google.com; s=arc-20160816; b=Z6uYDyqCAGZ3qMZn++YyDe1DEX8Fd+XK/AcHSNeYUktHkZiO2GYoDKvQl+DZXB1EdO N0nckFfrQfC3NMU4miBwpjtBrTHBVMAPrapj/hdjTTcfyhEchOTZaIbXSJQS+QmiucFZ LEVmokOng85fVtCMQTvmZg23o4K0frBhw6V3jVMy9l9IX0+ETviUjO6UZRxkJd3bM9zX kzKFpwS27ed/BncF2xgA0J9P/TKsHq6HlSQZboumOUIhrDxA7d+srDb7SENrC5Spr301 ETNtgknIFLssz27ka15RigSEj7++QwposaHzl9ZhTEJi4ohhAYBgOi13K9vzN98pEv9l JSCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=rbcpM5tdLSdMJN/Hgo5I5EbI0QPzYDe5NepOFGFBx2I=; b=rq3j1PxV3Uqz20lvYJxDu9vvspvM0vsp+Fr8grg8duWt9L/JpIj42H3iKBan+pg5/h uCJSgOEv58lWI4jgPbq9MIZ9bj6xOBZzJy7XvQ+bwljUZdqju/iNTTCQEitply8BhZtL YUWWLq2U49XduSA5qMuZ1qdWvYlRNg9emDkBHAg0g2rMPTA6Cj277hTDTi4CJIKNgtFi b7Fwzc7KYrtgv4MXI7UCo6SEXlU2f+ZVRuxQ6DCPsRrMor163nIoxqT8psMK+fXXeO3J 1qnchZC1zAGa1D9PjygW5EUqCQJdUTTp33T+wlnOPfOE+g7BaQSZGrBAcXQBANeLBZzh d6AA== ARC-Authentication-Results: i=1; mx.google.com; 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 y15si5696998pli.453.2017.08.14.23.28.51; Mon, 14 Aug 2017 23:28:51 -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; 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 S1753776AbdHOG2t (ORCPT + 25 others); Tue, 15 Aug 2017 02:28:49 -0400 Received: from foss.arm.com ([217.140.101.70]:48240 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753686AbdHOG2p (ORCPT ); Tue, 15 Aug 2017 02:28:45 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 303412B; Mon, 14 Aug 2017 23:28:45 -0700 (PDT) Received: from gby.kfn.arm.com (unknown [10.45.48.148]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8ACB83F3E1; Mon, 14 Aug 2017 23:28:43 -0700 (PDT) From: Gilad Ben-Yossef To: Greg Kroah-Hartman , linux-crypto@vger.kernel.org, driverdev-devel@linuxdriverproject.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Cc: Ofir Drang Subject: [PATCH v3 21/22] staging: ccree: save ciphertext for CTS IV Date: Tue, 15 Aug 2017 09:26:49 +0300 Message-Id: <1502778412-16255-22-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1502778412-16255-1-git-send-email-gilad@benyossef.com> References: <1502778412-16255-1-git-send-email-gilad@benyossef.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The crypto API requires saving the last blocks of ciphertext in req->info for use as IV for CTS mode. The ccree driver was not doing it and so failing tcrypt tests in some situations. This patch fixes the issue. Signed-off-by: Gilad Ben-Yossef --- drivers/staging/ccree/ssi_cipher.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) -- 2.1.4 diff --git a/drivers/staging/ccree/ssi_cipher.c b/drivers/staging/ccree/ssi_cipher.c index aa722e1..cc550b5 100644 --- a/drivers/staging/ccree/ssi_cipher.c +++ b/drivers/staging/ccree/ssi_cipher.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "ssi_config.h" #include "ssi_driver.h" @@ -696,6 +697,7 @@ static int ssi_blkcipher_complete(struct device *dev, { int completion_error = 0; u32 inflight_counter; + struct ablkcipher_request *req = (struct ablkcipher_request *)areq; ssi_buffer_mgr_unmap_blkcipher_request(dev, req_ctx, ivsize, src, dst); @@ -706,6 +708,22 @@ static int ssi_blkcipher_complete(struct device *dev, ctx_p->drvdata->inflight_counter--; if (areq) { + /* + * The crypto API expects us to set the req->info to the last + * ciphertext block. For encrypt, simply copy from the result. + * For decrypt, we must copy from a saved buffer since this + * could be an in-place decryption operation and the src is + * lost by this point. + */ + if (req_ctx->gen_ctx.op_type == DRV_CRYPTO_DIRECTION_DECRYPT) { + memcpy(req->info, req_ctx->backup_info, ivsize); + kfree(req_ctx->backup_info); + } else { + scatterwalk_map_and_copy(req->info, req->dst, + (req->nbytes - ivsize), + ivsize, 0); + } + ablkcipher_request_complete(areq, completion_error); return 0; } @@ -859,7 +877,6 @@ static int ssi_ablkcipher_encrypt(struct ablkcipher_request *req) struct blkcipher_req_ctx *req_ctx = ablkcipher_request_ctx(req); unsigned int ivsize = crypto_ablkcipher_ivsize(ablk_tfm); - req_ctx->backup_info = req->info; req_ctx->is_giv = false; return ssi_blkcipher_process(tfm, req_ctx, req->dst, req->src, req->nbytes, req->info, ivsize, (void *)req, DRV_CRYPTO_DIRECTION_ENCRYPT); @@ -872,8 +889,18 @@ static int ssi_ablkcipher_decrypt(struct ablkcipher_request *req) struct blkcipher_req_ctx *req_ctx = ablkcipher_request_ctx(req); unsigned int ivsize = crypto_ablkcipher_ivsize(ablk_tfm); - req_ctx->backup_info = req->info; + /* + * Allocate and save the last IV sized bytes of the source, which will + * be lost in case of in-place decryption and might be needed for CTS. + */ + req_ctx->backup_info = kmalloc(ivsize, GFP_KERNEL); + if (!req_ctx->backup_info) + return -ENOMEM; + + scatterwalk_map_and_copy(req_ctx->backup_info, req->src, + (req->nbytes - ivsize), ivsize, 0); req_ctx->is_giv = false; + return ssi_blkcipher_process(tfm, req_ctx, req->dst, req->src, req->nbytes, req->info, ivsize, (void *)req, DRV_CRYPTO_DIRECTION_DECRYPT); }