From patchwork Wed Mar 15 18:20:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gary R Hook X-Patchwork-Id: 9626389 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.web.codeaurora.org (Postfix) with ESMTP id 056156048C for ; Wed, 15 Mar 2017 18:25:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EDC2828629 for ; Wed, 15 Mar 2017 18:25:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E032A2864D; Wed, 15 Mar 2017 18:25:02 +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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 AE7FD28629 for ; Wed, 15 Mar 2017 18:25:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753112AbdCOSXX (ORCPT ); Wed, 15 Mar 2017 14:23:23 -0400 Received: from mail-by2nam03on0083.outbound.protection.outlook.com ([104.47.42.83]:7593 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753536AbdCOSWT (ORCPT ); Wed, 15 Mar 2017 14:22:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=GEvFk6iUCp+ALPuTVbUJl/0+T7tcvo2smEAPr01jObo=; b=ykOcITqlme5mxfmEdj82DGWwmb6NIiY6aQlZ3c80FJIqJ0SLCXAtZqstjdhUyxWuIUjo1RR+uqHTx9jajfxm+0xb0xFACwlBgd0Ivb64vVf9+yv6zS9pHWa8l+8lXcPsM5Hzqsq9/IyBMnr+NQT2+2IWISmkePnztioEtXhAMKI= Authentication-Results: amd.com; dkim=none (message not signed) header.d=none;amd.com; dmarc=none action=none header.from=amd.com; Received: from [10.236.19.42] (165.204.77.1) by CY1PR12MB0476.namprd12.prod.outlook.com (10.163.91.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.977.11; Wed, 15 Mar 2017 18:20:51 +0000 Subject: [PATCH V3 1/3] crypto: ccp - Add SHA-2 384- and 512-bit support From: Gary R Hook To: CC: , , , Date: Wed, 15 Mar 2017 13:20:43 -0500 Message-ID: <20170315182043.29335.23961.stgit@taos> In-Reply-To: <20170315182014.29335.93268.stgit@taos> References: <20170315182014.29335.93268.stgit@taos> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: MWHPR13CA0005.namprd13.prod.outlook.com (10.169.208.15) To CY1PR12MB0476.namprd12.prod.outlook.com (10.163.91.30) X-MS-Office365-Filtering-Correlation-Id: 75c0cbb2-4fe8-4b54-fd45-08d46bd00396 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081); SRVR:CY1PR12MB0476; X-Microsoft-Exchange-Diagnostics: 1; CY1PR12MB0476; 3:mjoW3uxxNp+hUqII4IHXovSxkdag8lGBkaUkFd+qhbXdEkiqGM4PQ/NCew3XdulhJ3J76BxaURW1r6H1eOaVuiT8Ck5bMPY2vVVKT0uIv8M9gFdNzxh5vgJfTWah7436vOUYyY+lk4/MsU0Mkamddl7zev+K19ZgGsZYZHzi/w/2LjZ/S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FlTgoKluVMzFjej6gXT/U/RcstbuKsB9cHHxf1V1Pbc9llcudS9wIeQfezdkm9jbYO44fFxMc7urNMjoue9xE6FQiRg13nrlqzjBSLuH+NxxCywVrxmF6wDVVlkY0Av3EIvgHvI1hR+Y6qzulD4N47gABT5Ody9bi5FOIQlrcUf+YpLl9QYzbwNxtrVPR4q9I/ULvH1C+RRtqW+fokdQp+WM1KuNaD5QR+3fEFWuyf1f9hRWdXVNO9pu95Gu/tX39xhQon/OPEk9jdCYqwACfYfVv2FdVxe081QUsvbcvZ718g5Uvy1 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6055026)(6041248)(20161123564025)(20161123562025)(20161123560025)(20161123558025)(20161123555025)(6072148); SRVR:CY1PR12MB0476; BCL:0; PCL:0; RULEID:; SRVR:CY1PR12MB0476; X-Microsoft-Exchange-Diagnostics: 1; CY1PR12MB0476; 4:hjMCNNH9kic3L0HkcOXdtB1fCyoM4hOU7IcPVysPCmPO7hgF3GpjkCXE7hR6s1k4J83QKn7NK0WZXBOfzqoJeyQiUNxOWvreRPYRRqhaKMMTA84fvEX+mDg0Dv7zyg3fpgcPtSD4oo+GNGdYpolcSDTXNqUW6cTMLpgED0qbxSyFEKvjN2f9RckoXgNCRvSoTewIs/gbi5ceDK+BadcfJyuPN5QPCMmislnoN4fdxBMqxLP4Cm2Fna2h0yNwTshKE1Cf3K4JkPK3JIdj0Y3cQxj01rB+TkZ32ya6smpUi68W2YmRJLnrqfhFq+xv0Sr2qi3V1yjc1F4fV3/NZPi+evF2QBplUH2uzejH2YbVQnoXo6qduyeEsoOUuZql09/w+t9iDckvbdr3L4WIAjE0Ww1AWhZLtO8T9pGAiIOzKioZmBUXg+9gnSOE3wCJWCyQgvLV/Q7Ij7UU2PpTr3tHS0msEKC9fSVwEitC6F3PZGT5eGbs00iXFv0RW142Lcu3CLlMAoaloFpe0WWbi5wuoo478Cy6miC4bE0OZraxcW3app9w9IxxYQJ72XgGqWhx6jhVG6oiUb1jFqFNDvpzdMlSarePXj3mR7JZ4Ywul0FVLolvojvmWaSUfg/TQB1PxygKxTZUUho6pV1q2gQ86510Og/FyTyVHArBql60LYg= X-Forefront-PRVS: 02475B2A01 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6049001)(6009001)(39450400003)(39860400002)(39850400002)(39410400002)(9686003)(53936002)(8676002)(33646002)(81166006)(2351001)(54356999)(305945005)(42186005)(4326008)(7736002)(76176999)(66066001)(50986999)(47776003)(2950100002)(6916009)(110136004)(38730400002)(103116003)(5660300001)(3846002)(6666003)(97746001)(189998001)(83506001)(4001350100001)(2906002)(23676002)(230700001)(1076002)(54906002)(6486002)(50466002)(77096006)(25786008)(86362001)(6116002)(33716001); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR12MB0476; H:[10.236.19.42]; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtDWTFQUjEyTUIwNDc2OzIzOnBKNzJyNnF4eFg0V1hGT2xjREo5eDhoanJw?= =?utf-8?B?RnJBb0tYbEJoTGVvZXhQZklQb0JMQ2ltNVZPdU5OVTNhWEY1c1hVTzNDeTBa?= =?utf-8?B?U2tVOGo0R0lPZGJ6VWZRbWlpNUxDTnJYUE5yNndJSXVNZGM2OEIwTU9uWlh2?= =?utf-8?B?TUJ2VHBtN0QrZGVQais2ZXRjS2pmWVBCZFNRd09SRDNFVTE5VVBRQTY0Zmh3?= =?utf-8?B?UjVCdGNJK3JNY3FkTXo0V2ErSGhneksvQ0Zza0dBcnFqdVlkTTZqNnArcGdB?= =?utf-8?B?VGh3Q0NqRlUzT2JJeUIxblJYRFNQYThqQzBzTUpSNG5Zc3A0UytyNlhvcCs3?= =?utf-8?B?a0hlWVVvd0p5N0h0K2IvSHRVaiswY0Uwb2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afEvg= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CY1PR12MB0476; 7:FWoAZoms7Ve3M1kCOqfmM3KXrA0AZctagLAppLvJg0N9fJigWigLphgGoi4sSqYNG7xJorlem7p6aVo9bb3XaoDlrEY7kvJXafOK8SWEjQdtVv8jsnZD7UvWPYoSZSpcjWRDSUqxCKrIXHa8Mesx/qxTP6H4awYlpRKqUrE0HSou76WCR5DubW+83HFis+NaK9DMldoJDAb3iWQ9xK73XAF7Bbf/VVYQMtlZbrOXDhRnSFrCEOx8SxnckRkovNSo6P/VTkd0Q09tGcG2x5vsuYqZkf2mP/XBJHCpimnZha2po5wfKT2cNjR5aIJmq4KehGITc5r8oWxvP1a9jIvPfA==; 20:PjkTsmRLtSwbupeD5FZIJrVPP4hzM0h3trFX+ixWbd5SSu77ysnwxd1MUnoK9MrmIOP8gPAsClKhWMavW6OkiECv2KrFS7I1AxHIwXVKKiCitPjHtibbmtEkDyBZScGPtK6QVkX/wYecQxpyd89f1BzIJc9UJYv+BFSgEgXo1cn2y10Fh7LG68xiR4zcvqMS+hhUkPr2PJ/ASOvr0yAfqdXsP4zGLvgNozjc9z++95u5IzvkSQ5F0coxucAaRE5g X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Mar 2017 18:20:51.8522 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR12MB0476 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 Incorporate 384-bit and 512-bit hashing for a version 5 CCP device Signed-off-by: Gary R Hook --- drivers/crypto/ccp/ccp-crypto-sha.c | 22 +++++++++++ drivers/crypto/ccp/ccp-crypto.h | 8 ++-- drivers/crypto/ccp/ccp-ops.c | 72 +++++++++++++++++++++++++++++++++++ include/linux/ccp.h | 2 + 4 files changed, 101 insertions(+), 3 deletions(-) diff --git a/drivers/crypto/ccp/ccp-crypto-sha.c b/drivers/crypto/ccp/ccp-crypto-sha.c index 84a652b..6b46eea 100644 --- a/drivers/crypto/ccp/ccp-crypto-sha.c +++ b/drivers/crypto/ccp/ccp-crypto-sha.c @@ -146,6 +146,12 @@ static int ccp_do_sha_update(struct ahash_request *req, unsigned int nbytes, case CCP_SHA_TYPE_256: rctx->cmd.u.sha.ctx_len = SHA256_DIGEST_SIZE; break; + case CCP_SHA_TYPE_384: + rctx->cmd.u.sha.ctx_len = SHA384_DIGEST_SIZE; + break; + case CCP_SHA_TYPE_512: + rctx->cmd.u.sha.ctx_len = SHA512_DIGEST_SIZE; + break; default: /* Should never get here */ break; @@ -393,6 +399,22 @@ struct ccp_sha_def { .digest_size = SHA256_DIGEST_SIZE, .block_size = SHA256_BLOCK_SIZE, }, + { + .version = CCP_VERSION(5, 0), + .name = "sha384", + .drv_name = "sha384-ccp", + .type = CCP_SHA_TYPE_384, + .digest_size = SHA384_DIGEST_SIZE, + .block_size = SHA384_BLOCK_SIZE, + }, + { + .version = CCP_VERSION(5, 0), + .name = "sha512", + .drv_name = "sha512-ccp", + .type = CCP_SHA_TYPE_512, + .digest_size = SHA512_DIGEST_SIZE, + .block_size = SHA512_BLOCK_SIZE, + }, }; static int ccp_register_hmac_alg(struct list_head *head, diff --git a/drivers/crypto/ccp/ccp-crypto.h b/drivers/crypto/ccp/ccp-crypto.h index 8335b32..95cce27 100644 --- a/drivers/crypto/ccp/ccp-crypto.h +++ b/drivers/crypto/ccp/ccp-crypto.h @@ -137,9 +137,11 @@ struct ccp_aes_cmac_exp_ctx { u8 buf[AES_BLOCK_SIZE]; }; -/***** SHA related defines *****/ -#define MAX_SHA_CONTEXT_SIZE SHA256_DIGEST_SIZE -#define MAX_SHA_BLOCK_SIZE SHA256_BLOCK_SIZE +/* SHA-related defines + * These values must be large enough to accommodate any variant + */ +#define MAX_SHA_CONTEXT_SIZE SHA512_DIGEST_SIZE +#define MAX_SHA_BLOCK_SIZE SHA512_BLOCK_SIZE struct ccp_sha_ctx { struct scatterlist opad_sg; diff --git a/drivers/crypto/ccp/ccp-ops.c b/drivers/crypto/ccp/ccp-ops.c index f1396c3..0d82080 100644 --- a/drivers/crypto/ccp/ccp-ops.c +++ b/drivers/crypto/ccp/ccp-ops.c @@ -41,6 +41,20 @@ cpu_to_be32(SHA256_H6), cpu_to_be32(SHA256_H7), }; +static const __be64 ccp_sha384_init[SHA512_DIGEST_SIZE / sizeof(__be64)] = { + cpu_to_be64(SHA384_H0), cpu_to_be64(SHA384_H1), + cpu_to_be64(SHA384_H2), cpu_to_be64(SHA384_H3), + cpu_to_be64(SHA384_H4), cpu_to_be64(SHA384_H5), + cpu_to_be64(SHA384_H6), cpu_to_be64(SHA384_H7), +}; + +static const __be64 ccp_sha512_init[SHA512_DIGEST_SIZE / sizeof(__be64)] = { + cpu_to_be64(SHA512_H0), cpu_to_be64(SHA512_H1), + cpu_to_be64(SHA512_H2), cpu_to_be64(SHA512_H3), + cpu_to_be64(SHA512_H4), cpu_to_be64(SHA512_H5), + cpu_to_be64(SHA512_H6), cpu_to_be64(SHA512_H7), +}; + #define CCP_NEW_JOBID(ccp) ((ccp->vdata->version == CCP_VERSION(3, 0)) ? \ ccp_gen_jobid(ccp) : 0) @@ -955,6 +969,18 @@ static int ccp_run_sha_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) return -EINVAL; block_size = SHA256_BLOCK_SIZE; break; + case CCP_SHA_TYPE_384: + if (cmd_q->ccp->vdata->version < CCP_VERSION(4, 0) + || sha->ctx_len < SHA384_DIGEST_SIZE) + return -EINVAL; + block_size = SHA384_BLOCK_SIZE; + break; + case CCP_SHA_TYPE_512: + if (cmd_q->ccp->vdata->version < CCP_VERSION(4, 0) + || sha->ctx_len < SHA512_DIGEST_SIZE) + return -EINVAL; + block_size = SHA512_BLOCK_SIZE; + break; default: return -EINVAL; } @@ -1042,6 +1068,21 @@ static int ccp_run_sha_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) sb_count = 1; ooffset = ioffset = 0; break; + case CCP_SHA_TYPE_384: + digest_size = SHA384_DIGEST_SIZE; + init = (void *) ccp_sha384_init; + ctx_size = SHA512_DIGEST_SIZE; + sb_count = 2; + ioffset = 0; + ooffset = 2 * CCP_SB_BYTES - SHA384_DIGEST_SIZE; + break; + case CCP_SHA_TYPE_512: + digest_size = SHA512_DIGEST_SIZE; + init = (void *) ccp_sha512_init; + ctx_size = SHA512_DIGEST_SIZE; + sb_count = 2; + ooffset = ioffset = 0; + break; default: ret = -EINVAL; goto e_data; @@ -1060,6 +1101,11 @@ static int ccp_run_sha_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) op.u.sha.type = sha->type; op.u.sha.msg_bits = sha->msg_bits; + /* For SHA1/224/256 the context fits in a single (32-byte) SB entry; + * SHA384/512 require 2 adjacent SB slots, with the right half in the + * first slot, and the left half in the second. Each portion must then + * be in little endian format: use the 256-bit byte swap option. + */ ret = ccp_init_dm_workarea(&ctx, cmd_q, sb_count * CCP_SB_BYTES, DMA_BIDIRECTIONAL); if (ret) @@ -1071,6 +1117,13 @@ static int ccp_run_sha_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) case CCP_SHA_TYPE_256: memcpy(ctx.address + ioffset, init, ctx_size); break; + case CCP_SHA_TYPE_384: + case CCP_SHA_TYPE_512: + memcpy(ctx.address + ctx_size / 2, init, + ctx_size / 2); + memcpy(ctx.address, init + ctx_size / 2, + ctx_size / 2); + break; default: ret = -EINVAL; goto e_ctx; @@ -1137,6 +1190,15 @@ static int ccp_run_sha_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) sha->ctx, 0, digest_size); break; + case CCP_SHA_TYPE_384: + case CCP_SHA_TYPE_512: + ccp_get_dm_area(&ctx, 0, + sha->ctx, LSB_ITEM_SIZE - ooffset, + LSB_ITEM_SIZE); + ccp_get_dm_area(&ctx, LSB_ITEM_SIZE + ooffset, + sha->ctx, 0, + LSB_ITEM_SIZE - ooffset); + break; default: ret = -EINVAL; goto e_ctx; @@ -1174,6 +1236,16 @@ static int ccp_run_sha_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) ctx.address + ooffset, digest_size); break; + case CCP_SHA_TYPE_384: + case CCP_SHA_TYPE_512: + memcpy(hmac_buf + block_size, + ctx.address + LSB_ITEM_SIZE + ooffset, + LSB_ITEM_SIZE); + memcpy(hmac_buf + block_size + + (LSB_ITEM_SIZE - ooffset), + ctx.address, + LSB_ITEM_SIZE); + break; default: ret = -EINVAL; goto e_ctx; diff --git a/include/linux/ccp.h b/include/linux/ccp.h index c71dd8f..90a1fbe 100644 --- a/include/linux/ccp.h +++ b/include/linux/ccp.h @@ -249,6 +249,8 @@ enum ccp_sha_type { CCP_SHA_TYPE_1 = 1, CCP_SHA_TYPE_224, CCP_SHA_TYPE_256, + CCP_SHA_TYPE_384, + CCP_SHA_TYPE_512, CCP_SHA_TYPE__LAST, };