From patchwork Wed Jun 15 14:52:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tudor Ambarus X-Patchwork-Id: 9178707 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 C8FED60831 for ; Wed, 15 Jun 2016 14:53:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B846227DA4 for ; Wed, 15 Jun 2016 14:53:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ACF9327EED; Wed, 15 Jun 2016 14:53:00 +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,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 16B1E27DCE for ; Wed, 15 Jun 2016 14:53:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933117AbcFOOw6 (ORCPT ); Wed, 15 Jun 2016 10:52:58 -0400 Received: from mail-bn1bon0067.outbound.protection.outlook.com ([157.56.111.67]:63530 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932740AbcFOOwy (ORCPT ); Wed, 15 Jun 2016 10:52:54 -0400 Received: from BY2PR03CA008.namprd03.prod.outlook.com (10.255.93.25) by BLUPR03MB1441.namprd03.prod.outlook.com (10.163.81.150) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.517.8; Wed, 15 Jun 2016 14:52:51 +0000 Received: from BL2FFO11FD008.protection.gbl (10.255.93.4) by BY2PR03CA008.outlook.office365.com (10.255.93.25) with Microsoft SMTP Server (TLS) id 15.1.492.11 via Frontend Transport; Wed, 15 Jun 2016 14:52:51 +0000 Authentication-Results: spf=fail (sender IP is 192.88.158.2) smtp.mailfrom=nxp.com; nxp.com; dkim=none (message not signed) header.d=none; nxp.com; dmarc=none action=none header.from=nxp.com; nxp.com; dkim=none (message not signed) header.d=none; Received-SPF: Fail (protection.outlook.com: domain of nxp.com does not designate 192.88.158.2 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.158.2; helo=az84smr01.freescale.net; Received: from az84smr01.freescale.net (192.88.158.2) by BL2FFO11FD008.mail.protection.outlook.com (10.173.161.4) with Microsoft SMTP Server (TLS) id 15.1.511.7 via Frontend Transport; Wed, 15 Jun 2016 14:52:51 +0000 Received: from enigma.ea.freescale.net (enigma.ea.freescale.net [10.171.77.120]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id u5FEqkpe011007; Wed, 15 Jun 2016 07:52:49 -0700 From: Tudor Ambarus To: CC: , , Tudor Ambarus Subject: [PATCH v8 1/3] crypto: scatterwak - Add scatterwalk_sg_copychunks Date: Wed, 15 Jun 2016 17:52:42 +0300 Message-ID: <1466002364-16945-2-git-send-email-tudor-dan.ambarus@nxp.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1466002364-16945-1-git-send-email-tudor-dan.ambarus@nxp.com> References: <1466002364-16945-1-git-send-email-tudor-dan.ambarus@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131104759716588581; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.158.2; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(7916002)(2980300002)(1110001)(1109001)(339900001)(189002)(199003)(2950100001)(50466002)(106466001)(8936002)(81166006)(8676002)(2906002)(356003)(50226002)(4326007)(8666005)(5003940100001)(77096005)(81156014)(5008740100001)(69596002)(87936001)(68736007)(97736004)(229853001)(19580395003)(47776003)(19580405001)(48376002)(33646002)(50986999)(76176999)(104016004)(189998001)(86362001)(105606002)(85426001)(6806005)(2351001)(586003)(92566002)(110136002)(11100500001)(36756003)(7059030)(4720700001); DIR:OUT; SFP:1101; SCL:1; SRVR:BLUPR03MB1441; H:az84smr01.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; CAT:NONE; LANG:en; CAT:NONE; X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11FD008; 1:JRiJiibHyGUHyU59LzbuFYXTC+bctPSdVrWvKyVIdXjo+iBLi+U1u1cSV+xqOG7CLScBqZo7gx4ItoFH626nx6NRQ5Bx7sc981tnhKGX9eBI/2YXem52Bf6nxdQuoOntlmWjG2tOt5ASKAzTkNBCvufU5uROGerj/Wed5WNwHW/qUc9nUvnUx2JK+4+1YNRg+3KDeEDO0kmKUxbIcyYBG7fF+wY+2WIDhb87jXnHjNB9SxtMEEu90DAoNTtorjeeKY8xPbnKLsqGU0pSZMjXhh/UC7djrBaaw4Rjz6tnY9lu5SQiSDEsC3W9lY6UmmLtDPfFdGMe/avETWJdPVbz1KR1RDFvhDbquA34zoFYaUBUCyozQ5BYCgUWukTVgjW546qU5WVcofDVwpnaw55FinSjDUeh7cxxcYAIA2JIP3yy0QGJbJQ3mm8yiBcYEvl18B6etZ/8G5mAbgZ5xxCTWEikKdH/knfoOzi/P4M+hvmwzHK+C0U1hCxqUHXcUWJ5sbzsEdQltL3flfHjme2DthtwoQAfZHH3iCtJgs1VLIoqhg1isEWb+/INnjFL+L8UeKdKzDWghrTbhYgSSfy0cruiXKEGGK74WXWIQrntRcVHmLwa5YIhxRFxt2PotAyuPswmLpemiFbHg3WDm/D+WSQMv5xSXO5i2gD501elz+X6yBy/lE+zZYte5rZ3wuje MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 5ab04520-a4d5-4bb9-2c25-08d3952cb9bc X-Microsoft-Exchange-Diagnostics: 1; BLUPR03MB1441; 2:R+ZPcDB5itmols5eBQigx/3It5WjLswj0V3nEbYTSddPRe1S7rs7oNuByt9Wjip25kbOeqgwBdRSkD/+c0OWvwKpAUTcHyc7Fmu+9071nxhlGtfa0biwLSikcTqxB9T4UJTyodduXq+v/SPqMCF7/oN1Tyz+H5jH9LSH0exi3cIXF0CMSR+GsXqp5erDsvG2; 3:ldrn3i4o8vArQym0ok7i7is0xZGoTT4YOeEx4a8JZepApGdd84xhLC3RFk3gv+ypcwkdAlY02C2OZIsE1ng/ip4PcwzmFaYdpFVA+jo9Ou/xNY4PO9gzuRz4PnJoc4HVJ52gwG8NtbNWPjVCL4q4H8DtYOQsxBcypZ7wIRgeWA++7tbzG5V2YLupiPGAcxDBNTm2jfEToWJraoc2WnmPclsi8FRWF2rHLWPb6N3uloI=; 25:pZPi+7o+U2g82FB/pk4BF3r930oLM2gSvxNW7rBqyiyUh0DccXKdcUoZRIKa0pn0tzXDlDz5wdUrLAzWTXJLAuYDQ+oPyPQPNLuefVljGBGK5fKkiES6AW/Sm4sp1afiG43hBx+UV3bkltkJ2JAw1iAsFw4UwO9y/km6sYDlnwl+vJgLXHNnUOrX6StdQzc7tClih+PQUwXWW+ti9pUecfDAcLshTTLramujIE636tko2OrBIZmASopQsNW+Tb/IwFZB0b9jn9gVfAaHfLWg4dsAi3lzaYA6nkNkOs/vE1xqrn9pm2RUFCrrLgvv2iP9/tDRqtWeOpl50cuMrd08DhNWaRnqGZbvfXrySNh2GhyNINta4M0KDfCz88MSth9giMlJ9eCBvzi6RTCAe/JSQYF6Zk6IiSUBlWhZS2343Kg= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BLUPR03MB1441; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(13023025)(13024025)(13017025)(13018025)(13015025)(8121501046)(5005006)(3002001)(10201501046)(6055026); SRVR:BLUPR03MB1441; BCL:0; PCL:0; RULEID:(400006); SRVR:BLUPR03MB1441; X-Microsoft-Exchange-Diagnostics: 1; BLUPR03MB1441; 4:orrzyCxgo1rXnx028MlQEI+vKiAeuBzZznQzR5r5iPlU2zKU29XG9PxArv05tQg/3xGdjgNIJemY7ARM+DbSwAdrRLHn2UWHvUoIM3dPWRDW96RHLD0BHmbJxPB8wtoG9bYr4yudbJ3IijaC/wHUHjv0HBp1sUavqS0p+3rpho+5qQM66kVx/6nohbtgF7CORPuINYRpicF5pZM+kxm2UwQCFHDm6ad/MbEPp7g+UnOgHY2ZaTDn/09cq945y+fjfsYZmnv7t4UMTZ3ZG93TRftrCzugwgUgiprPnApxqtt7RPbp3d8DKjJvX17AZgS95GhM5kPtH8vN6mvdAWYgE4NAmT2/ecL858rTp+/5bN7yTTDhWwiI9ZW3PvDDh1S242gmgU/1Y4hx7fidXkAnNZJY12VTTORZfpD2rTkpTadkYIxnjsLZSgnsQoHi7YgSJ1gyvvhn3YO325T3jEgNdb0/t2bpLM6XsnJmDCmAPoUf3i7HH+WBpfGVBYtYaVPSeJIXuszcXBnqEgIsRh7qwA== X-Forefront-PRVS: 09749A275C X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BLUPR03MB1441; 23:5EzcVEyl8dEwlt3TZjUIH87JNJ69ipgvWibrxFYM7?= =?us-ascii?Q?ABLiEs0EvKo2+pqAvuIM7wftw3yEDW3YUzijuMTatJAwCEY8l32bPeANKNez?= =?us-ascii?Q?sQpVGxWCv80icl4jgBaowfl07BVgPbb4rfLuoOW6mFoYPvte7N5fSQN1Tp7p?= =?us-ascii?Q?8RAfVWtodB9aS7E4vpgGWtm7R7YgCPhgqCjmtFF2EEqcBe0VLazDhEi4P+2R?= =?us-ascii?Q?rC2QwTixk83I3CGUtax5f+AZQadqxbFtrjCthpx+Z8FOWZ1+sCWDSWxh3r4W?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K9g/4szmXWpzCrXn9s45BEGAwCV2z9SheMQ?= =?us-ascii?Q?LucWBKR8ZnNR2hGdZuDTsmrhyvMnVfNAENbyhdto/fANX7s75zMfwxA1g=3D?= =?us-ascii?Q?=3D?= X-Microsoft-Exchange-Diagnostics: 1; BLUPR03MB1441; 6:PS8KJ/D45e+iNzierpyYynZc/KFM+1zXesczfmMG34SWTBc38mMpwRIuGXP9vR0vnstQse+Xem9N7bLz6X1RZgwph4/QhHspdy/KzyKD3Vf3HlurbXHKSqbghMuziYlMTdiMT81UrlbVL1sjBv84ndRujnXHw1iaIHgwa+gVr1fxOeQIWYflDYYFVmy4CR9/bzNMACo2I7pN8Ucb2wmy6p/fmMGuo8Ub/gB8xtJDluV9trt5GUl7YwLAoDq1KHECsVZTrDSZxJXBFPbL+mW1WA==; 5:607/39/9d7w1cFVDT81Jo2qX9NIVdYsIFJyfVOWHLWqebaCA/LuAuHeklQGoOooSO3c3iWSy9OExGovjWtwHTPtqlVlMHB8bAQXHswxTNpnVrQrA7zYWTRHAB+ZFX17oFGdOongtHK++Kqfck1aTvny33zH9lifVEaPduOu5sQM=; 24:g3XCIVoZT1t/E3/Zz7jepn9ZG56mTGdC8ayqJ8f+xUZjnSpcezvinqxQlEfy6RXWaGrHQOvLRejlSDL0NSqfTslflnRUUQrxaMT2CS93K/Q=; 7:J3JjfKRpxntdTxDxlozYBZTvf2lSZRL4E6T8/tWtDg5FJenjaQDMGxjeyjwq6oGgYGXPij87W3cOr00VVhJ23Dw00Z7W2/2iTZvVvzhXIF1yIbDxyJ0sDfKfu3wqxGkYcxclPJ6jsDBwYOHwk8aD6QEEKaQqtyXf/czNDrf23vOPbYLvpQg848dHcVIyPTKcx+djdF55fMiQ6tyu4OJh5g== SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jun 2016 14:52:51.4404 (UTC) X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e; Ip=[192.88.158.2]; Helo=[az84smr01.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR03MB1441 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 This patch adds the function scatterwalk_sg_copychunks which writes a chunk of data from a scatterwalk to another scatterwalk. It will be used by caam driver to remove the leading zeros for the output data of the RSA algorithm, after the computation completes. Signed-off-by: Tudor Ambarus --- crypto/scatterwalk.c | 26 ++++++++++++++++++++++++++ include/crypto/scatterwalk.h | 2 ++ 2 files changed, 28 insertions(+) diff --git a/crypto/scatterwalk.c b/crypto/scatterwalk.c index ea5815c..bc3222d 100644 --- a/crypto/scatterwalk.c +++ b/crypto/scatterwalk.c @@ -125,6 +125,32 @@ void scatterwalk_map_and_copy(void *buf, struct scatterlist *sg, } EXPORT_SYMBOL_GPL(scatterwalk_map_and_copy); +void scatterwalk_sg_copychunks(struct scatter_walk *dest, + struct scatter_walk *src, size_t nbytes) +{ + for (;;) { + unsigned int len_this_page = scatterwalk_pagelen(dest); + u8 *vaddr; + + if (len_this_page > nbytes) + len_this_page = nbytes; + + vaddr = scatterwalk_map(dest); + scatterwalk_copychunks(vaddr, src, len_this_page, 0); + scatterwalk_unmap(vaddr); + + scatterwalk_advance(dest, len_this_page); + + if (nbytes == len_this_page) + break; + + nbytes -= len_this_page; + + scatterwalk_pagedone(dest, 0, 1); + } +} +EXPORT_SYMBOL_GPL(scatterwalk_sg_copychunks); + int scatterwalk_bytes_sglen(struct scatterlist *sg, int num_bytes) { int offset = 0, n = 0; diff --git a/include/crypto/scatterwalk.h b/include/crypto/scatterwalk.h index 35f99b6..8b799c5 100644 --- a/include/crypto/scatterwalk.h +++ b/include/crypto/scatterwalk.h @@ -86,6 +86,8 @@ static inline void scatterwalk_unmap(void *vaddr) void scatterwalk_start(struct scatter_walk *walk, struct scatterlist *sg); void scatterwalk_copychunks(void *buf, struct scatter_walk *walk, size_t nbytes, int out); +void scatterwalk_sg_copychunks(struct scatter_walk *dest, + struct scatter_walk *src, size_t nbytes); void *scatterwalk_map(struct scatter_walk *walk); void scatterwalk_done(struct scatter_walk *walk, int out, int more);