From patchwork Thu Oct 13 14:52:48 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: 9375121 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 CBDE16075E for ; Thu, 13 Oct 2016 15:09:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BBAE02A112 for ; Thu, 13 Oct 2016 15:09:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AF9CB2A11D; Thu, 13 Oct 2016 15:09:27 +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 434BB2A115 for ; Thu, 13 Oct 2016 15:09:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753899AbcJMPJQ (ORCPT ); Thu, 13 Oct 2016 11:09:16 -0400 Received: from mail-by2nam01on0062.outbound.protection.outlook.com ([104.47.34.62]:53712 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751971AbcJMPJD (ORCPT ); Thu, 13 Oct 2016 11:09:03 -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=GmeKVwXJ4WXXBLT37GopLGTJrnOmCNmCUIA0Ggt5yqE=; b=TKZnMLQ4HrRTXie6INd4IofGCs3zz4kzzq5gsxJnl1sSIcrrNchWMcV8NNSYIpGNrAjbimSb3ZERJTrFixiAR1U/tx0faY32NBr1tWv5Iz/w/ERfEYsWyvptf1W6Ai8bTcTOfuOm8XI92Zpj6kfa7NO41on9nsvqwhzP+uvqJIU= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Gary.Hook@amd.com; Received: from [10.236.19.42] (165.204.78.1) by DM5PR12MB1404.namprd12.prod.outlook.com (10.168.238.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.649.16; Thu, 13 Oct 2016 14:52:55 +0000 Subject: [PATCH 1/6] crypto: ccp - Add SHA-2 support From: Gary R Hook To: CC: , , Date: Thu, 13 Oct 2016 09:52:48 -0500 Message-ID: <20161013145248.19759.23166.stgit@taos> In-Reply-To: <20161013144542.19759.6924.stgit@taos> References: <20161013144542.19759.6924.stgit@taos> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Originating-IP: [165.204.78.1] X-ClientProxiedBy: YQXPR01CA0054.CANPRD01.PROD.OUTLOOK.COM (10.165.103.22) To DM5PR12MB1404.namprd12.prod.outlook.com (10.168.238.143) X-MS-Office365-Filtering-Correlation-Id: d584dec9-356a-48bb-4e00-08d3f3789ddf X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1404; 2:UpHLI+5AB7t6dMhmnaPpzfk0ErlqhiyKYfJQz05EWgkvfIqw0Gm1YYSBIuc3RuB/8q+vds/0Grh9JlU5fzoTfnimpEB8WKgfBV/D/CuBNfZN4wp8PxRyrbVm4CIF8uoq2u2Dywcm2fgSRfOxjkq4mg3DUw+oaiEFhjTcZycbtK6YsNQNOaCqGWyIcgbXRrBNsKn+n/aDZXWhB4cch/nJqA==; 3:Fu8GM/YIJMqVAciC47PXsU27JycxXBk6RGzIBnwla7gaH2ef4ngFDmTZT55zhgi0Sf9OPndRN8gS+AoanZRyWjzFCkHY6k3ANf5F+4yPL/VjUzZrBz7nowKpyj/feEbhMZPvzOknfMjZhNXl+0ZGSQ==; 25:cXZyNy2FdbSunWQfaGDIdPrXNSs/q59tiybErZtJxiG/yZLD3yPfR+VsXWHXWPlNgoliAniB9CnNJnwk78mwUD8fTVEwk9Pc8/KdLYkZLVMnDYTIG0HThyA46bqP0OSAewTK6GCNf/a5hd21pdScPiRcnsU+LG0E267pwdQBUfj8UfQiqg4pThtVk6u1nnncbrAiyD3FpQsjNcr9aN4BXOCo1LM0LyZVPkxABel6CFbhKAGXWkE2N0u+jU8IDnTrsPVku3bOmPFYeotBuSvrODnjQtqnLizfupVIPNEsAxK1aDaOJ6vFhdRe361k8p9vp0+564pBR6hITh2SPaKJu7xkXEsN5V2FKOcmhqo5B+NwV5y0Co61k56uCu644rvhJbS9oYipnM5qHTDKDB+rEX5e9fEfW+NGu75jTANTCNBhLWUnWQVN9acCDc50KONo X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DM5PR12MB1404; X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1404; 31:wPyM62th5f4FbG1G48JkU+YQUSe+usJcuGdLuqEHA5TbMfwBaUcWWDaWniRfttYXyoHhm8NsvZnN2zqpvt8atJkts+fdDx6PVI4UxymMrmA55qd2PeLSn7Qk62sxdwOZFvdmWSrL9ZuVwvJBoPhKffltGeA44uV/Wqa+AtrfMct117vPkioBYx3X777oFJmyVOAZFvvzm3yKJxEiVO14L8STxED0cpq+mf1yQuthWCfTbc00F7uZn2u63ax3re7Q; 20:g08Rto5Ccz131xBMtCb/mM0Qd0MA6J7rxKluop8FVpJlRANcQ0lcxNHn6vUAzYasSUJMvMijPkgBf9gIXtmsBUQvrVF4R+RHG0bvFuWWAOe6brHHVIbfWa5F7+5yCEd69Szh/+e3rr0QC5+49JoZRF7b0AaCAaGl65Y+brdvHyE/XA6aoTDucTrEcF7SemCRk0IzZC8gmWnb71ut+VpeB85fZ8xFv+TS+yF384KqcA3fZErl8wTf82LXsWfqXbzmR1RHLZYwgbjx01rEddrnttWW+rxbkPGktnYbhqbGpTKfqbqGRWCIBmMxduEpTsXw7b2DoQOhB1dIc0K4z9AFFsjj6s1I7MnVze/A5GYFej5w8+n8M1JrSL2Qy76bBOW4tqviltluHlZlEbhtfztAR7TT5D6USoZfAKecXUsQDR1QVSQ/cZ1r1XgRsM0XXN/DtORegTyQVAiq7oCSMcLuK4YuKisYnE85tdJ1qvLrTa93n3ojC5zN2bjOwQAOjuAM 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:DM5PR12MB1404; BCL:0; PCL:0; RULEID:; SRVR:DM5PR12MB1404; X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1404; 4:gvbe/mBZZsiawEM1L2QZfepduGVrF1RvwY4jB4wg/zm7DCCdBTOGnR9JqSOgwQTbwMV7831+bDUog4MJRFWufrYHb5e+mTNN40/ciUcIAH/2XcxjZNeBmO8HoJ3ee3zveaS9gvIfc5R6P/+8cZXy6jPhq8lV9Wl5tnj9l/jSDs/YGWlTyHIPGsGzN3+DLiG1j+S2rIv6LyXv3cirJSgs9sYK3btQiRl2cIDnIWTJSGn1Q7is1Zph9f65fYv8D8YAX801u256h8newlmw2vBuf/xpA28niyJOcL+9jKeiiLF5O/cgl4WiqSHjatVhlS6Y8uxlvcRFuj4JvGandIPMWoeiBoYBH4NhC6+w/L6n/AkzPGR0rEQLSf++eOGq333eBQUomJ8NeSxTuWjc8gqw2jTUeVEaZPJgxWnrd/U+AfhdQnoWuhEng63sygTLnd4OmSh4kqy/BlHgH3XtYrhzpw== X-Forefront-PRVS: 0094E3478A X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(6049001)(7916002)(189002)(199003)(6916009)(586003)(5660300001)(101416001)(76176999)(54356999)(33646002)(47776003)(97746001)(50986999)(2950100002)(7736002)(110136003)(230700001)(33716001)(50466002)(7846002)(105586002)(2906002)(6666003)(305945005)(66066001)(97736004)(229853001)(106356001)(42186005)(2351001)(77096005)(1076002)(4326007)(4001350100001)(92566002)(103116003)(81156014)(19580395003)(189998001)(575784001)(6116002)(8676002)(9686002)(3846002)(86362001)(68736007)(83506001)(81166006)(23676002)(19580405001); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR12MB1404; 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?MTtETTVQUjEyTUIxNDA0OzIzOmdyTnZVK3Z3bkU3b2xWd1dJdWJvOWVlYTZq?= =?utf-8?B?VVBtSGRkbEkwZlFzQVMvaFpBTWVDb1NRUS84Vk1ySmRjYnEyVUVqN3VJRVVp?= =?utf-8?B?K3MvWHZHdjhwdVcyNXRLMUJvSGVDK0hHOTlpTlJKT0lWMmZ6cDVHSzFZVE04?= =?utf-8?B?dGE2dDJOcEUvL2JSUW5FMjBNYndjbnBzOERIRkEvbk0yNmNTWGNwQXBDS05K?= =?utf-8?B?NWI3TVlJUWZFYkpPOWhrOC82M2x5TWc3Q0NPVUlhMFN4WWJ3blVNU2kzOTF5?= =?utf-8?B?elhLOHR4WFlleUZacEExSkFzTVFYYVNxdEJXaytoc09ZbTNoZ2pwNGo2ZFNZ?= =?utf-8?B?RWMxLzZwVzg4eUsvUnZUbHlEYUNBMjY3WmxBcC9zSWlwcGhKd01XMDJsRUxX?= =?utf-8?B?M0ZxM0VTL3hYMzc4em5ZdHJFQXh1cHdvZGpEbnNLdkNTK1BZdU1leHJnNHFu?= =?utf-8?B?VSszbktIdXNUdUhCVnNybmdmd3I0eW5mYWxwUm5JcTVwRzUxcGt3eE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joOyI47iJaWY9igfAwm/eKprOalFZTuJdFElpC9naEEGI= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1404; 7:BeQBhsSyu+eTObESW+Jf8dCQETY++KYgCVP0qi4qWnB5YrYqtA63bEsCbpC1KrREh7Hick8yCtEps48OvRI8QTDDZR/AWoDzp+pwt0XbfKjFi5IKERFWU0Qq50+4qUHwX3X3hcHnL7YdSsMeJj0ra9g7GLfIVK4TkuklKyq8Fuz2hCTNa5uwVZwsywzTo2fGyT/4ETs5xt/N+vtOQRbyZkn9qpu1DHnhs4O8ibTHqE7qH3+0GCQWlleuJgqk+ci6H2cw6mvTuhuVH6qTLIp41edsOUQbO3xfqGbaOgFHlXxN4mosgiMj0w6/NA8ZMkb3o/Hn+Tw28n63cYJAC3RQTitVRKIibom22vZDrZJlbEQ=; 20:UYFPtFEtSyR70z7W2sMR4arTilgP7Jap6wCz5PBo5WIGEOfvDr2NkwuggiJfK/2YZzU/amewkm56VRsqBags17ALjJoftRhmqgBrHDIDLG3YUxW5PzwpXP8hmFbVvj+AZ8B8AlzKLIBTX4qakLPcxZcjUv91pbUopNQjkpbqFQG4rzkxDxriudALv6Nl19mkH+TizBSOLyGaixBetBPpfdkDv26gdOoBKZWoVMeiAssjtRQhQljUH0Ljc3vCmo9A X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2016 14:52:55.3549 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1404 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 | 9 +++-- drivers/crypto/ccp/ccp-ops.c | 70 +++++++++++++++++++++++++++++++++++ include/linux/ccp.h | 3 ++ 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 @@ static struct ccp_sha_def sha_algs[] = { .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..ae442ac 100644 --- a/drivers/crypto/ccp/ccp-crypto.h +++ b/drivers/crypto/ccp/ccp-crypto.h @@ -137,9 +137,12 @@ 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 50fae44..8fedb14 100644 --- a/drivers/crypto/ccp/ccp-ops.c +++ b/drivers/crypto/ccp/ccp-ops.c @@ -41,6 +41,20 @@ static const __be32 ccp_sha256_init[SHA256_DIGEST_SIZE / sizeof(__be32)] = { 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) @@ -963,6 +977,16 @@ 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 (sha->ctx_len < SHA384_DIGEST_SIZE) + return -EINVAL; + block_size = SHA384_BLOCK_SIZE; + break; + case CCP_SHA_TYPE_512: + if (sha->ctx_len < SHA512_DIGEST_SIZE) + return -EINVAL; + block_size = SHA512_BLOCK_SIZE; + break; default: return -EINVAL; } @@ -1050,6 +1074,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; @@ -1068,6 +1107,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) @@ -1079,6 +1123,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; @@ -1145,6 +1196,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; @@ -1182,6 +1242,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 a765333..1a3e0b5 100644 --- a/include/linux/ccp.h +++ b/include/linux/ccp.h @@ -249,8 +249,11 @@ 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, }; +#define CCP_SHA_CTXSIZE SHA512_DIGEST_SIZE /** * struct ccp_sha_engine - CCP SHA operation