From patchwork Fri Nov 4 16:04:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gary R Hook X-Patchwork-Id: 9412769 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 482C86022E for ; Fri, 4 Nov 2016 16:04:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3921D2B189 for ; Fri, 4 Nov 2016 16:04:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2E2CB2B1BC; Fri, 4 Nov 2016 16:04:19 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 50A452B189 for ; Fri, 4 Nov 2016 16:04:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935091AbcKDQER (ORCPT ); Fri, 4 Nov 2016 12:04:17 -0400 Received: from mail-bl2nam02on0077.outbound.protection.outlook.com ([104.47.38.77]:40672 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S935059AbcKDQEQ (ORCPT ); Fri, 4 Nov 2016 12:04:16 -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=ekLSEYEkUyVowm/6V2f4fWtAUv15+0Q3db2AzoaybEQ=; b=dJ8JXdqhtdh/JPWcUV3KT8pCqcfPBR+uYR5MhGCmZebGeCd3XCVaePJwRpnMiqy4BKlDOtj6pFvA3o4lXxciY7RDuXlRCq9X02q46aY88Ig4D9a37FWVZRn3Kzn6cQSIXijiXuGNp/yrSwI9rOrU9pr1t9frlkwetJESfEApVcE= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Gary.Hook@amd.com; Received: from [10.236.19.42] (165.204.77.1) by CY4PR12MB1397.namprd12.prod.outlook.com (10.168.169.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.707.6; Fri, 4 Nov 2016 16:04:14 +0000 Subject: [PATCH V2 4/9] crypto: ccp - Add SHA-2 support From: Gary R Hook To: CC: , , Date: Fri, 4 Nov 2016 11:04:02 -0500 Message-ID: <20161104160402.18155.50066.stgit@taos> In-Reply-To: <20161104160140.18155.75618.stgit@taos> References: <20161104160140.18155.75618.stgit@taos> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: BN6PR17CA0033.namprd17.prod.outlook.com (10.175.189.19) To CY4PR12MB1397.namprd12.prod.outlook.com (10.168.169.18) X-MS-Office365-Filtering-Correlation-Id: 7c245dfc-14c7-441d-d39c-08d404cc3936 X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1397; 2:+uNFH27/h0olEajdj6cXuqZf4TaPjXsLlXGgVi1mdSUhzolIgb9o4wcycKw4iUTF/5WSVlUCAjsaW29ka9q8+59WgAMS94zVz/s9eLRgRj5nHq43m4LuuMXpQVECgRO8fM4RmxD/t/lCktC7KogkOPIrUaYrEebymwVcuqdOUmYXCoJjn0+AImKiAUCt/wvUrbdVlnuOhWzQWJVYMTbsBg==; 3:IFyQ+h92Xa65QsPkf9ia1H4GrZyytHAzjjGUgeGSqusSUmc+a7t4TBql0wWk3HQUih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hIlIJBIOQDiGsdWjVUcJryOvbHo2Ep582DwA90ENsqkUD9HGHru6g3nJ1kyXUiJOvqdcoydAYB2pY8Jcw26CCOS03jxrHvNgifrWYf1JGlMt9dc7+A3Fd59QpPGOfC+/Ha0/wTOE3azuh/AETEgANrNI9a4vZ0p7N8LEHF4Zavzz/n0fQU3LHHpZiKjy6uQwvpcDnVBSHQU8/i+W5UI9uv8o3THRTUwBgJxPlXNJVk4gxSIrgS/Rc8L4eGw8cx+DVW84Pm9B5ciTGGsznoi/3GL07PkQWEQZHKG7UWz9vEvxJgD X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6055026); SRVR:CY4PR12MB1397; BCL:0; PCL:0; RULEID:; SRVR:CY4PR12MB1397; X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1397; 4:rEIndbr2ujTOnSvaqvMXSmBuZTZWZ/mcr5ZJYw8FzR4YVH0Lyqt2vnzjKhqwE6ke1mcV7lyndxhogN92wrcmKuPhDbWhuOc1uKQXfbHnMryYAyyPklC+rJMIN2TDqqCrPT4LBjLociUKd3/6TXySsZ6ElrorFK5Qzy82jZVco9ht+MxORqHfETHRITtwKDwUtjWYF1BzB9iKItfZH2LO7esgEM4EDcy3bH1zM/Hn+gFEXPrHYTCRtcQw5uOH3rOLca+Ur8OpauJeDXF/fx2PRY1G+NIemNGM3FfSuLFisnJmyyxtGQFtVgYWHSSCaLaC76DlG6StP6afnxHnGc/aCALxnDzXkVwfebSUVWi6414ros2x8sxWbDdXNB74rT9k2t9nOSH/cS5wCLxzMd9d/EP8LEBKjcxinbD3AGHc2qJOkiVEc9yHP1liT0iIIWEsMwmeQkDIb1uf6govIHbMCQ== X-Forefront-PRVS: 01165471DB X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6049001)(6009001)(7916002)(189002)(199003)(50986999)(76176999)(229853001)(2906002)(2351001)(19580405001)(47776003)(66066001)(230700001)(92566002)(19580395003)(81156014)(8676002)(7846002)(7736002)(54356999)(106356001)(81166006)(305945005)(83506001)(42186005)(4326007)(105586002)(1076002)(4001350100001)(97736004)(33716001)(77096005)(5660300001)(101416001)(68736007)(6116002)(586003)(86362001)(33646002)(50466002)(3846002)(189998001)(9686002)(97746001)(23676002)(6916009)(6666003)(110136003)(103116003)(2950100002); DIR:OUT; SFP:1101; SCL:1; SRVR:CY4PR12MB1397; H:[10.236.19.42]; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtDWTRQUjEyTUIxMzk3OzIzOmpSME5IdHg0UzdhTm4rVFptd2VQenVGdmlt?= =?utf-8?B?UEM2MGZWcnFkTU5paVJpWnBBc2NaajZFWTloTmhnaEc4U3AzSm5qbjNnL3V1?= =?utf-8?B?QXBXeEJHTmZBajNvTXdCQ25xd25ZWkJac0RobTFlSDZnY3ZBRTV1M2kzdlps?= =?utf-8?B?V2RPUytaNDNZU1dSbWF1b2RyZlVxOE5JTElwRkk1NE9HN3hEWElleVZHYXNx?= =?utf-8?B?Ym9aOFBvWmdqdEd0amdmbFBpdDJHRDhQT1JhWEVDTW40ZHN0Y3VNa2p5Mldh?= =?utf-8?B?c1doUXFaaU40bklXbVhFMzBRb2tJUWh1MDRFc2s5M2ZXZlMzV2E0dFpINEpt?= =?utf-8?B?djlzT3VNSWljMU9GOWkyNHpiNFRjcGs1UXNLcmc5TDJpcm8rQUNuT1JPaXFI?= =?utf-8?B?QWk4M0hXbnhLZldsVGJOWHp4MHBDVVk1OElpVDVZaUQ2RVhhakhvMlNvNUZB?= =?utf-8?B?eENlaHhKYTRaN0dyZUwyeVBQRGM2UUhOdkJ2bGtYSjRHU0o2ejFmMks4Uzhl?= =?utf-8?B?c0VNOFlY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-Diagnostics: 1; CY4PR12MB1397; 7:bR1RgfLP/GUqJTLCZ53lTG23xP0kwlWpEJEMjhLi8cs3196q0bt3NzDPrbZ0gxL106r7/5Jviuj+EQBmqJrXs/Tx3TPUfTPubJKCypbt9PlBQ0we4iA9xvbwwcaVtuJ+/gesQNtIL2xhR/NteP3YJYi/hkxUA6YzOYlAZQHZosYqr6zX7enk3RHxrZMEhsYWH8/JYwsMv2YHx3wDzDjlQrh46oDw51FcvBEoS+gHFEgKcdEUDY25CH4meKPkJ18Zl8u4Ty9CJmEKSklElJCa2OlpoKouVVpVpvsSnIQyZi/FmCvPhgzN4el0pc9noqud9bVT6ySL4oeN3w1/NTFFL06TiqXz5c3Ck29j/tH3wBY=; 20:KF2ZMORY8doZsifgmnmHqoJ08AJkwkC3pHBby+Qwons2cJVo4V/Ca0nZp3FPjA+Fq8W8D5w7pukyVUrRY7UEyf+GP4dyHxFz3s7dDE5kMWNHHJIATA5OSUq5oy2VIQ8tR+cNFXgGbSXZHsLiw+I63On4C7vDKerHOtBIuSqoMiDg6su9L3eNQoxwBc0+9v/vFTImjfVPBfRI0LUJQ2NZkaSlF+LI1UcC1MOaiJj1AuWKTgZ9yx3+Vzbd/XTza4D8 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Nov 2016 16:04:14.0141 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1397 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(-) -- To unsubscribe from this list: send the line "unsubscribe linux-crypto" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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 efac3d5..213a752 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) @@ -947,6 +961,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; } @@ -1034,6 +1060,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; @@ -1052,6 +1093,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) @@ -1063,6 +1109,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; @@ -1129,6 +1182,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; @@ -1166,6 +1228,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, };