From patchwork Fri Sep 21 20:13:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonard Crestez X-Patchwork-Id: 10610915 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8062514BD for ; Fri, 21 Sep 2018 20:14:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6E2D32D90C for ; Fri, 21 Sep 2018 20:14:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6BFD82D91A; Fri, 21 Sep 2018 20:14:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 94F612E6FC for ; Fri, 21 Sep 2018 20:14:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391243AbeIVCE3 (ORCPT ); Fri, 21 Sep 2018 22:04:29 -0400 Received: from mail-eopbgr30065.outbound.protection.outlook.com ([40.107.3.65]:23266 "EHLO EUR03-AM5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2391089AbeIVCE3 (ORCPT ); Fri, 21 Sep 2018 22:04:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=24O4j4s/+vhdfU9gGtA7B5z82u+ONm1OMka1hzDc1lQ=; b=xiA0vMJijkGDaIZ+xwk1RFfN1ahClgC2Hu7UGUQ4RksDQoYq1Qu009AMe3IbGYA0W2knQY+16g6fh/sigO8BpUopr9SZmlLrl0Z7qkqw/wxahCOQwtBk0fiM5mb589CD8x+HqxX9w4uHk3eO9wFhPAhOGc39ymju0U2mTf9BTLU= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=leonard.crestez@nxp.com; Received: from localhost.localdomain (95.76.156.53) by AM6PR04MB4293.eurprd04.prod.outlook.com (2603:10a6:209:4f::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1143.17; Fri, 21 Sep 2018 20:13:57 +0000 From: Leonard Crestez To: Fabio Estevam , Marek Vasut Cc: =?utf-8?q?Horia_Geant=C4=83?= , Franck LENORMAND , Herbert Xu , Kamil Konieczny , "David S . Miller " , linux-crypto@vger.kernel.org, Dan Douglass Subject: [RFC] crypto: mxs-dcp - Implement sha import/export Date: Fri, 21 Sep 2018 23:13:26 +0300 Message-Id: <704b9d1dff075d2afbe08743492b303ac24d2ca1.1537558970.git.leonard.crestez@nxp.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [95.76.156.53] X-ClientProxiedBy: VI1P195CA0081.EURP195.PROD.OUTLOOK.COM (2603:10a6:802:59::34) To AM6PR04MB4293.eurprd04.prod.outlook.com (2603:10a6:209:4f::31) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b8766dd8-20f7-4ab5-701d-08d61ffec37c X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989299)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020);SRVR:AM6PR04MB4293; X-Microsoft-Exchange-Diagnostics: 1;AM6PR04MB4293;3:h/guIxd+D3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qnXH+kfVRc3OdsAnHmGjgR4w+WNhci0XiWRR/hn3BElLa2AGUcjOJhSfCEChhxdx9YRDGnlUUBboB86EcfdXUYu5F3ZAgY0JlcGLP6iOVurFgKjff5THh0sZvmSHgk8k0Nq5VIM4xkp3uREx27CnNTch0O/WacYeksgIAqwcVedG6Ruq+S8eF9wkFmiFjD5vN6bHAOxLZw+CuDNAuDycgFZFw3X+aFVP+gUQs/POwI6DbizVLowHPYteA2YsimbcdE2XIdgqiJbJD1kMFDILF8f1nDjXWCEFYLeaqQ1j+itEuHXmfcA9K2e2rTtdAIPMYVq;4:FKahNic128Me+mu3hhmLakl+V8Q4R2mNpzqm3TLM8Y1Z31txsES/BYxj7UkfWXlZM0cS+rXMe6UtmTMSZJqeX4IDdqvQmcXXYkD4JpKwo8WZgqE/rtdoQw7ZTztS5VRkYob6K++nguqqs8c3RbhMZeRqaSURB48gu1zuWhP4h75/s19NcL38Qed1M3hTC2LJO8E4pgnSrpkJVfPOZUWWLmmw3aqz8o2reVNAdd46vtUZtZHWyxL9qd/CqtnvqwCJGaFQ7nRlF9kkJnWFIq2RAbHOYXupmv0dVtZg/x5u/QISdIrtVwUwHp503QMKrcrJu9wrBBnz0v4miaeSK9PfroFsbhHk3YE8MzPBL4DGy98= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(166708455590820)(185117386973197); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(10201501046)(3002001)(3231355)(944501410)(52105095)(93006095)(93001095)(6055026)(149027)(150027)(6041310)(20161123560045)(20161123562045)(20161123558120)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699051);SRVR:AM6PR04MB4293;BCL:0;PCL:0;RULEID:;SRVR:AM6PR04MB4293; X-Forefront-PRVS: 0802ADD973 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(6069001)(366004)(346002)(136003)(396003)(39860400002)(376002)(189003)(199004)(316002)(16586007)(14444005)(36756003)(48376002)(54906003)(69590400006)(5660300001)(110136005)(26005)(478600001)(6506007)(386003)(7736002)(966005)(44832011)(52116002)(486006)(51416003)(97736004)(50226002)(66066001)(3846002)(39060400002)(81166006)(4326008)(81156014)(6486002)(6306002)(6512007)(68736007)(106356001)(47776003)(476003)(956004)(2616005)(6666003)(305945005)(16526019)(118296001)(53936002)(8676002)(50466002)(25786009)(6116002)(86362001)(2906002)(8936002)(105586002);DIR:OUT;SFP:1101;SCL:1;SRVR:AM6PR04MB4293;H:localhost.localdomain;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; Received-SPF: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: 1;AM6PR04MB4293;23:fUdt6DK+zMIxxBDhD176tjwOD44z/C0NtmneB7jrzP31NV/PQqt0sOAfKkcxB7YLBi0o6Js3STzBBkOEkVv8152pIOcKsPamyCX0LRl9nrAkrvhlkuAUuBBBxT5ey480Fc7QTPJzJ1zSInZ0I0NDSoTtuFLIBwAGb6gR4ae0IQYlPVwJHiSQs9TuIb5pn61AcG/R1JR/uyKvbZuxyUcrmHn9xHBlNxbsPlfaN6QELd2mF9mrIcNYRxbFaMYOAgBx0Gl657+OTBc4m7BYrMX7ynJY8DGGFxOk3PRpafLRPTkoFm26NNbbsM6LJhE+UqI/74kL3DtYCTmXAFY00/WVNxhzvdPZRYp2Vmkre4ASm4S6G8NvXtYHGv2n+UPPkxfSP8ewIHhBINmAnReiUZZ/m/EWgBT801oEabDmnr204N19zMaHpX9O80xfPaxfhNDz/pE6YWAIT44MwwLxUVf+4Fj+SAvx6nRg48PAqbKJ4EnEtrjuD8Qg3uOJ6zLX+/iREv87xmwjl3po6eK5iu4Zxpu100LYC2MthouqyLJq+I4B4pcjR2O11MMFJum0oOyp7Fwn0ryH4XskE7MuLAgb6xNge0DrYv/OKWPWuAL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Diagnostics: 1;AM6PR04MB4293;6:0n3EHGzcGGLHSjmaQc72hwkXEebWTbootDCdpIUBA11UHBSrlv4ZxslvFiTwarKinRyzf5wSlDKQEabjaCFu0Osvr04Kw08wAlBUrCiMs53WrP+FJiRKOCu5NeZ/SDZdjIqkk6onBgEO8FUNtzkhT6qUt7XidyQBdAGQZPWipU8SpDkXvMdiAXdM/2nUdY64iQ76vqAx9EOebQTfz7RGwdYLhpnlVJkLDEIjm4Zw2lc1mPQVc+cqMXOYQvOsCGQ7lCYubwiusIbTR/oqbjif2JQ0msdiqsSuRk+6m3iGqrr74NY6/wFmP1gRkYZnfkyOfIc5G9RtSAYl5Ubke+tHSwoA9pdXN+eHPFN4b/+DsCL8iNA2aSn+uT4Ak3OTEDkJQKz5U7aDlrCU4hGrxE6WMKTC90kfQTudGZaBA2885a2Ld8GfIseL8hhFQYTMm4uO7whbA/QVmqHNTzIfbT7XZw==;5:IJp7wkerUKRAlfq+nFrGN231m0tu8z0UVPgvS3NdR9/G7XIwa+PwIZbj8abowtvtfkpERrwH1aePOWpx++t5rr4UswoAmhjlxpYDL2Hp0ZbSJp/MFDXJGvOzwTQg22GlFP/tCjfz/nvDaYRXPYPFvpUjtvLk5RFWfjS6CG/WLT0=;7:vYmfqUZdDonSH+g9c7sa5qRX8qRvB5TV6/cjWK0L9DUPJNldJ3+eqZizA5KMxC4Bm7xk3/+KVsN2TwDlbhxz9hqSaG8gYyOFGamUj6vHinFHzXNRjWuxkWr/f+UhGEF/w43us4v2JP38jnT2R6HVYFy/x9B20S29Jok7XAeqEyyoBK7a5P02A/jQZ5qZxaevF0EezcNvCKi1TiP5PFUCykZvWhSiT4CjRQNZ7tjEcvmNP9n7ZnX8YpIo2qGfrJcy SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2018 20:13:57.5246 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b8766dd8-20f7-4ab5-701d-08d61ffec37c X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR04MB4293 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The mxs-dcp driver fails to probe if sha1/sha256 are supported: [ 2.455404] mxs-dcp 80028000.dcp: Failed to register sha1 hash! [ 2.464042] mxs-dcp: probe of 80028000.dcp failed with error -22 This happens because since commit 8996eafdcbad ("crypto: ahash - ensure statesize is non-zero") import/export is mandatory and ahash_prepare_alg fails on statesize == 0. A set of dummy import/export functions were implemented in commit 9190b6fd5db9 ("crypto: mxs-dcp - Add empty hash export and import") but statesize is still zero and the driver fails to probe. That change was apparently part of some unrelated refactoring. Fix by actually implementing import/export. Signed-off-by: Dan Douglass Signed-off-by: Leonard Crestez --- drivers/crypto/mxs-dcp.c | 41 ++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) Patch is from NXP internal tree with minor adaptations, I can't vouch for correctness. This only fixes probing, *TESTS DO NOT PASS* without additional fixes dealing with HW limitations. A branch that gets tcrypt to pass can be found here: https://github.com/cdleonard/linux/commits/crypto_mxsdcp I don't know if patches that make crypto drivers half-work are acceptable, it can be argued that it's better to fail on probe and fallback to software than to give incorrect results. I'm posting this mostly because it was requested by Fabio. diff --git a/drivers/crypto/mxs-dcp.c b/drivers/crypto/mxs-dcp.c index 3768f6fb92d5..5555b284a59d 100644 --- a/drivers/crypto/mxs-dcp.c +++ b/drivers/crypto/mxs-dcp.c @@ -99,10 +99,15 @@ struct dcp_aes_req_ctx { struct dcp_sha_req_ctx { unsigned int init:1; unsigned int fini:1; }; +struct dcp_export_state { + struct dcp_sha_req_ctx req_ctx; + struct dcp_async_ctx async_ctx; +}; + /* * There can even be only one instance of the MXS DCP due to the * design of Linux Crypto API. */ static struct dcp *global_sdcp; @@ -759,18 +764,36 @@ static int dcp_sha_digest(struct ahash_request *req) return ret; return dcp_sha_finup(req); } -static int dcp_sha_noimport(struct ahash_request *req, const void *in) +static int dcp_sha_import(struct ahash_request *req, const void *in) { - return -ENOSYS; + struct dcp_sha_req_ctx *rctx = ahash_request_ctx(req); + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); + struct dcp_async_ctx *actx = crypto_ahash_ctx(tfm); + const struct dcp_export_state *export = in; + + memset(rctx, 0, sizeof(struct dcp_sha_req_ctx)); + memset(actx, 0, sizeof(struct dcp_async_ctx)); + memcpy(rctx, &export->req_ctx, sizeof(struct dcp_sha_req_ctx)); + memcpy(actx, &export->async_ctx, sizeof(struct dcp_async_ctx)); + + return 0; } -static int dcp_sha_noexport(struct ahash_request *req, void *out) +static int dcp_sha_export(struct ahash_request *req, void *out) { - return -ENOSYS; + struct dcp_sha_req_ctx *rctx_state = ahash_request_ctx(req); + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); + struct dcp_async_ctx *actx_state = crypto_ahash_ctx(tfm); + struct dcp_export_state *export = out; + + memcpy(&export->req_ctx, rctx_state, sizeof(struct dcp_sha_req_ctx)); + memcpy(&export->async_ctx, actx_state, sizeof(struct dcp_async_ctx)); + + return 0; } static int dcp_sha_cra_init(struct crypto_tfm *tfm) { crypto_ahash_set_reqsize(__crypto_ahash_cast(tfm), @@ -839,14 +862,15 @@ static struct ahash_alg dcp_sha1_alg = { .init = dcp_sha_init, .update = dcp_sha_update, .final = dcp_sha_final, .finup = dcp_sha_finup, .digest = dcp_sha_digest, - .import = dcp_sha_noimport, - .export = dcp_sha_noexport, + .import = dcp_sha_import, + .export = dcp_sha_export, .halg = { .digestsize = SHA1_DIGEST_SIZE, + .statesize = sizeof(struct dcp_export_state), .base = { .cra_name = "sha1", .cra_driver_name = "sha1-dcp", .cra_priority = 400, .cra_alignmask = 63, @@ -865,14 +889,15 @@ static struct ahash_alg dcp_sha256_alg = { .init = dcp_sha_init, .update = dcp_sha_update, .final = dcp_sha_final, .finup = dcp_sha_finup, .digest = dcp_sha_digest, - .import = dcp_sha_noimport, - .export = dcp_sha_noexport, + .import = dcp_sha_import, + .export = dcp_sha_export, .halg = { .digestsize = SHA256_DIGEST_SIZE, + .statesize = sizeof(struct dcp_export_state), .base = { .cra_name = "sha256", .cra_driver_name = "sha256-dcp", .cra_priority = 400, .cra_alignmask = 63,