Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp3271107pxb; Tue, 20 Apr 2021 04:47:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+JkvtWvvqFF5tJexz/7hcp9TiQbSwLk3ru2zjCrhWIxp2wZE0zdE8YjunYeyqj/UB75gb X-Received: by 2002:a62:8f4a:0:b029:241:fc67:d425 with SMTP id n71-20020a628f4a0000b0290241fc67d425mr25077251pfd.21.1618919239490; Tue, 20 Apr 2021 04:47:19 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gw5si3034127pjb.21.2021.04.20.04.47.06; Tue, 20 Apr 2021 04:47:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=mimecast20200619 header.b=H6vO2alJ; arc=fail (body hash mismatch); spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232138AbhDTLrU (ORCPT + 99 others); Tue, 20 Apr 2021 07:47:20 -0400 Received: from de-smtp-delivery-102.mimecast.com ([194.104.109.102]:22092 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232143AbhDTLrE (ORCPT ); Tue, 20 Apr 2021 07:47:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1618919192; 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=H6vO2alJRZp1QEZFhIdwr8ychC03GqqZIhKm7Vn6cieLp1R1DrLKElWAGutw93c/yCwPqk d8piYqDWTGA4WJwGxP0Uslx8rKaIClIOb7/gUGCKwfMmgMHm0tgVNgo06NSwiOUt6vI31s hyo2LHRl0p/GN7Af62wKYXqMrtxy6Tw= Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01lp2050.outbound.protection.outlook.com [104.47.1.50]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-15-ZNLBFaSyOgaGRSWf60g7Og-1; Tue, 20 Apr 2021 13:46:31 +0200 X-MC-Unique: ZNLBFaSyOgaGRSWf60g7Og-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=h7YApRX77Pu662NGBfbk8n2jqmePAGkREWaT3EZMRDymaN7srZ2O/vfnIwdar4GVQZRJq0BiOqXRcRIq7jWKJgqDEBE+SRRbkVeESapx9flJjFeMKO0Gzea6cojXCBulBfF4GJdr4QHKT5arwT0KiScIbvx/HNUkTYoX3e0icf1lzhG4VMfT8hNRKZlz6KiuVtBjJf8WQ9SxkSnm/anRytem5CSsessA/PcSKZFWgWe4EulIQuqAI1wT5euHBtofab1y9VMxcPX996MK25xVeFzfmGo3cxTUY1OP6uo4RKctRsARZwzUPywu4SNICPf2h1Ah18MAlVZirLvHY1arUw== 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=G5NmWNrilFaydDAF0jzsUmFRbDJNg1biD+2re/Iv6p2Z/kyF5dvhkBRSUsoxR5ftdaEx2+rb8uz0LLJ9VUMoWDdAfffwWgrXn81DCEB4SUQFUF753G2upJLgb0aN2pppCgqTTfQPBSXsxdhI8Rcg4FSwBcHnxywXE0NFx+6/9wazWGTSHSqXLkzKFQqTryLewQ28MCrGBJUoOmTdI2BmG4TzY9f1OmRvKx4Kxo/QPoaqy2YSoVQpJd1mbl2sGqAfhU+hP7VYlqKPqT8sMBdtgDDpouTC7pQrX9bMrwKEDwHaYw37x+mVzE9/IbVNOvut3XjHf16IP8xBYR+kyvVCFw== 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 AM0PR04MB5154.eurprd04.prod.outlook.com (2603:10a6:208:c4::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.19; Tue, 20 Apr 2021 11:46:30 +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.4042.024; Tue, 20 Apr 2021 11:46:30 +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 v3 08/18] crypto: rsa: Move rsapad_akcipher_setup_child and callback to rsa-common Date: Tue, 20 Apr 2021 13:41:13 +0200 Message-ID: <20210420114124.9684-9-varad.gautam@suse.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210420114124.9684-1-varad.gautam@suse.com> References: <20210420114124.9684-1-varad.gautam@suse.com> Content-Transfer-Encoding: quoted-printable Content-Type: text/plain X-Originating-IP: [95.90.93.216] X-ClientProxiedBy: PR3P189CA0083.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::28) To AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from xps13.suse.de (95.90.93.216) by PR3P189CA0083.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Tue, 20 Apr 2021 11:46:29 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 70643ec7-10af-4ac2-3e7b-08d903f1efff X-MS-TrafficTypeDiagnostic: AM0PR04MB5154: 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: NcvpiVK4rdAIQXfcDyRXtMWjtyeIrgPUeHyaYQFH6V7vmlOLTYAOvDZh++3T2IFuz6VVxZyD4JJ7Nu3eSYjI73vBnUaqb1ksKzQhu81U0xUE1mt1xFI0EdhBz5123Kb/3r2lfr8Y2BsTnhRLjwKAvTOEILoLUrf+V6G5+LlsxFNXxYWfPpCavRS9q6eoaKhm2jtdjYNsOumERlqOac5520pg1q/trj+IXDDFezlKiEe/R07dlAWqKCj07A9m1FjvJXdjVaFjYLsXVRyFr8rJhc3JLt5n7QxZgJvuddvDhSNmXCd5EbT/RKvl1SQ6aCel5Abi19y51WxNXo2zP5RFCFKv9Rsdto1XBhQCKCOwQ1eTTO900PCxcpNg75zqLWmyLV+YCaXFdbHMii0pOUTCLckPE/Ci91mnc0bYJU6sNT/iP1WdxpPq23H7OwlxEY2tEPqY1MxcEeZroXuJ1js2yRy+PDXg14CHeFHigtQhaIGXW4WxYiiY2/M345lvIUzd21fXddxU1zpilys27KKJmV5hSmR1P34I2+WM8eoJ4Sr0JrCKqUxBGIfOPB3Ji/BWTuDkUVVSHzz0g7UZTY72zKaq161WFNXiigcfwA3FnrArk+ZFjtbXoOYKTWDroLaC/vcMUqZnAxgzNCAKWSl+Ru9MFqVQKNviz5KcQH3vg38hm2vBQ+gtUXO1oy1tRh2Y 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:(376002)(136003)(366004)(346002)(396003)(39850400004)(26005)(16526019)(86362001)(186003)(956004)(66476007)(8936002)(5660300002)(66946007)(6506007)(44832011)(4326008)(6512007)(6486002)(8676002)(2616005)(316002)(6666004)(66556008)(36756003)(38350700002)(52116002)(478600001)(38100700002)(83380400001)(6916009)(1076003)(2906002)(473944003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?CoKouxK8AvihHDxD8Cv5avNb9qsxEnudJRp00cVcStA2plEw8XJtbdH9XRrp?= =?us-ascii?Q?jy+l7uYzZobnrR0g1TSiOHdaxbXVU5cIeF/42Hp5RkdO4RUKhAzcRfPIdIJQ?= =?us-ascii?Q?qnwEXZfTqO9pEOaMp3Gw4Pl94vFTC0zfvNHBbmllGDoJBDJz9S7MlImo0DFf?= =?us-ascii?Q?xo7uLUcjD4uAVlhDSt25hT/GGaCCkUY84vta5TL6cmcc5Sxz9uOkWBmddOx5?= =?us-ascii?Q?fnvrmgIXOjp3qpztCnkSaQx4j2kNrzgfvHes1IpHwfJ6aTMt0km0WePBtV0U?= =?us-ascii?Q?OnNuJ6Pr9VeqZXMYKiil+fkbpe1scP9jABZ4WPFzkKkPzYWvRNclaRKnDi4C?= =?us-ascii?Q?2A/82JRBCXZIP25WjpCZ6ZjUX8m03DVwNkf4UWvAjTmA6YYGOMmEvmujpApE?= =?us-ascii?Q?sszWsqqZWp9YRJn/tALGEc31oaqGGgyWhgunD2EjLpaawG/XK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IIOj?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 70643ec7-10af-4ac2-3e7b-08d903f1efff X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5650.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2021 11:46:29.9169 (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: zPnBWEYDzKLHrsmlKLSvaXukTN3O7th+NZhWdfO4AFGS72Ykl/fjcI8n8+0p03+LzLiC0is7gG8NrRRvFyBoyA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB5154 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 ch= ar *name) return NULL; } =20 +void rsapad_akcipher_req_complete(struct crypto_async_request *child_async= _req, + int err, rsa_akcipher_complete_cb cb) +{ + struct akcipher_request *req =3D child_async_req->data; + struct crypto_async_request async_req; + + if (err =3D=3D -EINPROGRESS) + return; + + async_req.data =3D req->base.data; + async_req.tfm =3D crypto_akcipher_tfm(crypto_akcipher_reqtfm(req)); + async_req.flags =3D 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 =3D crypto_akcipher_reqtfm(req); + struct rsapad_tfm_ctx *ctx =3D akcipher_tfm_ctx(tfm); + struct rsapad_akciper_req_ctx *req_ctx =3D 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, r= eq); + 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 =20 -typedef int (*rsa_akcipher_complete_cb)(struct akcipher_request *, int); -static void rsapad_akcipher_req_complete(struct crypto_async_request *chil= d_async_req, - int err, rsa_akcipher_complete_cb cb) -{ - struct akcipher_request *req =3D child_async_req->data; - struct crypto_async_request async_req; - - if (err =3D=3D -EINPROGRESS) - return; - - async_req.data =3D req->base.data; - async_req.tfm =3D crypto_akcipher_tfm(crypto_akcipher_reqtfm(req)); - async_req.flags =3D 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 =3D crypto_akcipher_reqtfm(req); - struct rsapad_tfm_ctx *ctx =3D akcipher_tfm_ctx(tfm); - struct rsapad_akciper_req_ctx *req_ctx =3D 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, r= eq); - 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, in= t err) { struct crypto_akcipher *tfm =3D 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; }; =20 +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, --=20 2.30.2