From patchwork Fri Mar 18 18:32:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tudor Ambarus X-Patchwork-Id: 8623111 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Original-To: patchwork-linux-crypto@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 7134EC0553 for ; Fri, 18 Mar 2016 18:32:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 774B120306 for ; Fri, 18 Mar 2016 18:32:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7E2AF2034F for ; Fri, 18 Mar 2016 18:32:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753409AbcCRScb (ORCPT ); Fri, 18 Mar 2016 14:32:31 -0400 Received: from mail-bl2on0059.outbound.protection.outlook.com ([65.55.169.59]:28491 "EHLO na01-bl2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752183AbcCRSca (ORCPT ); Fri, 18 Mar 2016 14:32:30 -0400 Received: from BN3PR0301CA0038.namprd03.prod.outlook.com (10.160.180.176) by DM2PR03MB384.namprd03.prod.outlook.com (10.141.55.25) with Microsoft SMTP Server (TLS) id 15.1.434.16; Fri, 18 Mar 2016 18:32:27 +0000 Received: from BL2FFO11OLC003.protection.gbl (2a01:111:f400:7c09::195) by BN3PR0301CA0038.outlook.office365.com (2a01:111:e400:4000::48) with Microsoft SMTP Server (TLS) id 15.1.443.12 via Frontend Transport; Fri, 18 Mar 2016 18:32:27 +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; 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 BL2FFO11OLC003.mail.protection.outlook.com (10.173.161.187) with Microsoft SMTP Server (TLS) id 15.1.443.6 via Frontend Transport; Fri, 18 Mar 2016 18:32:26 +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 u2IIWAmR015418; Fri, 18 Mar 2016 11:32:24 -0700 From: Tudor Ambarus To: , CC: , , , Tudor Ambarus Subject: [PATCH 08/10] crypto: scatterwak - Add scatterwalk_sg_copychunks Date: Fri, 18 Mar 2016 20:32:05 +0200 Message-ID: <1458325927-14737-8-git-send-email-tudor-dan.ambarus@nxp.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1458325927-14737-1-git-send-email-tudor-dan.ambarus@nxp.com> References: <1458325927-14737-1-git-send-email-tudor-dan.ambarus@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131027995471716329; (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)(2980300002)(1110001)(1109001)(339900001)(199003)(189002)(2950100001)(33646002)(6806005)(77096005)(19580395003)(19580405001)(104016004)(11100500001)(5008740100001)(229853001)(1096002)(1220700001)(586003)(105606002)(50986999)(85426001)(76176999)(106466001)(86362001)(48376002)(92566002)(36756003)(2906002)(50466002)(47776003)(4326007)(5001770100001)(189998001)(50226001)(87936001)(5003940100001)(81166005)(7059030)(4720700001); DIR:OUT; SFP:1101; SCL:1; SRVR:DM2PR03MB384; H:az84smr01.freescale.net; FPR:; SPF:Fail; MLV:sfv; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11OLC003; 1:v3whc0cBS5/g1gc2ltVdKo1REBvq/jkHCGPpjn0CMwvs2kvpUOQMHhRY4P6/f1ItPM5E7nrQFV1XNVjDIRZoHyiIfHaLPoWDBjoktbNOPIiYzkE93ugJrqEsVPBlhrzREMZ1SbDDWpxeIcQmjLKUaKEAUUf1eKtndDdfLbL9/MSG8CtQxrF1l510yqf0DJN2fXjWY+8Zvww0Azz1Nmjhm4XHiWQGvpALRWJ80pvT/h50whaW0sRyPFI7FIXcO9g09gSBImoBef2lvSIugDBirHUO0V5XHSqkUov/24xyB4/zyZWFL2Z9CCLLY6M7hM/y2au3N2gcLmPZ7w3F73yfR6oHIY/CJnIS/pNoZPRzppOhPEG/Z8MNLsjKAv8rq3movOPVSdAoc1oItmizK1slHgb+H0hD38nDLwgs7yzYjS2Am6yWpX3PsFOYrKKanoQ414DWhFoa81eGHFvVnvx0UsSGI72GhSjb5ApA9MIzB7yo6MFveTrOPgIS48nWQhAYUG0+Hufa++0KHPBdRsuUhZ5KI7IdJ98Xd8PM+m7vBrTX+Mn+YMF20qqx7ZHtg1YSpyD7mJbXjWsFLxkZmM66hBrPdqfoy21Ef9Z5H/ObgByObwJ1cwB+BjqTE1FDnP1s7QsnfnL1kDH7pjluX04S+gk40bSclBQ0Ioub7f32WNQ= MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 786c2bc3-8745-4e45-1fe9-08d34f5ba830 X-Microsoft-Exchange-Diagnostics: 1; DM2PR03MB384; 2:sgiOtWCt3vNmFIaVezwEgFMTBxVobxpdYsos+5JmrLZSxppPOBuZ04soQltfcN7YVC50Q4ekkkv/Av8P+VD9IlsUXlqoCzZ+wB58D2uP8jai28XynZBZ769bQpeJ+z41zEAxXPEsQvq3A9HtvdG09gDEv2yODqCx1F6ZPaEZokhb4+EiZzbDvGtbiXTHOWJ9; 3:QlSKPUxwU5omPw6MhRmtyJ0DX6aq9e0WwKIXMKbq0GsoerUtGLmASKYQALnASujRqlH4w8eLvdD7lzzN20WGXAy/IWxG0Al1C8xI4k85iMwq4n3Vgk7UA0F47i6sk8HIKUMZ2cvhaB+5jjtB/Ga0MWUxCPTvK+xZbgzkeoUSpS/1E5DSO+4f+deludv4T+lYe7weJC/q7OXOy+R+qLCYpMgBJzFCzQh9869Ju6AwYKw=; 25:RdnDvCgBCraZQUbxaPs8k85P/Ws2nql7K6RS1s11kiSLQ6tY6gnTgqBHJ1ucOZQHgm04zWsH3dOTr5EwIWUqaScOH+II3ZE4C7vC6adM8Z9XONcrljzv+fdUK/SkKKw69oLDgA+y3SKSJDBZM5vPfwqSjTJBywGTJclPvYM4WZq289ECUUn865iW40BHuXAOSYRTdawQfJkrmGmjmNtyfEiPCQAEBhvoekWpWHYZ7nJci1//POXWQtG3Q920LfBzF2n9tkmiJMkzSgJ8bxn7Y2/B4KRwSY7yPIxH4u0WShz/BPJ3LysYs3j6QO3GGRU81kje6Ol2/RFHwNA0YjisWhYLacyvJD/t20bRJTlUdjQk5lbpbrBZ2GaImOIe8JYP8tHqBOiD/Voozobhtrq8v76jfEsmg67biiHpSjz/g4JxNsK9daUBS/UF5EIKKeHvx7jVGp0b5SWLghmKH64O08AllatTfEJN/Rqbyrs3TBI= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DM2PR03MB384; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(13017025)(5005006)(13015025)(13023025)(13024025)(13018025)(8121501046)(3002001)(10201501046); SRVR:DM2PR03MB384; BCL:0; PCL:0; RULEID:(400006); SRVR:DM2PR03MB384; X-Microsoft-Exchange-Diagnostics: 1; DM2PR03MB384; 4:qjE1vTm29PMT318BOF3nrlYVheI5wByDf+kIyVxQge3TyGyz0sP8LhIQIvVio8iQPBNpkjEQe6JD0O20o3oim1ko5Y3nBG3SQHpAmb+lccWFpAIRB5CrdQ5eHi9KEWxEEANGjryxBD5LJX0Y3Fzxm+sSAGJCkOn5c3lj/iIahsW3XLSQ9NQjIpNlbyXQzVdYH4TCrR6o5dEuJ9plEiFNcy1oHnfVqMbDRKZcqkPL8p8GdRvT7qcumPe/kvTqoQCXK0Ftit5ygzcuXasDRT1+5JdbA6/ICceBhG3BJklcLC+bvYOpKD1dDk4AV/ADXG+pLsRJVM3LLwzoNO4ArxpXVtSRMox1sgYtjut2Oa+rh5raGD1GUlwNVS9dnaeb2Q3QTf2s15/YLyhdX2N/fmi/edyxfxCfYtZ/4QNsgY8MNQ+f12G7wHvDhQGhkWIaqrToZsGVkbVSVZ1ysm9FQCb8Cg== X-Forefront-PRVS: 088552DE73 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM2PR03MB384; 23:khNvuDkkUR+2xMnu73xgSIZvsVxnIGWzgqpmyALVB2?= =?us-ascii?Q?pyexSy35DYZJGQIoBvftFMwywQxPdaCREnuwZFf6qj5Wncnu5fk9FYwYLwDP?= =?us-ascii?Q?ehcztE9jxS+cLPlTrRq16BN73wjiRZg2zRdC+QNfFkvxjRkDSfU5xlTq0rqS?= =?us-ascii?Q?sPD3Yke2R5JPFMce8Wxlej4b39rAT+F+1kxjBGapPU0tVgHpDnVwaZwkVWOl?= =?us-ascii?Q?Vj7t25vcX6lP3gBJ5jMW1rMuNTPnt+3oxmtCEUjyKtTEM1UODSYdj1wPkAq9?= =?us-ascii?Q?mGK6jomu7PwxqmBd8LGooxpzk9EhDZsRcwcA98nbOh8sbCJcrFgLB+yZAN77?= =?us-ascii?Q?quUQI4CcO3HZiURTVkChCHGgmigQYr481huUz578Du57m+pcFJrOUOXf4iSL?= =?us-ascii?Q?RIElw8dRoqL09WUXEoBLdEAMJQEFjH2fyWUoQT4Sl2p81MACpRGaEyMpbcwe?= =?us-ascii?Q?3A06kDKXFaWM1JktajG8wTpks+YsWSW1TpsLfNExYOZ4dzgAck6AxPskTzyx?= =?us-ascii?Q?T5uYu16Xep0DJK+TnbxRumvvEDY4uxzvEJmeQ4NpxKJJPOwNEPWMrHvXk/zy?= =?us-ascii?Q?hNYOU3o9N5wbom+rPhOpJVlWMWRC3RVaDKV9k5QHFQCVReorJ3nWc+jl+cRr?= =?us-ascii?Q?d5MEhEk48x7G9Atry+llAcUfymCy7onaReW7SvQuVhPd+CjGqEW6SstuhDI7?= =?us-ascii?Q?SQcwEtf8D3iwH31CheJ4btCTQpzzNA2hJ9apOOgAKfkFW3tOV6y65rS6FEXJ?= =?us-ascii?Q?af65f/xZZG28mMv84Za+zDjxKFdYyq8fUft+RPkthZx6O/q32n4NFsYDdw5V?= =?us-ascii?Q?sbikGE8geSrio1ZgzynlgaO2RiRYVGxc2okAAbkVhOE28StejKTfr3h76SdO?= =?us-ascii?Q?aoCN/KYSqTQ8RUquEPviEp/yLHxkpJymR4sJP2vVBw653lUONGTds+a+vrz0?= =?us-ascii?Q?MX10UN6WWPgF3O/BDgcsZiy70aoc4oNrdxjXQsY+e12d85WAnZ2g29Aiz4Cv?= =?us-ascii?Q?64BGLDZV4Y/m3rr2Y/ph12SCyX+LntYaV7OI70ByjEWw9Zto6NmY7SMAevih?= =?us-ascii?Q?MwUAb6B6p0Hlj0cQM7ELzjj9EP?= X-Microsoft-Exchange-Diagnostics: 1; DM2PR03MB384; 5:W3aJDf83XHpnJwp95Sa+htg8Zfdm3LdgEta3SEh40k7WekvkTyg9lo8OFaAmqFkNuMDJYjnvr6XG3Gl2YaJqLIczcSYM+01g4+BlA1e2C8duAmNUYuLIZqPrEPXaOhpUDDtg+kZkDoCUHyi9mlDDGS5HdhtC9ubFLeF1omnanX4=; 24:mV94nV+iNOn6CXioo+vSvLa81xSjKPazqcKkvoqR9Gu8ZnbLmgqYzxmlRAJ7HDcQ3DLmt9e3OzzejeDwMqmqSbYAEgBC3Cbzb7Xq0f++fEo= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Mar 2016 18:32:26.9376 (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: DM2PR03MB384 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.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 of RSA's algorithm output. 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);