From patchwork Thu Apr 8 14:14:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Varad Gautam X-Patchwork-Id: 417579 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=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 A2E76C433ED for ; Thu, 8 Apr 2021 14:16:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 77E7D61151 for ; Thu, 8 Apr 2021 14:16:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231371AbhDHOQP (ORCPT ); Thu, 8 Apr 2021 10:16:15 -0400 Received: from de-smtp-delivery-102.mimecast.com ([194.104.109.102]:56515 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231672AbhDHOQO (ORCPT ); Thu, 8 Apr 2021 10:16:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1617891362; 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=4UO531muU9PFWM7c62JXlneUKIoLMkzWaK0fMBqgWqA=; b=leX4vE5USUzTD5Dfr+Imrc3ck+yt+5+dlTn1zIputJwW1NRr1EOkNt5aioAG8c1iNT2tIm znGUclj2lIvP/iuK7yH5La11NGAp1bYYIKEOH/mOKGFWX45mshfHuFnJhBTC7vb5upxhV2 lWDIIh7Fzig9iRYFwfwhB/EmlN8KCho= Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04lp2057.outbound.protection.outlook.com [104.47.13.57]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-27-ewTylNUtOQW7CNWuBvTWyg-1; Thu, 08 Apr 2021 16:15:55 +0200 X-MC-Unique: ewTylNUtOQW7CNWuBvTWyg-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GUi5QtI0H8gT21OtDKJJyEXPhQbowpFBLv4sDXdLPCQBrSaPGGhN3rbYVutHueKV7NyXqSNNgkcb2KOF8pGssj7cp6uYFTVU0/4MbQRuQe0mKVzlMLTO7JYsOP762/gEFnsMkvZYPLl4ohHZfUO262RHIP/EzdK0l7c6kIisym6EzAwuxTSfb7MLux4S0MzfCPLiGuRAb4C1tOd07TVMUCT4eY8I4DU+EbkW5CdPWfcsymg1uWIc4vx3xrH/xcCkHcyo9qYtTrnlmtdK1tUDm3c21WUSPd8KpbQozVpl45eoSyZVK0+WIwTY+L0DSazwF3EaO9gAHnxQ8V4nLOKSaw== 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=rmU+FZ7o8j5qnfLP6lKhFRSQRV5jYbVL7Gi1NqlT7s4=; b=CiMhM+6Dr6ReciPPOUOIFwfh5VRzOZq98zhj81CbCk8SHCCcIyL9Q/VpHi35hgSdHPqjGjg1ZETodOc9X7CqQRzhQ30ihi06FMhODiebMtf67wjMACH1JSqQyxq+sZ6V7xp/Dp6/8Hu4EMfituGRy7EZ4Zj0sUx9Ll6cGIG7qI9CfXIEIieRdZ70qDB+AaIkgMrxH232JXWeonVtrxtyD8/ZR9G0Zi+/DVkvCP9qHrfNxLWs+FJfcqN+QIAIxyO0aBJPSxKzmu4+GoODQ6hbsuRPQdR3ZLPChM0bS0a10Xs3vwDbMoasmxmHqfkwsynNbZ2Okf6fQ4dIaL/IoYPgoQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=suse.com; Received: from AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) by AM0PR04MB6289.eurprd04.prod.outlook.com (2603:10a6:208:145::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.18; Thu, 8 Apr 2021 14:15:54 +0000 Received: from AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d]) by AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d%6]) with mapi id 15.20.3999.032; Thu, 8 Apr 2021 14:15:54 +0000 From: Varad Gautam To: linux-crypto@vger.kernel.org CC: varad.gautam@suse.com, dhowells@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, vt@altlinux.org, tianjia.zhang@linux.alibaba.com, keyrings@vger.kernel.org, linux-kernel@vger.kernel.org, jarkko@kernel.org Subject: [PATCH v2 01/18] X.509: Parse RSASSA-PSS style certificates Date: Thu, 8 Apr 2021 16:14:59 +0200 Message-ID: <20210408141516.11369-2-varad.gautam@suse.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210408141516.11369-1-varad.gautam@suse.com> References: <20210408141516.11369-1-varad.gautam@suse.com> X-Originating-IP: [95.90.93.216] X-ClientProxiedBy: ZR0P278CA0137.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:40::16) To AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from xps13.suse.cz (95.90.93.216) by ZR0P278CA0137.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:40::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16 via Frontend Transport; Thu, 8 Apr 2021 14:15:53 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a2873a6b-b6ac-471a-c7da-08d8fa98d221 X-MS-TrafficTypeDiagnostic: AM0PR04MB6289: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:597; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GWgV22iRMSWa53dUmrLzagse58Ku+WdC4o6uraZILvZnY1byjlGZrYznX2vKJRVpYB8/em8H9e3e6nqgGuo7+lsAn7r+BS6wmcyqpCQ+g+5MAA1+JlJyCRECEptyq1xAQrzboLIauWBGoIoN2pQgXQ4NVgH5eKzgTrG38TtjNz5LbxaeYpRJ5J1MDBGU8TpBQU1qYGacOqkNgqJspYFuwZeZR7k2QcSOY4JnjIGY9rjC2QwKl+QQqSwaxW5fEqL1H34LnarTDNzn1U3rHmhOBGZPePB3EiwhT3vGZCNpysk+6I8RVSR5/kdo/FHePCwB+pbbjjFsk0a47wb6k4qoa+TebBIsh7nSHNzLKZcXnzQE5/7pATrPUDAfTVNgc2bN/1V7uL3FMU6AqGxoxCb3PxAUwoeogZYIlmQJKuULe7GznAR0jL/72OKGNWl6skY4Y5yTO62FmmwdQsMsfOIxPDuC+3dHEWYTm2ZxugBFy/Ts6YAyuvt7Qv5a8XtpjK5luCtwNZM936JIxuEKLQW1b4n0B2jPe8KfkvAaqmYvEFvb7mwdLleALPCjfsYpPx4M8EZl0GiXkmVLfwSYKJvCU+DijvRT22Va3Li5R+qenImsk9OF68Tud96CUpLUojC+YnZrhj2r87Pq2eyava98jX91XtfuCAaxhK+obvFDKLjNFVw+WOQ4WN3IbFC5BhBjDNQCu876UQrmZ6ymSr38Ao6WDxsQnLsNpo24B2ifTNWQYeQKDVYLvU35v8PILfta X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR04MB5650.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(396003)(346002)(376002)(136003)(39860400002)(186003)(83380400001)(16526019)(478600001)(6486002)(38100700001)(36756003)(5660300002)(4326008)(6916009)(1076003)(66476007)(316002)(2906002)(66556008)(26005)(38350700001)(2616005)(966005)(956004)(8676002)(44832011)(8936002)(6506007)(86362001)(52116002)(66946007)(6512007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: c9qoR1W9bwDQzMG2HDrJGy7Pk4wvRyCuT4sm/dPqruaEOKr3GWOqaW0YeJK7YxeepoYL4JcgkljH8Lp1rf1zuhb0vX/RZmrXujUtV92swDys7kA5nokPAaTZsk2UExVLkOUbeDBhCAX4ZcyzMspHtdy2gHAjjeX9zwFEqt/rlZuOuvaFKhzDHHdX2QFstJX6FQnne5IBJ006tE32UM8VW7KlQtlz7FLUO7zX4/OVkIeh1vjYsu8q4g6NI8NOM/5L7RXj1Nbw7EHP+fDyCpJvKFCIhDAqa8VlftrMHJT+9k2BuTbHKB7Z71gsGQj2wNo1ysA4K3ILJ4kzZYbLr3LbPnCU5pZu4rkDR0kWDNLJxuhyS71inTOy17+48czv4VY2hygQSL2j044PnpDhFEfH+f5bJTNow/Pnk8iJzeZ6dqtYYplSwHmAtpqZ4QoVXGcXqvE9aPAVWCiWxqJP0V2NBI3viJNz2DDNwQmProzvB22jhoOCOS9Zc9vuhof/WEbBBVjCiO6lgeSdlNaaFqGVTl1obyEQSvRw275YMIdbcV6XB7vQI6HTDyUEbQ0x/6jnJRCQkSNpBQmjSESF42Yf+YifMFxXfr7+1978ccR4f6OavLYLvcCoRDaJEzIlv7wtCUZWC9szH6aDT4Q0oi9BLnc+lUPYA9A+wkpM6PNuWc8gB5ZyNGmVwRi7MYkGHGL4Lzuaw6WwYJT8Ldctyb5P0RXntqO/vbfHS4wdKLSJq27CQPx/7dNoumV8qaQRsbHTSJKAykY13s3HK0CWqes702qRwxeUi6X0H8UZcRJRQE07Xjd2wYE3Wo18RmYrsF9gp0NBoqvtQEiLR1TcgysvISs5cf12bQ3/DsrRspbK5Ip+f2rPpU5CRCYHTp9NrFtdHrq8evJwki7a5JaJ37APXvLUUW6JgxRgrJLr1JrIGCjlN+Hu1WsANnwavSUXl9dMpxBZrxPhb6+6Bb5WiQnMoQz5mXz92XO3YVkdVci18DZ9X+3ApsN50FFNYoIZOFFF3LZZQNl2T6UybiOmBW+a6azBGkoilartEkyDpeNiMgCMJyXrAcs9/dDGd1XlL9NkeTF0zMox5sp29UpISsR9etRtrctXeOhrDJGzvRZ4usAVgTzZcQLhWnUZCFuKOPDzIHNoHU7rcc5VF842wm8YALlFwLPyD6BegzsYz/xwuJiDvF4wX63kBpTvXakj/Fz7Y9nMW0Yj30BDTCCfQxEDaqVsKLXMKlPY96m3bKgjamAjAnLQY0nUEYa4NtUWvBlpglWlCnEMOVBduuXOdd8b+I89QgknDwnfj2CtIsbjJ5Ch1Kka5sEkWK6UYtmhUvEg X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: a2873a6b-b6ac-471a-c7da-08d8fa98d221 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5650.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Apr 2021 14:15:54.1756 (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: xQf4cgCRLR8Hfo3NL0bX3Be/E7ckcC4JPCo5sNigdKC0Kq3jj8ec1czNM2FNtXhGkETSyn1ZPYISslL9UUxcCw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB6289 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org An X.509 wrapper for a RSASSA-PSS signature contains additional signature parameters over the PKCSv.15 encoding scheme. Extend the x509 parser to allow parsing RSASSA-PSS encoded certificates, with the defaults taken from RFC8017. References: https://tools.ietf.org/html/rfc8017#appendix-C Signed-off-by: Varad Gautam --- v2: Remove check to reject certificates with differing mgf hash and digest hash algorithms from x509_note_pkey_algo. crypto/asymmetric_keys/Makefile | 5 +- crypto/asymmetric_keys/x509_cert_parser.c | 148 ++++++++++++++++++++++ crypto/asymmetric_keys/x509_rsassa.asn1 | 17 +++ include/crypto/public_key.h | 4 + include/linux/oid_registry.h | 3 + 5 files changed, 176 insertions(+), 1 deletion(-) create mode 100644 crypto/asymmetric_keys/x509_rsassa.asn1 diff --git a/crypto/asymmetric_keys/Makefile b/crypto/asymmetric_keys/Makefile index 28b91adba2aed..f79ed8e8ef8e2 100644 --- a/crypto/asymmetric_keys/Makefile +++ b/crypto/asymmetric_keys/Makefile @@ -20,15 +20,18 @@ obj-$(CONFIG_X509_CERTIFICATE_PARSER) += x509_key_parser.o x509_key_parser-y := \ x509.asn1.o \ x509_akid.asn1.o \ + x509_rsassa.asn1.o \ x509_cert_parser.o \ x509_public_key.o $(obj)/x509_cert_parser.o: \ $(obj)/x509.asn1.h \ - $(obj)/x509_akid.asn1.h + $(obj)/x509_akid.asn1.h \ + $(obj)/x509_rsassa.asn1.h $(obj)/x509.asn1.o: $(obj)/x509.asn1.c $(obj)/x509.asn1.h $(obj)/x509_akid.asn1.o: $(obj)/x509_akid.asn1.c $(obj)/x509_akid.asn1.h +$(obj)/x509_rsassa.asn1.o: $(obj)/x509_rsassa.asn1.c $(obj)/x509_rsassa.asn1.h # # PKCS#8 private key handling diff --git a/crypto/asymmetric_keys/x509_cert_parser.c b/crypto/asymmetric_keys/x509_cert_parser.c index 52c9b455fc7df..19cd162acdb06 100644 --- a/crypto/asymmetric_keys/x509_cert_parser.c +++ b/crypto/asymmetric_keys/x509_cert_parser.c @@ -15,6 +15,7 @@ #include "x509_parser.h" #include "x509.asn1.h" #include "x509_akid.asn1.h" +#include "x509_rsassa.asn1.h" struct x509_parse_context { struct x509_certificate *cert; /* Certificate being constructed */ @@ -38,6 +39,8 @@ struct x509_parse_context { const void *raw_akid; /* Raw authorityKeyId in ASN.1 */ const void *akid_raw_issuer; /* Raw directoryName in authorityKeyId */ unsigned akid_raw_issuer_size; + const void *raw_sig_params; /* Signature AlgorithmIdentifier.parameters */ + unsigned raw_sig_params_size; }; /* @@ -101,6 +104,15 @@ struct x509_certificate *x509_cert_parse(const void *data, size_t datalen) } } + if (strcmp(ctx->cert->sig->encoding, "pss") == 0) { + pr_devel("rsa enc=pss hash=%s mgf=%s mgf_hash=%s salt=0x%x tf=0x%x\n", + ctx->cert->sig->hash_algo, + ctx->cert->sig->mgf, + ctx->cert->sig->mgf_hash_algo, + ctx->cert->sig->salt_length, + ctx->cert->sig->trailer_field); + } + ret = -ENOMEM; cert->pub->key = kmemdup(ctx->key, ctx->key_size, GFP_KERNEL); if (!cert->pub->key) @@ -194,6 +206,7 @@ int x509_note_pkey_algo(void *context, size_t hdrlen, const void *value, size_t vlen) { struct x509_parse_context *ctx = context; + int ret = 0; pr_debug("PubKey Algo: %u\n", ctx->last_oid); @@ -238,6 +251,35 @@ int x509_note_pkey_algo(void *context, size_t hdrlen, case OID_SM2_with_SM3: ctx->cert->sig->hash_algo = "sm3"; goto sm2; + + case OID_rsassaPSS: + /* For rsassaPSS, the hash algorithm is packed as a mandatory + * parameter in AlgorithmIdentifier.parameters. + */ + if (ctx->raw_sig_params == NULL && ctx->raw_sig_params_size != 1) + return -EBADMSG; + + ctx->cert->sig->pkey_algo = "rsa"; + ctx->cert->sig->encoding = "pss"; + ctx->algo_oid = ctx->last_oid; + if (ctx->raw_sig_params) { + ret = asn1_ber_decoder(&x509_rsassa_decoder, ctx, + ctx->raw_sig_params, + ctx->raw_sig_params_size); + if (ret < 0) + return ret; + } + + /* Fill in RSASSA-PSS-params defaults if left out. */ + if (!ctx->cert->sig->hash_algo) + ctx->cert->sig->hash_algo = "sha1"; + if (!ctx->cert->sig->mgf) + ctx->cert->sig->mgf = "mgf1"; + if (!ctx->cert->sig->mgf_hash_algo) + ctx->cert->sig->mgf_hash_algo = "sha1"; + ctx->cert->sig->trailer_field = 0xbc; + + return 0; } rsa_pkcs1: @@ -439,6 +481,18 @@ int x509_note_params(void *context, size_t hdrlen, { struct x509_parse_context *ctx = context; + if (ctx->last_oid == OID_rsassaPSS && !ctx->raw_sig_params) { + /* Stash AlgorithmIdentifier.parameters for RSASSA-PSS. */ + ctx->raw_sig_params_size = vlen + hdrlen; + if (ctx->raw_sig_params_size) { + ctx->raw_sig_params = value - hdrlen; + } else { + ctx->raw_sig_params = NULL; + ctx->raw_sig_params_size = 1; + } + return 0; + } + /* * AlgorithmIdentifier is used three times in the x509, we should skip * first and ignore third, using second one which is after subject and @@ -705,3 +759,97 @@ int x509_akid_note_serial(void *context, size_t hdrlen, ctx->cert->sig->auth_ids[0] = kid; return 0; } + +int x509_note_hash_algo(void *context, size_t hdrlen, + unsigned char tag, + const void *value, size_t vlen) +{ + struct x509_parse_context *ctx = context; + const char **ptr = NULL; + + if (ctx->last_oid != OID_rsassaPSS) + return -EBADMSG; + + if (ctx->cert->sig->mgf) + ptr = &ctx->cert->sig->mgf_hash_algo; + else + ptr = &ctx->cert->sig->hash_algo; + + switch (look_up_OID(value, vlen)) { + case OID_sha224: + *ptr = "sha224"; + break; + case OID_sha256: + *ptr = "sha256"; + break; + case OID_sha384: + *ptr = "sha384"; + break; + case OID_sha512: + *ptr = "sha512"; + break; + case OID_sha1: + default: + *ptr = "sha1"; + break; + } + + return 0; +} + +int x509_note_hash_algo_params(void *context, size_t hdrlen, + unsigned char tag, + const void *value, size_t vlen) +{ + return -EOPNOTSUPP; +} + +int x509_note_mgf(void *context, size_t hdrlen, + unsigned char tag, + const void *value, size_t vlen) +{ + struct x509_parse_context *ctx = context; + + if (ctx->last_oid != OID_rsassaPSS) + return -EBADMSG; + + /* RFC8017 PKCS1MGFAlgorithms */ + if (look_up_OID(value, vlen) != OID_mgf1) + return -EINVAL; + + ctx->cert->sig->mgf = "mgf1"; + + return 0; +} + +int x509_note_salt_length(void *context, size_t hdrlen, + unsigned char tag, + const void *value, size_t vlen) +{ + struct x509_parse_context *ctx = context; + + if (ctx->last_oid != OID_rsassaPSS) + return -EBADMSG; + + if (!value || !vlen || vlen > sizeof(ctx->cert->sig->salt_length)) + return -EINVAL; + + ctx->cert->sig->salt_length = (vlen == 2) ? + be16_to_cpu(*((__force __be16 *) value)) : *((u8 *) value); + + return 0; +} + +int x509_note_trailer_field(void *context, size_t hdrlen, + unsigned char tag, + const void *value, size_t vlen) +{ + struct x509_parse_context *ctx = context; + + if (ctx->last_oid != OID_rsassaPSS) + return -EBADMSG; + + /* trailerField 0xbc per RFC8017 A.2.3 regardless of if + * specified. */ + return 0; +} diff --git a/crypto/asymmetric_keys/x509_rsassa.asn1 b/crypto/asymmetric_keys/x509_rsassa.asn1 new file mode 100644 index 0000000000000..e524b978856d2 --- /dev/null +++ b/crypto/asymmetric_keys/x509_rsassa.asn1 @@ -0,0 +1,17 @@ +-- RFC8017 +RSASSA-PSS-params ::= SEQUENCE { + hashAlgorithm [0] HashAlgorithm DEFAULT, + maskGenAlgorithm [1] MaskGenAlgorithm DEFAULT, + saltLength [2] INTEGER DEFAULT ({ x509_note_salt_length }), + trailerField [3] INTEGER DEFAULT ({ x509_note_trailer_field }) +} + +HashAlgorithm ::= SEQUENCE { + algorithm OBJECT IDENTIFIER ({ x509_note_hash_algo }), + parameters ANY OPTIONAL ({ x509_note_hash_algo_params }) +} + +MaskGenAlgorithm ::= SEQUENCE { + mgf OBJECT IDENTIFIER ({ x509_note_mgf }), + parameters HashAlgorithm +} diff --git a/include/crypto/public_key.h b/include/crypto/public_key.h index 47accec68cb0f..f36834c8bb139 100644 --- a/include/crypto/public_key.h +++ b/include/crypto/public_key.h @@ -46,6 +46,10 @@ struct public_key_signature { const char *encoding; const void *data; unsigned int data_size; + const char *mgf; + const char *mgf_hash_algo; + u16 salt_length; + u16 trailer_field; }; extern void public_key_signature_free(struct public_key_signature *sig); diff --git a/include/linux/oid_registry.h b/include/linux/oid_registry.h index 4462ed2c18cdd..c247adc8a41e4 100644 --- a/include/linux/oid_registry.h +++ b/include/linux/oid_registry.h @@ -113,6 +113,9 @@ enum OID { OID_SM2_with_SM3, /* 1.2.156.10197.1.501 */ OID_sm3WithRSAEncryption, /* 1.2.156.10197.1.504 */ + OID_mgf1, /* 1.2.840.113549.1.1.8 */ + OID_rsassaPSS, /* 1.2.840.113549.1.1.10 */ + OID__NR }; From patchwork Thu Apr 8 14:15:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Varad Gautam X-Patchwork-Id: 417578 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E02EBC433B4 for ; Thu, 8 Apr 2021 14:16:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BD19261151 for ; Thu, 8 Apr 2021 14:16:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231879AbhDHOQc (ORCPT ); Thu, 8 Apr 2021 10:16:32 -0400 Received: from de-smtp-delivery-102.mimecast.com ([194.104.109.102]:41316 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231917AbhDHOQc (ORCPT ); Thu, 8 Apr 2021 10:16:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1617891380; 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=tpynPgwla+q00f14OSK+oz3Q7ZoNhgyTaJm8QHk1oaw=; b=gpHSQiggEGLUHYXQtV/ya//DVMu1loklvACuO6wjC5N+6gud1KbZRD8A6hpqrYSvP2qiDc LaC9FrQaewrQ7QgbTeoXjc64xBW/+Hh+PjLDul4XyQlI3mjiUS5jGMrOSaxGgKS0rV5mte iKsdcVrmc8k/qLn6afxIJW6G8+aHcwc= Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04lp2057.outbound.protection.outlook.com [104.47.13.57]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-27-H_WA3VGsM7GwVLdPlfz1jw-2; Thu, 08 Apr 2021 16:16:02 +0200 X-MC-Unique: H_WA3VGsM7GwVLdPlfz1jw-2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fdg/ShS77A4WdQ/PxNl8FBertjFmPxvhgHX+XIa7QxHtt2WfxB8P43JI+nJqwLXmdlglVhB6woUwbF8DZ54bb+q59r4Qhh/amYFH/bHWr8yOlEXqA48XACAKqnuObXnCbCD1kJ/bjwo8m34KYsvBa3/844lyT5Ul1Zz2M7mQOZQi5U47RVwuwv0t4uS6bZ2GDsiiGv1MxqoDndkMKGAmuBV7rgb/jB/PQArQ3kh1FQQIadGupv0kAHwRm4duwnIPH0+SN3jYE1n9jiRuB1ZW1jeNSJrKARPTrwPSxE1UCYlu3po/R7bA7JcvszvpzYvRoK8dUnPtzrXs6wdQC89V7w== 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=/1C11B5dbJ0SABsUcHKP1mpYYYbdqU+LKBIFDmuzuv4=; b=I5eMBTjJp/rC3McuI8umOQxr3yAIN465PtrFjA/H1LiAHtB0S1z6uTsXQws/tGw6MZsV/0BxVCsEKKgwawEddGR56Yy6O2rV19zLi7c4GZ39v3gSYe3mXtF4CYfKhSB0FD4io3rszDV7hBK8roavVc2VTvqvhwZsNiSiGj0A9bu7aKWMeSSpA2K5bt55bmZN3uTS0Vqa+7zxk3kxitS2ngoDuKUtwrQcWgjUkjn0SnI6F5bi2M27hHK1+IBLD4+2Qfdxjb9H1IzF1wFGxI/6KfXZi6tyW43AQ/3RCLAGBUnZKxJiVg8b8wxZD5dsJxquY4F++vAM1r5cm1tsJs561w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=suse.com; Received: from AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) by AM0PR04MB6289.eurprd04.prod.outlook.com (2603:10a6:208:145::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.18; Thu, 8 Apr 2021 14:15:55 +0000 Received: from AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d]) by AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d%6]) with mapi id 15.20.3999.032; Thu, 8 Apr 2021 14:15:55 +0000 From: Varad Gautam To: linux-crypto@vger.kernel.org CC: varad.gautam@suse.com, dhowells@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, vt@altlinux.org, tianjia.zhang@linux.alibaba.com, keyrings@vger.kernel.org, linux-kernel@vger.kernel.org, jarkko@kernel.org Subject: [PATCH v2 02/18] crypto: rsa-pkcs1pad: Rename pkcs1pad-specific functions to rsapad Date: Thu, 8 Apr 2021 16:15:00 +0200 Message-ID: <20210408141516.11369-3-varad.gautam@suse.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210408141516.11369-1-varad.gautam@suse.com> References: <20210408141516.11369-1-varad.gautam@suse.com> X-Originating-IP: [95.90.93.216] X-ClientProxiedBy: ZR0P278CA0137.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:40::16) To AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from xps13.suse.cz (95.90.93.216) by ZR0P278CA0137.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:40::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16 via Frontend Transport; Thu, 8 Apr 2021 14:15:54 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 366fe2d4-9586-4735-4b57-08d8fa98d2ca X-MS-TrafficTypeDiagnostic: AM0PR04MB6289: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5516; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Cpp7Mcj6p7au7jOtxs53k66mZunn3hzxneHlYcX29oKd6J3GA/z/979444sjgOnMpIhpUd/DsLBQKK7HP8ksXtP4zjO8x+K8JsAfxunCcrnWVlgYom833Ru9PfVkRBixn+KbJZKPGTeNZU1wRWdMRaywTizOpzeunpBQ6EuApzukOkWSm3nhU8sI4iED5rGDjjvUa1gkGWwhHFz1sCC3g/LnFBtzFzHn5CK3eb0/hcXidlhuxuUYuemesX1NjK6ONRo3JS+QBtox69+2QN15r5hJ2lL6ILeWa902lTOlv128Hd2eCpjOdCEaQY/AJaz75c2xa6s5m46iDbxpwU571vRxtGA54KcffyNbYnBoIkbrALkXu6hLrQa4fyEyFCfIuNSfx+l2N/xUSGOOfhZmO3sUwfOlc1sSWT+pY+WOYpReSyfiM4s+ATJY5tjChKK1vjfn0RnWakFI4NN5EJ6PyVrQ/Pl04R2o4Oc5Rp1EJXqD8/hVNRv024k+lznscaaEVy+LcGEuIrEKunKaKmQT/mI3v0xngyen5ibiK3SdQamtyhG2yTccnVlC95A9XTW8ZrsvhFquzFquSksUizwwI2oq3xVFs2UV1XL/hCmZaVhMKqf0Ay0s3wYGKIYjp+qmZ/4E+1mlIMD2vPlXVXoGiFfdSG2Rwh5heoMYAl9tUhYGqkPQ8nl53LdLAh7RHEhuME011df5VQ11Ewgx1P6/+P++leqGDHWE1yUX7kblalk= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR04MB5650.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(396003)(346002)(376002)(136003)(39860400002)(186003)(83380400001)(16526019)(478600001)(6486002)(38100700001)(36756003)(5660300002)(4326008)(6916009)(1076003)(66476007)(316002)(2906002)(66556008)(26005)(38350700001)(2616005)(6666004)(956004)(8676002)(44832011)(8936002)(6506007)(86362001)(52116002)(66946007)(6512007)(32563001)(473944003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 8qS8y6bMi85074ChFjIjm81KDSlkjY5alAxIrOz5F4rWDzv4NjvAnwhri/fSOdNt17/tSTuONlsQL5UXVSi/wWSYbJqrV979cZaIEUMAHqg7sOk4wBBQzg4nouQ10xAr7paQqOn/VCPAH9PODjdPAklgG/0PFjUskzXZhq5CGpsrs2eBBU7bog1aVb+bWZxHZnrpYIvZ6R2jY9TD6S0o3UJlAF0LlO2zrsaJ/eS3JIz5A/1houwX50KcvsLtqSBflDzfa6QPCmcqf5atpv0cW1gT5P43TWTlcSeRGGCQwACyAiYyPv4z+kQMpuxlP67w2S8oLcspkThWekrcMPugwpKWvjzPRwyDEQMFoYL8R9VSplPGSLrA/7MyJhpYfFHDak8LfYqKiYZbIDtqqsXZ9T4StWAw1YBALzJ8hcSiG/ADFIaOdxsTqrAhhZMee+SwIqzrX9CtXBACswtkZE9XacWOKmmSfoDWGFo4L0Jym2Ed1ifFYPskYGyBsaPjNWW8/cB1neuP6i4Wcm87JuXvYmM0vgpaXOurh3ctmafvHgFMEeH43lRX6kSsYXdhF8t+gg49QW+XKUyL20zvCpdiJ0IsvjROrWR30BuRa5IoyNvKyUktiuoBFXoeMFB8LiLesYkXFfC9XIcCZ66PrkR2Ma1cV7UpzYuUdLVpEr8AO4V9m34bTkNBrouM5rE4Q/kp/z9Eyk40/WrwD0gGb+i2xDEgkhOpGVBDz7pOWRkHd7aPfCIupKmVjUgmoaItATxrf5JHRR1aNP0k5G3v+SVbcub/sSBLtFMGPNCYFJB333E24aB1/yZ9NES9f1SENj3JN+kuFTyfK7pLyU/rn5XHVkoIo6nFqJmI78syMyg16+6tITBmcrQHavkoK35gdpvahKUUhdW5L7HNFQA8vdip31fs1Z/0nvYpeP3drFKOjXVXtyWCQ2pjdTNdQR0uQuCf1pYpuZJ9VWAKReh4LEI4h/+tdZVS+HnbwopIm+llHu+9YwkvApJ7lErQz7KOZ5T8BuYXQDGXgcpPU9RurWF2/vYFnrNawT+Z3qIsUFcV2QnGfkkaoqD6c4YYEmxBbiuhStOSMQYnrs5MVQVFbCg9IWJ2ODEQAjCVgJYg5rkTObKqi/1FTzKLhScsNoHcmQ12KmV96AU+rjh7jcLd9IjZzrZzT2IBA1xF0lA1i8RV7cgMwjgrVqBdLQDVwI2rTzQmWsshRNl3uBeynYTMxsCCxIjzsUDRN5Hjt4S0wJaRfOgyJdzZLQiED4X0GTvt9YP99yNqjS54tC/rC77j6Y5CjsW9CVbzAh/2u5pLOiIVQ2rVk+AFGi1vi0uGZcyPMtgB X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 366fe2d4-9586-4735-4b57-08d8fa98d2ca X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5650.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Apr 2021 14:15:55.3689 (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: dJ/rpfCyH2/GpHsWAKY4kVAmW4Xht/6DPRye/FBKaKRi54GOQBBzTSH+sfXr+tGvrvOjW0zJiVhGAZDxJMcB3Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB6289 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The existing RSA implementation supports PKCSv1.5 style signature paddings via rsa-pkcs1pad. A lot of the functionality implemented for rsa-pkcs1pad can be reused across other RSA padding schemes. Rename such functions as rsapad_* before moving them out of rsa-pkcs1pad.c. Signed-off-by: Varad Gautam --- crypto/rsa-pkcs1pad.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/crypto/rsa-pkcs1pad.c b/crypto/rsa-pkcs1pad.c index 8ac3e73e8ea65..83ba7540a53ac 100644 --- a/crypto/rsa-pkcs1pad.c +++ b/crypto/rsa-pkcs1pad.c @@ -104,7 +104,7 @@ struct pkcs1pad_request { struct akcipher_request child_req; }; -static int pkcs1pad_set_pub_key(struct crypto_akcipher *tfm, const void *key, +static int rsapad_set_pub_key(struct crypto_akcipher *tfm, const void *key, unsigned int keylen) { struct pkcs1pad_ctx *ctx = akcipher_tfm_ctx(tfm); @@ -125,7 +125,7 @@ static int pkcs1pad_set_pub_key(struct crypto_akcipher *tfm, const void *key, return 0; } -static int pkcs1pad_set_priv_key(struct crypto_akcipher *tfm, const void *key, +static int rsapad_set_priv_key(struct crypto_akcipher *tfm, const void *key, unsigned int keylen) { struct pkcs1pad_ctx *ctx = akcipher_tfm_ctx(tfm); @@ -146,7 +146,7 @@ static int pkcs1pad_set_priv_key(struct crypto_akcipher *tfm, const void *key, return 0; } -static unsigned int pkcs1pad_get_max_size(struct crypto_akcipher *tfm) +static unsigned int rsapad_get_max_size(struct crypto_akcipher *tfm) { struct pkcs1pad_ctx *ctx = akcipher_tfm_ctx(tfm); @@ -159,8 +159,8 @@ static unsigned int pkcs1pad_get_max_size(struct crypto_akcipher *tfm) return ctx->key_size; } -static void pkcs1pad_sg_set_buf(struct scatterlist *sg, void *buf, size_t len, - struct scatterlist *next) +static void rsapad_akcipher_sg_set_buf(struct scatterlist *sg, void *buf, + size_t len, struct scatterlist *next) { int nsegs = next ? 2 : 1; @@ -256,7 +256,7 @@ static int pkcs1pad_encrypt(struct akcipher_request *req) req_ctx->in_buf[i] = 1 + prandom_u32_max(255); req_ctx->in_buf[ps_end] = 0x00; - pkcs1pad_sg_set_buf(req_ctx->in_sg, req_ctx->in_buf, + 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); @@ -357,7 +357,7 @@ static int pkcs1pad_decrypt(struct akcipher_request *req) if (!req_ctx->out_buf) return -ENOMEM; - pkcs1pad_sg_set_buf(req_ctx->out_sg, req_ctx->out_buf, + 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); @@ -415,7 +415,7 @@ static int pkcs1pad_sign(struct akcipher_request *req) memcpy(req_ctx->in_buf + ps_end + 1, digest_info->data, digest_info->size); - pkcs1pad_sg_set_buf(req_ctx->in_sg, req_ctx->in_buf, + 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); @@ -545,7 +545,7 @@ static int pkcs1pad_verify(struct akcipher_request *req) if (!req_ctx->out_buf) return -ENOMEM; - pkcs1pad_sg_set_buf(req_ctx->out_sg, req_ctx->out_buf, + 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); @@ -564,7 +564,7 @@ static int pkcs1pad_verify(struct akcipher_request *req) return err; } -static int pkcs1pad_init_tfm(struct crypto_akcipher *tfm) +static int rsapad_akcipher_init_tfm(struct crypto_akcipher *tfm) { struct akcipher_instance *inst = akcipher_alg_instance(tfm); struct pkcs1pad_inst_ctx *ictx = akcipher_instance_ctx(inst); @@ -579,14 +579,14 @@ static int pkcs1pad_init_tfm(struct crypto_akcipher *tfm) return 0; } -static void pkcs1pad_exit_tfm(struct crypto_akcipher *tfm) +static void rsapad_akcipher_exit_tfm(struct crypto_akcipher *tfm) { struct pkcs1pad_ctx *ctx = akcipher_tfm_ctx(tfm); crypto_free_akcipher(ctx->child); } -static void pkcs1pad_free(struct akcipher_instance *inst) +static void rsapad_akcipher_free(struct akcipher_instance *inst) { struct pkcs1pad_inst_ctx *ctx = akcipher_instance_ctx(inst); struct crypto_akcipher_spawn *spawn = &ctx->spawn; @@ -656,24 +656,24 @@ 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 = pkcs1pad_init_tfm; - inst->alg.exit = pkcs1pad_exit_tfm; + inst->alg.init = rsapad_akcipher_init_tfm; + inst->alg.exit = rsapad_akcipher_exit_tfm; 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 = pkcs1pad_set_pub_key; - inst->alg.set_priv_key = pkcs1pad_set_priv_key; - inst->alg.max_size = pkcs1pad_get_max_size; + 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.reqsize = sizeof(struct pkcs1pad_request) + rsa_alg->reqsize; - inst->free = pkcs1pad_free; + inst->free = rsapad_akcipher_free; err = akcipher_register_instance(tmpl, inst); if (err) { err_free_inst: - pkcs1pad_free(inst); + rsapad_akcipher_free(inst); } return err; } From patchwork Thu Apr 8 14:15:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Varad Gautam X-Patchwork-Id: 418317 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS,UNWANTED_LANGUAGE_BODY,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8DA81C433ED for ; Thu, 8 Apr 2021 14:16:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6811061132 for ; Thu, 8 Apr 2021 14:16:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231819AbhDHOQY (ORCPT ); Thu, 8 Apr 2021 10:16:24 -0400 Received: from de-smtp-delivery-102.mimecast.com ([194.104.109.102]:27012 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231892AbhDHOQV (ORCPT ); Thu, 8 Apr 2021 10:16:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1617891368; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cmUAdFJ0uQw14A1uRJhYFxeqhrEmpnRdb5fucZevEH8=; b=fGlcoX8rvKRT8gJ9xr9grhsA+3R5WMUqZtF3hRI/sF55nFORQnoFXiLrjR7HQWjDLAUgXD mRAp32yC+Y/X5j5kKTcoTs9RwoF/Bm59yAznGlhd0D70V3nyHQVh7EX663MzG8iz8KFkX4 3bi1fcxpWkEh8oJIVu1tu9j8i2k87q0= Received: from EUR03-VE1-obe.outbound.protection.outlook.com (mail-ve1eur03lp2054.outbound.protection.outlook.com [104.47.9.54]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-1-hp_enYxZN1uqXJ_i4yPCAg-1; Thu, 08 Apr 2021 16:16:07 +0200 X-MC-Unique: hp_enYxZN1uqXJ_i4yPCAg-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JgaCdXJk0DGipYkmRq5X4pIUnDwo0K/NxDDpZiRRLCQ3nkwJ85sO5QQ2XXOGUcu9SJe2Bn/1ou/wV8kMhSFAwwUNK1/1cEi7vPveP4TXa1F6zaciF3CmgjP8bkq8fvLo/ymoY6O4aKquZTvArykTmTYz84LkK6jF6eM5+PwG7YsjQ3RP2mhQqqcHjl3GMwAV5Z2Cjw4hlZH7seJHbp/fnhj78g8z0dhEC31uhslsnub2qUtnQ2wlzyxrXu8W09VVYDBC09Dm2v/kCQBuTlZPhhIRUtZWPDndppu0QeyzgyNadnY+RhC4i/Jveiz5t4zhUHfUStMhiKmDsmZxt9czCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=93i75lPbvB/8koH1C6/WbV75u4YZP4Ne/6Qzxao+vC8=; b=fjeKJtiUeYvXFjdo9QoNIBxUdFjNTxM2kIQoTKJcp7ActWD2bCraM+F4heveOUg8/CoD9sB0yRuvIH+kVxzPldGJh9ijUWqNO1ABpfU3fDI31fKmJ8I2TgYL1KQEO3U7URsJ9i+oyncFTg4CJnS+EkKsFfq/lVCe8xHHoqVTmT2sE+HqO84pjD+ycrUmhHWM/LSIbbamrcauNudzIxNpGGKfXAGm2IiVE3EotJemfo1xnJmCIkAzQ4wEfIw661wNl1G9uhkQqiacIqaxNzF22S2MF92kAG7kVSvHX8tBEk8NwaSTD0GVbJSpPFXDl5bmNdcyX8DZ5HndRcL0lDMZhg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=suse.com; Received: from AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) by AM0PR04MB6289.eurprd04.prod.outlook.com (2603:10a6:208:145::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.18; Thu, 8 Apr 2021 14:15:56 +0000 Received: from AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d]) by AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d%6]) with mapi id 15.20.3999.032; Thu, 8 Apr 2021 14:15:56 +0000 From: Varad Gautam To: linux-crypto@vger.kernel.org CC: varad.gautam@suse.com, dhowells@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, vt@altlinux.org, tianjia.zhang@linux.alibaba.com, keyrings@vger.kernel.org, linux-kernel@vger.kernel.org, jarkko@kernel.org Subject: [PATCH v2 03/18] crypto: rsa-pkcs1pad: Extract pkcs1pad_create into a generic helper Date: Thu, 8 Apr 2021 16:15:01 +0200 Message-ID: <20210408141516.11369-4-varad.gautam@suse.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210408141516.11369-1-varad.gautam@suse.com> References: <20210408141516.11369-1-varad.gautam@suse.com> X-Originating-IP: [95.90.93.216] X-ClientProxiedBy: ZR0P278CA0137.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:40::16) To AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from xps13.suse.cz (95.90.93.216) by ZR0P278CA0137.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:40::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16 via Frontend Transport; Thu, 8 Apr 2021 14:15:55 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fbacf15a-b043-40a8-54a6-08d8fa98d37d X-MS-TrafficTypeDiagnostic: AM0PR04MB6289: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:98; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pyMxu3B8G1b+hK7CJk1UYJqsSmxR8FbA3eNI1Zb6GQBSTP+hYj+d1UYNTqbeRBv8FL6uDtdD6ZYZXz/znIJhFYyuQVXthCZ2ZkZqZT6tKgt9JG9tyKNl1B3xoI6j5AxuBzh8W5Fk/uwFf0UEW8ry+74aTdf4hIWjTkIYcRwXjlDY0yxVcp0J5vjD7JbZqRe2nJPxzw9Xu9Ajj9NOKci5A1FQ7RabC/GjJIBV5PNzzgnH+kLwS+XBqTW9ATMTSDUBezR9tLbv0c8twFPrKKN6SufgCra/wTtUp43aoOL5HG3D0NJJHQVk90xcafUFjuc7eLfCoabuXaCGUWjBD4MwxenxxRxYnJ/vCVV8v5S06Z6U7V9hRrlzj3QRlDUFyjPK+/mj3NRogCBOF+0v9oEjuCIPm/FofwD2byXIyowEDan4wP6nOCi4VR9BKqW8Pi9x5DBtYrZci4qOT5qJgN5CGZZnO0CEAcPdr9SPWPCGkkt3/Hc5SyzQ0ULzDB6ucxcKpy2Es+kScepqBotIsKoWBpffSuJQ0Ze4mFru0fZXfP+phfvd/X2YDEO9m1lw2Z+bJ5IEqfhqu0dmqyeKt3XG024MkerzeYR9FiGqD98Wr2qRAeSKonMpYlTDmIaoLLM5OUi9MWzBrrYD7oZ9oCqeSAcF8l0H1UrvY8qOim5NKnNr2yK5tSVjVQI4knP1Ew8QMWahvlMqcpGFtCxam2CfsQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR04MB5650.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(396003)(346002)(376002)(136003)(39860400002)(186003)(83380400001)(16526019)(478600001)(6486002)(38100700001)(36756003)(5660300002)(4326008)(6916009)(1076003)(66476007)(316002)(2906002)(66556008)(26005)(38350700001)(2616005)(6666004)(956004)(8676002)(44832011)(8936002)(6506007)(86362001)(52116002)(66946007)(6512007)(41533002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: PzTDZcmo/TcQU02mvb8KNhH1a1mgZOAQUBg/LnI079uQD6FPU6GFspnmMXV+NpgQaAoOUioJ0S2CyywhwIIPIr/4PFbo+4VoH9BcA+vx2LJYUxpkSJKY+4aa748e1/mnYZWrPlD+ShA73w9LpmAcJ9hUJeZkHJzBeWi8sx/jUtgZ54Hpa9kJAxCxOlaLIBkzDUAIdvNZVtDMiUz6D4CrA4/1g643DvW87YMLzIyNEPBfwpw70VIdj/ZXSHwqgh4DZpE+BXgcMQyQeVnmbgeNTLycUiIQ0n2R6cL67PsUOEvpeHJ8uKFk79vFZhhITeyS4L717aW17HNj/4+eg6oocSeEOzRWuSVUZ+e4m8B0GM4dYHfZiUbA8MNq3iGbFhzQFtwwL6PwHXGwTrVE806hu46G1DR3ZO20gAioq+LyYCcRkzZrohv/AnXMuu9jQg4sj4VqfHXArowQ24gsF48A9CXmMjUOkOpJtmUbODuEpRWxqgIHpUHcrIgjEurrMoz4OltOXZOp5EiuUfIRh8Znmpp09KQ/PQaScprbXgY4XkHxdCwpu69IH42zLmcAiNpZfAROlaQEdVm85x+ouYiS+NFqQHYz1MGAqUMCHkM3X+mwewR3s8BOT5Kdgonab0RRLNvlW/yG96YCQJe4ncPq5oYCs3U2TERkCOtQLuulkLh4pn/XBuvU00WDG+fKe++YB1CcKMDeIQvkOOAFg0xFeyHZfe2+S4IF3/X1yuWGBMWXmA7uJwaj19z8w6M17TehQP2i7J3y2M8W/t2Z0YmBhEMwIE0qVk4ddEhrNSirJdD3C3D9RnnjiMDa8Z8P/KhgvoeXcDMz5UQiVG3P4DAR7GGfZ9Ournb8eYPWCqKpJoBRCB1u9G/GUZpxjlYsHcIeg7e5xFyXbkYpi9PGqJ370aU99mEsa7vbNvv5B5lTa/P4JHO4hkz+leh4i4MjGE5j9kdmqZg7Ggnuq4awRazm9yrPlgwjTKqUyenwqYFdj3yk2+avCPZUfWOLxfO8tPCQsUTjJx6JLCK7bG7qFOZhTXXqcW/SCL7G+mKyU3y+ZPS+B6LTqFXgy96jbEpNROPxgRXOVTZiobDpfiewlD0AQogp4KFQfa2HyrLN535dfEFKY0xOTkGyih+WvhH4/A5u6HeijKNyLzpRpPCySxwHWbO4+oDSeJKwkkHKUdJcAXhz/K/xvr9BRrGCXfnUtefB1yJs2G5cV1d4tIRpnOa/7HjJF5uY4SdtmZNif88nlTj0JkwEqL/QiMWNbFCj98X/Txvz0UoxzUSBwXAq0Zi2kXklNve611xlvDN0k5QVK5dEVl4axsnvaKu6Vwb/cCPu X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: fbacf15a-b043-40a8-54a6-08d8fa98d37d X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5650.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Apr 2021 14:15:56.4363 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: OLApZPyi6+bgWbLZJnguyNd+4sD+uMmtxOzJaNCu5RFpLWXclw8RVCAVFWNCuqESLFKWh9RgGgSAWvuOC2FFWA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB6289 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org which can be reused by other signature padding schemes as rsapad_akcipher_create. This will be moved out of rsa-pkcs1pad.c to be used across rsa-*pad implementations. Signed-off-by: Varad Gautam --- crypto/rsa-pkcs1pad.c | 48 ++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/crypto/rsa-pkcs1pad.c b/crypto/rsa-pkcs1pad.c index 83ba7540a53ac..849573f6b44b3 100644 --- a/crypto/rsa-pkcs1pad.c +++ b/crypto/rsa-pkcs1pad.c @@ -595,7 +595,21 @@ static void rsapad_akcipher_free(struct akcipher_instance *inst) kfree(inst); } -static int pkcs1pad_create(struct crypto_template *tmpl, struct rtattr **tb) +static struct akcipher_alg pkcs1pad_alg = { + .init = rsapad_akcipher_init_tfm, + .exit = rsapad_akcipher_exit_tfm, + + .encrypt = pkcs1pad_encrypt, + .decrypt = pkcs1pad_decrypt, + .sign = pkcs1pad_sign, + .verify = pkcs1pad_verify, + .set_pub_key = rsapad_set_pub_key, + .set_priv_key = rsapad_set_priv_key, + .max_size = rsapad_get_max_size +}; + +static int rsapad_akcipher_create(struct crypto_template *tmpl, struct rtattr **tb, + struct akcipher_alg *alg) { u32 mask; struct akcipher_instance *inst; @@ -625,12 +639,12 @@ static int pkcs1pad_create(struct crypto_template *tmpl, struct rtattr **tb) hash_name = crypto_attr_alg_name(tb[2]); if (IS_ERR(hash_name)) { if (snprintf(inst->alg.base.cra_name, - CRYPTO_MAX_ALG_NAME, "pkcs1pad(%s)", + CRYPTO_MAX_ALG_NAME, "%s(%s)", tmpl->name, rsa_alg->base.cra_name) >= CRYPTO_MAX_ALG_NAME) goto err_free_inst; if (snprintf(inst->alg.base.cra_driver_name, - CRYPTO_MAX_ALG_NAME, "pkcs1pad(%s)", + CRYPTO_MAX_ALG_NAME, "%s(%s)", tmpl->name, rsa_alg->base.cra_driver_name) >= CRYPTO_MAX_ALG_NAME) goto err_free_inst; @@ -642,12 +656,13 @@ static int pkcs1pad_create(struct crypto_template *tmpl, struct rtattr **tb) } if (snprintf(inst->alg.base.cra_name, CRYPTO_MAX_ALG_NAME, - "pkcs1pad(%s,%s)", rsa_alg->base.cra_name, + "%s(%s,%s)", tmpl->name, rsa_alg->base.cra_name, hash_name) >= CRYPTO_MAX_ALG_NAME) goto err_free_inst; if (snprintf(inst->alg.base.cra_driver_name, - CRYPTO_MAX_ALG_NAME, "pkcs1pad(%s,%s)", + CRYPTO_MAX_ALG_NAME, "%s(%s,%s)", + tmpl->name, rsa_alg->base.cra_driver_name, hash_name) >= CRYPTO_MAX_ALG_NAME) goto err_free_inst; @@ -656,16 +671,16 @@ static int pkcs1pad_create(struct crypto_template *tmpl, struct rtattr **tb) inst->alg.base.cra_priority = rsa_alg->base.cra_priority; inst->alg.base.cra_ctxsize = sizeof(struct pkcs1pad_ctx); - inst->alg.init = rsapad_akcipher_init_tfm; - inst->alg.exit = rsapad_akcipher_exit_tfm; + inst->alg.init = alg->init; + inst->alg.exit = alg->exit; - inst->alg.encrypt = pkcs1pad_encrypt; - inst->alg.decrypt = pkcs1pad_decrypt; - inst->alg.sign = pkcs1pad_sign; - inst->alg.verify = pkcs1pad_verify; - inst->alg.set_pub_key = rsapad_set_pub_key; - inst->alg.set_priv_key = rsapad_set_priv_key; - inst->alg.max_size = rsapad_get_max_size; + inst->alg.encrypt = alg->encrypt; + inst->alg.decrypt = alg->decrypt; + inst->alg.sign = alg->sign; + inst->alg.verify = alg->verify; + inst->alg.set_pub_key = alg->set_pub_key; + inst->alg.set_priv_key = alg->set_priv_key; + inst->alg.max_size = alg->max_size; inst->alg.reqsize = sizeof(struct pkcs1pad_request) + rsa_alg->reqsize; inst->free = rsapad_akcipher_free; @@ -678,6 +693,11 @@ static int pkcs1pad_create(struct crypto_template *tmpl, struct rtattr **tb) return err; } +static int pkcs1pad_create(struct crypto_template *tmpl, struct rtattr **tb) +{ + return rsapad_akcipher_create(tmpl, tb, &pkcs1pad_alg); +} + struct crypto_template rsa_pkcs1pad_tmpl = { .name = "pkcs1pad", .create = pkcs1pad_create, From patchwork Thu Apr 8 14:15:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Varad Gautam X-Patchwork-Id: 418316 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9C8D8C433B4 for ; Thu, 8 Apr 2021 14:16:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 770A661153 for ; Thu, 8 Apr 2021 14:16:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231996AbhDHOQv (ORCPT ); Thu, 8 Apr 2021 10:16:51 -0400 Received: from de-smtp-delivery-102.mimecast.com ([194.104.109.102]:22236 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231935AbhDHOQj (ORCPT ); Thu, 8 Apr 2021 10:16:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1617891385; 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=KH0v0aoXcA7hrq0AgsRogda6T+ioH6k9wwvrgrJNqBw=; b=Tg36TQ+ey+HzI8QxGLBUPzgPTuZaT/zcUFGjoC6BeVYpnzJ1FzhZdi2GLDLz6En+Bafnyu BawBfeZL6kFraRPyymGgXwEjSKwOkGurQgHoXDd1mSEAnQJDsMk9lauw4SHa3TL+rNGlLd uMdLF8T1KzixsYm2Q/5rECadU5U0gBA= Received: from EUR03-VE1-obe.outbound.protection.outlook.com (mail-ve1eur03lp2054.outbound.protection.outlook.com [104.47.9.54]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-1-aQejvcLkNK-nNUBcs5vMeg-2; Thu, 08 Apr 2021 16:16:08 +0200 X-MC-Unique: aQejvcLkNK-nNUBcs5vMeg-2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Z6XCSMBzMh+zzW86ffjAh3Uu7MSS4XaUvPi2pWzkyb13FbLAINTWd3pcmGHMWuSzsX7oLu6dgMVXs9E72a+e4yCGvaYV1Zy3pSly24IjO3ZwJCp1+sgecRmxP3qUthoFtCUj7Fcy09qGD57bF86TQkIjEd/UJIp7eoFWCAidRJc0+EtWi/RVZqmj2cw+TaOcyvIY5aE42odlohTeFCr7mXdCngkTiCifSxjQ/dfSEoawbe9TtrQ6KYUnd6R9r0UCQ4r2kKBGHE7e2ZWRhHZ3sAaFTb2/8HEr15Mr4kwU0Y0wP1QosipU2cb2uWF30B/CFvb7VtDoY6lb0CRFzaShmA== 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=XGT2urG9jqdhUkUdTwt04hei+fMGgSf1B3Vu5f4IAFg=; b=K+xaJ4uQhFAj0oFoQUACQk8CDNikWERPQMVDvjB793IumeR07NP//s9jdn8ycLzuGTEiPQPqo5xSSmGDoE1Nht5hRSYGZIRHTFk8/4nUK+Nq3EwVZEvA3AHDoXPNDxdHDxRnzk+Xu9tpMa6w89hbkYuhvr10mIfBqEkSqu56hAHMzfDHRo1S6MAtujNxCIQ19FR4YFngJ/HfwV6BYdFIfaHt1D75GhWy42D8ReUfuUvtCtlkTu4hAkRB2ouRrdwiImd2JJWn3wnspt4XR378yv8N6xF6g/6fTCwTew3XBmt38F2Nb16GGyF0BhC4EAaETcIlJML5S1lEfVh2TRl+Gw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=suse.com; Received: from AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) by AM0PR04MB6289.eurprd04.prod.outlook.com (2603:10a6:208:145::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.18; Thu, 8 Apr 2021 14:15:57 +0000 Received: from AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d]) by AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d%6]) with mapi id 15.20.3999.032; Thu, 8 Apr 2021 14:15:57 +0000 From: Varad Gautam To: linux-crypto@vger.kernel.org CC: varad.gautam@suse.com, dhowells@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, vt@altlinux.org, tianjia.zhang@linux.alibaba.com, keyrings@vger.kernel.org, linux-kernel@vger.kernel.org, jarkko@kernel.org Subject: [PATCH v2 04/18] crypto: rsa-pkcs1pad: Pull out child req processing code into helpers Date: Thu, 8 Apr 2021 16:15:02 +0200 Message-ID: <20210408141516.11369-5-varad.gautam@suse.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210408141516.11369-1-varad.gautam@suse.com> References: <20210408141516.11369-1-varad.gautam@suse.com> X-Originating-IP: [95.90.93.216] X-ClientProxiedBy: ZR0P278CA0137.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:40::16) To AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from xps13.suse.cz (95.90.93.216) by ZR0P278CA0137.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:40::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16 via Frontend Transport; Thu, 8 Apr 2021 14:15:56 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 64c755e7-4d0f-49b3-9304-08d8fa98d421 X-MS-TrafficTypeDiagnostic: AM0PR04MB6289: 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: n7CRUtjg1/McsMTHewGBNO5lB80hwMjVdFyxlGE1+10Fc8yPsgQs0Nd5eeF9tZPiTeIqGeRULgCNmPTMotEuzLwbaZFLlP/SMUoOBdEZu0F/I9JRO14aDFgOJX2+IH6GvcZqh29msj1lkj4Oqm1KCqLmTCSoZyDYu0F27vBOZm+kxeKbVRJV1tsOABOH1tdsdllHa1VjcXYcwVTV5yQrSNhvhANpC+OcwX4WoXFzwFAucvz9ntH6aDe1udX9CaCfa12pt9PgG7zbqVmbEsXFwk3mI0lQI/4Ej9TS+J2Yawyn+yh3iH9ie7Y6ZvwLT6m4Hrxy1hop0zqgFPKfLBooEezdKDH1cIKZljowAHQ5eokJqTBCmiHXSWI9a/J/msyf8wWu/zn5SZ75VQ6wp+sf4Xj610bwBeiROWu6oB9SHyi83wlXWgoAUEoHxAq7R/ASR4kSmHRgu/W29Ht4i/6wolucWYO5ncI9sycKFhyrMlF+11BVvxQCIIMtgllAJQ+dKcLDSjjF9RKw2Eq514dwVreabQBlVHIkZNkVbQU1RtWKfBQmYE7q+X+/LNChHM6z3EETl15IOBllRtnHEDl82D2rY7B89cFIbNBRIHRjX+47jU83eZxPfttPsLpSchUJzSHwWfE7De/YxJ5e8sN2jjX+4mziY2SVZEtRMiM7gZZ/QIi8kuqTRJJhCNdUH0ZJ3qsq4wFZUESGa980tDqETQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR04MB5650.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(396003)(346002)(376002)(136003)(39860400002)(186003)(83380400001)(16526019)(478600001)(6486002)(38100700001)(36756003)(5660300002)(4326008)(6916009)(1076003)(66476007)(316002)(2906002)(66556008)(26005)(38350700001)(2616005)(6666004)(956004)(8676002)(44832011)(8936002)(6506007)(86362001)(52116002)(66946007)(6512007)(473944003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: M5OGOrTcWvEYNt+Pr1mixE1QcOoixVcUJNDeqkp/Yeq52onVFN9JnX6uUlnWRyT6oV96EYgKhe5S6o3dCEjX5LjbgzW0GQvHJOFgVodtUDUgvHsOhhnJV1c5o3pBrAZoV8Z7KCVKKwBsVf8LQ0AkDDTVjRv/JAcaQF0p010h025okqTKZnTIsAqe/raUqf+yKK4KdQhnToWurmBm5LCzmrMuJQQ+ESk9Z4N3eFVWUPuumDP1NTz4EBLRwfWpwcM0jjarsDoFnw23uCLFVZwsmTwJ7zJtgm8Jxf0/AMZPpl+ORN7QpmlCN1HisL8Q0mwUpQo/jvcUb0m2KzUTaLxYppVVgn6sZhObEBeC7K4Hf0+BG3UO9RpDfrgqXqVqwTmw+ta+pZ3cnjfFGP+pbGtvkSfdoJcaFEo2KVPxQSM3aZPbPTCPpqn3AuLi9k4STSYB75kpjta3Qi073AOpe22x8lTpwSvK+Wv19QWKKfUgdrWh8z0YbHbjV7N5aHqFnPfVaV5TFLmovOnRDRzBvV57nWyLrUq9JOOISxWGN8xZuljy6KG+uusNXoS2s87QOFvLuCNJoA+YhQONrEMA6bu8g3QjUoXz6X2Pe8UH1l4CJwoi1wRYDjjlTLPQGs3otFoqYzIGtUgQLRAtuH57CTQ0cimb9vRbnoaiINRWzol8T9qmZq1PcvVGV+NJ0qlFPHFLo6qgEscyrC/JxSLuOFqzeDm13iApKT3ZKhMxVFLrSyGFPb8Vwy5MuBCsG3s/SpNvbuOspbQPUC//7FSV0dEh8G7qUcsF7r74exrWl6oVZlywWMaM5crhzoKNEchqnYFA5ia2oKOrfxZU0Y9i0GtsVHtcakgXEhCCd0f6OtxSutbtrEtRmK7W1G7pkyaB92w94HPyKbGvwVsjdDN/g7jCIG6oIbCV/ED/TTV72TVzC5NL/yP4DK/DqGud4i5XzQrEQiLY6RjyebXiqV6gxgs4tOVv0oN+FXBAhFqWD0PmR3MCL+1drEW3TBV4HwderXyoELyaFpgSYH3X3OKoRoDJ3voFd76lkl7ZgrwcwYlnJoNKaYghCevElKpfNe7ufjutCcZZ7a7TZEmyfu/nLlCHC9tcaPzi+didqQMeqH2bdYo6tiHacO2K2UIg5w4R95nkpfnZqnGPKFWIBN7QHtiHJIlfSiL2uZAC1SHcrgxd01kyhmJMkDdNrXL0DvE47IcIfCpGR+RNwcwbkQJaph5mIhgVeUSwT95KLhvfd0IFPmGaPPC8n0GDO+Fatk+YAzHQC3P2ty/zh7g4B7m6C8PvnjtwFhUWHNpmNutzoeefUW3xxiW7hUqIHvjxk6NO/Nqj X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 64c755e7-4d0f-49b3-9304-08d8fa98d421 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5650.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Apr 2021 14:15:57.5067 (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: xNxIGeAvstQk6+qq1y/+H1wQ+HrtDA3Ub8nRsb/KMl0YupGYYg4pVGbZjYTZJkB437g/pA6cu7K3KBxxLqpiHg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB6289 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 849573f6b44b3..6329c79316d24 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 Thu Apr 8 14:15:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Varad Gautam X-Patchwork-Id: 418315 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7C71CC433ED for ; Thu, 8 Apr 2021 14:16:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2DCA361151 for ; Thu, 8 Apr 2021 14:16:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231773AbhDHOQy (ORCPT ); Thu, 8 Apr 2021 10:16:54 -0400 Received: from de-smtp-delivery-102.mimecast.com ([194.104.109.102]:49053 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231962AbhDHOQo (ORCPT ); Thu, 8 Apr 2021 10:16:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1617891391; 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=ocAazsLxY4QF9+UznNegPKeahTtK1vL+omwrBn0daXU=; b=eWW7qg69GPVQ04rHd0l63xCXPfcrEDijbqU7fOuLgo57beJYfociM4e9YENWI9Gf5fJ3UE ByOfP63XpRIvhO9hEqkv9vL/kvJjQ1Xi+/KhT7y1v+7CsdBw3tUWN2Zuds+IGPLOq0hFOK BJTISTDk3mBdAbnzCqYd65H3Dh5R9CI= Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04lp2057.outbound.protection.outlook.com [104.47.13.57]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-27-hOkGH2q9N2Cpl-qqeYRULA-3; Thu, 08 Apr 2021 16:16:15 +0200 X-MC-Unique: hOkGH2q9N2Cpl-qqeYRULA-3 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=I5A3DwmU7gzJd6uiJ2OjvZmu02L5TcItDBliULG/pFn8vAuFmMegMYKhIoFg6HVYyX/GHAzCDjMD9t7I9vEXs/DsWjr2i5sMgwk6F4aD3jj1nQudv/d2W2IMCrkpJTkJfY+hj6n+RGOxgc12HpOUw63lAF7PeeaGDVQ7pc7OUXVUe9bnKFHiNJ7dVUvCQbaNApohUQfm4Iv5VFKasp754RkIGgp/cq6WNuMLmXFnYYLNdIHw6Fs1mTqfVV2OotOzo8SG3GlYnSJkoGEp5gFqSfZTAo2jMUjzlvYxw4QDizcXa+v4cWejG5wAyyElc+qmCYlssipRfT0YLAmvPtIM9Q== 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=aYLADhNkUUMdivmEEQa0kCwOxggXebXsloq8B+dupUA=; b=JFpIw1PMXEg1JPBJjaD7Vociw5F48MU+646dJb3JcYFqUiiGJoXSsqpghDpz3rmGKh39VbugmVCtrZLIwCWctOW97w4Cv8puOiCynEdoopmIifQX+E3Pvpj+V+7HMCEHVTCXJxdsj51pYT2N05xdyF/aKQTP5sqpgp5ZDh/Acqj8zl8I3mSm8dheY9R3nqdbNo/x9W5g4AWaBWcsnLzyUrefaE7MZikQy/IFeDyJXXHZm8Jt5iH3a9bmHMWWbPApxrOGbRRTN3OeTad7Jg0cgCzn+TTJN+rfhC9BrM0/AtLM9O0j6bxOA2HsTgE6Yxa/l4bMQ+8OJz3BZifModgR6g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=suse.com; Received: from AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) by AM0PR04MB6289.eurprd04.prod.outlook.com (2603:10a6:208:145::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.18; Thu, 8 Apr 2021 14:15:58 +0000 Received: from AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d]) by AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d%6]) with mapi id 15.20.3999.032; Thu, 8 Apr 2021 14:15:58 +0000 From: Varad Gautam To: linux-crypto@vger.kernel.org CC: varad.gautam@suse.com, dhowells@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, vt@altlinux.org, tianjia.zhang@linux.alibaba.com, keyrings@vger.kernel.org, linux-kernel@vger.kernel.org, jarkko@kernel.org Subject: [PATCH v2 05/18] crypto: rsa-pkcs1pad: Rename pkcs1pad_* structs to rsapad_* Date: Thu, 8 Apr 2021 16:15:03 +0200 Message-ID: <20210408141516.11369-6-varad.gautam@suse.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210408141516.11369-1-varad.gautam@suse.com> References: <20210408141516.11369-1-varad.gautam@suse.com> X-Originating-IP: [95.90.93.216] X-ClientProxiedBy: ZR0P278CA0137.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:40::16) To AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from xps13.suse.cz (95.90.93.216) by ZR0P278CA0137.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:40::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16 via Frontend Transport; Thu, 8 Apr 2021 14:15:57 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 54ebeb93-a4d2-4aeb-d5e7-08d8fa98d4c3 X-MS-TrafficTypeDiagnostic: AM0PR04MB6289: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4502; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: PCf4MRTS+yd02bm+avSrJu3ExfWYg9YYu9yBSZH0VOrTr8GFrytvZq8CnhrlRDhmO9zrSDL5MdhKt0WsxgNdeF8Qj9CsULIIMSoCcFIatCYap2NyH3YxjxiR5PPStBKtTx+gWSFhNuwMzJVRO+X4bFlY1NEuT7+uNbXTCyp12wv3Jsjxye5Fs4z+jBgxR0mlar2wV0wc45CdqxvECSLZwHxVQsoaMfFBgo4276Pv1/+YKGbdq7YUI51M9eacX4yKd9ri85gdAjv9To9/+nS4RsLdGvVflwOwe7a4b9+jLIUxj7VvfwfQxhVc9BWjaROHT2lmx2ghwGuZAFYMO0ujdMGTr4QCrXNmEghO+0GzHYqwTrVt29ZyI9HTVhxHkOMjlwkzvBIjsDwN3KbRJlO9xkxmtB9L1YiAHAbGWx7kPT7pbcQVCiGWZEbx9a41Icsyw5+zAgmRu1FBUMMDEDQI0nURRR0/vkqFjFXoQI57r6a9FTygGY3h4JUQt32pPsajGRXZfurDwWoD+4qfm2MJABp45hb8mn6wihHANcLd9TeQWCGm7eFctWfzPaedCMfIwa0XrOKCFyf/OnlV4j4o0b9tIUP2ExQe9kVQgVvv2W1C7ixd+j1D+FbXNi3A2U2zQVF6huzN5fG4DgMgI2pqJqe2VqgYMlDqgGsI8z/vByAWAY91xtE/ITTYHdRc7gG6 X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR04MB5650.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(396003)(346002)(376002)(136003)(39860400002)(186003)(83380400001)(16526019)(478600001)(6486002)(38100700001)(36756003)(5660300002)(4326008)(6916009)(1076003)(66476007)(316002)(2906002)(66556008)(26005)(38350700001)(2616005)(6666004)(956004)(8676002)(44832011)(8936002)(6506007)(86362001)(52116002)(66946007)(6512007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: Df5vn6fn+M/tnkmyFHzP9bdYHbyMoSzpi4Va3Z1/mcolaprB/wuFVT8rQfCwOmIUYCZcgVkE8gBj2bn6PekfhqGPCLdAVaC1U7MBWxbnQfYRVeOQUoM1+IJ+4f9YdkPczMncHBBnaUvJG6xwJlVPqDRnDTkaRYAjmHrv51bMFBbo6c2e6A2tCz3AoqeiB3/Wf0VAj+hgwW5WQvy/GGzoHYJaTGNImXqIjMzuikmWvESqMBERDoA1IE3M3xo0fAINJ0fNtEOFmrqvqkZ6Qfo3OP70sMOC81HJZxLvRs1YTICAiB4zrjyEMz7CFIybYXFDruWlQreH0xrIYChnZ6QVOVPiKvnbj2ZDQplz9BEL99UGJ7+RwVD6WRZRB5QGYcoFuhr0t0sIo8lqx7+xebOCiMDgHQofFSFvX1znJXPLGwBDcVYODb/1B3WZKlg1Zkw5+l863RZ4YYVpa9kRh31jXATpeB3RfM/GbDX9Xe8hfCTZWrdf7i6gQAO6FQIS26kgLwlOmxDX8TuzmU2HVAfo1ZY43+hrUhuAJIGWktNjXXDsEadrUI0l4kn+6sJgPG9Q3e4R+Ji3fjm6uUp9b07gU0Z70prYFvJ9PQJnrYr/YPK05VNPe30XhRJ/PtJyNc5YVT2RQQ2GV38lV5orRYjC5I6HgSjy5+M9W8Zc5WbWE9f33Vt+OLXyzMrtqNrFcgj5S2xZnSV7IiOgp5UrFyEfOoGsV1K/SiBJf1Kco1BhcSTT7T+yZR6Czcj/8BjUyTBRqQd94IyvK86DE7MaS28t2FpEVOm9qJ+UAEEXJjZYIE1E21Q+r6z0lnhfcgExY6l/swVZ0r7rOdraqU9hUuUWLgJp06tbOtLVgvXIfqnF0hoJdVR81htw2DjlN0KoTvCDW9kMhRL54N119p5Ln6EaGaw6K60TXhhnXRhjfZTutBJStpWUk3Uww0tklRfPXAOPQYBjohvdzH+xWb+0xR4TwQ28FIjXvPWuWCkaW8hzDQN0Z4hgj7M1NRBUIJ7S4bLsb0YEvTHyVJPzhDCq5IyB5RWOo2kuL5u/irSdUqCfhcuOqg5q2l6GQr6Lj1bJR+nBZhzM3FYFpyh1R8HxPUEzfzvUJsmREiKxidRWcPH5UYWlu4DbPHJu8kh/H8V6+06EnRulQKzZzDdwjIA3OjIu0lunKF/QnpB22FAdlibHVcdf9ngxPCXWLfftnfPEFd+o9yyeVuu6sIoWhhz2RpWZVLx3OTH0xrjI2isVQCWONKVVEJWYipG1ZESgcBG7VpGXT/HZOTAU+aXRsikMTLGai3FeLhHnXPsvuNrsRlnvzcjPbLabgeVpKTWSmZ5JSVbL X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 54ebeb93-a4d2-4aeb-d5e7-08d8fa98d4c3 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5650.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Apr 2021 14:15:58.5831 (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: rGJGjrYyGFtQCncntIpqYlt27SILptpVbjGNxQj4499Mg6LBgTU/bn5z42Pdu/GzIeUGJXBtENe0PgJn0urXTA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB6289 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Use generic naming to share with other padding scheme implementations. These will be moved out of rsa-pkcs1pad.c. Signed-off-by: Varad Gautam --- crypto/rsa-pkcs1pad.c | 62 +++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/crypto/rsa-pkcs1pad.c b/crypto/rsa-pkcs1pad.c index 6329c79316d24..e76fc98a537a4 100644 --- a/crypto/rsa-pkcs1pad.c +++ b/crypto/rsa-pkcs1pad.c @@ -88,17 +88,17 @@ static const struct rsa_asn1_template *rsa_lookup_asn1(const char *name) return NULL; } -struct pkcs1pad_ctx { +struct rsapad_tfm_ctx { struct crypto_akcipher *child; unsigned int key_size; }; -struct pkcs1pad_inst_ctx { +struct rsapad_inst_ctx { struct crypto_akcipher_spawn spawn; const struct rsa_asn1_template *digest_info; }; -struct pkcs1pad_request { +struct rsapad_akciper_req_ctx { struct scatterlist in_sg[2], out_sg[1]; uint8_t *in_buf, *out_buf; struct akcipher_request child_req; @@ -107,7 +107,7 @@ struct pkcs1pad_request { static int rsapad_set_pub_key(struct crypto_akcipher *tfm, const void *key, unsigned int keylen) { - struct pkcs1pad_ctx *ctx = akcipher_tfm_ctx(tfm); + struct rsapad_tfm_ctx *ctx = akcipher_tfm_ctx(tfm); int err; ctx->key_size = 0; @@ -128,7 +128,7 @@ static int rsapad_set_pub_key(struct crypto_akcipher *tfm, const void *key, static int rsapad_set_priv_key(struct crypto_akcipher *tfm, const void *key, unsigned int keylen) { - struct pkcs1pad_ctx *ctx = akcipher_tfm_ctx(tfm); + struct rsapad_tfm_ctx *ctx = akcipher_tfm_ctx(tfm); int err; ctx->key_size = 0; @@ -148,7 +148,7 @@ static int rsapad_set_priv_key(struct crypto_akcipher *tfm, const void *key, static unsigned int rsapad_get_max_size(struct crypto_akcipher *tfm) { - struct pkcs1pad_ctx *ctx = akcipher_tfm_ctx(tfm); + struct rsapad_tfm_ctx *ctx = akcipher_tfm_ctx(tfm); /* * The maximum destination buffer size for the encrypt/sign operations @@ -195,8 +195,8 @@ static void rsapad_akcipher_setup_child(struct akcipher_request *req, 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); + 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); @@ -206,8 +206,8 @@ static void rsapad_akcipher_setup_child(struct akcipher_request *req, static int pkcs1pad_encrypt_sign_complete(struct akcipher_request *req, int err) { 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); + struct rsapad_tfm_ctx *ctx = akcipher_tfm_ctx(tfm); + struct rsapad_akciper_req_ctx *req_ctx = akcipher_request_ctx(req); unsigned int pad_len; unsigned int len; u8 *out_buf; @@ -252,8 +252,8 @@ static void pkcs1pad_encrypt_sign_complete_cb( static int pkcs1pad_encrypt(struct akcipher_request *req) { 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); + struct rsapad_tfm_ctx *ctx = akcipher_tfm_ctx(tfm); + struct rsapad_akciper_req_ctx *req_ctx = akcipher_request_ctx(req); int err; unsigned int i, ps_end; @@ -297,8 +297,8 @@ static int pkcs1pad_encrypt(struct akcipher_request *req) static int pkcs1pad_decrypt_complete(struct akcipher_request *req, int err) { 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); + struct rsapad_tfm_ctx *ctx = akcipher_tfm_ctx(tfm); + struct rsapad_akciper_req_ctx *req_ctx = akcipher_request_ctx(req); unsigned int dst_len; unsigned int pos; u8 *out_buf; @@ -357,8 +357,8 @@ static void pkcs1pad_decrypt_complete_cb( static int pkcs1pad_decrypt(struct akcipher_request *req) { 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); + struct rsapad_tfm_ctx *ctx = akcipher_tfm_ctx(tfm); + struct rsapad_akciper_req_ctx *req_ctx = akcipher_request_ctx(req); int err; if (!ctx->key_size || req->src_len != ctx->key_size) @@ -386,10 +386,10 @@ static int pkcs1pad_decrypt(struct akcipher_request *req) static int pkcs1pad_sign(struct akcipher_request *req) { 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); + 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 pkcs1pad_inst_ctx *ictx = akcipher_instance_ctx(inst); + struct rsapad_inst_ctx *ictx = akcipher_instance_ctx(inst); const struct rsa_asn1_template *digest_info = ictx->digest_info; int err; unsigned int ps_end, digest_size = 0; @@ -440,10 +440,10 @@ static int pkcs1pad_sign(struct akcipher_request *req) static int pkcs1pad_verify_complete(struct akcipher_request *req, int err) { 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); + 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 pkcs1pad_inst_ctx *ictx = akcipher_instance_ctx(inst); + struct rsapad_inst_ctx *ictx = akcipher_instance_ctx(inst); const struct rsa_asn1_template *digest_info = ictx->digest_info; unsigned int dst_len; unsigned int pos; @@ -528,8 +528,8 @@ static void pkcs1pad_verify_complete_cb( static int pkcs1pad_verify(struct akcipher_request *req) { 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); + struct rsapad_tfm_ctx *ctx = akcipher_tfm_ctx(tfm); + struct rsapad_akciper_req_ctx *req_ctx = akcipher_request_ctx(req); int err; if (WARN_ON(req->dst) || @@ -559,8 +559,8 @@ static int pkcs1pad_verify(struct akcipher_request *req) static int rsapad_akcipher_init_tfm(struct crypto_akcipher *tfm) { struct akcipher_instance *inst = akcipher_alg_instance(tfm); - struct pkcs1pad_inst_ctx *ictx = akcipher_instance_ctx(inst); - struct pkcs1pad_ctx *ctx = akcipher_tfm_ctx(tfm); + struct rsapad_inst_ctx *ictx = akcipher_instance_ctx(inst); + struct rsapad_tfm_ctx *ctx = akcipher_tfm_ctx(tfm); struct crypto_akcipher *child_tfm; child_tfm = crypto_spawn_akcipher(&ictx->spawn); @@ -573,14 +573,14 @@ static int rsapad_akcipher_init_tfm(struct crypto_akcipher *tfm) static void rsapad_akcipher_exit_tfm(struct crypto_akcipher *tfm) { - struct pkcs1pad_ctx *ctx = akcipher_tfm_ctx(tfm); + struct rsapad_tfm_ctx *ctx = akcipher_tfm_ctx(tfm); crypto_free_akcipher(ctx->child); } static void rsapad_akcipher_free(struct akcipher_instance *inst) { - struct pkcs1pad_inst_ctx *ctx = akcipher_instance_ctx(inst); + struct rsapad_inst_ctx *ctx = akcipher_instance_ctx(inst); struct crypto_akcipher_spawn *spawn = &ctx->spawn; crypto_drop_akcipher(spawn); @@ -605,7 +605,7 @@ static int rsapad_akcipher_create(struct crypto_template *tmpl, struct rtattr ** { u32 mask; struct akcipher_instance *inst; - struct pkcs1pad_inst_ctx *ctx; + struct rsapad_inst_ctx *ctx; struct akcipher_alg *rsa_alg; const char *hash_name; int err; @@ -661,7 +661,7 @@ static int rsapad_akcipher_create(struct crypto_template *tmpl, struct rtattr ** } inst->alg.base.cra_priority = rsa_alg->base.cra_priority; - inst->alg.base.cra_ctxsize = sizeof(struct pkcs1pad_ctx); + inst->alg.base.cra_ctxsize = sizeof(struct rsapad_tfm_ctx); inst->alg.init = alg->init; inst->alg.exit = alg->exit; @@ -673,7 +673,7 @@ static int rsapad_akcipher_create(struct crypto_template *tmpl, struct rtattr ** 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->alg.reqsize = sizeof(struct rsapad_akciper_req_ctx) + rsa_alg->reqsize; inst->free = rsapad_akcipher_free; From patchwork Thu Apr 8 14:15:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Varad Gautam X-Patchwork-Id: 417577 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=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 BE78CC43462 for ; Thu, 8 Apr 2021 14:16:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 92EAD6113E for ; Thu, 8 Apr 2021 14:16:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231938AbhDHOQx (ORCPT ); Thu, 8 Apr 2021 10:16:53 -0400 Received: from de-smtp-delivery-102.mimecast.com ([194.104.109.102]:58412 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231965AbhDHOQo (ORCPT ); Thu, 8 Apr 2021 10:16:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1617891391; 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=RLInDh1h/QkEsygzJTUoZgnIz9dQEBlOY2EEntpAdgI=; b=l18Pn2sw4/x3B8dikKtbRgQ3csaWQDSsNZ4WgJhk4opqetLb5DYlMaDQbouM1WILb8ogJP stx9uCEn1nIDMz57rk1bgKn6YpiZYE+WPT3k6qkzaOafji0ahwFN9l66Rge+y1jGc7HqRf mNGP4Xh10pNCWKRh5/NfN9NnY4YO4Kk= Received: from EUR03-VE1-obe.outbound.protection.outlook.com (mail-ve1eur03lp2054.outbound.protection.outlook.com [104.47.9.54]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-1-ZTpLxAohNKOtORKYzWW-Gw-3; Thu, 08 Apr 2021 16:16:20 +0200 X-MC-Unique: ZTpLxAohNKOtORKYzWW-Gw-3 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IdgX0vw8HPRAKR2YiKZecFBktziDxWS7x9rsFb6rtoIVM5YLZti2NNyPBsBOiHU5e/Gj0Navz80fKWsdG5imEPGWbPdbVWR+q5GUnRw34S31vfLdGipJHg8cF8u/0OMWR53NVqanKp5omExKbH12Z8jLtV9lCzXSPHS5az2dE//6yswsYDQoupozySp6VEb5UiHXTS3TD2GpffGgsHeKcaD9vQbM+X2ip5cqCWxQElh14NRPWc7Bty+VfCZUjlKfgXA+ZFQlR7jWFib3tL94kqpujV7Onm/rQvIF4WmTJNjId7/Zqs/KReZhxs3DcM4QliQedeU6fNfh42xEBBoHkg== 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=68wfWvHe5jcomxWSlTIKYqj5qEWMMKnldpc+63TNMwI=; b=PxS+fe2L6nVUjvTHFzgwOfRUJK1nW9Di/6t2NKB65HVE9KsjPH1DXMKwij1HMlR8mVbZyTYfEe1129p/b7+G51qfFfhNaH1tQGjUsMV8AxreGZ/hokQER3jT77Xh3GykoW+RwRSkpZol7SPUSY+HyCE/Z+aBB8VDixmIIqQ/L5FMv8IpzvB/ZO/irIir7Dzcov9/pbNf6WYNtF1eHIdCt33zYgRQmjzfRT+gr7vlnUepgb54WzqzdyCiH3QyhJycQ8jP5Lm0N81hTHZ/3Lqz9YVLLYoz8jEV/BZyYWiZgJPC0I8CGOHjgbo7Yj5TQyq3Td8PGjXB8OC2VZLMR3ypjQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=suse.com; Received: from AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) by AM0PR04MB6289.eurprd04.prod.outlook.com (2603:10a6:208:145::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.18; Thu, 8 Apr 2021 14:16:02 +0000 Received: from AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d]) by AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d%6]) with mapi id 15.20.3999.032; Thu, 8 Apr 2021 14:16:02 +0000 From: Varad Gautam To: linux-crypto@vger.kernel.org CC: varad.gautam@suse.com, dhowells@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, vt@altlinux.org, tianjia.zhang@linux.alibaba.com, keyrings@vger.kernel.org, linux-kernel@vger.kernel.org, jarkko@kernel.org Subject: [PATCH v2 06/18] crypto: rsa: Start moving RSA common code to rsa-common Date: Thu, 8 Apr 2021 16:15:04 +0200 Message-ID: <20210408141516.11369-7-varad.gautam@suse.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210408141516.11369-1-varad.gautam@suse.com> References: <20210408141516.11369-1-varad.gautam@suse.com> X-Originating-IP: [95.90.93.216] X-ClientProxiedBy: ZR0P278CA0137.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:40::16) To AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from xps13.suse.cz (95.90.93.216) by ZR0P278CA0137.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:40::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16 via Frontend Transport; Thu, 8 Apr 2021 14:16:01 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: af2984c0-cfc6-4209-626b-08d8fa98d6df X-MS-TrafficTypeDiagnostic: AM0PR04MB6289: 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: hCkcAUtDkQJ+h5Vu7vycDSApD4kZQEAxWrq0Etf0sKpe7G7nHAgpB+o0JQkOrj9we67cVu7t/t9iafagrVdfMy1JDBIxj0oAKUvU3J7jxgw3UrBuUCpj2j88H/mVfg1NiO2P5Qd4FRTl4Aittl3bQFiwPyeGcMzeCpK8K0Fq//unY1hgy9MMCPM089p5ydxU9NkiLiUaSakE6EtZk/cXDszBypD6uzFQSLP96cW9lKAopx5+WCvXQvMFsanA3ysFddpMf9U9LA7hpIhbTqsrmFyqqYTEPDb79MWKhxZK/KnbYqYnGxRhEVmtFLbqetx1GaUrXLtnhkkRNSYGrdHfeSEcxAxVYZeAczmVpCpBzv8FrzUT5UssuJMQwI7rq0skyL2zrUmFzxnv8oXyfYBR3WZvjnB/JzFJcoEljBlHdjXVGXuaO4u7r37umLe26K+WaayeYQKv/pQGdI4hFtpnAUFolcfUxTDbsnybRcTnzhsxn2N6+ksYEwkBCgkCWhAwtIiaJLa63HzpdjUUr/S6uNHiNB71IO4J5cvRiOWaedcEBYIvDN5+uMjw9D39yUrzJya4PE8bXOGM4263mgPqI0aurxjiIQ+U1MJKKF2MBPCUseMFZfXQA+HEsSJbFfYjqdt1YRUeyAC07tCahlQ0NDK7rT3YA9HOhjk9kRwH1MX3xgpvgU6lGtjMa1XJAljn X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR04MB5650.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(396003)(346002)(376002)(136003)(39860400002)(186003)(83380400001)(16526019)(478600001)(6486002)(38100700001)(36756003)(5660300002)(4326008)(6916009)(1076003)(66476007)(316002)(2906002)(66556008)(26005)(38350700001)(2616005)(956004)(8676002)(44832011)(8936002)(6506007)(86362001)(52116002)(66946007)(6512007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: YnxqARE6H4PoM7bVRgxsTYxMErgdOQbK5jZaGBDF/ucK6ef+OaSWQPHqLhneLDROyd744gFrPX1seN8oBrdANoOJPy5WNxQO2qTiaWD1/8AWh/d60pkOm7SkuigHQfGtu03vs7emaPa2fi7SJMedoCOMA2UmkWzgJRME62MhLkemz3J4p4jdrROOPQdZn8aRsijPqOIGswGhu37ld8g6wN44RoUj5Lng9b0Cokf8dle8meKnZAUUQj7g2TTc+cbr/f4+YmAEDyPCHdqFDkoWFMnnWnw7Y0sdMYeerMxpqxT8z6JlCJs4QNjVBky1yLDG6B+NY1uCXg9NEoXcES2sSwScPnN/RpGH0nhGQQ+ZPWDlGrcCEFIyCgDM5nEKudGsFe/RGprFYOBLTxdw3Kt7IdyC7Cxk4uZ/D/pYHihHld+dtu91Eb9nWlT9g32ytnRxWYA1+5LCjh/Y2mIc+6FpJOaoXpQYUGQ9u6j3MwMvSjYG0cn83AqiavFzji6gpTst682vxVBcNTxyJiljnJSmdH8aqvJJmBdajLDRHKeWZNcTj/doLzOoQY3Vni4E69TVUuW/hiWy1UxzMCSn1XSBmLl8Im6C1W/diOv6HWV+ud07AcZk06968ibc4xwbeINzayj5Et7XdPf6ozO5hcPuqaWlEWGkHJL8hiq+n9cQ+Ko36gMF0xHUkIOJBJYlmXSfZ879n9ZMttvqedDNtvx8qnQHDkb7tUx8QgFNLqHXdRg5+/fKhoPbx7seGXjJ8qOkbMqBSVoIZwGj8aejAYvslTglRPwGEHN7yeGg9SUSvT2I8owr3+XCyGuedJqBgmTA77ziUJPW/xPXBQLGE5QiNzqAs+pwmqQsstJK0mN+JGp2ZfKVtCe/ZtSeq2SWPoGQ5z4yHXSdY+Oc+XhwcxEmMLqHHVL78as+n55KQgIa8vTKw26+LFurmHA5XrTzAAyCT87/ndxZ2j45jW0ZQtUkpIVSZO8n7lD86ngu2hV8rZlIDLtSsZ0ENw2tGvOEKal+mvF221o3XVbFjWMAR4HOy/5/lhR1vyreSYeeN0OifHNnE7nHDNkD/B5qJxGxq4/mTrXK9/m4s4Ydt1JGPEs16Av76apav3cq19aa7VLS966VfReqiiSDY/FXOcXO7YKyyWMu1ve1QwVY49CRngDAXiNva55UdOtCv4DubWUcFXfid1d3Okc6LUSH15LibB+YN9EuzZr77HkDxdhU7ym+B+OtRMMD4rXS/RN8tNqkbKq/X49U/jFTy9WoblVR/+HBfYaw4Um4KeBSA9zGREs/6aI+elyzVnn3kfjdU5a/ZjdKPXWQwFq1zp6/EogMpY0R X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: af2984c0-cfc6-4209-626b-08d8fa98d6df X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5650.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Apr 2021 14:16:02.2100 (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: LYPs0OM7EK3PkqC/C5ZisX56OCbUHTeZHi8P48bZRIYka1BW01o0hcgcqaWteXvGYkVJT/KYcbMewFR5aesAJg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB6289 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 cf23affb16780..57a85b2b3429b 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 0000000000000..60073c56e3748 --- /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 e76fc98a537a4..ffb7220b3d10a 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 0000000000000..ecdce0cdafaa3 --- /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 Thu Apr 8 14:15:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Varad Gautam X-Patchwork-Id: 418314 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 63314C433B4 for ; Thu, 8 Apr 2021 14:16:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3333461154 for ; Thu, 8 Apr 2021 14:16:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232033AbhDHORH (ORCPT ); Thu, 8 Apr 2021 10:17:07 -0400 Received: from de-smtp-delivery-102.mimecast.com ([194.104.109.102]:25127 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231980AbhDHORA (ORCPT ); Thu, 8 Apr 2021 10:17:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1617891408; 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=yajnkEc27ntpQX9y5f1agIELyl3+Xvf1Su9bs6qert0=; b=IYWwnsTaYd7Ef/ZObP4sVrEKQv5rNeCHaE3u3G6ie3JIB2bxFv/0UO0VWTIqAHJn2kT3HJ uhx/nSCuX734A+GZw4Un+SwUiEV5DbRyL5l1JAXEEpY5plzGEMouzwbEbxPlqw/aPJPc17 YzD9yMDprzh5D3VCpusA1osZErX2zXY= Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04lp2057.outbound.protection.outlook.com [104.47.13.57]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-27-4bJ2o2H5PpiXblB8gvqBow-4; Thu, 08 Apr 2021 16:16:26 +0200 X-MC-Unique: 4bJ2o2H5PpiXblB8gvqBow-4 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PKTcxT4u4m+BC6xbGkMUAmrKX1YcEvKVtTEnLUO7x6mpYdgZSxK700x/1MPUHiNOTO1CJkJRx9ARAdV2eOxAtPNcqYPqtdRoeEAqGZxaLCQ/rmSqCL5JmUoePKQWpzj4gzFRZbKQvsXCV19QcB4AfBifPRP0rPtNwmeSxxmknG2VTViXChPszzpWfuTVsLoPyPOLCYLpMYzHutTgGVrFnk/l90Vq1HmvGAy2gdiOpfuPYswbrFRfw47cBXuGXjzrOknWvZilEFilXzL6VoV9/1HkOkewyVqnV3WQDXv6RFP6mFfSND/BTRbqceBsHX46O+Vshhw2p2yzXsGcFvVlAQ== 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=7T9VlDQvS45hhOSp2ljrxv0PI2XxklWAE2faxm4TbDk=; b=jNSSu+uYq5PfXijKdlIgW4sqsJRFaQz1GahRK/LPffxMtxUbnj42jP8LyIO8gMTkbdzcYNxhnudX0u5eimTf9/C4tGZ6zJsLIi3N/781LlR3LxhMUKD07zc5zIW4W266oqwcgo7Dl5bXZ7+aGqDe0mECEfoInebdWUn1XNq7O9wjD99qCk/fMgRIeXtv9miYdfVi5ZWQcbw9HTlXjHOSpnlkbHLNwFj/WIZQseXeuWxioBgRgeJVGlr/eFeYq80I2c0FrM+GWuqwl8SHR2LhLXwkdI2ktfJs2+d7vvSgWW73cWoWBTpjpP/EO05U7YAJZHtLG2yOyX2LuTiaCk3a5A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=suse.com; Received: from AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) by AM0PR04MB6289.eurprd04.prod.outlook.com (2603:10a6:208:145::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.18; Thu, 8 Apr 2021 14:16:05 +0000 Received: from AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d]) by AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d%6]) with mapi id 15.20.3999.032; Thu, 8 Apr 2021 14:16:05 +0000 From: Varad Gautam To: linux-crypto@vger.kernel.org CC: varad.gautam@suse.com, dhowells@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, vt@altlinux.org, tianjia.zhang@linux.alibaba.com, keyrings@vger.kernel.org, linux-kernel@vger.kernel.org, jarkko@kernel.org Subject: [PATCH v2 07/18] crypto: rsa: Move more common code to rsa-common Date: Thu, 8 Apr 2021 16:15:05 +0200 Message-ID: <20210408141516.11369-8-varad.gautam@suse.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210408141516.11369-1-varad.gautam@suse.com> References: <20210408141516.11369-1-varad.gautam@suse.com> X-Originating-IP: [95.90.93.216] X-ClientProxiedBy: ZR0P278CA0137.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:40::16) To AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from xps13.suse.cz (95.90.93.216) by ZR0P278CA0137.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:40::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16 via Frontend Transport; Thu, 8 Apr 2021 14:16:04 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 562b625c-9a30-49ea-500a-08d8fa98d8a4 X-MS-TrafficTypeDiagnostic: AM0PR04MB6289: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:252; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: irSJHN+OYLOOsdHGoMiRHJ15zQt89a3DMHxqPOVepuObKhEVzgJ16XxanIcfLhKeMDFUFkoiG/SLo27P2E7IyEj91C5GkqfOhG21rVVk0afbIPhPmfp0VH+B8vcnMo8ssHxcHai9ttQat2o0RoVjrPKV3etpnWRIw24VsszCyIAIU3/jewauqgd5xV23oqbzRIm/vvoWQr8V6Z0QBblUSIDlyn2Mm4LXNH2CfwJAwtn7bkbknyCIBri70htj2+TNzHMcsYlo7dEPsWtYNcPckOmrHdUsFfjhO9GRfVi5xeIp2TntQKRFWYW5njSOiQZGmhVR5PpdVH9ULFQ/B9W1GYU5Pxdp4RVSI/aYmtmzPIvNdKYZ9rNgornACJgjFVxSB0m5d0CxXNjilqONdIT6qoKwqpc+7yg4q22O2d2Dv7VcSnIQ3ua0H5a48up7A1lYng4PXN2dMNxvcKgUtnWb2E5mOVWm1APbe6llDyZNAKgE7clTB9IFiTJYJhlmNgda6XEMb0nGgl+MmSC/UauMBLDlg3iOPrUZFA8DdaReyE4E/vM3E2bfNGEXWUriInpm0qVVwbM6bhN/3HsKjiCYpd/DcDj4JP3K85N08BaEN7V5fl1X8y/PEypaL/wFZvz2lqc9FQ+j77x6+xblI0ZFxbVH/n5zWd6kzQY0WtJ4+0Ff21cTYYnoMthV9J7qS/jX X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR04MB5650.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(396003)(346002)(376002)(136003)(39860400002)(186003)(83380400001)(16526019)(478600001)(6486002)(38100700001)(36756003)(30864003)(5660300002)(4326008)(6916009)(1076003)(66476007)(316002)(2906002)(66556008)(26005)(38350700001)(2616005)(956004)(8676002)(44832011)(8936002)(6506007)(86362001)(52116002)(66946007)(6512007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: bcSEJPJ1UANNX2hdaJU4P4GgjY1nklfla/xwO5isIEwv37Dm8kXUgK7JrZJtwtwoTeSni+8jwRgTabgcBEmL9ZYemlJso28UeWZt4tFV+ToyhBib2qHLs8WXE/Yt9cNEknb5DyBvooX4aMy1/OlunNeKaXDrIrhQdNtquFQ9HYtt/UACcCVXaWHlVDfUnCNNuRokbI2irjKLGoarlf/YcldCd/oVQa/7bOSMJiXWlupgtWiZ/bgTBJViMWTkErX2uEYIvdcdf2AChBOQ1lAnjJjgtPyJPL39bozGJDZNF3jGyn4uQ4+BEvCys6zxyJorNTOB7V1WV7esudK2Wq7JxwtPPUJZsIVrGO/X8kYGHlg/9cHX9jfBOQePw20tRC+P64zg9z8jOLRIxG0qCFD0Y/TM5dbjy+UsWKpRzwXACUpnG7U+PuxsP5R20An0mKKVMVsKwMaq1gV6JyAK4cVqODbEOSJZQ2AluauBLAPOOJi6r1IHNmVkBUZjINRctbYJelt3G5q0I17YqBtXZtBLuYd+KsHTkX0lLRZJG5mbaub3WKevm7IIV2U0GxUeuhVBNL2EQ4jEaYVcNTbTSvE6T0f2Vq203v9yJh1ueTNkElvkraLA5mWM4S+LDGwe0jb0GgWRX40QmkrNryH/2cnG8A35Etp0dEtSJzWK6eh+aIhKKbsGzDJID2WTB1LhTUD7DxQ+Mri9FKtXc2E8WlUpbZLDzL35gSppcDHgEegV/wQA9mC8jaVwj6RhZnSDR/jKPxISNt8eqOAUBW6d77XYjC6bCUG9GSndQH8W40M2JaaklJOd4BdM094rPIClkEknp9oi3+etQ8fxnk9sxS+KO2skTrS+MIkyR66f9avbZplQkYJlE1pmv/fq+yt2eSFPkXYCXlzCpdYzeFZTmxHapwDtypli46a7aAk8+T4sSwyPBwmYiCe1gRRc3qUokzRiE4j8bb455+l7z+nWXGEyD+W13EymHc96yW8397a9kkQLJqKlzmYV5nD7b8FUvp78q1gMaPV3GXE5FPx8Jcr83b4cZnvVPehTG80CVbt9EzD1HDxdLeKs38iPf1VExjqgZi6Hk2qkcGW/laV9a0JOhKhnMokVWPRO2neJx2HNxXodJV0E8IlpNQCjWlorYyJeXXY5i89+kYxPw/KoGoewT0YwXyqdZI09SAkxsdOUeRu/GE1hiiHihW/GSeHMNsAuIca9uqc9xgSe1/2KCTIh7q2d27jYlX8Q1DdRw3H+bBoLyKfqDfaEH2qqu+ZG61XmAHYXryrDVhwx4n69g9sBf+RAywL4JmG7S33UMiw+zOMIveHxh7yzZd3W5Sjbn1jL X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 562b625c-9a30-49ea-500a-08d8fa98d8a4 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5650.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Apr 2021 14:16:05.1344 (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: KSOZCnNVLL0eeb0P29Odu6ii+DZznAThTrQAj8iMX5+4bwel7YanwSSRzX+qJYC5KgskyP+NkM2dkmkm8m1ekQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB6289 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Move helpers for setting public/private keys, RSA akcipher instance setup, keysize querying etc. to rsa-common.c. Signed-off-by: Varad Gautam --- crypto/rsa-common.c | 183 +++++++++++++++++++++++++++ crypto/rsa-pkcs1pad.c | 183 --------------------------- include/crypto/internal/rsa-common.h | 13 ++ 3 files changed, 196 insertions(+), 183 deletions(-) diff --git a/crypto/rsa-common.c b/crypto/rsa-common.c index 60073c56e3748..d70d7d405165f 100644 --- a/crypto/rsa-common.c +++ b/crypto/rsa-common.c @@ -74,3 +74,186 @@ const struct rsa_asn1_template *rsa_lookup_asn1(const char *name) return p; return NULL; } + +int rsapad_set_pub_key(struct crypto_akcipher *tfm, const void *key, + unsigned int keylen) +{ + struct rsapad_tfm_ctx *ctx = akcipher_tfm_ctx(tfm); + int err; + + ctx->key_size = 0; + + err = crypto_akcipher_set_pub_key(ctx->child, key, keylen); + if (err) + return err; + + /* Find out new modulus size from rsa implementation */ + err = crypto_akcipher_maxsize(ctx->child); + if (err > PAGE_SIZE) + return -EOPNOTSUPP; + + ctx->key_size = err; + return 0; +} + +int rsapad_set_priv_key(struct crypto_akcipher *tfm, const void *key, + unsigned int keylen) +{ + struct rsapad_tfm_ctx *ctx = akcipher_tfm_ctx(tfm); + int err; + + ctx->key_size = 0; + + err = crypto_akcipher_set_priv_key(ctx->child, key, keylen); + if (err) + return err; + + /* Find out new modulus size from rsa implementation */ + err = crypto_akcipher_maxsize(ctx->child); + if (err > PAGE_SIZE) + return -EOPNOTSUPP; + + ctx->key_size = err; + return 0; +} + +unsigned int rsapad_get_max_size(struct crypto_akcipher *tfm) +{ + struct rsapad_tfm_ctx *ctx = akcipher_tfm_ctx(tfm); + + /* + * The maximum destination buffer size for the encrypt/sign operations + * will be the same as for RSA, even though it's smaller for + * decrypt/verify. + */ + + return ctx->key_size; +} + +void rsapad_akcipher_sg_set_buf(struct scatterlist *sg, void *buf, + size_t len, struct scatterlist *next) +{ + int nsegs = next ? 2 : 1; + + sg_init_table(sg, nsegs); + sg_set_buf(sg, buf, len); + + if (next) + sg_chain(sg, nsegs, next); +} + +int rsapad_akcipher_init_tfm(struct crypto_akcipher *tfm) +{ + struct akcipher_instance *inst = akcipher_alg_instance(tfm); + struct rsapad_inst_ctx *ictx = akcipher_instance_ctx(inst); + struct rsapad_tfm_ctx *ctx = akcipher_tfm_ctx(tfm); + struct crypto_akcipher *child_tfm; + + child_tfm = crypto_spawn_akcipher(&ictx->spawn); + if (IS_ERR(child_tfm)) + return PTR_ERR(child_tfm); + + ctx->child = child_tfm; + return 0; +} + +void rsapad_akcipher_exit_tfm(struct crypto_akcipher *tfm) +{ + struct rsapad_tfm_ctx *ctx = akcipher_tfm_ctx(tfm); + + crypto_free_akcipher(ctx->child); +} + +void rsapad_akcipher_free(struct akcipher_instance *inst) +{ + struct rsapad_inst_ctx *ctx = akcipher_instance_ctx(inst); + struct crypto_akcipher_spawn *spawn = &ctx->spawn; + + crypto_drop_akcipher(spawn); + kfree(inst); +} + +int rsapad_akcipher_create(struct crypto_template *tmpl, struct rtattr **tb, + struct akcipher_alg *alg) +{ + u32 mask; + struct akcipher_instance *inst; + struct rsapad_inst_ctx *ctx; + struct akcipher_alg *rsa_alg; + const char *hash_name; + int err; + + err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_AKCIPHER, &mask); + if (err) + return err; + + inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL); + if (!inst) + return -ENOMEM; + + ctx = akcipher_instance_ctx(inst); + + err = crypto_grab_akcipher(&ctx->spawn, akcipher_crypto_instance(inst), + crypto_attr_alg_name(tb[1]), 0, mask); + if (err) + goto err_free_inst; + + rsa_alg = crypto_spawn_akcipher_alg(&ctx->spawn); + + err = -ENAMETOOLONG; + hash_name = crypto_attr_alg_name(tb[2]); + if (IS_ERR(hash_name)) { + if (snprintf(inst->alg.base.cra_name, + 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, "%s(%s)", tmpl->name, + rsa_alg->base.cra_driver_name) >= + CRYPTO_MAX_ALG_NAME) + goto err_free_inst; + } else { + ctx->digest_info = rsa_lookup_asn1(hash_name); + if (!ctx->digest_info) { + err = -EINVAL; + goto err_free_inst; + } + + if (snprintf(inst->alg.base.cra_name, CRYPTO_MAX_ALG_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, "%s(%s,%s)", + tmpl->name, + rsa_alg->base.cra_driver_name, + hash_name) >= CRYPTO_MAX_ALG_NAME) + goto err_free_inst; + } + + inst->alg.base.cra_priority = rsa_alg->base.cra_priority; + inst->alg.base.cra_ctxsize = sizeof(struct rsapad_tfm_ctx); + + inst->alg.init = alg->init; + inst->alg.exit = alg->exit; + + 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 rsapad_akciper_req_ctx) + rsa_alg->reqsize; + + inst->free = rsapad_akcipher_free; + + err = akcipher_register_instance(tmpl, inst); + if (err) { +err_free_inst: + rsapad_akcipher_free(inst); + } + return err; +} diff --git a/crypto/rsa-pkcs1pad.c b/crypto/rsa-pkcs1pad.c index ffb7220b3d10a..30b0193b7352a 100644 --- a/crypto/rsa-pkcs1pad.c +++ b/crypto/rsa-pkcs1pad.c @@ -9,73 +9,6 @@ #include #include -static int rsapad_set_pub_key(struct crypto_akcipher *tfm, const void *key, - unsigned int keylen) -{ - struct rsapad_tfm_ctx *ctx = akcipher_tfm_ctx(tfm); - int err; - - ctx->key_size = 0; - - err = crypto_akcipher_set_pub_key(ctx->child, key, keylen); - if (err) - return err; - - /* Find out new modulus size from rsa implementation */ - err = crypto_akcipher_maxsize(ctx->child); - if (err > PAGE_SIZE) - return -ENOTSUPP; - - ctx->key_size = err; - return 0; -} - -static int rsapad_set_priv_key(struct crypto_akcipher *tfm, const void *key, - unsigned int keylen) -{ - struct rsapad_tfm_ctx *ctx = akcipher_tfm_ctx(tfm); - int err; - - ctx->key_size = 0; - - err = crypto_akcipher_set_priv_key(ctx->child, key, keylen); - if (err) - return err; - - /* Find out new modulus size from rsa implementation */ - err = crypto_akcipher_maxsize(ctx->child); - if (err > PAGE_SIZE) - return -ENOTSUPP; - - ctx->key_size = err; - return 0; -} - -static unsigned int rsapad_get_max_size(struct crypto_akcipher *tfm) -{ - struct rsapad_tfm_ctx *ctx = akcipher_tfm_ctx(tfm); - - /* - * The maximum destination buffer size for the encrypt/sign operations - * will be the same as for RSA, even though it's smaller for - * decrypt/verify. - */ - - return ctx->key_size; -} - -static void rsapad_akcipher_sg_set_buf(struct scatterlist *sg, void *buf, - size_t len, struct scatterlist *next) -{ - int nsegs = next ? 2 : 1; - - sg_init_table(sg, nsegs); - sg_set_buf(sg, buf, len); - - if (next) - 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) @@ -461,37 +394,6 @@ static int pkcs1pad_verify(struct akcipher_request *req) return err; } -static int rsapad_akcipher_init_tfm(struct crypto_akcipher *tfm) -{ - struct akcipher_instance *inst = akcipher_alg_instance(tfm); - struct rsapad_inst_ctx *ictx = akcipher_instance_ctx(inst); - struct rsapad_tfm_ctx *ctx = akcipher_tfm_ctx(tfm); - struct crypto_akcipher *child_tfm; - - child_tfm = crypto_spawn_akcipher(&ictx->spawn); - if (IS_ERR(child_tfm)) - return PTR_ERR(child_tfm); - - ctx->child = child_tfm; - return 0; -} - -static void rsapad_akcipher_exit_tfm(struct crypto_akcipher *tfm) -{ - struct rsapad_tfm_ctx *ctx = akcipher_tfm_ctx(tfm); - - crypto_free_akcipher(ctx->child); -} - -static void rsapad_akcipher_free(struct akcipher_instance *inst) -{ - struct rsapad_inst_ctx *ctx = akcipher_instance_ctx(inst); - struct crypto_akcipher_spawn *spawn = &ctx->spawn; - - crypto_drop_akcipher(spawn); - kfree(inst); -} - static struct akcipher_alg pkcs1pad_alg = { .init = rsapad_akcipher_init_tfm, .exit = rsapad_akcipher_exit_tfm, @@ -505,91 +407,6 @@ static struct akcipher_alg pkcs1pad_alg = { .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; - struct rsapad_inst_ctx *ctx; - struct akcipher_alg *rsa_alg; - const char *hash_name; - int err; - - err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_AKCIPHER, &mask); - if (err) - return err; - - inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL); - if (!inst) - return -ENOMEM; - - ctx = akcipher_instance_ctx(inst); - - err = crypto_grab_akcipher(&ctx->spawn, akcipher_crypto_instance(inst), - crypto_attr_alg_name(tb[1]), 0, mask); - if (err) - goto err_free_inst; - - rsa_alg = crypto_spawn_akcipher_alg(&ctx->spawn); - - err = -ENAMETOOLONG; - hash_name = crypto_attr_alg_name(tb[2]); - if (IS_ERR(hash_name)) { - if (snprintf(inst->alg.base.cra_name, - 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, "%s(%s)", tmpl->name, - rsa_alg->base.cra_driver_name) >= - CRYPTO_MAX_ALG_NAME) - goto err_free_inst; - } else { - ctx->digest_info = rsa_lookup_asn1(hash_name); - if (!ctx->digest_info) { - err = -EINVAL; - goto err_free_inst; - } - - if (snprintf(inst->alg.base.cra_name, CRYPTO_MAX_ALG_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, "%s(%s,%s)", - tmpl->name, - rsa_alg->base.cra_driver_name, - hash_name) >= CRYPTO_MAX_ALG_NAME) - goto err_free_inst; - } - - inst->alg.base.cra_priority = rsa_alg->base.cra_priority; - inst->alg.base.cra_ctxsize = sizeof(struct rsapad_tfm_ctx); - - inst->alg.init = alg->init; - inst->alg.exit = alg->exit; - - 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 rsapad_akciper_req_ctx) + rsa_alg->reqsize; - - inst->free = rsapad_akcipher_free; - - err = akcipher_register_instance(tmpl, inst); - if (err) { -err_free_inst: - rsapad_akcipher_free(inst); - } - return err; -} - static int pkcs1pad_create(struct crypto_template *tmpl, struct rtattr **tb) { return rsapad_akcipher_create(tmpl, tb, &pkcs1pad_alg); diff --git a/include/crypto/internal/rsa-common.h b/include/crypto/internal/rsa-common.h index ecdce0cdafaa3..a6f20cce610ab 100644 --- a/include/crypto/internal/rsa-common.h +++ b/include/crypto/internal/rsa-common.h @@ -34,4 +34,17 @@ struct rsapad_akciper_req_ctx { struct akcipher_request child_req; }; +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, + unsigned int keylen); +unsigned int rsapad_get_max_size(struct crypto_akcipher *tfm); +void rsapad_akcipher_sg_set_buf(struct scatterlist *sg, void *buf, + size_t len, struct scatterlist *next); +int rsapad_akcipher_init_tfm(struct crypto_akcipher *tfm); +void rsapad_akcipher_exit_tfm(struct crypto_akcipher *tfm); +void rsapad_akcipher_free(struct akcipher_instance *inst); +int rsapad_akcipher_create(struct crypto_template *tmpl, struct rtattr **tb, + struct akcipher_alg *alg); + #endif From patchwork Thu Apr 8 14:15:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Varad Gautam X-Patchwork-Id: 417576 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6CF04C433ED for ; Thu, 8 Apr 2021 14:16:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 50D4061153 for ; Thu, 8 Apr 2021 14:16:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229803AbhDHOQ5 (ORCPT ); Thu, 8 Apr 2021 10:16:57 -0400 Received: from de-smtp-delivery-102.mimecast.com ([194.104.109.102]:60690 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231990AbhDHOQv (ORCPT ); Thu, 8 Apr 2021 10:16:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1617891398; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=96DN941Ef/gymzsqU9SPmXm1cdxD7+/+a/zlrCm7hnM=; b=e1G9MwjfObHAjERyVisDqiwhS0u+hAq671cihnfHk3i+VhdPugVzZCorg3TkfuvTCfERCp VB/Y+vm4ZgNON700t0v6N7K0+725c+g7q3v+S/RI+EHJF0ox0wdptrzBKwXXNe1/M8Xl5b wfRuKpMlsqVrenKd360r5gbPSOWNkqI= Received: from EUR03-VE1-obe.outbound.protection.outlook.com (mail-ve1eur03lp2054.outbound.protection.outlook.com [104.47.9.54]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-1-Ft4tSEzDNbe_GsUI_sFm7Q-4; Thu, 08 Apr 2021 16:16:27 +0200 X-MC-Unique: Ft4tSEzDNbe_GsUI_sFm7Q-4 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ecn/gqBFy/bFB0c9wcNA3mcKJXNdF2VEEKK9R3O4hOwrUvfHniOnAD4/8J/Lr0ataZfUmAaRVTZnQI5iRp60hs0LvU9vu5MnfHk7zNHKu8Fre2JLqN83XXyB5oDNVaLZ+K64FLmje0BaADG2uV8nrPwYU565kS5Ogfpq9TEdx/Yaibi05vwciTlC+jqeQ86bK3oNgnIKhER3BMfsHXSMhvAKIoQ2zi/L43KpG/egvfZ+uOF0nl72czL9EMLgAGEEjJP9P4l8NWIqD/4Avc1Laab3WuLJoiRAcvtLtNQKBYDnORGh2jIGLMVad7xfR6d1UhMG4nufbY+Rb7m2GDwJzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1Sa23WQs3NsEGBLTmg6WpJVp9KxgVeUeR2V32E5DXSs=; b=k+Lle9JVsQkzoOAkPuPkw2CnrDxZnWy0uevWizVFntUcZAzIuyTkZvGJl51JlDbN5FHGuNYUsOzfRilWZQl1ikzKFukUIXAxzFqqzwnsRUXmnn6/JVUc9mbHaaDbDHB+PnRZSxF/VRZttzuYfYIDA/HYeoBRNvGK5cqofTOw9lcsVBGcCkRf3Gor7baYrl65H5sQybj15FvwEPH0r6xpwx4I7GceXYoz6IWqwaehnVI4scL5av1GatgyOc4vWkVsP6DkOgHQLoJgBUDlqvSBZ8VLICLBMAtR60mr6oFzQelUFD8I6lnm1l9ap+Kf1q/ZCLcufeLTX+fGdg/THhO/Xg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=suse.com; Received: from AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) by AM0PR04MB6289.eurprd04.prod.outlook.com (2603:10a6:208:145::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.18; Thu, 8 Apr 2021 14:16:14 +0000 Received: from AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d]) by AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d%6]) with mapi id 15.20.3999.032; Thu, 8 Apr 2021 14:16:13 +0000 From: Varad Gautam To: linux-crypto@vger.kernel.org CC: varad.gautam@suse.com, dhowells@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, vt@altlinux.org, tianjia.zhang@linux.alibaba.com, keyrings@vger.kernel.org, linux-kernel@vger.kernel.org, jarkko@kernel.org Subject: [PATCH v2 08/18] crypto: rsa: Move rsapad_akcipher_setup_child and callback to rsa-common Date: Thu, 8 Apr 2021 16:15:06 +0200 Message-ID: <20210408141516.11369-9-varad.gautam@suse.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210408141516.11369-1-varad.gautam@suse.com> References: <20210408141516.11369-1-varad.gautam@suse.com> X-Originating-IP: [95.90.93.216] X-ClientProxiedBy: ZR0P278CA0137.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:40::16) To AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from xps13.suse.cz (95.90.93.216) by ZR0P278CA0137.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:40::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16 via Frontend Transport; Thu, 8 Apr 2021 14:16:07 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c9a6d10f-5f6b-4e2a-f0d5-08d8fa98da56 X-MS-TrafficTypeDiagnostic: AM0PR04MB6289: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:185; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Ybx9oqeXHRlFh4GkPHKjyBAYerFOLC/BKtshcilpZmh41HvhgvCnb+h0DEw6qkLxjKSPgKUdmAshzMzrXzVXRTUg+jLWRjdOBIXhAU0nZtf4jmoP9NwRPIj0vNJNXV6I1kerky5mMmqmnWthbioofM17TqCsvG/LuklIsxDTWEVzns+Xj5MOE39CkIz133KgrO38lnAMkNpZsAFuatIGBwMcbFZwi36cAd07wPCFaQV5f1r3OUadHaOSA1RX7Z25LHQr8Q83g2s7LHdWRdKjMNJDn3kj+qrFBes/28aCdNkJdkSyE1j7/4flcBYfIm9GkHurVmgTQ0eOyrr+1azTewEG/01uzQDwGA2vhPSkuo7EeJdFuZkBx7RH07mfu7/AwufaWARrHGNjrjZHnCUxGCged3rLAUqIpv6ykTIPaEK2H4UtT1rqGBYmROIlx+0kDkIT2rf6o5ksKkwEAXrHdOIKqBBCg54/zJ59ZKbX6r/ZadW1UhJUOaz7omRdhZMqH7s0jxpCh2WMjXoaJW1og4vpYnpYaeuFNxQStUFYrwpl3t2z2SsEuONAWAUV3mt1jAun0SWKI4s6h8ylYec5akyaJCa0Ymq4HUOvMSlJN0xqqEmNfBP9ODFCP2WKhc/jiKpiZv6xJVSIJZSj/cYeFRNpRIoUtnhF6TKbgc7PDvGMMCFC23GXNA7yKq8mgovkl5qG5A9v9Ph9CxrWwSSWlQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR04MB5650.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(396003)(346002)(376002)(136003)(39860400002)(186003)(83380400001)(16526019)(478600001)(6486002)(38100700001)(36756003)(5660300002)(4326008)(6916009)(1076003)(66476007)(316002)(2906002)(66556008)(26005)(38350700001)(2616005)(956004)(8676002)(44832011)(8936002)(6506007)(86362001)(52116002)(66946007)(6512007)(473944003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: BW6WZiNYxD+8/YNcl2HxlD5rgJMTf+n8QLbNxqurDVHC97YeEa9euOClnwaJ1ntSFJoVwiMG0cBGGqnLYbfYJx6n02wMX2SjNnSC+PuQ269hsrHK4TIsNmlqQHn2DBm+KVwDRM1199jjQH+y1NDdQZkdi9lE17UC/19KTHIDFSdgym04chdoQSoSW4v1w+Vl4MUVwqFpQIanTVb/cXcfqibBmgiRKa22juzBQjBoFzTebnxPNDnwEbHFJmwVZa+vZyATMBazmAZZggpTwizVO0ffCALzbCwOSB07OgRckAdglXFUWi/mJXx4cBOChdYR040K0wSA9Dd8ZmKZZrN0b2AY/yDtPhL3rAsvwIF8kFG7ubTZHE102njZHnbMOiZojv9Y4lDwZHY4L+xYfJw2ipnLCUTF/cpG+I4JmONw9LwTRmVupI2L9UzHVMqHq/T4ME7x7a7OWhCDE6yvahEWV3dVfbkfp34akXn6aiyecqaasDVtKUPQIHMrjGdwvwx8nqmmjY9VPaCkgukucKpviXeG/CjBHQe1oLO9zyHz/fUPcB3FhiladxqU7eRH3LKP8agyemkHwLXrzm7PcaSBPdeUXgv5F13zSfj3zpuLJ2rLm8X++MyV8y+TQ1oMGYO5SyW8V9iCCw3bf4RZ1NDlvkMdO54cT7oYCeCQ4PMofI44cJho4BFwDV1jT8OZyQpEI1NOIYp4PzNrl0kPOGSHUDS+5jcUnfJ45RfDxvqshhIWVDJGr/tCxqLwhhh3L34fXQAwW6L5TND2wXeL6WDMrwrAkrMCEMXjSIBDSw2lcTNxBkSsAIro/1guYA26ViLwmaAkWC3o13NDTcjClHOhSouohS5PbvmHuhwJRFMyfiThSGJmnuYuWkKgdR9ZpRXNYqquP1u5uGctVmF1I3sfw266u9Y2r6xHq+FFCRYgPz35RMc/f0x2+mNdacilOUtZJhk8VeaaIe+pThWyaQGEh/6BjtldFWQlBLwIOaVtsWrkZuC72gSuBe4X0NnlMoALhBpuiT/crLQ2vevTFB/0qUPOokiLuYCZYTIUx9byepmRzXp+KWEZFY5KTQbRH1zlKe/qwNPBPbxqGrMqzv+WJwQ84jzl+yY4nL37Ev5ZiLkltZEqYEV5ji/fSYAxDLMCvZBsCBK8Y9vECi07EISax6NsqmEu4ZQLPTKZ9DN4JGSgu7QrDL3wuJkOoy0rawS+e6HtXb8S5fKKvhzhwJEMJhL4Vf6RzJM02PjWU6to3f8TWiq8CSXDYnZr547vJgsr9gYEXchpX7pKZZjfa9GNBZ58a09MoOWqeN+Uiv/EiF0hC0TQgXWAKBz+LQt7y9eW X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: c9a6d10f-5f6b-4e2a-f0d5-08d8fa98da56 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5650.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Apr 2021 14:16:12.9499 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: DeeJmq5HYfTpzBBfZdrGZJXhPGQjS13ljawHDz5VcSxHs4E5NzbjniHJrhhtJChVTV0Lp8OTbAUDvBNDoGLJxg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB6289 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Pull out more common code from rsa-pkcs1pad into rsa-common. Signed-off-by: Varad Gautam --- crypto/rsa-common.c | 31 +++++++++++++++++++++++++++ crypto/rsa-pkcs1pad.c | 32 ---------------------------- include/crypto/internal/rsa-common.h | 9 ++++++++ 3 files changed, 40 insertions(+), 32 deletions(-) diff --git a/crypto/rsa-common.c b/crypto/rsa-common.c index d70d7d405165f..6ed258a782875 100644 --- a/crypto/rsa-common.c +++ b/crypto/rsa-common.c @@ -75,6 +75,37 @@ const struct rsa_asn1_template *rsa_lookup_asn1(const char *name) return NULL; } +void rsapad_akcipher_req_complete(struct crypto_async_request *child_async_req, + int err, rsa_akcipher_complete_cb cb) +{ + struct akcipher_request *req = child_async_req->data; + struct crypto_async_request async_req; + + if (err == -EINPROGRESS) + return; + + async_req.data = req->base.data; + async_req.tfm = crypto_akcipher_tfm(crypto_akcipher_reqtfm(req)); + async_req.flags = child_async_req->flags; + req->base.complete(&async_req, cb(req, err)); +} + +void rsapad_akcipher_setup_child(struct akcipher_request *req, + struct scatterlist *src_sg, + struct scatterlist *dst_sg, + unsigned int src_len, + unsigned int dst_len, + crypto_completion_t cb) +{ + struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req); + struct rsapad_tfm_ctx *ctx = akcipher_tfm_ctx(tfm); + struct rsapad_akciper_req_ctx *req_ctx = akcipher_request_ctx(req); + + akcipher_request_set_tfm(&req_ctx->child_req, ctx->child); + akcipher_request_set_callback(&req_ctx->child_req, req->base.flags, cb, req); + akcipher_request_set_crypt(&req_ctx->child_req, src_sg, dst_sg, src_len, dst_len); +} + int rsapad_set_pub_key(struct crypto_akcipher *tfm, const void *key, unsigned int keylen) { diff --git a/crypto/rsa-pkcs1pad.c b/crypto/rsa-pkcs1pad.c index 30b0193b7352a..6fa207732fcbe 100644 --- a/crypto/rsa-pkcs1pad.c +++ b/crypto/rsa-pkcs1pad.c @@ -9,38 +9,6 @@ #include #include -typedef int (*rsa_akcipher_complete_cb)(struct akcipher_request *, int); -static void rsapad_akcipher_req_complete(struct crypto_async_request *child_async_req, - int err, rsa_akcipher_complete_cb cb) -{ - struct akcipher_request *req = child_async_req->data; - struct crypto_async_request async_req; - - if (err == -EINPROGRESS) - return; - - async_req.data = req->base.data; - async_req.tfm = crypto_akcipher_tfm(crypto_akcipher_reqtfm(req)); - async_req.flags = child_async_req->flags; - req->base.complete(&async_req, cb(req, err)); -} - -static void rsapad_akcipher_setup_child(struct akcipher_request *req, - struct scatterlist *src_sg, - struct scatterlist *dst_sg, - unsigned int src_len, - unsigned int dst_len, - crypto_completion_t cb) -{ - struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req); - struct rsapad_tfm_ctx *ctx = akcipher_tfm_ctx(tfm); - struct rsapad_akciper_req_ctx *req_ctx = akcipher_request_ctx(req); - - akcipher_request_set_tfm(&req_ctx->child_req, ctx->child); - akcipher_request_set_callback(&req_ctx->child_req, req->base.flags, cb, req); - akcipher_request_set_crypt(&req_ctx->child_req, src_sg, dst_sg, src_len, dst_len); -} - static int pkcs1pad_encrypt_sign_complete(struct akcipher_request *req, int err) { struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req); diff --git a/include/crypto/internal/rsa-common.h b/include/crypto/internal/rsa-common.h index a6f20cce610ab..4fa3cf5a989cc 100644 --- a/include/crypto/internal/rsa-common.h +++ b/include/crypto/internal/rsa-common.h @@ -34,6 +34,15 @@ struct rsapad_akciper_req_ctx { struct akcipher_request child_req; }; +typedef int (*rsa_akcipher_complete_cb)(struct akcipher_request *, int); +void rsapad_akcipher_req_complete(struct crypto_async_request *child_async_req, + int err, rsa_akcipher_complete_cb cb); +void rsapad_akcipher_setup_child(struct akcipher_request *req, + struct scatterlist *src_sg, + struct scatterlist *dst_sg, + unsigned int src_len, + unsigned int dst_len, + crypto_completion_t cb); int rsapad_set_pub_key(struct crypto_akcipher *tfm, const void *key, unsigned int keylen); int rsapad_set_priv_key(struct crypto_akcipher *tfm, const void *key, From patchwork Thu Apr 8 14:15:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Varad Gautam X-Patchwork-Id: 417575 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 56259C433B4 for ; Thu, 8 Apr 2021 14:17:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3336F61164 for ; Thu, 8 Apr 2021 14:17:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232036AbhDHORK (ORCPT ); Thu, 8 Apr 2021 10:17:10 -0400 Received: from de-smtp-delivery-102.mimecast.com ([194.104.109.102]:37918 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231987AbhDHORB (ORCPT ); Thu, 8 Apr 2021 10:17:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1617891409; 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=yN4wtR5jd/CKbP4TNdutXtmJHYMvPTYZO36/3uXm/FE=; b=d3IJuWY1q/QRuiBKmD/pxmY9VlHsKIHI+dQiKxHb7jEVXSM+4g0vuI5gt8jhReUhLxr3R3 RkOS49PG/u8c/BX5HF71rzKf4yXwcPAeMRJyZioG3F3BFZc8kH7CMLlggm7ZR5rlzsqM6m EZlFvAXUkMe8FGk6DArVUFkKjuzNifQ= Received: from EUR03-VE1-obe.outbound.protection.outlook.com (mail-ve1eur03lp2054.outbound.protection.outlook.com [104.47.9.54]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-1-PwsyEarLN_OkBlwcut1VBg-5; Thu, 08 Apr 2021 16:16:33 +0200 X-MC-Unique: PwsyEarLN_OkBlwcut1VBg-5 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=H1BNWP53fQEw5dcJt6rW4iZcYYv7oI7YdamxWIYFksoJ5HONIgX4KILsZ4FizkSsjxEes1v6zJg6HNnczv56oimpYZ7jTbjNy+Ft3nrMLQfpeT1aG8HtY8M99ExZQ/BJJ4XKdHYoE9fZ2YNDY2zvo4Md+6s55+fab6OYACHODShf8VKu1Izk4DBvouAGEQ0U8hG00JUazOXdVnoiBuIcCx/4GdxO6CqfVG0UdvfxNQjiUiDVOBvWrQtwWmWprhG0OIKX6n5Uidvyh1kEEl4xxSDmWW2ZWycIKL4AU2LZtFACpTqQ8RD66ld3reqkGAIBNlfFEheMvjNOgtv5biflHQ== 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=i8SkvN5sNCcLK7KC5Wzzfa3EoWG186cgQIpcgTHH+5w=; b=AUd6ezg1NJYfOV5K9jk7Fzg1LVAi38sAjCgOEPrK0vgKdvMzzFDO4c0HsIn7BxuqpYpkxKcXikiz4Jc322Ik1OpYFoa2pMEN1r19VAKsThuAhiqfOt9kk79hFZ+4P5N/seBiw9bTeBzlnVn8+5ouO0webAapZNZsAzPjIQRV54Hnv9Zq/RAXCJL/p4VmmFinH2OwSyN1tqVIDHh0NL0XdUn13UKliwb92Wm6mDp64PaW5lAqfY6ng9c6sgTT1eyP4Mw9d2jkE2/ql4HHodA7138Uhvf57oZvFQ2yln2fUnMmfiU31LLeRQxK+xNoQhFKNwANyejpbaITNv2T3ff6Ng== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=suse.com; Received: from AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) by AM0PR04MB6289.eurprd04.prod.outlook.com (2603:10a6:208:145::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.18; Thu, 8 Apr 2021 14:16:23 +0000 Received: from AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d]) by AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d%6]) with mapi id 15.20.3999.032; Thu, 8 Apr 2021 14:16:23 +0000 From: Varad Gautam To: linux-crypto@vger.kernel.org CC: varad.gautam@suse.com, dhowells@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, vt@altlinux.org, tianjia.zhang@linux.alibaba.com, keyrings@vger.kernel.org, linux-kernel@vger.kernel.org, jarkko@kernel.org Subject: [PATCH v2 09/18] crypto: Extend akcipher API to pass signature parameters Date: Thu, 8 Apr 2021 16:15:07 +0200 Message-ID: <20210408141516.11369-10-varad.gautam@suse.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210408141516.11369-1-varad.gautam@suse.com> References: <20210408141516.11369-1-varad.gautam@suse.com> X-Originating-IP: [95.90.93.216] X-ClientProxiedBy: ZR0P278CA0137.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:40::16) To AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from xps13.suse.cz (95.90.93.216) by ZR0P278CA0137.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:40::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16 via Frontend Transport; Thu, 8 Apr 2021 14:16:20 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6625fefa-0cf7-4f10-070f-08d8fa98e223 X-MS-TrafficTypeDiagnostic: AM0PR04MB6289: 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: lvqTKoLG3BzX0WNJCNUhU2ZI+WENaCD4khtEGlQmLmjfsLXtNxjhCIR/LEl27EIAEIVxRrWUgTxDmwsL2PWbxobfHdbijI+rIe7WCSUrQAPOMrGVW3EGEadZIU96NPPx+ebz7kj22spvSMKkYsfXytMJzxpoQgPAhS1PNbddMPRBTPJXxBsE/3pKn9Gs1k51uw+9/09Mtze9WhMr40G4neE3STm6U9cU2Kd3RyQ5Z832Qyr9qMWPhY3kYz4sh8ULI+lZQ1CgsmHxuL4frcdj7OaEQR6GHyrkrW92xGRDDB2V4n+tGn0g39EPykp/uQbduTRGcHiyafgArRTzXjT7lOP85f3pflXUNXY41sxbyaRkH20FYDeL644nyjlY0w9aZd5dELZ3QVXSqHV48LH3JH/2Yn2bI7y5N/wlCFmLvyWFO5AluaSHKwdiCgtqKI8j5qZPfec4C4NStTjuYbsvKinYHWgbkPcGMaTqFz2OdcSQDUyoMqAbBL9kpnzJNxzUy+HsA9y4yXOOeSZBNsKHkLKbY7vtIMRKioi5k2lKwHE5YT2XJWMwNHLzlKY2gS7cXdt0rubTycUDvNiytAEOQ02+JO7B8WX1Ray9l0tEBs74RSzdkhTmNVQvPkIHCHjQZARBhw6ejtM2/5F7Pm36hDLG/zzU+eA+ZeGtJH0vLvFQQ0QQBDJ05TZ3jFH1hneg X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR04MB5650.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(396003)(346002)(376002)(136003)(39860400002)(186003)(83380400001)(16526019)(478600001)(6486002)(38100700001)(36756003)(5660300002)(4326008)(6916009)(1076003)(66476007)(316002)(2906002)(66556008)(26005)(38350700001)(2616005)(6666004)(956004)(8676002)(44832011)(8936002)(6506007)(86362001)(52116002)(66946007)(6512007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: L9dZG+J/fuP+3kksHz6J4aSrWOHxTdl5z2IIrAL0h2FKkxPTCxbPjp+C+m8i15BGYXbondubPvrGLL3qPn5uQooHqrtA6GiAqSvDACmQi5ZKSHMbaZ2ntsCh4V7BWVeNwIZn/ZkkztAdzXJ2YrzXBLgqaws4Bfsx/hhg8nT+uEV00y+yFOHDf+fW6LGbjxb8Z6CMofCeKpsDLgbiKgXuegxy1gAZp+r5RI4c1NHk60WJO3EjXY3wZmfUjo5mcx+LrXjA+3YhHeepMM1rVUvAr3chPREbaupYWomIphDRYPZHCWDr/+ElbGmHQGvij0Vsx201HYQV+9cgPluLJq5ItIz3hdMPw37F/CZraI/Z+aLiWFmlVW7fg45rLvHPr9+fM2Vg96EFAYXUdZDMCFQZ0TmoV9jTxyLt1eVo1YYofHaQriNNneUMyYw9f79uHKlhhfJEvTCO+I8ja/ZUbE13zWP8dybBEpPcGuSvHOXqc1hx3l4/pwecd8tl2OWmeAQt9DPaATg9zZi4XXvLl36RGpBZmBQzIGZo7WKn0QU5u5XYevEcGljSrjDUuR2SgALEQJ8jrATKnOTp2f3vkUxNGM9EoEneV7RoJOR/d+VZxw+Mf3l8lXp5vqVPKtUvA+e95wc+OU1WoukKJ5ylHzYdT3fEslP898lwdsJQB49ghgA8lCWnDYbFdl9Foz1v0mZ6caEkNQOypGUgk+UAUj9e4sbMVXlQoIexnrK6qYAVlWBhrO4bAWo8Wd2VeXFtx3NvW6GwoZBo4Y9QGvatNMI49w1qUWz6y03kRIq5DKexnVnXMvvpebKTCAEHmlFu2mf1Zv6Fi4rgXUoPe7DqVSC9AHO73qfbPPlGBXR4MPD0+wgc7qHmdThC++oa6m+UfKhjf1mtpC4piRjUQO4XTNLHu9X4ylGv8XMsyALxBME2yuMrD9U1wBiOFqnmu12ZGZLag7zfOz1o9NnOZf3X472jz3aNikcmPcrm0G2fOuOhrRvY5akspiC6ux+bss9M+6jSgqxodrOVa5Qvbci5Y73EMrHanE2W4yB2cn6/ttBn1dN/cOXrKbKnSxVBg51dItyu16eLOFDebd7dl+DedilG/vQXNB54AebgMzQwK0gRPWupUIvm6R9t3tr52MmGrKBucnpXbCP2ZyK9z0ZPrHFhvGbzlAiWYEcCgElv9dR3/QU2fXV2GomaBLK9bSmzuhWWKqZZpFP08RhrjpAP9bUS5XwPTvT3zU5tb3qTUW0r/3tYhRxrTL/P3inyK7PDpOY59mAyi9fhbXW6mbuEoDltaxPmtmfq2RWzxwc8PddqoWlIi/pnG/PJ+UML25fSWiez X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6625fefa-0cf7-4f10-070f-08d8fa98e223 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5650.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Apr 2021 14:16:22.0238 (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: kcB8x4LJF2MVKAxUpSTtgy4sEhv+vEJ925+tGDKL/vGExQQqgtS80G+eLX/p4yEbzQeTyj5hJLD9r2V7hJhXKQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB6289 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 6ed258a782875..f80cdfcc1f9ee 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 1d3aa252cabaf..a0e8720294293 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 Thu Apr 8 14:15:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Varad Gautam X-Patchwork-Id: 418313 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=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 3598DC43461 for ; Thu, 8 Apr 2021 14:17:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0FB6861166 for ; Thu, 8 Apr 2021 14:17:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232046AbhDHORQ (ORCPT ); Thu, 8 Apr 2021 10:17:16 -0400 Received: from de-smtp-delivery-102.mimecast.com ([194.104.109.102]:42395 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232020AbhDHORE (ORCPT ); Thu, 8 Apr 2021 10:17:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1617891412; 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=GNjWFjXDejG3E3NOFeXgEdrLskVD3XbvsnvqDZWR808=; b=g4UDDcP2ukwnlYhwsUKrGcP9yi8KFgnA80ksf6Ih0E8lwSGP2mAKhKNhapAO2SC+Lmykv+ vRbFekr46+1BNEY18CV2Uh4NJtHjG4fwt7HMgoCwqat0a9pw87MwZou5CPmbBo44yTtlJK LQVnEHxdHyMT/DR4AmVB2gPyjtiUebg= Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05lp2111.outbound.protection.outlook.com [104.47.17.111]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-17-tzzGxpx3PxiplTRQhzGM0w-1; Thu, 08 Apr 2021 16:16:41 +0200 X-MC-Unique: tzzGxpx3PxiplTRQhzGM0w-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=k4eRUcO0eZYlL09iU6KtToXdJ4ZY0+nEjBNx1Bvx6wSH8LzrOFd1I1VpZKwjPT9tBWFmkB8S8ULYjIkUApm9gTA4AokGAm4aHCyK93fdo2jKMn7yYKdDzTU8e0Yqh/GMCdteU/JmLrnvxzlB1v7G+6kP9rSxL0T2ncUALPWCwlug8OSNLO34hZ/mV3+ilPCW1cKN6V3m6gddRlnXkzENVE5zVAMe5CGhLmTKyH+XT4RfqImVpqBuz3KgOKvHK1wHqMdYZVlMGxxAdGHgmkFuATxzYjESXhOU/mNGUX9CxQBTwagtlOAD19RlUvvoof1+XzMht3RXa2L+hwuNAI1mZQ== 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=1F0kTH773gbCKICjeT11lBBAalcITmZBWtl2W9LJ9fA=; b=HWdk5RFZM0hUCtWCyj0JvLNbPbjVgF6E+CH5r8orBt/SIwtjMK9fsRanGN/AD1UOFhi9aOCkIMWzyTgyQ5UZzJ9/3scvrv1kcrFayHzP8+PXvIV7tBv6PfRbK4Zrt1fd6+eAFfmbtrf+SmCYY+gKdTXHb1B0bUh4DJzDPkSAs0wEZngj/IBCG9hiLUQ4TxQR50GpjGwP8BxAHjEcwiBZqVLM0Jq3Cd78mAuBDp2D7trv0cQAJZU0tKLXlfPb9hvxAPmYvyZ4fKdAHM36+b8Op8Vcm9TZGocdB/CgnaEpV/C67dOGwunGCWKd19tYk1ORX9A4bEv/Vs8N2YbinqHV0w== 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 AM0PR0402MB3572.eurprd04.prod.outlook.com (2603:10a6:208:22::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.29; Thu, 8 Apr 2021 14:16:39 +0000 Received: from AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d]) by AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d%6]) with mapi id 15.20.3999.032; Thu, 8 Apr 2021 14:16:38 +0000 From: Varad Gautam To: linux-crypto@vger.kernel.org CC: varad.gautam@suse.com, dhowells@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, vt@altlinux.org, tianjia.zhang@linux.alibaba.com, keyrings@vger.kernel.org, linux-kernel@vger.kernel.org, jarkko@kernel.org Subject: [PATCH v2 10/18] crypto: rsa: Move struct rsa_mpi_key definition to rsa.h Date: Thu, 8 Apr 2021 16:15:08 +0200 Message-ID: <20210408141516.11369-11-varad.gautam@suse.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210408141516.11369-1-varad.gautam@suse.com> References: <20210408141516.11369-1-varad.gautam@suse.com> X-Originating-IP: [95.90.93.216] X-ClientProxiedBy: ZR0P278CA0137.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:40::16) To AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from xps13.suse.cz (95.90.93.216) by ZR0P278CA0137.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:40::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16 via Frontend Transport; Thu, 8 Apr 2021 14:16:24 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b188372c-d210-49f0-409b-08d8fa98e4c3 X-MS-TrafficTypeDiagnostic: AM0PR0402MB3572: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4714; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OlBx+Wc6ab3amZM6/UjZu/ku1nclB3CuRlGg73UbFPiJMnd0jHAJZs5A4vnLxFFVM4P2TmcbkP3nWq8HN9d0qkQUIBRHBTNNmrfY73wV89vhfvQqFIMey0KYhda+mafShP/5qT1JePMBzZtIlDzNTG/8R8RkXtv0kyIGxTrdzCOX72EpyQYbcPQSkrpa+0X+eTMKLDESirFlEoA6v4g/j6537XEVLj4OCrdMhmgRDFGIdwdzaRZZJFWEx1tCmWyxiPEXVrfmcnh+XOpwC1t29eiGBY7IpD4kutqHm0InjeuTcuGSj6VItMGlXXQC/9GHSH09/umfqqRIJ6sti1iYBW+uEIZJ096+wsrMVlxART2TdBitIvfrGBgKBKXrGAz6IxsQ372vDpDE3FSiSxMlNLs0vhxxRjAJLaq1yYg5iaC4puzP9tvILZ+TgShEoR7Hf7PAxYbpSJPuQ8xD5Ew59U0MfVb4SSKg/y/+XO4gkPCISET99hg/RfP5pPMGAjqgedQNidnEsfqS9uk+5gowrGL2GszdFLDanV/3K/uhXHwPIQ+Bj6eSM6BSy2jF/FayDkF5KzkZsmODTN0XWy7LxNUhbumxf+jm7YL4ZGyaUR0udEMwJ9nESYCDp/ltNcvnoJp3Kfvr551T4otnKi8XUk+y66ib3ZMHh1Zky19n0jXZ1OtvETFtPGhevsz9Qmkp 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:(39860400002)(136003)(396003)(376002)(346002)(366004)(16526019)(186003)(38100700001)(2616005)(956004)(38350700001)(52116002)(6512007)(2906002)(36756003)(44832011)(6916009)(83380400001)(6666004)(8936002)(26005)(66476007)(66556008)(66946007)(4326008)(316002)(1076003)(6506007)(6486002)(478600001)(5660300002)(86362001)(8676002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: DvZaCPiSTkPaEKq3kyJp4YL3PJZB9xvjIh1eYvdzmbkVXSBRhKkC7yzKJ/GUY+40ZfPpmKoauAjGAT5/ZjnSqbl0HVpPit/syO/nbO+1twWbl+JaouR2UtunwxhXJ+qty62uLyS3pkrKAw8E3WuKIkoJg3hSKUJHU+ploJbYP82laqhTaN/jvB7gRTR9qsrOzzeuLVl05O12cqOdc8ByE26kw8wHsDT7iAmxPsIaEyj/1OtBiclNicEwBq6faGOCqi0Pq2GP7041XUbUUl8NGc3xf8Xf/nt8shnykA7VdouVPQnGIcf0KrsbAH8E+lqL/e8/0WO3sVXbyRVntI0pIFz1wluCp1zFKS+8mm4LcKCoBCmEsXaPq5bJpcYPEKNx/5wmdQtrzhPgV0r+fp23fOZ1wWKZn2KIowFSM/RUFKM4jrpuP/VFQwESudUGZgh4lDdhYW4BPTFHzKo0Ngy2rGkmr8Hfty3qg8D3qDevkKa3f+1iRSxLAccD2kz233qVp439XaSkQSfNLcdzdjO8NpA/STHA/Bkhi19uZppwmXB2quPY9LDgvFi3oS78wIg3W7lE9XRnNiSFFtjWoZ/Ecci85TaSsRFxMvh6AM8PbdCSSLtqAd8SzCGtFikU4mocwJnNfDVXDsxUSDmtjG/HaRWdCTeNquKTiCdykRU59qBDsiciPIA/ocbEHtseFv0IYO2d/OYtOv9F7hhd8fkDmtClY3Ifq0VjPzADtWbYFoI0Aku19baQ7UdMVZAJ4s73n7uZpssjHLk3TllDzCR4/j+tSZdI8TGlLltnd6M2j+R3e0mTedlA3LxhIpF1f/5+a0IGbftY9GalF7D/zkz4QQ34CclSsyTVU0+g94v26BOPzCa4PudD9ewChCMD7mm2tCdJOWqHMSkuKk7SKnYTeDOaZT2/OWrq05zZZJUWSzR/QM7X1bg3ZMxwpG4Znr6v5otPpCjX6K8fGy7eRMu1pFv3gHJ17XGIntIa7QSmdX2vEMhIZ26qgCzFrNMDsCZZOVfYIR3yNGIG/0gjau71B60Dm11hLCS4j39pDYxRrqhZocHOnQDsqVs73+diPEsNSV7o9Zwtn2QymZ1/f73BmEgvy4Ns6IzkRu/JBqDqFvCibyI/oGWvG07NDn4Z/0b7ivtEqxtghqsBRzrfqwrfeKFOrUkfj4wsvVZ5JUnS7/MURSsS/Qy9tr5ZL24/L8PLErwomBVnHdXHfStxkge1h9lhqDX775cIk+60xKsBDIq42F6n8qevHQq/cLc9pD15ikx2ysmWkrT4wZp15jzdS7NxupYTN/MVkqhl1Dxk26A5sO9o+jG1S0hKlUUrLE1i X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: b188372c-d210-49f0-409b-08d8fa98e4c3 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5650.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Apr 2021 14:16:35.9998 (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: loys/0cRTDZ3gzOhEFXaWVi7IAWymzdnypOG445DyD63wVwBhqIaCrjSUdZt8TeOkoR0SqoF3sIStCteYon64A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR0402MB3572 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The RSASSA-PSS signature scheme requires knowing the RSA modulus size in bits. The rsa akcipher_alg max_size call is insufficient for this, as the returned keysize is rounded up to the next byte. Since the RSA modulus is stored as an MPI accessible via struct rsa_mpi_key, move the struct definition to rsa.h to help RSA sub-implementations query the MPI values. Signed-off-by: Varad Gautam --- crypto/rsa.c | 6 ------ include/crypto/internal/rsa.h | 7 +++++++ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/crypto/rsa.c b/crypto/rsa.c index 4cdbec95d0779..5c4eece5b8028 100644 --- a/crypto/rsa.c +++ b/crypto/rsa.c @@ -12,12 +12,6 @@ #include #include -struct rsa_mpi_key { - MPI n; - MPI e; - MPI d; -}; - /* * RSAEP function [RFC3447 sec 5.1.1] * c = m^e mod n; diff --git a/include/crypto/internal/rsa.h b/include/crypto/internal/rsa.h index e870133f4b775..e73c61f788e68 100644 --- a/include/crypto/internal/rsa.h +++ b/include/crypto/internal/rsa.h @@ -7,6 +7,7 @@ */ #ifndef _RSA_HELPER_ #define _RSA_HELPER_ +#include #include /** @@ -53,5 +54,11 @@ int rsa_parse_pub_key(struct rsa_key *rsa_key, const void *key, int rsa_parse_priv_key(struct rsa_key *rsa_key, const void *key, unsigned int key_len); +struct rsa_mpi_key { + MPI n; + MPI e; + MPI d; +}; + extern struct crypto_template rsa_pkcs1pad_tmpl; #endif From patchwork Thu Apr 8 14:15:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Varad Gautam X-Patchwork-Id: 417574 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 E4AB7C433B4 for ; Thu, 8 Apr 2021 14:17:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BFED76113D for ; Thu, 8 Apr 2021 14:17:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231968AbhDHORh (ORCPT ); Thu, 8 Apr 2021 10:17:37 -0400 Received: from de-smtp-delivery-102.mimecast.com ([194.104.109.102]:30131 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232006AbhDHORQ (ORCPT ); Thu, 8 Apr 2021 10:17:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1617891423; 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=9Igtuzm/ok+NRbcSZq13s9pDJLANSUiOqCGZ0QY7cno=; b=NvLktv+I+77N4mbEO3WlHFVmusDwOtPcadB+Qos4IHLhy5BHbH03862k1f5T4BtHf0jNDl Njp5MX29+Xy/mbC8pT4zor7cBYUqsUGCrdiKWalhy8K6PWnPSL9K9W9urru44werL9Whfa giQph+rnQoxP1ABrbV5hb3ButvPhxT4= Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05lp2111.outbound.protection.outlook.com [104.47.17.111]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-17-FODe4QFwOwS8KoFUGSkj7w-2; Thu, 08 Apr 2021 16:16:52 +0200 X-MC-Unique: FODe4QFwOwS8KoFUGSkj7w-2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=naUxeLsiv/2i/KlcmuXlumdaBOs5ZW7S9KTBJ0+YzTqzFR4oWNcfVHPQu4ZV+9PyZNTokqoZ/dSLuAAeVUzojSvA4yD/g5OgcSL5k0rTvED94ThKHKV1Ug7+UeTKBE3CY2RVnJgAYf1m1YsFpO/VkhGbF1DQD+vpDW1X04rCwYcFtgCx3wgdheWaqKQK6INdVSVumOpcptlCwc4RvEuTdqx0TqTALLTgHOLzYDSOB4GjRT4mpwgukrFCNpXbHW20QTxCKttuyYp8Mk6vwXW78a0GgW+43TrskrKnT45gfUJ3XqMxyTdX/Ia2c+yNwV00VNq1FYl6vorJEktG4N7AEA== 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=e7DWld0uBXexXyntNHnpn8e2x15y1B2pMLwJzTav2Lw=; b=aiYgRDGO/a7HvOW9fVnIulVOJpiYqwc8qV1mPZRh6mFWvuBb6M+UaUNxlGEu65OuVD1Mwxm4x6khJEdtBxicYKScK2uKcIVua6YVRXg/8P/NE792QgGhFYPjhqxRsueq7/4D31If9/AP31FDjC1S3i0rH5arRH/sSpDpRv3vr8dtM5E3YWgWTgSpfeihpPETr5JglDHO9Sr89YuCZC31jLvDokolp1/XHq0a5A+1BATYu+Q4JCnK9hQmGp76YnReSSaWMs+PF9Nc4DQ9ik/z4DCGRWEXY4LepUvzVw2F/TC7cHt7FzcSNE/GVjOFQ1OLRKny9r52EKWILYWi1dDqWw== 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 AM0PR0402MB3572.eurprd04.prod.outlook.com (2603:10a6:208:22::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.29; Thu, 8 Apr 2021 14:16:42 +0000 Received: from AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d]) by AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d%6]) with mapi id 15.20.3999.032; Thu, 8 Apr 2021 14:16:42 +0000 From: Varad Gautam To: linux-crypto@vger.kernel.org CC: varad.gautam@suse.com, dhowells@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, vt@altlinux.org, tianjia.zhang@linux.alibaba.com, keyrings@vger.kernel.org, linux-kernel@vger.kernel.org, jarkko@kernel.org Subject: [PATCH v2 11/18] crypto: Scaffolding for RSA-PSS signature style Date: Thu, 8 Apr 2021 16:15:09 +0200 Message-ID: <20210408141516.11369-12-varad.gautam@suse.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210408141516.11369-1-varad.gautam@suse.com> References: <20210408141516.11369-1-varad.gautam@suse.com> X-Originating-IP: [95.90.93.216] X-ClientProxiedBy: ZR0P278CA0137.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:40::16) To AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from xps13.suse.cz (95.90.93.216) by ZR0P278CA0137.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:40::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16 via Frontend Transport; Thu, 8 Apr 2021 14:16:41 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8c3a7e99-e990-448e-2ee9-08d8fa98eecf X-MS-TrafficTypeDiagnostic: AM0PR0402MB3572: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:747; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zNTqufgO9RPVcc3WGkTL/EbzQslqML2QxocVZoljn2PAI3MVtio+ztM7pXMumuwaxOGy+lRh6kUQN1/Rjdjgg32hRC5++25+GnAmEUls39S0RznAKKwMm0As1MIH0u0sd8V/epMG9UNtClB3czkrksdvSkmF0ucJKSn17uia6VPgOyBgTNWoRKC4yWR9HqzQAaf0VBXpnovjrbYQcCbscqcmFTuzbouKWkCpvcw071Mo6ZQuDJTzf1R7uDLBTEk8c4d2wtebFLEIupGy/tXzZ+OBtPwM4WSFUAROZag1BOuOMRs9eysVjhhwlaHu6KKrTSTlawRU3a+YRlJ4MmHVUObqvHylaMi9d2fKJc6trH3Z0EbutczB7er4xPt+4nxMBoR/Cu3LhIBxAvfjz7W0I00xpnViSj9QZylJnDB+J3f5xkF9MeUYoy4X2dA0vV+DE3xtJiroSYPEpQsu46ccBYmx/ODkAL4GyCpjzLQdpy9E+C2B79OwxbICt6ZzTl3MfJxzHJRJKQEqZnv01YfEIkbvgBSdikhiEaTnuIaIgM9Q/dtPaMhRmpNysJqKvOE5cXOiSj+sJEo+r6rIeD/9+cVU18T2pHRmUVN1pW23iGJyyGdYpZ0HzL7CkzohgO+jYDwLMW3KBEJnyJZ+jv3SJZS7IygcZtZJvddzZF1bPBLHQR7tSOtJmzpwvA6h7lGm 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:(39860400002)(136003)(396003)(376002)(346002)(366004)(16526019)(186003)(38100700001)(2616005)(956004)(38350700001)(52116002)(6512007)(2906002)(36756003)(44832011)(6916009)(83380400001)(6666004)(8936002)(26005)(66476007)(66556008)(66946007)(4326008)(316002)(1076003)(6506007)(6486002)(478600001)(5660300002)(86362001)(8676002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: qvxPb/lpbvZdmGd6ljo0jwSA856MTvTrD8I4SoxeANBARPr72kMUvk1bZG9wk91VDkml5cdetlzPbbuaSFCMVIxcdze7n/9rNbNkHxxteak3w1ySbPr8tJhK9yWDpaJP/DcVO3kJVhflcJOvg0Ii7/ltOtY5ozRwoRN7xy44uRSlrquyE3W3QF45WCO3/BYUOZZFmYxjAS15DmNYw40UvGvo0dzUlmZMDyjMEDLzlgdaBgl9WKq4rFqNYRxYnB4mG5T3WIdIsPqAkKPLWlX0fDKwh+BkZJ9v23lVTMzzl6M3Nb4piJpPUEMTfJ1xK2dXLfZzCQ8B/49Teyp+f4xsYJ/vgv0IbcIkURTY5WTbmAH/AZke2jLiZ0HuqViCzehzAIVx6FU/DIuOls8PSB4tPlByICBAPPSwaVda3wAUZWacv+xf2Gl/2ZtLZLzEi3m1CBOn9ibPj+402osqEH2+BHCGSjvuI/cqjuDWDrhhW3D1S/eGJcLoh+Hr9lD5GDUXUJ4fVgqYpfGztyewZ1oyyD7gGzSRmZJo3HzouQ5lDqfyUu1Z/nRt/l/IXW1T+LxzUxhlZ84pMKUNFo6HCsCCVCv0V63j3GvHwbwH61Mp4GwsPUUCHsfFD+noJyQ6iygm2mwbSqsyHujDLx5PootHsdR7KwOHJfeskVQQBoFXQyys1V03PEm8wOfQfXQkRvBghmMByWZzgG8A+wu4n8P+KehlUesBT30udUZrW2Aedu3tbaVu9Xz674oQD+V1k2UQyHWCuLbNin7PQ5WgDJy9q3JDCPYlECfegeJItvXsGgKSu//1doGXvtkb7JYK6JjNW04xRtAmgfLk4lIb7jsQWnU54LE5D7rc/X15XyZuM2gwb18yoTu1A6LsFZrU4P3gcYmfBIzcyHg21hnIxy23Mw0eNXJg2LhTdDq68n7+zJh0gLdAAOPQjRWsbxj9lwUfA0QBdcgjg9oCVoSrTWC4uhYFYAaz9o5vJQA0Powk/BOQDc3zNm8nGTkKTr6GI1d1Ehe4D68o2to5wgqoALVH1lFarGMJkk8BMSgfKuW5cJeWbXu1Qs8KAOxxFslBIC8WvQwBo5FEOv2iO0cvp6ZkbUhULR4/CV6296kSEf1tylGdK6L3Gj8aeYbJcPmeWFdt1PCuahHxdqMwfYwMaDz0ltcYaX6XohTTG6TJ6vkpN9RzQdXfEfrfKzjJ9IqEScJyHEROk4uLeFeK9DhXtcgydfLC+l390lB8nLt0glg2altPNPu6wreULOgIh9sX20cgRDSi7OqvD42E6NIEqp7f9hDl8hgkHQ5TIBc/lcS0nm/5crR5Py4S4yrEdSGwfD65 X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8c3a7e99-e990-448e-2ee9-08d8fa98eecf X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5650.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Apr 2021 14:16:42.3262 (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: o+4seCmMFSyGrribJXIsFvPlUNB3A2czg8zw9/m0WGyWo936SRYa4RP7+8Z0X8oIQAEKell0XQF2Yt4z9NEXZQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR0402MB3572 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Add a crypto_template for rsa-psspad, hidden behind CONFIG_CRYPTO_RSASSA_PSS. Set the sign/verify/encrypt/decrypt operations to return -EOPNOTSUPP, to be implemented in the future Signed-off-by: Varad Gautam --- crypto/Kconfig | 6 ++++++ crypto/Makefile | 1 + crypto/rsa-psspad.c | 39 +++++++++++++++++++++++++++++++++++ crypto/rsa.c | 20 +++++++++++++++--- include/crypto/internal/rsa.h | 3 +++ 5 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 crypto/rsa-psspad.c diff --git a/crypto/Kconfig b/crypto/Kconfig index 5809cc198fa7c..3aedb40aa08f1 100644 --- a/crypto/Kconfig +++ b/crypto/Kconfig @@ -224,6 +224,12 @@ config CRYPTO_RSA help Generic implementation of the RSA public key algorithm. +config CRYPTO_RSASSA_PSS + bool "RSASSA-PSS algorithm" + select CRYPTO_RSA + help + RSASSA-PSS signature verification scheme. + config CRYPTO_DH tristate "Diffie-Hellman algorithm" select CRYPTO_KPP diff --git a/crypto/Makefile b/crypto/Makefile index 57a85b2b3429b..88be24b9bcb24 100644 --- a/crypto/Makefile +++ b/crypto/Makefile @@ -42,6 +42,7 @@ 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 +obj-$(CONFIG_CRYPTO_RSASSA_PSS) += rsa-psspad.o $(obj)/sm2signature.asn1.o: $(obj)/sm2signature.asn1.c $(obj)/sm2signature.asn1.h $(obj)/sm2.o: $(obj)/sm2signature.asn1.h diff --git a/crypto/rsa-psspad.c b/crypto/rsa-psspad.c new file mode 100644 index 0000000000000..0e5422b05c081 --- /dev/null +++ b/crypto/rsa-psspad.c @@ -0,0 +1,39 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * RSASSA-PSS signature scheme. + * + * Copyright (C) 2021, SUSE + * Authors: Varad Gautam + */ + +#include +#include + +static int psspad_s_v_e_d(struct akcipher_request *req) +{ + return -EOPNOTSUPP; +} + +static struct akcipher_alg psspad_alg = { + .init = rsapad_akcipher_init_tfm, + .exit = rsapad_akcipher_exit_tfm, + + .encrypt = psspad_s_v_e_d, + .decrypt = psspad_s_v_e_d, + .sign = psspad_s_v_e_d, + .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 +}; + +static int psspad_create(struct crypto_template *tmpl, struct rtattr **tb) +{ + return rsapad_akcipher_create(tmpl, tb, &psspad_alg); +} + +struct crypto_template rsa_psspad_tmpl = { + .name = "psspad", + .create = psspad_create, + .module = THIS_MODULE, +}; diff --git a/crypto/rsa.c b/crypto/rsa.c index 5c4eece5b8028..de4ad34f9cd95 100644 --- a/crypto/rsa.c +++ b/crypto/rsa.c @@ -258,17 +258,31 @@ static int rsa_init(void) return err; err = crypto_register_template(&rsa_pkcs1pad_tmpl); + if (err) + goto out_err; + +#ifdef CONFIG_CRYPTO_RSASSA_PSS + err = crypto_register_template(&rsa_psspad_tmpl); if (err) { - crypto_unregister_akcipher(&rsa); - return err; + crypto_unregister_template(&rsa_pkcs1pad_tmpl); + goto out_err; } +#endif - return 0; + goto out; + +out_err: + crypto_unregister_akcipher(&rsa); +out: + return err; } static void rsa_exit(void) { crypto_unregister_template(&rsa_pkcs1pad_tmpl); +#ifdef CONFIG_CRYPTO_RSASSA_PSS + crypto_unregister_template(&rsa_psspad_tmpl); +#endif crypto_unregister_akcipher(&rsa); } diff --git a/include/crypto/internal/rsa.h b/include/crypto/internal/rsa.h index e73c61f788e68..4c168ea2f050a 100644 --- a/include/crypto/internal/rsa.h +++ b/include/crypto/internal/rsa.h @@ -61,4 +61,7 @@ struct rsa_mpi_key { }; extern struct crypto_template rsa_pkcs1pad_tmpl; +#ifdef CONFIG_CRYPTO_RSASSA_PSS +extern struct crypto_template rsa_psspad_tmpl; +#endif /* CONFIG_CRYPTO_RSASSA_PSS */ #endif From patchwork Thu Apr 8 14:15:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Varad Gautam X-Patchwork-Id: 417573 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=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 7AB73C433ED for ; Thu, 8 Apr 2021 14:17:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 452C66113E for ; Thu, 8 Apr 2021 14:17:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231937AbhDHOR6 (ORCPT ); Thu, 8 Apr 2021 10:17:58 -0400 Received: from de-smtp-delivery-102.mimecast.com ([194.104.109.102]:59084 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232008AbhDHORV (ORCPT ); Thu, 8 Apr 2021 10:17:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1617891429; 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=///ASwrCwSoyQk6TntxWUaPjldH2ujSwh3Qa/ku6+rk=; b=O/v8kxtOZDYfcQGwFZm05ikfek//dIomhGrov/Ca69owWM9kXLCubR3LsoZWXgfThLFL7n yM0z5SPEkrM9zIxJqPvr3/DsyA6yUBAKEVi55C6pJ8SmfQabLB2A/kKCKB2NZVD5OSWxKJ Om6/MKeQT4aZhR2nNIC+U8YyDSwn/VY= Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05lp2105.outbound.protection.outlook.com [104.47.17.105]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-5-SvHOEj-INEKeOoVWjtp8Fw-1; Thu, 08 Apr 2021 16:16:58 +0200 X-MC-Unique: SvHOEj-INEKeOoVWjtp8Fw-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=E3QQEMTu2Xf7xVZtCq3N4+R4u9J11ACP9pAC2RCzJ9Lg7rodkP6Efu/yKa7/8pq2KkLyjUDOFuMUMHvxvagCLc4X/QTHKtB4Fic8/3g23rc9WeXfKIasC6HfVSoTXnEcaV+nivkiy2c8gx9gVcTfstvDDYRyabLQtL7TKHiBCbiVoZaOGsoPu0Y4h+8nzf38Q+I5f1PBWxkh+sIJmYb7ykj/DWYOK1xI61SLl0wxvv+dQpYDiU2/LubcniBcPUy4/DNLV5bftkPyd+SDsAHGhoZY9g2CXQPi1+ukCSvH9wnrbqJ6Vfyuug2+M5mdDut1nbTsNl2iofrRd3LSURlEdw== 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=PNB1YDHlns+BxNLIqTflqWFz5pX3SsgTctL5ouUKofk=; b=QfncvG2zIgYhrL1+EjR342e7Wa4fQuRmNbZ7Za2bi9X9TGCUlsUOimGOx5p9Rl0cdmik+A95FsgAsJ5348maVDhgUyXgtXb8ybbajyTnipi3VHgsOo1YuZWOkUR9WKUSaANqDqheBR/q66aQc9AjcTOTCCUEhriWS/1nYppIyr3Swv8GHp1zEN6TFBxOVJp94GJMECqKBDJXSUd5SfY/ljdBRB4TcVAgjM6BA69D20i7gZRGPAXlspuuSQ2xlJnfUVwQbzsQZORygjhU8qkd+QRlEAEAlPaBDGB7EpcMc0KkbJVrK33STSIGBPAglLEe2u6UwPyiFvB9gIpTKvkuiw== 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 AM0PR0402MB3572.eurprd04.prod.outlook.com (2603:10a6:208:22::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.29; Thu, 8 Apr 2021 14:16:43 +0000 Received: from AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d]) by AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d%6]) with mapi id 15.20.3999.032; Thu, 8 Apr 2021 14:16:43 +0000 From: Varad Gautam To: linux-crypto@vger.kernel.org CC: varad.gautam@suse.com, dhowells@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, vt@altlinux.org, tianjia.zhang@linux.alibaba.com, keyrings@vger.kernel.org, linux-kernel@vger.kernel.org, jarkko@kernel.org Subject: [PATCH v2 12/18] crypto: rsa-psspad: Introduce shash alloc/dealloc helpers Date: Thu, 8 Apr 2021 16:15:10 +0200 Message-ID: <20210408141516.11369-13-varad.gautam@suse.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210408141516.11369-1-varad.gautam@suse.com> References: <20210408141516.11369-1-varad.gautam@suse.com> X-Originating-IP: [95.90.93.216] X-ClientProxiedBy: ZR0P278CA0137.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:40::16) To AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from xps13.suse.cz (95.90.93.216) by ZR0P278CA0137.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:40::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16 via Frontend Transport; Thu, 8 Apr 2021 14:16:42 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 69317702-6bd2-46a4-5309-08d8fa98ef76 X-MS-TrafficTypeDiagnostic: AM0PR0402MB3572: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1186; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Juf8W7aFcmPVe5qrvCwuzpbYpXzvPgmhMuj5e4qgREzEe0Mrijz0bhS0IKzmCR26/FncfnSiDkowyV+bDoLp6acuPyGrtkC0WQB5JEfXGTEPGiSP2Y6Qz4Lz1AMp/42RgVU1Q1Ll6F3H8BgsR5KUzBIEzluCjZhfIciWeQ/4/SxuWMrnXwhfNyQHhewd++dmkn7qQZO3/5OhYNY3eBC3jIYJaDSUp6nazC2obuC6FBVKPdJ73FixcLgwUg8LEmQn+QJwMkOvBX2HIppPG/kY1RwzsiOQfXxFO4bag+ZdgRwdTtMm3M24vrLdrLdlrws2IUSflivtnffvhGhC+gBti5oLyyd2N7bJMSm+bi0XNtcMBwPRvrkCla6t21t+zKs+xzW/2Gt2pgL4HBgK8NMK1uAX5xAZwtg1GQDzQmZpb/H+tsmKGNz3pLIr9DD9H8NwfT+pNNYjf42NJlqUtMjcrJt9X0/7u92eXwVV5jEeRcNSleKWX9Z5cjB9sL02wbQk86hGRSqb0QLrdeUs8isyuEFPpF1wB38UG3n3y8zwzFvhQRDC+2a7uYKtAm7bpNf1OySWFcuEy/2uRZoowBCPbVRoKt8wdfbie/6oNvPUm0Om+ejHtUOUDq0G1vxzkFgvStJKvFURzbRsDvXAeA9ipDMOEGDcbTCTyrNvdLVsTggSkbT3kT/brw0oTHdHZJyp 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:(39860400002)(136003)(396003)(376002)(346002)(366004)(16526019)(186003)(38100700001)(2616005)(956004)(38350700001)(52116002)(6512007)(2906002)(36756003)(44832011)(6916009)(83380400001)(6666004)(8936002)(26005)(66476007)(66556008)(66946007)(4326008)(316002)(1076003)(6506007)(6486002)(478600001)(5660300002)(86362001)(8676002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: MbZuw1DN+wkd7VkZTQterXK70D/51bTsDRp+ulvrjLClAEye/IkTjbRcwdccyZP1qAyoYFcFBmUMDpEtF0HjbQaq5dkzUvvR4v4XxyHEEgpNQrZJhAtK4+Ql4wpihgiIgWumbfYQ+18dvedirXy3ElvNbeQ6UqPky2c+xF81sHp7plN4z1ter2DnQFzI7kNyPNrhMRppxqO3/m4kSokFSl4MrBOEZOeSm4SoJl1QdLUkR1Z+qUwMhv6BD7IdI4e9gCyW3zGKRbcINk2BsXxspXJkG9aJrVINHhaC2r+2GfMkwB3fAcSFka5hAVU0yMEPb3EfcrB4oTHjGQhe4yrGL1G6QIjKSa9iR8A/Ft7uVegV5ImyVozBf8Wl2/rVl5yDtN/ihBDLL5yqO4OBUIJK0S88+87hAeSvEmVCPfBUOn9FtPwChBdDMLoCFvjfnZdSkL9dh30exmYO81OhdD2Ll7Nn26mZypZdWXi7ZAIdWk/HGJT6Gt4tACBQVcAqf7gaycGUX80hgXzjbHFR9P49e3lAx1fVgfw96wx2becFKyeUjKR7rAEZ4DtEzk5G4dH1rjpYezk5Zj8heqwgf109suu6TWCLNyN3K2IdV0uWYLv9nNnfc3TtUo3hdc6J5VoMe+62GLD/aQCfY1paEJ/dTjMnYlyjF79GJ5JJvTMgYn0TcIMVyCa2ZNxGSTW0TdnfDTL036FKDLilqIWHXjgLW/VC96jttrUn/+gsOo8GgeG6l+5KEJSwZzh4HBays2vHydrpJwZClXiVKGQu69pXtJTcpi1yRRM9zRL0ND9zMGGKJGXE1jVFhcDPebI4fQIkFRK7dkJt5ZpCEtARcvPW5oHOdibIOt+ldV+NVHNEqKuGETi6YoEs+i5nPBFxJkmPKxPquTa4l5CTNHB8uy7g0Z/ms6sAyQ7ptZc8ZTwKMGoIW2CsOo7LD3znF7tz03icME1KZBO4nLFBNuAkeYPskmxyrCGUjf6ux7arZd3hc1MGDFb8k/pwlX2hl9BLMN8KnNRlf3nZGzIESSLV24dkyu6zrpfN4RlnPkgaiyh4CHn5dUKmVmc+aX+DekHoWZnMWQDhSik8JWJKEoFmJxEyDAVNfKf0MWaJxGu+AjO0ML9ji2kfLc3kv9O3KimaLFPiVN6z9SH/0e4Ezcu7NfluWDeGDxe19GLZhRqFcE8nXyWJmrKWVmi3n7Y69oqzilSJuX5qnjwx+uwVwlQi3qTQXjADrn5hdDq4ewM/cDdq9oNdOdhH0ABM9GwNm8xwqcksez+6b+QqSKlsRw0l+uU3QCQqOytiXGa2B8et/RwhHf8IYehBcHPbEZjJ4Smc4i8e X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 69317702-6bd2-46a4-5309-08d8fa98ef76 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5650.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Apr 2021 14:16:43.4156 (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: 4BMnTyYjx4hVby9lVWIremJsE/LmyIDLizW6FJAJ1NzppfAD4bH9bEHDLqSV5505rFuF8mLqpMIct5lAaoSRAQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR0402MB3572 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org RSASSA-PSS verify operation needs to compute digests for its Mask Generation Function (MGF1), and for digest comparison. Add helpers to populate a crypto_shash and desc for use in both cases. Signed-off-by: Varad Gautam --- crypto/rsa-psspad.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/crypto/rsa-psspad.c b/crypto/rsa-psspad.c index 0e5422b05c081..855e82ca071a7 100644 --- a/crypto/rsa-psspad.c +++ b/crypto/rsa-psspad.c @@ -6,9 +6,33 @@ * Authors: Varad Gautam */ +#include #include #include +static int psspad_setup_shash(struct crypto_shash **hash_tfm, struct shash_desc **desc, + const char *hash_algo) +{ + *hash_tfm = crypto_alloc_shash(hash_algo, 0, 0); + if (IS_ERR(*hash_tfm)) + return PTR_ERR(*hash_tfm); + + *desc = kzalloc(crypto_shash_descsize(*hash_tfm) + sizeof(**desc), + GFP_KERNEL); + if (!desc) + return -ENOMEM; + + (*desc)->tfm = *hash_tfm; + + return 0; +} + +static void psspad_free_shash(struct crypto_shash *hash_tfm, struct shash_desc *desc) +{ + kfree(desc); + crypto_free_shash(hash_tfm); +} + static int psspad_s_v_e_d(struct akcipher_request *req) { return -EOPNOTSUPP; From patchwork Thu Apr 8 14:15:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Varad Gautam X-Patchwork-Id: 418311 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 A6FF5C433ED for ; Thu, 8 Apr 2021 14:17:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7EE7B6113E for ; Thu, 8 Apr 2021 14:17:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232081AbhDHOSD (ORCPT ); Thu, 8 Apr 2021 10:18:03 -0400 Received: from de-smtp-delivery-102.mimecast.com ([194.104.109.102]:38475 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232088AbhDHOR0 (ORCPT ); Thu, 8 Apr 2021 10:17:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1617891434; 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=izg8V+cMAU0CJTDlxfWbsq1f/plw234ZS+maxSMN81c=; b=X0S70+Hg8VWa2GWyjmraAr+F36Qm2nif+Tb3J4/7WO4O6icGtILCV4weQsYCKIIY72ctms OfOuHLr5wQQwriX90rhoiR31NdSaZ4ppzCQlE8vPB0KDtbwUmjGkuLp+rMD2/+m0wZCfzY OhFcnyCotBOstxofvxMB6Zg5ceLa4hQ= Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05lp2111.outbound.protection.outlook.com [104.47.17.111]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-17-54HrX2WrNKSsTDtXY3XT5w-3; Thu, 08 Apr 2021 16:17:03 +0200 X-MC-Unique: 54HrX2WrNKSsTDtXY3XT5w-3 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HEC9+focFd1EzDMxs5lbLUWoU9HmIkxIadR0iHjH/hGrCRc3rnXK1JKDofWmCMbzM0qWUIWDQLmrlb5iCSm7Z7mGI1Wbwp+J9i+40wYMmITb2KYvKDrvXCVcXfle3bW8YjzB6Ar4QPyebO98RCRloMAPwvz/8qUbyBV6KP+f2ZkWza4Nsl+RTfOscNBU6N5uwzAmbUi3kYQIx6yAPhQJgxWD6JNA7UfaBXgobz39kiLiBwxpc3Lqsf8157Wmr6+dDdvwW2UeoUcVN7OTVqsDVubdP9Xqm64vj9eyvAyG4F7+G8tzxxRAlqgSU0v+5cIapEFKJN3kuuTuwxCk/Balig== 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=b3isiNpQLPrO3+BBiER53A7gJdG2+eYaUagS52qvxwc=; b=ClD4pBtJGD1MOl3Ww1tHO3Q/gdNXkaQ1G92WsC3NRP1r0J/DAmU7Bguyo9aI382I/q7FsmINq55GHPFUDa+Dl/UwMgIcQa9o8RAaSB9MhR84ryGlK2RkhSN8FPv/AtYaW4jQENfvdcPxlIUPJyx0sbogkoM7JxwuUyCnO8IYBhpwIwQ9LsF1N6XWbxxcjxDe3EdPx4268o2PtUJvfqVQcjelwvyIVyUtpQed1MP6acN556+GMUKA9gzKejArEjr8t/5z1ET1hgdHhPeVfPxM8msqo8VozR/MBrHrvWToAPQPmxdffTBro4n+4DDtEqjRqPAz3n4ICY1c192zuiZKWQ== 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 AM0PR0402MB3572.eurprd04.prod.outlook.com (2603:10a6:208:22::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.29; Thu, 8 Apr 2021 14:16:46 +0000 Received: from AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d]) by AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d%6]) with mapi id 15.20.3999.032; Thu, 8 Apr 2021 14:16:46 +0000 From: Varad Gautam To: linux-crypto@vger.kernel.org CC: varad.gautam@suse.com, dhowells@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, vt@altlinux.org, tianjia.zhang@linux.alibaba.com, keyrings@vger.kernel.org, linux-kernel@vger.kernel.org, jarkko@kernel.org Subject: [PATCH v2 13/18] crypto: rsa-psspad: Get signature parameters from a given signature Date: Thu, 8 Apr 2021 16:15:11 +0200 Message-ID: <20210408141516.11369-14-varad.gautam@suse.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210408141516.11369-1-varad.gautam@suse.com> References: <20210408141516.11369-1-varad.gautam@suse.com> X-Originating-IP: [95.90.93.216] X-ClientProxiedBy: ZR0P278CA0137.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:40::16) To AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from xps13.suse.cz (95.90.93.216) by ZR0P278CA0137.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:40::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16 via Frontend Transport; Thu, 8 Apr 2021 14:16:45 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 842a4e0b-6cd7-46f9-f33b-08d8fa98f131 X-MS-TrafficTypeDiagnostic: AM0PR0402MB3572: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:935; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1BjMF+QTzcVFscR1F9snupiFutzZ7ENb6rbSimkiT09NiijxVtIz61pgm5SeO9IfAFJVC9Mv+h/d07axNLZs0kKm54IgApEhIBgJxhxvmO8qtBOCGVk0aoEPYe6sznuzeVrvvHMPpqk7XfCqFz9z8MEUXgUhB+FGzywhKZJlFDaCUekxroimpjvCiC4KgcekSg089sZSijuwVQ3EAtqx44Tfq6zZ1nJTteFbiazomM0POUwLZbVLicuGaWb8elHijHtNXdGNVuGHu+w/1h+afPGlgmbLdQCHAjshxQab9JsVMJQiXsoCXvopQ3VJearcXvrRb3GbP8mLqLp0Wlzv+ZuO8Rsv6B75reDz7sjAKEBsNQ1riZbtALJ1eFEvl3LcA4KqxCH/4hJ2T8qQz51E4HT460KCCXMPj9kOT3tEHIph7b4jz7Kd1+rOJBt6LiSlD0i5m6POKa2xDoAprP2adNBTb8Lj34FPcIJw6iJxVAsWPelY3/dhnVMrKxR9wvOwYTjuJS0DmkBhrb9035hkL30grjUT560V7dFhsMVUI/PPQi0h/Vvjy3v8YQhM15bN0QNdWiM3EN92V5xH5k5hLo/0Jfx1FeIfIy0tUiko5U+SqLtG0WZqDSR5tr8hQM+cNYKh+oBaUYA+oHYqYPitMdDNF+MBdTVfZyd9BmKoqHBFNCBxc2d4vntMGptYPBOC 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:(39860400002)(136003)(396003)(376002)(346002)(366004)(16526019)(186003)(38100700001)(2616005)(956004)(38350700001)(52116002)(6512007)(2906002)(36756003)(44832011)(6916009)(83380400001)(6666004)(8936002)(26005)(66476007)(66556008)(66946007)(4326008)(316002)(1076003)(6506007)(6486002)(478600001)(5660300002)(86362001)(8676002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: GsZ/TaakOZ6qnNA23YXi2nNrSKcShYW0wafGwjS85lGEckZJ8OktbaV4QHEkGmp7UgUl2SpCQV4jc7TdpOlnQ/T5N4pFlKWsON9714qr9ShJU5JGhtYSsd2G6e2ILOD9SSqk+xNJpj6JBxFvHPA/+stZSoce3T3cLPhp7oMK3L2NtCGnHyyQ11a8XfG5i1MGrAqz9ff7j8SrQT6sMbAYTiNumggEA3rynY9aMte6k0lR5uglwwkGf1Xx6ZYnbmO7IgNSBgJ9lTY9kvZFkbaUEayaz1X2WqLbJzCHFn50nyU8Jo0MvdfoiRoY3PGm7SmlbH6RXBd+b0Sq7fUd8DUjq1tVxyyxMhNeIyZ1EHC9PokZnad6q5qopas6q1YtqC7QE3Rax9DJg7XUOM7pMVidBwKW1qVkrhdLdLhuJ8eg2Ptdkpf2HNiM6QLqgRNqVivj+bB4ZCWKRAXMGYyQmulf27S0/d7Yg4h2xGEdD2WwCHwZOift0z1YGQXXT1cIqEU13j/e4CZRdQZ+fYMuVh7WN2/pY5c23HjgVEZTREy08WPcuOYQ9QeIKEGEpMmSnoH9MdkWGWTod311BYrMx80imLXQgMbvnx0pB0Qeva9ROxVY14DaOAKw9Oxte/NSleO7xjBmdCqG35Fp9FiG0tMELbtOBM0Pq/1J7GA7mfvSaEyIbKPYKQzeRV9vCFuoj1HESK4WJj7mqpMo39TDytqrKWSy5woBiMxVAFI2JGSVioQH6AVwghNQT0DrM918KRUUjNvfjEeqRu3mmiC9cVzQclIJvn055Z04Ngc8d122o5f43aKMjiSKM23QF2D0XqoxctPJsNEDFRpZcUBcWeeueEywcK4dZxWYfOCh3PE+lUiXfmzA42lZtM5DrPHzvzQPinMwp5TbwQFQR2BGtuu3kMyOKjc1IkL5rY2Ofddzl8dyu4NwECHDwAfI1x4kehVNtS7zdEs1X4Jg7qARGR4gbtvrcKZ2CTUDNRq5opUVtI1rxl9DmRJbwg8flsKAAXvbWseCblAB0owhH1BqUbS0Pzhl/PbIozt4m+0KFypx21bdGcEEs/xs4eXpIjBiVHSHxT7B2EuPWl8R5Zpa0IthOWeBa0d3KUiU+L6lVvlMsxpuxqlLN2AVTuCuRhIPY0+zQDZ/f/ktXSdKRq5k99DHZdEGmjTvYvCD6aDa2wK15RaK6mZrRHrmid9jV0Ely3mkCcXr6YaG3Etvj8aFqrjWFLbkZvFp2ZuQh2dDu2McMWeYDvwhOwmcNctCbQaA1moO12QJ2Q3RqKQ10jespvBwfM2b1Rt6mShBecD8ACytXfFnPax/b1/avo7wodrBESC3 X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 842a4e0b-6cd7-46f9-f33b-08d8fa98f131 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5650.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Apr 2021 14:16:46.2650 (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: QvWFPT5k5b4UEPymrSDEOJtQp1fW6T+Jhr3tJcIDOfcEQVlmWzinn9zLhJVn5XIk5DTTq1u+SNs7BedlXw1i8A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR0402MB3572 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 and MGF hash function for the signature being verified. Signed-off-by: Varad Gautam --- v2: Set mgf_hash_algo in psspad_set_sig_params. v1 assumed this to be the same as the digest hash. crypto/rsa-psspad.c | 21 ++++++++++++++++++++- include/crypto/internal/rsa-common.h | 2 ++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/crypto/rsa-psspad.c b/crypto/rsa-psspad.c index 855e82ca071a7..eec303bb55b2d 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,23 @@ 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; + ictx->mgf_hash_algo = s->mgf_hash_algo; + + return 0; +} + static int psspad_s_v_e_d(struct akcipher_request *req) { return -EOPNOTSUPP; @@ -48,7 +66,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 4fa3cf5a989cc..8b7ba0174d5bf 100644 --- a/include/crypto/internal/rsa-common.h +++ b/include/crypto/internal/rsa-common.h @@ -26,6 +26,8 @@ struct rsapad_tfm_ctx { struct rsapad_inst_ctx { struct crypto_akcipher_spawn spawn; const struct rsa_asn1_template *digest_info; + u16 salt_len; + const char *mgf_hash_algo; }; struct rsapad_akciper_req_ctx { From patchwork Thu Apr 8 14:15:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Varad Gautam X-Patchwork-Id: 418310 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 18FC2C43461 for ; Thu, 8 Apr 2021 14:18:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EB74A61151 for ; Thu, 8 Apr 2021 14:18:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232209AbhDHOSQ (ORCPT ); Thu, 8 Apr 2021 10:18:16 -0400 Received: from de-smtp-delivery-102.mimecast.com ([194.104.109.102]:37322 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232119AbhDHORd (ORCPT ); Thu, 8 Apr 2021 10:17:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1617891441; 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=iRrxgw68q6pfk4lUz7LU5w9BVk3PvX2ZAS9xN2QluJs=; b=fmuLAz8RKg3DVudDCF/TLLcUEc1pWYHWih/YKzbNYTTsZDd5wD/csiopd7KkzSCtEA1zhf mCrcq2PenIQl4VNqBRWTabZAw0evs3Tmuuu+5em04tgz+Ad+LFQBFsdmEdTf/ktpwdhYwB 3mofN1QdZTuihm/0i5ChY034Mu5/hjA= Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05lp2111.outbound.protection.outlook.com [104.47.17.111]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-17-7CC3_sUfOXizLHEbsMdYEg-4; Thu, 08 Apr 2021 16:17:09 +0200 X-MC-Unique: 7CC3_sUfOXizLHEbsMdYEg-4 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Jl6LVUTO0gr6u4yPEmc6h5WgjAPe7BKkcUW690d5xoq9e6djKAsfpEHe3FEdYkVea4KPCGbZsZwETkpSsWyxWnEhzfCmMAsVjp9FlJifCCJjjAGiqrtze59wjCmGFU4ouTyXmFnXtXkYxAn8fXB228z0OhiHMjTAmJxuGzckYpNWoxg0IBQDq74gCUufsHDOQoSeyAMXhLJGTI1D5iS2NUGPViEVdznPetd9OWJEE9WKfCzJzv5qFCfXVBzYSLw+iuj8BkzVQWp8Gt4x1PO4bPZWXEx8bMoTGInHJBpnmo13Nr6hVN/6PizZ58QflstNGaKrVWzxu5JdaZFMGtV27A== 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=IskEQdezwsG+1Vbwgg1ivmFRskQn4FAtE3PJv8JoXBY=; b=faTpkP2a+EMm4J1jAdU1FPTJcymssBxWgQlE5R5/wRiabPWLPpWwxKJZl8KsYZ3/Ep2kRxXMSBqE6Uq28Da5RBtyBr3FbVw+5A6+WxHXXcCphyAM9mb3+eoB8blPvdVwwUaJ71YFq+3fRyiwDEAmrn4/dUzdSVL0JQwJRZbCeWST6CA5I1/4RpalUfBbXq3XuIzApfMqGbCjLulXoqN2Wnu4PACRQTUagmn+uBGm+TpGriLoyVjn4qo1B/nKU81PBhWK581XbGpWY1imvZ22B/WEu1VgywkUVFOHf5OM3g48Z+xffKqYbB/3wMNhZZpnPawhMBkDUx7GTMAD45w9iQ== 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 AM0PR0402MB3572.eurprd04.prod.outlook.com (2603:10a6:208:22::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.29; Thu, 8 Apr 2021 14:16:48 +0000 Received: from AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d]) by AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d%6]) with mapi id 15.20.3999.032; Thu, 8 Apr 2021 14:16:48 +0000 From: Varad Gautam To: linux-crypto@vger.kernel.org CC: varad.gautam@suse.com, dhowells@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, vt@altlinux.org, tianjia.zhang@linux.alibaba.com, keyrings@vger.kernel.org, linux-kernel@vger.kernel.org, jarkko@kernel.org Subject: [PATCH v2 14/18] crypto: Implement MGF1 Mask Generation Function for RSASSA-PSS Date: Thu, 8 Apr 2021 16:15:12 +0200 Message-ID: <20210408141516.11369-15-varad.gautam@suse.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210408141516.11369-1-varad.gautam@suse.com> References: <20210408141516.11369-1-varad.gautam@suse.com> X-Originating-IP: [95.90.93.216] X-ClientProxiedBy: ZR0P278CA0137.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:40::16) To AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from xps13.suse.cz (95.90.93.216) by ZR0P278CA0137.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:40::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16 via Frontend Transport; Thu, 8 Apr 2021 14:16:46 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4e7dcb37-588e-432d-37a6-08d8fa98f279 X-MS-TrafficTypeDiagnostic: AM0PR0402MB3572: 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: 43VUSBm4UyNwEBcrmhxFfTxwVBHo1hNWnTdqcHqegtToUJcwuZYDtgFwOClGTv8CUnZWdZnBe7IKgvaNSauj44vPTn7tota82YsHVU5cBFiCm6Ec9IWPW0p281v7JDm+82zfed3GDVIuwdE4AIhxia3zzzOBpdwvf8D/pcVq7mYZXVYkFEfp+KpKBqeT22w5DfXcVNS3FOqXaEwAp4tjRgi5bDT/V7lA/7K+ZmiwBmUTLhLlUdxfNcA6o7zyiuTTjsDXmJkjihJRyXJpJ4P8CfRpPMFQbTi4fHs7F+7FvI4KtVOsX79XTOvmkkOCUC5RboA/15cLRYAF52uPXLrMpo7JlXdXLKDF7yicK6R6ldlBv7ZQXOjlYoT2RRvY9zO6ZZbAhnBmivstMMuVbsaSWMx/eUEUtJNsPyVW50APXuKuyAf1cgbBpWZssfQdWsAKO65FrgpFeWvwI9i2YT451vIpz7S/iwzWZoYzAzZQP+OsF8ghMMSRM4czYXca4RfCEjAPT9koOMow7mx/dHsJ39nTgR3a7FaYi08l3n1BxjfpI4vWyrqk2N7/ojVPGJ10qo2CnvdXuqTlRwvZo5Mz1FE+0BFbQyoHPthPJimJ6y5h188UqvODef04/aLrF6VCr64g2OPQjQHZVMa+uB+bCmjhSdRYc/sKbtdJGqtBEyqi39Dhgffrrp7XU/YEFZ55ar4FpGZxw8QEC7NfJHep1Y1xtl2Bc/aAi3HurJuj4S4fnSl72nH5/ZnSWh/4D0S3 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:(39860400002)(136003)(396003)(376002)(346002)(366004)(16526019)(186003)(966005)(38100700001)(2616005)(956004)(38350700001)(52116002)(6512007)(2906002)(36756003)(44832011)(6916009)(83380400001)(6666004)(8936002)(26005)(66476007)(66556008)(66946007)(4326008)(316002)(1076003)(6506007)(6486002)(478600001)(5660300002)(86362001)(8676002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: Y4f7O2+Zg+WZsnPJP2mwd7H0nmHhVDPYcUU42xkqu0oJxbjAGpKWOE1AxFjk7GV74gLohGQPXKUA73MRyKEXUnsiUX+1KsxZHMT8PP97a/ZqUFKqmidW5VBwwZq/k1v9iyxDfwIRj8w5ke5FUGQlWFt2XfkB9NDKoboYA3bP/Uheu1Ale1t8wKqTCkTUcAeH8axN784uejMat4mFiS/eb29OgnVWyySCpD+qHyLt1x8XgfHODLnCS4tCvpLk4ik9Zg0KugcpBBsnBNXweYDacJg/hc8Hnq3Z2zzF+nCimpIU7exorgQDcQisUImmSmVVlo3BIjTAiDLZt5Zm9CbaGDAWGTQ+8chPCWRxLAVyZIC2cnttoT0oEP5pSM85GdrWn3EJeg3i9zLrptoZvJbEoPKBUApnlv/hKvB2bVO5+sUXV+SI69ugdgnPjGF809ZoxZ8coWypMXJzm9s8t5d7tzgA36kwVBTqJ23SzEeAJ2hAztxyjDG9awa4aHOYuVa+UeCS6T/JA19IAQ4Gp7j+63rDtMFdl2KItwSkwgQ1EnGSd8FCmNUJqpM7kmJDyD0iztFLdIr24xnAZ9dIfPKx2EUaMqKhhocj3eg+ix2C4zInLeFUbmn9oa/sMqanPLhTFlSqPWm6IfN4H5mpjn/CqqekhlTOQ/XZOe8X2ZyM4P/mh4+7ZNBj2lxhZ25Oqg/zkIvpmgIaZ96NejPYmC6oj0y0TKJHuqtp6pXnJCVWiDicz/nVINM5FTI6Ot/oGBMQT4qgoX8ReB/M84XgBKZEbXcVA72PkQKCxZhx16CNN1ZuQ5Bm/zE8krK8CPL7MvetznXRUqgZ0+LIycse94EEf//qkUAqb6DEOKdczshHl3dCfRfSsiUX5vz715XqbyqxFqOFxu0YjITYbsIJXoeUT5OuQtMxON3Rvu5W/UOCklyC2WXW8RRgR8lIPaXV6DN/GveZlTHMsl9OK4TR0Dynroy9mKK5LQST+QK3alR63jVDilqlp3RsuWyPMgN1klCFQdlamT1YFZzVMetsYunktw0A/RSLatqigA3GZ2eBJ7rjzoLZ+4Y4h5Ece3NUO9u77NNfQgFssPRh9Fx8A7KMf00czobuOEyG309TwmMMRRGLBFE/ZNygSsOGQRciNn6Ebx1Po6coVxsgnR9UCZwYlEXUr4Z5vyWU+47YQHq9HcZB9sqdGKH8Og/5F3VlTacb3K91aNBIxDg2OkPPOGf+c3x8ncWwVQBV4kI5BflKmvNuZ+APT7ludipDlHWqqq8HfBrRPh8sQAkhvzZhCZCJ5xhh+A3pGSqsR18CgRYFQubie8lFKRn05yPwJ6NY6ixm X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4e7dcb37-588e-432d-37a6-08d8fa98f279 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5650.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Apr 2021 14:16:48.3977 (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: TRdmxlHOiNFBvNYT9Cmva2HTV82oRfisqN2GU2hLa/UpoHxxKigdQezGg+vFORMxHmqohRLEdlbm4OLnI1nODw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR0402MB3572 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 eec303bb55b2d..ed5374c381513 100644 --- a/crypto/rsa-psspad.c +++ b/crypto/rsa-psspad.c @@ -51,6 +51,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 Thu Apr 8 14:15:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Varad Gautam X-Patchwork-Id: 417572 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 2BB2CC433ED for ; Thu, 8 Apr 2021 14:17:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 053EE61158 for ; Thu, 8 Apr 2021 14:17:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232181AbhDHOSE (ORCPT ); Thu, 8 Apr 2021 10:18:04 -0400 Received: from de-smtp-delivery-102.mimecast.com ([194.104.109.102]:45766 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232093AbhDHOR2 (ORCPT ); Thu, 8 Apr 2021 10:17:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1617891436; 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=ENeoeGjztm6hP91FXe6TqkfYtzDzY/mPPZPgO97Y1Sg=; b=FL9C4dtC0P0hFmefeIGWdXMJFAy4/Kg4uwkWCtiulP+I9NRT3Va8OuS9kHnjfu+aJV67Tk 6+qKG6h0q0x4JSh0MfKUvuivAqpfsE1VMB+WfxNvQ9ETAQMokpSn8bW7dEOKOiudpTr+dX Y3vbUF9GsgDqub9VzbwnuuRyuxjSqfI= Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05lp2105.outbound.protection.outlook.com [104.47.17.105]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-5-AYv-Joj7P4-1LLRdqZg-oA-2; Thu, 08 Apr 2021 16:17:09 +0200 X-MC-Unique: AYv-Joj7P4-1LLRdqZg-oA-2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VWZwEaUg3HYORrRIT+j+p8c0SstKlhPcXHNpXUx3DFenVsw2nroxs91kF9iTTQ9VzYuV+97R9xhoStzbKZ5SOubYNMqDRxlSuxwbAyc/j1u2Fc/6yUE8CH5afSH9ma/IByCcMOosRbUfbg79Kyh00vVHig3QxOhBOwPQKTG4keRQjR4fcL3JYTB2CVvPJSVYJQ1Q655nYHNtVbwFeIGJ+Yrk0tFR2hWhRMXtdN7RzZ1Z3wup63OeKzLS+kgH0Irq72iZmk2R6dXIiDnhEp1Oo3bLwuj/3CZ1vnj1H1v2hEZhrWL0THawxdVEvyaV+axoGpaKU9JLqNn9mkAgySKZeg== 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=kT8Pld7hTo+LQK3LxhFaGHsHTvl3EkbRAdrK4Z5Udv4=; b=CNGJyHb+EOoyBMyxxrkAOv4A22mDnfqqHLd1g/nuULMaQsyfhBdJmGMNZqBz3SiVhdXTLyzHsmVKHvXMioqf8Nfe8QtCsDGLBz8IM6ikBdQpbDdu77duA61Gcuv+rJIma5YsEAcv5YCwco7Mt77nlkTMXRBAr0h9rWskKL22wf7upPfJFk1ofaanpq70VrMJAxMA5k0PuTebanWuHk4I4zKojrp442rlsKFLmuBBAe6l+QXSIVlX34znbclLjIe1QQy6F2T2YyC78xjhAP9leT87Yva6jJP9j2RR7QFczvPyIBp60OxiCDKZx/4QnxpwaEuem29D+ACjhMPoAoDbCg== 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 AM0PR0402MB3572.eurprd04.prod.outlook.com (2603:10a6:208:22::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.29; Thu, 8 Apr 2021 14:16:50 +0000 Received: from AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d]) by AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d%6]) with mapi id 15.20.3999.032; Thu, 8 Apr 2021 14:16:50 +0000 From: Varad Gautam To: linux-crypto@vger.kernel.org CC: varad.gautam@suse.com, dhowells@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, vt@altlinux.org, tianjia.zhang@linux.alibaba.com, keyrings@vger.kernel.org, linux-kernel@vger.kernel.org, jarkko@kernel.org Subject: [PATCH v2 15/18] crypto: rsa-psspad: Provide PSS signature verify operation Date: Thu, 8 Apr 2021 16:15:13 +0200 Message-ID: <20210408141516.11369-16-varad.gautam@suse.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210408141516.11369-1-varad.gautam@suse.com> References: <20210408141516.11369-1-varad.gautam@suse.com> X-Originating-IP: [95.90.93.216] X-ClientProxiedBy: ZR0P278CA0137.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:40::16) To AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from xps13.suse.cz (95.90.93.216) by ZR0P278CA0137.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:40::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16 via Frontend Transport; Thu, 8 Apr 2021 14:16:48 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5eadd5c3-ce5d-4fd3-7623-08d8fa98f35a X-MS-TrafficTypeDiagnostic: AM0PR0402MB3572: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:332; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9gydYn2KDw8a499iS8lDOr9sXltPFuHmYiqxsI7tRTwuXK6rfReDhxWoQBj0URK183S3T0Z3zSmHYjM/US2913NPyeJwx0gOfIZm8ycLLS6IRxBehwAMLwUZkGQTiu/asZCOnf38CK3k659Jss8SyFtRJkCrT7g/EAgMLM7IoPXQUdcY0OJZPR9rbgJtqbkZdy8UtXqQ5Ttd5wN1hQHjUoCkVhTlVwhc2MNobkq7y3YakMRgv7EYZK5CXy2YheadbBVxYGnTDoLRpWfhFJDCBEHxtsNV+se4X+ptBdnIi5vKiQTgOgt5cIGOMUzQBs3q47OVdGYlHsfw4ywkpHpSEx2b9Ap1xfJkk7qDNkLeFpO6W7YiOnqlvPRVAL8A9obLT19j/jnvR0JUxqdcRKLtgGMeyULdP+u556+C5V1dAGh9g0cXfPqQQlnsQqfp4bPPBzVzzccL7/55V0xb/xKwHz6bO2bR8eERdQJi/ejIrGts675jMkiycWaoau5j2hfKYYHnJdLbHZa3Aw3RrOaTFLZCBa/Zf+/qtdP1fHzciNYlO4VgPL3zbKFodDkEQQJ66eUjtCtT33cgXv71916MfrgOeVgmCSDjtuXiDAEIUprtASaVkEaEzPFYOBICMRMaWvNZ6lVRBPPaYM5UllryZB6p1n4JHtpj3GflXfYsKpeuj+arRW6b3L9q/fWX2BiXmG5buXN1YNgAlWabfvXvIhLNFvvPiAbi3vBZewyEzaa/sw95bx3H/Q4wErfz5r2P 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:(39860400002)(136003)(396003)(376002)(346002)(366004)(16526019)(186003)(966005)(38100700001)(2616005)(956004)(38350700001)(52116002)(6512007)(2906002)(36756003)(44832011)(6916009)(83380400001)(6666004)(8936002)(26005)(66476007)(66556008)(66946007)(4326008)(316002)(1076003)(6506007)(6486002)(15650500001)(478600001)(5660300002)(86362001)(8676002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: Nc1L5luD8tks8CzoKsbxKy9Fok1/fJhZcI7hIu1Kg/rIPccoSzt3e0Sr9Ck5Ema1qfNMBNyvOrL9yglgjDMfmBi6KhvGpOD+Nb27SKAw4Z+BYAJ4GRSmn9lC13jZiI4gHK5lIsgHGI67gzJ81I/F29DK0GWeFZQ51FWOICAmsawHOPgEZpiOdw8GO1o2ffyyAnHWeP7k2TTnM4BucLHkvVAoih1NpYifrMsYLX9crFOO1rCSNenEcY573DD5GDB2/kW86cR/im7zVpLdT3nGhNphGnC/7fyJjwGGIzSJNdzxVd921TOzwasqSbYfeEpZ5XVCUKfNFCie07eYRlo8lWTF77lPsSQqPPmHrlBZe1ECHJvLr6A8yYQf3ixjZsj2+AWk/cG1zIBYWcCmCMTAlMYNDKcSgxJz/+Owk/dbsraGsxUrIj4Zfc/OygN7mvMH0N8aAWgNmiJJlLujLcOckUNcuA9vmeHvhS4j7vy2ZVcJL6Pq4Rw/pFp9wabTTX3G0ndWWF9s2YkdUarnPCLNBum8c3ZdUN9CBjKjtl5rnbrsCZvyCTwPugwYdGwOUEI6eGAGzK4tNCT3PsLFDiaB7EViojp9xgcihZeK583jKMWJxhQSjTP7GbMPpILPvnsafXjhWpAXvVqBX0+USQ3wo3NRuHkBnexStvjceKROaMeSY6WAZZDX0CUKP0fi71d8P7KwJNwN3+C4O4GwtwqHr1WX0HsX7IdUdB4W1J9v3PSbSIchdFCSFzj+JJaajlxLjVECX43CoOI9BAOztCVqaPmANdMCtEAOiW8gP0zxGLP0NmSq/iaZD3mZfR5K51VP5EimScqQvwVQCbp51/oEd4rHSctl18zQpP9TRq7bw/9+HK8A63IapQPdiZ2tC5l2eGnxW5wBna2zfgSQQ6Hx9vL622cH7hxJzrZLNSDwMVN2oI+JkkwjINHj3soxMAb+kKh+oCPom+hG7GQrUkxlS3ZYod7eGWCnprPp3YrJG6R9TRsXmaWC8GBA+PM+aZ4HhhACeM+2vV/+ruWSbXULfCmsp1xdBRmkbb2wmEUNUQvMPuu+Rk83oeU8TfKLuV/+jp7F4UJ/YGinEgU10F9RQDhohAzBVIA2Nla5PoFk7AiCl7/yRwtSsmSwZF8Kh6lQYkb7QD6bJGZfJd24IDuGVIRBTFGYKBa5m/9txJb0Gkq5nxNKUhdrJhunL6CYL7AIRDl/+B6X31umoBCJvet0sg3U5Tjx4xEr1UkwOL7WDq6DhO7nnvyN1TJB241OdE6iB0zfBU3ZOI7o+QpjOGpHPd8jFMeNroVNH4iw0IBZVdYTcSahjXiJgBK5x5CdEeI9 X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5eadd5c3-ce5d-4fd3-7623-08d8fa98f35a X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5650.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Apr 2021 14:16:49.9798 (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: EDTm0pS3AjkJwjo5IpX4hzsv3yJlVDbym8isDmc7qIsMMvzLUMb5+X9tD5iWmk/qhHJKc3AUlPntgQhli2/s+w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR0402MB3572 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Trigger RSA transform on the signature being verified from psspad_verify, to produce intermediary data which will be handled in the psspad_verify_complete callback. Reference: https://tools.ietf.org/html/rfc8017#section-8.1.2 Signed-off-by: Varad Gautam --- crypto/rsa-psspad.c | 53 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 5 deletions(-) diff --git a/crypto/rsa-psspad.c b/crypto/rsa-psspad.c index ed5374c381513..4ba4d69f6ce17 100644 --- a/crypto/rsa-psspad.c +++ b/crypto/rsa-psspad.c @@ -105,7 +105,50 @@ static int pkcs1_mgf1(u8 *seed, unsigned int seed_len, return ret; } -static int psspad_s_v_e_d(struct akcipher_request *req) +static int psspad_verify_complete(struct akcipher_request *req, int err) +{ + return -EOPNOTSUPP; +} + +static void psspad_verify_complete_cb(struct crypto_async_request *child_async_req, + int err) +{ + rsapad_akcipher_req_complete(child_async_req, err, + psspad_verify_complete); +} + +static int psspad_verify(struct akcipher_request *req) +{ + 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); + int err; + + if (WARN_ON(req->dst) || + WARN_ON(!req->dst_len) || + !ctx->key_size || req->src_len < ctx->key_size) + return -EINVAL; + + req_ctx->out_buf = kmalloc(ctx->key_size + req->dst_len, GFP_KERNEL); + if (!req_ctx->out_buf) + return -ENOMEM; + + rsapad_akcipher_sg_set_buf(req_ctx->out_sg, req_ctx->out_buf, + ctx->key_size, NULL); + + /* Reuse input buffer, output to a new buffer */ + rsapad_akcipher_setup_child(req, req->src, req_ctx->out_sg, + req->src_len, ctx->key_size, + psspad_verify_complete_cb); + + err = crypto_akcipher_encrypt(&req_ctx->child_req); + if (err != -EINPROGRESS && err != -EBUSY) + return psspad_verify_complete(req, err); + + return err; +} + +static int psspad_s_e_d(struct akcipher_request *req) { return -EOPNOTSUPP; } @@ -114,10 +157,10 @@ static struct akcipher_alg psspad_alg = { .init = rsapad_akcipher_init_tfm, .exit = rsapad_akcipher_exit_tfm, - .encrypt = psspad_s_v_e_d, - .decrypt = psspad_s_v_e_d, - .sign = psspad_s_v_e_d, - .verify = psspad_s_v_e_d, + .encrypt = psspad_s_e_d, + .decrypt = psspad_s_e_d, + .sign = psspad_s_e_d, + .verify = psspad_verify, .set_pub_key = rsapad_set_pub_key, .set_priv_key = rsapad_set_priv_key, .max_size = rsapad_get_max_size, From patchwork Thu Apr 8 14:15: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: 418312 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 5D4CDC433ED for ; Thu, 8 Apr 2021 14:17:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2E76161151 for ; Thu, 8 Apr 2021 14:17:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232152AbhDHORl (ORCPT ); Thu, 8 Apr 2021 10:17:41 -0400 Received: from de-smtp-delivery-102.mimecast.com ([62.140.7.102]:33132 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232053AbhDHORQ (ORCPT ); Thu, 8 Apr 2021 10:17:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1617891425; 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=DWSSzP5QXhI7WRhos++wXtpxy/9BblHdAqI5QoxPlPY=; b=RiwTC4Nd53V0nXvAtyjhyou6SdpaEqw9u0oZep2LGnLNtaL6r1zT9KfY8vBnaEc2LQ4y+Y NvfrUW9/r6MkC+YlTJWMz4NFI9+2Li870qv+w9M4zC3ZI9do8jokNV+2vNZ0TV4Tg08YLk vvIisa6l9+TGN2hj+bpL8NB13ZwP+kE= Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01lp2051.outbound.protection.outlook.com [104.47.0.51]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-26-sRhzaybBPhqKB_esGrPGOw-1; Thu, 08 Apr 2021 16:16:53 +0200 X-MC-Unique: sRhzaybBPhqKB_esGrPGOw-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YK/19zV/q98+dyZkJx76wRPhNF96MRU5Ao7xrz9hNQE6JB4S5fCvZ4uk6pXoN74VAl8/slvZhda5txasTIuAvo/b7lcw9pnG+XcDaQewTFIfrlnMtxgpzMaAsMHUeb7C7v2LaFOnNN4U5NcJLrhxKC9ODv4lIwLK7byo7Fyquv0FhEBua1Pxdc8bxbrwiwkTQatqJtG26NPz3i3/k8UFK75mmqCZ1Z9YYeVKfG6zF2yVo8Ixw/2qJNEp/BhnFP6VW0raaWq9yDqsbnQHJBJXjNaFQ35noJwDsfhHVCqiyq6kjMrUlZkL+nb+lnBDj6rx89cJ4c2ZQ8LzLBAp5o67og== 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=huqGSLffEZrdFn84hJb0MF2BX6fnQrDe+V+X+XzDV7k=; b=ZFznT/6qdsV0oD3dI4tQNur5JSTAHuv0g43CKiuMmE/KJ3QBPJQ7caj0dsGgHExpWB6taIFD6ZRCSEG0KyA0rDQMXawdFM2tq1OegawrOlQs0ZNRLS1R8rx9WYTQR4cBTwNWOxkuaaQXf0Lyjcca/uYfQzex+qki9lxD4tuvigSEIxtWfZVYlGkaOgNf/vHVgZrh5kcTi3MK7Nb8w7RpJ+U9NV1Nq3TWi5o229CQwTHRe4WNZUndBbNw3uKK/rZVZs+g92FDjepsqD/PUhFRwGoOnGlMC6Zy4U8J1QemvOwwpqD/1Q05k8tbg352TsDtxhs0pTWAg3aoEB14XCXcMw== 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 AM0PR04MB4833.eurprd04.prod.outlook.com (2603:10a6:208:c2::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.28; Thu, 8 Apr 2021 14:16:52 +0000 Received: from AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d]) by AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d%6]) with mapi id 15.20.3999.032; Thu, 8 Apr 2021 14:16:52 +0000 From: Varad Gautam To: linux-crypto@vger.kernel.org CC: varad.gautam@suse.com, dhowells@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, vt@altlinux.org, tianjia.zhang@linux.alibaba.com, keyrings@vger.kernel.org, linux-kernel@vger.kernel.org, jarkko@kernel.org Subject: [PATCH v2 16/18] crypto: rsa-psspad: Implement signature verify callback Date: Thu, 8 Apr 2021 16:15:14 +0200 Message-ID: <20210408141516.11369-17-varad.gautam@suse.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210408141516.11369-1-varad.gautam@suse.com> References: <20210408141516.11369-1-varad.gautam@suse.com> X-Originating-IP: [95.90.93.216] X-ClientProxiedBy: ZR0P278CA0137.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:40::16) To AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from xps13.suse.cz (95.90.93.216) by ZR0P278CA0137.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:40::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16 via Frontend Transport; Thu, 8 Apr 2021 14:16:50 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 835ba732-e120-4355-dbeb-08d8fa98f4b5 X-MS-TrafficTypeDiagnostic: AM0PR04MB4833: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:546; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: IhEqgx0SzwGU7PxoMQOcCQRKF+H82EQWhANSv+XW1mcI71AzjW/BHa+c5WKA5cb3PjfOGjwb9KHrNAIZ3N5NuTuSSc3wbe/k9zj8ex2BrZxXujw5wG3MHF5obcP3yuYljcAOXxHFkuH58/HuLWKC5T4YjowZ/fQi99zKOOK8xsq6IDRJv2+eyvGQHpCdbZeb2DibeF7jZ/UhXwgWViPZkStFAhp72hnUSbgvGk1CWldeq0G07euT3E5dy7u1RXpdR3gdjRaQBrDdj5Olo1tK5jafeHYCo4t41ccEap4zObBF9ErwDnuZvaU1f8J1rKs2wL1mzvg/b1ors4a/bgQ5Ct913AkLhuYIVkmSXOJYRZcnhrjxOIjHVLHOE4x+O2Df3ZJ5d0aZozLMm7Lvbfj2hqbE0lKG7xHz+K0IpLIm3gL2I1InSK0iOLx8uX5xIsmVY9vtLxoASjB42tj1OMA4G1vD6LUf5wXam6M+stdTAqpj5sdC/FXHGdfVBJR4wSSNbT6MmBDbUTu9PE6PPFhj1ydpePSUhJnjl+Y3OOVvc1iB3x0VgDnuvjR3CpKvqoaamOBOtnjLuOr2eHAyB4VIgasSjxSITHthV4hxdesG9JBhC46CNVZLs7xqatdaou7wTL9YnYyZPzrPcCD1BglhQ3mxisNVy528GEvSWcmMUo8tGdg2MwbwwFkVrq4kQgdmaKOA1o1XYWc0OlrN+pAJiR2D7JcBGJfzACLAXJNqNkD98GvxP9BpO8aUXau64RTk X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR04MB5650.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(39860400002)(136003)(346002)(396003)(376002)(478600001)(36756003)(2616005)(83380400001)(966005)(38350700001)(956004)(6916009)(316002)(6512007)(52116002)(6506007)(38100700001)(6486002)(2906002)(66946007)(44832011)(1076003)(15650500001)(86362001)(186003)(4326008)(16526019)(8936002)(8676002)(6666004)(26005)(66556008)(5660300002)(66476007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: NNDZBXjoCmFE1i91tuNaSQhz0xp4I/QZd83W+bZM6Sk+9c5thgoYdyp+ZWdB8RVlzJEUCgONif0sECabHBWv66fXrTuuGEglikDKV7XEeFg5Oq/8/DcqoLhFidfXJFfd1vykL7yVruUfeqrLw6h1SpmB1u/228lpBZiLJ5Ftkajip2X4t4gyNzQ8ZvSKtFvazNvJ/dkgLwlPftXBCkaQTlli4e7rdKWpTkHk9pxU7ZlTta6sFIY9csG8ZlNUR/CLQGR3aLUJKAR9qPqxxa5Sd8o/jtKisMr587UNr7abgFGhC1D6XorLt9c9ocGgSoyAVKFjareJXFROGBbLECT6CqIR/fldAFV6cJXIxgeivQXgpBwcnDJtSSoRiXFJfOz37VUY0d+INNreiullyDvHmhJH62fhUmfhyRRPzeN8ju/g1MYQUUFsF3dATuguwLOYPySYpEgCyTXubLnIUY0IxLtrvoREnK+oQfrpT3XcO6nJmvwA3IrzdoJB6Lx1KmgvreQ8t2BRh1x9HSeJESK3txVvksmloKWPyCqMPHj9Az2Usky89j/nmZsxAsoKr25BHV2h0RxloL7K38QIwE/Aeu+aNVwpvtNHFvHEuogJUFspo0rYHwCfTOOfjCv1pPDaNRizx6zbmnOnISAcKPu98Wp/odpe1GkGYUoR3sg63ww0CdWUqAxejNkupot0FCtnNnSy0U5DH1hklkwfXJZiICkEGxrttdjJsQTCK9VTdxK/2dTamfbloj/bWbE6a6pNg8yYFoeIBHqZNx0MC/cODmdw1Ltx90jW9mT2SPXPXXMDJktH7/f8C4hkd8SWwIMiNnpTGyNCPsg+xwUOLUe40T44gUFukNwytQJNPIwtTlBv5ESFeOelUDg10n4t7A8gTYM4DHo4kvJadew5vLIiqgGvwzJHjCR8dzsI0j0vFjYGTkWkiBZUQpb6VAQRJEenace03+nClshPfPZkvIWc1N4IjbbSwHDUi+/HxQ93r1CXBpWgsPKt3+XmBXT4rX/wLcv30UeBlDf8LS+Q12E52PX3Poqlpa6u0+exicmRy0RhTQqYvo4kUKsUUDQLsNuEQNl1JqZRIAnjjyDtgS/YLlkSiUtdk9FRd0HYuQiiYfY/UhuMoE/eWjuCZDS8Ay9BVyefr7R2cJjZmIWxdUpsibkWQrjVAkYLSshHBmJ3cOR2xdgSYVJrPNaKN2E9BlnEcmwU6kX8m7T+8Wqm0/D1tsj9VsYQ7CYR+8F1zKZFF6fUUo4c/XlA/OaH/F6zCagLaVmH7957F/KQdVaY0ninfjnlhob0bID1ViCk/QwsQHlejD9Hl+wWK50bto+mE40s X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 835ba732-e120-4355-dbeb-08d8fa98f4b5 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5650.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Apr 2021 14:16:52.2685 (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: YdfLK66g6YLxVDDvu4vRkprGAwE5955KTi76zAHxhxuik3gVC6ysFXkjkPnZEC7nMOLNzDZNDTIm811W/TaMwg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB4833 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 --- v2: Allow mgf_hash_algo to be different from digest hash algorithm. crypto/rsa-psspad.c | 114 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 113 insertions(+), 1 deletion(-) diff --git a/crypto/rsa-psspad.c b/crypto/rsa-psspad.c index 4ba4d69f6ce17..87e90479a4fa7 100644 --- a/crypto/rsa-psspad.c +++ b/crypto/rsa-psspad.c @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -107,7 +108,118 @@ 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, ictx->mgf_hash_algo); + 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); + + if (strcmp(ictx->mgf_hash_algo, digest_info->name) != 0) { + psspad_free_shash(hash_tfm, desc); + err = psspad_setup_shash(&hash_tfm, &desc, digest_info->name); + if (err < 0) + goto out_db_mask; + } + + 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 Thu Apr 8 14:15: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: 418309 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 E726FC43460 for ; Thu, 8 Apr 2021 14:18:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B86DB6113E for ; Thu, 8 Apr 2021 14:18:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232129AbhDHOS3 (ORCPT ); Thu, 8 Apr 2021 10:18:29 -0400 Received: from de-smtp-delivery-102.mimecast.com ([194.104.109.102]:60724 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232161AbhDHORo (ORCPT ); Thu, 8 Apr 2021 10:17:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1617891452; 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=Gi1QTA91cQ04j2dsKALt2E8D20b12P2HzyMTUHz5qfY=; b=O6L96p6JTwtH7xr1SY17wiavTUmyfbAJ6bs06x3JBFOr+gwCMg9gWh4lU0d8YVxmgVSPFP ck8GH+8wN0Ttp4dUHgQ3G+PDFkHO9stleg9TwZR1SxmWisDWUnDwskbdlXjY+jsLJAsukA +CO1EOiJeQl7rUoQj4JihbGLwZR1mkE= Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05lp2105.outbound.protection.outlook.com [104.47.17.105]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-5-JMKOEsrTPGqCDN4FvasxEA-3; Thu, 08 Apr 2021 16:17:16 +0200 X-MC-Unique: JMKOEsrTPGqCDN4FvasxEA-3 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QtzaMOqWgSfvPvcWADuDFNoTQcDVJcEv3QUjGwTeC8W+6V3YcLPbGo1pvT06ql8eOa9l1+EZn59aOBSpr+bx6hrfdSgW4XqgICCCIiP5OmgJkiaf3lV0qiMvhHEUJ4NVzppgx48AiXIx9zP/3tczHpLXaecnZoLpxkwAxBvC5eNlbvmDkA8eGeufUd56V+VtocObDP2pjlxonR9Wu6M8HBvQ28SXwL1SdJU4hISLwaZKaGZbmHSIZA2gzHcM0EG+T8mDVYkdxEL2ooL2RAxi1NqsGXMVlzTZ1UIr/WIHnz1QEkz/W5Ki8sAD7DjE7hK48K2+OElU9m6PEAQf9huIhQ== 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=+xDN6qusrHHlYH2y3rkKXJ6kk5Nij4grlay+a7TTMdU=; b=CHFQyVmvNTdhj+JTC4d6t17TzPTXrzCb1EYYKHuM0zZhK65OrL1j2gHJpP0iy7FVWGCH/4znl25rS1YDnVSJe01J5kVmhG3YyM+1UzlbBcmW5T0ZKG3rPMR/gZ+L2aixTcyJoStIFlIJtdPH8ArTVtUS0pT7pwAnKisJAszn0D4LO/+z53tzChjbHlEgDXunxUpHJOmFhzDtUhDb2Yr/PzqPe3uwpkzuo/w3rJ7gMjftGpI5tW5xt2ZuQyEurJMeVXHW7K8nvOwBeLrrLjIDGfHViYQmu5CwKWL0FBqaH0rSJykDR/OJb/ZEMmfzKfWBxWk4MZLBKxyKQt8pKYKpyA== 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 AM0PR0402MB3572.eurprd04.prod.outlook.com (2603:10a6:208:22::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.29; Thu, 8 Apr 2021 14:16:54 +0000 Received: from AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d]) by AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d%6]) with mapi id 15.20.3999.032; Thu, 8 Apr 2021 14:16:54 +0000 From: Varad Gautam To: linux-crypto@vger.kernel.org CC: varad.gautam@suse.com, dhowells@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, vt@altlinux.org, tianjia.zhang@linux.alibaba.com, keyrings@vger.kernel.org, linux-kernel@vger.kernel.org, jarkko@kernel.org Subject: [PATCH v2 17/18] crypto: Accept pss as valid encoding during signature verification Date: Thu, 8 Apr 2021 16:15:15 +0200 Message-ID: <20210408141516.11369-18-varad.gautam@suse.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210408141516.11369-1-varad.gautam@suse.com> References: <20210408141516.11369-1-varad.gautam@suse.com> X-Originating-IP: [95.90.93.216] X-ClientProxiedBy: ZR0P278CA0137.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:40::16) To AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from xps13.suse.cz (95.90.93.216) by ZR0P278CA0137.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:40::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16 via Frontend Transport; Thu, 8 Apr 2021 14:16:52 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 654f3388-95c1-46f9-d862-08d8fa98f565 X-MS-TrafficTypeDiagnostic: AM0PR0402MB3572: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:546; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: W0SskvxERI4R+oDxY/CaQ7neZ4r8zlVOX4i4Bn1oNXtQQPPp36pGUCb86jFa+WA+XkXrnX7NRex911ISLYJB/qcCJah1iDk1ttj6svPqrz7vJx0acJALEhA0hGE+edOsQQvKywawS6KZBRSRwRGSt/x64EaEGN2XuNY5tn5PTZhLjcFs7ypQqVbfMXtthJ+J+PpHmCdBAOsDTDqvNG2hYKNIBCHvVH4oTYcaFX0E9kVlrqKmxDWV7edNxpZA8Du9Dy8kHhfBFIS25YUDJ6Seu1alFXTNQN4IWR7CzQnUXTefwmWdXkLVPS+dP0H5nW/P/D/GB4M5SkhesUc2erD7EOZ0DfPELA8WO64jeUco2nmD8lnnmhSgS1A1wmdrRAvkfGZsU/efWhXo2NXiBsP9rLI2i0oo4QmrRpbLaTJr/PVKHtKCfQCq4IyyY9Ov5ME1iNTs4Lw+fK7TGv2saC+6oI/kyuIM3yPJ3L21rsxfgL+3UM590lNqUIBDktcVMeiv9cSevPKKBFGnFGFLkeMTAG7rC7loiC7MjTcdjBc76e7nqQth+ZbavmkJX/co0cZDxZMGcI8lfOIsV3AZhYM49cGP2h4Flon0wKLqHLVrAG6/YNbazS756X5VVe/875Qchpaun+r3tNku6qoMD/4pRH4AxQpafRvkSM/pXQVUVBPLeWdfPcK26B3j1vAUTXTC 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:(39860400002)(136003)(396003)(376002)(346002)(366004)(16526019)(186003)(38100700001)(2616005)(956004)(38350700001)(52116002)(6512007)(2906002)(36756003)(44832011)(6916009)(83380400001)(6666004)(8936002)(26005)(66476007)(66556008)(66946007)(4326008)(316002)(1076003)(6506007)(6486002)(478600001)(5660300002)(86362001)(8676002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: rL5vEEx2KGRZZa70I7ReC1NDG2+c1mhgBqVOgV/OK1XLsGZY5TaObAbXN1gjd2pNwL1zvZLYyVDOhMg4lvUxt45gwNad3cNob+0lGgwqaITbDox7QRB8U10XiZULLQizUj9nNNb1fZv/VbuRY5p+3UpkYJZOKQs6MoQI/s4Z7jy3YJ2uPxtcmBvBaIk+oCigp32yqksoTkjMnKGq8pXGrdxU6AlE8Qt6yIb91Oi/2PnUnrChslzcKXEw4Bljm1ssHoS7mrtghsLH2eDDakgtLRzqOhrQH5WX8NYMNnW8ixj/MPuPFJJAOnL7MdZxVnzhlUTgEK/ySf+Umdz46Tq3NT1b7sQoEA9tfKqx0FJri9AZNuPlxRzeALC5e7zfUs9J5gYUHSgejVe0cnCWk/Sc0eTUNzr33VNW+93aXcvs5bNPPLTa5twMATxxAISu2OJrZ81unX42PugJ00DxwM7fhw1IdW/UHbtjxngmC+4cXPPrjSulS/P5oFuBDmF8ctjVngKIgVQzJlfHVNX+tywbOdYnYLaG/6VKJjPPmcw7dclQXreDqOCevBPWNQ9JHU+JvW84NCLSKl20VU3bDSULkc13pAuN8n8eKdeARoHJkloKkiqKdFvhLf32Hb08pt5x9KJZpZ9XmfS1GgAMvpaSfh5cYW/CY/BBtth1eWchfeJ+SWZHWyKIA7/wVrBsIm0ACXZSiIOl3uwqhlu2Efy7ojfhorgLzL2EFnegCwdDfKVjGzjQ0YRM7EF2vNkVFIO68lNrmjTHADlm3WHdQBgHFwMw49dohMNkNyrrooHdgfsDW5nqMik2UIzZHAPxxihTO2kv8v4V9AKwAk3cslic890SA9MMaSuijxY6YRf72wvt9KTgtis+6B6tHd3nZ+zC8Nvp72aJibKsUA7+u6H9mGIwWMljzh+b8yQADZ0olDRzOXH1cpuSACDVnc9wRk6iRd+b2AqC8eOd0ylGT4pThaE4rIhRZACm6J6e04k2kK6KrDli3zrpf4Od9pZ7nW+foBNudKPMNZDrGD4B8zcOet9CqZgQyhvYS4T+dTpnbA4PqKl8HDQQPf7levA80rxCsZs36Fmp40iGPOfjGIU8C0G+5LyaWylH8WxPsilrmpZpcehLiVoSWpFemqNXtrCwaqFZ8vBvggm7/576P4GDIJmNHHDNe9VKzk+40ZxQ8vKySFT039dSpFY537tcHgLUzW/ad8NNCTQuQbbAIdycE8l8BD3EAftZ/+Yq4/5C3iscnn9AnzwaHTNyki6tCFKQRFo3mTnQjVRWToh1FWui+eMDpkAEEuzv9nr1XyxIbhIE1awB64N2Xho3GPcG9NxN X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 654f3388-95c1-46f9-d862-08d8fa98f565 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5650.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Apr 2021 14:16:54.2314 (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: r6RVAcPFOEGwbXJlFEF1Eqyn6zq0nGQEVUEJa+Vt8nP8lsgWx0fH0pC3mZuAUNkA/FFrVm0YwdzDpt+FsXxxBw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR0402MB3572 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Accept pss encoding for public_key_verify_signature. If CONFIG_CRYPTO_RSASSA_PSS is disabled, crypto_alloc_akcipher will fail to find a pss backend anyway. Signed-off-by: Varad Gautam Acked-by: Jarkko Sakkinen --- crypto/asymmetric_keys/public_key.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/crypto/asymmetric_keys/public_key.c b/crypto/asymmetric_keys/public_key.c index 788a4ba1e2e74..b9cc83ba7a127 100644 --- a/crypto/asymmetric_keys/public_key.c +++ b/crypto/asymmetric_keys/public_key.c @@ -69,19 +69,20 @@ int software_key_determine_akcipher(const char *encoding, { int n; - if (strcmp(encoding, "pkcs1") == 0) { + if (strcmp(encoding, "pkcs1") == 0 || strcmp(encoding, "pss") == 0) { /* The data wangled by the RSA algorithm is typically padded * and encoded in some manner, such as EMSA-PKCS1-1_5 [RFC3447 - * sec 8.2]. + * sec 8.2] or EMSA-PSS [RFC8017 sec 9.1]. */ if (!hash_algo) n = snprintf(alg_name, CRYPTO_MAX_ALG_NAME, - "pkcs1pad(%s)", + "%spad(%s)", + encoding, pkey->pkey_algo); else n = snprintf(alg_name, CRYPTO_MAX_ALG_NAME, - "pkcs1pad(%s,%s)", - pkey->pkey_algo, hash_algo); + "%spad(%s,%s)", + encoding, pkey->pkey_algo, hash_algo); return n >= CRYPTO_MAX_ALG_NAME ? -EINVAL : 0; } @@ -363,6 +364,13 @@ int public_key_verify_signature(const struct public_key *pkey, goto error_free_key; } + if (strcmp(sig->encoding, "pss") == 0) { + ret = crypto_akcipher_set_sig_params(tfm, sig, sizeof(*sig)); + if (ret) { + goto error_free_key; + } + } + sg_init_table(src_sg, 2); sg_set_buf(&src_sg[0], sig->s, sig->s_size); sg_set_buf(&src_sg[1], sig->digest, sig->digest_size); From patchwork Thu Apr 8 14:15:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Varad Gautam X-Patchwork-Id: 417571 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 B495BC43462 for ; Thu, 8 Apr 2021 14:18:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8E37661157 for ; Thu, 8 Apr 2021 14:18:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232151AbhDHOSa (ORCPT ); Thu, 8 Apr 2021 10:18:30 -0400 Received: from de-smtp-delivery-102.mimecast.com ([194.104.109.102]:48011 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231907AbhDHORo (ORCPT ); Thu, 8 Apr 2021 10:17:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1617891452; 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=GnrmaZwbgXiIv/rOu4TL6GUmzZbQVWq/QF975uCU+sE=; b=dilT9pfcIr2QbDWC154jGRfO6iNoSdxGD555ErI21vs4ahTHBxQx9ejVDhbfnpvO8c4+Sy grJNV4KRlk+p2QkeubDEg8YdQiUvMs4qVjFdgxORty5JYPn1s9rDDfJJKZ8bhMsvUBQuD4 wyXD7XiNjyGwEpI/G0oYi+Q2MqmLly4= Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05lp2111.outbound.protection.outlook.com [104.47.17.111]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-17-mwAIHhIrPtuF02ZRB0HTNA-5; Thu, 08 Apr 2021 16:17:16 +0200 X-MC-Unique: mwAIHhIrPtuF02ZRB0HTNA-5 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RAEmlPK8h90VVuqjeWOz2cVxYHFpVzXj0B6HCldgDypaxsfHl7noaCRseB4YtrskPjOyvuuE2tGxwg4/XNsLRdaIzxu3EgyzPqv27tY6enTofd1R/YFPhFK9TJj5BTpe2HDQX2Mww2YAq7VZfszZnJOEr30TLdr4zI58FeN90teqI+bSdWR4I1TG8mRfaBX3gk6XkQmf1MPGB384wr3Scsh/1YHC++FZbBZamBcTRmNHzY0syzb0abcJQIAbUkJ0JO0TvkP20of1pgpbRoAKVyW2+Z7LvrJOZXHKTmBypwWM79pT2dHi96cmpfXXhqzMXpumnxx+TBSzb/54ouuL9g== 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=N9fhs+zp4NcPCPGfLKrmGHO+qpgcx6wUB4XRLs0IAoo=; b=RYl35YT//oPvratuWJ2KakkSWG3BirExb8oGu5o3iPQfNylfzuH1L57x+5CDpBPs5QEudV8zQcXhedAe+DAgejBLSVCWEKgJMg0hV68+TNkV5wBzUSB0wEXQvGCjrYkeuV5lX5oshWKy7UtDNQu2hzZQK2OyDuDsQaoq82LcxjNBogjykm4zocCb+VS0VINePJPYrZXwtCTk7hQiT6tnfGmtVoQjagLjDnnnM6Qh/Cx+lbmCPciV9XZXtVrjuqOXvAHvMbSeE1fU/U/UDSygbemft/7LB8RFfA+L5HlCQK45/Zh+xrxjyQNODFt2guK04Uy1eaoynA4MWZ4XIKD6CA== 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 AM0PR0402MB3572.eurprd04.prod.outlook.com (2603:10a6:208:22::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.29; Thu, 8 Apr 2021 14:16:55 +0000 Received: from AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d]) by AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d%6]) with mapi id 15.20.3999.032; Thu, 8 Apr 2021 14:16:55 +0000 From: Varad Gautam To: linux-crypto@vger.kernel.org CC: varad.gautam@suse.com, dhowells@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, vt@altlinux.org, tianjia.zhang@linux.alibaba.com, keyrings@vger.kernel.org, linux-kernel@vger.kernel.org, jarkko@kernel.org, James Morris , "Serge E. Hallyn" , linux-security-module@vger.kernel.org (open list:SECURITY SUBSYSTEM) Subject: [PATCH v2 18/18] keyctl_pkey: Add pkey parameters slen and mgfhash for PSS Date: Thu, 8 Apr 2021 16:15:16 +0200 Message-ID: <20210408141516.11369-19-varad.gautam@suse.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210408141516.11369-1-varad.gautam@suse.com> References: <20210408141516.11369-1-varad.gautam@suse.com> X-Originating-IP: [95.90.93.216] X-ClientProxiedBy: ZR0P278CA0137.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:40::16) To AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from xps13.suse.cz (95.90.93.216) by ZR0P278CA0137.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:40::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16 via Frontend Transport; Thu, 8 Apr 2021 14:16:54 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e623a562-3742-4eec-f9a2-08d8fa98f6b3 X-MS-TrafficTypeDiagnostic: AM0PR0402MB3572: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:972; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: s52Pi7UpXJRp6WWS6WAwLFbfr2B4yxuyzJULYHHZ+VCEW0SP02jBTKZl2p+xyNeQPgJKy89Pymc4/m+Y00kCjSV7ITBSaDzQQqKCXEjqPZstT4D/AVCq12J8/n6rqMPRaEpIHb0eyVM19N6HIyGmKVjTHVc1qDFS/vcYXFMlqgPfHr+DZNQ3i/bWqq4oSU+rCV0LAvhE6f9fmRfL+H0ZYKkfgGy/ZGoxBsHzr3Wu/CkhCk/hSvldRKR6WiQ/Juw7HIcrT9So2a0kk5ZGMfvBSX1us5PELk0gIxcUXmmdtZMcFtnlsexajrVe04u67nsdoebl4m5qSSoz2O65AyEEuQ33f0CSaTtHtAuA+jaWUHv3+hetf4pvh6jrANXp9bzj/9e7x67oJGkkZdqEKe5rrBLcbgZv2kZaejVX9wLOzEj8mi9uSFUf62lT0kEm7DESWd4emQoeG6keAALP3IViFy+pe6VddThqlsNUHdIYGi83j97HMW+uUSRNsfbG3kH7/wW057bhb9nPhqhQ2wRiGLD/t3Wot+YNtpUjVjqyh/dJjWE3KqIO0vCQvSgPvW1+McewcVQBd6PJPQWGqnDwrswG4nBLhdGVi05WQI4mqCsQVUqgANw6/669tnyc+9mV41kRzlQ0ymtaUlM0D9RD29QQmM/tu0KLDfBgNp+KcWg2GTT4v1T0030Jx07Bt0Bh 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:(39860400002)(136003)(396003)(376002)(346002)(366004)(16526019)(186003)(38100700001)(2616005)(956004)(38350700001)(54906003)(52116002)(6512007)(2906002)(36756003)(44832011)(6916009)(83380400001)(6666004)(8936002)(26005)(66476007)(66556008)(66946007)(4326008)(316002)(1076003)(6506007)(6486002)(478600001)(5660300002)(86362001)(8676002)(7416002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 6phw9izw0jEpewr6e+v+luN6tEbtsz/sgj2WYxwPBYXO4lwQuhYyCxM1jHnngeosy2e4XHX/vp+NXnDaoGw+VQOuX1L4SiQGyEb932iqe3hcExXA4GzQSb0OCCSWEdCjdRFE7fTMBl8tCY8mI8QX5nKDAQz5GCZ2cQJMKnB+ME7EasyF5WzEbIETo1q/uzY58N2Ojyes/mr2MNnOOwOV5/EALVEOGRIw/PS/EJd08PRkGqTkQLSpOM0yRDsb7FS8QWnHdOCr6Gkw6lsmhEXOyxJoiitb6fi0NclOCabIOSOfrIGzPNAUiDAUfrXNSRWTkZ55sOQX8eOa6FJcbF0m7ME3rosE/1FgJZTILds3MKm8mUcOVg2tUsodQDzx6hAxv6/ArqiprymxKbkpJTrnCqsLlAD5IwvKVrcS1BhTZR8jr8DayqO5wtLVyEzBgcIPo9RUu1kPxWsYlyXf5iof37EgPnhYmaMcUPP8pMcJvpim1eBZfxCRq1sk3gXFEHD89g8cjJ4PZ+RDsGKJdQlT1QszD6EeTniGmWxH0cm8ocXXTeDJhgRw+TKshBD/aL+/xLd9A/oZrkba33zTJTdIdTaIglFxMYosybVEywOJUQZp8k5oVBW9Yu3FoSVBigPIJOn7bGJFlKBrJYVLIOfMRyNgOJdlYnS1ZUP1NfgUpCO4ipnYlcF4PM6MOi25gAGez9XFIClTRv9yYYHQyPvdc+ox/3dW1eBTV1GXs9jzSgiRSfJ9iQvkpujyZuYODdyCBeMBCkVaV9Q/urEr4o7YQ0XZ2cOBd47UTJzRjiFj8ReX0ofA7kisGgmOPngPfx8se20l7C9VFeNI8ADgoYUa1ISQRnW5PZLFT9NvIsQM/OpkEFmgGBjrCaXyfe0Ghp9vwt64L+/IrmjuhyxE2J651yA13t5F/HKRTOe8emizS17jLz66faz2SnjzGyQlqsXmCwpLTYghDmYJ7POIRfJSA05yLqiwx0gQhdz2dX2S4EuWta01MOh/yUR3YD+NhHby+g6x80AvEUIkzb/P+XoyHiyYY+G4Yz6YEenk4YdtN6sA0SqlNJlSemTRU06bixFSqlk5BB+8mFHNP+FClLiURqpBX0GsRQPodEEpZaU7tI6bQurlE2PfG6fPR9BsvzgNnCmNo3/rjYrKBC3HCqpXaEgUVdxORMqGyItHoUWF8U/7D7iHm8sonfax6iU3LbX44Xdn/h3eJnit4yLFE8bhSDhaHtH8oPRDRAnjiVDaBdzncBbzr+ApFppPSkkuglxe+pqvoN1iQT1vL86pD13DMKTDW8vDcmGNW0naLj8REgYEpF29I0k3RWqVFrspJqn1 X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: e623a562-3742-4eec-f9a2-08d8fa98f6b3 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5650.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Apr 2021 14:16:55.5247 (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: A0iuqT2y/54YgdH1AYpKrWiLvWF93qyve1tVV2kSAIxO8h3oe7vJaHP8y4hMqnpsDUqevmsSasSK5kBdDvLoGQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR0402MB3572 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 and the mgf hash function. Add parameters: - 'slen' to feed in salt length of a PSS signature. - 'mgfhash' to feed in the hash function used for MGF. Signed-off-by: Varad Gautam CC: Jarkko Sakkinen --- v2: Accept 'mgfhash' as a parameter. v1 assumed this to be the same as the digest hash. crypto/asymmetric_keys/asymmetric_type.c | 2 ++ include/linux/keyctl.h | 2 ++ security/keys/keyctl_pkey.c | 13 +++++++++++++ 3 files changed, 17 insertions(+) diff --git a/crypto/asymmetric_keys/asymmetric_type.c b/crypto/asymmetric_keys/asymmetric_type.c index ad8af3d70ac04..72c1bf964826f 100644 --- a/crypto/asymmetric_keys/asymmetric_type.c +++ b/crypto/asymmetric_keys/asymmetric_type.c @@ -571,6 +571,8 @@ 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, + .mgf_hash_algo = params->mgf_hash_algo, }; return verify_signature(params->key, &sig); diff --git a/include/linux/keyctl.h b/include/linux/keyctl.h index 5b79847207ef2..753d004d76ece 100644 --- a/include/linux/keyctl.h +++ b/include/linux/keyctl.h @@ -37,6 +37,8 @@ struct kernel_pkey_params { __u32 in2_len; /* 2nd input data size (verify) */ }; enum kernel_pkey_operation op : 8; + __u32 slen; + const char *mgf_hash_algo; }; #endif /* __LINUX_KEYCTL_H */ diff --git a/security/keys/keyctl_pkey.c b/security/keys/keyctl_pkey.c index 5de0d599a2748..ae3a81c726322 100644 --- a/security/keys/keyctl_pkey.c +++ b/security/keys/keyctl_pkey.c @@ -24,11 +24,15 @@ enum { Opt_err, Opt_enc, /* "enc=" eg. "enc=oaep" */ Opt_hash, /* "hash=" eg. "hash=sha1" */ + Opt_slen, /* "slen=" eg. "slen=32" */ + Opt_mgfhash, /* "mgfhash=" eg. "mgfhash=sha1" */ }; static const match_table_t param_keys = { { Opt_enc, "enc=%s" }, { Opt_hash, "hash=%s" }, + { Opt_slen, "slen=%u" }, + { Opt_mgfhash, "mgfhash=%s" }, { Opt_err, NULL } }; @@ -63,6 +67,15 @@ 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; + + case Opt_mgfhash: + params->mgf_hash_algo = q; + break; + default: return -EINVAL; }