From patchwork Thu Mar 2 21:26:39 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: 9601565 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 036C3600CB for ; Thu, 2 Mar 2017 21:27:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E452B237A5 for ; Thu, 2 Mar 2017 21:27:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D5963285F8; Thu, 2 Mar 2017 21:27:54 +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 AB088237A5 for ; Thu, 2 Mar 2017 21:27:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751194AbdCBV1w (ORCPT ); Thu, 2 Mar 2017 16:27:52 -0500 Received: from mail-by2nam03on0078.outbound.protection.outlook.com ([104.47.42.78]:6784 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751065AbdCBV1u (ORCPT ); Thu, 2 Mar 2017 16:27:50 -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=ekLSEYEkUyVowm/6V2f4fWtAUv15+0Q3db2AzoaybEQ=; b=CxC1lOBCdwLKkCMwNNJsqWtp2R+PgWbQEI5DIcHMM+31CmHIFGy2vNxOze7KR2K3ZbT2xpnEDgPabR5MHb/vxGtQuxdpLGRkUCjxdC9p6/kGW1IQpsl+qH5pMA6k8JtTkx8V0IgWwGSDs483QzMN5q4OH8qxbboltWjRKccKmK0= 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 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.933.12; Thu, 2 Mar 2017 21:26:46 +0000 Subject: [PATCH V2 1/3] crypto: ccp - Add SHA-2 384- and 512-bit support From: Gary R Hook To: CC: , , , Date: Thu, 2 Mar 2017 15:26:39 -0600 Message-ID: <20170302212639.30959.6341.stgit@taos> In-Reply-To: <20170302212331.30959.44149.stgit@taos> References: <20170302212331.30959.44149.stgit@taos> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: BN6PR15CA0021.namprd15.prod.outlook.com (10.172.204.159) To DM5PR12MB1404.namprd12.prod.outlook.com (10.168.238.143) X-MS-Office365-Filtering-Correlation-Id: 0893a60c-0058-4108-1d4f-08d461b2d82c X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081); SRVR:DM5PR12MB1404; X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1404; 3:g53dskruDH2SIbQO/i5CI8AwKPKII3jauUlMq0SPfiA/oONCdvf3w1Bhq0fVyUZs+DVb/cIr7rxKVGB8uVIrVDYwvfKcKDAPF1x2JhHo+m/G/XTiYyXUXmE5kL9CDPNzOWoymJZIdFin0c9mDV+UDhpfMKsPhEiGDzM6VMBSVIrpn1HGA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9l0G3apXVemWOKzAtYG1YWA+P6QJa4UuuNlIk6FQTVXPKdtfPJueQkNsUrb6SaVjFQvVcYMurb0JhkB6HWWLqovrHJpaMUU/qlE+5tE9cFMFrqH6zUCQiiiNbn2RD01U4tr11D4y//kNW8Ea0mXXQ0dXqNsim7lN9mQv4gIhEHZZYobMbdIllCbIO0tw0FeCEHFiQFXho9ZD2aoQ7Xdtrsw0Y3ASJ6pkOvtiKa5x2rbpiCX0PXZQcDVyYy+c9Y08EqolKynWBHZolDXOahTBOxCtRmxHljaECseZYwzEtqpvglMKa7EfX8PGKpGe9/kXQL 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)(3002001)(10201501046)(6055026)(6041248)(20161123562025)(20161123558025)(20161123564025)(20161123560025)(20161123555025)(6072148); SRVR:DM5PR12MB1404; BCL:0; PCL:0; RULEID:; SRVR:DM5PR12MB1404; X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1404; 4:zSHouaxuWaCGb4xf2wig9IQNrfDoFMGeFejylXK/xOG9x+wgY7s4ZJiSwjAowjnoiASxqAaBNK45bu/l2NtrhmnIPDByr9tI2oCA51pxLyW6wfVYW6kj14csIEfrxFTBxfBTLEyYFGe6oRm/kzLoeCU40BqnMWRYIyABl2lZgTAJOiZycewrEesg2mBntgaTJfpiZuj1YGdxhTxn6XT9vhofxKL4PBASBVjM0Av53L6/pjGP7U4JOxlPlNObFJ6df3HGGeZ+cXm3UkVDHfEuX2v+TU/lzxLEKmKnF+nGuvAUqKg+4xMmFe6SDjbcrPddYskXBjWyyFkRXMZkzbpNgIFtl+d/rJ3nRFNOg0p2fV7BKjagHSfnNPUsffp/Nn6Svo64z9To/G5WXD6dHtRrueT0nEgpYA02l9d2tXnqI1Qw4xXxQGBxZX4CNXIidwdgvztLi5dpkEfctBJGQYCb8GxBNhUeUfQSaD/OcamagDrT6/aW8mTYwZKFchkerGkyrDedTWfEuuEZALO0g+64w9khuaXwR1UR1P8japIazw8jbzO3kl54bNazusJ/Ih8894lpus2Dz9heH2jzY9uHszGUqRc70iNOMdqIOZd/lAlTdxKdVjfenn6P513/h4BFyIvHJkTL2rXaLAmeC9q078WwVUpsqsE+GAAerAhilj4= X-Forefront-PRVS: 023495660C X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(6049001)(7916002)(39850400002)(39410400002)(39450400003)(39840400002)(39860400002)(2351001)(2906002)(81166006)(4001350100001)(47776003)(6916009)(103116003)(2950100002)(6666003)(97746001)(33716001)(42186005)(92566002)(54906002)(66066001)(9686003)(4326008)(8676002)(25786008)(53936002)(6486002)(76176999)(54356999)(90366009)(77096006)(23676002)(50986999)(38730400002)(230700001)(83506001)(305945005)(7736002)(110136004)(50466002)(33646002)(5660300001)(1076002)(3846002)(189998001)(6116002)(86362001); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR12MB1404; H:[10.236.19.42]; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtETTVQUjEyTUIxNDA0OzIzOjRSWWMrbHNhYjdBZHluV0lhUXVwdnNsT1J4?= =?utf-8?B?V2tlYWRtcVhubjZSTjRibkFSa1M2Ykh3bThMSm5VbFAxMG40MS95allaODJX?= =?utf-8?B?dVVqQ3ZYTG4zVnFLUGRNODNXVW50VUdjTEdEZVoyRENuaU1zSjh2OHpOenRm?= =?utf-8?B?Z3ZzcWcyUERxSnV3anFQdzExenNOOEU3amtIQ2tKUTVsemNtV0VxTHZNVllS?= =?utf-8?B?djZnR3pXL0FFY3lGZjloZEtIYTRacnF6WUdjRHFrWXYzOWJscTMxa0VHRUw2?= =?utf-8?B?bVB2eWFlckFjdG1kcWY3c0RTVkxRV2tVam5qSmdaUVhNRDhXekw0cTY1dUJw?= =?utf-8?B?SXMybE9aN0NBSmVIblRqcWJVQ3BLYT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Ge22fe0IXHpvIEjJ4w6X/IHKFuzyHWPcqH7XSsFQ==; 24:6LA1MT2fNr27KNswEbJBzwRxFN6IvGoCKMh/Q4pnPuVDzS6C5hEgbSAC7vDABny3RWPx+iPTo9QwlxbRgXzrIxR4ZKg+g4w0T9YX0f+dg5E= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1404; 7:z2x+mbNEsqRVp72By6pX1T/WS+3kOcmm+g2dHtkXV+NbADo1CtMtPzw6VYO8xC+28vMUq0oWhIMOcyvnNwN57YYv0HCcoQxcgZlxhEDLHxqCtmI17plU1Tah/oE65NBeCoERIvHZu/4/3rIDDY2/6PjM3lm5hi/qJk/IBJ3j/kdM92bp0O0st0I1Or67za3W1WERIDBOfSKSGcwLuV2YQeRk0GCryb3TYzWD/bmxEwu/bNR68/+omd6sWXR3XK7C3ubkm7lmtJ+ybon94yt7A6ECxOkynAikslbe04znKB+ce5gfCqqENflvI4tmwhpedWYdHNKWNGACqPV0wbO2fw==; 20:PvMRPVthE9EVsG+00ZM58ivSXGvf4aczrBWB/RmWrCKch5+pXeBu63WP+0nbCuVRNNTupVRWQVBoJcLWawHmOtghKXTB3oRF6zIFoHwiU8rDwnzTJFr7CN5ObnbwxNaZOQbp0MmKAVZKlyWw4+JIty0lDp0HQBHOF453kdoz/92W0t5r5pokoFrJFeywajcS8qPrXrMakB4fQeum7IBcF7Yxt604FH2OTol0PCJdQbRbLP4kPbQq3pimYxdDWx+C X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2017 21:26:46.6205 (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 | 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 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, };