From patchwork Wed Feb 15 21:55:55 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: 9575169 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 742EB60209 for ; Wed, 15 Feb 2017 21:56:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 65C271FF27 for ; Wed, 15 Feb 2017 21:56:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5A46828555; Wed, 15 Feb 2017 21:56:08 +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 9D5491FF27 for ; Wed, 15 Feb 2017 21:56:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750806AbdBOV4H (ORCPT ); Wed, 15 Feb 2017 16:56:07 -0500 Received: from mail-sn1nam02on0083.outbound.protection.outlook.com ([104.47.36.83]:35103 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750719AbdBOV4F (ORCPT ); Wed, 15 Feb 2017 16:56:05 -0500 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=LtJEO3zG5IUfWGLf6qOk2C55XXPxJN8aTRH7Ydpm7tByJwyyunBkBzdvBXWp+rJnilq6ylimI2DfVaWFBs7qRo+xaumCpnYQON7iZsukqnaNnaB03ighvZhIFWE+SVOf3msU/K2UE8G4AgNWqCJCFL/rWkAdkxqNQro6hV4xG1I= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Gary.Hook@amd.com; Received: from [10.236.19.42] (165.204.77.1) by BN6PR12MB1394.namprd12.prod.outlook.com (10.168.228.140) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.888.16; Wed, 15 Feb 2017 21:56:01 +0000 Subject: [PATCH 1/3] crypto: ccp - Add SHA-2 384-/512-bit support From: Gary R Hook To: CC: , , Date: Wed, 15 Feb 2017 15:55:55 -0600 Message-ID: <20170215215555.26536.62696.stgit@taos> In-Reply-To: <20170215214954.26536.76736.stgit@taos> References: <20170215214954.26536.76736.stgit@taos> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: MWHPR22CA0065.namprd22.prod.outlook.com (10.171.142.27) To BN6PR12MB1394.namprd12.prod.outlook.com (10.168.228.140) X-MS-Office365-Filtering-Correlation-Id: 8752a95e-43a5-42a8-3ffb-08d455ed6f2d X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081); SRVR:BN6PR12MB1394; X-Microsoft-Exchange-Diagnostics: 1; BN6PR12MB1394; 3:s17jlxpcO2uucsnoBpu7a3XI2GkS9hOb+EGpz3sehY1BJLzukDUF0QkTrEo36+8v1c2HsWY8J72xgxkVuZ9+yg/5YhHL0mRfOUI9hGq/zwqzxTquA8WhhQdepZU7rjQhlnmE8+avHiIZ5FykMwaXzyUKYFk4cGvyiGjoSCzpa015lRx7I8PImQp4UYID1hm32W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qR70UC5mK7T9D3RtC2gK1RsMvTUeooOo51T9MmfaZy20ba1n/PU61pseHyud3DZQJgkgBcPUdhsEqtXsdURRNyl+Ga+lggMmFMHhhUKcaroaGh0W2LJG//wIA2j2t6aCU64AMzHcxD+FzErSV7eC/2ZXS4McOru4xnVaQEfZq6Ndphr8JoTIEOmWnNlxaPlKN6RB6UK/kiiMXsA7yy1qe+BXoGkSbEgd+u8E0IfVHeP1r2IzmDLG5FpWkqdNpyR/j7ST6CEdT9lm9Ph8lQL9 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)(20161123555025)(20161123562025)(20161123558025)(20161123560025)(6072148); SRVR:BN6PR12MB1394; BCL:0; PCL:0; RULEID:; SRVR:BN6PR12MB1394; X-Microsoft-Exchange-Diagnostics: 1; BN6PR12MB1394; 4:BGAfbk9BHekEmaeWP6x5Vx0rKXIcorxWb6e26Jt4B0Iu77NuM+V9cdQVQsuAoovS0d2Xz+weBS3JR5hVw0MfILHgcL2N8e2HAXfCaqxib+ISyXgk2FpdgvEI6As3g4sO5rDs8cOlGoLlIVUdFznAfE3KQ1MpDF373kpkcy4qNFtlAtDb4Ers/MbAMjOWU3+WS1lYEcCN5i2eILW4LXbLuXEgreuczRPjEWBXjqKijAdaQx3WXIFS9aP1JDzkP4/UFRudatRE+I0PHXhPi+dVdVXLXxHG06p59uLrfyUiCzJ3WrjjAZOE87CNaxpKsYbT5/iURQr5hXbK0d1aSjkv1Y4twDBjkUV74XKrEZGQJWX98mmJ6KzZ3xk9rEBGzkxKbkdj7YsbKhsAM/WM9cd9YcPC553GhcayZZolYC6Wo1TE1bmogRxmHuoENcDOKJCg1RFlA3SrMsfnGYK1PXCXINj1FSaSYAqKop6h+NaRTLcxcra+wbvhcJsubDQA5qe2i4i2LuR6c4F3wKQTcEsB4yQPCMfghP1by9DSTlcl2jiuK+lo4bDMAQRAO9SGXrmUB6n4YwPeIsgNlzIhWDY18uOO6ZE16TaNA1TFKawawSnf/Qd0lYQ/YYnmge7enKbdW2be0xyr7LHzvSrHvoz+k0kDHGIlBy864K0ab9G3J+o= X-Forefront-PRVS: 021975AE46 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6049001)(6009001)(7916002)(39850400002)(39860400002)(39410400002)(39840400002)(39450400003)(189002)(199003)(189998001)(33646002)(25786008)(54356999)(7736002)(92566002)(77096006)(50466002)(90366009)(54906002)(76176999)(103116003)(305945005)(6486002)(5660300001)(389900002)(105586002)(2906002)(33716001)(1076002)(6666003)(6916009)(4326007)(2950100002)(230700001)(3846002)(6116002)(42186005)(66066001)(81166006)(83506001)(47776003)(106356001)(68736007)(50986999)(2351001)(110136004)(38730400002)(9686003)(81156014)(23676002)(86362001)(97746001)(101416001)(53936002)(4001350100001)(97736004)(8676002); DIR:OUT; SFP:1101; SCL:1; SRVR:BN6PR12MB1394; 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?MTtCTjZQUjEyTUIxMzk0OzIzOlhwdlNKVTFMR3hvVTdZVExXelhaK0l2ZUp1?= =?utf-8?B?cFhYTVRXZGYxME5FeHVHMEhKRWlHYUFSNUFqUjBMQkJmVzZxQlkwVDVrcjRs?= =?utf-8?B?c1V0TGsyNWFmQ0g0RFgzd0owTUs0UzFocFVCWnJWUnA5ZGlOckNiYlp5eW00?= =?utf-8?B?RDJsZTdwd28vWmhjelI4V283dFZ5WlhNTWlmZmhVMmRTL2ZsekhXSnkxYllU?= =?utf-8?B?YnIxbUZzb2JiQ1dnMmg0amkzVy80OVB6NHhJWmhyY0tua0hVcHEyZXl2WGh4?= =?utf-8?B?dFo5RmNjeGJ6cCtCR3h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CW8MlqMHLv0TZ6hL2Dfq7Bkl7SX2Kr77K8eJNmvDDI0lP0Jz2SfA7ox4gPc1HVvwTabA6buR1uWrxm/1C9cFTHe9iwVW62WA7lVkCqbB1jsfpXjFNIC81gimdezdeArn6fYdQmiQXCFJzsGfriugzb49jMuus0t X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Feb 2017 21:56:01.9542 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1394 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, };