From patchwork Tue Mar 30 20:28:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Varad Gautam X-Patchwork-Id: 411820 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, URIBL_BLOCKED, 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 65C0EC433E1 for ; Tue, 30 Mar 2021 20:30:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 30FA8619CB for ; Tue, 30 Mar 2021 20:30:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232507AbhC3U3y (ORCPT ); Tue, 30 Mar 2021 16:29:54 -0400 Received: from de-smtp-delivery-102.mimecast.com ([194.104.109.102]:40154 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232401AbhC3U3V (ORCPT ); Tue, 30 Mar 2021 16:29:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1617136160; 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=/Usa2anEQfD1HDNoVZzI1ENJWTQC0PIla+85ydFxgZs=; b=UFhQ+yanArlOTo1VAbire+K8G+je8SduNKJsK/SN4JimGoFUgepqtD3ZA82eY3c3xkKB3T jFnz+iRKLYPIRzlUjgymroQsH3W0GKPLuR3zdlEeNAT+vNzfGSBipXAG1Zaiy0c4P/tXMv H4vcY7sNExSf9UFhp6vt1OhyK2bx6hg= Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2171.outbound.protection.outlook.com [104.47.17.171]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-19-RH_giBZ7NbedMS3fnm1iYg-3; Tue, 30 Mar 2021 22:29:19 +0200 X-MC-Unique: RH_giBZ7NbedMS3fnm1iYg-3 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Jz5pnoIuUCGDEoUrZSdYEZXNfs31Ez1FMAXkA305H6kCf+500MbdZqXg4vpEgbMa+8znUa/oLi2Bn5MWovNE/D7KSWsIqxrPZ6ri43RbSkG9vs1l/wlvVJD0AN1KIph1bVh0bECKPIV19MeeXZcADooHQmDk7+fyfAETNzgDcAE/VQ+e8mIVVYC0QyltuWvxuYBWZ6hputFWPDn+qr4Z7Hx+xb2N/vMoMU3uECUdrCHQPZvMVr7HnsmPMsfnfswNjPnnRbusuIyQrloE+HBhuJmd9wjANeDl0upPDpNzZ+pB+xEgH44vMq2pkDLhWb+W7xRXCQvmTeskU6LHC0Av/w== 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=tbSL2LwFQ69rW84cAtlFDOjNeTwax1Jt+e7+frs7VJw=; b=DrUxBQXde6ZHbe8U97npRfFua1TK0KS8aBUiW0kdctcts2tGpp4uunNjWF60scEzXlwMbagN5QFNEchirbFLjTqpEKGBITln4GGtdKH+YYkHOGv1impjNfnPCPt08zMaH0Z6uak48CFShsxJyb/RUcTS8+dkJQa3g05ndxzSNhgCb7dZ1tzkeuySHUYV5af2SwNnLMe9Iebt2ItDMjwCwuxrbt8me7P4GixxMgWct+uJjFTr6IOWoG+uSDy4bd1M1/hat5I34OkiPu93Oxyabm8xmePgozGofKqFAVvZMBaAb3BrtNsdqWK9VIlBrT92w/QfGGkYB2OZjIfY24n25Q== 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 AM0PR0402MB3393.eurprd04.prod.outlook.com (2603:10a6:208:21::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.33; Tue, 30 Mar 2021 20:29:18 +0000 Received: from AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::40bd:b7d7:74a7:5679]) by AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::40bd:b7d7:74a7:5679%3]) with mapi id 15.20.3977.033; Tue, 30 Mar 2021 20:29:18 +0000 From: Varad Gautam To: linux-crypto@vger.kernel.org CC: Varad Gautam , Herbert Xu , "David S. Miller" , linux-kernel@vger.kernel.org (open list) Subject: [PATCH 03/18] crypto: rsa-pkcs1pad: Extract pkcs1pad_create into a generic helper Date: Tue, 30 Mar 2021 22:28:14 +0200 Message-ID: <20210330202829.4825-4-varad.gautam@suse.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210330202829.4825-1-varad.gautam@suse.com> References: <20210330202829.4825-1-varad.gautam@suse.com> X-Originating-IP: [95.90.93.216] X-ClientProxiedBy: AM3PR03CA0066.eurprd03.prod.outlook.com (2603:10a6:207:5::24) 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 AM3PR03CA0066.eurprd03.prod.outlook.com (2603:10a6:207:5::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.25 via Frontend Transport; Tue, 30 Mar 2021 20:29:17 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 28fec1f7-e4c6-4ea4-2a39-08d8f3ba7e46 X-MS-TrafficTypeDiagnostic: AM0PR0402MB3393: 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: JZ/C/+R/wp8Rh1FWgRJ/4SBP10YY85ikOa5GMuGYiUAvPmTmvytMiG3Uha7b/JE/+JK/oLANNOiWf/h6y/3EEGhfLQYlxgFHQXPQmzf1zjDiuQleOqHJvbpoAnI/YFlOaedxJiWI7HlxAHMw3GkfhPOSx0zwGyyyURPfk2j5NbKPiiQYfS0lIoV5DYIWljbCE2dfOaby7Vqox5h4RMoN3xl1MURZIjiPD74otFnVYjICj9nJ98hLYJMob83y9dtzy1Ont1EOU/tTT68HX9KeZjXn6N2zzpNyIpTuYaTt2ApH2ZPnaDkQnewX/Xwn7+sH5bhdGL5a9RzZPtKJGiBM9mCHbJbr/2hQYdEL4R2Pxq0IgEDeWx3ofwXub+OnV6IwIDfRt4xBLUKlRUoY2jMNFMPrbHlrxEFOT7HtOKi5/e+U4AS+wUJJJnp1Z33RSWEMlyQMo78AshtR/dqk/HSkDFBJebGG/udTu5L3gCOpGSaStR+wDZjnt+xcjFBEg05uZgDXB41mFXaOzKwYUSfY4EHj4MzzrTX+KglNOaAXeyZKpUJP/Hv81A0iLjEHx8mWdCL1HRG8vT5Psv+m5ETq/102clocE7xh003OnNiVs08ZVb1mcBWAdHADxpgJT1oxYP2BbWJvQC9MhKwS9NYFUwx19vEBaY63XFQtaiBiem4= 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:(39850400004)(396003)(136003)(346002)(366004)(376002)(66476007)(66556008)(54906003)(66946007)(6666004)(83380400001)(8936002)(316002)(6506007)(6486002)(1076003)(52116002)(478600001)(6512007)(5660300002)(38100700001)(36756003)(4326008)(86362001)(6916009)(8676002)(2906002)(16526019)(2616005)(956004)(186003)(26005)(44832011)(41533002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: Xm5MVY2LW6ARPnpERD+0E7jIFNjwyp+ZnD7UGAl+eh6ACd0QZNDkbw/PspBOM1cBnGbydwYa5J1yI8yLmKxIXo3TBxcfY/2iOdA8V9mNeYMH802vlaucnpZVPwB41wd5miX09Wn/+cOOo/dtVIGyt/gMMldYaNebLBFbOvTd32bAzN5EL7kU1yTjLFFosoDo1zxOoKjvINF6mQvrcGWIEUXm0es6+/nQX/cV3yN6B0lqV1Nqise/ngNmjNXQRLtsMAfvfIIrA9gjDtAAgfNO///72eMnWnP6DPV0E/RO3TZMh/4ChlYbUEWx/y89r+CEvP6tG8TrimjuTTnfCl4l3YDG1v61ozo4sK/Trj/JOOtPu3UnbQkqm8T01jQOCMPqe5sEN8hzx6PLXrDB8IChWzpXK1USx9oU5sx+a6hNX+PPrQaaIKZaSWfE9IHyREC7QXaOP63HGZmzuAA2RyMXK7PAOGEidn/KtopevxyvzVVbgviddXYAC6vLjVdLDZsVto1jODDPzJW5G6+JB3PfmXsQ1K3F4ChbqPy/WzFJoM4KUYsbrlJTncb5IPDUoIfgMLFIYrmlClh+necq9ZGo+9UsU26kKxj7/n/cB4foSfoeQVsm3mod96CNTzu1/c1mG03OF9eyOfgSgzJCn6ENPIEvJFdFqEUZR8zmjDeEjxyVe/rNjxj4M5pUX+VtTFweNrJserbOQNey0qeTLko1n3GIhOX6fIvwYJGYKT3DOQvf5rvUd7ndlyUtemgWpNo/zOgEfd2Dl+Q0/1YkPjYyIxUOcWwCfyv58WBkud3BJ8okkPdQTMLMtpa5ogJ9BMTXjkPFjp+qBQ1AhC0KzRNM2rbHPZgl81EYChNAuD/lNXonXSJGvFCbE3Eyt+lfjVpp5si3kKtfiZSIj7Pe7X7246XjISzET6QstaLY02bM8zmmN89iUFNS76er1Jwgh3MLqXfe4XQzyNlP9uv7+s3vAIyadQmErafJoZ6MEZOWtpU4Y9JKO1KdTQv5jrbfqaTjRBWmRrP+woTSNp0F1t0GEPG8Q3HxIu0HBpfROPNPP6Wn858Npm4zz02sUKcapkL3Zdc8QqpiIV/niK+n/vNIzrWtV9F6wAe0rj0NYPyq1Hnr3LxTzZ+SmSjkpeo0rJBHMtL5xQzh08na0gD71gUACOw+DwBttFFAY5NRhC3iZ8LHFcoR+O3NPk1hXuXRe9V2lkwoyxeBBKdu10d3v5WYUJXVrNT3W5YGUaN53+eUNaH2t7uu8sEjswWlOic7zj/udSHO2xl5XdRPaQ5i98gy5mWyJM6bNmlcpnjoEeS9HEpij+dVqZ23lEiFHmDbSf3m X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 28fec1f7-e4c6-4ea4-2a39-08d8f3ba7e46 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5650.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Mar 2021 20:29:18.2958 (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: NJUQZnCrJmD7ny5E95PpNo6Jol4N2qS5i3U7pnHQk2q+oAQ0rhum0KIvGo+uT4Kvl6ZGGd/m27GjdE6EcRlp/Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR0402MB3393 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 83ba7540a53a..849573f6b44b 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, From patchwork Tue Mar 30 20:28:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Varad Gautam X-Patchwork-Id: 411819 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, URIBL_BLOCKED, 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 A66FAC433E3 for ; Tue, 30 Mar 2021 20:30:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7FA1461989 for ; Tue, 30 Mar 2021 20:30:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232401AbhC3U3z (ORCPT ); Tue, 30 Mar 2021 16:29:55 -0400 Received: from de-smtp-delivery-102.mimecast.com ([194.104.109.102]:39391 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232416AbhC3U3X (ORCPT ); Tue, 30 Mar 2021 16:29:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1617136161; 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=0lVu0kNchvYW/X5Tf1wjeKmtDGbtUc56LRj2YTgqL/4=; b=Gl3a/C2wRj1w8+5C9+TwO26XoMLhj0bhQI06H1llRYPDKtY9vn5UiXyZevJ2p/flf3+MZX NY+WuiR9PIKtcx1b5EaKFl+82bO9WUaW2du8pHsVf/njFqFyLutXKc7TKIiJBDXa9ldWOq 0BVcjdzKjDivRed6DirH+zzomcCfmDc= Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2174.outbound.protection.outlook.com [104.47.17.174]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-15-4wsP7MJpOj-Bt2tGbS0PSQ-1; Tue, 30 Mar 2021 22:29:20 +0200 X-MC-Unique: 4wsP7MJpOj-Bt2tGbS0PSQ-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QANK5DHrX3VqXZUFgIrEAM9gmNWRUnnO8j9jGOAasLyLwldEYy5RpRT3lGriwZCt4+ixcv7NNZg2FcO1eGP7q/Xg3bGn49EbalaSaHh9Q7LmEy0FhcrriwFCz2npZwk+sBX0kxO9fgLkTq8fBzWjHPn+/Vrs0cDO0FKxldIXvD/latSBqZPyaLHquAHlva3/JuVEaRGIYb69je71u2thwdbbOhp4rhvKZi1J8tIrRW+z2wRgJg51ZwbX1uduUvKsxXQ9yk9zQMSTlmW6fSPCR8VB68rXyFmv4/COjWMBXEKiNRLxvApUnVfzl+yNAtQlbsClkh0JSpVOvm7pLyzC/w== 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=LxXb7YdJtc7JgFY0x+ZjWZpHV3wSedJnwe7QRQoiKWs=; b=KVelIHL3NgUuyOi75T+gQoUhT8hUSEFgMF09t90QA5rlUluDx2C1pv6AkvgnNODZ07dWZd1oyLSMn/SHvv0EP9u0vAtO2SgSEUvjEJq4iAteTzBbA1tOmhWzJWD9s87mWcyBsIZ+HuhjjjmG9P34omhIAXGo+oYjudwYuTJ7RuN4IORt12goKPA5+jZuf28UbaZNzyDarjME0zc1bqxUWzu7wKA6ykWFEq6uH49jgMNRAH7ZZ4YvBX6Ik0GQUiFotv6gW5CsiTuW+ZlBuhSOrYqUz3HfeLIy9KtNMQ951VXJqGNJL2xP1ussbyOJgXaCBMbOCPUZcUTe8Of4kVBI+g== 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 AM0PR0402MB3393.eurprd04.prod.outlook.com (2603:10a6:208:21::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.33; Tue, 30 Mar 2021 20:29:19 +0000 Received: from AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::40bd:b7d7:74a7:5679]) by AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::40bd:b7d7:74a7:5679%3]) with mapi id 15.20.3977.033; Tue, 30 Mar 2021 20:29:19 +0000 From: Varad Gautam To: linux-crypto@vger.kernel.org CC: Varad Gautam , Herbert Xu , "David S. Miller" , linux-kernel@vger.kernel.org (open list) Subject: [PATCH 04/18] crypto: rsa-pkcs1pad: Pull out child req processing code into helpers Date: Tue, 30 Mar 2021 22:28:15 +0200 Message-ID: <20210330202829.4825-5-varad.gautam@suse.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210330202829.4825-1-varad.gautam@suse.com> References: <20210330202829.4825-1-varad.gautam@suse.com> X-Originating-IP: [95.90.93.216] X-ClientProxiedBy: AM3PR03CA0066.eurprd03.prod.outlook.com (2603:10a6:207:5::24) 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 AM3PR03CA0066.eurprd03.prod.outlook.com (2603:10a6:207:5::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.25 via Frontend Transport; Tue, 30 Mar 2021 20:29:18 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6be7db8c-d37c-496c-1768-08d8f3ba7f17 X-MS-TrafficTypeDiagnostic: AM0PR0402MB3393: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pDxp6y3WH67HsXJQ3V30naVbl6HJlq9jaE1VR+Ypn4MbDvKpxN3hovYXeYEWIK0Vmg8IldkFUGRhPtD8NVwZzz7OmLrP3FyyYqut2mpSYkSxbXS3HSEkfmzJq6FIPHRtw8FmJ/aWgZMFYM24aybCvg3wVmpe0+6nAxJWfE0C8OPvL6S5cq0kxpU5X3P0tnOChW63/Xt9I0iHpSZ0fZ65YY7W7p9/zf68RyJE/v0FcT4n5Qvfwk5sefK1YwE3oqI00iVj+8bq7luvMmufCj0s9vJVceQXTTI4pZPxtxgDsmCPxQtHuaVmqtum8j/Uu3Qkw1LVcbQxe1ceBppsUPq4PaxHSq+WuKW3pjeDbh3ngPftaEOGrXUqrr+sb2iHkV+1v02S/Q0KuW514mefgNI5o1PWpqklDophqtZ5p46VshIv1m0+yHogVNw4d2tinP1VRAQIKG9cshiTjx/1kheCdxWYCjqMmbhTVWdCItRUFI6g1PyPHSV9G/AkQ1e5CGlRVAc+mAgcacMO9Q5NwKfdfOueK3l/dfTFRqXl0woGM0sqkYrQgYDWHLDEXbtn/r8acZ0pRvqVSXm//cUPlJwjpPFUIo/W+Y5xEmm3zXtvaxaW140br5WTv6N+nnLZYmbemMoLuxZluvETNYPq7IO858nHRSJlb7OJoJ8IlUfRBR/8kNJ7qu99l9P4o0nQo/hu 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:(39850400004)(396003)(136003)(346002)(366004)(376002)(66476007)(66556008)(54906003)(66946007)(6666004)(83380400001)(8936002)(316002)(6506007)(6486002)(1076003)(52116002)(478600001)(6512007)(5660300002)(38100700001)(36756003)(4326008)(86362001)(6916009)(8676002)(2906002)(16526019)(2616005)(956004)(186003)(26005)(44832011)(473944003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 9kFxzxq0DcVMPsRCBCKlEqLY0CbEe3mNYob44lM19sRQYhbi30AGbSZ1wxLKS71AQgT673xN7/SPAgUI5G5BvGlu281qJCDM5335XyftNmU8LlGqHMEC1mqlWh2Tql/syi7b+OLf441GxA2iHHvgJu58K/oGSwf++hwBEoWHJx2ySQNRYHVGt24awFt5K+ZlFY9IKb2EExgZi2re5aNAuotr5DDvPO1sq9ii3nNbpoMYW+fx4Wss+PRZkjfWKBsJQPVbKTwgEjUkUDeHqyi3PBfwU57HHCZlhXZMvqqAbxCUGLk61Ajv2s3REKWWX7nnMtWQLYb0qaRluLcdFD6G+c8B59dnvwlDRHyGDO4md70XUTi/OS9cuQp5Ul7fZoKkvYI6q0nawEMxTVoS6Iu1OBycgVpFK8HIk86pjeGdKgzFH8vVp0NM/7oCYIfmgwHp7yWFv/3TZRZBT6eRiHvWUyEwz6in/bsMvkqkBxUXGhMzsKhP9MJDft8eBechPbJrGq8ySpon69oZTyAP+ZmwP4Cxj2mFoFQe55RNvBnNcySvZp1lG8Zos4zHy/6siJvuLej8/w7fK7tiNRwGD4EcTFVyZKNuxsF5tafLhl3rHGyEtbg4RfJpxm5Bc5asmHA9D2Aj9+WK5Rs8oxni3VQvhwP7KpTS1MABZNRkdFBE5QpVcDSmHfD5aktsjQd1qY0p0UORmThJ5xAtuXzXILvrsdzR5SX3jUZg36D3q8sU5s+iFiQqnhNy79Lg6BClhEpDYcWOcG7pn58uaFy4xkVfD7qHg+biQf9MMnH0gQYJ381mbSHDzTK58EVRYvM3H8+wdxPqOMO46QV8v0DSCH0nlCEHiX29692w9lMHPck8OmoSwks+cFuv5m1Ivh8l2AwTaDz3O+1dw3qgnfxlwtW4l9pQDkSAm6hP6hvFopvIGeN70g1sw7TsYYt1K7vhzq17CXAo7oU1+evbVVX5uvp1Z7tWNRtd6X/GX86lr7D0pIpRf6D2WdGBZDbUeI/Zlh20ax3mJFdAaL5MH4d4N7M+OaNUU63zeo9QbaY7oKT1zraky1I4gbzc/qvETfkt3pjzSK/FbiYrR8hOoLIsuw03Q7DU1/djkIKCjOSdVpOJeTP0H8wtu5A950uFAwQwsXWz+226iyRfO7+OZMsS+1j69xk7bw3P5Kfcn5hzp/pvJ2NudJrHlIp/lLz3okCijuIKVMU27qRwnCxlIbPPil84ZJUyuGzD7F7dfFt5HzT1+qN14yOr5VRvuYjw4d4MwbO2Hm1YlT0CdMhVA85SXtzuZ6NCRp7qEzQlI94Y8UUz/jwOIqrFBbNqRZwkY2dBW1rj X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6be7db8c-d37c-496c-1768-08d8f3ba7f17 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5650.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Mar 2021 20:29:19.8199 (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: m1zyh2J0dZJhysxkrgg+s/VAt6xBKsxaYbtbSmXyiMIrWLeU7bZs3Rt4TfjBso5s1CjaxcVTDtRI0FTCVF+OKw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR0402MB3393 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org rsa-pkcs1pad operations that require using RSA primitives rely on creating an akcipher child RSA transform and processing the results in the operation-specific callback. Add helpers rsapad_akcipher_setup_child and rsapad_akcipher_req_complete for req setup and callback handling, and switch pkcs1pad operations to use these. Signed-off-by: Varad Gautam --- crypto/rsa-pkcs1pad.c | 106 +++++++++++++++++++----------------------- 1 file changed, 49 insertions(+), 57 deletions(-) diff --git a/crypto/rsa-pkcs1pad.c b/crypto/rsa-pkcs1pad.c index 849573f6b44b..6329c79316d2 100644 --- a/crypto/rsa-pkcs1pad.c +++ b/crypto/rsa-pkcs1pad.c @@ -171,6 +171,38 @@ static void rsapad_akcipher_sg_set_buf(struct scatterlist *sg, void *buf, sg_chain(sg, nsegs, next); } +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 pkcs1pad_ctx *ctx = akcipher_tfm_ctx(tfm); + struct pkcs1pad_request *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); @@ -213,17 +245,8 @@ static int pkcs1pad_encrypt_sign_complete(struct akcipher_request *req, int err) static void pkcs1pad_encrypt_sign_complete_cb( struct crypto_async_request *child_async_req, int err) { - 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, - pkcs1pad_encrypt_sign_complete(req, err)); + rsapad_akcipher_req_complete(child_async_req, err, + pkcs1pad_encrypt_sign_complete); } static int pkcs1pad_encrypt(struct akcipher_request *req) @@ -259,13 +282,10 @@ static int pkcs1pad_encrypt(struct akcipher_request *req) rsapad_akcipher_sg_set_buf(req_ctx->in_sg, req_ctx->in_buf, ctx->key_size - 1 - req->src_len, req->src); - akcipher_request_set_tfm(&req_ctx->child_req, ctx->child); - akcipher_request_set_callback(&req_ctx->child_req, req->base.flags, - pkcs1pad_encrypt_sign_complete_cb, req); - /* Reuse output buffer */ - akcipher_request_set_crypt(&req_ctx->child_req, req_ctx->in_sg, - req->dst, ctx->key_size - 1, req->dst_len); + rsapad_akcipher_setup_child(req, req_ctx->in_sg, req->dst, + ctx->key_size - 1, req->dst_len, + pkcs1pad_encrypt_sign_complete_cb); err = crypto_akcipher_encrypt(&req_ctx->child_req); if (err != -EINPROGRESS && err != -EBUSY) @@ -331,16 +351,7 @@ static int pkcs1pad_decrypt_complete(struct akcipher_request *req, int err) static void pkcs1pad_decrypt_complete_cb( struct crypto_async_request *child_async_req, int err) { - 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, pkcs1pad_decrypt_complete(req, err)); + rsapad_akcipher_req_complete(child_async_req, err, pkcs1pad_decrypt_complete); } static int pkcs1pad_decrypt(struct akcipher_request *req) @@ -360,14 +371,10 @@ static int pkcs1pad_decrypt(struct akcipher_request *req) rsapad_akcipher_sg_set_buf(req_ctx->out_sg, req_ctx->out_buf, ctx->key_size, NULL); - akcipher_request_set_tfm(&req_ctx->child_req, ctx->child); - akcipher_request_set_callback(&req_ctx->child_req, req->base.flags, - pkcs1pad_decrypt_complete_cb, req); - /* Reuse input buffer, output to a new buffer */ - akcipher_request_set_crypt(&req_ctx->child_req, req->src, - req_ctx->out_sg, req->src_len, - ctx->key_size); + rsapad_akcipher_setup_child(req, req->src, req_ctx->out_sg, + req->src_len, ctx->key_size, + pkcs1pad_decrypt_complete_cb); err = crypto_akcipher_decrypt(&req_ctx->child_req); if (err != -EINPROGRESS && err != -EBUSY) @@ -418,13 +425,10 @@ static int pkcs1pad_sign(struct akcipher_request *req) rsapad_akcipher_sg_set_buf(req_ctx->in_sg, req_ctx->in_buf, ctx->key_size - 1 - req->src_len, req->src); - akcipher_request_set_tfm(&req_ctx->child_req, ctx->child); - akcipher_request_set_callback(&req_ctx->child_req, req->base.flags, - pkcs1pad_encrypt_sign_complete_cb, req); - /* Reuse output buffer */ - akcipher_request_set_crypt(&req_ctx->child_req, req_ctx->in_sg, - req->dst, ctx->key_size - 1, req->dst_len); + rsapad_akcipher_setup_child(req, req_ctx->in_sg, req->dst, + ctx->key_size - 1, req->dst_len, + pkcs1pad_encrypt_sign_complete_cb); err = crypto_akcipher_decrypt(&req_ctx->child_req); if (err != -EINPROGRESS && err != -EBUSY) @@ -509,16 +513,8 @@ static int pkcs1pad_verify_complete(struct akcipher_request *req, int err) static void pkcs1pad_verify_complete_cb( struct crypto_async_request *child_async_req, int err) { - 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, pkcs1pad_verify_complete(req, err)); + rsapad_akcipher_req_complete(child_async_req, err, + pkcs1pad_verify_complete); } /* @@ -548,14 +544,10 @@ static int pkcs1pad_verify(struct akcipher_request *req) rsapad_akcipher_sg_set_buf(req_ctx->out_sg, req_ctx->out_buf, ctx->key_size, NULL); - akcipher_request_set_tfm(&req_ctx->child_req, ctx->child); - akcipher_request_set_callback(&req_ctx->child_req, req->base.flags, - pkcs1pad_verify_complete_cb, req); - /* Reuse input buffer, output to a new buffer */ - akcipher_request_set_crypt(&req_ctx->child_req, req->src, - req_ctx->out_sg, req->src_len, - ctx->key_size); + rsapad_akcipher_setup_child(req, req->src, req_ctx->out_sg, + req->src_len, ctx->key_size, + pkcs1pad_verify_complete_cb); err = crypto_akcipher_encrypt(&req_ctx->child_req); if (err != -EINPROGRESS && err != -EBUSY) From patchwork Tue Mar 30 20:28:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Varad Gautam X-Patchwork-Id: 411818 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, URIBL_BLOCKED, 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 B4F34C433E6 for ; Tue, 30 Mar 2021 20:30:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9BCB4619D1 for ; Tue, 30 Mar 2021 20:30:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232417AbhC3U35 (ORCPT ); Tue, 30 Mar 2021 16:29:57 -0400 Received: from de-smtp-delivery-102.mimecast.com ([194.104.109.102]:44015 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232439AbhC3U33 (ORCPT ); Tue, 30 Mar 2021 16:29:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1617136168; 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=YS5dnhOZ1kq2JM88mSCOF6Sr5aEHkj0DlHwhdbYRAvE=; b=VioZYxrjZtLyFQS/JuVp5nFxHDPeQ0q9XuoU5mla8jH6VRp16xbbNBUxrt7uP1NM+E90/x KZcxKoEjz3Toy+uvN474NlVqTslB2Hg9kXn8QsS3xmTOTNXOc5I0FFdAvnkOqWDBSqxaqY freLOZoCEn3pzByOxwuxDLWKsv+jHlI= Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2169.outbound.protection.outlook.com [104.47.17.169]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-25--Ae-J4dZOve2Zezl1OyKQA-1; Tue, 30 Mar 2021 22:29:27 +0200 X-MC-Unique: -Ae-J4dZOve2Zezl1OyKQA-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=N2Tx0Xpci45I7dotcRt+N0cWpH3gZcFT+gbJMIFTn0OrUcjWlRI2bfMQkZttp1hnIvFnHL2EJAt1+rllLmWgrXVcaSiTPDvGwdPN9fFovlX4yRBIr7POtXiGOSUJHljQeMcSajpDlqek0LQ3mH1G43rIXtBPu+7D4/0tFHeGvKMS6iRvguidO6egKfcPV7dZN4FetCYckQfry3l0Jcdfzsveg2982/ckqjcd0gj1ZWWdPVu8b7v8wuHGnjhPH8xRQMapNGn1vJf+BWQ92n82cOct4/D2iVYioFQCFBiDbFApdn1jVkUTRkFKlyJbittUURz1Rbuj9TJbvVQ555JNMg== 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=QnjW6jOyPK073QZdomwNsfNcxfz2d5QALxIoSAHf1b0=; b=RLdTeSY71Cz0dTMTT2tOecNA7LV5TO1GsfY9Mu62E3EUZGpb93KTixp3JSMZzpSpQmyog7Y7rIEQ5+Tj8gg6y/xT899vwMmaX8Pq1lcT40rfEqR5saJNKZHDriXmyb6SLrJ+B7R6aaOJl+soek/0As6EUlI26AuHEvJ1LluvuYyMPRn+0jWQse222bDwkVLrTJvf51yKzcQlxhvuR7o0BWKgYdJLizo2J8WO32vSOJjlJs7lspmUi/HglKh65YQK5qr1XGmtKwsm1FrifGv2AotKrOjsbH9uGTGcQOH2xiBlXBo5F0DgIunor+1gSzyoH1tzRJUkXwa7tZ/zr2ANWw== 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 AM0PR0402MB3393.eurprd04.prod.outlook.com (2603:10a6:208:21::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.33; Tue, 30 Mar 2021 20:29:25 +0000 Received: from AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::40bd:b7d7:74a7:5679]) by AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::40bd:b7d7:74a7:5679%3]) with mapi id 15.20.3977.033; Tue, 30 Mar 2021 20:29:25 +0000 From: Varad Gautam To: linux-crypto@vger.kernel.org CC: Varad Gautam , Herbert Xu , "David S. Miller" , linux-kernel@vger.kernel.org (open list) Subject: [PATCH 06/18] crypto: rsa: Start moving RSA common code to rsa-common Date: Tue, 30 Mar 2021 22:28:17 +0200 Message-ID: <20210330202829.4825-7-varad.gautam@suse.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210330202829.4825-1-varad.gautam@suse.com> References: <20210330202829.4825-1-varad.gautam@suse.com> X-Originating-IP: [95.90.93.216] X-ClientProxiedBy: AM3PR03CA0066.eurprd03.prod.outlook.com (2603:10a6:207:5::24) 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 AM3PR03CA0066.eurprd03.prod.outlook.com (2603:10a6:207:5::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.25 via Frontend Transport; Tue, 30 Mar 2021 20:29:24 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 089255ad-6a19-4d33-9347-08d8f3ba8262 X-MS-TrafficTypeDiagnostic: AM0PR0402MB3393: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2657; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RyD7J/a6ActYEYYru6+jeEbLueBxaScANtQVJn9EM/AC1T2S3TzFaTD8VyBxZR5ZpMKCA5z4BYqfToRrO2eDMgX86L7pIuFa8j9xM473Ry6S7MsrYaYviUfWhJi4gi7y7oSWiY6xYkI30IonsNNttl2ZfDfBD90ImKfKQVN3h03ZG5379XV2qytoxQMELFzF2Q7YXtLakerccQ2O3BM1fBUJ6dmcIjk+6jUJPzB8yMMaDZ7nfDdszABAXRZwmkYqjfUa+neYA2glhNguG+mFMMKhIxrra7GVBf+8EpPw9+88I67X4t99RiBjAp4iPf9nFTkAsZ3lnG0ChMKIFN/FUEbvGYIGMCMl10aMdDoKg70/gRbL/9uGOoeGZohID7hfoBxUmmJV6jV6oy16d6j7HT6vGf2uVDe68UT9sDp9eIzlCPvJtFxZ1sLUXNKH//KLL8Rdr8tgzPo2FQMW+H5JBPoBtYycr8tiffwbubf1o/Z0fAD9Uyk5aO8F4YKZHsSOyXy4bNP3Jrb/gzYkKGrdC2c9vEdppZ0iTpxHkAg655Bobmj3Nj97cpHEwYCZzLeql9VXGWohSQnezMt4atXAfI81DpwAUJs/IqZoZuelxcGlDaMTfokvQnVh8L/8fpstDfs5CBGkHV+4sA4zzecaTQ== 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:(39850400004)(396003)(136003)(346002)(366004)(376002)(66476007)(66556008)(54906003)(66946007)(6666004)(83380400001)(8936002)(316002)(6506007)(6486002)(1076003)(52116002)(478600001)(6512007)(5660300002)(38100700001)(36756003)(4326008)(86362001)(6916009)(8676002)(2906002)(16526019)(2616005)(956004)(186003)(26005)(44832011); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: at/8A/UlRxFCe3YzgAV/CeXmjcDdG0MPEn791JklOxdCNCjYYeqyEZ9cVl6z2EkgjaOkzypRUXPQJM09HMZiU0FAjqda7qXSId3q3JXg2W6H9sENaDSyxPfqkP0L1ABoY1JMBnhqA+4scuH29zgG6pl7/xgXcHh2CJPsGiJ31zUlRb1N2QX+T8aiQjjw5WN6DemOXa95UHtf6g+jIWQbvAFWhhq6augeIWczVS/kvSRmXQSH3hvsLimjTXR/0FpjYR6GEG7Lb0R5pKn0VZSWySpTxPSv7u3eswpsEqLKEpFyFgYwoR50H7bpqUzL4P6VPAfjUfMHiJyujAooeK6xSkrO65LlZNmfJXY3eOczpgROLFhrOvUGU3O1uBkJts8cn9CZDkmaYdhRFhTKGgezSxNRglxVe4P2+h9gOaffsmUNFZgD5RHiVIkvUIV7Gd5DvJ9mhvWkLhDwCy2Ow0AvDL2sIIbS2qPjjnmJ+Mh14fRKyd6IcNaEI+q9Kk5Vhlvdb0pTufjF0Yh2N7JY9+7RmRk/VGaBcq8mdbhGdeSlGoK/Szgp/QotoV+V7pLKITVksM71v4PFZWcEs7QA9sOSOMTRTc7UvFL5xyVD/IId7b1nDM+lu1gm9aQPExz6AP9dTDdPLwWnEi2dRTfI3IaT3q0C41yC+l3cY1JX0NFKiif9JGglB1uZFk7yIXXT2VUsjMZvBJRRuz6Sez5rQHpJgZFwxjMX8Rc6FUiV5dN8K1qQj/G7bXOGltxN50SWHWM81Cs0wW9WokZPaV+bCeCYzdSziVNNA23FvF18PPFLJzeMoNU1NWxZbVpZ5P+OO+MCDh5uvx6TlAgQwB8jyNVUw+zLafzS8y+Lmcc1JB4UAyYFbO0puoZmfPjMyWJ+r//FzIVmasUxHqVTJ5GW2Rl9jk5gE/kXdMWFifEr7S2UakGeaFpQmFx4wshAKw0hk+dJQbMkVegkmbq98DUwvnkpocilJ1PPnBVmRXIPJJPpjbS7k+b/OzlroJ7cKXp784zyjOLLKFI/LZJUIlxyIU1KgoO1+n3vVmE8pcOW5YoddUPI2yYlP49n6sRNi1ebe+7H93xFbYggbpHNzbLEXwEddGayQGdsbNSI/G+Fj6/f/ZZbn4aoZDAWp7/BekDbqTs/dcnldbd5fhc+WhsQXJQ9WSVk1FsdaQyxulLiDPs6wc4dasw8MOk2QsRtaBV7sWKFCogltX2Ep2B7Xw3bUaHdWvJR1taxHHvbpVzoQqWDITl9XLeTHZP2w1EFRJjQk2I/NpnrD2FSdW4z+GKmSx8k0XJMxLYlzGjtz7ia3bGc6/l1MrIGNzjCIElDSjk6OCdu X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 089255ad-6a19-4d33-9347-08d8f3ba8262 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5650.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Mar 2021 20:29:25.2238 (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: GKvk664GLb8kl8tGb1BDqpjV8mkMS92WhoHq81pKNd2S36VWvE5i61oMUiTzRiIU/eVf5eimWxF2JWMVX/fC0g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR0402MB3393 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Move out helpers from rsa-pkcs1pad.c which will be shared across rsa-*pad implementations. Signed-off-by: Varad Gautam --- crypto/Makefile | 1 + crypto/rsa-common.c | 76 ++++++++++++++++++++++ crypto/rsa-pkcs1pad.c | 97 +--------------------------- include/crypto/internal/rsa-common.h | 37 +++++++++++ 4 files changed, 115 insertions(+), 96 deletions(-) create mode 100644 crypto/rsa-common.c create mode 100644 include/crypto/internal/rsa-common.h diff --git a/crypto/Makefile b/crypto/Makefile index cf23affb1678..57a85b2b3429 100644 --- a/crypto/Makefile +++ b/crypto/Makefile @@ -39,6 +39,7 @@ rsa_generic-y := rsapubkey.asn1.o rsa_generic-y += rsaprivkey.asn1.o rsa_generic-y += rsa.o rsa_generic-y += rsa_helper.o +rsa_generic-y += rsa-common.o rsa_generic-y += rsa-pkcs1pad.o obj-$(CONFIG_CRYPTO_RSA) += rsa_generic.o diff --git a/crypto/rsa-common.c b/crypto/rsa-common.c new file mode 100644 index 000000000000..60073c56e374 --- /dev/null +++ b/crypto/rsa-common.c @@ -0,0 +1,76 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2015 Intel Corporation + * Copyright (C) 2021 SUSE + * + */ + +#include + +/* + * Hash algorithm OIDs plus ASN.1 DER wrappings [RFC4880 sec 5.2.2]. + */ +static const u8 rsa_digest_info_md5[] = { + 0x30, 0x20, 0x30, 0x0c, 0x06, 0x08, + 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x02, 0x05, /* OID */ + 0x05, 0x00, 0x04, 0x10 +}; + +static const u8 rsa_digest_info_sha1[] = { + 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, + 0x2b, 0x0e, 0x03, 0x02, 0x1a, + 0x05, 0x00, 0x04, 0x14 +}; + +static const u8 rsa_digest_info_rmd160[] = { + 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, + 0x2b, 0x24, 0x03, 0x02, 0x01, + 0x05, 0x00, 0x04, 0x14 +}; + +static const u8 rsa_digest_info_sha224[] = { + 0x30, 0x2d, 0x30, 0x0d, 0x06, 0x09, + 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x04, + 0x05, 0x00, 0x04, 0x1c +}; + +static const u8 rsa_digest_info_sha256[] = { + 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, + 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, + 0x05, 0x00, 0x04, 0x20 +}; + +static const u8 rsa_digest_info_sha384[] = { + 0x30, 0x41, 0x30, 0x0d, 0x06, 0x09, + 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02, + 0x05, 0x00, 0x04, 0x30 +}; + +static const u8 rsa_digest_info_sha512[] = { + 0x30, 0x51, 0x30, 0x0d, 0x06, 0x09, + 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03, + 0x05, 0x00, 0x04, 0x40 +}; + +static const struct rsa_asn1_template rsa_asn1_templates[] = { +#define _(X) { #X, rsa_digest_info_##X, sizeof(rsa_digest_info_##X) } + _(md5), + _(sha1), + _(rmd160), + _(sha256), + _(sha384), + _(sha512), + _(sha224), + { NULL } +#undef _ +}; + +const struct rsa_asn1_template *rsa_lookup_asn1(const char *name) +{ + const struct rsa_asn1_template *p; + + for (p = rsa_asn1_templates; p->name; p++) + if (strcmp(name, p->name) == 0) + return p; + return NULL; +} diff --git a/crypto/rsa-pkcs1pad.c b/crypto/rsa-pkcs1pad.c index e76fc98a537a..ffb7220b3d10 100644 --- a/crypto/rsa-pkcs1pad.c +++ b/crypto/rsa-pkcs1pad.c @@ -5,104 +5,9 @@ * Copyright (c) 2015 Intel Corporation */ -#include -#include -#include -#include -#include -#include -#include +#include #include #include -#include - -/* - * Hash algorithm OIDs plus ASN.1 DER wrappings [RFC4880 sec 5.2.2]. - */ -static const u8 rsa_digest_info_md5[] = { - 0x30, 0x20, 0x30, 0x0c, 0x06, 0x08, - 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x02, 0x05, /* OID */ - 0x05, 0x00, 0x04, 0x10 -}; - -static const u8 rsa_digest_info_sha1[] = { - 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, - 0x2b, 0x0e, 0x03, 0x02, 0x1a, - 0x05, 0x00, 0x04, 0x14 -}; - -static const u8 rsa_digest_info_rmd160[] = { - 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, - 0x2b, 0x24, 0x03, 0x02, 0x01, - 0x05, 0x00, 0x04, 0x14 -}; - -static const u8 rsa_digest_info_sha224[] = { - 0x30, 0x2d, 0x30, 0x0d, 0x06, 0x09, - 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x04, - 0x05, 0x00, 0x04, 0x1c -}; - -static const u8 rsa_digest_info_sha256[] = { - 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, - 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, - 0x05, 0x00, 0x04, 0x20 -}; - -static const u8 rsa_digest_info_sha384[] = { - 0x30, 0x41, 0x30, 0x0d, 0x06, 0x09, - 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02, - 0x05, 0x00, 0x04, 0x30 -}; - -static const u8 rsa_digest_info_sha512[] = { - 0x30, 0x51, 0x30, 0x0d, 0x06, 0x09, - 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03, - 0x05, 0x00, 0x04, 0x40 -}; - -static const struct rsa_asn1_template { - const char *name; - const u8 *data; - size_t size; -} rsa_asn1_templates[] = { -#define _(X) { #X, rsa_digest_info_##X, sizeof(rsa_digest_info_##X) } - _(md5), - _(sha1), - _(rmd160), - _(sha256), - _(sha384), - _(sha512), - _(sha224), - { NULL } -#undef _ -}; - -static const struct rsa_asn1_template *rsa_lookup_asn1(const char *name) -{ - const struct rsa_asn1_template *p; - - for (p = rsa_asn1_templates; p->name; p++) - if (strcmp(name, p->name) == 0) - return p; - return NULL; -} - -struct rsapad_tfm_ctx { - struct crypto_akcipher *child; - unsigned int key_size; -}; - -struct rsapad_inst_ctx { - struct crypto_akcipher_spawn spawn; - const struct rsa_asn1_template *digest_info; -}; - -struct rsapad_akciper_req_ctx { - struct scatterlist in_sg[2], out_sg[1]; - uint8_t *in_buf, *out_buf; - struct akcipher_request child_req; -}; static int rsapad_set_pub_key(struct crypto_akcipher *tfm, const void *key, unsigned int keylen) diff --git a/include/crypto/internal/rsa-common.h b/include/crypto/internal/rsa-common.h new file mode 100644 index 000000000000..ecdce0cdafaa --- /dev/null +++ b/include/crypto/internal/rsa-common.h @@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (c) 2015 Intel Corporation + * Copyright (C) 2021 SUSE + * + */ +#ifndef _RSA_COMMON_ +#define _RSA_COMMON_ + +#include +#include +#include + +struct rsa_asn1_template { + const char *name; + const u8 *data; + size_t size; +}; +const struct rsa_asn1_template *rsa_lookup_asn1(const char *name); + +struct rsapad_tfm_ctx { + struct crypto_akcipher *child; + unsigned int key_size; +}; + +struct rsapad_inst_ctx { + struct crypto_akcipher_spawn spawn; + const struct rsa_asn1_template *digest_info; +}; + +struct rsapad_akciper_req_ctx { + struct scatterlist in_sg[2], out_sg[1]; + uint8_t *in_buf, *out_buf; + struct akcipher_request child_req; +}; + +#endif From patchwork Tue Mar 30 20:28:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Varad Gautam X-Patchwork-Id: 411815 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, URIBL_BLOCKED, 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 CB16DC433E5 for ; Tue, 30 Mar 2021 20:30:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B043561989 for ; Tue, 30 Mar 2021 20:30:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232531AbhC3U37 (ORCPT ); Tue, 30 Mar 2021 16:29:59 -0400 Received: from de-smtp-delivery-102.mimecast.com ([62.140.7.102]:29412 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232463AbhC3U3e (ORCPT ); Tue, 30 Mar 2021 16:29:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1617136173; 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=j4Ewybz6w4lMErRfH/jnufOCEmHJHtgwHitXjb47p9Q=; b=Tl414XZPzOrnTK0wD/eCarRlxKNGmeqj6cvB1S7zMOleSR2KargRoMpaoV50sQzjIDJiTC edpgcMnEsdm8uytfjHhMvg1R9Ir/Pmp3nV51DVb9PHTxaA6UnwSYk4SVzwNvSrJWdO4go9 jJaqFQl3N/ooSpB8Bzswnzkeo4vsAq8= Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04lp2053.outbound.protection.outlook.com [104.47.13.53]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-32-SLkxt6rgNHmwAer7UvmeAw-1; Tue, 30 Mar 2021 22:29:32 +0200 X-MC-Unique: SLkxt6rgNHmwAer7UvmeAw-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MI5ZRmaqjtqJ9DTguIlX5fxe6iM2Pk7MeutD2Q4yjauz3488QgZiConSTUzrx44Le03JaKR9YPPLtQk3roSjMficNrMyX9+MHjgrfCV4VNNsXpLPgZG7r+dCCf4c4s6X/YGYbZI0u7sJPspozZdRpPP/gwK+NYkNYGxXWeZRdZMnURM5C04pXX5fy1Tv2ExB/xrrWkN8L/BSViyUEf52E2SRqoQQbdad/zYnmlMJHNc8px2ll7QCjJfR8a7Kh7EqlCdUFfivz+D/WMPzP0AG24CX6GtTTfG7H0dtDkdjCFthaOvOqEdNuTyzvdd/aLrvUlvdGUblaoOdKuFyjOWtEQ== 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=nyZxX+2f+iKZH6W/fnwpcP/2p2RvxmgjA9KljJUpZRc=; b=WhWS2PJBsB0OdH4WxV+6LirRwYINfHG+qw314SLreoT3En+3zaNziYQuDcpMklN1XKF9hFOwTZYZHsFegEFzjyhGp+DAXO1HppSCK3p5YFKni+E41XyEyGFiFsnx02RtHq6sRyk3OxyouMQp91OBl24gThJoqW/iLk8B6kt1N2f1Um4Dyw17G2EbmhZ+EVwXMruh+EhnH/PYScYwGU5cTRfADbyS7n+ZdtTZb6A5JSWMNxtfAn7jLDqU9z4L5NRW1CccC4R5XeRFQqQQREnZ2fXjzeJ78igcZQzZKTjMCb/EY0+dKis57ubYdBJ+vGN21hVm23lT0zdqMPUWADR+6A== 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 AM4PR0401MB2321.eurprd04.prod.outlook.com (2603:10a6:200:4e::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.29; Tue, 30 Mar 2021 20:29:31 +0000 Received: from AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::40bd:b7d7:74a7:5679]) by AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::40bd:b7d7:74a7:5679%3]) with mapi id 15.20.3977.033; Tue, 30 Mar 2021 20:29:31 +0000 From: Varad Gautam To: linux-crypto@vger.kernel.org CC: Varad Gautam , Herbert Xu , "David S. Miller" , linux-kernel@vger.kernel.org (open list) Subject: [PATCH 08/18] crypto: rsa: Move rsapad_akcipher_setup_child and callback to rsa-common Date: Tue, 30 Mar 2021 22:28:19 +0200 Message-ID: <20210330202829.4825-9-varad.gautam@suse.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210330202829.4825-1-varad.gautam@suse.com> References: <20210330202829.4825-1-varad.gautam@suse.com> X-Originating-IP: [95.90.93.216] X-ClientProxiedBy: AM3PR03CA0066.eurprd03.prod.outlook.com (2603:10a6:207:5::24) 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 AM3PR03CA0066.eurprd03.prod.outlook.com (2603:10a6:207:5::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.25 via Frontend Transport; Tue, 30 Mar 2021 20:29:30 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c17cc80a-f321-4947-9703-08d8f3ba8617 X-MS-TrafficTypeDiagnostic: AM4PR0401MB2321: 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: hwB29a/i5wy7EMkHN5+s9yo4GjPHFMC6e5XLqcDU9sPWhEE+E2Dr1J/hTC4aNN8xYDRqAVHZU4rEESwg7Tk/QXpScVHlXeUu924y3mUj6vXBGbhw3vOpeH+D9vtQW/AAuF/dytLNmDkmEFPbcpJmhM/ZshtrWEW+y7y4DQv2kziSHW0EKG2JhN6knL7aPs0s6WC02xL7ZZCY/jqU942Tk8wxJA7RCMKB2FnxlcQHcgf9pKxQNfBmsQqo+aCkoaFeN+dJxS2l9ny53bzFZ5rNSk8UMOHRgWePanJkJhD/tqb6RhI2Tvru1yiJtqfpSNXAdYMYx805degpNXDTNasH5QqFVXk3m6q1ZdnKJ4K/pwvKB0qz+k+mwikJztHsVj1ScQdONIVwMoVdSOPbmHkpkWqYmn/r7T5bRPkeNZNKJcyqOMdgTzsbeiM5FCNijIuWg1yAPDYgFVwo/hmMsNlruLh+xJ6qmJyHgVfGs4/twYGRbXksa6YCQQKlksB1gozEP/Mx741geUmSizN2d7NH3WSn1YKu1EQCspMKVgsC/P0k86rxuToJO67E9rO53XwDFmS5une3+62IGG4UISJ88Sey22mAx5t5Hx1Kh2DbyN/nDmeFSC+y+6jcT0spxyxp9w6YOQZZskbr9ICQE8+TPrm7u908aXXlKsdQ3UHzzhk= 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:(396003)(346002)(136003)(376002)(366004)(39850400004)(478600001)(4326008)(8676002)(36756003)(186003)(6916009)(38100700001)(66476007)(26005)(66556008)(8936002)(6666004)(66946007)(5660300002)(86362001)(54906003)(316002)(6512007)(1076003)(16526019)(52116002)(83380400001)(44832011)(2906002)(956004)(6486002)(2616005)(6506007)(473944003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: Nt4HunzG1EulApf78lhF1csOPA/FvKaoR40KDNBPmXJL2J+O0CfRlZbqrrP6SdWbmmxHndrSO/aB46Z5W3DyT4of41O/H2BHDuFovmN1/lZheo2bCLpKGzTxP3+kK85ZPo60BT3+l1IhW1B9WZT93QRFA3ci4WPTJvMi7DmsuyuG0CrvwWJycgfpXSAdMHqy1UC0CXHZeFKxMPCJCXg30F+S8oimQ2xrOaHkq7iT4wHSOJZ1znUy0bbmTEytYjm4FlLfYgRVMvaPuI9mb6iPcMeNpgjmWlm7jrIZQS0+6CgOHwLvFITHFHeb6iwt9OH1me9hmgrPjxkp1AjvQw27DXsQWPg7PAmM+yj5uUdFVPZ7UqspQjypN4CaKOHRN5sIiNOZP7+KukyoN5mC2/8LJyvFiC4azGV57LRT1x6wLb1+966dVudktHikhbCatDd33dr6O5+ejjETKwzHs3uCNTAMBmpm0Dq58Crfyx/qonj5cCImPiPpFHtZivSB4Zvk45mJeczgKloXrDgkG9R4qQTZFhLL/HpwUvucGcbwz2zkDcgpgEynOFH+WPFsgTIvzXUsnh7oCcFYJrDjTvoKlOuF0vz7LvkGKuLTTMsKieQ1gVb4RQP5fnN0JT4k+3FyLA64zXrR3T2AtgoIAwXBQxpN/tQLyIFGdEcK/EoIKLIzfrE+ZF8uQ0DZMFPWKxuDMoVU1Y7kbJ+LG3+R0kP+E3jmgccoUMyYC0uj/BokhIBiSCqk9gGbsM6UboTw57rzUYlWt7+PDjZnJXgO7euBN9Wt4OI1s0dzznoGGFNQY92L2t3ifBkLcPPqgWb9pCT7EFAwZKwKG7fSW4pucfrP6GgsJ0U+1dVLrJx3TRG4XR8JULeL140YB6pFu3HSt/bAaE7OtEBaa+9QG6sj2b7B84tc7Z3tyUbFMayNDdXzO7bQeYmUe2uEktUpRnfq3gVU8cJ4ftrTkTdYeNDUl0Wl5NhVb0y+ajnffJGC85EUfRjbiJv+m8rMkHDoe/mhXKfxgcHN0Jgjh9ulGjXtKe+PVTd81YXFKF/G/iQBNiFNrexSj/ixzcWEDAoQSAc+ea2thh6AGq+NdMiI9XlrMQaay7ZH+iRkQCETC17X7ityxTMoaGPs+1iBWW2JtyN9Dnw9ly5TG0dPwX8Bw1ohMOfWBpZmGYi9RBbm6wHGg1fHvsl3gYyBB3G4yC/tGLMz4p7LiLQjrXE2y7GMfTxSIWr+d7Fye3SIBJJpH+ehsImk33ozQlnLEJCseHLlfhy+51U8l6JaCEPzZOx9KzwVsusSgPm8OBC8KESo+W/Rl2WSLMf0/NIu57+8WWchQ+6A/lDm X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: c17cc80a-f321-4947-9703-08d8f3ba8617 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5650.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Mar 2021 20:29:31.4183 (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: ECOv304d5zdH7XB+L6ZR69oCUh3LMO+j78gh0p6JscDj/lh949KjgHfjtx5+hapLkppsq6vL0+t6O6UKe0j8jg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR0401MB2321 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 d70d7d405165..6ed258a78287 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 30b0193b7352..6fa207732fcb 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 a6f20cce610a..4fa3cf5a989c 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, From patchwork Tue Mar 30 20:28:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Varad Gautam X-Patchwork-Id: 411816 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, URIBL_BLOCKED, 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 3CD80C433EC for ; Tue, 30 Mar 2021 20:30:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2456C619CF for ; Tue, 30 Mar 2021 20:30:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231650AbhC3UaA (ORCPT ); Tue, 30 Mar 2021 16:30:00 -0400 Received: from de-smtp-delivery-102.mimecast.com ([62.140.7.102]:20614 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232455AbhC3U3g (ORCPT ); Tue, 30 Mar 2021 16:29:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1617136175; 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=I65mV+PIIl3VRquXzisMZaiDhjOgopTOPxB/0TnfXOs=; b=mqLKpWcn6aRQJxHbQfZOUvuJBXS7I+gKwQsmJdOvyge2vNeLTVEIxC9GUSXLGXHH6UUJ9q 4V6K0rtTEcEfmseVD4Lst9FBVehIiTWU6+zcAIl5reCPauFQUIHcrAAstZ4mUGSD4iHFIU AUAAL2yUB4lveRpdAyR5D0nDD1ceS6k= Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04lp2051.outbound.protection.outlook.com [104.47.13.51]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-34-VbAvbaQxPP2kqf-dsSqA5w-1; Tue, 30 Mar 2021 22:29:34 +0200 X-MC-Unique: VbAvbaQxPP2kqf-dsSqA5w-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=On8gGmndxoUdHMFM7xU4y0x0s8d4NDMj1Gjc/+MSxMoas+kYOSTgM9CxURgdlu0RiVcIhaA2fuFypJwhI612AVY8H8sRu9QfKo96F1+gaMBV4j74BNEKs7zkRBzWDglu1PdQyjDl91xGFAcWPzlPLfADK9koDlD/k2ScpI3rQUCbW6mu1freHU8t4HN9MGPw3w52Qun/d6DjcDgxbRWin1TQvjZ4yVPR45qU1n/zV1YYINCOlMtsPswGN5iY0/x/o3+f5lfMIatoCnB9+Cx/T43IpPbit0e8ut58qy+Xaq11pFk4WtUQsrs+d5YOnd2ej7qWtPEwxvh4UDR9Ex6+/Q== 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=dUbavBm2NRZ6YjYW77yaS1bS2GmZfFG7RJ2VzcSHI4A=; b=IWvEYQafUjnxR0xLG4AdSsDSOZY6NVUOxkV9dCpzYeckgn2xEvWyoHyCRoJE22nqhOy5LmBQhYoVmD5GvHS1eoSYzbkDhU4uBVhk8MnXXdCJ6P9NVZYvnTjq5gE71S6Qc4Tbrc63or6a38v2AbmHholHyvZvCIshW6JBEcLluOdP2ML8gDp+b1vU72UgjBg1d+zwrcLFMQm+f00iOIPPWrgE24TAZj0PhCyUhKdGigz+vUuB8jAKBrP7MLFaQ/9pwWR5MiW/DPty2sSMCl1YV7Q6RF9Q9HkVJ1NO1F3w/pFjrCWeXMzhDlMO+lNIsNMq4rHRGUrYwrwmWaQK8MYj/g== 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 AM4PR0401MB2321.eurprd04.prod.outlook.com (2603:10a6:200:4e::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.29; Tue, 30 Mar 2021 20:29:33 +0000 Received: from AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::40bd:b7d7:74a7:5679]) by AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::40bd:b7d7:74a7:5679%3]) with mapi id 15.20.3977.033; Tue, 30 Mar 2021 20:29:33 +0000 From: Varad Gautam To: linux-crypto@vger.kernel.org CC: Varad Gautam , Herbert Xu , "David S. Miller" , linux-kernel@vger.kernel.org (open list) Subject: [PATCH 09/18] crypto: Extend akcipher API to pass signature parameters Date: Tue, 30 Mar 2021 22:28:20 +0200 Message-ID: <20210330202829.4825-10-varad.gautam@suse.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210330202829.4825-1-varad.gautam@suse.com> References: <20210330202829.4825-1-varad.gautam@suse.com> X-Originating-IP: [95.90.93.216] X-ClientProxiedBy: AM3PR03CA0066.eurprd03.prod.outlook.com (2603:10a6:207:5::24) 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 AM3PR03CA0066.eurprd03.prod.outlook.com (2603:10a6:207:5::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.25 via Frontend Transport; Tue, 30 Mar 2021 20:29:31 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e0be63ca-b4d8-47c4-543a-08d8f3ba86ec X-MS-TrafficTypeDiagnostic: AM4PR0401MB2321: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HTPdW2/KDY0Jem7KAyFSJ6RPgxBQTnRtN87c9wU2lW5ba0ZBuLpgy+LqZHZpJF+C+D/TCiqHADzcPJ6bvEgZORNgGamxnV2UMfHw3Uzmjp+OJP4S8EZzUNGIzBJPw5ubm312jp7Yd2/NoFqX7OWHFSGbXEPRx6o1QBFHuaLopJQpN+T+aXFldcKm0CeIXWN358WoyYJ/22Y0b49LY1KZe2TpIPHoCr226TCQGGeRFbHQnr4Hb1M7SQclfgwHxh172BjLeLDwAg283rAVPt21xjtpunoNmOdGDNumiI862dAETFSmaWYzt7ddAn6JMiia1kytA72NmokzRLFQvLFq8c0Rq/rK2tQDQfSSePrX+y+YcDPupLoYUm+64dTEoKmTPz9EDy9SkaMCMszoblHm/11iHcHi6WYcb9qrVi9VscRlRLpQ2Zln3tlcnkcNZHEcHQm6AYd+yFFc9WrIZ9TMT81RQc/a7jRLGntd0SekhHMk0dzh7VBVTV9bjzbW0iskHAwzz40P/YjXBh35Xi3u0mHFsIJRxIclUSd5yHrEob69kjoqoV5H/9We7LZh/I086HSbbmlpZRoIEw02MQQ2aNvbepfV6n7Bs5csX3TPLoZfqs7G+lL0bKz2o3u7rnnHl10sXQD7Jkz6FYIpFxmIjA== 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:(396003)(346002)(136003)(376002)(366004)(39850400004)(478600001)(4326008)(8676002)(36756003)(186003)(6916009)(38100700001)(66476007)(26005)(66556008)(8936002)(6666004)(66946007)(5660300002)(86362001)(54906003)(316002)(6512007)(1076003)(16526019)(52116002)(83380400001)(44832011)(2906002)(956004)(6486002)(2616005)(6506007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: g5Jj2Bb4KVC+GqZ/bDBgeXvSjEyTqlS850Ttp41dI03fbDb7ZEuTLjkgKDCl7BsPoFVfvKznWVU4y2W/FHL0W7NNJF8mbvnHx8Ws4pzSvv1xTEYvwSn3vJXCWMfj3Ym1ojQKtIcNpZva9YLW/i0R0qlqOr+wNPHRlM/0VfEz3+H5pd4d+HKR6mbz8kMPacSygiuNP9JwS79X5fmzHMOmA7XHxCl50pzmxiEyVVB8ovN4W2DmmfrdG4YWJiuqQWMbVSt6WuDUPNgtAMSeaRxRf4KLl92+B4+i1Q4QWJEO1Fch14Am2yYzAiXS+diw/pOAx2ZHkhWnLOmG2Yb/rE31RTacND7z7ghv2qnNq4waeGHnMxaQFx3ny+UbYK2AeRZhJG/lYLvIfugRjoVQ3TC6X4mBcUL4c0gEMknyW7TekufRDvdMB0zg9gtnSrUFkn41abr4439INrZmuFfwHrJVWy7QYpo9hjaaSw5d0H8GOI2Z5DO7prN7GXpBVlL9kD+hH2eZn36h3o80RUZot9yC/03YQQEIf5x/4uBZ4uCAftKRVV7jbkCuZ0hkdxhOusIUdYEWDvlDtrm70qRrER6aWGSkE9kKlRNEKiarmYEwmBNnqJ35OS0vYmUCkG8vGR20eGYR9DEKmfsJQL6zXC13XgebnTbwmLbie4k+GYS+MZ2M3rf7VyspdCQ069VJDNiHh9YG+wcY1VpQ6a9945lTTLZLKyHEPVk+hILxF+8HJxRaxmtSUSdtcVTMCO2KHmT5hKn1YTY3TNjoAxqgdkVcfo7ijl8Q8wcUgcmDmPHbLnV8qST0qfWcLOzIFCXcvB5DBUQGl9LQIkzq3DoDWzJzIQ/zqyQyF3CjJ/TIp1NEnmKazcxW7tbSLpZfmmMARVazWeSpP681MFhSo8L0XglCEOBSHN7sQKZGHWOBFUG+vipEQyOE3ou0E2voGjQQLWpqGiM67KAbEyyDwDoW0cDMjFdIJwiXz9XVsOSJWyYAyiBdOT8uSlVIZjd5F7h7lNOMX85R654JQTi7awlww17keFY8lBLwgNkzFDpR5RWqnwtga/kYfoo6mFfL877zIJ07tbgeauOmNDdZxjorZQkUxyK8khheMwUDC8kqYRghhtwwJeX9ZETHfDXuFLAL1FjT94ZXnUhN0APRJtAwCvhaUSC3qwSLl16ERHqFilIr6O1MeQvJ49I3jdTYq/xzo79TLj7RfPbTkJfbTHxdHxBMFklgVXzrhkmU7SoscXt75YLWCdqj2vGjae7BJPOhr51xPed8sFSISjChPqT3bG85Fd8gigZ19nkr12xqThxg4en84lrDU+TBF67vWoKPKDaM X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: e0be63ca-b4d8-47c4-543a-08d8f3ba86ec X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5650.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Mar 2021 20:29:33.0404 (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: 0NPkTy4m/tH6y44OHL3QVlBxwOb5KapcDo0F3onRbxjH/chqQQIAtXA59TQOT6E0MmBi1MyYfcdSxamxZk0DSQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR0401MB2321 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org For certain signature encoding schemes (eg. RSASSA-PSS), the verify/sign operation behavior depends on information contained in the signature blob. Allow passing this down to the crypto_template by introducing a crypto_akcipher_set_sig_params() call. Signed-off-by: Varad Gautam --- crypto/rsa-common.c | 1 + include/crypto/akcipher.h | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/crypto/rsa-common.c b/crypto/rsa-common.c index 6ed258a78287..f80cdfcc1f9e 100644 --- a/crypto/rsa-common.c +++ b/crypto/rsa-common.c @@ -277,6 +277,7 @@ int rsapad_akcipher_create(struct crypto_template *tmpl, struct rtattr **tb, 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.set_sig_params = alg->set_sig_params; inst->alg.reqsize = sizeof(struct rsapad_akciper_req_ctx) + rsa_alg->reqsize; inst->free = rsapad_akcipher_free; diff --git a/include/crypto/akcipher.h b/include/crypto/akcipher.h index 1d3aa252caba..a0e872029429 100644 --- a/include/crypto/akcipher.h +++ b/include/crypto/akcipher.h @@ -101,6 +101,8 @@ struct akcipher_alg { unsigned int (*max_size)(struct crypto_akcipher *tfm); int (*init)(struct crypto_akcipher *tfm); void (*exit)(struct crypto_akcipher *tfm); + int (*set_sig_params)(struct crypto_akcipher *tfm, const void *sig, + unsigned int sig_len); unsigned int reqsize; struct crypto_alg base; @@ -413,4 +415,28 @@ static inline int crypto_akcipher_set_priv_key(struct crypto_akcipher *tfm, return alg->set_priv_key(tfm, key, keylen); } + +/** + * crypto_akcipher_set_sig_params() - Invoke set sig params operation + * + * Use this if the verification/signing operation behavior depends on + * parameters contained in the signature. + * + * @tfm: tfm handle + * @sig: ptr to a struct public_key_signature to extract info from + * @siglen: Length of sig - should be unnecessary if you pass the struct. + * + * Return: zero on success; error code in case of error + */ +static inline int crypto_akcipher_set_sig_params(struct crypto_akcipher *tfm, + const void *sig, + unsigned int siglen) +{ + struct akcipher_alg *alg = crypto_akcipher_alg(tfm); + + if (alg->set_sig_params) + return alg->set_sig_params(tfm, sig, siglen); + else + return -EOPNOTSUPP; +} #endif From patchwork Tue Mar 30 20:28:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Varad Gautam X-Patchwork-Id: 411817 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, URIBL_BLOCKED, 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 664BFC433ED for ; Tue, 30 Mar 2021 20:30:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4E9AA619CB for ; Tue, 30 Mar 2021 20:30:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232565AbhC3UaD (ORCPT ); Tue, 30 Mar 2021 16:30:03 -0400 Received: from de-smtp-delivery-102.mimecast.com ([62.140.7.102]:58536 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232478AbhC3U3q (ORCPT ); Tue, 30 Mar 2021 16:29:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1617136185; 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=tulGvBsCnhbOvRxIjVzEDXvgBez3x2KNyJw/j62v9tc=; b=LrFQKsYtUEnVcPTkttvqJwwXlVd0B5LiC66wSEsxJl4vTxnIy83bJAzFZa+XeP+XDh4eZd 1VA5ylGpNWLs3UMnGyh1NNLTeiIQVTyzMSUXs382N2M0RJKxAa6HgDOK7Men+HHIt949fl Wu3M2mkiqKc0lvz2QSx6N8AtSGA0WiQ= Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04lp2051.outbound.protection.outlook.com [104.47.13.51]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-40-T7DFSz4LPS224rvkGHQkUg-1; Tue, 30 Mar 2021 22:29:44 +0200 X-MC-Unique: T7DFSz4LPS224rvkGHQkUg-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GLETIgv7XHZdNRbIDTRywgV6eOgV8Gwk24wTd/wrqB1PdOizDgQawk9LPvOWjQVo7jmraQfgixVsY8wGQljw3FDDUKQzgkPJS/oS+hGHtkBeM/1e4+c3sd+rUWdW1+5OHPOOr9R5NgxWKrbBh/Z63aiRgvtHgoQAI8wv32rSFVrqKHiKIGM4HuFDuAwdpUYzz/QdXFR8oIdz+zoGce7z1/+cP4f0acbaCPBVo3ORPPIm4YZbYi0qdiHJsqoIgoCVsrjiLNoWm0fKpMZ14FTSBkKVsoRnnqxniUGPPUwCeYQqLVGmcaPoex87cc6Tzo8Dzt6emZtylx3zbCzzSD4LZA== 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=RtaGWAilVYSzQAA4YPzjms4nCHUEHbgL2thqZEfCgNQ=; b=jxXDlwIJDYnZheWWyBfxP0wB84RkaNfrcX3MLVm/VWzU+uYVQsYJguN7HPt/vmZanjKmeALu6Vmk5dglRyRMVvMqVsAF5s/2+Ip4Z2pFGWYvASsz9DMFVTGhKIVueEYld4HmPZu6S+wDFFjHihaouK5GjSwIpBZsV7sDztbQKe/br8BfUS3txYvImVdPPlTL55kd1EeoQo7+ndgjlELpH9R1bLSDAb5i8EJzFh3O8ys/O1nfXeE3672ua38I09cCuPWTHMC4naT6bDHhfKfv/8SXrf2ZN2psHqJF5xcMJZtsuMFSuCoLxQ5jvQj6D4ZyBMgJ62/+X36/OBPmGVqdJg== 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 AM4PR0401MB2321.eurprd04.prod.outlook.com (2603:10a6:200:4e::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.29; Tue, 30 Mar 2021 20:29:43 +0000 Received: from AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::40bd:b7d7:74a7:5679]) by AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::40bd:b7d7:74a7:5679%3]) with mapi id 15.20.3977.033; Tue, 30 Mar 2021 20:29:43 +0000 From: Varad Gautam To: linux-crypto@vger.kernel.org CC: Varad Gautam , Herbert Xu , "David S. Miller" , linux-kernel@vger.kernel.org (open list) Subject: [PATCH 13/18] crypto: rsa-psspad: Get signature salt length from a given signature Date: Tue, 30 Mar 2021 22:28:24 +0200 Message-ID: <20210330202829.4825-14-varad.gautam@suse.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210330202829.4825-1-varad.gautam@suse.com> References: <20210330202829.4825-1-varad.gautam@suse.com> X-Originating-IP: [95.90.93.216] X-ClientProxiedBy: AM3PR03CA0066.eurprd03.prod.outlook.com (2603:10a6:207:5::24) 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 AM3PR03CA0066.eurprd03.prod.outlook.com (2603:10a6:207:5::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.25 via Frontend Transport; Tue, 30 Mar 2021 20:29:42 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c64d6458-c2d6-49fc-0239-08d8f3ba8d44 X-MS-TrafficTypeDiagnostic: AM4PR0401MB2321: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:466; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mmGhoGYxfgcwhCAbXRuE5ECGV35MaCW36bDRuBvsApty6RSn/Z4BT1c7CZ8tj275MmFD2HdwqcPIunRIzDvU9Ia/nYl3s3S4KmixniMGaQCglwFItwecTRat/sknPX3BqLcq9yRxZBBjOS4p3fdMzNhV3jP4E2DiLPOIBLOYXNodSeUa1NpKVCMpahNpSwHV9Vq6MYEdTZik/o97rpPafBt7JUMv2xX1Lh8Q0Vw0kNW8Q4/qxN/Y3KNcY1amYKlThg3pr+TVTZa06xI2NHO4pxZA7FvQboxOmuKePXHqjzemdEnbndKp1+bm1haVeMbJ62ngtXQ0AD1aMnNKMiy1N56jwoWOhwdFIpo9AviTLa9n203HUIkjhWk0ZD3rV14N85kWJX3fTYXmHsO6cxjQYLhPuOaiu51NSOCDeujqZYNdyLPIBZmf0csos/bXpwzgzAr676HaSWbRSzaPWCsr4cIkSI30j1RP4ryOYgKopiOlYojghUeKX+khQfp5YY7Glh4IhMgP50i2gXWsF86PtusleHyVkGnt8solnl9tKquHeQO5qY2GICdzF7Y/EsYlDbA7IEAwMgygz3NaBWDCbEa2YynOSzZ2vYVF8knNWJvcf+KiX3vteNOSjMOF/EhguGYIgJRSdVT0BxYwmfoXpw== 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:(396003)(346002)(136003)(376002)(366004)(39850400004)(478600001)(4326008)(8676002)(36756003)(186003)(6916009)(38100700001)(66476007)(26005)(66556008)(8936002)(6666004)(66946007)(5660300002)(86362001)(54906003)(316002)(6512007)(1076003)(16526019)(52116002)(83380400001)(44832011)(2906002)(956004)(6486002)(2616005)(6506007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 1fH7KpCOKIM7vDl7D/cJXnYL/WDSlITxnAf83kraP6wtXj70I120mrbwbVKXCf8rdzCgP5fIuBTyi/qiEkqQe4muuQS7UX+j1bMSfD+gvCfS1NqqPQ5P3bvqM8d8qAikCs3XWxW8UbCU2cEKsT0vgIDFXmxli4eJZDBFBb8UcKTlA48swsFto0fwUFAvas9H5AbYWGFU/fp53W6A9H/jOVb8xOzTVTtC3AchS2UnvxlNZr2H7Gp2Cg5J/5EjsMyt1rhZvRxkHpbi/bd2lQQU6vPOfU9Na00MiRVgzIc5npXlcLXlqEe1lv8yLYJo3bDv3sza/Qh+sfNrN/1u7ljdL8rBrFoVK5cEYZtETRWCGWwP4emkt3W/EmjuwfX60sqjEOICgKbdnyCbJOe1DW23suaa5iGc3Q4bsqvJ1eMvBnTxMJxhuJ6Dqt3XtUJp17QoSS0gqjWSl4fa8wi8T5VeFTvSxoijFOLk+C/eFfC8s7ee36Kn3pNod+dCNvpA71eWYt1BMPx1a5e4F/xgpxX1k7yiIYJ1zIHn5kWWUEEuatlAtyGn7Ksv98qGp7p46F1rbrLhATfZKpWLWXdJpA0XCk5/eaHD3xeMnE8mxULDVdbl16OF79kA4lyYzy8gKFh1TfgHWl0BocIYx2GidsCWVJTEC7l9Ipk8jlPnOo7oqlm3NhGJ+3sCJai6sA8F778lnIBgbSocBgZDnPmDSN0Il5O4sk3OrbHsxiey7SMdaSADd4hE0Ge2W+VWIxnsmtDQJTtXF3BIFnvCgia5wdV75OzYzSt1dvEk2e9+Pf4ukpQu+NeiACNo8hepp9cSaHZ7xLjNFF6iksrA60rRw6IhHOqMmovyAxF2+jLyOn2mUrOJSIUO7a7S9yEKyjSRj7PNz0JAwd3iftjLVJnVpNeQYRsZVVTsyt2V9GUrWpcDT6WoiKwZaV5XWIADVGkb9p9oqMVvFiQvUheNbM/lW+7f9hD9gJrFbJeLn1bWM6FvCR7oSHpIu69sTpXbBeKDSXEIs+hvizfR/53gG6rUV797xJWwOeRri8wt8TzmPjfFFT8Um/WcAsGjlsAh12vrwgoYKB9rdbfedMcecmE9rDDdra4I7nyoWnmUK5OmUjLDrDfN0WINAwEP9auWFMcKRnfkcX/zQ3mv77iiELeRkvB5TWCICuiyTcW3QNKupf+2ddO0ObGEOMBn4qCRHn0uSwxbSJpZgS6SzAB2Z1sPfnPXxL9PAgtnhvyrSR09J2DqLwBwb3G24F8aeNwMZ2IJmuCp+tHGVG4gHrX4WTUIsA6IVw0n3lBIi6MaNVNmTNacINgtZXXjYco6tQD7S1BPxz51 X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: c64d6458-c2d6-49fc-0239-08d8f3ba8d44 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5650.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Mar 2021 20:29:43.4714 (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: VlNwT4gkRngi8QZyt3X4gEbODOuz9N9/AHMmmU5kUP/Jv0kTytZnfXZDQEZUXn5oxhCeYvOelVPuTWzfR4EBZg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR0401MB2321 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Implement akcipher_alg->set_sig_params for rsassa-psspad to receive the salt length for the signature being verified. Signed-off-by: Varad Gautam --- crypto/rsa-psspad.c | 20 +++++++++++++++++++- include/crypto/internal/rsa-common.h | 1 + 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/crypto/rsa-psspad.c b/crypto/rsa-psspad.c index 855e82ca071a..bb8052821982 100644 --- a/crypto/rsa-psspad.c +++ b/crypto/rsa-psspad.c @@ -9,6 +9,7 @@ #include #include #include +#include static int psspad_setup_shash(struct crypto_shash **hash_tfm, struct shash_desc **desc, const char *hash_algo) @@ -33,6 +34,22 @@ static void psspad_free_shash(struct crypto_shash *hash_tfm, struct shash_desc * crypto_free_shash(hash_tfm); } +static int psspad_set_sig_params(struct crypto_akcipher *tfm, + const void *sig, + unsigned int siglen) +{ + struct akcipher_instance *inst = akcipher_alg_instance(tfm); + struct rsapad_inst_ctx *ictx = akcipher_instance_ctx(inst); + const struct public_key_signature *s = sig; + + if (!sig) + return -EINVAL; + + ictx->salt_len = s->salt_length; + + return 0; +} + static int psspad_s_v_e_d(struct akcipher_request *req) { return -EOPNOTSUPP; @@ -48,7 +65,8 @@ static struct akcipher_alg psspad_alg = { .verify = psspad_s_v_e_d, .set_pub_key = rsapad_set_pub_key, .set_priv_key = rsapad_set_priv_key, - .max_size = rsapad_get_max_size + .max_size = rsapad_get_max_size, + .set_sig_params = psspad_set_sig_params }; static int psspad_create(struct crypto_template *tmpl, struct rtattr **tb) diff --git a/include/crypto/internal/rsa-common.h b/include/crypto/internal/rsa-common.h index 4fa3cf5a989c..84c63830577e 100644 --- a/include/crypto/internal/rsa-common.h +++ b/include/crypto/internal/rsa-common.h @@ -26,6 +26,7 @@ struct rsapad_tfm_ctx { struct rsapad_inst_ctx { struct crypto_akcipher_spawn spawn; const struct rsa_asn1_template *digest_info; + u16 salt_len; }; struct rsapad_akciper_req_ctx { From patchwork Tue Mar 30 20:28:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Varad Gautam X-Patchwork-Id: 411813 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, URIBL_BLOCKED, 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 5EFC0C433E2 for ; Tue, 30 Mar 2021 20:32:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2EC23619CC for ; Tue, 30 Mar 2021 20:32:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232726AbhC3Ub3 (ORCPT ); Tue, 30 Mar 2021 16:31:29 -0400 Received: from de-smtp-delivery-102.mimecast.com ([62.140.7.102]:56503 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232537AbhC3UbC (ORCPT ); Tue, 30 Mar 2021 16:31:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1617136260; 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=GHepSS3Vy4lR/a3Gm+qJxWkfBniUrSrX1LTWunOaGYk=; b=L7lgt5sKGng+Ep0hluoopgIy37MIQL+5wwjk9klJMPji29920M39USdZcsPCM+MqG2+O+X NM6ZvsgzOoJfebdFOo4AGWDL9ZWo+ZL/lYoeZ/L7pjun3BpegujOxAjatKRdTizZuqQ2B7 AIKWa9cW2Qhmn+LhHWlDawCyI0kUfe0= Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04lp2059.outbound.protection.outlook.com [104.47.13.59]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-2-hL6_RrhDO3qIf8M4iqvhTA-1; Tue, 30 Mar 2021 22:29:47 +0200 X-MC-Unique: hL6_RrhDO3qIf8M4iqvhTA-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fEIu6ruS6eqMFIJD86XSeV42O2YQNtqIvsAYPeto9DmJMBokLUOW3qJ7ayqxYcKlpNoPdHRWV+EHsBrVnabr52/d8BGYE3bYPrRjGxkzKgOc3aIfTMWcWgm1a8Z8WbXFR5JDXZh07WZIz5GdVS5Cn/X6f4nIFUGUM3MiemwU5/2ZL6kbSAyJRC0N0eQaKc85wsa8bKpr3nASpEF1PaxbeqUClfBPBhDph7mXkPeiBk9KCqxDJdfkGnEsWMcLpdS7WDcTLCz1JQI1r2PyOe2DP2kq7og/hGJ2VAk166Z8ZROBMMZUJsguT+LD6Ke7zhnAn/DPU6scbXu0zk2+1rVi7w== 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=pZVZgEUnDj9tU46k6BnFUyvHlNHFhm0M8qHCOciqpnk=; b=kwc8SbkFQnjwIqC2QX+L3tXKiYJE9fadqZD2NcT4OZ/2OYpz/Bvjh2FOqXZWjLn+RV5kxCX6n2NhWY48/Dld2lrxcZLjkWdT4KSn58EtVPGKm/Asb4WowtlbP0/qEE7M5H8qc2tyg+/ieMpz9xuUdpId2+D/BIxGFGi5bxKtkctrg2TZTlVEoeCxDUTT2mEXPFXHgr61+ZCNa6AhlmrJ8XvHKspGIpJwPKVNTT436UoyuFChwY5q4awypvhY0th6UX5gOXaiUFsXud9TcKflHpA0XBmwYY/6GezJKk6bR4FpCnpeF7cgjyd6NyNraKYz2E+fzVWY058wq2jDrcOo0g== 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 AM4PR0401MB2321.eurprd04.prod.outlook.com (2603:10a6:200:4e::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.29; Tue, 30 Mar 2021 20:29:44 +0000 Received: from AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::40bd:b7d7:74a7:5679]) by AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::40bd:b7d7:74a7:5679%3]) with mapi id 15.20.3977.033; Tue, 30 Mar 2021 20:29:44 +0000 From: Varad Gautam To: linux-crypto@vger.kernel.org CC: Varad Gautam , Herbert Xu , "David S. Miller" , linux-kernel@vger.kernel.org (open list) Subject: [PATCH 14/18] crypto: Implement MGF1 Mask Generation Function for RSASSA-PSS Date: Tue, 30 Mar 2021 22:28:25 +0200 Message-ID: <20210330202829.4825-15-varad.gautam@suse.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210330202829.4825-1-varad.gautam@suse.com> References: <20210330202829.4825-1-varad.gautam@suse.com> X-Originating-IP: [95.90.93.216] X-ClientProxiedBy: AM3PR03CA0066.eurprd03.prod.outlook.com (2603:10a6:207:5::24) 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 AM3PR03CA0066.eurprd03.prod.outlook.com (2603:10a6:207:5::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.25 via Frontend Transport; Tue, 30 Mar 2021 20:29:43 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a082bb55-fbc6-4684-b480-08d8f3ba8dfa X-MS-TrafficTypeDiagnostic: AM4PR0401MB2321: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xNVqqjQb3qso8vE/f8xnGhgsYqJwDlSykq/h6dREm+VqMiV4AdHP49C3f7kN49mF3o99MwAYRObX5PyYUalPmQR0gW+7h4QW78gEG2tkhS+YLNmA9xQwfB6Fmw6J+GhjWrzCP3DbSw0BhDnB128arK9LL1pJHSPG3mdqaJ/eNWwEXerOuO8gifUN+oSx/xTsutDmXgRw3d/KPK/r6xsVTXpzH2qrL8oXcojHViY5/ak7H+AcA7/lqI1jgdkTBlfR7hlqqwyM9KhCxlpBGnXWJbLDU+ZiwGIjUG4mKRjmCRCuxvxEUXwG87Gst4qHEZDhhcHWg1wcnn/uavcvveeL9GDqF5iebRqOPQ2teC9SBg53pHdlrx+fage2RmqiYDBV4cSi1c2ZEPAqwkTF9FOTnZI1HczpYudaUEwIkBYRp2rwioMK7uJQedgTSHt9CDB7yJCexjxbJd8WSOT1NGgmwAH/PsX1p0118fpPsoVufmVHsquJJalb0SYCwcsAl89+00SJZeRAMASaMqW3DUXN2lod02Ii55Ozzj9zRZEL3dz2OS3xWcp41hzhNVnYZAIveIHDmcUK7X05Z+pYJ6QuerwEqzo8/omGk5rqhblzwhwdlwecVapm3zLQXQkmzUOw3xoLHjiN2NBvhBwb+B4UKChK1qbH09JmAjokCfAe6qm/5hAW+tC3grUh4Mi1Lafg+INyNczB49kFKt6qXdei6Nj2PPTfYi3Mo2B+WBj/6Gw= 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:(396003)(346002)(136003)(376002)(366004)(39850400004)(478600001)(4326008)(8676002)(36756003)(186003)(6916009)(38100700001)(66476007)(26005)(66556008)(8936002)(6666004)(66946007)(5660300002)(86362001)(54906003)(316002)(6512007)(1076003)(16526019)(52116002)(83380400001)(44832011)(2906002)(956004)(6486002)(2616005)(6506007)(966005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: GuJng0WLQiQ2KC5EEKYUQito3O1yB0Ba09yfb/0xKvxuz8tEmHtdAzD/yBMq0p7HlJbP9BU1/F9bJhKqbt2I0iZKXvO8QFRFvUsCWe3uEXToz7i9mhHa2VP4M5FbIuxSjDXkaIYJBzDOx+JcjT60nkuhTsccPGqMlzOVIzm7/BqDrQlsvzoWy6AtNS+JZs8jEndkfN6qOK8t+W6ZfMvcUFNb1rdMRpUJWixzxAVioxCiAQPDQhbdaZBaAGzpIzStB6yDH+hQgizytDJowMIvHFc7xAVBz5tBJC6v+8VsEyTzA5JAs0+Pu7GRjnOUZj+y+jzxhvgF95E9T5niJ4ZxsWXufpLARE1ufMScaAYYwL/IH5L8nEvznpJVDrDNjwc1eIovssU4T6ymVsVXexSTT4KqJxAynmK2MgUmLkvWP9CvpHDECT/Nk5elfcxkYTinWHV3wzvWeiCpQVfvV4KhLQw0p1/NRDnsMrBTMeCHaeeww38hxRgi0LKzStlIqTQW0ATG7A9BOZVGpINH2Ut4E+KAH1Sk1cPGw4bo+Rn2bO++Vr7r3KiX1179Etz305v2HWvn13vfFPxDiV/sMrjuxSgRTekyiRGYTopyWVxUvfbPFCXMj/MhjeVlKs+uFkgjISL321uH+OkQSdRws/xdbY1rTugE3RZELefjFoW+uB/lUUA01O7Mk/uyBiuOV9fc74pyUwX4KAEHrBtlYUOn3BCE+dixPAcbPjX8MHMDpWqp2E7+SWr4irWOH5zeFl68zAWzP2XL7xbaqrOcodkOPLAfJA2rAjHR6MO5RaOvhQUKDD+S+fgGc/DxjTvJ95RrNj1FenKCL8NaSO6I5AuEbFwXrggrufhL9A8JBXkizzesXrVgiLyRLxk5OlfqO759mLg9QeZC3xcuN5L/q0k1jYx0lRpXgmEDLFi/WlRcLs/tCa8WQ9hN5ZnkCVrcwXoUiRnIb8Mu2kuOStnR6DFbHjWbYurgRMkPFe385gorpm5MoMPISdjpnXhMGaJSp4BqtPetXUsbfu7If9ngp29NmBineiD6ocSS2iPVpSXQKw176EVQYFl7qsoSe2mnIvrbml6jxTzNXZULDbP57VvYCy3SC8cUXxbFyjfh8i6Qeqcwhr+tIkWuB0YxpYvJ/W+T2rCd1o3+hB/h2011+qANwCeljPnE1/f3Uh3iREe3q8TVKozHyKGNXgnBSX+NjpRcwcgzgkeqgZGUWjyjC2jpVIqnzviKiJi+cFXQKisT+XljyUpLeY+6bf/Y483HrEkewES4nE2rEq/xoT9vzp2XlEpmIjdzlfJlGCDwm4EUns0axsPevjVpd2gVs5LYQBdl X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: a082bb55-fbc6-4684-b480-08d8f3ba8dfa X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5650.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Mar 2021 20:29:44.7487 (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: jCYdPgFozT+rZhf4pIf6LDvMpgFI/Ge8ZJcTjbtdNDBuJOv8eJstJkl+w1ddYY9aFrWz5iv4kbwIlqcp4Zyikg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR0401MB2321 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org This generates a "mask" byte array of size mask_len bytes as a concatenation of digests, where each digest is calculated on a concatenation of an input seed and a running counter to fill up mask_len bytes - as described by RFC8017 sec B.2.1. "MGF1". The mask is useful for RSA signing/verification process with encoding RSASSA-PSS. Reference: https://tools.ietf.org/html/rfc8017#appendix-B.2.1 Signed-off-by: Varad Gautam --- crypto/rsa-psspad.c | 54 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/crypto/rsa-psspad.c b/crypto/rsa-psspad.c index bb8052821982..46578b8b14b1 100644 --- a/crypto/rsa-psspad.c +++ b/crypto/rsa-psspad.c @@ -50,6 +50,60 @@ static int psspad_set_sig_params(struct crypto_akcipher *tfm, return 0; } +/* MGF1 per RFC8017 B.2.1. */ +static int pkcs1_mgf1(u8 *seed, unsigned int seed_len, + struct shash_desc *desc, + u8 *mask, unsigned int mask_len) +{ + unsigned int pos, h_len, i, c; + u8 *tmp; + int ret = 0; + + h_len = crypto_shash_digestsize(desc->tfm); + + pos = i = 0; + while ((i < (mask_len / h_len) + 1) && pos < mask_len) { + /* Compute T = T || Hash(mgfSeed || C) into mask at pos. */ + c = cpu_to_be32(i); + + ret = crypto_shash_init(desc); + if (ret < 0) + goto out_err; + + ret = crypto_shash_update(desc, seed, seed_len); + if (ret < 0) + goto out_err; + + ret = crypto_shash_update(desc, (u8 *) &c, sizeof(c)); + if (ret < 0) + goto out_err; + + if (mask_len - pos >= h_len) { + ret = crypto_shash_final(desc, mask + pos); + pos += h_len; + } else { + tmp = kzalloc(h_len, GFP_KERNEL); + if (!tmp) { + ret = -ENOMEM; + goto out_err; + } + ret = crypto_shash_final(desc, tmp); + /* copy the last hash */ + memcpy(mask + pos, tmp, mask_len - pos); + kfree(tmp); + pos = mask_len; + } + if (ret < 0) { + goto out_err; + } + + i++; + } + +out_err: + return ret; +} + static int psspad_s_v_e_d(struct akcipher_request *req) { return -EOPNOTSUPP; From patchwork Tue Mar 30 20:28:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Varad Gautam X-Patchwork-Id: 411814 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, URIBL_BLOCKED, 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 1F483C433C1 for ; Tue, 30 Mar 2021 20:32:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ED98F619AB for ; Tue, 30 Mar 2021 20:31:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232465AbhC3Ub1 (ORCPT ); Tue, 30 Mar 2021 16:31:27 -0400 Received: from de-smtp-delivery-102.mimecast.com ([194.104.109.102]:27315 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232533AbhC3UbC (ORCPT ); Tue, 30 Mar 2021 16:31:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1617136260; 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=ZG2q3nBTbEqxhzYwuz4UXeDSfxU/8bhB/7YcV6Mt9Hg=; b=OiInAvtSmigkRLsR/thhVB9asWWrwuR22u0j9Jspl+PknKTl+iZBywsIlW8s15keUiaJq+ jiN6mgm1S6jIC6EST8KJHPhpK574R0z/jfuHWAPqzaHNhZG4EmSFGxx1MoPEYOZ0hoMZj2 1rtFfn7aOc52xi2pBoCErIfvBl93Y1w= Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04lp2059.outbound.protection.outlook.com [104.47.13.59]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-2-n6XydNNvPIOS7LMTlmq0fA-3; Tue, 30 Mar 2021 22:29:49 +0200 X-MC-Unique: n6XydNNvPIOS7LMTlmq0fA-3 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EEJDWnA/C/ACybDDif4bI9qxHE3QbZwxxVaQ9EUtS7222mUtqKyJ9FvYAWhbMo+2whXEbCQAf8luLlPHR2BDxH0Wzes6xRaEiPG5cLWeRXjoCsDPqhg7bWNwdOSQiSA8xrk8uIEQ3ULCeaRReILbSXbDTEuYJGquxUWabh1HNFT5FZc8XI0W0SDxQl/X4SjxExqHfMN1wakk6Z19KMl2A+7zgMyxwYjHSXdUVRSASuSSsYAYiuOtIivYkmcwVshpuzeXd1LpuktbJ6lwlNo39WRzQaS6R0SMauz16cAU+TH6gbFV9AwGzQNTIQA+u+pEO9YTveNS/pMNC6ZN800eGg== 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=pqf7Ev3EWaySfHRXohz7oJ4413HDR5jqJObo4e216/U=; b=WUTkk/XLDBQC+6uYAUIerHDFk58Y6kkPepJ7gOMnfVwOtzEjJAR57KHcSoeRCAu3N15VMTVFU9bdmJAkknqAsa1fitVliB0ESjD+s3V4sYJB0b4yS2T3FR8t0ShZzVuQ6VJwwjKdgkuVFycYCMVOu7r0KA+VSBA2jnNGLLmRyCXcF+359xG3UJPFJihbObZaRcK/bDC7GkQTAtzoCmzl+aIDWOZBbWd0TNP+LMHWscvwz4Hu4pAryWdGlJ9xKgz6wlU6+BLhpOO4prq82r3dey30Spe7AhkWFIscxQXE1BQOryjhPVm7BXOEO5e40XXFdUblquNllsMM3oEfjm3C6A== 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 AM4PR0401MB2321.eurprd04.prod.outlook.com (2603:10a6:200:4e::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.29; Tue, 30 Mar 2021 20:29:47 +0000 Received: from AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::40bd:b7d7:74a7:5679]) by AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::40bd:b7d7:74a7:5679%3]) with mapi id 15.20.3977.033; Tue, 30 Mar 2021 20:29:47 +0000 From: Varad Gautam To: linux-crypto@vger.kernel.org CC: Varad Gautam , Herbert Xu , "David S. Miller" , linux-kernel@vger.kernel.org (open list) Subject: [PATCH 16/18] crypto: rsa-psspad: Implement signature verify callback Date: Tue, 30 Mar 2021 22:28:27 +0200 Message-ID: <20210330202829.4825-17-varad.gautam@suse.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210330202829.4825-1-varad.gautam@suse.com> References: <20210330202829.4825-1-varad.gautam@suse.com> X-Originating-IP: [95.90.93.216] X-ClientProxiedBy: AM3PR03CA0066.eurprd03.prod.outlook.com (2603:10a6:207:5::24) 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 AM3PR03CA0066.eurprd03.prod.outlook.com (2603:10a6:207:5::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.25 via Frontend Transport; Tue, 30 Mar 2021 20:29:46 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c2b92d20-a6c6-40a0-fa75-08d8f3ba8fa9 X-MS-TrafficTypeDiagnostic: AM4PR0401MB2321: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:473; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jMtV+rYqKAcr+KX3X/5oQiJHqFpvfNxWLPL0m/g1/hEWoxyzeK8Jt/q6UJCKuNp2Z+7bEHXBACKtA8mPb4pjsu45SzIEtNOn5xb58SLuDr7BQNYgKDTzVBfWX5S7QfaNNmHlSbxMO2h+7W+0MCs8KYaNUC1BKICWnwM7aO1OBFgTfLAVq8QHj0No05EYGzFa5XwANS8MwdMjcwqQIMwkzWuDx9BaGzGO299x7yk/3S+r/Wopr4u94E/X1DF5C8Qtv3ZDXyhW3gYzf9rktRBhW9HJcWE32oSM2/X5MNVdIiYaFIpU2muzsOoNT3b5hNlSjQkdSqtVdm2GkpM8o39TQ5DGfkHsctEBWM8sxDGC60MZ+xqWDi7IwZPcKSP0piIjL6OhCS+tY+5fqJDyXq6sJUrVrCvg+2dE2ghTKIHx3fAHp7eE0c+qB9qCFKe5kymItiZVhLDxUhODn0dVRSNtSH6PGa0Hl4BJHyV8opu08GUtQqcKve/TST+wBHmeBVt+CM6zI3F8N0Wp3X1EdDmUx4MGW5hOR5DwmBSRGE5MIBSKJATnLDS1Wc5tEG/hro6wMckVGoiLf3x238DU9TjgpoAdq1ESL6QRqhJgcz2kdQBKhJL6g0zJwRoKJnBqQfyN7ECnd/QyGZIhOxbG2nDUf03MAoDXGhuPjR3p4yoUhdXn8YB39xzRwGM0BjmOKMnTr49JdZ5nG6GUfqWMjzEIko9Tej/ydgmtnd1HY8HJ3ok= 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:(396003)(346002)(136003)(376002)(366004)(39850400004)(478600001)(4326008)(8676002)(36756003)(186003)(6916009)(38100700001)(66476007)(26005)(66556008)(8936002)(6666004)(66946007)(5660300002)(15650500001)(86362001)(54906003)(316002)(6512007)(1076003)(16526019)(52116002)(83380400001)(44832011)(2906002)(956004)(6486002)(2616005)(6506007)(966005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: Rl8lyNKBn7WN0B5e6rM87TC5WR8jOr+SLpGHLTfIfxRCSCLui6qCM5VWkYbPvNdw5szyv6a7TTQvScagsb6RavMQmHakb/Ykb+AtCama5PQYlwuPvr4VWiYBTnsAhUu3ywDSLzRnKURvpoEgbAQofQZ7LPExy130UsxBlDonURcH87ThKLoI0sM9y0rW9wy54hh/1TX/Vok/pwnVfP/A+3Jvw3JP6gz41G/HNCMEC9Pcb0LBtrDLRdK7L65JAVbLBmfytDHTG/HS6fdsREoMbwfLEspa+M6NEDFrsKwEOF26/L2tPnuX5De4B8t9RvdGjw9mfbJkdSvURIEnEyJibo7wDnwqWyK78sX6tDPdzHFLkil6LE3l0EtEYUqufDfPsqcqH9n7p7BBNZjKmD1r23wknthDyUu0XduAi109XbiZM5IlQBzIIArIcl2Yngz3DfkXU+JsNE7+erM04C8xoNDOxaPqSr08S06XytvUqkvSzxYVAsWEKNE1/G6yNrivQq53Bq1OBpEX4Pxa+IGyjeQPTbrCwRd6eeMZ/rb8U1UpKyViOJV8ZkGBe1MLDmF1UbjkDfJYeStqP3RsAGulLYG1sEHacaFgb7OdIK5UhAKA1v13JwIrPyg7jV7WPD4N5TAiinqrmuvLCPbYiJzccg8vii6rb8i45rS96XvrGDdmrwBMm8OIJze5HIXJpn9jYbznnkiXxgCBjF04kkT5VtHQ+Tp/FywTl4x4cCbL4SzTaHcjZRlWGbCpWkDUb5V+8JdSQ+qKbq9RT6CHeSfy7OUOMm9hkVLCdt16DrZOclYK2t2Jolnki7WZbV1Ft3SSSkymvVDvpKULHCWeg1rMwmGWxmfncVAaJQ2ZqvZWm84H+UPMl+R7urFkoTvtI5Gz8Kh3owzYzLsPusQQmgfX1D8SoWPWXFEmgJFGEs/I66tYumg7oSaDwBxWEYSDUOcnP6FZnijO219FdJSTz2Rv+eZT7Wq3wRuozdg9mZSbsxppt82uBFHPM+OlRx22Zj1u+z5vGlmyLLM58TJyG5PRnAZcieKIXiFQe6x1+jUVKKsvMA5poK/U4So1/4/3mM53+new3oq+XIVoNT+ICthHCzENVbu+0hw7s2JRMRP/CNGuTMJ0sb1PoY9DlqKpX56yuMUZmECTlBE3WSFSsp7du5IUq1khhxO5UMnt0gNgM0EiMl4AODt7nzCxvyzQOdPHL+A/hjpIBdCBNRfjWAMcFUezNNHqwz1R+QPw2qauqcWxmKZ86k5VrBufLhgiRyTBQZtm2m5Whfn2oDodLKh63gNjzFWmJeNWSD41oxZC/c+wkyMyYPqRN2mvBMaafusN X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: c2b92d20-a6c6-40a0-fa75-08d8f3ba8fa9 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5650.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Mar 2021 20:29:47.4952 (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: KTbZ/jdvJlPBX0G2h+i+iZWbsGqO3dOdIPajjwwyZ5EOy2eDj18yIsU6fbQhDDgRDFERjMLlnBxpjYT1UgaMAQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR0401MB2321 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The RSA output must be processed as per the EMSA-PSS-VERIFY operation from RFC8017, which forms the core of the PSS signature verification. Implement the verification callback, which operates on the RSA output buffer. Reference: https://tools.ietf.org/html/rfc8017#section-9.1.2 Signed-off-by: Varad Gautam --- crypto/rsa-psspad.c | 107 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 106 insertions(+), 1 deletion(-) diff --git a/crypto/rsa-psspad.c b/crypto/rsa-psspad.c index 1ca17b8b93f2..2ce750c5a23f 100644 --- a/crypto/rsa-psspad.c +++ b/crypto/rsa-psspad.c @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -106,7 +107,111 @@ static int pkcs1_mgf1(u8 *seed, unsigned int seed_len, static int psspad_verify_complete(struct akcipher_request *req, int err) { - return -EOPNOTSUPP; + 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); + struct akcipher_instance *inst = akcipher_alg_instance(tfm); + struct rsapad_inst_ctx *ictx = akcipher_instance_ctx(inst); + const struct rsa_asn1_template *digest_info = ictx->digest_info; + struct crypto_shash *hash_tfm = NULL; + struct shash_desc *desc = NULL; + struct rsa_mpi_key *pkey = akcipher_tfm_ctx(ctx->child); + + u8 *em, *h, *salt, *maskeddb; + unsigned int em_len, em_bits, h_len, s_len, maskeddb_len; + u8 *m_hash, *db_mask, *db, *h_; + static u8 zeroes[8] = { 0 }; + unsigned int pos; + + if (err) + goto out; + + err = -EINVAL; + if (!digest_info) + goto out; + + em = req_ctx->out_buf; + em_len = ctx->key_size; + em_bits = mpi_get_nbits(pkey->n) - 1; + if ((em_bits & 0x7) == 0) { + em_len--; + em++; + } + + h_len = req->dst_len; + s_len = ictx->salt_len; + + if (em_len < h_len + s_len + 2) + goto out; + + if (em[em_len - 1] != 0xbc) + goto out; + + maskeddb = em; + maskeddb_len = em_len - h_len - 1; + h = em + maskeddb_len; + + if (em[0] & ~((u8) 0xff >> (8 * em_len - em_bits))) + goto out; + + db_mask = kzalloc(maskeddb_len, GFP_KERNEL); + if (!db_mask) { + err = -ENOMEM; + goto out; + } + + err = psspad_setup_shash(&hash_tfm, &desc, digest_info->name); + if (err < 0) + goto out_db_mask; + + err = pkcs1_mgf1(h, h_len, desc, db_mask, maskeddb_len); + if (err < 0) + goto out_shash; + + for (pos = 0; pos < maskeddb_len; pos++) + maskeddb[pos] ^= db_mask[pos]; + db = maskeddb; + + db[0] &= ((u8) 0xff >> (8 * em_len - em_bits)); + + err = -EINVAL; + for (pos = 0; pos < em_len - h_len - s_len - 2; pos++) { + if (db[pos] != 0) + goto out_shash; + } + if (db[pos] != 0x01) + goto out_shash; + + salt = db + (maskeddb_len - s_len); + + m_hash = req_ctx->out_buf + ctx->key_size; + sg_pcopy_to_buffer(req->src, + sg_nents_for_len(req->src, req->src_len + req->dst_len), + m_hash, + req->dst_len, ctx->key_size); + + err = crypto_shash_init(desc); + if (!err) + err = crypto_shash_update(desc, zeroes, 8); + if (!err) + err = crypto_shash_update(desc, m_hash, h_len); + if (!err) + err = crypto_shash_finup(desc, salt, s_len, m_hash); + if (err < 0) + goto out_shash; + + h_ = m_hash; + + if (memcmp(h_, h, h_len) != 0) + err = -EKEYREJECTED; + +out_shash: + psspad_free_shash(hash_tfm, desc); +out_db_mask: + kfree(db_mask); +out: + kfree_sensitive(req_ctx->out_buf); + return err; } static void psspad_verify_complete_cb(struct crypto_async_request *child_async_req, From patchwork Tue Mar 30 20:28:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Varad Gautam X-Patchwork-Id: 411812 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,URIBL_BLOCKED,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 EC62DC433E0 for ; Tue, 30 Mar 2021 20:36:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BD78161985 for ; Tue, 30 Mar 2021 20:36:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232236AbhC3UgS (ORCPT ); Tue, 30 Mar 2021 16:36:18 -0400 Received: from de-smtp-delivery-102.mimecast.com ([62.140.7.102]:43852 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232381AbhC3UgE (ORCPT ); Tue, 30 Mar 2021 16:36:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1617136563; 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=9zKKEj6MKz/JIXNozOfbnLGlLfXIRj4Xfb3E1WrMoKc=; b=QoIRLP+Gz1Z/XJj0zaesd070/ZI+VjhJBkN6VLPoy7oqrrcj/6bLIF3a7uokpD8JhRDwyt LpWhd+7+/MUpxutVXeZnIf7FrQQeQu46OY+NDKz3y13ThOBx0qDrIM8F8lN0a/3dFjGhb1 HRmBIN7IdvcTIpZWmO0gegx7SDtflTQ= Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04lp2059.outbound.protection.outlook.com [104.47.13.59]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-2-1T9VMgkXOxK41rOU3XVbkQ-5; Tue, 30 Mar 2021 22:29:52 +0200 X-MC-Unique: 1T9VMgkXOxK41rOU3XVbkQ-5 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=M9RUYUPo9OYm9Oyn1GvKp2/kmgv+ixw27L5yvljB4YwVZWF9T7K3W3UqQXga5EVnIBumqbsOg9gnKca4u9/4OgneGB+18n+rqMk8AwJx+RTGoLCcevqp6maFl3DbCBzDpH+h3P6C7Hn4Db3l1NW081A4ff++yurx0c3TkOPmkdFna0IVEk5EPc1DUjUDbyqC1vdzh3E+7i+qbsUq14Kg/RAu6RlZX+XCEmAUpJKzfUmRSSnur0RvuVOj2iWGSHVsvz7sZ6G3CLzuM+X3e+wTPv0IG9PL6iwVjeBeDvSIXlbNdsuOEU+IM2+a46ArO4/NsoP5QzZpmvFHobR0R077WQ== 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=0PGs18I+TKe1h2xOALY1QG3g4J+7kNSWv6sCbnQ4WQ4=; b=A7TrO2Eut/GSeDfgTdDda2tw3c9WJL5OPxwBgklTpp83RsJcQV96y/ozrJWvad3aOq8v83vOhwI4wcWq8tjCecj8CWlAUzH3s0g012TestlCMKTzGokkD8ZOQ1aArqtxDbc7THIe0dzC/NtlY1vMdRPp20H0XKVNbexVziedjRVjQQ63QxsfY57TbgRKl7qEVTjOkD2NjY7spvyv+ebLbbi5qyHima6LS4l4zI6dUUO+X8pmP2yL2Cu8uS5osjx5/BA598hQItyVWmc59vE8IhjSpGqKrmFi1au2pLgyRhol9JS6Of9R67L+qkp+6O1PQPk/wIe9G4csaymJ6H4hlQ== 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 AM4PR0401MB2321.eurprd04.prod.outlook.com (2603:10a6:200:4e::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.29; Tue, 30 Mar 2021 20:29:50 +0000 Received: from AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::40bd:b7d7:74a7:5679]) by AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::40bd:b7d7:74a7:5679%3]) with mapi id 15.20.3977.033; Tue, 30 Mar 2021 20:29:50 +0000 From: Varad Gautam To: linux-crypto@vger.kernel.org CC: Varad Gautam , David Howells , Herbert Xu , "David S. Miller" , Jarkko Sakkinen , James Morris , "Serge E. Hallyn" , keyrings@vger.kernel.org (open list:ASYMMETRIC KEYS), linux-kernel@vger.kernel.org (open list), linux-security-module@vger.kernel.org (open list:SECURITY SUBSYSTEM) Subject: [PATCH 18/18] keyctl_pkey: Add pkey parameter slen to pass in PSS salt length Date: Tue, 30 Mar 2021 22:28:29 +0200 Message-ID: <20210330202829.4825-19-varad.gautam@suse.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210330202829.4825-1-varad.gautam@suse.com> References: <20210330202829.4825-1-varad.gautam@suse.com> X-Originating-IP: [95.90.93.216] X-ClientProxiedBy: AM3PR03CA0066.eurprd03.prod.outlook.com (2603:10a6:207:5::24) 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 AM3PR03CA0066.eurprd03.prod.outlook.com (2603:10a6:207:5::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.25 via Frontend Transport; Tue, 30 Mar 2021 20:29:49 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 15ccd719-31f2-4bed-73b9-08d8f3ba91a2 X-MS-TrafficTypeDiagnostic: AM4PR0401MB2321: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:366; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: CnLOumaz7PKgFVT5rwTmttS6CsR/9KTjcBVagzaidQr2+Lr478SDYx5/drqm9gTkef3dQTfCVLU5dZ2dKstUhp5i5OjY+WKrNRU6syyEojSv88WP0gBfQf3fSOs48cCalyq3Ou++xKAArLjMGTjDriW/xR3GTyL3G4+eq9iVQeQ5wU2BEfFBw5yqmCF/aT24xlJN58tTDxBOOG8k0tUFAEkn5EJfdX0BXoRyXUwIiyTD/Kg8+ie2cvfOVukU+rDdEejC2tjXN9pR4EvVRZe3r2jXQzJu6Y0c0qSS80wLOMtoW/WwqFmQOmh+lkAGt9m/hPXRhQWJWwFDpchQ6nsXQ/psolaQ2J9G6FaWxNcmUfK08M6PLimNOus1JlRVFU4b6sVzUpjzqm9sNh9JPR7OeE2910tpHsJES613msjvJIzBvSp2VKMMx3Hs4d4WzOIbKz3MKPKunppFzkfuVMlt2su13wUP3wQLAbTLW+KruSiCa7u/ZfFJ/KijP09EoJBZLd2Ij8jj622W/8T1RxuM0BRVDC1PPpVE8N5LVWmJ0P4JySVBALncf1XOOTCiFVSx/CXiyY2axKQuqXt5li76dH3bJ+NF2+RONocQwF98RcXwN4ch5fNIWm0rTIhv4os0K4Lq8sQHefFbpp9uYlUV0Q== 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:(396003)(346002)(136003)(376002)(366004)(39850400004)(478600001)(4326008)(8676002)(36756003)(186003)(6916009)(7416002)(38100700001)(66476007)(26005)(66556008)(8936002)(6666004)(66946007)(5660300002)(86362001)(54906003)(316002)(6512007)(1076003)(16526019)(52116002)(83380400001)(44832011)(2906002)(956004)(6486002)(2616005)(6506007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: IgddJZYhEEWDrsRka/46BTacDL53UkVauxk67rtWsZEO1uyoN3vP735hhIplCq2c18whlE6CUUm9185CyKDpii8gICdpeUyDxJSof8EQlSMngirHaSJC30BzBTfEws9KHGVvK9cBusxIgdLT35EmV9V/gFGQAKU9D6ceNAF8V8nYcqvBcuKNbaInfH7ipoB8kamlO2boR81H5stfNe0I1RhT3y3GMPpTZxbc9BvG7g+qUrQtSmmYqUU0WXpFcEARUPYV29JjdjnnkuEAPB0OCVmhS9p0zR6EEfqN1u+sn7WEk3Z0M7DAJ14LxZBIL1XMmvWHs5SMTfGCG8BP0wFh4j6LaDLMLPq2EdH+7DtVsXPhA5MLAtsCMseMVoKjcRxNsPqT718mhtdKWrR+vXM2ccH16PHI8QuM9lR/rvCx/RDRNAr13O+Bdo4Jc66MuJiAOnU+S9gBctExcnrh3CDimlFQc+x45BKHss7DJKIKpn1N2Ro24/jyFA3zSRVnDRaewJpiQsQV6YCd3qE12BUSDED+9nYYAp3mtwC8rrBLCM2rMSyJs5+MiYwqLi2V2/ZC22cla8jpS1sD/V9OvOQSKZM6yoBZulTbXfu1I0qT3sJaF5Af6BxG9TVdafmoSotBcvul1FnE9Bs5ySlLEdx4aMIFGaxaJ4rgOxAAW8/jrrdpoz9qu+/uhTQhTDi3t5Wwk254y+H/0SkuDKFETdy+3UBGG9Zi3nMkC6VbWSmiwVc4fF1wyrxoo97JoW4R8+wYLEfwhxNNvx2Ww+xVLSj/CTol3iRUyMGR0xX4zkjiJ23e2LfvZM0pFvRVe0seh+6+kOqV+KDLShwXEFv4D3umxmBpxlXpdPqGIUj0jIZlW1VfQgdR733AnxyV0RE32XSwp68ZmkXOAgRsUVfCQn/111PRLN3GJ8CuPcthWc9LynqkA/fT+ctm5KbwEdKv/WARlvfJLU9V/oqHaTezZosxYFSYGK6lcoW3Al3yK8uJl+2lQRPf6L49t4Af3AW4z++68y7y6kes9SjDbPvLgiTSwxCmbzhhJUIvxlmmjw9MZZP6Qm3YpFnQCy/E5XmVHfTqOvyxZjgPlgjN/XmgPFtJZHAeLZifWYe0QPYNVNd9XpwhFIuc/TpgBkCAZWFUWpFYfVfPfp/ZEqHZCg38KsysYejR3Y30KUp3jMwlMUu59des4XZcwgHchAAKTw95khXZ+dciOiAWrJ7wZdZGR2/xqVkJM+96ZneeoZe8/9ee5/PhCQdK4enEZmB0Xl1jwmx3sc7E45yRnMKbyOxwXEiaWresYqXbgm/hqfTgqbFjRrcv0A7CMvH/sprxcdYTWAuG X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 15ccd719-31f2-4bed-73b9-08d8f3ba91a2 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5650.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Mar 2021 20:29:50.7613 (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: STsh3HwcwDOQGFS8jMo1y5V4njnoPk7L7djVQks0ZqXw97i+4UsB1GwDH0r7cO+9k+J+pFsPbRv/PtxaT7Tw0w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR0401MB2321 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org keyctl pkey_* operations accept enc and hash parameters at present. RSASSA-PSS signatures also require passing in the signature salt length. Add another parameter 'slen' to feed in salt length of a PSS signature. Signed-off-by: Varad Gautam Reviewed-by: Jarkko Sakkinen --- crypto/asymmetric_keys/asymmetric_type.c | 1 + include/linux/keyctl.h | 1 + security/keys/keyctl_pkey.c | 6 ++++++ 3 files changed, 8 insertions(+) diff --git a/crypto/asymmetric_keys/asymmetric_type.c b/crypto/asymmetric_keys/asymmetric_type.c index ad8af3d70ac0..eb2ef4a07f8e 100644 --- a/crypto/asymmetric_keys/asymmetric_type.c +++ b/crypto/asymmetric_keys/asymmetric_type.c @@ -571,6 +571,7 @@ static int asymmetric_key_verify_signature(struct kernel_pkey_params *params, .hash_algo = params->hash_algo, .digest = (void *)in, .s = (void *)in2, + .salt_length = params->slen, }; return verify_signature(params->key, &sig); diff --git a/include/linux/keyctl.h b/include/linux/keyctl.h index 5b79847207ef..970c7bed3082 100644 --- a/include/linux/keyctl.h +++ b/include/linux/keyctl.h @@ -37,6 +37,7 @@ struct kernel_pkey_params { __u32 in2_len; /* 2nd input data size (verify) */ }; enum kernel_pkey_operation op : 8; + __u32 slen; }; #endif /* __LINUX_KEYCTL_H */ diff --git a/security/keys/keyctl_pkey.c b/security/keys/keyctl_pkey.c index 5de0d599a274..b54a021e16b1 100644 --- a/security/keys/keyctl_pkey.c +++ b/security/keys/keyctl_pkey.c @@ -24,11 +24,13 @@ enum { Opt_err, Opt_enc, /* "enc=" eg. "enc=oaep" */ Opt_hash, /* "hash=" eg. "hash=sha1" */ + Opt_slen, /* "slen=" eg. "slen=32" */ }; static const match_table_t param_keys = { { Opt_enc, "enc=%s" }, { Opt_hash, "hash=%s" }, + { Opt_slen, "slen=%u" }, { Opt_err, NULL } }; @@ -63,6 +65,10 @@ static int keyctl_pkey_params_parse(struct kernel_pkey_params *params) params->hash_algo = q; break; + case Opt_slen: + if (kstrtouint(q, 0, ¶ms->slen)) + return -EINVAL; + break; default: return -EINVAL; }