From patchwork Thu Apr 8 14:15:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Varad Gautam X-Patchwork-Id: 418317 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=-15.9 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,UNWANTED_LANGUAGE_BODY,USER_AGENT_GIT autolearn=ham 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 8DA81C433ED for ; Thu, 8 Apr 2021 14:16:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6811061132 for ; Thu, 8 Apr 2021 14:16:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231819AbhDHOQY (ORCPT ); Thu, 8 Apr 2021 10:16:24 -0400 Received: from de-smtp-delivery-102.mimecast.com ([194.104.109.102]:27012 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231892AbhDHOQV (ORCPT ); Thu, 8 Apr 2021 10:16:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1617891368; 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=cmUAdFJ0uQw14A1uRJhYFxeqhrEmpnRdb5fucZevEH8=; b=fGlcoX8rvKRT8gJ9xr9grhsA+3R5WMUqZtF3hRI/sF55nFORQnoFXiLrjR7HQWjDLAUgXD mRAp32yC+Y/X5j5kKTcoTs9RwoF/Bm59yAznGlhd0D70V3nyHQVh7EX663MzG8iz8KFkX4 3bi1fcxpWkEh8oJIVu1tu9j8i2k87q0= 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-hp_enYxZN1uqXJ_i4yPCAg-1; Thu, 08 Apr 2021 16:16:07 +0200 X-MC-Unique: hp_enYxZN1uqXJ_i4yPCAg-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JgaCdXJk0DGipYkmRq5X4pIUnDwo0K/NxDDpZiRRLCQ3nkwJ85sO5QQ2XXOGUcu9SJe2Bn/1ou/wV8kMhSFAwwUNK1/1cEi7vPveP4TXa1F6zaciF3CmgjP8bkq8fvLo/ymoY6O4aKquZTvArykTmTYz84LkK6jF6eM5+PwG7YsjQ3RP2mhQqqcHjl3GMwAV5Z2Cjw4hlZH7seJHbp/fnhj78g8z0dhEC31uhslsnub2qUtnQ2wlzyxrXu8W09VVYDBC09Dm2v/kCQBuTlZPhhIRUtZWPDndppu0QeyzgyNadnY+RhC4i/Jveiz5t4zhUHfUStMhiKmDsmZxt9czCQ== 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=93i75lPbvB/8koH1C6/WbV75u4YZP4Ne/6Qzxao+vC8=; b=fjeKJtiUeYvXFjdo9QoNIBxUdFjNTxM2kIQoTKJcp7ActWD2bCraM+F4heveOUg8/CoD9sB0yRuvIH+kVxzPldGJh9ijUWqNO1ABpfU3fDI31fKmJ8I2TgYL1KQEO3U7URsJ9i+oyncFTg4CJnS+EkKsFfq/lVCe8xHHoqVTmT2sE+HqO84pjD+ycrUmhHWM/LSIbbamrcauNudzIxNpGGKfXAGm2IiVE3EotJemfo1xnJmCIkAzQ4wEfIw661wNl1G9uhkQqiacIqaxNzF22S2MF92kAG7kVSvHX8tBEk8NwaSTD0GVbJSpPFXDl5bmNdcyX8DZ5HndRcL0lDMZhg== 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:15:56 +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:15:56 +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 03/18] crypto: rsa-pkcs1pad: Extract pkcs1pad_create into a generic helper Date: Thu, 8 Apr 2021 16:15:01 +0200 Message-ID: <20210408141516.11369-4-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:15:55 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fbacf15a-b043-40a8-54a6-08d8fa98d37d X-MS-TrafficTypeDiagnostic: AM0PR04MB6289: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:98; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pyMxu3B8G1b+hK7CJk1UYJqsSmxR8FbA3eNI1Zb6GQBSTP+hYj+d1UYNTqbeRBv8FL6uDtdD6ZYZXz/znIJhFYyuQVXthCZ2ZkZqZT6tKgt9JG9tyKNl1B3xoI6j5AxuBzh8W5Fk/uwFf0UEW8ry+74aTdf4hIWjTkIYcRwXjlDY0yxVcp0J5vjD7JbZqRe2nJPxzw9Xu9Ajj9NOKci5A1FQ7RabC/GjJIBV5PNzzgnH+kLwS+XBqTW9ATMTSDUBezR9tLbv0c8twFPrKKN6SufgCra/wTtUp43aoOL5HG3D0NJJHQVk90xcafUFjuc7eLfCoabuXaCGUWjBD4MwxenxxRxYnJ/vCVV8v5S06Z6U7V9hRrlzj3QRlDUFyjPK+/mj3NRogCBOF+0v9oEjuCIPm/FofwD2byXIyowEDan4wP6nOCi4VR9BKqW8Pi9x5DBtYrZci4qOT5qJgN5CGZZnO0CEAcPdr9SPWPCGkkt3/Hc5SyzQ0ULzDB6ucxcKpy2Es+kScepqBotIsKoWBpffSuJQ0Ze4mFru0fZXfP+phfvd/X2YDEO9m1lw2Z+bJ5IEqfhqu0dmqyeKt3XG024MkerzeYR9FiGqD98Wr2qRAeSKonMpYlTDmIaoLLM5OUi9MWzBrrYD7oZ9oCqeSAcF8l0H1UrvY8qOim5NKnNr2yK5tSVjVQI4knP1Ew8QMWahvlMqcpGFtCxam2CfsQ== 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)(6666004)(956004)(8676002)(44832011)(8936002)(6506007)(86362001)(52116002)(66946007)(6512007)(41533002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: PzTDZcmo/TcQU02mvb8KNhH1a1mgZOAQUBg/LnI079uQD6FPU6GFspnmMXV+NpgQaAoOUioJ0S2CyywhwIIPIr/4PFbo+4VoH9BcA+vx2LJYUxpkSJKY+4aa748e1/mnYZWrPlD+ShA73w9LpmAcJ9hUJeZkHJzBeWi8sx/jUtgZ54Hpa9kJAxCxOlaLIBkzDUAIdvNZVtDMiUz6D4CrA4/1g643DvW87YMLzIyNEPBfwpw70VIdj/ZXSHwqgh4DZpE+BXgcMQyQeVnmbgeNTLycUiIQ0n2R6cL67PsUOEvpeHJ8uKFk79vFZhhITeyS4L717aW17HNj/4+eg6oocSeEOzRWuSVUZ+e4m8B0GM4dYHfZiUbA8MNq3iGbFhzQFtwwL6PwHXGwTrVE806hu46G1DR3ZO20gAioq+LyYCcRkzZrohv/AnXMuu9jQg4sj4VqfHXArowQ24gsF48A9CXmMjUOkOpJtmUbODuEpRWxqgIHpUHcrIgjEurrMoz4OltOXZOp5EiuUfIRh8Znmpp09KQ/PQaScprbXgY4XkHxdCwpu69IH42zLmcAiNpZfAROlaQEdVm85x+ouYiS+NFqQHYz1MGAqUMCHkM3X+mwewR3s8BOT5Kdgonab0RRLNvlW/yG96YCQJe4ncPq5oYCs3U2TERkCOtQLuulkLh4pn/XBuvU00WDG+fKe++YB1CcKMDeIQvkOOAFg0xFeyHZfe2+S4IF3/X1yuWGBMWXmA7uJwaj19z8w6M17TehQP2i7J3y2M8W/t2Z0YmBhEMwIE0qVk4ddEhrNSirJdD3C3D9RnnjiMDa8Z8P/KhgvoeXcDMz5UQiVG3P4DAR7GGfZ9Ournb8eYPWCqKpJoBRCB1u9G/GUZpxjlYsHcIeg7e5xFyXbkYpi9PGqJ370aU99mEsa7vbNvv5B5lTa/P4JHO4hkz+leh4i4MjGE5j9kdmqZg7Ggnuq4awRazm9yrPlgwjTKqUyenwqYFdj3yk2+avCPZUfWOLxfO8tPCQsUTjJx6JLCK7bG7qFOZhTXXqcW/SCL7G+mKyU3y+ZPS+B6LTqFXgy96jbEpNROPxgRXOVTZiobDpfiewlD0AQogp4KFQfa2HyrLN535dfEFKY0xOTkGyih+WvhH4/A5u6HeijKNyLzpRpPCySxwHWbO4+oDSeJKwkkHKUdJcAXhz/K/xvr9BRrGCXfnUtefB1yJs2G5cV1d4tIRpnOa/7HjJF5uY4SdtmZNif88nlTj0JkwEqL/QiMWNbFCj98X/Txvz0UoxzUSBwXAq0Zi2kXklNve611xlvDN0k5QVK5dEVl4axsnvaKu6Vwb/cCPu X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: fbacf15a-b043-40a8-54a6-08d8fa98d37d 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:15:56.4363 (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: OLApZPyi6+bgWbLZJnguyNd+4sD+uMmtxOzJaNCu5RFpLWXclw8RVCAVFWNCuqESLFKWh9RgGgSAWvuOC2FFWA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB6289 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org which can be reused by other signature padding schemes as rsapad_akcipher_create. This will be moved out of rsa-pkcs1pad.c to be used across rsa-*pad implementations. Signed-off-by: Varad Gautam --- crypto/rsa-pkcs1pad.c | 48 ++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/crypto/rsa-pkcs1pad.c b/crypto/rsa-pkcs1pad.c index 83ba7540a53ac..849573f6b44b3 100644 --- a/crypto/rsa-pkcs1pad.c +++ b/crypto/rsa-pkcs1pad.c @@ -595,7 +595,21 @@ static void rsapad_akcipher_free(struct akcipher_instance *inst) kfree(inst); } -static int pkcs1pad_create(struct crypto_template *tmpl, struct rtattr **tb) +static struct akcipher_alg pkcs1pad_alg = { + .init = rsapad_akcipher_init_tfm, + .exit = rsapad_akcipher_exit_tfm, + + .encrypt = pkcs1pad_encrypt, + .decrypt = pkcs1pad_decrypt, + .sign = pkcs1pad_sign, + .verify = pkcs1pad_verify, + .set_pub_key = rsapad_set_pub_key, + .set_priv_key = rsapad_set_priv_key, + .max_size = rsapad_get_max_size +}; + +static int rsapad_akcipher_create(struct crypto_template *tmpl, struct rtattr **tb, + struct akcipher_alg *alg) { u32 mask; struct akcipher_instance *inst; @@ -625,12 +639,12 @@ static int pkcs1pad_create(struct crypto_template *tmpl, struct rtattr **tb) hash_name = crypto_attr_alg_name(tb[2]); if (IS_ERR(hash_name)) { if (snprintf(inst->alg.base.cra_name, - CRYPTO_MAX_ALG_NAME, "pkcs1pad(%s)", + CRYPTO_MAX_ALG_NAME, "%s(%s)", tmpl->name, rsa_alg->base.cra_name) >= CRYPTO_MAX_ALG_NAME) goto err_free_inst; if (snprintf(inst->alg.base.cra_driver_name, - CRYPTO_MAX_ALG_NAME, "pkcs1pad(%s)", + CRYPTO_MAX_ALG_NAME, "%s(%s)", tmpl->name, rsa_alg->base.cra_driver_name) >= CRYPTO_MAX_ALG_NAME) goto err_free_inst; @@ -642,12 +656,13 @@ static int pkcs1pad_create(struct crypto_template *tmpl, struct rtattr **tb) } if (snprintf(inst->alg.base.cra_name, CRYPTO_MAX_ALG_NAME, - "pkcs1pad(%s,%s)", rsa_alg->base.cra_name, + "%s(%s,%s)", tmpl->name, rsa_alg->base.cra_name, hash_name) >= CRYPTO_MAX_ALG_NAME) goto err_free_inst; if (snprintf(inst->alg.base.cra_driver_name, - CRYPTO_MAX_ALG_NAME, "pkcs1pad(%s,%s)", + CRYPTO_MAX_ALG_NAME, "%s(%s,%s)", + tmpl->name, rsa_alg->base.cra_driver_name, hash_name) >= CRYPTO_MAX_ALG_NAME) goto err_free_inst; @@ -656,16 +671,16 @@ static int pkcs1pad_create(struct crypto_template *tmpl, struct rtattr **tb) inst->alg.base.cra_priority = rsa_alg->base.cra_priority; inst->alg.base.cra_ctxsize = sizeof(struct pkcs1pad_ctx); - inst->alg.init = rsapad_akcipher_init_tfm; - inst->alg.exit = rsapad_akcipher_exit_tfm; + inst->alg.init = alg->init; + inst->alg.exit = alg->exit; - inst->alg.encrypt = pkcs1pad_encrypt; - inst->alg.decrypt = pkcs1pad_decrypt; - inst->alg.sign = pkcs1pad_sign; - inst->alg.verify = pkcs1pad_verify; - inst->alg.set_pub_key = rsapad_set_pub_key; - inst->alg.set_priv_key = rsapad_set_priv_key; - inst->alg.max_size = rsapad_get_max_size; + inst->alg.encrypt = alg->encrypt; + inst->alg.decrypt = alg->decrypt; + inst->alg.sign = alg->sign; + inst->alg.verify = alg->verify; + inst->alg.set_pub_key = alg->set_pub_key; + inst->alg.set_priv_key = alg->set_priv_key; + inst->alg.max_size = alg->max_size; inst->alg.reqsize = sizeof(struct pkcs1pad_request) + rsa_alg->reqsize; inst->free = rsapad_akcipher_free; @@ -678,6 +693,11 @@ static int pkcs1pad_create(struct crypto_template *tmpl, struct rtattr **tb) return err; } +static int pkcs1pad_create(struct crypto_template *tmpl, struct rtattr **tb) +{ + return rsapad_akcipher_create(tmpl, tb, &pkcs1pad_alg); +} + struct crypto_template rsa_pkcs1pad_tmpl = { .name = "pkcs1pad", .create = pkcs1pad_create,