From patchwork Fri Oct 16 23:19:33 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victoria Milhoan X-Patchwork-Id: 7421501 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Original-To: patchwork-linux-crypto@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 3A576BEEA4 for ; Fri, 16 Oct 2015 23:35:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0004A208AC for ; Fri, 16 Oct 2015 23:35:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D5494208A0 for ; Fri, 16 Oct 2015 23:35:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751201AbbJPXfX (ORCPT ); Fri, 16 Oct 2015 19:35:23 -0400 Received: from mail-bn1on0138.outbound.protection.outlook.com ([157.56.110.138]:41264 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751103AbbJPXfV (ORCPT ); Fri, 16 Oct 2015 19:35:21 -0400 Received: from BN3PR0301CA0047.namprd03.prod.outlook.com (10.160.152.143) by DM2PR0301MB1312.namprd03.prod.outlook.com (10.160.222.17) with Microsoft SMTP Server (TLS) id 15.1.300.14; Fri, 16 Oct 2015 23:19:39 +0000 Received: from BL2FFO11OLC006.protection.gbl (2a01:111:f400:7c09::173) by BN3PR0301CA0047.outlook.office365.com (2a01:111:e400:401e::15) with Microsoft SMTP Server (TLS) id 15.1.300.14 via Frontend Transport; Fri, 16 Oct 2015 23:19:38 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=freescale.com; davemloft.net; dkim=none (message not signed) header.d=none;davemloft.net; dmarc=none action=none header.from=freescale.com; Received-SPF: Fail (protection.outlook.com: domain of freescale.com does not designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Received: from tx30smr01.am.freescale.net (192.88.168.50) by BL2FFO11OLC006.mail.protection.outlook.com (10.173.160.95) with Microsoft SMTP Server (TLS) id 15.1.293.9 via Frontend Transport; Fri, 16 Oct 2015 23:19:36 +0000 Received: from stc-hedley.am.freescale.net (stc-hedley.am.freescale.net [10.67.70.12]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id t9GNJX7P011241; Fri, 16 Oct 2015 16:19:33 -0700 From: Victoria Milhoan To: CC: , , , , , , , , Subject: [PATCH] crypto: caam - Add support for hashing export and import functions Date: Fri, 16 Oct 2015 16:19:33 -0700 Message-ID: <1445037573-29667-1-git-send-email-vicki.milhoan@freescale.com> X-Mailer: git-send-email 2.1.4 X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11OLC006; 1:quMkgVb6ENEjfbVcJjmUhM/agG3mckfpLWARYOHmTeGCE9ThfL2IC2WAoD1dbWP3C7TsmG3lk9hd8eGBh7Js9VDdCl6tHq+PCcltpldrR0RshgUqclaIvR2bEG8U93sxCIADrrD2Jd1wDfTfCkPiH/IXebgdlNlXYp11L9YAxfDb4RGrB+0cbM5abXNCtMtED/hHvlounUG/hE/Votbfoh/SxKRHHtuaUGfpmHI1SBxbZLzfH6yhIQcI1gLJttGL4AeRIWRygJXS8+AxyZSocD+aYg5V3TwEz0P4rjBMxvaBYPsbamR+82Gu5W0al8D3l0CqT5wBp8sqm8g5P8i7fh3swRgiLDoNvtbrhQXFVuTj+9jgHUDiQiWOtTasXCLWt8Htcwqdukbeo1DHQybDjA== X-Forefront-Antispam-Report: CIP:192.88.168.50; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(2980300002)(1110001)(1109001)(339900001)(199003)(189002)(189998001)(64706001)(81156007)(5001960100002)(48376002)(5003940100001)(110136002)(50466002)(6806005)(104016004)(92566002)(5007970100001)(97736004)(36756003)(229853001)(2351001)(85426001)(46102003)(105606002)(87936001)(19580405001)(19580395003)(50226001)(77096005)(47776003)(33646002)(5008740100001)(106466001)(86362001)(50986999); DIR:OUT; SFP:1102; SCL:1; SRVR:DM2PR0301MB1312; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Exchange-Diagnostics: 1; DM2PR0301MB1312; 2:qOBzLCWoJ1DUUumFQT7fkDCLHWi+64O6m33zyqVwPS5zEaqgODz6R5BTby9zVCeQbs19OqA+UDdXbXMab7cyUDECtJD+357mjLMtrI6dfQCQuzkrz+5VSres5GR7RZTdKabuS+ZCmTZVWsEuOoaPn1gcC7E6fUvCLgp7wwhhaE8=; 3:hwjYs8N6YgjbIylbYgb0Ud3esqGsoAp5lo3onUspiQFcc/yw7O+galgBYPFu/i5r3ftfCMLN5AtfZWH8BfotZFJXXUkqe1WGVtpCPltDSy6JLozD2qndR9/LHEhzBjlA+Q2DGhhZ6neqdpRTW5vqMfIcG92e0eYyqpvkHXGCGvPJrfFM4Op3eQ50Gm/1aspSVH6alfZn9Z58dcgYWPcG1ye1ZGaLTJ83ArCpceSL69w=; 25:Qr6zDThxe5R55vmo0VtmskfT3AMIfikXEvvncOFbjkoUJrfYjrJIO5LRYX8QHdaN8EeqXFkYVE+eCjyI0yEYZYNb+aqe8tG0+J20v5kRfoFM3P/5S0U274nFuenfInrIViZdkAoyVNcHCX5Odkzx98MMkrRQRgveWQnYCvFaMyvFK0VLtsAKQWA7R1MHXyqQLlQLtpZqvn+DhSjKEWbl768Q1VnydiEXlWZElzuYgY8TsgivBr0dsr+28alvf14SG264hGXo8ZhDBfLz8c8chQ== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DM2PR0301MB1312; X-Microsoft-Exchange-Diagnostics: 1; DM2PR0301MB1312; 20:fXVBQjg5uTieyJHDFLo1Xe1sJzymhfLUBJBzvNxbQF4nUX9u2129K3/C/QzKn8hHzUoDUmuIBsAMZ2ZV+ts/u8eORY+vdJBp+ywFV3ryP9eEEp5+D40IziUW5T5KMyzaBMlJHKwp11OBRZFVu2d3JjG3KE6lmr7yOP6vct6orGL0NSqUSUDkCS86p5kZesc66+3+NxCWNGj7Akp8IZyHocF3VnMWhWfL/4YXF/hL4N/t7+sF9F387c7Xmz5uu1pMMqnTc4tmTU9MYmozohLzWEqS5YxH7xSkmsePSupXbmVpYz3TDAoLTuL9J8yS2evKHA8yZRAedxyuYD4p4xC7LchXh0/h4ZMlPCWMRKZtiBQ=; 4:u5seC6/k+vsjl4iMI8ay957iRkIUGgHtonkWsiN/Ik+LiC2wqODBDSh8wnKgWXHVi/+YjWa8vC0r1YariAdTbffmgJEv/WOPjvAKp4c8aPgKd4+sLHho7CDG80I8brEumoYdnc7HxzuuBs0Vr64JFy+ZO5QDhGhPzzS49tFakbotTuCSGKfIiZtvyP3f9ewcNQEFOq6wgOrbbfCjYaIzrWatoDoeh3SOsySWGt7gnK4H5DtVus+GoWiXO7qv1dc84O3+oiTWvByZvNeCH/c352krECbMtcvZS92b3UL86y/SxmaYO99icqQt8qDgX0mk32rAR3MKdyX1zF3olVNwl78nMvCMqC6VkMoGaea5Gls= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(101931422205132); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(520078)(8121501046)(3002001); SRVR:DM2PR0301MB1312; BCL:0; PCL:0; RULEID:; SRVR:DM2PR0301MB1312; X-Forefront-PRVS: 0731AA2DE6 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM2PR0301MB1312; 23:0Ad02dxlTUbDN0V1vkXiRS3nT/5MjzCxvl1rMel?= =?us-ascii?Q?ADkzKH7ADArK+CgFaaZFk4Pj7GDOuf/T80++q2JZcWaHw9m+DrYP+sKoQdMc?= =?us-ascii?Q?/r07gIE7PF01O2K/nnf64fxK1E75pV6zzfU8csA5qYNdhp2gJf8AlpSKfkD9?= =?us-ascii?Q?Nq5vkDxi1kZGnvuemWJoKN+CHawXjvpBkhIhhgTXVhTx/Vb1s016g9z32MdH?= =?us-ascii?Q?q6sqdL1PUnJiPDfE/ORg/7Xurgc+EAL64jMMRpj5lHjSkzZsDTHyLTKlBVp4?= =?us-ascii?Q?cQ/gSe24KwQB8PFikj5fxJgjvuDtz+prtqb6J8Z8lOiIJNKf4F97uIGi2/Mj?= =?us-ascii?Q?LNa2xS6GJVPQ4Ep2SlK/TIYoIcIWjgn0RCsomd3LIR2jsvMpFXm9Sx4vdDI2?= =?us-ascii?Q?jRmgIXrER2wMN31URnv0YBZ+q/S/5Pj+lB7zkS6FzL4FhRm3+lmzfFETv7HF?= =?us-ascii?Q?sdLPHuX4GAxIhuo9VTYd7edQPY6qPD3yIT63syr7IK7kfwiNiKoS1PlrS7JT?= =?us-ascii?Q?2Ggqx0zU1+osIdY2Y0DN5lBXjHCXCs/eWSGlRZdej39DKOdnFwGszr+2OCFf?= =?us-ascii?Q?jXgCLg2QpS4euYmoon10jYYB4aWmdlrQ//3YRoQJ3OJov6kIB4NIxabNRO5z?= =?us-ascii?Q?6+zbum8rCwMFpbxElKky2DpGQCz02PG1HMlrc5E1gIa2FI0hLtD+NBrD3JUv?= =?us-ascii?Q?rvyxmPl5Ap5c+zQTiClmQvRBhpoXS7RU0zW0tECPKeMADfBz2MfVzLzl2v/G?= =?us-ascii?Q?bQCM454nwQnxNmswklHM3KaWQ7inJoxxL3RIHC9rRRrNMTBFYYv5Tu4Xmc9J?= =?us-ascii?Q?YfCDsEgU2tcq20Kxt8aPsvErzezBLkLwA6kFW7dFaMI/oODeCl7BAUXWrjIS?= =?us-ascii?Q?MY3XVGJK4J7fFXq0yhi4vZVUR0z+cVtwUiF5tUiJoewmoHm+j91RIxBdmB4x?= =?us-ascii?Q?zR5EAAYEifR4IizI1xCJtd2jpYEWsx68nd1roXdaY1GifU06AkwCNtJt/yJS?= =?us-ascii?Q?ZHNN9CFX6ANNJXsZgWowxtIdq?= X-Microsoft-Exchange-Diagnostics: 1; DM2PR0301MB1312; 5:4LSviKlZ+ViSYl9s+LGNWCmqdNS6Xbwhx4tzXkGNBRL/WTE/UxnYoKmx5f5w8xXrN72g9FDezbC/ooDD/QwlClZMKc/tXMVDXnsyDYQXOZ+4eTXQ8xbOLFItwHBuWfpMXBFlC3C2WflMPq67Lr2W8w==; 24:dnWPEsdpTqXcpgHJc4LbcMz7/BEtNudKBBYqE6eVykrGq+cLnmUmpHTQCCErw+ZOiB7FrIVY+rvj8YLIwkI0+8VXkHwXf60teMGn7C6l4F4=; 20:zOd71r7jxc7vkbqrdmej1oZFaDTq5O8AQQgghMBS2bL5JjI8ZndlPUanJ8fE96qhDkZ8StNC3VHG3G4sxtGWlQ== X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2015 23:19:36.9759 (UTC) X-MS-Exchange-CrossTenant-Id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=710a03f5-10f6-4d38-9ff4-a80b81da590d; Ip=[192.88.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR0301MB1312 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add support for the export and import functions used by hashing algorithms by specifying the size of the data saved/restored. The size of the data is provided during algorithm registration. Also, modify the structures saved/restored in order to meet the size limit of 512 bytes imposed by the the Crypto API. Signed-off-by: Victoria Milhoan --- drivers/crypto/caam/caamhash.c | 82 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 68 insertions(+), 14 deletions(-) diff --git a/drivers/crypto/caam/caamhash.c b/drivers/crypto/caam/caamhash.c index 9609f66..bb81ab6 100644 --- a/drivers/crypto/caam/caamhash.c +++ b/drivers/crypto/caam/caamhash.c @@ -100,11 +100,11 @@ static struct list_head hash_list; /* ahash per-session context */ struct caam_hash_ctx { struct device *jrdev; - u32 sh_desc_update[DESC_HASH_MAX_USED_LEN]; - u32 sh_desc_update_first[DESC_HASH_MAX_USED_LEN]; - u32 sh_desc_fin[DESC_HASH_MAX_USED_LEN]; - u32 sh_desc_digest[DESC_HASH_MAX_USED_LEN]; - u32 sh_desc_finup[DESC_HASH_MAX_USED_LEN]; + u32 *sh_desc_update; + u32 *sh_desc_update_first; + u32 *sh_desc_fin; + u32 *sh_desc_digest; + u32 *sh_desc_finup; dma_addr_t sh_desc_update_dma; dma_addr_t sh_desc_update_first_dma; dma_addr_t sh_desc_fin_dma; @@ -123,9 +123,9 @@ struct caam_hash_ctx { struct caam_hash_state { dma_addr_t buf_dma; dma_addr_t ctx_dma; - u8 buf_0[CAAM_MAX_HASH_BLOCK_SIZE] ____cacheline_aligned; + u8 *buf_0; int buflen_0; - u8 buf_1[CAAM_MAX_HASH_BLOCK_SIZE] ____cacheline_aligned; + u8 *buf_1; int buflen_1; u8 caam_ctx[MAX_CTX_LEN] ____cacheline_aligned; int (*update)(struct ahash_request *req); @@ -319,7 +319,7 @@ static int ahash_set_sh_desc(struct crypto_ahash *ahash) have_key = OP_ALG_AAI_HMAC_PRECOMP; /* ahash_update shared descriptor */ - desc = ctx->sh_desc_update; + desc = kmalloc(DESC_HASH_MAX_USED_BYTES, GFP_KERNEL | GFP_DMA); init_sh_desc(desc, HDR_SHARE_SERIAL); @@ -334,6 +334,7 @@ static int ahash_set_sh_desc(struct crypto_ahash *ahash) /* Load data and write to result or context */ ahash_append_load_str(desc, ctx->ctx_len); + ctx->sh_desc_update = desc; ctx->sh_desc_update_dma = dma_map_single(jrdev, desc, desc_bytes(desc), DMA_TO_DEVICE); if (dma_mapping_error(jrdev, ctx->sh_desc_update_dma)) { @@ -347,11 +348,12 @@ static int ahash_set_sh_desc(struct crypto_ahash *ahash) #endif /* ahash_update_first shared descriptor */ - desc = ctx->sh_desc_update_first; + desc = kmalloc(DESC_HASH_MAX_USED_BYTES, GFP_KERNEL | GFP_DMA); ahash_data_to_out(desc, have_key | ctx->alg_type, OP_ALG_AS_INIT, ctx->ctx_len, ctx); + ctx->sh_desc_update_first = desc; ctx->sh_desc_update_first_dma = dma_map_single(jrdev, desc, desc_bytes(desc), DMA_TO_DEVICE); @@ -366,11 +368,12 @@ static int ahash_set_sh_desc(struct crypto_ahash *ahash) #endif /* ahash_final shared descriptor */ - desc = ctx->sh_desc_fin; + desc = kmalloc(DESC_HASH_MAX_USED_BYTES, GFP_KERNEL | GFP_DMA); ahash_ctx_data_to_out(desc, have_key | ctx->alg_type, OP_ALG_AS_FINALIZE, digestsize, ctx); + ctx->sh_desc_fin = desc; ctx->sh_desc_fin_dma = dma_map_single(jrdev, desc, desc_bytes(desc), DMA_TO_DEVICE); if (dma_mapping_error(jrdev, ctx->sh_desc_fin_dma)) { @@ -384,11 +387,12 @@ static int ahash_set_sh_desc(struct crypto_ahash *ahash) #endif /* ahash_finup shared descriptor */ - desc = ctx->sh_desc_finup; + desc = kmalloc(DESC_HASH_MAX_USED_BYTES, GFP_KERNEL | GFP_DMA); ahash_ctx_data_to_out(desc, have_key | ctx->alg_type, OP_ALG_AS_FINALIZE, digestsize, ctx); + ctx->sh_desc_finup = desc; ctx->sh_desc_finup_dma = dma_map_single(jrdev, desc, desc_bytes(desc), DMA_TO_DEVICE); if (dma_mapping_error(jrdev, ctx->sh_desc_finup_dma)) { @@ -402,11 +406,12 @@ static int ahash_set_sh_desc(struct crypto_ahash *ahash) #endif /* ahash_digest shared descriptor */ - desc = ctx->sh_desc_digest; + desc = kmalloc(DESC_HASH_MAX_USED_BYTES, GFP_KERNEL | GFP_DMA); ahash_data_to_out(desc, have_key | ctx->alg_type, OP_ALG_AS_INITFINAL, digestsize, ctx); + ctx->sh_desc_digest = desc; ctx->sh_desc_digest_dma = dma_map_single(jrdev, desc, desc_bytes(desc), DMA_TO_DEVICE); @@ -631,10 +636,10 @@ static void ahash_done(struct device *jrdev, u32 *desc, u32 err, struct ahash_request *req = context; struct ahash_edesc *edesc; struct crypto_ahash *ahash = crypto_ahash_reqtfm(req); + struct caam_hash_state *state = ahash_request_ctx(req); int digestsize = crypto_ahash_digestsize(ahash); #ifdef DEBUG struct caam_hash_ctx *ctx = crypto_ahash_ctx(ahash); - struct caam_hash_state *state = ahash_request_ctx(req); dev_err(jrdev, "%s %d: err 0x%x\n", __func__, __LINE__, err); #endif @@ -657,6 +662,11 @@ static void ahash_done(struct device *jrdev, u32 *desc, u32 err, digestsize, 1); #endif + kfree(state->buf_0); + kfree(state->buf_1); + state->buf_0 = NULL; + state->buf_1 = NULL; + req->base.complete(&req->base, err); } @@ -701,10 +711,10 @@ static void ahash_done_ctx_src(struct device *jrdev, u32 *desc, u32 err, struct ahash_request *req = context; struct ahash_edesc *edesc; struct crypto_ahash *ahash = crypto_ahash_reqtfm(req); + struct caam_hash_state *state = ahash_request_ctx(req); int digestsize = crypto_ahash_digestsize(ahash); #ifdef DEBUG struct caam_hash_ctx *ctx = crypto_ahash_ctx(ahash); - struct caam_hash_state *state = ahash_request_ctx(req); dev_err(jrdev, "%s %d: err 0x%x\n", __func__, __LINE__, err); #endif @@ -727,6 +737,11 @@ static void ahash_done_ctx_src(struct device *jrdev, u32 *desc, u32 err, digestsize, 1); #endif + kfree(state->buf_0); + kfree(state->buf_1); + state->buf_0 = NULL; + state->buf_1 = NULL; + req->base.complete(&req->base, err); } @@ -1522,6 +1537,9 @@ static int ahash_init(struct ahash_request *req) state->finup = ahash_finup_first; state->final = ahash_final_no_ctx; + state->buf_0 = kmalloc(CAAM_MAX_HASH_BLOCK_SIZE, GFP_KERNEL | GFP_DMA); + state->buf_1 = kmalloc(CAAM_MAX_HASH_BLOCK_SIZE, GFP_KERNEL | GFP_DMA); + state->current_buf = 0; state->buf_dma = 0; state->buflen_0 = 0; @@ -1557,6 +1575,20 @@ static int ahash_export(struct ahash_request *req, void *out) struct caam_hash_ctx *ctx = crypto_ahash_ctx(ahash); struct caam_hash_state *state = ahash_request_ctx(req); + /* + * Do not export the data buffers. New buffers are + * allocated during import. + */ + kfree(state->buf_0); + kfree(state->buf_1); + state->buf_0 = NULL; + state->buf_1 = NULL; + + state->current_buf = 0; + state->buf_dma = 0; + state->buflen_0 = 0; + state->buflen_1 = 0; + memcpy(out, ctx, sizeof(struct caam_hash_ctx)); memcpy(out + sizeof(struct caam_hash_ctx), state, sizeof(struct caam_hash_state)); @@ -1569,6 +1601,10 @@ static int ahash_import(struct ahash_request *req, const void *in) struct caam_hash_ctx *ctx = crypto_ahash_ctx(ahash); struct caam_hash_state *state = ahash_request_ctx(req); + /* Allocate new data buffers to use for this request */ + state->buf_0 = kmalloc(CAAM_MAX_HASH_BLOCK_SIZE, GFP_KERNEL | GFP_DMA); + state->buf_1 = kmalloc(CAAM_MAX_HASH_BLOCK_SIZE, GFP_KERNEL | GFP_DMA); + memcpy(ctx, in, sizeof(struct caam_hash_ctx)); memcpy(state, in + sizeof(struct caam_hash_ctx), sizeof(struct caam_hash_state)); @@ -1605,6 +1641,8 @@ static struct caam_hash_template driver_hash[] = { .setkey = ahash_setkey, .halg = { .digestsize = SHA1_DIGEST_SIZE, + .statesize = sizeof(struct caam_hash_ctx) + + sizeof(struct caam_hash_state), }, }, .alg_type = OP_ALG_ALGSEL_SHA1, @@ -1626,6 +1664,8 @@ static struct caam_hash_template driver_hash[] = { .setkey = ahash_setkey, .halg = { .digestsize = SHA224_DIGEST_SIZE, + .statesize = sizeof(struct caam_hash_ctx) + + sizeof(struct caam_hash_state), }, }, .alg_type = OP_ALG_ALGSEL_SHA224, @@ -1647,6 +1687,8 @@ static struct caam_hash_template driver_hash[] = { .setkey = ahash_setkey, .halg = { .digestsize = SHA256_DIGEST_SIZE, + .statesize = sizeof(struct caam_hash_ctx) + + sizeof(struct caam_hash_state), }, }, .alg_type = OP_ALG_ALGSEL_SHA256, @@ -1668,6 +1710,8 @@ static struct caam_hash_template driver_hash[] = { .setkey = ahash_setkey, .halg = { .digestsize = SHA384_DIGEST_SIZE, + .statesize = sizeof(struct caam_hash_ctx) + + sizeof(struct caam_hash_state), }, }, .alg_type = OP_ALG_ALGSEL_SHA384, @@ -1689,6 +1733,8 @@ static struct caam_hash_template driver_hash[] = { .setkey = ahash_setkey, .halg = { .digestsize = SHA512_DIGEST_SIZE, + .statesize = sizeof(struct caam_hash_ctx) + + sizeof(struct caam_hash_state), }, }, .alg_type = OP_ALG_ALGSEL_SHA512, @@ -1710,6 +1756,8 @@ static struct caam_hash_template driver_hash[] = { .setkey = ahash_setkey, .halg = { .digestsize = MD5_DIGEST_SIZE, + .statesize = sizeof(struct caam_hash_ctx) + + sizeof(struct caam_hash_state), }, }, .alg_type = OP_ALG_ALGSEL_MD5, @@ -1796,6 +1844,12 @@ static void caam_hash_cra_exit(struct crypto_tfm *tfm) dma_unmap_single(ctx->jrdev, ctx->sh_desc_finup_dma, desc_bytes(ctx->sh_desc_finup), DMA_TO_DEVICE); + kfree(ctx->sh_desc_update); + kfree(ctx->sh_desc_update_first); + kfree(ctx->sh_desc_fin); + kfree(ctx->sh_desc_digest); + kfree(ctx->sh_desc_finup); + caam_jr_free(ctx->jrdev); }