From patchwork Thu Apr 8 14:15:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Varad Gautam X-Patchwork-Id: 417576 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6CF04C433ED for ; Thu, 8 Apr 2021 14:16:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 50D4061153 for ; Thu, 8 Apr 2021 14:16:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229803AbhDHOQ5 (ORCPT ); Thu, 8 Apr 2021 10:16:57 -0400 Received: from de-smtp-delivery-102.mimecast.com ([194.104.109.102]:60690 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231990AbhDHOQv (ORCPT ); Thu, 8 Apr 2021 10:16:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1617891398; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=96DN941Ef/gymzsqU9SPmXm1cdxD7+/+a/zlrCm7hnM=; b=e1G9MwjfObHAjERyVisDqiwhS0u+hAq671cihnfHk3i+VhdPugVzZCorg3TkfuvTCfERCp VB/Y+vm4ZgNON700t0v6N7K0+725c+g7q3v+S/RI+EHJF0ox0wdptrzBKwXXNe1/M8Xl5b wfRuKpMlsqVrenKd360r5gbPSOWNkqI= Received: from EUR03-VE1-obe.outbound.protection.outlook.com (mail-ve1eur03lp2054.outbound.protection.outlook.com [104.47.9.54]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-1-Ft4tSEzDNbe_GsUI_sFm7Q-4; Thu, 08 Apr 2021 16:16:27 +0200 X-MC-Unique: Ft4tSEzDNbe_GsUI_sFm7Q-4 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ecn/gqBFy/bFB0c9wcNA3mcKJXNdF2VEEKK9R3O4hOwrUvfHniOnAD4/8J/Lr0ataZfUmAaRVTZnQI5iRp60hs0LvU9vu5MnfHk7zNHKu8Fre2JLqN83XXyB5oDNVaLZ+K64FLmje0BaADG2uV8nrPwYU565kS5Ogfpq9TEdx/Yaibi05vwciTlC+jqeQ86bK3oNgnIKhER3BMfsHXSMhvAKIoQ2zi/L43KpG/egvfZ+uOF0nl72czL9EMLgAGEEjJP9P4l8NWIqD/4Avc1Laab3WuLJoiRAcvtLtNQKBYDnORGh2jIGLMVad7xfR6d1UhMG4nufbY+Rb7m2GDwJzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1Sa23WQs3NsEGBLTmg6WpJVp9KxgVeUeR2V32E5DXSs=; b=k+Lle9JVsQkzoOAkPuPkw2CnrDxZnWy0uevWizVFntUcZAzIuyTkZvGJl51JlDbN5FHGuNYUsOzfRilWZQl1ikzKFukUIXAxzFqqzwnsRUXmnn6/JVUc9mbHaaDbDHB+PnRZSxF/VRZttzuYfYIDA/HYeoBRNvGK5cqofTOw9lcsVBGcCkRf3Gor7baYrl65H5sQybj15FvwEPH0r6xpwx4I7GceXYoz6IWqwaehnVI4scL5av1GatgyOc4vWkVsP6DkOgHQLoJgBUDlqvSBZ8VLICLBMAtR60mr6oFzQelUFD8I6lnm1l9ap+Kf1q/ZCLcufeLTX+fGdg/THhO/Xg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=suse.com; Received: from AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) by AM0PR04MB6289.eurprd04.prod.outlook.com (2603:10a6:208:145::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.18; Thu, 8 Apr 2021 14:16:14 +0000 Received: from AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d]) by AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d%6]) with mapi id 15.20.3999.032; Thu, 8 Apr 2021 14:16:13 +0000 From: Varad Gautam To: linux-crypto@vger.kernel.org CC: varad.gautam@suse.com, dhowells@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, vt@altlinux.org, tianjia.zhang@linux.alibaba.com, keyrings@vger.kernel.org, linux-kernel@vger.kernel.org, jarkko@kernel.org Subject: [PATCH v2 08/18] crypto: rsa: Move rsapad_akcipher_setup_child and callback to rsa-common Date: Thu, 8 Apr 2021 16:15:06 +0200 Message-ID: <20210408141516.11369-9-varad.gautam@suse.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210408141516.11369-1-varad.gautam@suse.com> References: <20210408141516.11369-1-varad.gautam@suse.com> X-Originating-IP: [95.90.93.216] X-ClientProxiedBy: ZR0P278CA0137.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:40::16) To AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from xps13.suse.cz (95.90.93.216) by ZR0P278CA0137.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:40::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16 via Frontend Transport; Thu, 8 Apr 2021 14:16:07 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c9a6d10f-5f6b-4e2a-f0d5-08d8fa98da56 X-MS-TrafficTypeDiagnostic: AM0PR04MB6289: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:185; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Ybx9oqeXHRlFh4GkPHKjyBAYerFOLC/BKtshcilpZmh41HvhgvCnb+h0DEw6qkLxjKSPgKUdmAshzMzrXzVXRTUg+jLWRjdOBIXhAU0nZtf4jmoP9NwRPIj0vNJNXV6I1kerky5mMmqmnWthbioofM17TqCsvG/LuklIsxDTWEVzns+Xj5MOE39CkIz133KgrO38lnAMkNpZsAFuatIGBwMcbFZwi36cAd07wPCFaQV5f1r3OUadHaOSA1RX7Z25LHQr8Q83g2s7LHdWRdKjMNJDn3kj+qrFBes/28aCdNkJdkSyE1j7/4flcBYfIm9GkHurVmgTQ0eOyrr+1azTewEG/01uzQDwGA2vhPSkuo7EeJdFuZkBx7RH07mfu7/AwufaWARrHGNjrjZHnCUxGCged3rLAUqIpv6ykTIPaEK2H4UtT1rqGBYmROIlx+0kDkIT2rf6o5ksKkwEAXrHdOIKqBBCg54/zJ59ZKbX6r/ZadW1UhJUOaz7omRdhZMqH7s0jxpCh2WMjXoaJW1og4vpYnpYaeuFNxQStUFYrwpl3t2z2SsEuONAWAUV3mt1jAun0SWKI4s6h8ylYec5akyaJCa0Ymq4HUOvMSlJN0xqqEmNfBP9ODFCP2WKhc/jiKpiZv6xJVSIJZSj/cYeFRNpRIoUtnhF6TKbgc7PDvGMMCFC23GXNA7yKq8mgovkl5qG5A9v9Ph9CxrWwSSWlQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR04MB5650.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(396003)(346002)(376002)(136003)(39860400002)(186003)(83380400001)(16526019)(478600001)(6486002)(38100700001)(36756003)(5660300002)(4326008)(6916009)(1076003)(66476007)(316002)(2906002)(66556008)(26005)(38350700001)(2616005)(956004)(8676002)(44832011)(8936002)(6506007)(86362001)(52116002)(66946007)(6512007)(473944003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: BW6WZiNYxD+8/YNcl2HxlD5rgJMTf+n8QLbNxqurDVHC97YeEa9euOClnwaJ1ntSFJoVwiMG0cBGGqnLYbfYJx6n02wMX2SjNnSC+PuQ269hsrHK4TIsNmlqQHn2DBm+KVwDRM1199jjQH+y1NDdQZkdi9lE17UC/19KTHIDFSdgym04chdoQSoSW4v1w+Vl4MUVwqFpQIanTVb/cXcfqibBmgiRKa22juzBQjBoFzTebnxPNDnwEbHFJmwVZa+vZyATMBazmAZZggpTwizVO0ffCALzbCwOSB07OgRckAdglXFUWi/mJXx4cBOChdYR040K0wSA9Dd8ZmKZZrN0b2AY/yDtPhL3rAsvwIF8kFG7ubTZHE102njZHnbMOiZojv9Y4lDwZHY4L+xYfJw2ipnLCUTF/cpG+I4JmONw9LwTRmVupI2L9UzHVMqHq/T4ME7x7a7OWhCDE6yvahEWV3dVfbkfp34akXn6aiyecqaasDVtKUPQIHMrjGdwvwx8nqmmjY9VPaCkgukucKpviXeG/CjBHQe1oLO9zyHz/fUPcB3FhiladxqU7eRH3LKP8agyemkHwLXrzm7PcaSBPdeUXgv5F13zSfj3zpuLJ2rLm8X++MyV8y+TQ1oMGYO5SyW8V9iCCw3bf4RZ1NDlvkMdO54cT7oYCeCQ4PMofI44cJho4BFwDV1jT8OZyQpEI1NOIYp4PzNrl0kPOGSHUDS+5jcUnfJ45RfDxvqshhIWVDJGr/tCxqLwhhh3L34fXQAwW6L5TND2wXeL6WDMrwrAkrMCEMXjSIBDSw2lcTNxBkSsAIro/1guYA26ViLwmaAkWC3o13NDTcjClHOhSouohS5PbvmHuhwJRFMyfiThSGJmnuYuWkKgdR9ZpRXNYqquP1u5uGctVmF1I3sfw266u9Y2r6xHq+FFCRYgPz35RMc/f0x2+mNdacilOUtZJhk8VeaaIe+pThWyaQGEh/6BjtldFWQlBLwIOaVtsWrkZuC72gSuBe4X0NnlMoALhBpuiT/crLQ2vevTFB/0qUPOokiLuYCZYTIUx9byepmRzXp+KWEZFY5KTQbRH1zlKe/qwNPBPbxqGrMqzv+WJwQ84jzl+yY4nL37Ev5ZiLkltZEqYEV5ji/fSYAxDLMCvZBsCBK8Y9vECi07EISax6NsqmEu4ZQLPTKZ9DN4JGSgu7QrDL3wuJkOoy0rawS+e6HtXb8S5fKKvhzhwJEMJhL4Vf6RzJM02PjWU6to3f8TWiq8CSXDYnZr547vJgsr9gYEXchpX7pKZZjfa9GNBZ58a09MoOWqeN+Uiv/EiF0hC0TQgXWAKBz+LQt7y9eW X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: c9a6d10f-5f6b-4e2a-f0d5-08d8fa98da56 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5650.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Apr 2021 14:16:12.9499 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: DeeJmq5HYfTpzBBfZdrGZJXhPGQjS13ljawHDz5VcSxHs4E5NzbjniHJrhhtJChVTV0Lp8OTbAUDvBNDoGLJxg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB6289 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Pull out more common code from rsa-pkcs1pad into rsa-common. Signed-off-by: Varad Gautam --- crypto/rsa-common.c | 31 +++++++++++++++++++++++++++ crypto/rsa-pkcs1pad.c | 32 ---------------------------- include/crypto/internal/rsa-common.h | 9 ++++++++ 3 files changed, 40 insertions(+), 32 deletions(-) diff --git a/crypto/rsa-common.c b/crypto/rsa-common.c index d70d7d405165f..6ed258a782875 100644 --- a/crypto/rsa-common.c +++ b/crypto/rsa-common.c @@ -75,6 +75,37 @@ const struct rsa_asn1_template *rsa_lookup_asn1(const char *name) return NULL; } +void rsapad_akcipher_req_complete(struct crypto_async_request *child_async_req, + int err, rsa_akcipher_complete_cb cb) +{ + struct akcipher_request *req = child_async_req->data; + struct crypto_async_request async_req; + + if (err == -EINPROGRESS) + return; + + async_req.data = req->base.data; + async_req.tfm = crypto_akcipher_tfm(crypto_akcipher_reqtfm(req)); + async_req.flags = child_async_req->flags; + req->base.complete(&async_req, cb(req, err)); +} + +void rsapad_akcipher_setup_child(struct akcipher_request *req, + struct scatterlist *src_sg, + struct scatterlist *dst_sg, + unsigned int src_len, + unsigned int dst_len, + crypto_completion_t cb) +{ + struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req); + struct rsapad_tfm_ctx *ctx = akcipher_tfm_ctx(tfm); + struct rsapad_akciper_req_ctx *req_ctx = akcipher_request_ctx(req); + + akcipher_request_set_tfm(&req_ctx->child_req, ctx->child); + akcipher_request_set_callback(&req_ctx->child_req, req->base.flags, cb, req); + akcipher_request_set_crypt(&req_ctx->child_req, src_sg, dst_sg, src_len, dst_len); +} + int rsapad_set_pub_key(struct crypto_akcipher *tfm, const void *key, unsigned int keylen) { diff --git a/crypto/rsa-pkcs1pad.c b/crypto/rsa-pkcs1pad.c index 30b0193b7352a..6fa207732fcbe 100644 --- a/crypto/rsa-pkcs1pad.c +++ b/crypto/rsa-pkcs1pad.c @@ -9,38 +9,6 @@ #include #include -typedef int (*rsa_akcipher_complete_cb)(struct akcipher_request *, int); -static void rsapad_akcipher_req_complete(struct crypto_async_request *child_async_req, - int err, rsa_akcipher_complete_cb cb) -{ - struct akcipher_request *req = child_async_req->data; - struct crypto_async_request async_req; - - if (err == -EINPROGRESS) - return; - - async_req.data = req->base.data; - async_req.tfm = crypto_akcipher_tfm(crypto_akcipher_reqtfm(req)); - async_req.flags = child_async_req->flags; - req->base.complete(&async_req, cb(req, err)); -} - -static void rsapad_akcipher_setup_child(struct akcipher_request *req, - struct scatterlist *src_sg, - struct scatterlist *dst_sg, - unsigned int src_len, - unsigned int dst_len, - crypto_completion_t cb) -{ - struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req); - struct rsapad_tfm_ctx *ctx = akcipher_tfm_ctx(tfm); - struct rsapad_akciper_req_ctx *req_ctx = akcipher_request_ctx(req); - - akcipher_request_set_tfm(&req_ctx->child_req, ctx->child); - akcipher_request_set_callback(&req_ctx->child_req, req->base.flags, cb, req); - akcipher_request_set_crypt(&req_ctx->child_req, src_sg, dst_sg, src_len, dst_len); -} - static int pkcs1pad_encrypt_sign_complete(struct akcipher_request *req, int err) { struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req); diff --git a/include/crypto/internal/rsa-common.h b/include/crypto/internal/rsa-common.h index a6f20cce610ab..4fa3cf5a989cc 100644 --- a/include/crypto/internal/rsa-common.h +++ b/include/crypto/internal/rsa-common.h @@ -34,6 +34,15 @@ struct rsapad_akciper_req_ctx { struct akcipher_request child_req; }; +typedef int (*rsa_akcipher_complete_cb)(struct akcipher_request *, int); +void rsapad_akcipher_req_complete(struct crypto_async_request *child_async_req, + int err, rsa_akcipher_complete_cb cb); +void rsapad_akcipher_setup_child(struct akcipher_request *req, + struct scatterlist *src_sg, + struct scatterlist *dst_sg, + unsigned int src_len, + unsigned int dst_len, + crypto_completion_t cb); int rsapad_set_pub_key(struct crypto_akcipher *tfm, const void *key, unsigned int keylen); int rsapad_set_priv_key(struct crypto_akcipher *tfm, const void *key,