From patchwork Tue Apr 20 11:41: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: 425368 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 4C111C433B4 for ; Tue, 20 Apr 2021 11:46:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1294A613BC for ; Tue, 20 Apr 2021 11:46:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231869AbhDTLqv (ORCPT ); Tue, 20 Apr 2021 07:46:51 -0400 Received: from de-smtp-delivery-102.mimecast.com ([194.104.109.102]:57764 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231922AbhDTLqu (ORCPT ); Tue, 20 Apr 2021 07:46:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1618919178; 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=6fL98t5zZN0iCvyW4Pat9TU44DEzWzujgQbdoqyxf5A=; b=AWJkYpkmexESZRQL6dvmds0tzlrJZEI79jsE4FSwT4trEMhaYKDjwHhciPktSAhNHyMidA RPxeE1XiLjlDUwTn28GlhptgCbkxooOjnzDavEwz8ollssSz86MB8Y3aXDmBgjqLCKNgEJ OKaeyGLwwOOlmYH3CI1ew+1n6EkF7Eo= Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2169.outbound.protection.outlook.com [104.47.17.169]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-35-oXuShDJuOdypKjVYQKlG9w-1; Tue, 20 Apr 2021 13:46:16 +0200 X-MC-Unique: oXuShDJuOdypKjVYQKlG9w-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=d3NxH+SeNzUV+nEtlMtmJeqTF6ZGrrnYnwI8ATiIpMjQgwybZ2ezvG/SvAv1FZCVQJ0+o4wDqFpzd4mnNXMHrSZXWrq7TCiHjs6Qyqgybe5O3RZ4ZDW/mOx/ns2/dRSqe9CXa0NXI1s1YJGV/o7qz8RbNXLRuMePPBq/JupkFOUBa3uIztBLRh1GZsu+uKpvySzhdpyRMdDHTNJQ1ujiNco0XwMhf2OBddMtDP6raMQq2+J2mzk+AZY8XUvfSkcAKrDQ1p9/bysT2D5HaJMRCrmc8dY1M0L+43lwEt6D8EGBBEcrAswObHxskaQ0LNzAscRVwoH9NYuSCvEgDGAGzA== 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=Sj5+vSrW7VRmF6gKH5OlFOxZGJYseHq1OU1GF+D6wvc=; b=MdEVqX2CylpIqXN4qXkWkhrwtYfhLv6wjpnFIh8t8ShdFt8lFknRnJ1AlncP+Eln+JiiBXcBPQo56KkuV/nMYHTIyCBLbJWZSlBk6UpF1hVfuM2tDHNZulWCmwN+SXhOz1qxk1Bi8DrtrQW/nfm0wZmXI1oddeTIllxmLzHlI3HHDawHap6P3K4HwSyDOx49z+iIsW9x1maJbb6WdueNs4H3esoksnCFsOncybdXI+ano4h05fDbcy5zQnL8ZRWasqPDYmCFJawJ2VZREI61uEDBIn4exu6cK4wE6K4IZiwX/r+WArqRDw9dXX3EOnRPGco/zBMjF8cpqHivUrSDwg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=suse.com; Received: from AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) by AM0PR04MB5154.eurprd04.prod.outlook.com (2603:10a6:208:c4::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.19; Tue, 20 Apr 2021 11:46:15 +0000 Received: from AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d]) by AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d%6]) with mapi id 15.20.4042.024; Tue, 20 Apr 2021 11:46:15 +0000 From: Varad Gautam To: linux-crypto@vger.kernel.org CC: varad.gautam@suse.com, dhowells@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, vt@altlinux.org, tianjia.zhang@linux.alibaba.com, keyrings@vger.kernel.org, linux-kernel@vger.kernel.org, jarkko@kernel.org Subject: [PATCH v3 01/18] X.509: Parse RSASSA-PSS style certificates Date: Tue, 20 Apr 2021 13:41:06 +0200 Message-ID: <20210420114124.9684-2-varad.gautam@suse.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210420114124.9684-1-varad.gautam@suse.com> References: <20210420114124.9684-1-varad.gautam@suse.com> X-Originating-IP: [95.90.93.216] X-ClientProxiedBy: PR3P189CA0083.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::28) To AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from xps13.suse.de (95.90.93.216) by PR3P189CA0083.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Tue, 20 Apr 2021 11:46:14 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3dfc24c3-495e-4cc0-d941-08d903f1e73e X-MS-TrafficTypeDiagnostic: AM0PR04MB5154: 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: wiwR76UUzcKjRdXWEJksBVLVwx0rybR/EHPjER5MFfYhw8gRYpPy6/nJXqyu8Ik4jl6Ei0jS7HJvi4lS4cL/n4P3cE/zTNZXXbA+DRW/K5zqWUYL61xPKaQqviqazSJG426AYYnvPgLSBNU3y0ModrYhyaKi7gAxrKLar6L0aqDy29p/cuJU61oUUvyObDwKMMj1jD0qpXUxKsbcHalZ3GAkQXvm7JXFxeUXg9rHovhas6/95MMrZTQFIrENFegu6CdylGwoJCHv+LCJQbrhQzN7pb3vaGRsmNBbT2wZOiP0a5toiUWlILobDGL4ShmOB6+GI4hxFQW37nluI4sbxU0NHbLj3Lydm/QGu1+60AXPcZZr/N6Bfgrp5dtW4v4nLUTUYco0QzB/zMWsiF/o84Hl1jfMKgjjAeYhwzoa7ZA0dQVPHYD9yS4fIItUWX4gFDD8gbfM7PF6svWoKbdnYuErYRLxkkXLDy7hy7KPj/2oGLJbxHoV5EkxIJ2oYDkuNDYadLu2Xcg6IZUfcSdFJemkNlbv4tkFtmi83GNLAVcSY0mYLYG5dE9xFedEGGh/yhXtRAJhTXQ6RIwuDoWeSvnbqd1uoD13VR97OuhStds0vKAdLnM7CVAZSgXEssRFdd0ZkqzfNalcoEMfMimz9pC7nDl6GE3NwTJMzZmJqDt7bP9+XUfx4BiR17e9R2oYozSFLxuKyEJFjwUlFw7EwVPkH/E2+ZGgljqY0lYEAIA= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR04MB5650.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(376002)(136003)(366004)(346002)(396003)(39850400004)(26005)(966005)(16526019)(86362001)(186003)(956004)(66476007)(8936002)(5660300002)(66946007)(6506007)(44832011)(4326008)(6512007)(6486002)(8676002)(2616005)(316002)(6666004)(66556008)(36756003)(38350700002)(52116002)(478600001)(38100700002)(83380400001)(6916009)(1076003)(2906002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: SzROJ5eyNfL2oXGDyrcSGuavYgb3nJ9sRsTBxFi83NekGtxpzoEdwZ3XxdnNgviYz8nehfo+2yaj3o235ry16/7k/66/pNzfYH0Mhr21qdywsh++1qH0knuodt3N7aaA+zNG7KFmf6MwVzmeFr9yyV+iVr1UZc87vv4C26aRMxZfiBCQZGNgEHLHlXbE+jae8TLMIolXR4Yoq/6+Fl8pfLCBmJe3cz5fq1XNV9l0ZO0Sa8vBRuYtOXIsHX6BOd9hlaBFghqF0aLFIq3zGe8MTz4nxAX5t8+ApppdMI9kXrVP0zjxwdXgn2ATETV+RiKxV2hauRh2B5q9qz7UTJcAGdtgvWMzkFZHafWeMj66rZwBRltQF+WnF2HJ2V4v6HJEPWKe5xPaHxWPiZ3K5Lm6D1paUS/w7Q8M5jqpAbY71ZsPCP97spVyLIJeM71KaZt1gZF6cJVDWGPnVRq3ymMIB6Pfp3+puM3ajv/cuxCgJY/tT8GTIJqQoJKZX2M6Luop5ANuRfJF5upLyfZJIcC3nWYStaaZ9dP6/U+KJYG50ohgnnsxfJybriyGdX94R3SUiDwmc4oQu4x7X+x+r0dtNBGfwcy2Ghv7d29RiuUVswVgIAi/8/g/57ajzMEncF99KL68NXpBfGKka2K8RsdqKBBUlOx7mP54yK4kXOTZCGa8opdX5SNTI0tGbgLIqlpA+PQXWgr9Pa0fflkDgZX43xHhaCh4dVAKnVlx+y12ZzgeJtcdDdgTI8xTCzTXQ3JVvh529kLZH3LZZTIkAXuw3iOZ8jBUKwzdX9Idmy1LiBK9MPQTMvdV4lFEHJ3PPPP/63Zeo2A5BjGVPiJVTXXuX3RyoLQv4YgevKJ48tkcoCoR1Y9J0ew/ZPaqFNnDuSpaUBGNj/c8lb8M52H9oeyIYHrixpzakGF4UHNTq0bfE+pfMTMXh9ZW6xyx4ay6oIFdorw2GVW45Nv1MizU2bj+Mru8KtjsykHv4h5vXSXSzzKAdIL/nPjAKrpNpo/U02pUyGIGBbSgazdY+0C3eNelwSPgCnEZYCcye6kNoKKSfAqoUXvnsEZ7pvnyg4FAZb2YSpTmtYnAfRYHvMvaepcmU95+Fj34mOXpWNIeJ0rOF/qDDR6ltNroSEvWb+lHFhuCfLFpKcGKpbMR0D1PpKwqWubXUEfJ5mPL9GEyw+61vCOJ5fdfZvosHYajgh2dmi1FeEAf3kRT+trKmx4aNdv6wlAp/zVxrRsBLtXt1fFCL1dn38LJ+lIew9nirniq/7xfjFXvHtPfvSGE18jX4lD3jyDM8hmaoW/aUtIRMWABrgKNLtrvi+tYLw/mScHN06oc X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3dfc24c3-495e-4cc0-d941-08d903f1e73e X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5650.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2021 11:46:15.2752 (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: I2gTxBKNkX9TiwsrdAp5RcEqd2tJiClQH4GPaZWlr7A2tXPdhQCqo5V2O8yMNBwm6BC89z2ov+hlV2AVwtH0Yw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB5154 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 --- 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 Tue Apr 20 11:41: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: 424663 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 24F5CC43470 for ; Tue, 20 Apr 2021 11:46:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E9E7E613C9 for ; Tue, 20 Apr 2021 11:46:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232018AbhDTLqx (ORCPT ); Tue, 20 Apr 2021 07:46:53 -0400 Received: from de-smtp-delivery-102.mimecast.com ([62.140.7.102]:27646 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231977AbhDTLqw (ORCPT ); Tue, 20 Apr 2021 07:46:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1618919180; 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=ghrBEzpdgRBPixm/l8qVRufH3MmQ6X5ZVKsIHH1zWVls4BwdPWYhMr/20omqu4w0mrCKvw D21zRV6JHmjcfbfVQSQzIhD7JeKo6eRYZWsEhRbv7S0c7yb7JayEWZU/WL+Z1rf+polPeZ cxnR5lM+pvvEZ29GvTZfeTj//i5Vm9c= Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2175.outbound.protection.outlook.com [104.47.17.175]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-22-bDpJklJGMJm948XlI3-iPQ-1; Tue, 20 Apr 2021 13:46:19 +0200 X-MC-Unique: bDpJklJGMJm948XlI3-iPQ-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZhbIIB0b/T3jEN+/TavHosuTlICV921fvLCJG+QtcIRXKo0FZlRwRCGT2ZQrOfW4sjaPA0nDgbhgPZXP/IyK/pq7lxSaqT3eAzEc60Oj+J3scYC0AA81AA0i6I463SQ8SzI2P08Dkh9W8aETSmXPv+LpNiXNZ9853DNysZlHMlNhwY4Aepd9DddrmrVcOst1k+Q3u6IMiogRI4AOUJn8+fzxn2GThFLDGpGiPlhrKYAm5NT33l8TayZ0+Pq4IvUnFWM1SJmHGl4ZQ6YCr2MxfozigjBbf4YwQU1ve8u0aXN8gpkwS9w346udAMcB4HEfB/dQRNlYiosnH7aNi1IMaQ== 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=ZHvp1xHpZMSfj+yjLHG99qVBlUWRSzFvznilV8ZC+REpcP5unOpIJKTmW6a1ZbYD5ddmWmMfnnnvpDQCup6I9i+W5BY3zImrwKjGLwcuH/1XIJjb7RCVMv/WqaIq7qU+NJihC16SQurf5IVTUmqX3B5mpGctsz3LsKxcCI2YnrSMIz9L4ABz6FRhLdLhbf/LnhbDiMjy/HQDIt+ON1VWtk6oKtf/PV8NoGLM7o1YQtZ85bDCue0whmG5AUdVDYRKibAk88X/gBT/iU6jFWY1twivCEiiFPIwwT2PmQZXG/0XLgZlZh7ZRCivjEVOXgw77QbffIfqk8j97chjaXSZHw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=suse.com; Received: from AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) by AM0PR04MB5154.eurprd04.prod.outlook.com (2603:10a6:208:c4::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.19; Tue, 20 Apr 2021 11:46:17 +0000 Received: from AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d]) by AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d%6]) with mapi id 15.20.4042.024; Tue, 20 Apr 2021 11:46:16 +0000 From: Varad Gautam To: linux-crypto@vger.kernel.org CC: varad.gautam@suse.com, dhowells@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, vt@altlinux.org, tianjia.zhang@linux.alibaba.com, keyrings@vger.kernel.org, linux-kernel@vger.kernel.org, jarkko@kernel.org Subject: [PATCH v3 02/18] crypto: rsa-pkcs1pad: Rename pkcs1pad-specific functions to rsapad Date: Tue, 20 Apr 2021 13:41:07 +0200 Message-ID: <20210420114124.9684-3-varad.gautam@suse.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210420114124.9684-1-varad.gautam@suse.com> References: <20210420114124.9684-1-varad.gautam@suse.com> X-Originating-IP: [95.90.93.216] X-ClientProxiedBy: PR3P189CA0083.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::28) To AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from xps13.suse.de (95.90.93.216) by PR3P189CA0083.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Tue, 20 Apr 2021 11:46:15 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 14a0252f-2d76-4eaf-13f8-08d903f1e819 X-MS-TrafficTypeDiagnostic: AM0PR04MB5154: 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: BtpqaMuqK18rLBAeOVjoRpERggEbxmF5XCAQfDHtUNeAO5S3IDAfMGSrkhPKQngMbcWuEXyRDNsST7LAugZl7JT9ytWTTrNcisEpw7xLC/cUDcg60zl8Sbxosv6Ub6Y8rq+ZAOlwqFHKDhi3u39zPBlHRa0aRG+BUXp3RJmgxJ1A8R3+1Xcqutz5GEZRBwsIzO0zjvHlZ3uwutXpiiEPzWTR3t+B7KdaFO4YyJijgmwmfPAduBDfVsHSKqPviE9GrIDOTGdlxI5wj72kY1dKM4T/m7mkieilM8g6Y0OoyM/GAFkYUPtNWTzqbkDuif5KVGiVcpnxwngApfehKFrFqAUsa0PRng/2kZAzQux9cxq/2tVwibg3puGKJAGiGyGHt555VcqAawrL0F54wOnQtOHa0MV1dxjca1HnYSbII0lB+Jx6lkguPeM06sx8yD0QXlfRTq8wSVkNddNBuf0dsglYMkAtWUBmMGkpgKOtzcOXcinHLHo7gUQpTUCmrH3aDn6JRsWrVzMUhf5r+DPD1xkCa60EzxpMi9ESLaCe/tzKcVy6napvJlI0zrvVUWhwBHMabpmA+QyvtZkg3YSbsoBIfExLBS6Khdhb+ETvPs+ut2tV+GyGDX19KOxtPAE/0k2S7s4a0zllhwyX/bIK3UIIsCZ0x34S60g1O8/DUo+bZdA+0Zdl94+5/xJv3B2Ogb+cfXWQ1p5YnIZVw425AQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR04MB5650.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(376002)(136003)(366004)(346002)(396003)(39850400004)(26005)(16526019)(86362001)(186003)(956004)(66476007)(8936002)(5660300002)(66946007)(6506007)(44832011)(4326008)(6512007)(6486002)(8676002)(2616005)(316002)(6666004)(66556008)(36756003)(38350700002)(52116002)(478600001)(38100700002)(83380400001)(6916009)(1076003)(2906002)(32563001)(473944003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: WSv6QnnAHvcS6oOKXMixg19kkSLvXNYZR/YeEgfIyEUDpQ0DSmOmuXLko3+mOha3RntOHbqiOoysHo4w5Kk3M9rKg6Y4v/iYFr7PjZ04f8ryrqmIkm+1xoLhScR2M8TPzFhDsxejxO4LL0kMiKIqnKmEyN95C3CwjzEZ2JppyuyasXugaCPs+o3RGS2MX7tAfnJ6etWhi3VNdWyAJ+xAK3AX0SAC0QpZ0+GIRkBm5KkSgvHJoy6xnAEX3Td9bEI8ePzFHgqGYvPE91jHfhT3CIYVCxYT/iNazyPsXCFlecApwnNAXlE2ZTfNlQ+buiMlkcZ4kqXqmAFmgFgcbUeH/mvtD9EQVGh+f534M4sH4UnSZzurfC7JgSmMUx0PGnCPO8fkKeR6zmblhNPzusypzZHN60qCrPh7XE+ZpjF1qaTqfQ4wnA75z93K/27MM2a21qNEiqPOyMDiobTSG2OtYcxsyobRc8Rt34aMlsAU0sXI0svTD7hXQin5iw3JPvCTp3PSiDPkE3kW2UCfIpN6qQtLte7LoPaYaZV12rdVr1hIN8uA2BX+xqLdz6v6E1uJ4zoYI72HbvjP7fokX6Y1GKre6gm/jLEszP4dT36bMTrDI2CLsiBnMl51HnzxoBjcydHvpj74R6H79URqfrvdLJjboKWQUaZM63df747qhRCMgcfYCmJnEWQGDPsx7Yh3ues4CvfarlsPWuVrMBFn3VsZBtw7t3k9U0ciYv1J687uw3Pmot4eLQCq6YTKr111JBGsha8c2VGMBgshJeNNIbII4/JcjnYqP6DbQ0zk2jAv8MNTBoTJXYJficVtvbYHkA3BR4g5ttVmq95ABWRqsr3oNBCCo4O0d1nvLaG8161eb3h/Ng0w+Fss6hn48Lsdk4AwtPBvDFcxIWn0o1/pDRECMenMOs+qold6rwHtim8FJIMoNiGjEgaOlhxHEYXmYBwFtHQyvkdmNDVwWXG/u4oUGu0MHzIAniWaYPtg21wmHz7I6/ijYyN/vxVSPQApmbOiQWDLIbO36aB+Klkb4hIBujitmMXw7SyvttireR9MqkCYnx9aEKu8dCsT2WonoeHNF5W6s7599gL9hkZwmk3rIl90Ucj85fUC+dWjMFqYTqAEjG/aznhMNCNsTzhOqXW4nwH+w0Ks3XrD40lmtMN59rJ/RPOUEJ4Zi5uEbYfox5fBKPflicIMGwELBiL+vEc1S72WWWQ+AnPPiIT4S6H6uZ3DHMa5ZZhgPpulEKAE4SWfr28aTOnQGf24JXKkEQdxL/94lnXOCqFUPScAJ3/kFLF5Z9F+eDqKAdazzMui7oIi1/NGTRTLVLs6BXKg X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 14a0252f-2d76-4eaf-13f8-08d903f1e819 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5650.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2021 11:46:16.6864 (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: bT8neN/NKR8Q8WJVuFvlsmWtSMkqSnH7JOitgAQ1L9H672vQszPBL0ODRf5MLNFQxHRT7YRGzkzAYOwm9BAxQA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB5154 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 Tue Apr 20 11:41: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: 425367 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=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 75F42C43462 for ; Tue, 20 Apr 2021 11:46:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 370DA613BF for ; Tue, 20 Apr 2021 11:46:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232056AbhDTLqz (ORCPT ); Tue, 20 Apr 2021 07:46:55 -0400 Received: from de-smtp-delivery-102.mimecast.com ([62.140.7.102]:58475 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231996AbhDTLqx (ORCPT ); Tue, 20 Apr 2021 07:46:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1618919181; 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=SSltrLkE460CiVSLUZi3Io4OGkYh4OINmbvaEAMp2bvDlfP3W36J8ErXICMQUij1jGQqOP qPjhxQD49+OrrkZsjdUWm8l27f+6OkoFXJjlzOd8T23BU++Yn9xf+qu7VqK4txjcHiPejt PFtPska9DWCh48eK/Lfs+jNqCYDNp84= Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2175.outbound.protection.outlook.com [104.47.17.175]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-22-2MRsBgdyOdqdnNQ_DWCOoA-2; Tue, 20 Apr 2021 13:46:20 +0200 X-MC-Unique: 2MRsBgdyOdqdnNQ_DWCOoA-2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JJH93DmWWgSnM2z64k+I49JPA0I7btmmI1uTqkx/puQC9I58qs401YRDn3l4lO8ycRVMoBZLMB9hkgT9NOmmWkkUeipOfWrGOd9hO6t6ACbeeYccRqcng8FSqitNG3bL3AoNZJkX+fd0hhQuLkA83QmAwV7foLcY5TkqpyylBEcWZYFM+H/beUJOW7nNH/vlHavUFj83pJd/KHwkK27xZqhY9K3zSCWbUSWKhUyVRmAx9XVr2bU0Z8K/eJzg4N5zHsAgnyuwrWsfT5mS8ziPO3gF8z4JWhY5YfVd8x72NE6Dkl++UT3cqNlRbQH3G8WAV26QZ04eYnR44pLpqxkyIQ== 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=JOGOBXjc0nS1N0MCT0OtEN/qgSrjSmWmvp47DDtVgKm9rgPbfK8CUuA9O0jzOW08MoibFCkD7XykFrUdXRSok0Sy00rq77+K6hzNE0Q+AtRYgvhNMr6ExVf7AuSadtFhSkD0EZeqghRnQnhFx58qvb2+Cq+tLwzBb781oAIB0fDmfSfI94y0R9g5eVud2Pp/R9MlfRCiqVO9viGh4qHQ7j5R/Kdn5p+7vTv3txbP8i7S2hzFcV8khCb2Ub4p6dRJ0RLrL02xEAn0RK9+79IPiLd7/3WYHypQK0STVy48s8LemAoWt5aINX+yGJQtlgP4uPRw3fJsQxFG4Cihgj3zvQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=suse.com; Received: from AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) by AM0PR04MB5154.eurprd04.prod.outlook.com (2603:10a6:208:c4::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.19; Tue, 20 Apr 2021 11:46:18 +0000 Received: from AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d]) by AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d%6]) with mapi id 15.20.4042.024; Tue, 20 Apr 2021 11:46:18 +0000 From: Varad Gautam To: linux-crypto@vger.kernel.org CC: varad.gautam@suse.com, dhowells@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, vt@altlinux.org, tianjia.zhang@linux.alibaba.com, keyrings@vger.kernel.org, linux-kernel@vger.kernel.org, jarkko@kernel.org Subject: [PATCH v3 03/18] crypto: rsa-pkcs1pad: Extract pkcs1pad_create into a generic helper Date: Tue, 20 Apr 2021 13:41:08 +0200 Message-ID: <20210420114124.9684-4-varad.gautam@suse.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210420114124.9684-1-varad.gautam@suse.com> References: <20210420114124.9684-1-varad.gautam@suse.com> X-Originating-IP: [95.90.93.216] X-ClientProxiedBy: PR3P189CA0083.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::28) To AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from xps13.suse.de (95.90.93.216) by PR3P189CA0083.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Tue, 20 Apr 2021 11:46:17 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b1a61b98-03d1-46ec-f460-08d903f1e8e6 X-MS-TrafficTypeDiagnostic: AM0PR04MB5154: 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: o7+uY/ciYssTYjrBXr8rpY8eb06yNc5qD7WmVjANJW3+4Yw0XLxf93+Vcz3FlyOCNVybwzDr7S8/YIre5dCHPg0P04jWNiJ9FvZXRFbv73fY2DocmrjgcBV9P3Bb7oPWmUTAFjqBS+yQtSpbI0Ao/okgnXj/LxBiYM41aO3Si7w6B/i5YvK6dWL6fRL2U1K8oOWEyKbL4mktatsxMlPJaG5jTorrKsn0xvwMMii47mV1bu6VydRaCKfqi5mkH2VZ28EgMBU7c35BLY1Naz/indwgi6GxWtyf3/SMn0QNUZw0GKrGloCWkozYorSKJM7qqQ/qv8uPBf4Z56q5A2SfQiTUZFO57WxSLjhS/u/xurEUrEjQtXshvvQCLJUWSXtWkePQoEPEdXTITvvCFUlmtX/MNq1Cvdkls31rnYSjogN23N3NFC2rgeQibisQCp57i6SEVDoVCf2wSw3xuCKNBstFpUTYOAvZhTilcRfYyyFgtOCRZlhk7NHWs6B0HgAAsBoNt7KxMclTeiTOnj9xZQAdefq9hDw33kcWhAYf2Y6QFcmPbBdZkruGz0cSwBEUr/VEtESLDB9rzoL07riA3xJyN6SmCT77Q97XxqSI7LdFrRwzN4uiMwliH8xjAs4dK9Xps0Qb9K+8e46GBeczFWK0v+Up3uQ3M18y8cAiOVfuPHW2yp3MU6yekkb0tGsO X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR04MB5650.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(376002)(136003)(366004)(346002)(396003)(39850400004)(26005)(16526019)(86362001)(186003)(956004)(66476007)(8936002)(5660300002)(66946007)(6506007)(44832011)(4326008)(6512007)(6486002)(8676002)(2616005)(316002)(6666004)(66556008)(36756003)(38350700002)(52116002)(478600001)(38100700002)(83380400001)(6916009)(1076003)(2906002)(41533002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: KPacT7tzKBfcD3SDmvexXqj/t1pk2epPkwQHl2cYUjyf6jRBCaKrBMN1NnSbi2hAnZ/cTN3twXCbOWn4ntaA/9UDDodgG6r/JG1JYm6PpqOniLWIP9Hss/3vEZnBIyT8WxDJXtTcQaGUdFV0n1viRIIcw4HNqdK4yMX5+jNZlfxYv/YtWXi+wyjdBsRQLD+xsxmVr2nOw3d7QwyILNzLNQjT/epNbHUK8aN9oT6CtO6zrEtIKDCbY0px5LEwpOEd75lWaWfd9DQdVpVwDQDOo+8Lv9zNGwDSEfTATvOq8/Uak3I7lkpL9TZUlcAQI8sTzdQ/YBDHaadKdG9Agr+jNXheWsi+3oWRSruKJdsStCZdG+botcnZjdKi/5pu4bUBXNpicsi7Uz7CtTDkHBnSNcgBt2ifoOsa6acBTtIDl5JjbgKI1gSEph/kTGbji8vUm4gjnwpEbqitEStfc3cYIsgq0qxzXIXv3iCDCMplIS7BB41WRcE2Pe48nIP+XShoTyMlxlCxb25Bv9gVwbWNrYie0zsAobdb8LMDDnTreGOTF6YALYSP+KmTqygB0ulOk2Qz6AHOC56oyPGEhOR1aCA6Xl1YHlt6n9Q/BrYfqpad9rqGTWzVxHm/XFtnopRSlt6H0aShZQw0/DAM/3dXdxZ700qBGbqAfz9o42cOFcfYfy8O0XsFxThxgDKRbD4fh4LvFN56ZmQR097JPbKtvtPJGAK5VRjx09X8vq8dl8f+LJCXj1bZZSfd5ZIrvy+x7OA9Q8mCcZixocy+R+m+6wYn45QSX8VfWzEAlH2PxIie4523oPFbcRHJGZ1oGU9CJi6iqiGQ16KWTn1IDFacwY3+PRFjgTAKfb8umyZCFRAfLM8/Ly7nIFzYDtgUB/i1CBWfgQ0h66srqjtvhdM5Gox096WCzPY400AO06CVrHSKoap8D6S/1FrSsnjGJ1jEP3WEhUKOY7K0sHAzbjOPSCAT+pCB9Iz3SPhurycQngranvrh2PTaYzEwZ7VkgT0vUtlKvgFmOxjqONrV+fIfsciapczN2rjdpxUjh3qnRMXSYVcT1xpqbMbC7bJz81orRxZDvomTXfBiQdaJmWEPiNQseJJdeKVNa9Z+hyQ0cF/YrAeIjISF6UiYOx9/jLNOMc18yejAtAQHWmzBVs5Znq5Q/zfADD1GAJPDfvifHIqueQ2qpHxKWhY2aFv46AHFvC3OB9y+KSMw5+UP0TnKpXxC+WNajTrWXgwwFsBzwGFV37q4XRbC2Fb65T7I3qHNReV5+IokHP6KCw2b7iCUNi2RlkUbMQvml5a0z7xYsVyQ0FOLxAESS+7Op9iYzjCg X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: b1a61b98-03d1-46ec-f460-08d903f1e8e6 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5650.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2021 11:46:18.0076 (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: onROkuajrtA5SgzYGr/P8wiuEHESazOAlCUfacm35GeZUX1Xv0egPenQGrTjALkD04drghXomm2tLqn3dT4FFQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB5154 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 Tue Apr 20 11:41: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: 424662 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 999A8C433B4 for ; Tue, 20 Apr 2021 11:46:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5E5C9613B4 for ; Tue, 20 Apr 2021 11:46:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232087AbhDTLq6 (ORCPT ); Tue, 20 Apr 2021 07:46:58 -0400 Received: from de-smtp-delivery-102.mimecast.com ([62.140.7.102]:45409 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232060AbhDTLqz (ORCPT ); Tue, 20 Apr 2021 07:46:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1618919183; 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=hgsQa0D2daWQaMCGL1MMoWrOotMJRgSL4cQZcXrZ/jtuEFxNRPcbOlF+6LKAj/wmP4N9GV hXH9dzaHmN2U6+5QrIr2zjAKvouJ5Z/FO2Pk8vDUNQe7E5GFJ7ebj0JqpG1oNpZtn3OsjH Td9vpXwSzUQyOiRILVfV1CJECPY82z8= Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2175.outbound.protection.outlook.com [104.47.17.175]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-22-4BTrZ2diOoy70Ki9KiW1kg-3; Tue, 20 Apr 2021 13:46:22 +0200 X-MC-Unique: 4BTrZ2diOoy70Ki9KiW1kg-3 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NVMQyzkPfOoMpAeuyBg5U4igLO+6p9YOISzZMPz0tNpu/HGaipY2OyAVGkK88jJcKJNgcQCJ7/Mz+/Xk5OywwMHalIOFKYJynIF0I27ypvXbIcqgRkgWgokijZfMgcs4DKKXt4exqsWUkTmacx9a6YhoQ6hdnKeNuX1ASYfvw8P3QK2Nm5quslSgb8TGQ+2zbLe8fwP7t+9aXgi4oAHjTS6mMAawOli5TlsGTYE7b/JMxxVm6gqcYr67zIMXsVw4erG1h2nYBUnHpard65AoALo3oO85zp1b+Ok4K718Br1Oa6KVr6QR8MmnOw1YMpeqyf6xAzT1lQKZ2PybP0duvQ== 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=cmE1guJfQqP/MrrsNuG3+klQFPxWdX03EvK9xF5QKFUvzQhlhOX7ryNGun/IAEWa3fe9TC/1QtdBzeRS+v/rWIdbGBBfC7r5rAjbfQm21R201JR79zwkm95cpQFzhVufoFphRHADICmTMsGw6glWJYFJMqAfYv84Lp0vcrH+A93y9lA6RSkWvcshEXvPYSAZ4PH1RQa8Rlb/Rw4SeUzSCnUUJLMMU7tOd6j2Ip+/nD9dvxBGKC6mSOVO0y0pHkUI/5W6WWGGOcaKkdaVKGFkeRzIGGuVGNglwURAIXTEfcwj29ecC5WBjnRNWww7SorvgrKTLCaQEYOY4G+TzjPLrw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=suse.com; Received: from AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) by AM0PR04MB5154.eurprd04.prod.outlook.com (2603:10a6:208:c4::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.19; Tue, 20 Apr 2021 11:46:19 +0000 Received: from AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d]) by AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d%6]) with mapi id 15.20.4042.024; Tue, 20 Apr 2021 11:46:19 +0000 From: Varad Gautam To: linux-crypto@vger.kernel.org CC: varad.gautam@suse.com, dhowells@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, vt@altlinux.org, tianjia.zhang@linux.alibaba.com, keyrings@vger.kernel.org, linux-kernel@vger.kernel.org, jarkko@kernel.org Subject: [PATCH v3 04/18] crypto: rsa-pkcs1pad: Pull out child req processing code into helpers Date: Tue, 20 Apr 2021 13:41:09 +0200 Message-ID: <20210420114124.9684-5-varad.gautam@suse.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210420114124.9684-1-varad.gautam@suse.com> References: <20210420114124.9684-1-varad.gautam@suse.com> X-Originating-IP: [95.90.93.216] X-ClientProxiedBy: PR3P189CA0083.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::28) To AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from xps13.suse.de (95.90.93.216) by PR3P189CA0083.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Tue, 20 Apr 2021 11:46:18 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fee6097e-6614-45e1-7a88-08d903f1e9a8 X-MS-TrafficTypeDiagnostic: AM0PR04MB5154: 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: /RIoqMpqsb9l+9zrWvo0jywbI6xJ1V6RuDgogzw+FYj0Jj/qms/e6b5x5XWI/W6VYL0XlLU8gjJJzmfyy/EHwrK95wY5dYlKV/+M7kVzmu0vyArs07ffcv/tAIkcC7fqTfmD2A7fRiV+oeK9Ux7v5jyIbsLAXX5zZg+7vhqhCs0bdKMP91dnKZsZ48hfRnDlFhscTn87Jadqg4vuHXOoXEAAxJjC5w5mscUI0DpvchUp9QacnEfDmi9xBZlHGau0WqyxSoMLTyLSLIr7BJKTvYgLMdHl1Xvze06+B2TeeAf7KvmJ8qPRwg5LL3tfZR/waovZCJcScTFXcaXLYOpXum878yrZ3XOCOemb3IUno8Ff/EMvf5nB88AW1BOz6otTotY0044osBJ/+c5vHw9ico9YbabfCJuC8uxr0344bXdERRVJ5TdyKXUrSAMa8tp6EtGKBMqWChrpKaGipVH/4si7nxrr2x8uo4lbr0WRCoQIGdfiPpFur1Agt+lQ439s7p5CfSqWW9Sz0fyDrYJnhhKgotF1r+3z1vrg8Vb8EMxvdy69x6h/ywA+qPKvzLXAVr4vY4l686hZ0Lu6Qrn2taXi0s6NexpPJDDlZsw4lecHneEhEW2EI8k+G1FTGdS8xhsXqtP9qNyl3kotBEjladmFxRNjI9j6sVSs2CWvw3h5ulnNl7axa8n8uCUbcKE5 X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR04MB5650.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(376002)(136003)(366004)(346002)(396003)(39850400004)(26005)(16526019)(86362001)(186003)(956004)(66476007)(8936002)(5660300002)(66946007)(6506007)(44832011)(4326008)(6512007)(6486002)(8676002)(2616005)(316002)(6666004)(66556008)(36756003)(38350700002)(52116002)(478600001)(38100700002)(83380400001)(6916009)(1076003)(2906002)(473944003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: r+j0K3VLSKCQMT5mcM7XqoGhapwXwJRi8Mm/Kv+Ioykmp4xtgDAXj7TMq5ZKKJuwobFyEGgLISi8m0x4gyhEhzpkXhgwnIZiAHT/S0ggZkWsCIH0W4ShNy4mtOqYHbdEkcATBQxjwsivpszTRPM5cnRipLwhfh4Xn2VCopEjQHVeMr6/fjwWBHKU5KJTUilisy3P2J+PAc1xnJ4v63SzoUQkLbf+2od4UDSL74+1Y0gSojLkhAjMsMvww714BOEplcgTYEcUDANAFbCfgzOCt4VtVouKAIbwCbFx7x/sRKRj9CnO24RFxyr1jYkQX+TmP/pTsrj4ILjKXnBm1auTp2oaks/mIfxuohW+UORxtIsp9ni/h3dtkSTj0KQew1ji845B8jeIi+XP2/tgMDvxqDSOd4ssYWV7v+lVxHw5xS2i7geg4GSyTEeQSp/Bj+LML/MCANFmTgfPTsWoLk8+fq73K7DR3JVKueNyEp/dzJzLlrukWPfXvlS9jaOZ5/S8NLKTvoJ+LKkifqTN94w1lABKkOK/Fhhm9QrHtWQczfb7/Y/mbMRctsG217JQg2YOWZLYc4R4R6MQdCQzkXM8Unz8goznm+tgK7hmyRxYEoa/zRVTnuP8AphPY+G/21F/x3eKGXO+cCGdATHlhhhCb1GMPHS9bLY5GB7mcUJChS6T1rL3Vv9LeszddW7Ksrw9AkVFx3K9Ti2tyqQJ6JvEUw+NdyLvnUzgq1R+NaUkoBptaPuYmAX2yWF3GQBUKqYjMh8EcidNjhDMO29aIqeCCZhbL9L8C+1DzN06I3Klbv5CyghKn8+ewJvBtoykQ3azYrGP+sLnFzcnGODZBzVGdyUPZ0WjqAJol/BQ7WlT5Z6gLX2woemNcY4pUzUVeIym9rWJMOA50mmymZ39oUyPP+TfnH8MRCyj3BEegkwgnxKOjE7XwOSoyaUI028ftLxdLBLY1wx2YPCExS/MnJiXM5yNs2a916SMTMp4a83JCO2Z9Vq7lS6ZWCVLjoBnFBNzpDNx8IvYools6pAy8zl+UGipjLDC8A2TLeOH0UGk3lIsJuEBYwq4PSZF1REkN0/Dl+u1331AvyDS32yxGsDIEdWZnugwgkfxg2SrmEW05UOK1iwwH4kRWpp0BGsWPiNeUbldemgn3yd43yBfjDE3vyyizl9XZ0OwBOUL20igk4DCud0lLrcQaBbYAb3lkSqrCEVR+8kl7Y678zJQFMj9Bu/IsMSZj0KvGNrRKx/sJIW951JjRAk8/YRBl2pxWU5Fvn5G/jNQBSEckfjBV3NREzvsrk8vXBiTyZ5COOBfA83YJfzd+9gSIFDJI//WjzNt X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: fee6097e-6614-45e1-7a88-08d903f1e9a8 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5650.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2021 11:46:19.2819 (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: O0ZQfldRmWCi9CMa2m90hxHuS8u5fT1twdCXOhcdOreVxORp6uM6GbUKlHbqvLRPhoeNR0E0hTkcCBesCxGa6Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB5154 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 Tue Apr 20 11:41: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: 425366 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 1DE88C43461 for ; Tue, 20 Apr 2021 11:46:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DAE9E613DA for ; Tue, 20 Apr 2021 11:46:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232117AbhDTLrB (ORCPT ); Tue, 20 Apr 2021 07:47:01 -0400 Received: from de-smtp-delivery-102.mimecast.com ([62.140.7.102]:57187 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232089AbhDTLq5 (ORCPT ); Tue, 20 Apr 2021 07:46:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1618919185; 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=dqORQmFPmO2nPonuDsVH+q3S53zVy/ABWID1dcoPqmlSbjxf2vtqcC41GyxtqRC8D6TvRi fPEw4PfotqRkXSqetTlFTrEqK/2+E218+aQK2yp1aEufXhbEKpqlC2cElk36Qw6HzIHRco 9ptL7mWnHgO/bzhusprhSKW+jXCHDWw= Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2175.outbound.protection.outlook.com [104.47.17.175]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-22--rUv-S5HNHC72uLx6cJgVw-4; Tue, 20 Apr 2021 13:46:23 +0200 X-MC-Unique: -rUv-S5HNHC72uLx6cJgVw-4 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kKGSguDMRpPHoo7DEeTlVVsRsXvcUHia/6PmYPvWWpUiIKgM51CVVBkFvXV1I0JN4GJK5QhUdD/WSY6U+MjWNstBn8sAYzmCKHVbKkLCRTr6iNjLstAvD/39YgAtkoTO1ejkyH6akn6ovSi+R8qpE5O1jxFfbrzMhABKu3SaFqWUoDHbTFBKWmU3M1l/pYO7MV2v8KvoD95oMB85esvhRqSPW2CSJBH0ws6GWC3z92BM1/97w0Yxay3gUeDJJRP6+Gq/BR6i+c5SttZkBJ3Rt7emgyiVt75w7mnHe54DQLRtc/W6E4mAcb4dP5hSDPX9skfDDjCbC7X4HQKywAkTXw== 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=lsNMetoOc6PGxTunlp/Ncr8I6T2zfSB/EJLoAhH5zmtxyY9yf4564icIl0usmmRE/QXAF2xtpNuagZKNbWprddZKClGyaHTcpJExc7g/+b/6m2Pojc3t+JColfCoPnBd6SnTIV4H0RJdt0rUvvFmujybaLFKAoyNuKNkDNjv07RmWXXTwgzKk9Ut+dWlqqrSq5SvVDmiXez4bBWpiIQgF8JUju5tjv38+hdMvuR1D44EaH21jDxrjgQN2TkkhKsV9jVqR56KuOe3KHOiLzvdlilL7fdMA7z1Qgp3GhyCbboz8w8SJJzKLIo9w+/uZKQ3vu7I5T/dGWN+C7CMOICWjw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=suse.com; Received: from AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) by AM0PR04MB5154.eurprd04.prod.outlook.com (2603:10a6:208:c4::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.19; Tue, 20 Apr 2021 11:46:20 +0000 Received: from AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d]) by AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d%6]) with mapi id 15.20.4042.024; Tue, 20 Apr 2021 11:46:20 +0000 From: Varad Gautam To: linux-crypto@vger.kernel.org CC: varad.gautam@suse.com, dhowells@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, vt@altlinux.org, tianjia.zhang@linux.alibaba.com, keyrings@vger.kernel.org, linux-kernel@vger.kernel.org, jarkko@kernel.org Subject: [PATCH v3 05/18] crypto: rsa-pkcs1pad: Rename pkcs1pad_* structs to rsapad_* Date: Tue, 20 Apr 2021 13:41:10 +0200 Message-ID: <20210420114124.9684-6-varad.gautam@suse.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210420114124.9684-1-varad.gautam@suse.com> References: <20210420114124.9684-1-varad.gautam@suse.com> X-Originating-IP: [95.90.93.216] X-ClientProxiedBy: PR3P189CA0083.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::28) To AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from xps13.suse.de (95.90.93.216) by PR3P189CA0083.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Tue, 20 Apr 2021 11:46:19 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4e92b382-dc3a-44b9-9e1d-08d903f1ea58 X-MS-TrafficTypeDiagnostic: AM0PR04MB5154: 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: 0n6OYc8LYJUcCj8IW4Iv0e+spEfhpbl5skc34AkkoTiBugf3p98zv7nLZHMtVnjpucWDAMWka1ry1IPQ28y0rI5hasdoTelzlm0tT0ZC/CnHFfo+jvCueWAUuD/6Veg5xe/ZsqLHofHf/pwX1AwNt7803luITfor9UAIC/DmBMcWd7U9OLolI9x9HQoaBFiCoJFPzGuS06k2IjVBM0j2n7utvDU71Jsz6JVP6QDTuhUs3ZqWiD83wc6NVtz6Da/mCMO7lWLlvWSgQNWQnEs0Kxs1XFM+bjQWl8u6LTzhLOfPe0BcHHxNiQ2LVxlYXmUfddGbLiKMmMoGrFfRKK1bJrzIzkdidQQt7GZG9qM5DlgvyYtNqoaS7RO1mScFvdLiCYKvG1XV9zE2PWqT8+T6rALiVpKbGkJMu70jIWxB2Z7ecNSxThivVvT1k3bJbh0vOS5tjc9EgN0LkG2bCfht9fYn5e6FI4xlz49iI3TmkWHxRVlZTG2c9SyUJUF7b2gO45NiqX6IYkTbmG/P1p2EagAx1zfgClkHwEFDzGl+B7+f2EFJznTggoHOU+AUzq4fOcp6jq5EyBmxZPneJZ5q4XGbAuM9fNv4QH7mVPtQNaMtYm7HVJCcEVn+Cwi/AfFyi/k88PHBXQOLkVKM4hQeaLLsySgR+VrfBrdT8g4CNNE= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR04MB5650.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(376002)(136003)(366004)(346002)(396003)(39850400004)(26005)(16526019)(86362001)(186003)(956004)(66476007)(8936002)(5660300002)(66946007)(6506007)(44832011)(4326008)(6512007)(6486002)(8676002)(2616005)(316002)(6666004)(66556008)(36756003)(38350700002)(52116002)(478600001)(38100700002)(83380400001)(6916009)(1076003)(2906002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: TtUwg0NqsnZxS8BKvBDLyB6VmFfZFiZkcKXSKVmWhkrIURWHIMpc3EzBdIT+JASv8QGUcQ7RTMhbY1FNXh7Wt49c2RdBxZ5rXyKU7aYoaxpn2f9cb8wEnQ5rgfZrvV0aYJK1NshZaPh3X7mgTBDy+/JHegfxLaXLeeslmiaaEsLluUMRX3enEQvbpb4Gb1IYe9/L21gbKwlSGBTauDy7Ye4ozGrBSRTMzwUe55pdQ5yjJx9rZ+bsgzKpiCR/qSBU0vw3bBvCb0pj3ZORbBJMuWN9Q+SCqvylcqYrSdFuIq5hT8DhtTJMu4WVMCoRxQY9fyBAjKyJBS0HLxXD/ewBfYcsP+CM5ZQplTbwSpvKeFV4J6NFframfNGdiH+mHi8XSRTit4JTlPpHQAB8QiQAkysuaHtfwWt13m7ZHVrtpSg4liEjv6tJXlOYPAUN0dlJSRguxGgyPKZ4q01129PzTrumwrEoYKGOrMHiZuMU+MqRiTjBoZxmPsaHbwZyhyVP8Ef3ZKlwERogOOJBzid5+5BxShVnMqYdKR3rNzOEr7HvcmhXTMxsPD8HHSqPnc+Aa5qPDu9eSa6GgPXCdHHZrCFPh4Y8O6/6bZP9vNxxyzQV1bRDguSUFqKSp1MdNzlhyR6rzoxhremX0XvZsMeJxRTBIkKCDViIlOYntYmToxRqR0OUjgjcQHZ5H8RsRCc5MnfGSXu52gwz2gudWOZs8qlksRZCS62liLYYWucv0pK6djyLeltSaEdix6b7pbaiW47Bm24+s33+nb0ascIpBkrnSCBwUXK0G3mexQv8KfW/e/aXjftFE3ZYIH77AuB3UMeuLceeNtYs/3sou5egrptkx1Bn0R//T+N+iHquGqpo0MZqcXANGMbA+YTzIwFjXB475kLgrBaGqrZGsEFd63HDJftYgO3XfygdOWey4wqe3INHWf1OR9Wix73tovEt+xSHerC5uYNrByg7H7RIweLbHO+31Iwukj9BZo6+Ci6e0JtZ2RobwMYjVUvMzpHmEZPTuQ77sm8QCUCIuvuZGZwKBEycibMYfRnwIEo1Gojws63nkzYvOcqKQOrSnCujn177L41LECVtaPP0WkgPPexT+0oiZMTR7h3EOBV4EB8qYP9pSh3Pls3msMRBF+XIHuBYr1RWTdk3q3jl0hmInIqwmm10UeTFnMuVQ55R4cB0X3lMwbRrGFbY/W560/kj+48d0GsD/57i840/1ImAsmBTKomwIJCw21PN1YmX2Jez0spcZUmKrq6WQlIxMJ9zmBGDRJOlcm93OogVMOAVe/pGlzcVTT70RoxqYVMUNN2UFyoZzoo7pMtceD9wCzTv X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4e92b382-dc3a-44b9-9e1d-08d903f1ea58 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5650.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2021 11:46:20.4542 (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: /JIjLQSfN5oIzdXNfpm4hGBvUkltwIl9BSzNfm0Ph3WnBex/vuJ7Ez8ARFBgSXwWOF/HFZG3HnRm+Sx1gYJdnw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB5154 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 Tue Apr 20 11:41: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: 424661 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 895BFC43470 for ; Tue, 20 Apr 2021 11:46:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6C99D613DB for ; Tue, 20 Apr 2021 11:46:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232066AbhDTLrC (ORCPT ); Tue, 20 Apr 2021 07:47:02 -0400 Received: from de-smtp-delivery-102.mimecast.com ([194.104.109.102]:38223 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232110AbhDTLrA (ORCPT ); Tue, 20 Apr 2021 07:47:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1618919187; 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=Q3nF2gNzFpsgBjtJKlkQCqHRV5FaXuheQhcX516OrHHlgatMg/EuKvU02CwxdTY2TVXVdu +SbeZHetMkLpyWIjnvVJwq/YPMmAwCRf+GmeZBI2iBVmpIGvv2RvVFlLBDsOoHO+WT4D4g jgFmoGQHVqkOdMzIzFnGgL9GRW772R4= Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2169.outbound.protection.outlook.com [104.47.17.169]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-13-apgE18vcObemiJIrBXOkUw-1; Tue, 20 Apr 2021 13:46:26 +0200 X-MC-Unique: apgE18vcObemiJIrBXOkUw-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=k9AR9j7KYoJlKKWMUWXzzk4vOYCJLwoicEEG/KciJyfUaL5BJNH8XzT6t8BNB/hq9Tfx5BY1dx53cmW3/bEs5Kzp96UI4J2uWIW6em0OApL1uIfAYfRVm53tMRC67aERzi1OtSztRO03SioeI3YHkOYImnDiqC60yx16Ymy+KUFWcJbY8KRjuIOb4IbwdEARUifjeZRbdvCjZC+lT8JjGKg5m5Ehsg8Lm2Ly1durQtyBMRb5bndnHbZUJwZ4QefbTLwm7UboIphqM8Zni/nAM2pM72B6l53Sd79ow1XS57o2sKuyGPXykubhYzA5bN3yKJZFM/uIYMoOU3A7804czg== 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=SzdlZv5XzQUTKCtRLHZwVztJT+q0xJcVYrsRLyVDUegduaHUfJGh+F9trRidiw95e0HXHmeEl0kOZU22IAGRMIEwrNLdxvq79tw/TlxFJGUn/4oqE5rc/03y0b1irXRKp3uF6W4W6E7w/E3qk9JtSNKEC6mNA2nWumIss2GLBldqSDnN+9CxgspgIMuDmRqu73K/JzRn1GRuqh9f/sAokLLf0Xio6XALlHfopCZG+Rs9yqguh5ufCuVb45xhOb94ZvFoUbOX36EO8mo/Wr1u6kFYEzzt1SePyfHLo6Hhma6TfEBjCjyM1cJenBVgT7jd/8wOKS61lIeTqGOzKewCig== 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 AM0PR0402MB3396.eurprd04.prod.outlook.com (2603:10a6:208:20::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.18; Tue, 20 Apr 2021 11:46:24 +0000 Received: from AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d]) by AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d%6]) with mapi id 15.20.4042.024; Tue, 20 Apr 2021 11:46:24 +0000 From: Varad Gautam To: linux-crypto@vger.kernel.org CC: varad.gautam@suse.com, dhowells@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, vt@altlinux.org, tianjia.zhang@linux.alibaba.com, keyrings@vger.kernel.org, linux-kernel@vger.kernel.org, jarkko@kernel.org Subject: [PATCH v3 06/18] crypto: rsa: Start moving RSA common code to rsa-common Date: Tue, 20 Apr 2021 13:41:11 +0200 Message-ID: <20210420114124.9684-7-varad.gautam@suse.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210420114124.9684-1-varad.gautam@suse.com> References: <20210420114124.9684-1-varad.gautam@suse.com> X-Originating-IP: [95.90.93.216] X-ClientProxiedBy: PR3P189CA0083.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::28) To AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from xps13.suse.de (95.90.93.216) by PR3P189CA0083.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Tue, 20 Apr 2021 11:46:23 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 583502c6-d146-4844-66df-08d903f1ec7c X-MS-TrafficTypeDiagnostic: AM0PR0402MB3396: 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: 6LmwBR1DDezUQVX1ms2U8KA7B1BEympgHJLbrxmF6CsQYEhfv08Ui49L1vomunTrjU97bpj7aTU3M+saLmrsEombZB9Df4aIIFVd8fmiisNloJ0BGAnZ0pkRL9in+GGJ6P9Jb9aovcQg8o+BN1yKKvIW4zRuO7ncb6rhszdSK3oniSSe2NfU4KsVFPdCc3Y4Y8sVE4xkSzFMVLhucVoEeZcNB7haGnn06rcCNFxaxpz0FS46IakA+HjMOp9vrIhu9ClLjio+QM8kPoQar4J+rtAJie0fwx2trai8hHJV6tsAJFLAqUlnxCGK518KHwUW2CuNCkDzN/uIqWe6TxIWDXCDc7lRZTXZJzBgMVhC9323AFc0Ebk2DLfcA9KwOQxjiLDXRkay0hASh3MfSZxGn215h3aTsxYxqco+d3J9A4GizXOGgGuQtUI4AYUYZPMB7D6V9CzDYUxoyU1wLwddjCJfpTe/MDcO1c9DBg+VILddoO5YaQ3I7zhsJreePT16PeywQNL4RZudH0ArBzbMXNrGVOE/tGD7QZdQ0V8fbtBPygIJpjq+dwZv3UzXIMPotBln+E7Pwp29svEu33LHAqdLUOe981XEjvtHAHLiaEBsNSnBBPHA7Ws4ke4insVxaicJrxqHN8+6AoYyfeZk9A== 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:(136003)(39850400004)(396003)(376002)(366004)(346002)(6506007)(8676002)(52116002)(4326008)(1076003)(186003)(66946007)(316002)(6486002)(956004)(44832011)(66556008)(66476007)(86362001)(36756003)(16526019)(2616005)(5660300002)(478600001)(6512007)(6916009)(26005)(2906002)(6666004)(38100700002)(8936002)(83380400001)(38350700002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: Pdcw0ExoTj1PSpklbzf8fx0c0RKQnb95l89+vw17sw1LsDW6g3944B1d36sCbcU17GY5gmoZRSWQTyDo7l6VGKSgTkqP7IG3iaW/1N1+gEX4pTdsaQr9R77fhnTdnuie30FDBvRfADkSH1oBWUAXt3R+LdSlO/+LsKzSpXkkurOm/ODL3AJ+fvxcLX54ybkx6/jX/fuMF5qE9n2ecKb/Jo6X9l2MS3KR2tiPiiwgdqyw6xV7lTNni3IJsStudNv89Nh5xjUn62KQJEl28i2D4hQpUQYXfgx+DvgjAOm0/JiEVhxhXnlAk9S8K1kXkdYa5JSWkzdn3ut13Uq+uOMU7hrPR4nMAK5ZPgAKNQKIvtaxfgqQowbHkjVCWQ7AuKl1ZsPoWR9UKyGnT05IjwDNdvdHscZzrkwEMlJe6orpgR2m8BrYBBxzu+BvvZdRLFFLmxiRrso3uAT6qS2MD1h2yGmx75EeBmCI6cy5AY2UV6VK25g2rDe+F30vJY68tKdo3JY3f4B7sXoJNBnAPxROzfreHLd+hhJNNmYLZpFLNuWcw7vc7lIkpAf99iAcifWreXYxRkBgs4ofOV5nFKBdiOcNQnDjTH44Gqj228TbwHe9d007JxNEN7bxdvC1bhz/aqWZuh6cQGWl14GV1jGPq5aP27zEE78cMcOVI8gVVClKfy4vjg3oAJOnDPaR7q2VSFD4gU0EwaIHDt1u903Tx1owK5kPR3E2q5Q86PotgqaykqWypiGy/NN6o8fojtrUo3efxBlGEaZWBhXpvsGKVb79TYKxCUxTGhcvA/dP5RLDSCqcySGRZ7UCLqUSz8XVUmXiv/nRcTObXMfwwj0ZD1/zqTa8DyCKWXfHEB+DS1A9Dce8kGpuQNGtgdiHlT9vapvGdA4xgRZiMQXGRCZtbiGNBJ22JiVOEA1ZnxJ25FcJqXQZqcn/r3RWBtvUFpU7ytXR1VgCo8XYWLJlR5GPLTYe9kjYxMQhNuWl8AfH7LBed02jWRM9hZoJHuDfB5Tnwalsta1Qd0wxOzWErlVnoGO2ejpX29agZ/e6kVTaqKutoZhBC00mxo7oQpW+joSh2Wi55HcU37GaxPwYxv0Nh+sJsyMyEHDPw61gVwlxcVlU3cbZaUeXnpQLjHcpzpPvh7KK1DQ/egB9jywZgO3jXXFNXVhF+WV7vlzGAsB1ZakXUxGB8oQmxvPQLwZqevEkkZK54yPCgVnhSfIaCgHahUFTMJRXUNGdh+d1Vxv3vP8vWrjYiIyb4EZ8eEALICdeC3eAroeyAGshMRreXEr90SOKvknkutXE/yKJTvivJ7RjXwIHDvj4biKRU/2zavIN X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 583502c6-d146-4844-66df-08d903f1ec7c X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5650.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2021 11:46:24.2051 (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: gQABqkQz3aASsMm305IZl9DSi1VhvrpI0gJLsO3IXDcK97NXIgSXepBZkbjV0KuFclp6QHETHCg0EZsy83XypA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR0402MB3396 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 Tue Apr 20 11:41: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: 425365 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 DC514C433B4 for ; Tue, 20 Apr 2021 11:46:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A172460FEA for ; Tue, 20 Apr 2021 11:46:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231661AbhDTLrD (ORCPT ); Tue, 20 Apr 2021 07:47:03 -0400 Received: from de-smtp-delivery-102.mimecast.com ([194.104.109.102]:20120 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232119AbhDTLrC (ORCPT ); Tue, 20 Apr 2021 07:47:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1618919190; 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=fgrjQFrr0R+VJmeVsfJnIxzGl7ZJDfWG0AaiF/apZvV6Y0K2Fm7OFxreTYcRRL9cmJWFxn 5ZATYNvKxEzDu3dGI6jRLE65rw1P1mSlwvYK21q8l4qsI+Fdi5mymPA/0Rjfwi8ybDMyo2 P0mZhBGxGwlbTA2uQyGX1zQp2UfaAjQ= Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01lp2059.outbound.protection.outlook.com [104.47.1.59]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-19-EEBsFvTZPliE8uTBdC-X7g-1; Tue, 20 Apr 2021 13:46:28 +0200 X-MC-Unique: EEBsFvTZPliE8uTBdC-X7g-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mT4wbYdELaxU7z+pUNZ68PPWLZAc7iXupgCFTT6KeLknSB+gAIJdjsAy0X5Stu8bIAo/gZ2ZwtOPQyLqZ2e7ceEXPeTBddDoYmBA/SWPWai6JIc9Be5tih7uSL5lZqmZjQLjLbC+LTA59dnsC/hHLcreXdSO+XaKZPAhTk4sPDWqXcMYKQtaqLfGTAytJUZO2HiH0AGQVvYoSpqAPx0tJqG62P4w9XkeaSZYEfZmfT2quVycbELLD1T+EbTFY5/10hyaidGOf/dV8rRQjyJulShy8GIgdmhEj3X09Oem/ctdhXaXyKV4qCerT4TFIU0FqI1Y18yloLtsngaQnaxfrw== 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=VRqNzL2WugmCifTHv1XAu6XK2XglNXQ0ByJbrkqPHIoficevU7UeYn8DPUf8qc6rCc5CVl+yfzunkhu26oROTU32mAmCY7shfexESo3k/v2ylb5g9C3Tm+/IYQxEwp2iO7Dl5L56kbJFrGi5YW/iXqXAVUjlSVsQoa9WKdp14ZE96LjCbJKByZWOCNZdXfkTwaaG5ZoolVL2bPkLlFFkpCssJzWNaL7B9pFrenuPfmEK5e3ttCyB4plE2qtQIVgWDptwsrtuaJGP5dRgJXO2ffejXpWLfHAiiX4hGxzZ0AZTBHjx2YnmW32s3L7+n0ReVsJG4erGEbl3+aiW7r4Gxg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=suse.com; Received: from AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) by AM0PR04MB5154.eurprd04.prod.outlook.com (2603:10a6:208:c4::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.19; Tue, 20 Apr 2021 11:46:27 +0000 Received: from AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d]) by AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d%6]) with mapi id 15.20.4042.024; Tue, 20 Apr 2021 11:46:27 +0000 From: Varad Gautam To: linux-crypto@vger.kernel.org CC: varad.gautam@suse.com, dhowells@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, vt@altlinux.org, tianjia.zhang@linux.alibaba.com, keyrings@vger.kernel.org, linux-kernel@vger.kernel.org, jarkko@kernel.org Subject: [PATCH v3 07/18] crypto: rsa: Move more common code to rsa-common Date: Tue, 20 Apr 2021 13:41:12 +0200 Message-ID: <20210420114124.9684-8-varad.gautam@suse.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210420114124.9684-1-varad.gautam@suse.com> References: <20210420114124.9684-1-varad.gautam@suse.com> X-Originating-IP: [95.90.93.216] X-ClientProxiedBy: PR3P189CA0083.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::28) To AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from xps13.suse.de (95.90.93.216) by PR3P189CA0083.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Tue, 20 Apr 2021 11:46:26 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 451cb5f8-7f8e-4306-d888-08d903f1ee66 X-MS-TrafficTypeDiagnostic: AM0PR04MB5154: 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: ecWhF4pwHqrcWs3YJvM1/X4cbSQgkxASN7Rcpm4HbtJnjGUmv23HRtzgvdxLBmL0SHvrN5uApsDbX5HzUaneBOTO3wP2W2PbPm0GzauKnLcQc1+JWb1Iq8BHDBnNz3maabT/Czb2L8u6mE5cC+lQLzskjfjyhV1jdvL6uc+4ognDnrApmwYdzRA7YHkhOioxZBlQkgKfu7Ob4mJCu5DmRP97aVdhZNjPaS/l5M8yU/DsNIwikrhel70DKGY/JRxJbDjS8ppo68XvbAZjtJwmWMqj5reMfWHKFysEl7slb0XZMJamlVcvJaEYhaq65lPK5RudPO2N9Mzgn49s4WZApqmeQqIf1VB4zITBe+uMuE31oXaV4p6XOLZyZ+tONeUe17LoYZaMrCcTUJd3SW+HiPTgFw12qfbFGt3EB/+6UEeOMTguMU1Kd1mPmgboKFtDyNM1iXNVXSx/ZYHA/zNOHbQpYb63+YDl7PJqIwRQM2trfw2N69gJb8L7cj7DxctL7wCKwl+wFPRcx0DHXNNr7iiIr/xQRtv24b/tq643Kzw9wckEuJtBQswcGbkilBMO1MFDZ6GpGc67lx2muDlmNQ4CrF8xbmrdCKuWDUch/aDqeeEVgOstjIvEjIamTuAzZBW4c4nakWI+P1VcaHD4OBdzdlGShzyTOkGXvf0KnZ4= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR04MB5650.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(376002)(136003)(366004)(346002)(396003)(39850400004)(26005)(16526019)(86362001)(186003)(956004)(66476007)(8936002)(5660300002)(66946007)(6506007)(44832011)(4326008)(6512007)(6486002)(8676002)(2616005)(30864003)(316002)(6666004)(66556008)(36756003)(38350700002)(52116002)(478600001)(38100700002)(83380400001)(6916009)(1076003)(2906002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 1qf36gbMrU1uc4GUmdSKu77Smafmsy1ySE+B63i3eDrpfqjUJhPqagL6rfzHGA+1Ry8SuS0Bn+ZpRBbzPBR6RluXTD1q/+1ZnrFnKoa+J+v9BT8m4FXY4jE1LW2Qq8ZVv+jkPsPHQMBxMoUo0T+9ZHC601YiM34lwCZvT4i1mUQw5gMfXHa4mp2x0WdMKL9UIhlbRqAs1/jnkEa7DS9Ac3vkBFeDzGKiVKzP9Jj1ii+WGIl5RbbicmD9t+5VMnMpNmSjTujHDbBH4g8ma+IClfDuH5lSsJtggrCRE7X5HHwL1iK91slCSNl1Hf5b5sFl/yI+aU2gG4/vQAwo45oTydK5z1Ge+qDsy1HVl1yG8gT7vKc3RNx1eBaumwLfKCkZpCJp4damunER8ooG99nTgX/1B5O4QUUqlD5+uE2rpyLdbJVWNWwymRb8HetvwIJx0r7caYfulKGxR9PaJUUtNJ+yI9zE6GLIyINERODczxX3g6vcvrEg6/s3tRAsjJerIyONLDc69zZ0UnxyoTTvLw1RTO3iTSGVWItRc+tmftAgfBfvY/B0FWOK0BpTJYViymo0XI6uMqPfXLOJMzpW/u9RJLj70+CPA2pQ15VDlADEMtfDlRf64np4iScc7C4ldL3w7QnOF4JO9RZiZeB5grKR/6/kNko2XgWlnSr6wLIaC8n4mo8tpP6nZgu+JWI9NtWT2tqdMcKNdnPQ9iq6V3GXbyJB2NIQSdxWm9/ltVIE2HBnGQx343du4p6IIn9GJAUWLZ5r1M4jHL/aT0maGY+061EASmPY1DaA1ZH6WUYp071a9xuooE54F1nUy4FJgIWWbkgJfejDaYcPz/aYw9/jeatdFyubgAS2xmnd90kL0JIGkblXA3BjYOKnWBWlfQrK1JTRkAlp8y9M896ApGVQzP8Re5rfjjuoahFjGzmoLOLC0N/AGdDie7x4WR+ITr49O/bXbyPtggTku2g54J1W9Y4jgp6SPsrH1TBTK0Tw4gYf9oiwQhlHY7MBa42BdoyCrte/exjEYfO+hbSehC20ivXEaI6J1fFK7qrxpPBfUmhdMjGQBb6jD+zwTSowkrM04bqsAHkNI9jHsCtwLIFQse3iR07XACqwuEy8+s8OVrAEErUfKCJ52q04kC/gJHidOBYKAlvTKH4rAZPngJoNPPFOKQxpsfSTzGBqVM84sS+hRH5ys6XOhNDAL2fNlQnD9/qr2XLo48C39YjowvFJEy7cfvjxjEJj/HnOeYsPR24RxXurQuZ8dgikfwH9BThYVhe7x3s+bEQ9zSvHmdknvK+wyDH6vtXp8Jg1jIW5dAejlK+NgJLt3UJJXb+a X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 451cb5f8-7f8e-4306-d888-08d903f1ee66 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5650.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2021 11:46:27.3004 (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: 7LsZgmcKRoddHAxVo14qzccnFitymdUuCtV7RWLiQJisoJTAAcx1VbuhoWAR2JfHF6fDJ7vinTUsrRjC26zpFw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB5154 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 Tue Apr 20 11:41: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: 424660 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 B0125C433B4 for ; Tue, 20 Apr 2021 11:46:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 74C6860FEA for ; Tue, 20 Apr 2021 11:46:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232138AbhDTLrU (ORCPT ); Tue, 20 Apr 2021 07:47:20 -0400 Received: from de-smtp-delivery-102.mimecast.com ([194.104.109.102]:22092 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232143AbhDTLrE (ORCPT ); Tue, 20 Apr 2021 07:47:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1618919192; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=96DN941Ef/gymzsqU9SPmXm1cdxD7+/+a/zlrCm7hnM=; b=H6vO2alJRZp1QEZFhIdwr8ychC03GqqZIhKm7Vn6cieLp1R1DrLKElWAGutw93c/yCwPqk d8piYqDWTGA4WJwGxP0Uslx8rKaIClIOb7/gUGCKwfMmgMHm0tgVNgo06NSwiOUt6vI31s hyo2LHRl0p/GN7Af62wKYXqMrtxy6Tw= Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01lp2050.outbound.protection.outlook.com [104.47.1.50]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-15-ZNLBFaSyOgaGRSWf60g7Og-1; Tue, 20 Apr 2021 13:46:31 +0200 X-MC-Unique: ZNLBFaSyOgaGRSWf60g7Og-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=h7YApRX77Pu662NGBfbk8n2jqmePAGkREWaT3EZMRDymaN7srZ2O/vfnIwdar4GVQZRJq0BiOqXRcRIq7jWKJgqDEBE+SRRbkVeESapx9flJjFeMKO0Gzea6cojXCBulBfF4GJdr4QHKT5arwT0KiScIbvx/HNUkTYoX3e0icf1lzhG4VMfT8hNRKZlz6KiuVtBjJf8WQ9SxkSnm/anRytem5CSsessA/PcSKZFWgWe4EulIQuqAI1wT5euHBtofab1y9VMxcPX996MK25xVeFzfmGo3cxTUY1OP6uo4RKctRsARZwzUPywu4SNICPf2h1Ah18MAlVZirLvHY1arUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1Sa23WQs3NsEGBLTmg6WpJVp9KxgVeUeR2V32E5DXSs=; b=G5NmWNrilFaydDAF0jzsUmFRbDJNg1biD+2re/Iv6p2Z/kyF5dvhkBRSUsoxR5ftdaEx2+rb8uz0LLJ9VUMoWDdAfffwWgrXn81DCEB4SUQFUF753G2upJLgb0aN2pppCgqTTfQPBSXsxdhI8Rcg4FSwBcHnxywXE0NFx+6/9wazWGTSHSqXLkzKFQqTryLewQ28MCrGBJUoOmTdI2BmG4TzY9f1OmRvKx4Kxo/QPoaqy2YSoVQpJd1mbl2sGqAfhU+hP7VYlqKPqT8sMBdtgDDpouTC7pQrX9bMrwKEDwHaYw37x+mVzE9/IbVNOvut3XjHf16IP8xBYR+kyvVCFw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=suse.com; Received: from AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) by AM0PR04MB5154.eurprd04.prod.outlook.com (2603:10a6:208:c4::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.19; Tue, 20 Apr 2021 11:46:30 +0000 Received: from AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d]) by AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d%6]) with mapi id 15.20.4042.024; Tue, 20 Apr 2021 11:46:30 +0000 From: Varad Gautam To: linux-crypto@vger.kernel.org CC: varad.gautam@suse.com, dhowells@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, vt@altlinux.org, tianjia.zhang@linux.alibaba.com, keyrings@vger.kernel.org, linux-kernel@vger.kernel.org, jarkko@kernel.org Subject: [PATCH v3 08/18] crypto: rsa: Move rsapad_akcipher_setup_child and callback to rsa-common Date: Tue, 20 Apr 2021 13:41:13 +0200 Message-ID: <20210420114124.9684-9-varad.gautam@suse.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210420114124.9684-1-varad.gautam@suse.com> References: <20210420114124.9684-1-varad.gautam@suse.com> X-Originating-IP: [95.90.93.216] X-ClientProxiedBy: PR3P189CA0083.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::28) To AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from xps13.suse.de (95.90.93.216) by PR3P189CA0083.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Tue, 20 Apr 2021 11:46:29 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 70643ec7-10af-4ac2-3e7b-08d903f1efff X-MS-TrafficTypeDiagnostic: AM0PR04MB5154: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:185; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NcvpiVK4rdAIQXfcDyRXtMWjtyeIrgPUeHyaYQFH6V7vmlOLTYAOvDZh++3T2IFuz6VVxZyD4JJ7Nu3eSYjI73vBnUaqb1ksKzQhu81U0xUE1mt1xFI0EdhBz5123Kb/3r2lfr8Y2BsTnhRLjwKAvTOEILoLUrf+V6G5+LlsxFNXxYWfPpCavRS9q6eoaKhm2jtdjYNsOumERlqOac5520pg1q/trj+IXDDFezlKiEe/R07dlAWqKCj07A9m1FjvJXdjVaFjYLsXVRyFr8rJhc3JLt5n7QxZgJvuddvDhSNmXCd5EbT/RKvl1SQ6aCel5Abi19y51WxNXo2zP5RFCFKv9Rsdto1XBhQCKCOwQ1eTTO900PCxcpNg75zqLWmyLV+YCaXFdbHMii0pOUTCLckPE/Ci91mnc0bYJU6sNT/iP1WdxpPq23H7OwlxEY2tEPqY1MxcEeZroXuJ1js2yRy+PDXg14CHeFHigtQhaIGXW4WxYiiY2/M345lvIUzd21fXddxU1zpilys27KKJmV5hSmR1P34I2+WM8eoJ4Sr0JrCKqUxBGIfOPB3Ji/BWTuDkUVVSHzz0g7UZTY72zKaq161WFNXiigcfwA3FnrArk+ZFjtbXoOYKTWDroLaC/vcMUqZnAxgzNCAKWSl+Ru9MFqVQKNviz5KcQH3vg38hm2vBQ+gtUXO1oy1tRh2Y X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR04MB5650.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(376002)(136003)(366004)(346002)(396003)(39850400004)(26005)(16526019)(86362001)(186003)(956004)(66476007)(8936002)(5660300002)(66946007)(6506007)(44832011)(4326008)(6512007)(6486002)(8676002)(2616005)(316002)(6666004)(66556008)(36756003)(38350700002)(52116002)(478600001)(38100700002)(83380400001)(6916009)(1076003)(2906002)(473944003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: CoKouxK8AvihHDxD8Cv5avNb9qsxEnudJRp00cVcStA2plEw8XJtbdH9XRrpjy+l7uYzZobnrR0g1TSiOHdaxbXVU5cIeF/42Hp5RkdO4RUKhAzcRfPIdIJQqnwEXZfTqO9pEOaMp3Gw4Pl94vFTC0zfvNHBbmllGDoJBDJz9S7MlImo0DFfxo7uLUcjD4uAVlhDSt25hT/GGaCCkUY84vta5TL6cmcc5Sxz9uOkWBmddOx5fnvrmgIXOjp3qpztCnkSaQx4j2kNrzgfvHes1IpHwfJ6aTMt0km0WePBtV0UOnNuJ6Pr9VeqZXMYKiil+fkbpe1scP9jABZ4WPFzkKkPzYWvRNclaRKnDi4C2A/82JRBCXZIP25WjpCZ6ZjUX8m03DVwNkf4UWvAjTmA6YYGOMmEvmujpApEsszWsqqZWp9YRJn/tALGEc31oaqGGgyWhgunD2EjLpaawG/XKwVPX5u8W1z8pFiOd6y6Z+CIGxkItfKQKwTcdaf0HiwCNYxx+SzLLMEu1t/5NqSW3MowudazTBjs2MbGeASFhiof3bUCE+RcIhDH2m6sDKYhh1l3gB2lyjuZqDGHJ57K9jpQSex0JPb38lw+NAXP/l/PE1IalEBfwt+F36wORvZ3/fbtHnHNpeho4OZN4xWPGRd43rGcXmArgUHdWXRSN/xO314au7Tn9EM1KdrmDZoKG7IsK9bfP07MQoRjcln8q26oHf94P8dT3LRMdlydFUxQt2sl0H6Ls2Q6vPUkGB2dMzIt1XN0QlxIR+FvHary0vk9mqIIxsEy1Y3Z78isrch7PNCXNHhuvJ16FjZzgyqyH+sfTsJTp0ooCODYe3YpetYb9/L6XDGJDUvKwpT94W9QAS7FGQh3Y/lJZh4JxkvarKmwfc0w2ypyg0wFSXJsPKsQqEFp9xEkkCH2Tm50f1+OmAj8H4UIlc2nkWxzKRo392itfsIOXCoBh+AyCG3CJQtswxT0NAy+U5B5++NfjKaf3eloDUWaA3PkdbASVVsAkhfrWRdKb7fZ5DI2m7WQUb619fCE5IKYcnXkcTeBm+VAmskmw9h1igMC/chWwtBqPmp5TFVZTKP5gV81926PtBH2gUWIGq1332oQfE5UndkfwSlCMeWfqyuHS8KECZZUSnL3dzHizem6IgP5IkEvEEv2HM//eppPzaPgNkoJ5vutD1NqEN7lj3LTUIKd9RH8Obed7xgZdmLSjiwSwLFIl+3IdQCNMU4qJs2sWdju1rLfbcUqlWw9C4ZeH4UbFrCiQQw+ydlFRW2j9COGgkPuWsLeHcFvWnwc+CrDcgj1SMmujY8JARm4ThhbcE8zIIOj X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 70643ec7-10af-4ac2-3e7b-08d903f1efff X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5650.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2021 11:46:29.9169 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: zPnBWEYDzKLHrsmlKLSvaXukTN3O7th+NZhWdfO4AFGS72Ykl/fjcI8n8+0p03+LzLiC0is7gG8NrRRvFyBoyA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB5154 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Pull out more common code from rsa-pkcs1pad into rsa-common. Signed-off-by: Varad Gautam --- crypto/rsa-common.c | 31 +++++++++++++++++++++++++++ crypto/rsa-pkcs1pad.c | 32 ---------------------------- include/crypto/internal/rsa-common.h | 9 ++++++++ 3 files changed, 40 insertions(+), 32 deletions(-) diff --git a/crypto/rsa-common.c b/crypto/rsa-common.c index d70d7d405165f..6ed258a782875 100644 --- a/crypto/rsa-common.c +++ b/crypto/rsa-common.c @@ -75,6 +75,37 @@ const struct rsa_asn1_template *rsa_lookup_asn1(const 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 Tue Apr 20 11:41: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: 425364 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 7E8FCC433ED for ; Tue, 20 Apr 2021 11:46:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4A65B613AF for ; Tue, 20 Apr 2021 11:46:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232171AbhDTLr0 (ORCPT ); Tue, 20 Apr 2021 07:47:26 -0400 Received: from de-smtp-delivery-102.mimecast.com ([194.104.109.102]:49595 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232177AbhDTLrG (ORCPT ); Tue, 20 Apr 2021 07:47:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1618919194; 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=UmdJMv/Sp6PoDD+IWkku4E9jctMsV8iO5srh6iF3x8dSmprmDvROTzz0gd2hvTVImF9IA8 wO4eVZW3rUtLx+xOv85gL4j/DoMWi9I5cCtmdonux6fQwt6rszrPMj/G5usWamNVmhRTq4 m/HmdAwddxXme4VgdQOV5FIjMI51H1I= Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01lp2050.outbound.protection.outlook.com [104.47.1.50]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-15-Okr-ZIEpMUe6xGYplEQ4KA-2; Tue, 20 Apr 2021 13:46:32 +0200 X-MC-Unique: Okr-ZIEpMUe6xGYplEQ4KA-2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ldQWksaQnvohsNRhSL/qWAbb328VsHn8pAjo1WnoQpMGP2P74D5/w5Vy4bH0vL1tNhSPjSg3g/XdSG8/OteU9uCB8/jH4zN5RRisnGHy1pzZnGAARw/XWC125S3Im2mKa4OtSVAMNpcEw5kSPgAmgB1e7lR//vgeXVx2/bU1lynZ8Om3QLBgl/1sLdlqxsknRaW0t+SqL27zxoGn9B47HHv/HzxuPgbJVZQ2zOjUQSxgFZr/rSajRQy3tmgdUCwZhPzhXn2RbtxGzr/S42CJcaLXWCoSK0R7Se61XpDTuFqvyOBW+jWWHgwf3duon1Huk0ueJqSiKKlQLGOGICM4Tg== 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=PpvtKY3ICkh8x+HDxLpVVc1FhPbn+ASAuOrvfaht+DH2BVvl6eoUlRa6jsWX995YVNBoJJBEQrBfLyNFEVNLzWcnF1im9MbfIxVI4suIfIGeWWL8vzpQTglPRlj7awclXTLpyXMv9vEnc7n42+VjDpLdasuZS+KhgmZYzWmnLI9c/Ofi0S92NjF65i2H35GQ2nv2Z9VEV/rReT0ZRJeu8juoGYzYFisrJscLYjBarlIAJ6XbQQupXMbYhplcGYbNQ52AFKbeOSM7bgQGtbFNgEwbgy1WVV+WWXDrWvpaacCgGXFxjZrB7EriIdJgvBUs1K51TnfB3VfTHfxCAyfkBQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=suse.com; Received: from AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) by AM0PR04MB5154.eurprd04.prod.outlook.com (2603:10a6:208:c4::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.19; Tue, 20 Apr 2021 11:46:31 +0000 Received: from AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d]) by AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d%6]) with mapi id 15.20.4042.024; Tue, 20 Apr 2021 11:46:31 +0000 From: Varad Gautam To: linux-crypto@vger.kernel.org CC: varad.gautam@suse.com, dhowells@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, vt@altlinux.org, tianjia.zhang@linux.alibaba.com, keyrings@vger.kernel.org, linux-kernel@vger.kernel.org, jarkko@kernel.org Subject: [PATCH v3 09/18] crypto: Extend akcipher API to pass signature parameters Date: Tue, 20 Apr 2021 13:41:14 +0200 Message-ID: <20210420114124.9684-10-varad.gautam@suse.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210420114124.9684-1-varad.gautam@suse.com> References: <20210420114124.9684-1-varad.gautam@suse.com> X-Originating-IP: [95.90.93.216] X-ClientProxiedBy: PR3P189CA0083.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::28) To AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from xps13.suse.de (95.90.93.216) by PR3P189CA0083.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Tue, 20 Apr 2021 11:46:30 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: eb38f916-5b18-4751-84b2-08d903f1f0ee X-MS-TrafficTypeDiagnostic: AM0PR04MB5154: 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: psIKbriYGsae6zUGDZ1kYHrcQTMjkLLLhcYED4o52q7D4H6bcO8LIXIehi6w98gw9jtpxmsi49LLexiFwUtx/QbIiw5RjUR/ywlZQUi87rn0KuSzolJYTWQYoBCXm/eOKkKYLmMUo3k9l6PZ+MkFO/q03alrLZNvFjPCTR9j0WwJwNTTXGI3DDi8CJ90izxHz0AIkBy+lAK9r37ZG47FKQHo65Fe4Im0urUI06H6IoKtRN38p+50ShD4c4rRCIIJMZGOOEOwqmoraqprk2sBxFBnqZgMykCQbXJ+7jAiw9qG2v8WKoipIfgySyrRqAYDdJ9TZjX/wSYz+ZxQTPeKto4JO5jUVgh41O8QGMWu83urC196dVGRQDRmgZ6GbSQSp75g7tmO1QSXnKIrG3p8ctTGF+aAkBELujj5wf3NK7OobovRe+sy/UcqaocAOunsugXXX+aJoQKdUWgvIMJdhc17/+4WOBInslj55FvLOLX+bAx6ejnsCISDfJe47Xu1ZL75VTAvS3NA/8tjSNYVWY5QcNPxmLly/vR1wp9jCUg1umS6A6MgFXmHpJxmUcTROo7EKmB9SuquWj5vEv4PnvRCx1y6ncP2nk02mmB7oN6G0FwV9d52PQMbDRFprfaJj+PX64lBsHHDd+pRal8ZsEbulqVUarrEP1yFuwrh6KU= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR04MB5650.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(376002)(136003)(366004)(346002)(396003)(39850400004)(26005)(16526019)(86362001)(186003)(956004)(66476007)(8936002)(5660300002)(66946007)(6506007)(44832011)(4326008)(6512007)(6486002)(8676002)(2616005)(316002)(6666004)(66556008)(36756003)(38350700002)(52116002)(478600001)(38100700002)(83380400001)(6916009)(1076003)(2906002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: JxAnRyqQr4twVG0TSQMSuY2c/r6LS4Qiv7YGXwWW0EidRJXsynRN2x6PGbcfUydr6YZ7JUzaJUa/VEOfLm7F6X9hlGQzpiHp51A2dsrA0/cHwKYUMVGv2HvpfdifQk3xQzZX2BmQQE7ZP40FC9Cq7u0ddj8Vbuhxu87nx9KOZoTdkFzYLc9pA6kIHyLxswycdGTMY63WxdMTTy0PZTNg+nvlmly2TgXAqRNl59aeWFs6k4Z11HMIqjpzED07nhpEctKRnpexJ3hVbwH7N0Lfq5QemABOpFRw7gOhdHT6jVbEkyV7DQ2ygPM/2Tn0+a3AmPyhsNjzOGpqM8p1DTtgWvzu9FcnHlQspSe1lNFpYPOhxBAJFVHsQ1YKtyuYKGyCYqcH6iBl+XhimmAsUHUtjT1wuTXo6w+vqqiiYc78T/LN7CWb0RF7WRLg5U8pHJ1pNiG9TecxtugTqZ4m9V/xmlLiMPZx35BxFvAQ3xeegKGI1ZdxNVsj9ggOZlmNOcnICHU5/8Fay3IE/pZKs0tj3JCacZKiJqrHxQTzuhoueTCzC2grlOtkIgsBz8J/44nP5Gg4SdD+qCcAeBqIilHcjkZY0g71/5+Kpv2x5maLrnSk5UFTs1oM2Bs81oIwt+vhBOPHGOyO0qU3XY3ehPbWRqvfvxKTQZjJIXeTwHNgLiwzqz5UP/1QD1IctTGxqaO/M6Ie6cwrc77oPYwVP4u/b3abvaTZDSsiK2Hrt0l1ujUpDaE460jWD9UxHlxN2ma7Dx5Y2TKW+7IBqoEfBrE8buxuo4xFMUqG/yu8h1DGDH0q/ZZbm+wD6Ym1ttNfCgUyT8UwuGfPIbeNOYrpxmlUtaXq28d2R+magdBCs3ICzAgwrzpRkp4sZxrd7eQn+iICtd1qWXqmpCtxgv4M2aY6fL0LFr55uRc0qb/omWMwUHcB2Ut7DKXUUXkNyNO+QIXlmuqpe6D4+LX0PpTLQtqWOzSEC6OLRc0BOzTksGm+6u4D+wy8u5VbM56qHWIOZAAnRplc2DdH1WhA7aWTvMoaFKhZsCxlXB4wasbC2cWnoGycfLb9w2jWnmy/i6yrSZfTy+K9fXH9gOf6B3VEhk4qk+9S3WGf8XNGlX5Ntx4qcgF2NBCYHxamhNgCyPzjheMj/65d+Bb5ZPRHDEzwS/IoUqFQN425yUzmrLUbslW/qPJVMemniNnhNPPVUUHrc79C2yUk0c3tfackypaDujWbIr0tBJop73Cdf4TobZwFZ4R5t6vGezRI6ZNAUZzRbR1Z6LsOtACKsOMCNS0ujiPGm42nkiT2OYbJwULzmei9WGm/h9y29Bp6K88yQX6sMxVq X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: eb38f916-5b18-4751-84b2-08d903f1f0ee X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5650.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2021 11:46:31.4940 (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: M6R+x5TbUR1pWYgqjfIBF3u0Yc96Tsw9A1qMvsFbup+XDpuvSM6h+BUFq3dsbamizVYIyKllELZf/tg7pLPEPA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB5154 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 Tue Apr 20 11:41: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: 425361 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 0792AC433B4 for ; Tue, 20 Apr 2021 11:48:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B61A660C3D for ; Tue, 20 Apr 2021 11:48:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232311AbhDTLsm (ORCPT ); Tue, 20 Apr 2021 07:48:42 -0400 Received: from de-smtp-delivery-102.mimecast.com ([194.104.109.102]:50906 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232323AbhDTLsg (ORCPT ); Tue, 20 Apr 2021 07:48:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1618919283; 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=li7rRpB+Nkntpa7qXnRrbKXci7FBJmHhNF8E/GDrPe3adRSmRhqR5Bc4jrVYcd0aqp0pqh 7BtzPMH5Mve3njlLfXvXC2ZCR2EC88SK1Ki4q22okgTR6N0yqq0U/Y4lkmxXVP0/P1Gtsq qmP/vDA/7KanLeqgHzzjHsCJRp620OI= Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2172.outbound.protection.outlook.com [104.47.17.172]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-2-p-qnXwYGPTC95uZTfVGp_Q-1; Tue, 20 Apr 2021 13:46:34 +0200 X-MC-Unique: p-qnXwYGPTC95uZTfVGp_Q-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Y/1rqm4DQjlf40PXMxWeCYhj6IrzCEp14ZQohUb1KOlunrBadXjI3XfFj1T4WIKqzOFNsQBlwg6lv1Cnw83Jcrjzr7SUy29jqbScCZiVjag44V8T3eUPvVXHlGSCxlCjD3HopJz8lz32MTbTgBPXgE4z6tY0QtVUVZvFC93Y7a4igY1MGqKEGTrMpndUoGWmLK53L1rj88jClyrU7K6p6CmiZVjWtEZ79CliFkSFfp/QPNhz5iWIzZAQpfB5EVHlgZUe7hB32kYZer6/3rkGsmK12ERVW7khdtEdjB9AvNynOjxG1Bhxx0t/1gUeX5rCGguqiVhpmvcUzX7nRAJHyg== 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=LRUbuGWFGIzQ/xn8kG7blQOedq5Z5th9urBYrGgFJLecoD2Il7gXfU9W/snGJQbu3mNdA5gx5F1X2EsLMwqnzO2pUD8SwrU50oVt5X+9w1dojVG39Pk+tv5H9JTKuEF4R7TwSQ/+4jISwqccBt0nNshxEe0FTme6nL/v6fgPt7wxJ+osG/TOz8qoc4mRfudQl3gif3hjnYDm6dluKSS633O5K+2roVnB0be5sfxm6vk3sK7eusryN/7Ih9WovIzmlgDPwuZz68TFE7gkO8pxti1/ki2M/O51lSlfpp1f6RAuaGj62TB9JpH5oiPadHh0i8WML8eYkWBgXbjZ+jA3FQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=suse.com; Received: from AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) by AM0PR04MB5154.eurprd04.prod.outlook.com (2603:10a6:208:c4::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.19; Tue, 20 Apr 2021 11:46:33 +0000 Received: from AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d]) by AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d%6]) with mapi id 15.20.4042.024; Tue, 20 Apr 2021 11:46:33 +0000 From: Varad Gautam To: linux-crypto@vger.kernel.org CC: varad.gautam@suse.com, dhowells@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, vt@altlinux.org, tianjia.zhang@linux.alibaba.com, keyrings@vger.kernel.org, linux-kernel@vger.kernel.org, jarkko@kernel.org Subject: [PATCH v3 10/18] crypto: rsa: Move struct rsa_mpi_key definition to rsa.h Date: Tue, 20 Apr 2021 13:41:15 +0200 Message-ID: <20210420114124.9684-11-varad.gautam@suse.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210420114124.9684-1-varad.gautam@suse.com> References: <20210420114124.9684-1-varad.gautam@suse.com> X-Originating-IP: [95.90.93.216] X-ClientProxiedBy: PR3P189CA0083.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::28) To AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from xps13.suse.de (95.90.93.216) by PR3P189CA0083.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Tue, 20 Apr 2021 11:46:32 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ef786923-2a0d-4aee-69b7-08d903f1f1f7 X-MS-TrafficTypeDiagnostic: AM0PR04MB5154: 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: 12ar3CKvzqpnijPev7KVtD0EeiWB6/Xg6hd9qRDOYIbOnoQrtBh0aCGLPJQHdbUA5ogm3Qajinbos7KH4GLn/vbjW+Bb8p30rwSAsrqE/JOIIsVRzrBEVpu6dWtVVEqBUSu5ViWi+NYmWfJcRFUeoTolY4BtsGNyaAYvaSG6MEYaZ/DQJSXRbRDyReFz7DMIuqAT/OV5tyunVCsxoys6qslvKtjiqaWA/Sk7nARPMQ5aD+Ez5iyn1aRccPyZUBa/y8m5uiFosusq32Q+5wQ5NLT/G64EIQle2iftxmjIo4iDNU1h25Lrpnxp6a/IXO15+jifLbpR9evGgMlDYG0DQ36z7SnjkkGZ8/MsbTyq0H4/xLcjCnUckYjzdswkRxkI0NRhJiKSVVUCYDsHeUB73J/xH70dhn2LNJwZ7rPtcsv1n3JBQEbhr7z8a75Gg4hGydNSP2VTmDMmFrlU/RM8KsH57heFMePgdq0QiLixLUTe/UXs3oH3t6wKyzRwtVDNedID5XsJkoGam5/0BWFaJUdqX4dJuiljjutlfqqkg3vlU/i55fF5OLWpOYQnyyXhIBlKcPudt/CzbD5c7pdnbiqDx+RGGmqPj8Asy5PqWto2TuN+OB1FC4l8eGopvFJl37iWlPoFdVeNMCvsxXCuwv/EYzdFPEdT77maEAYfhcE= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR04MB5650.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(376002)(136003)(366004)(346002)(396003)(39850400004)(26005)(16526019)(86362001)(186003)(956004)(66476007)(8936002)(5660300002)(66946007)(6506007)(44832011)(4326008)(6512007)(6486002)(8676002)(2616005)(316002)(6666004)(66556008)(36756003)(38350700002)(52116002)(478600001)(38100700002)(83380400001)(6916009)(1076003)(2906002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: RmEyKyMYVnGhmF0tHUeq4OvkmbWHqoy4/hm52B+9EBVFu/wU4ck7Kp7rWJ689/PPjHYZt8/6+fT8iy7WH7jY1DWjfmLE5T4R/ZmqZ78+yZsvL1tm9NknRuQlHXnLQUWs84jBLL1U+sI53nLEMKis0qB+BDXvwkphDpzP0PEP0vK2GaUgFWlsRYBFOht6OFoNtTKF8OZxCOP4/AZJrf2AvHxdSrPXbM9bXgy2KCQk0PRPu0qrYjJF1pb4kjKw/3UkmvVxsZG0N142idefu9KSIpZ0mgj3cUM7RmtKGWAQ8e97SBbY4okroGh0jMIsOqV7fg1OyRzkYcpQiideFygxSddIG79YIGcG/7BTGy+9qYjTnmTodHLfS8eJ/Zq2wgLneGlKQR6JfDT7ZnkI3+AXhQ1scMgriZLb2mdOHxxzqsgZP+a2bnZ0rdAIvQL4CfkcTxegwPCrpA25cRFdOGisYkAgdEtBPBloi8oSwTDbEf+GoZUrk/OJ+xK7CHucW9WaImBKrk9mJTwfyWqGkgPEjoUI41bzyMOVpbumSxdBt6gyI6RUlq++6/FpH4RZ3ktyobX+TmOR9DBYmdM4C2hzYn3lENQXVuiAO77Oz66RM0Mk5ijZRu1JPXAjhjhRuD2x2j+vRHcNkD4EIOAF+PoK+NDsONW5eezsKCfhtTQu1kTYEPs6nchb1eLWs/0Wej5Yv2LI+fcK7YrAiTzFSAMKKtqb8l9OHRSdAPxL1adtPH1QT+MSZmyHR17mU8NAcWP1anOyOPBLoiVICUuBrWdUdLD/8urGKIPjsGlTLZF6xhOfxWwGRuytgx0gOtWx9fFiYNO9FIew54G6OsC9g58LG8gv3Sd03PC7tIfHrjjyMnY9k5JI+OIAuW8O1Puy6LN0swnq5I2EiqS+CFLEyR+1Wj4OlTu2AOTPhCxtcvCEO8HA6OSkRj1Jx+BmtZBpDYhZbXe7qDNp++BOS+BvrXx7/laCSnt91k7oPZJHJ0KwBJbhxb6WqoG8qA4xA2rt64/yXgN8TO6XpUMtHUhRPtWiy/5PxzhWiF8PP4SLR3x8Y3sgrX7ZArQr9bsRC8xcGXX7s44hAcJE7rMkLN0EISQXg1tx4bKps7/PY07vI+t7YAhsdgYPR9dY9WXZO3+W023XRDfPi/8Zv3y4urh/O5KTltSpEAuFOlSmQCUTZjBFdw5KVosKRzpqf/lqT10G/H6urXfASlU1x1masrbncttwgU5siAULa7RZ7iZ63qayZO1nEHHkxxhwUTa++6qS32WGw5XRfxHGT1JvsueVtjZC7oTm7sFR6TdYYEKwZXiSJTWHKg4/UESOUiD6lWYuqhFL X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: ef786923-2a0d-4aee-69b7-08d903f1f1f7 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5650.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2021 11:46:33.5408 (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: roM9SdtJuzUiAAXI56WujwHCRvdIUt/J3GH/H+UOmPZwPxwRBHHi1/RpsOjnNOLHbCbyrmj3OCGPN4db/ePTaQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB5154 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 Tue Apr 20 11:41: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: 425360 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 985BBC433B4 for ; Tue, 20 Apr 2021 11:53:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6161C61155 for ; Tue, 20 Apr 2021 11:53:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231196AbhDTLxi (ORCPT ); Tue, 20 Apr 2021 07:53:38 -0400 Received: from de-smtp-delivery-102.mimecast.com ([62.140.7.102]:36020 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230118AbhDTLxi (ORCPT ); Tue, 20 Apr 2021 07:53:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1618919586; 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=V7VF5KEVX4dYvqF7jCXiGRTVxc68LNQ5ZU4J+DHwWXeNurJiqqCJtAyC9MANDb0n1/V4XH +ctrxkfnBUF9g/HMJu9p3lDTi7HaJcIbJYh/EvizuPXO3QdGKumtPcQrvd5kZJ2iAYPTP2 sGnqDTEdqoXMj3Gm45t2gllctPzxT+I= Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2169.outbound.protection.outlook.com [104.47.17.169]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-8-Mf4Ald4COPuvjd_zrSXeSQ-1; Tue, 20 Apr 2021 13:46:37 +0200 X-MC-Unique: Mf4Ald4COPuvjd_zrSXeSQ-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=O7MIXKG30FPrSo0GjNlqIY4kfyuplxUrETEKVCsh7pFhBMkhsrgpKo66kKHiz95Deedwmr7VHm6l1Lg50krsPP5S6T2Aw3BrD3ixsTE4i6SE0HMLTalAdKXaq/zpvI2c/WqheRnKsWSLH8WuvYYwNWQG0vgJ8th6Gm1OEHK2k55D4eyYoWmrliLluL/tD/e0fVQ0XlgsaO7UudWnsPltptyKxLcz2nQNi2wldPrBq2ONzuoW24GB6LbbVNYZrYfJK++fbJsIIAsu0hMRH6iUpQzsSpjikGqv8C0ZPvIQV6QjACswa2NQaM+EUSnPF4toHreP8lzcTNBfonTx6mAPGw== 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=XU0Pde72YbqXzzr8VY1MJDgpvgLiYAD3glGMtzIr0b/T4uKSgMIGUdAavWYzY47xQUQjPr9DzjaG+TIB46tLDx8wmVMljUd/32nMFbBmHmwAVH/aLsuy9LKBZVUnVwu/Zwsa9XN9gXtMA8EwZqLIatEQgnVequSE1/iiK8vyyI3xM2cjIKgrW6f0OkK1v3CbEhysGG0VJPgNJRrypYjtV1WPjR+TWgWw0AF00kF1HFXgmB0VNfGtAj1GNzSAv2QPrz1LSMyJF0BzQ92qMP5xFowr81ZBQhajRa9A96rmOPxzLcTXUiGzBe2bltx6YFsqQHFTQ5xtE9ru7J4VR19gtQ== 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 AM0PR0402MB3396.eurprd04.prod.outlook.com (2603:10a6:208:20::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.18; Tue, 20 Apr 2021 11:46:36 +0000 Received: from AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d]) by AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d%6]) with mapi id 15.20.4042.024; Tue, 20 Apr 2021 11:46:36 +0000 From: Varad Gautam To: linux-crypto@vger.kernel.org CC: varad.gautam@suse.com, dhowells@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, vt@altlinux.org, tianjia.zhang@linux.alibaba.com, keyrings@vger.kernel.org, linux-kernel@vger.kernel.org, jarkko@kernel.org Subject: [PATCH v3 11/18] crypto: Scaffolding for RSA-PSS signature style Date: Tue, 20 Apr 2021 13:41:16 +0200 Message-ID: <20210420114124.9684-12-varad.gautam@suse.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210420114124.9684-1-varad.gautam@suse.com> References: <20210420114124.9684-1-varad.gautam@suse.com> X-Originating-IP: [95.90.93.216] X-ClientProxiedBy: PR3P189CA0083.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::28) To AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from xps13.suse.de (95.90.93.216) by PR3P189CA0083.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Tue, 20 Apr 2021 11:46:35 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 902f047a-535a-436f-49fe-08d903f1f3c2 X-MS-TrafficTypeDiagnostic: AM0PR0402MB3396: 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: 3gDmJIYW/jnsefgEaJ/qdjYlfbvx2wnedMEjeLDUoinmaZgJw53pqluCc3Kru9viYkKeM9OXldyxhTKQlN+G79HSyOf2QiRpjALkdn6TMeUAgtbxt4ttxD9qYxXlVVd4tsin0SWKqUa6b1sJx2AUiLJj3mt1dhnM3H4nY45yvsx1iZbjnaHSXoukRFD8neFrX5b0SBQnjEuF5c/UOK1XS+sA4NQ7IwehLnGm63/YEQodTv/bKc9MAyox6u90Mm2Ktwoev32/aro0djfGY3vKyla1xHRMzD3/UGC1QjFZYZnmxjc5W7oLkbTnPsoZDiJesLVIelOy/CRSdoHmL+L/dB3bhSdPjVqUaD4iNvagq9ntgvLjHYwQFCwYLaHhaVdp940nH/QLljvJAgftpZpNrp8QK7N7akZSEJdRvClEm5EE378Gu6L93nZf7cMHxDALGp2YSoG5LxPYD7aLtvkFEI6tc5QICu/E6M4P1Fkc2dLRa39MAQFEwWPeUuta+IP8pLuziDzRu1cqexc3/CnqPe+dFekjbKNTRkJzwccu2RlpUmZwZo6F1G+50CBRW9BsrcJtnGkR8scMKTR5ZVnKMvvEFYHBv5aEtvU9A7nleR40Bx/7T2arsLTXM4EFsjQIc8uT/r0Y6gwOSfEuiZuCyGc3DwcH3n29aifyvV2tv38= 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:(136003)(39850400004)(396003)(376002)(366004)(346002)(6506007)(8676002)(52116002)(4326008)(1076003)(186003)(66946007)(316002)(6486002)(956004)(44832011)(66556008)(66476007)(86362001)(36756003)(16526019)(2616005)(5660300002)(478600001)(6512007)(6916009)(26005)(2906002)(6666004)(38100700002)(8936002)(83380400001)(38350700002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: BQHclds9BKFNEJmuEj4T444ow/lmjXtFUH21pLO8Uoi5WOjmEwzQ41N5NTBJpYIF/nmaid3RKJeY2Y2kWHYmIaAK0myJE/9yPA8eZJ7Aj87M+ZWDCzD/S3wqnIEG+7t2+KajB0abBxYejE2VTfBbNRsHNWYuyrJtW58WnJzFTRosVsvYqH7Gnr2tBmNw5wuAjy/6fsxrqzfQGePH8lxI7oevnJj+wLNSs7Q0V3giEWTUx3Lr7mPN3eNlAchQQT8NIrQ1WbSRmglvE0y1/VpbZIWVKUazwnFmT+Nr+zLObQCD1zbtzBwKAqPY4jultMh1IjeBv56wjbjnx3TOw+gWVkMv8dY30KCFh1nmJzWA9vPGJQQfAzkeGCGyK2Zjdfl0j97DRS+ORuzqYfyK1LBCnPmMuQAeoaCKuAc1kHLcsykfB7pjJRv6GXqUU9m+yN20o8HsKQbudfvJ6iIFYJ/TAoBWa/kXm6elLayruN6Ax+wvWy27B/ZBkyeIknIHZZc5Ln1UQW627qoeNXD0Gk0WZRAnZ3foif3GW78wvNV5J4AGu35azKTM2kcKxgN5MwVAb7VmzbzSwGe7XXo0DRtNWg38UkD/+7S8IS4l5EXzn07of3UoSpkgtqoB6d7NRx0vDj+5IYEyh89Lha/8oJ/yc+TbscLvWExfI9CXRSM3xQQ5QR869PpxngyHz3pxUKhEdQZzGw9UQbU534AeOUPHFqU/v+tawLYf6MoANr7Jz2E+m4AnPLohiQbRg0F8pHbDjKOUegd7CrhppcMotw28Nv3fGeOJd0QPWjzybb5+lRKS1vg2Gnlvql/9FbR+TJt7ndtmLVPtJ/jkaH9LkV4Jq2Eaw3/wXOdSyh9I8jJMCuJ1Pqn6dpSlojjhsp9XhFGhiF+LgcEF7+DnHvL4EtYr+fIjwCBfLfiG0o/w6lR8BnXoe/ysOUFgNFi/hN+KZWPxJBWfHUhfj+SdAnvLlNT5XqmN1C3DoSba/i8Pe/PWTLzkB+0O7e89h+3NMwTgCTyTRLsiqI1d2n4x/t59sDvbei+mDGs8OkGBEFnPsZKCOF1WI2j/1jOc+vwTcTIUy8TkloJcAce8Gm3t2vRePqAxEkGEBL2dXBcX6QJ/Phi776V1jOCIViqVBLqtsTQtp5AUkGe2h/2mJST+AcCaXPI/jE1AXwCWSh9qAHnJHprLG5AEqVU1f3aUewUZkH09jKY5s7xEqpfEm3YravRGYwHoPyKY9d4mHgUNabjiEtV5CTNzxt99iM+LJ745eWt7cpNi12/wd4ru8nkEFoLnGwEUhJeb+MgMCK/TpU2evTw4kHSrtR2VrEd0yPpVeuZO7v80 X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 902f047a-535a-436f-49fe-08d903f1f3c2 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5650.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2021 11:46:36.2852 (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: h7AgqwK5GK+aTzxefk+ifSdiykylaXfOONZFFfciKhxbh+Zv5wdyixHLxYsOL/pCj78JMXGtLtAp9eVNBocxiA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR0402MB3396 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 Tue Apr 20 11:41:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Varad Gautam X-Patchwork-Id: 424655 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 28FD3C433B4 for ; Tue, 20 Apr 2021 11:54:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E011261090 for ; Tue, 20 Apr 2021 11:54:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230408AbhDTLye (ORCPT ); Tue, 20 Apr 2021 07:54:34 -0400 Received: from de-smtp-delivery-102.mimecast.com ([62.140.7.102]:31874 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230118AbhDTLyc (ORCPT ); Tue, 20 Apr 2021 07:54:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1618919640; 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=EOMupzGMwbHtr4Sr8xRQS7/HtpgE4rBfbmrRmZn9jbQ=; b=kbLRBMpeNSNqgKjfXVprAS7ip2U7lKKlooMc2qV8Hqxpz76JYohsjK4nyQNgv0PGo+gcGH t9HbtTgrjjZX/UMHrR5u9NTA3N9HDpr/zDKCM1pTJMQ+Gpa6E2M1NL03Dov8gn1HEFNYbk w0j3YE2oD9TsXvSrHV88gxzFmK18LdU= Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2169.outbound.protection.outlook.com [104.47.17.169]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-8-wd3ZV1jCN1606-s2AqaItQ-2; Tue, 20 Apr 2021 13:46:39 +0200 X-MC-Unique: wd3ZV1jCN1606-s2AqaItQ-2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=T62REWDaveUEnjVXxDNS6ZuBWSoc7bubhGsTVtm8LQ+RctrwImKArgn7/MsqPibQBzCsY14jQ7V/TS45kgZ6uaSvZqm19z2HR90VvwwV0xnTg8FoWYQZdS+kG6PXBnj3s5IhqO3NHdO8GTZUS8PdlFX+R2/tn2yYcMUZAts6zSA3aH20RzmpUarME0/uhWVKryrXNstoABJBDheBR9eibclwKrGlgYWDDXmlgvkhI1D6VHCEveGlz1SyAc8b70Yc6r8IhTTo4G2RkEC/thSo7Uzil6CkWcSQmBQjBI6J1Xk7r/LPsBqXzbaZ8C9Kt+GAHtOGh1OQ5kfwBtqkcVeYxA== 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=2+m+IY0z8fsaEXhUEPsDlsQ8iOhG2QlOeKccdIAYNz8=; b=Pk3OVJxb5UjZzGB8zOMrNPamsXavKVlfC1tTI2QFv9qN9X5sAxiIpZ2jEUj20cPTzLxosI69gE+gbrhsvpsOJ7CVstsFJcLui3xPRQZuZN5bP/Gyu+8MHwma+f0T6rDUcmtf1Kae6K5gM2RyIRJMcg/qjsWP72puT2gVVecAiX+JeObghwK92Mpy3g7bErI8NAcj640ky9T3X589rIgqLgYE46052f50vJnzUCn5SayGmRCcTtZz4qewmA8wGu1GtcCC5q+TjB2lIE2FE8xxblAMSHxGWtQrBIXjAscgByqk7Ef/XlXYG69T3sPhX3so4d+QduhPQRB2MNGKRyaT8Q== 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 AM0PR0402MB3396.eurprd04.prod.outlook.com (2603:10a6:208:20::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.18; Tue, 20 Apr 2021 11:46:37 +0000 Received: from AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d]) by AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d%6]) with mapi id 15.20.4042.024; Tue, 20 Apr 2021 11:46:37 +0000 From: Varad Gautam To: linux-crypto@vger.kernel.org CC: varad.gautam@suse.com, dhowells@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, vt@altlinux.org, tianjia.zhang@linux.alibaba.com, keyrings@vger.kernel.org, linux-kernel@vger.kernel.org, jarkko@kernel.org Subject: [PATCH v3 12/18] crypto: rsa-psspad: Introduce shash alloc/dealloc helpers Date: Tue, 20 Apr 2021 13:41:17 +0200 Message-ID: <20210420114124.9684-13-varad.gautam@suse.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210420114124.9684-1-varad.gautam@suse.com> References: <20210420114124.9684-1-varad.gautam@suse.com> X-Originating-IP: [95.90.93.216] X-ClientProxiedBy: PR3P189CA0083.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::28) To AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from xps13.suse.de (95.90.93.216) by PR3P189CA0083.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Tue, 20 Apr 2021 11:46:36 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 515f0581-1544-4c94-4aff-08d903f1f470 X-MS-TrafficTypeDiagnostic: AM0PR0402MB3396: 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: hSbGzJd8ti/l4ikEYYJ+sqUtCc2Azt5Cw/ynsR/8Kb+RFB4x+o13dGocFwhxuPmX2LtQfKPtrokemkNA4vTvEuWi7X3SRZff4/K4+jPoxgmwF4PnophgHNy9yMIFRgqZKW31itSzV/8YerDZYSJSiCP5hRSCJOg+gSwO1MXpV6d7j3RMh9z3H/tNd3vAxhq2xG36LOc1Vnq7nAsoGdwu2EImgKaqEn0fVj0iPQkuFwqkdWR8LTFU2xN1g3Ly1g60F2FZ4WE+wbSSAGOnsFgNRA6gKfuHzH+j6SKEvSvsEG3P/Ikhkcy/t+880N09jx712IKQ9krsTf2Iad1Lv4JyHgq0zSWy7hqAFTaUmMT2PkZ0eoIQi5Cyuj0OcC2LKxmup3gETXcNdpuH+e3QEfEgqAOjDRFeuaEhpkbKiXmz2JDI/qP89RkFOzRgZKzo2duViLtD7MdTPMujSXbJ9V9MetQVk8RTn6/tmVzJFuxFkl5cGuDc0OD8jUH3SwKLiNKwF5yWPEkavY+cf1eWDgW4gGktU74ZTyHfRvQcNMyMX+M+emLvn21OM74Gge0Lc0gn0dwjdYVJkytNFYWbq2hPByoASQc6jNHHAjLgkMQTzcHIh+rGZH54KJPR702O2hEu7y/h7DdIcSnV/mkRGByIGQ1EqrYOa2r8SUn1p913Rc8= 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:(136003)(39850400004)(396003)(376002)(366004)(346002)(6506007)(8676002)(52116002)(4326008)(1076003)(186003)(66946007)(316002)(6486002)(956004)(44832011)(66556008)(66476007)(86362001)(36756003)(16526019)(2616005)(5660300002)(478600001)(6512007)(6916009)(26005)(2906002)(6666004)(38100700002)(8936002)(83380400001)(38350700002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: DPWsUNnAMv9spXACOdTQ1aPFMVMjnRAfmuVorchrtDyaCXaclRh4+PlQY697r8c0AjFID9QqOlD2dJpNl0pkGn8bAykiex/as9hT5I58kcJI7rIGwzQjFEPEG8jYTpjj2QpChzMaCMfE7HJowSzEA2L+2+IicaplV40LcW1rwUx69K1AQnM67eWcIOnD7MXKrMnFqKl6rrQjdR4TL07CawkksWA/rCQ7UGTnLz6m88AL+gKKd4/kwiZlxDVr7lkIdD2DkZlAIdnMZrMwVydeYy3IQYzDAmRn3Ykn6sLkGS1k4K9zfctasjSqSBNIPtiKP8owuOA95FQagRJRM/TPQfh/BGULLiXK6Kg1l5402EZHOpfd1Gi8Aww1pReoiuhosncsAMTHS5hf028J1SGA0brL92FlCcYPisYyhD1hv92g8ROKnLFYXGIApG/bve1L0vUcQAHf5B6otgHn07gaom2ALJZb6/q274GbU8szkxwm/v6ylbMzSiwOsNIOnPNW6JocS+fO4NTs11EhP8PlQFqwa/eWFpBJpZei0YvIwTk8YnOYvpt6DlKH8XA37zimDtlCuLrNaEeM3cLgd0fZfTY8ovG3g6+N0EnRhuBoR5HFms4t3SS6jxUsCB3+ii6VOq1qhcm+fsRlcQCDrW5bQ7mvbINf/4NyWu/rJTGwZJV6GIAuygFNXQL+ei2nz3NLnBW4dwC413wju8aaEAlL3fS5TbN7PyLPoJcvQsVzPSrqBT0NEuYB0bmnODfZfZw2UmAv+gfQO9uP7JlFZD0quX45Tq9r2S3CIZDvwK+gvJx4RbepF/p33xST1+RSW4ojaz04PgbbefWlm9+PbNJaKJ94Fqc7pMR8cWdWTQVJB035Oq1gKyoi82g/fHIsnJLmR0Mkj90garblAjFsjKo8GY/EdHBT1Simk7gPL5SUoRgdr1foiVjONsiNG38FhoOsOZ0eAdMy0kaffMi6VkrcB2xqsDywcv7TTHkbxinLIuuBcbjYNVs2uJ5lY7WvO5ZpV2Alf6OEfdkTi8BGSlYRZn095HUPC/VSpvvKPa90kfv66ryx1R4naA9n9OjctwzGxqO1VB5cRG8iqQ+CGtwsp49NvMxSMRTfDVHtdzYcMhoNlzIdmGcOuraCl/hQMqlX8fAF07+ItsiGBs9nbZyWXykIYpHtHP4BhqD2Vzl6F/KlDttaDf0PmICZhqBQ9kKt/rqZ/05YxaW72chAonwSabnhgiPkDPLDRHf3w9olxMGBwtsP7N1tvzmhxlse+WnXxn4EalCugOKGGkkkKBY0A7WYoipoPNfAlHWQjL2UUzO9dOOXJyF7kp+7G5nBTnYU X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 515f0581-1544-4c94-4aff-08d903f1f470 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5650.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2021 11:46:37.4786 (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: aHpc48LoUfw+FcIzjwIvKRYvSbhnBpDTfbN/xokPiYQcWRDtQu3cVQvMCU81qrdTK0/cmnixR5iauT5wBEfzkg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR0402MB3396 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 --- v3: Add psspad_check_hash_algo to only allow valid hash algorithms in psspad_setup_shash. crypto/rsa-psspad.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/crypto/rsa-psspad.c b/crypto/rsa-psspad.c index 0e5422b05c081..40bb6d1dd2067 100644 --- a/crypto/rsa-psspad.c +++ b/crypto/rsa-psspad.c @@ -6,9 +6,52 @@ * Authors: Varad Gautam */ +#include #include #include +static bool psspad_check_hash_algo(const char *hash_algo) +{ + const char *hash_algos[] = { "sha1", "sha224", "sha256", "sha384", "sha512" }; + bool found = false; + int i = 0; + + for (i = 0; i < ARRAY_SIZE(hash_algos); i++) { + if (strcmp(hash_algo, hash_algos[i]) == 0) { + found = true; + break; + } + } + + return found; +} + +static int psspad_setup_shash(struct crypto_shash **hash_tfm, struct shash_desc **desc, + const char *hash_algo) +{ + if (!psspad_check_hash_algo(hash_algo)) + return -EINVAL; + + *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 Tue Apr 20 11:41:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Varad Gautam X-Patchwork-Id: 424656 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 6A6A2C43460 for ; Tue, 20 Apr 2021 11:48:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 350C3613B4 for ; Tue, 20 Apr 2021 11:48:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232039AbhDTLsn (ORCPT ); Tue, 20 Apr 2021 07:48:43 -0400 Received: from de-smtp-delivery-102.mimecast.com ([194.104.109.102]:26748 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232327AbhDTLsg (ORCPT ); Tue, 20 Apr 2021 07:48:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1618919283; 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=4lFyc3yLWpXiOfYcEJyfMrliRSHRYKPlDmfuDpz+W3k=; b=eQ4Drp5m1AAUJ44+0lTuDKz3GJPKV9Yam80mi8Os0Ipzc5t5u3FNQvAKSkLQq6tGgCb0Qo wyRsdWmcOruzjIlNolaRhDmyAfZ+r9GCVN2enVJ5Aekl4+Km4ZRJdLIJvUimP8OO+wfrTU rQRsRWw/w4MQrkCFYH1Lok6BSvUEZNM= Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2169.outbound.protection.outlook.com [104.47.17.169]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-8-A22MImTFMCCI7oQGfa0qEg-3; Tue, 20 Apr 2021 13:46:41 +0200 X-MC-Unique: A22MImTFMCCI7oQGfa0qEg-3 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=i0G7O2gXeNnZXGAjdzC1A0OPO51w03aKuOf35fOEPrLMBDrbfR9EwJez0LMhr38aFjiAuXiGv24r/wzsMrzOpf6Hmezs4MImyFJCvStMd1DSpkDW49vDKYa2Nq+JPqpz65/Cj8nFVQP/YgShSTDmpiDnll1ZJesIiq0W8nDIuK6+p5AUFIXkZ4e5p330J8WTHLoqO0oF0vZXmBQM+hateTmwQebjQcK8n5aNpW8O85zJMWbDMadeVQIMbRmt5HTIKH2ZwI7uafcghW7Ii4XNTItcK5yMNcLy18d7qBap82PqHQHNh6fq9B4WR7fs1lMcwXKB3lb7V/cdcSq9hu9sEA== 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=2Xk/V8iT4HWlbPgVyGyWskiP9ND3eRaEKtYh4i7AFzc=; b=jiXFMrvXyYtB21TDzJQP0rxqcLg196Gk5skcAl7hqxn7+d7EU827Z0NH9IMdxi43Xde9pgB78HpypfT9jpYi0VLPdxoOfzL8hU4aSqdFqtzgX/cuSbaMI8qhBW8dlmySsAeyljSayWcUB1P8Qlx7g4cLSuaiae1fCUAbZLIm0Oe2+nCgLiCkCxR8qF0f1Z/gMAsQALVAj0f0jbbFUwFM3upxn85e3LYjAOQBUSJ+jvcJ+x5r2zuJzIChiNwWVF2k8iFiPxr9GecI0v9oj49N6FV0IPtALpGDCdpUJ6QaOQE5vVNyRv7oCML34CEAX38KZn94B8zgAgehFejunpyg7A== 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 AM0PR0402MB3396.eurprd04.prod.outlook.com (2603:10a6:208:20::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.18; Tue, 20 Apr 2021 11:46:40 +0000 Received: from AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d]) by AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d%6]) with mapi id 15.20.4042.024; Tue, 20 Apr 2021 11:46:40 +0000 From: Varad Gautam To: linux-crypto@vger.kernel.org CC: varad.gautam@suse.com, dhowells@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, vt@altlinux.org, tianjia.zhang@linux.alibaba.com, keyrings@vger.kernel.org, linux-kernel@vger.kernel.org, jarkko@kernel.org Subject: [PATCH v3 13/18] crypto: rsa-psspad: Get signature parameters from a given signature Date: Tue, 20 Apr 2021 13:41:18 +0200 Message-ID: <20210420114124.9684-14-varad.gautam@suse.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210420114124.9684-1-varad.gautam@suse.com> References: <20210420114124.9684-1-varad.gautam@suse.com> X-Originating-IP: [95.90.93.216] X-ClientProxiedBy: PR3P189CA0083.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::28) To AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from xps13.suse.de (95.90.93.216) by PR3P189CA0083.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Tue, 20 Apr 2021 11:46:39 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 661fa924-3b1b-46eb-16a3-08d903f1f5ed X-MS-TrafficTypeDiagnostic: AM0PR0402MB3396: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:466; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cTsMG0MZzkSSy7u2fu4EZwvkg4m1dZQ6K2PMuV3YDSkGKJI4eAEoM56tRSDb1pB+THIlFTUu5wIq2G5mxjx+Xd2iLtmtk1UxCEqRBmgt1NRwE33Sz5Potbo7TuUaZTX4ZTqqHU/7tSHS8ZtDHs8K5t6j3t5+pmfb4UqVCZ9vT2ImKeQa0Nxf9v5OnNdAziWQUNcAEXY2kijWt7oou12OoglP4ZB2mZBOB0q4DWVpJ/dEidATbdcuS4vPasmJ+4OgC5cbRy2+AZECY8kgNukOZDUp1ideA/nht/+ENpXttLCdw1qYAEtKT2P/vMjn+MLdxDSE6YT/iFFjm2k/I6bsrBrLgB4lABAPLoMrjG25lpJBr90elNWy6BYMy8k8lxwXvmJ+QDQjGHT687cISW2XcP+R3CdceD3upRnOfbMNQq4WDmyR/pJ7EylZzkTfP1bm/9CDbKFZ1z5DhkotFCjhXlTeQCRClFRECqmEj3/eL+cBvs/KjEv2t0DlNBAZkUam304pVj+HUdHtmz63339IXSAmNFB+r3wuh6fOzcfVsrXnA+g0Ea6NTBFQ3Q3VmkUXXSLqEOwqD3tlbzwO0FE1N5DSxBIxM9mEutZEMrb/0LpcLzEERmrv3hQu+5ezQvIan1Nq581OTkIWZXM72EccTQ== 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:(136003)(39850400004)(396003)(376002)(366004)(346002)(6506007)(8676002)(52116002)(4326008)(1076003)(186003)(66946007)(316002)(6486002)(956004)(44832011)(66556008)(66476007)(86362001)(36756003)(16526019)(2616005)(5660300002)(478600001)(6512007)(6916009)(26005)(2906002)(6666004)(38100700002)(8936002)(83380400001)(38350700002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: OyeZwPMsSg7lUQnSzKB9PNqpkV5ZXBqrMYtIMtsykyxUMosgquNgyq8Hh7Csln7H7A739zumnMPk53+BwDMDz40u0SOvN+8OijngaBX6Mi2cjrZUsw1o3h+kQLhYfaaLCzjfWVEe+4+84exYSVuSl+0kIodkziOtltGU0uosFnlAAchzbkkg9UfxDmV+D8OehS3mZz6datztT2PEO3Fn8O84RIbWsASEngK0lPIEzra1dBqk9PV08SN3C4Rasq7PDdalDtzI/LF4Q6gWJAfNCA45WeqlfgywZNgSsCLbKjTyoIMAEgceI14lnGLmirYXaflTHDQgu0onBAMKZmAWYY1imL5vsB4TwDYJhFqzOiZN5biJyIDAB2Ykw5cFeNrSKgV/WRGOHfwWdCCvflvfyjN0UkVMu1FWpmU4TzlRSes1BsDPTBh6tCpguNhXxGB6NDmxRGFVu8rw5Uprby0+d/3u62+toIOT/mOJAYSKJbn3LNVZTpPSnuN9SrNJwK+WjYXYbSKL2mBlDc6iCmSMz7SnzC1K97Zs0gGNrfQod+4lOK2TikV3zyqPBkD5y2jXdm5m3f98LLTiPNRzDF5WJTQWDDsqUQsQTr8Ou8CWRGf86w2orlU8fEkEvmxihJljNDn3+bBevpC4dIUszgut+aKC51m94xMYlvRxAFO9sXUZTeZz5vDH5EJ0HoNqTzxj1fNIz38Pmvx/r0eugD1ppYioSiAqtLIF33+J9yCrOrCXhQUsCFSm/1CIFjiNR8qd3AFdWpWbcdfJVsEfuJOLrb1xCjC1E0Jl4ay9Bq0XNtRwgkFqau9qBjP2cgEQjNJxS2RuzGpOSt91J2EoyoaBo+qcqsimaY368UDzKLcqWOkWwtP4I9buqPTTe2ZvQVLrikFNQeiPbvGACKfxbCj9RuPZ96mZKH5MGl1Usuwvu96zNVy69eCId1Wa8/ulc1W7pSLY0CTm2ZXXVKebdNBFYB90VlSqrDG/7ohjvSh4NFFYNCj9XTYjODc8zCMbfU8F+Aywv9RD5ncUAdogIybuMcr4DHEEjVv3ZhsRXZ6YbFW5o114lH09dj8ZLY/jj01JIMVCtkjQTyoixyosT1VusPWwz6q8O7CObhvBm0FxsLqBg/lCV9vg4PuFbXb1uDenoKWPNwyz09UOT0o5LoasdDvm6vCoGhSFD38CIqqLiQZuESE5cX1il0JsXK69aDtjkQc70opguQwK01FOJEStpd/XndTVYKqZYROCQ3IKWqT3Vjv3k+dW3hxpGzhJc8OEI+m2BvzGknMFNjJ9AlSoTgW9L/gYOG2fkx7OWqqIGdMfNAh6q/Clurc7PjLZZbWy X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 661fa924-3b1b-46eb-16a3-08d903f1f5ed X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5650.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2021 11:46:39.9532 (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: CEYfCyuDCDNHR4b4LYnwRQ8ADlIajyszbUQ0SfJD4bUtD9YVa3R3wZpnZtgUM3l9P338ZUOUO9uFT8VITBxazw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR0402MB3396 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 --- 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 40bb6d1dd2067..0a9c0f9e9f0fe 100644 --- a/crypto/rsa-psspad.c +++ b/crypto/rsa-psspad.c @@ -9,6 +9,7 @@ #include #include #include +#include static bool psspad_check_hash_algo(const char *hash_algo) { @@ -52,6 +53,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; @@ -67,7 +85,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 Tue Apr 20 11:41:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Varad Gautam X-Patchwork-Id: 424659 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 C0735C43461 for ; Tue, 20 Apr 2021 11:47:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9409960FEA for ; Tue, 20 Apr 2021 11:47:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232266AbhDTLre (ORCPT ); Tue, 20 Apr 2021 07:47:34 -0400 Received: from de-smtp-delivery-102.mimecast.com ([194.104.109.102]:57690 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232262AbhDTLrP (ORCPT ); Tue, 20 Apr 2021 07:47:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1618919203; 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=MD+r4pw6uAQkNHnxfZHNh2cUWpurcpYUBU4PYm7eHcY=; b=MoKIRvgprrkWfXFwi8anwH6SBbS012Vb0UX4fNLWPl3o9Rp0WmsDJKDupTArCkkRnUYxDW ahHzKC5IJWTDk8whiOBfHcZMZAtX4vq4vZckCwTFyYlAlHGVr06VgFhsj43nQ/ub9dReWp 4hrxYdzemflsusgNe+H1CW76CEuZ4Ao= Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05lp2110.outbound.protection.outlook.com [104.47.17.110]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-35-toJOxvH7PaOpHKLUrj7AbA-1; Tue, 20 Apr 2021 13:46:42 +0200 X-MC-Unique: toJOxvH7PaOpHKLUrj7AbA-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MuhfgPL1IaYcgo8SdXCh/Djb237ua08xV/j90Vg9lpyvjNhrVrHpW/K7V23FwdstWdfGFriAnFLO1Z794bBB5nPM9zVk1xr9Rjw/yM3M64+mIC5FZ97tEaCy9OseDq2u4n/5UfXAJOVPO1mOlJBRy6heWT+cxNH0hgB+0nLU/OORKE4zwijbyzo00BpxV6DAg0stDfVgXoISaExRJUCqC4zDerB4nbz5Hek4pgOgTz/ADpywoyWvCXwZ5/a7NRPao+05PkIGdGRkHGBGL8kyf2fIFXScHWXHHvsi6mUW2h+GiWMca6RswKBYaTjchlpycsHBXG9mEvcacGHQQwL3OA== 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=tQYOA2QVqu3B/sTnmWzy/OgH1SgEXg/Syt3CrThw+d0=; b=LEvhrYs8wDZLjgCMUrHAewWTjcmrSMqF63WEASGENI826zibyCE+1lGvgHQsLxRtqFSmS/EJHjimkBdH8SUO6b0f+GF30YPHz/wqnld7iXtvHH431YbbPuIrYwQ1GBzEklqbbG72mxiXY3qXjSBlHIyekfqvEVU/F49RO1rmJymz8Am7FVX4DGXK7sMW8HroTFq8zdgA8dgGry1fyvpGnk5RnbAZi04isV54F+eKsFYm5hUnDApebUUvHdJDc0+KWtqveqEE24U2jw0/aMmMotMMuxj7IPpjR9KCTVmEUYM211gmg7nep8QUjhCOJAy3Rs3sH6hIE6MGlZ1HE259AQ== 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 AM0PR04MB4995.eurprd04.prod.outlook.com (2603:10a6:208:c4::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.19; Tue, 20 Apr 2021 11:46:41 +0000 Received: from AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d]) by AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d%6]) with mapi id 15.20.4042.024; Tue, 20 Apr 2021 11:46:41 +0000 From: Varad Gautam To: linux-crypto@vger.kernel.org CC: varad.gautam@suse.com, dhowells@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, vt@altlinux.org, tianjia.zhang@linux.alibaba.com, keyrings@vger.kernel.org, linux-kernel@vger.kernel.org, jarkko@kernel.org Subject: [PATCH v3 14/18] crypto: Implement MGF1 Mask Generation Function for RSASSA-PSS Date: Tue, 20 Apr 2021 13:41:19 +0200 Message-ID: <20210420114124.9684-15-varad.gautam@suse.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210420114124.9684-1-varad.gautam@suse.com> References: <20210420114124.9684-1-varad.gautam@suse.com> X-Originating-IP: [95.90.93.216] X-ClientProxiedBy: PR3P189CA0083.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::28) To AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from xps13.suse.de (95.90.93.216) by PR3P189CA0083.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Tue, 20 Apr 2021 11:46:40 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6ae8f027-8d06-4dc9-aff4-08d903f1f694 X-MS-TrafficTypeDiagnostic: AM0PR04MB4995: 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: cvKrRIteC8ArEltpRy/55XicrZOiBIMXBn8FxF33MuUryATngnr5GV5/hsjaPD/n7U+GVk3d8wszS1Jhg6gL2ACuUAOum9mfV1c54S4Z3AOTeV7OqbtIeKPwNi8nuo7dBYuZNIGgCHqBqyMibaPglXUyugZr7fdCY+Ze4UWSB0dTh2hUnL/96hyPhfedmAtGIg9PZ7nGJjkzynR4nB1kQM/zb5gyU+Dn4xAGl3jQoJhRmNOW3puemNV35eus0w2fLp3p/JzmXw5IgOzRy0pW0rqSbUbu8yRYj8RN0TEVC29KgRZk6/vKbHyRG5Mp4kYXQ/wzUcxk3U9JG8+/y2y8rFSsL2j6kzLSQ4gu5Do0zT8MYwVPQrervpM0bfHEJhdH9S8UrqYlmNIUwVw/d01ay9fMln1n2p3aqulOSCTkySnmLIPBCwv15CZTbq4IQnt0iLK6QDPCLssceakfhT5SPznHijescLEhp8Uhp3zVtrRUMQWPBodYO6V1otXLnb6PEaTAC+HQPf4LnUqdrbFbzy3YtQ1n9ATOBvQ9tdqj54yRCBCaoOJixYbEpOUAfmyJqHhoYQeZTzcQiEe+vGk3EzGUlYEvDux34iO4pj4jmtQIL8iVdt4q0g1Tw5hi3060rNFYfpa49ArLRdvujvqub156V3AWFV2ASwcNjY2JRf+FpVYzx7E3H4geplOQcj98DkTDRjI7ea7851/va7NAvZPYtN3etwtZ+harVOgbGYc= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR04MB5650.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(396003)(346002)(376002)(39850400004)(366004)(136003)(316002)(8936002)(83380400001)(6512007)(6486002)(52116002)(26005)(956004)(6506007)(8676002)(16526019)(2616005)(6916009)(478600001)(44832011)(4326008)(38100700002)(186003)(2906002)(66556008)(86362001)(66476007)(38350700002)(5660300002)(66946007)(966005)(1076003)(6666004)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: Bqc83DW0v4L+IX8D5a1OJnk6/5hO777ZO0vbU/aJLNbuHCeUJQv6M7nQ9FzkLzX2oNC/RUyfxyuRyOOu+KkGx2a4a5xTEcnsamwLcPxt575JiKB/mr4h8CdJMXsqOlrekX73Z2mYcre4wNhSU6Zf4Jd86qguWYI+f4bwcDqXXACT3cNF5o6SrXLcpQ2xtEGj+kIehd4xwBG5bMqnhOXIp521ucj6qz9FP3j4Sna2ClSpa4JHRhBrYl1TpFfxVo7+KSwvR6TADTSN7qvvUaTCo4LWxCR3PMg5WDMOJkVaqRij59BxTclcR1G+/OFOH/kefoP8vBj/GnxGe8mCL6JiSDdnpzp1Xf52vNbHL294d4g4Oju9sfAM6ZQlLZFThLueZAXMYWygWo1+ZNac+xtryCncvy9av6QXugFaQdYd81lEZ1leSHDvmXyRpmkAqHHKnXTIKE6FJKpSsG3EN2Gv46zgUL67bH9V0Q6NvRpIGaimEVz6szmUJgtsKJB//GxHKW77ngA1FhNrR/1CweW+WUhhSocE0t0aq1kWEM4qmjhU4dxv+kpwX+IIe5K18J3dLlZEM0bpdZJT8BkKRtUcWUQUR/6NXFHWbZsk81qW+ki5u5cEDDal7h9Z+jG/Df26U5ooo7BVnyid6LguopkzdMdmdmxasPbzKOwcWHtn2wOFKEjwOeU58EbcSKiiDNVOhJtmd01wfnTCjd6fp0mL+BDJTmnhtstSQkZ2kuaq/5aiZpW8oTb7CYPRK7yj13KhhQ10gIBpkm/TZjBP4Wp95TrVBDZut5hXih8VA3WowehXrqJbHmufjP5fk5eejvzgcp7i1/Tl0ZTcX5rG6heXsFhvdcP/sVPoTAxa6n/KVy5EcTOEOEKAGXi2glwARjrPTw0xS9tmvF6Chj8DeBgkbosIZiLbunW4qxyh3lufzMhO6VvS1aHSICfVscwS/GgTOdbm6H3xeAEF3KW4MYtRNFu0s+sm1tQEB4WD1xts4hdI1vAueP0As8qqiWBUUCkynHMdcU+cAQwEhuSBoCHQYMIhjrzL53PvL701UvPXqT2Nj1qrWYU+iNwjL3Xkefh73HOrYcEt0xN6moGnS9hG/xZM0MBrPevLCxreerNVVNqjL13BZeEA0praIrz3lXcCkLg1t45l25iU41GXMltaZawI9axGbvc+UEVq3zdhGbLFIvjfHeZLILW901KO7PXyChE+wXYgD1hPAEyijzryCOOD2z0Qk8C8GU26Z/M4FrWeg5Z4RL4AlTyirmLpkYfa06mmKABVSNv0ENbxCNSoajCSL5aDssyvC2UmrsqPGfnHPDNL5eGjq4vl2IinKn7E X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6ae8f027-8d06-4dc9-aff4-08d903f1f694 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5650.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2021 11:46:40.9566 (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: 7RYh+1wLDabazFC7r131NxDGNM96nh/VNAlnjm/NRDTFX6D66MQnHGsdSgpVTwYxxk/ZZKQW2xKxqcIyTQb6Ww== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB4995 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 0a9c0f9e9f0fe..990c2cda552a7 100644 --- a/crypto/rsa-psspad.c +++ b/crypto/rsa-psspad.c @@ -70,6 +70,60 @@ static int psspad_set_sig_params(struct crypto_akcipher *tfm, return 0; } +/* MGF1 per RFC8017 B.2.1. */ +static int pkcs1_mgf1(u8 *seed, unsigned int seed_len, + struct shash_desc *desc, + u8 *mask, unsigned int mask_len) +{ + unsigned int pos, h_len, i, c; + u8 *tmp; + int ret = 0; + + h_len = crypto_shash_digestsize(desc->tfm); + + pos = i = 0; + while ((i < (mask_len / h_len) + 1) && pos < mask_len) { + /* Compute T = T || Hash(mgfSeed || C) into mask at pos. */ + c = cpu_to_be32(i); + + ret = crypto_shash_init(desc); + if (ret < 0) + goto out_err; + + ret = crypto_shash_update(desc, seed, seed_len); + if (ret < 0) + goto out_err; + + ret = crypto_shash_update(desc, (u8 *) &c, sizeof(c)); + if (ret < 0) + goto out_err; + + if (mask_len - pos >= h_len) { + ret = crypto_shash_final(desc, mask + pos); + pos += h_len; + } else { + tmp = kzalloc(h_len, GFP_KERNEL); + if (!tmp) { + ret = -ENOMEM; + goto out_err; + } + ret = crypto_shash_final(desc, tmp); + /* copy the last hash */ + memcpy(mask + pos, tmp, mask_len - pos); + kfree(tmp); + pos = mask_len; + } + if (ret < 0) { + goto out_err; + } + + i++; + } + +out_err: + return ret; +} + static int psspad_s_v_e_d(struct akcipher_request *req) { return -EOPNOTSUPP; From patchwork Tue Apr 20 11:41:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Varad Gautam X-Patchwork-Id: 425363 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 70952C433ED for ; Tue, 20 Apr 2021 11:47:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3AF92613BC for ; Tue, 20 Apr 2021 11:47:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232280AbhDTLrf (ORCPT ); Tue, 20 Apr 2021 07:47:35 -0400 Received: from de-smtp-delivery-102.mimecast.com ([194.104.109.102]:23823 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232249AbhDTLrQ (ORCPT ); Tue, 20 Apr 2021 07:47:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1618919204; 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=URAufh9G4VgN4MkCX5Z/LjG4n/IsUcl/tv9wamHX41A=; b=eQfFNuqEiLkjJZLWVhwuxhNnEAPIEpCVQAMK4qQqfdr7u5EcLFRNfTMneEtHBtUSPubRzN +gUS6Aii7OKSNkaOwvmb4DQmM8DgvKX7qAxnXct50+lA9bEWmysUdyHT4Ur2Ws73fYukqK EER8AlVsTgj32fQL5js6ERbdGRr0eFI= Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05lp2110.outbound.protection.outlook.com [104.47.17.110]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-35-vVbYYK7PMlmetb-zxZFBtA-2; Tue, 20 Apr 2021 13:46:43 +0200 X-MC-Unique: vVbYYK7PMlmetb-zxZFBtA-2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=F7Xtrp8OmqSM4e8G1m0Px8z+flbmhsyR1xARCYb3KGMVjEoWR4WoX/ljk8NK8Aqqj8hkNs+MQd/K40On5VbVq4HV0QEb76cDThmtaFM4fOHfTuTSsj0ngmzslW15zTOcVcFZDmsIrGHCKuQIAqXNuY21uNgzaXxaot+CAHtnAY2JJ98XT8QNKm17+RpRi5K7F1/iU0N7dlLbrKjp3d/9q0f7oj26rjjv4lkkx+9pkiNZGSHVw+fWFGvaMI/58VhqQpl8rRsh3Mosp3S/2XOadGiZX7QPP1g+a1ejKV9P7HH2bjgPGRheEv12X1GEwTKXxHbekeTJOBj3gPcVvaAY0g== 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=cPPUr1yJmykEATN97PtEAMe5qXCY3900ZCoRjV2kMuE=; b=l7Upn+3hPyE795mC+CGg9SJLM7QkZfzXe4srkU/7IYoL+cXjAizR77wJyRwaUrQ8AHKkW/w8TLBi6Kz3GRs7f9c/uvwaHs5ZlJxcVAELkqA8Neb6fQ8Alshw/+WTPm1C++7H3ygDS4ZrF+1t3JmLfD3eYg8H5jq1Y4GCqunVBV32DyQbgOrGWE6/OhLGO2+HeXn/IU0kOgO2uh9esf3vHVWJ4vjSo1poNhNF9jnVn7gvZdBjmVVawSyS9nkYohZFCJOptuY+D8E10M0LOtA5zslgr7Ey0Pdd+lg4IR/YvmlfHzgPemUrSLvrCssmAKK9HBPVBfiZ2HTJZXnTSYbuRA== 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 AM0PR04MB4995.eurprd04.prod.outlook.com (2603:10a6:208:c4::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.19; Tue, 20 Apr 2021 11:46: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.4042.024; Tue, 20 Apr 2021 11:46: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 v3 15/18] crypto: rsa-psspad: Provide PSS signature verify operation Date: Tue, 20 Apr 2021 13:41:20 +0200 Message-ID: <20210420114124.9684-16-varad.gautam@suse.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210420114124.9684-1-varad.gautam@suse.com> References: <20210420114124.9684-1-varad.gautam@suse.com> X-Originating-IP: [95.90.93.216] X-ClientProxiedBy: PR3P189CA0083.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::28) To AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from xps13.suse.de (95.90.93.216) by PR3P189CA0083.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Tue, 20 Apr 2021 11:46:41 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2c25aba1-7e8d-4722-eef6-08d903f1f72f X-MS-TrafficTypeDiagnostic: AM0PR04MB4995: 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: LYmnkRO+0+kfz42zli0VnuHJNAQk/mf9Zz4imR0lEXblu43xyDujFz+eQZ3G14luGtKbAKfmRlW0+cCTWsswl6Rk5l3iVei5wHxPekojL5XiQP8F2KIKGGjxwGIy11Khn9grf9DSYIVx4v6Ov8iapFnrppotdTWyMuzcevyjLuP3FQNUHio/Yvxif1e8DZ0UIEcLCMBSjyhKYLkWOA1OF2Ygjztd1xs5qpjB5STA6iikYK0CuoLfr/k7M5WhEdyPX5oArAwAPoeaNpyJ/rCgb7uIpWD3flXaaVmzKtqjOJ0TE8OteAZDU+985Q7QbRFibTseXcgmJhPXbVPO4aBZD90obPJA+EroS13YhmPU8EoKWDYsw6GqdLLAd++F9nkfc4HXy+q7vmYdd9vBtMlyT0CYkldyH19d2TFf9hlu+n5aw9qspMw8o1o/nYTr/n7eekwZeH/RHhJz2sDMSB2txAEvO1fq5t0IUn1pjUnXwWgrCwgxY/og0BO8tibTnDh5ca7w0DwicXuGD+OjuHq7jU5vRzJvRKTgRzjy1SbCGer4xKLyUxQtGXhtO/cTDYM/er+2WpyRcAQmouxm/Pm+E+T5V0DWaxtHPIYt3yCi4SRO6Wp58SW6MQCMRzYFcKjkS9kzudRIiXyY/N3Vxn6ChVBGE+ZDiPNDZdMzpFmELe+/g5M17sB2+XaFO31UpAJHXbenfPJmJ8gtB0aHB4OZ0D1lo7foc6UZr7aIuQ0GN5I= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR04MB5650.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(396003)(346002)(376002)(39850400004)(366004)(136003)(316002)(8936002)(83380400001)(6512007)(6486002)(52116002)(26005)(956004)(6506007)(8676002)(16526019)(2616005)(6916009)(478600001)(44832011)(4326008)(38100700002)(186003)(2906002)(66556008)(86362001)(66476007)(38350700002)(5660300002)(66946007)(966005)(1076003)(6666004)(36756003)(15650500001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 8Y/PYh2hxBpyziAxMBMp1L5F1He4KP5YxLSdSzsszyU7AMby1b4QjPRstMcIZxUX6YgKrvmlRsme1luBcr4ym3yeRU12oD59sxRqQZdaGuWyhoHqBE2PDiNIE/UysOWKhZZvWVuOB6EnBL9pzlBHubuIXHtTJpxxfiWOZHjOpkxjK4uy3k2EFvTCYncttaUYDSmBuKHMnKd0tBGefNHi/Dh3QpKze3xvYuIR3wVK3mfk3kQe0DkHz9ar8DYnvWFpZiH2K97gfvr+FxFl2Q45XaHGlbMcTtwZIGfqCenEDCCO+clBfw4N5bJCl0aQMDGW8S+Pxbe6Hl+gKPqaptAjvrMcscCbQSgDyLOlSzzwSRxJYDfThD2n9920PooAetM8LDqJCGyG1L1Fk9Wq1FkqCq5qqLgbLL0WntcYausQTSVLHtsu9P5ANxPuzsylNtAm3qfcbgfSUGQ03MoVcxpc+4Y4kv9I1py7ihCXUS/8S3a7beC7DVtmmh9Gpd8K2otziv2YH1709Cz7vS8zSfmhI0pvQ6pxA1xfuVIhPJm7z2PpGRDU3qQ4UPMFQsLCYvmRoYwpTz8OIojxJrUpDYzgcwaNOBooTwby6Jo7aA12LW3Z/6zj6l+/wdNQpTb/h7PuWR/Hvz2ZeWu3fs9kNoF76PgybO+O8PEgpihaonL3bFw6o8Pida6ym3CDTyOpTnXAQpE8s3sQBTaJ+eqp+brxe4A9C+9sBSQjRKBdFvDR4mOo8bfCv62fcKUUSFzTQEaEx7e2qamJ8JNtZpx9Qbw3a+O952G/ajefwRiePdRZqZR3R8+efEpa88umLs40eQV1QFNyonxjdHRDioBzYc76EWuc7pS6hKqTRakaX0f6byLigG+B5NNuQwiR4Q6pr4M359iDfGGbNmECq6zN59S9DW9taSdvSP9VmCrdCWVpKki/aXTEx1sn24Azsy31SXqK/poS4ENao0RRpRRZVMrEvM/TqBvrt8u0aXdYjpuA3Koti51wo57sJMLXeOJAl85sfSfifKm/H1dFNe8TWcjCdAIrpLwpWa8i70p+a9DCVbciqVs6fmkw0hpaFKGH/NDzjBvsRFanvrU+AEDz38oCpKepg0dKKiLdMwDuqTIjVDGqI50lSgDVWEc5oaWuiytrQ5CDlSjU03Hdsbm1L/8UnbGQnnOeCHTDTVTyje99Yg+jk82QVz8VbeDqd34QGzPFsSKf1eYwdj1kIzS2I1ixfjGeDq7TOxDDaRjJG4VFpvRPh+uxkZj0ekip3I+LDeM+YZqYSZBL63tndEQdqQGzqlJEnTZ4dPB5RvvVrV2zbi0YderpJo8TOz2NFDd6cDQJ X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2c25aba1-7e8d-4722-eef6-08d903f1f72f X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5650.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2021 11:46:42.0320 (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: toRBzf53l1Ox+jlGiC1lgEIy4YdR4Aqr8MLrupfwx5RN+1ha95xV53NodKAmDAzPwFsesdcerObvyLBaonK6qw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB4995 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 990c2cda552a7..4e8525d89172d 100644 --- a/crypto/rsa-psspad.c +++ b/crypto/rsa-psspad.c @@ -124,7 +124,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; } @@ -133,10 +176,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 Tue Apr 20 11:41:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Varad Gautam X-Patchwork-Id: 424658 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 1F562C433ED for ; Tue, 20 Apr 2021 11:47:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DD434613AF for ; Tue, 20 Apr 2021 11:47:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232362AbhDTLrk (ORCPT ); Tue, 20 Apr 2021 07:47:40 -0400 Received: from de-smtp-delivery-102.mimecast.com ([194.104.109.102]:53495 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232290AbhDTLrS (ORCPT ); Tue, 20 Apr 2021 07:47:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1618919206; 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=15vXHCaH+YxkEfgrwleV2XzhWAoSPQq0tNygd8qDnyQ=; b=jsRBdmJbGZLzJYJOXfqd1n8QcUbjIn+Dhc4qafVEydS4/ZR1aUaiPzZeuiB0ka9S6YYSI9 av1vpH+OssJtaLrVh/wK132Kq4DJWyc9Ffu6W4qDXPN3HvrqulKIfQuAjqRvWOQtzXQ4SG jopM7XV+51mUxnS1d9f7Yry4+c5ZXuI= Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05lp2110.outbound.protection.outlook.com [104.47.17.110]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-35-FwvRfpuENhuPFDjRU7qOpA-3; Tue, 20 Apr 2021 13:46:45 +0200 X-MC-Unique: FwvRfpuENhuPFDjRU7qOpA-3 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Y/qJEbjJmljhtXuhBlriYsGFyylTEH8vdTq5sla0r2ZGSbCwfBHjhJzJf26VPxlZfQO3E33lJ6kuLf8j98oCkx1AVqy8t63y5t4TGSfwUvbNClJp3kSDv0QokMMo158uGxtH+FAEK85TYqtzJ0G93OYv9acMAkox800tL8SNBawP02knA6JkWIuzExaHYtQzwQOb+hsg+Mi+yDW2FJKjiWEGCvEIaL6BJysdho4KZqPdp0H8QRlcWxY80sPGw+64lvDfIKKZxbggS+feu9DLomp19khw+wPlGfZX3jJlsEGaz0dUB5JVtpk4Q4QExdjNNEOMBHQNHlQ1F+Uv1viPoA== 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=4kR0kbogPVyQdnEOdtWYnJSMAeXbwjz7KpE1s1gMeyo=; b=JC1L6I4YeZt924mYyEHM1Ef6A/CI+q7nf5F/LRi9fDBBIcbmVQ+txeQ6YGhdhFPXNlmUHvmZ0gFxJm0vSojmdv7yPmbVEHtGIVF9jDe0gw3U5Am87qn/EorWNUtCkaKybaF+lemRSMlc8xdv3iK2J34HRoDHL/vrPC9Sxd0nREOLfkbZZiZtkMf7Z79bh/fNuMYMvUY0Vi92Tl4E7QsfYEpKBk3nJmX7P+u0VFkazEcRkvHzdxj/3Wcc82muytGV169Ymb5PNtidqXr+/7gZ5UJeIPIzY3mWEWftPwl1RKPncFwuc5i/O9lf83Pyi8UxxYT/dAD2UrIGtpAFrbq6Ww== 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 AM0PR04MB4995.eurprd04.prod.outlook.com (2603:10a6:208:c4::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.19; Tue, 20 Apr 2021 11:46: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.4042.024; Tue, 20 Apr 2021 11:46: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 v3 16/18] crypto: rsa-psspad: Implement signature verify callback Date: Tue, 20 Apr 2021 13:41:21 +0200 Message-ID: <20210420114124.9684-17-varad.gautam@suse.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210420114124.9684-1-varad.gautam@suse.com> References: <20210420114124.9684-1-varad.gautam@suse.com> X-Originating-IP: [95.90.93.216] X-ClientProxiedBy: PR3P189CA0083.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::28) To AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from xps13.suse.de (95.90.93.216) by PR3P189CA0083.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Tue, 20 Apr 2021 11:46:42 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 84e4983b-5885-45ef-df4b-08d903f1f7d3 X-MS-TrafficTypeDiagnostic: AM0PR04MB4995: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:473; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Yu2LnJhFqxAc7UbnnElsGlyhRcCv8C0vIGnNX1SrVTMLj8ShC469YmA5TdUhwLBOBz9OeJoxlZBxAmJ/36VE7PcGy310xvVX16TThJRV2OT9ibnLX1WEHSt0fzFJR5Z8FoARNBWT5VBOKZ+2zf+ACKVfuix9Ibkt/yQMJNWAy+OnTA/hP78vCL9sbqdEJTLS2pTCsjxs4QJCJ5CIReVS3ip+kuLnQnDVZ1X0SuHwUCrE8Mj5j7kmJyFXL0qjc6EjDCo/SH9uMr5fBfqy0YsgD40XKaki9HXNc7ATgg2bS+fgAY/jNQTU+eWnnWkeSfw0MdMv3GC2HBUytqHPn3BZhGCzLbn7Q+a/NHSfbvQHT3bd6W2ZNGfV3ACo+/CVMkkGiLCmC7rzdi81SdVGASkBFdmgIhyeuayayonvPIIiLkO8ngUGXlfuUTbxsBgzL1fSy0BWb5/ycGugM2fDbjdnaUcIvufKfDx7TWtJOf9HdW50DHtgDTnUmQqYgHPCPgLT7KJ8jI8s5ANdaQOUhssuuGIGUle+0jf3AmvSdrEhene8MZqUkfsovS7kPFfQikc55ES9yrZHQpkAiJD8hRIMx05SILCwGRV2b9kHyH482hxErW5ZfoYNVxmDB0XaHyjpS1g6rAOHw9bzmmBbnS3tP5Fl2JnZLo3L3IsIps853kExmfZDayayM90IHkon8sZD02rjWj5+OEn0d9unigtCMjcsTDnOGCDl+e+rPWQcGQk= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR04MB5650.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(396003)(346002)(376002)(39850400004)(366004)(136003)(316002)(8936002)(83380400001)(6512007)(6486002)(52116002)(26005)(956004)(6506007)(8676002)(16526019)(2616005)(6916009)(478600001)(44832011)(4326008)(38100700002)(186003)(2906002)(66556008)(86362001)(66476007)(38350700002)(5660300002)(66946007)(966005)(1076003)(6666004)(36756003)(15650500001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: +hsIeiRW99cVYdkeDdDL+aUwOHYoxJQg0N6kWDphu43PmcIlHLcaR8Tn5kqFlqp18L6QGmzeJ8tynQoggpAV67SRhNbpM4H/Vja6rJONOhIOmYxBkdZEdVeUJRX/Y2GqT3G5sg4i3ebHNdo/vtcxsQo83QEFYUzzP5ExTUtzsOqCNmDgtrjIW6fKWVDPJUqPprbUQi96WtpiAiyq6Nmw7aMVAGcW7U6ULIgmzCG7/+tO0zjmNNFHK3f3pl/vjepWUC5kdGd4vgEFxtsp1PI5iu6tIgoCLWtuLaYRhdT3i4WCfd0XXHRQaXP1YgeM7vdlxkCNkmgnvO86nUMRgd0jN2muOt5Fv1gBNQGxiuhHAoDCD7GixwFzYQWsy40wIRTEpRPZrw2mAnzG6juEKVuO+Ktr0H1oZxfhNCTF0eMqBU2+W+4UdVbmMeDNwXy8Xhks7fPsOXaIpImYX8BR5Ov7w1dg92bYYOyjY4SY5GZdRP62+MeMfdIHguoz2fknQH/MpDf4+ZyFms/9lXhaYyFJV+Xa5qdG8XesZ/SiDY745uktPpwdgf/p+so/yd5z2entbMIzD51YJVNXCVyATlsiEY0tg4N0+eWE0XIhAC7Nw7mYuU29fZiT4sgd6p4bS/b0rr9rOmJiOie47Cx24stS+jc8K8g7mdNwnw2C1ZZM3F1IDx0cAn5UUaKV/cRryMxJezB4pgqbOejZYwPOXMCMISelAD2aMCmBEyrmjvzN0YmG5HtpkCHNbJrMV7/CR16Kbtkk2XWi+78IgodQ+nKQ4VocfsN6W5+ukFQF8PgKVWdCDHxXzpvC1ZKL+OA73IbfMyN1jLfoR6PcUGOlJEMCtSg37hEUDYQgp94blbTW4wcEn2C3ZJpePHZ/I+83SlOuQahuGRZyPo2iYwEN85kFXrAQRJGu5OCn34apcXXeRbx5IslpB2PeiY2BfNA2h5J1PlvloUqvoPZjxgCkQpLiFVOZAaq5qUCyrfTsJyd8BECn9RnDfFkHH5PPvhO/73LPnHBvuCcZ09BI2Dd0fQap/QjDKVHnemQKy/tLQm+O4Y/pwVjMrCikp0mlerpGbihTalkmB6Xy8wiSOQe8ms/HTCPZHHni7wzxZ79KKDoCKGl55uxr6yn5Td5VsWxzDlFoZ3PVkElU/exxm1f4eyRuq0lyhhPrxGUz4fFuIwsuyhgHT0nS6/uqfrUXzL/heImdHBcA1t6t0EWdjK/YzIHSzSu8dgYxoYOPvhHsOgBHdzuM0XEEA0TfzdVreqfZA+o4bW3nE9LIVSvkUo8Hq9L9tXMjnyhGifIMlZMuF+qEr3L9G0m9Iv+cLQitGcFLbZuN X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 84e4983b-5885-45ef-df4b-08d903f1f7d3 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5650.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2021 11:46:43.0544 (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: ZVy2w3WCe7FSL+Dk2OTfWcRMQuJ0/q1wK5x0EdqhRxcgaAW2G3bEkTJVoQ+gMkv6mLv/mLWz2EsIy7eqlKlWnA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB4995 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The RSA output must be processed as per the EMSA-PSS-VERIFY operation from RFC8017, which forms the core of the PSS signature verification. Implement the verification callback, which operates on the RSA output buffer. Reference: https://tools.ietf.org/html/rfc8017#section-9.1.2 Signed-off-by: Varad Gautam --- crypto/rsa-psspad.c | 114 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 113 insertions(+), 1 deletion(-) diff --git a/crypto/rsa-psspad.c b/crypto/rsa-psspad.c index 4e8525d89172d..c6f8fb43cb01e 100644 --- a/crypto/rsa-psspad.c +++ b/crypto/rsa-psspad.c @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -126,7 +127,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 Tue Apr 20 11:41:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Varad Gautam X-Patchwork-Id: 425362 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 0FED0C433B4 for ; Tue, 20 Apr 2021 11:47:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D69CA60FEA for ; Tue, 20 Apr 2021 11:47:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232374AbhDTLrm (ORCPT ); Tue, 20 Apr 2021 07:47:42 -0400 Received: from de-smtp-delivery-102.mimecast.com ([194.104.109.102]:26693 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232292AbhDTLrT (ORCPT ); Tue, 20 Apr 2021 07:47:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1618919207; 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=QiFsbwCoaUl/Kg4Ql3AWlmqlMORs4slIqTOI/FF86GG5rsPmaVBGbN5Xr5wDM/V7SLy4ob UBvmbnnzp/DL8VMSoD/40aYIskbap3I67IwqOaFZOkffNdxDtRTbUSAjExzYMBfG7EIzSH +Go3ZlOtBvLnzL0jMcQWFn/5KrAVwCw= Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05lp2110.outbound.protection.outlook.com [104.47.17.110]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-35-4dwSqqHONMucMjlxtZUubQ-4; Tue, 20 Apr 2021 13:46:46 +0200 X-MC-Unique: 4dwSqqHONMucMjlxtZUubQ-4 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UXi+czS57U3tEggkrE2TDxipNzvJGDVX6sPrurnQ0HrRjtJx5rSduHis7C3oetjLsQHfu7qhUNoUBaj2sqIbDDUA4s2In2VueO6wBp1O1TYL4Ic/qFfjHqzUtmQwabDJ4xjWGnT3lFbGFsDRpRKZdDyK4vaDOK8Y1bJ6W0zXq17J0vlczBAsdvD2uCYRVBcSEgo+XGo2xhKv5Cq4QHizn/WgX61ylp9QAjxDl0gZtR3qtswhg7EW+AVFCXActEtow2Nz+TgocpsbZZPM5lKaOEN4MR5cVen5jFAEH9kv6dZ0n/vU5pEULVcKgY5aLwmzfNZHzwOd2XJHGesfUBDesw== 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=JxfhDn3hacfWxoisSgiv43YhV09GxIRFt70tx7TzuoYCnef3iCMxPCzw1NaI7cYGrGuNfR1WjR77jALzC+6nyMLkTzyFuV12AlEi4UJ2xP0QxYqApUGajYqECJSSTPUflTQCaYyJt0f5RhvkRbO6veRqQH+w1/Awmvm3F5m9ejKvMu3BaPTuRxLTqwzEau56VBc+AulwbFkGqnNEuR/jgFqcOUkKfyYTZRV03GeKe0s2faEU9dOOkJjL6ry7AI9joYms4/T29tumPx3neL2mUvAkvQjmVTzTEuG74OdMI2OrhSRwQjRFXB4kXES1ZVhw51Bpq08V66dTjJCB7EaKTA== 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 AM0PR04MB4995.eurprd04.prod.outlook.com (2603:10a6:208:c4::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.19; Tue, 20 Apr 2021 11:46:44 +0000 Received: from AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d]) by AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d%6]) with mapi id 15.20.4042.024; Tue, 20 Apr 2021 11:46:44 +0000 From: Varad Gautam To: linux-crypto@vger.kernel.org CC: varad.gautam@suse.com, dhowells@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, vt@altlinux.org, tianjia.zhang@linux.alibaba.com, keyrings@vger.kernel.org, linux-kernel@vger.kernel.org, jarkko@kernel.org Subject: [PATCH v3 17/18] crypto: Accept pss as valid encoding during signature verification Date: Tue, 20 Apr 2021 13:41:22 +0200 Message-ID: <20210420114124.9684-18-varad.gautam@suse.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210420114124.9684-1-varad.gautam@suse.com> References: <20210420114124.9684-1-varad.gautam@suse.com> X-Originating-IP: [95.90.93.216] X-ClientProxiedBy: PR3P189CA0083.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::28) To AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from xps13.suse.de (95.90.93.216) by PR3P189CA0083.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Tue, 20 Apr 2021 11:46:43 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e0b4de44-25ce-40d7-8dbf-08d903f1f883 X-MS-TrafficTypeDiagnostic: AM0PR04MB4995: 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: fX0djtRMffAwSPPUiapr3Wydb0JZGx0mvBMDg2jnB1soG9i8vNo/Tq4CJQBugGPRyqqxW3VxO9oGJ/5ldGo03yaJHx7bmQyoeziEvCOB3CL+39FhaV2hAa4otFrUTcsvGiKHs0+ZWCEfI4rCtCJ1pPtJfFVYYvHLadF/TXq6riHe0fNYj3+KOo7fA7vwCg4rk4wsgD4FBIwKJXrbt1SPVKRO7y37jR5SowHwC8fC3ognebY9JifIIBqyfUeMJpylasofz+e0mQy7efkLdAFP3533iqZ58ckn1PH5JdxFfdlv6kvUkLweISMJIJhiCu1ek6KZzjI/gcFCXFhhIpQznrqnaj5mB5LXYfxvwkENeR+z7OmIN5ztcpA+/vX1f+a1726Sst+IZhCAuKoiQ7JkRNXwK/ooowXHHfpyv9CBRjH8tz0ekPzDR2WoscZsjpP4CoU4IlHOEYgT+rS7Ru5mXhXeAwS33ni+EfNTwvWHuhdkvMV0zrLVGy0daClnzxEo3pULxkI334mB+IisOju/V4pLOMCEeFr17UsPvU1QvBvi1R2ZAaN9FykE+6llr55wK7tKfXqeH0+I0x4hoSxleMcnHCqep/gOpkywdsZmoTO5YDr7C8swK5J/dKCSkSha2zUu/O6FqTgOJ0Z3vomYqQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR04MB5650.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(396003)(346002)(376002)(39850400004)(366004)(136003)(316002)(8936002)(83380400001)(6512007)(6486002)(52116002)(26005)(956004)(6506007)(8676002)(16526019)(2616005)(6916009)(478600001)(44832011)(4326008)(38100700002)(186003)(2906002)(66556008)(86362001)(66476007)(38350700002)(5660300002)(66946007)(1076003)(6666004)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: BBdgwLWEBx/8CRWLyILVwUvMlehbHhVHBs4uU3sr5ChRDFfvE9v0SpjubxYmB7GXwedkZgcwnoum3ZFB5/7l1XQZKc4EJMx0bWIOB0hf5gEcJg3LZ9reQjmbiZ9A5At0qDhpaIQ4enstj1XeqnttioS3v/8fu9W/Ud927ssbsPo+7W91Jlx2T9SbDj+SLJ/MlX6AgKibIM4bR3tYkWvdu0HXsZQTr9dp+q2HVzzl3YeiwVJrwqROarkEuGnbNi7f+Pwdp/tZDfmO0pflGBrGf/BMeRTyYdOo0yg0kFu+r/3ScMJd0fnAYtZmlXCbD/c4KWyjU8e0IvtFnt8RpDhhJkKyq/fR4RI4qkqX5aTI1Ujqvj0MJiM0VuABik2boN0tanlH8tt5pFITd7npfH/uhdf+7tH/HOfeRQKReyg0R0uqD5BE/cX4s1S182rUxguP1NPB1GXMG5hGVUtbSeu2CVlXjuf1e6B37czuqc/yTbNAd8YZviQeNl5zfh9FGltdoKcw5DtGmzvGHdrH9aOSQ4cG4L64csgiU8n2wxT5hqrMLYErm2Jmdqh2lMSq0xwoLU8wvlxcKNiPN6CnHsRHo7yUnVO7b0Ks2HkrTHpRhv4Os/r0MSK7GF+oxNzmwFZEsBkPTEjnL617LwUxDudIQ3KzOnjGUjrHHTOuy9kuOo3jL8XMHs9Xl1/NU84LvgfxNBDa6RcSh/KKZ66ed5Wbk84W0SNU5eeQuP6O415dWVK06EQ/9Zo4VTryy2/e9XEWdjRIG0Im65XtIHaqG+CoeukKCgIGxpy57JdmmeNs4JVOEXIMr0EmImvuSaVTnmOF8aG4Mm0FRXl+tgdqnUxXD1/R6kzCsiUbSbpnYQu142wJb5xxGHO81ZC6ErXsReB3WZ551zDkOVpnsJDAqZv13ejehNRIUmFllaX9ajSQUYWjJrrZ1/1OR0ynbVPNLsnFj0lFBwmgdcsgHp7OIq5SJRjxoLZrqu1QRQdUZ6Ak8dTCzx9CGrHYybcc2sagOumbq6RA0s3p1JG9SOc0g2dKZBPQVSxx5lRryOXmi2CtSUwMmY56ZZ//El5Dc5QJfltCgKVfaLSfShVmYWqpKqKTKtB01PDbHJk0aFP5VlVntRSSMPK6B0agtw1qgRDykkQMoxL1XSYYZCb1eNUvYwbbdJ19mOioXhGT1+5r8cmlS9R2n3L8nKWvwsJiKlZz8twbFlNhJzZsPNRWhkrIzwLKoeSps89Gl5wvnibqwYMvCxx3nNN86fKsLfywqCNbe6LnhOJ3Ooa9BuK7k5Br+sAqzDbuZiSX+7XS1t1HdvIOh0A4edSzXF0C2RTjTvwy3U83 X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: e0b4de44-25ce-40d7-8dbf-08d903f1f883 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5650.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2021 11:46:44.2157 (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: 8wBoLncHK/ReI74b4pjitQ+T4mSYgfYZqOa3p8Q5cM4m8NCGlQargDAsXgEa6LtH9NyUSSQ4oyUQIRjHeNKcFQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB4995 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 Tue Apr 20 11:41:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Varad Gautam X-Patchwork-Id: 424657 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 0186DC43460 for ; Tue, 20 Apr 2021 11:47:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BC23660FEA for ; Tue, 20 Apr 2021 11:47:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232412AbhDTLrs (ORCPT ); Tue, 20 Apr 2021 07:47:48 -0400 Received: from de-smtp-delivery-102.mimecast.com ([194.104.109.102]:20737 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232295AbhDTLrV (ORCPT ); Tue, 20 Apr 2021 07:47:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1618919209; 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=Dtx1HpslgLwDNo+cZrr6/lfosvuJM0KIomZbB5ORQA8=; b=HkhJYVjC5qKjtK3f1fOySWwq0XVV5Mv+BFcsoXnkftbxI9BUqcLllXXwJ4Z4n11d/3PQgD baBDLB6wGna8pPgIuEA+8qCDDPIVaQfz3784UN+oLQ8dNkylxRaDUAajauOha8bt1bjf1W hwifVM8vCIM1C4cGxvZZKC6oLU6Iiww= Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05lp2110.outbound.protection.outlook.com [104.47.17.110]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-35-JZg3QnJTPEubXxg26mwsqg-5; Tue, 20 Apr 2021 13:46:47 +0200 X-MC-Unique: JZg3QnJTPEubXxg26mwsqg-5 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DPOUozchl8cljvcVEVsRyOicRIKrJg+T24zDf5di82fqCedrSb2pOAejtcNXiMsFpUlh1MXeY/sGtpyzrzGNUqq7pJ+sPMkEECGvIxzRRtyOBvIFCi3s+cojVsqJN1CYUnWLTIHdkI2TckiDrGG25B3nNA02/AEuQbbyHZannJ0cp9aXZziteXD34JBdUMI57mk3luWU+W60CMtfcfBv9HVxGbh66U7AWHfgtTbM5pACW5zCrAjAUytVmd7SIrilGe7tr71nUahUL7ZgsGUdvJEsb7p41D89kLmO5nsvPQ0gZiQpTBwt0z7aq/HNvrYilk7il0UZDvsFiVAlt/djmg== 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=ZXBTMCgIrSY1cHuJ/Qcn642Fg/21QQ2PFDUiHYMpMbc=; b=LkvrPewPDA6nlYK8IYhwR3PIOy07Y32udbZsINT4oVG9P3IqS9kNDizWE+sc/GHQJV2owwU7RhMKODOGFhNqabg3vMESN6oAcGRzzxC7Ll20bQfCuarQJCQi5kn6JceDAJDSe+wShDsLtIlNCETwQUSDCJdaT55kHpFDC6H0CL5akXodHthHXAUMZ3xo8jfxy+5kBi82NYt7o0Efvz5bBD21E8rGHFh9loJNwV3V2b8nDDGriGlbct202SXi8DWvecs/itgVEtwPIjQzKEiSTwDTjaJyg8slcvHgOL4MH1Tgm1WAUhjs3EXrhY/dREs3YsUqNz3Xtvt8f5buHY8GIQ== 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 AM0PR04MB4995.eurprd04.prod.outlook.com (2603:10a6:208:c4::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.19; Tue, 20 Apr 2021 11:46:45 +0000 Received: from AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d]) by AM0PR04MB5650.eurprd04.prod.outlook.com ([fe80::756a:86b8:8283:733d%6]) with mapi id 15.20.4042.024; Tue, 20 Apr 2021 11:46:45 +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, Ben Boeckel , Jonathan Corbet , James Morris , "Serge E. Hallyn" , linux-doc@vger.kernel.org (open list:DOCUMENTATION), linux-security-module@vger.kernel.org (open list:SECURITY SUBSYSTEM) Subject: [PATCH v3 18/18] keyctl_pkey: Add pkey parameters saltlen and mgfhash for PSS Date: Tue, 20 Apr 2021 13:41:23 +0200 Message-ID: <20210420114124.9684-19-varad.gautam@suse.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210420114124.9684-1-varad.gautam@suse.com> References: <20210420114124.9684-1-varad.gautam@suse.com> X-Originating-IP: [95.90.93.216] X-ClientProxiedBy: PR3P189CA0083.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::28) To AM0PR04MB5650.eurprd04.prod.outlook.com (2603:10a6:208:128::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from xps13.suse.de (95.90.93.216) by PR3P189CA0083.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Tue, 20 Apr 2021 11:46:44 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8162cf49-5add-4cd2-0022-08d903f1f968 X-MS-TrafficTypeDiagnostic: AM0PR04MB4995: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:765; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fuNmE30MKCe5WhlZc2k90IeNafgIFeNIRqFA88btmyhfpKhaOBfEUIHKH4BSyFo2HqLN/wrK005gwGqye8lVtaaDC387QH5/JP2Z5X/Pp2k6PG9nH+dO7xlBYqKNfTkynl7lQIZTUT2y7cmNjU/VfwqC/S5DMLWLDmezBuxPprEdi752PV4OzlREAjJ/jiSTnrfdO6d0Q2YMy3sEmAV7ixXvWd15ndQ1vnJpUilIfmeQaLiSBqh875XHrzToI4s/kZ6kfYN70w0VwGixboGhknSlVoKRU9xQtUQ3zAqktGdziFSFOeekO6ShjpYqZswZvA2ARQGdHvjgcfym8PfIJfCN1QeEKgzje2ymVHgZJSD69cCe+TWCd9h9B/BCewPcogvodKueg/7gfgtKeuSqCCqDFm8Y7ShvzR+L1RFATFzrAXoCfBHJDh8j3uYF6ucsfLAflfkOuE7Xs5o4WzF1+hZX01fnGYQChyDBGX7zgOYJzNKK8V1By6ZRBTz1AvgXUW0c1UeLHlHNDu4kk+Yj2r25imZLKQkHXOXb8qBAxL5GyjaxlG0zoWZUC1bGIcAnzQ/89zzwAA20vTaMz5razyMW6BukrUpikegrl7h6yUuljDd1Vh4J6lqItJJ9EIpItcUZGfiKWdvhsqKunPrA1g== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR04MB5650.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(396003)(346002)(376002)(39850400004)(366004)(136003)(316002)(8936002)(83380400001)(6512007)(6486002)(52116002)(26005)(956004)(6506007)(54906003)(8676002)(16526019)(2616005)(7416002)(6916009)(478600001)(44832011)(4326008)(38100700002)(186003)(2906002)(66556008)(86362001)(66476007)(38350700002)(5660300002)(66946007)(1076003)(6666004)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 8D/zJbXtArmduRmpk9vkopRxsDcPL4JuRvXKvLjEgA18ukf6rOMd7OsZoIWjiWkrshckotpuzxhXh1qLeTeR37iVo+EN1twxtBOxBzy/+PzJgHHdOVQV8u63V6mNNtbsb7SsIz8ryeCwMFFqoRNOEGyNVnIdhSGlkfFNSEka/r30EZPC8jRBSb6GyEIOgS2COy4Wg980YrjIQJIiRcivG9GEUYWQAdgp0VHDE8inA8+49QAPm+SzcejBWL+ZlrdXc3xKgSynl9XTfewQeAl9zbZryifB8mx+AZE+Mv/xa3kqCz37LeWt5IRa+tzWNN/dSUZtwQ2FQlP6aS+8aE0rw3TqpP8u+rwauO9Lkb+hwRvZNqalsJPqa180yDOs5C6pbMgNaq/KcdPVEStXosOnZOrq6jiXREQsd96Qqk0zHqijosny1BBA62NzgzSRpiSc/iSF9SniPZZ0vrAU2twIoe+Miskn2D1zmeby1otJaUvow6J5dzVGMLWhGu//xB+bCJySQh+alrY+JBnhix4qnxs1r9umOQvmOR5oDxU8ELHYg2Ct/FPhim6dzNapTu6JpOEodKfzsYXLvazOfYv6F+xqQeINwxZQeqQ0G8ccYbxeTK/DJsBtUM0tjjJGvGACx5iA7DMWxupOaXlFTUYVTjKU6rbww/NE8wqkjkjTax5iO0Rpy6QrGx1GH4jKxOMI4UNpIactor/sZZkzeiKlQzRj5kK5upL83p9QRXtnn16EPTU4vY8WsDj9PXumsmtrlMaIY94EpPS6GaEQ0LR0nMoMc0oOCc/848QM7SDEBd4zMGDviQR6zdADTBd3r5j0TTuE4VsJXe6OIxJrldBWRgl4I3oFvllXxGp9yEWcgEoKcx9VTgl9Iz1yl8CTiNcKw/IX/3JeoquhD3/6PHAIQupxI9rIx5wjLa5P+uRaydMRSiNGXBBGBJZc+gj5XVIuoSQJ16U116CnHB2TDXqrkrPj8H0KSsON7qVMkqy6LNBTSUWrDwvsIwOtNLHqYLY3UNlMbmcmBu2YRelHUT3pUfGZho3KT2pWQUS/sp5HHMUTuVbHsXQtwfsWPzqXunIcFBupozmHOtR8TMMJPcVsJMa4NwzPgisshqqi+vAszXPwohFpS/YLk1KITDxzYd5KcJsb9Z80RBh0hpBHm4trIs/5Q8LdoziqrlQfLeRjN6I2cUjNdj/hdf6LHCDNZF3SwHiyuQGktNDR2jiB+0F/6sYwGW2kCwGmupqB1c0TRnQLB+ARgTfQPJQM+7OhX4BOp6Bt0FO9ABcVDQH/1hEW4T62f8HLUAsEB0Hgw3dLabh63+OEtffHKGW9g89g0IXI X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8162cf49-5add-4cd2-0022-08d903f1f968 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5650.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2021 11:46:45.7009 (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: k31+wdv5d1mVNKQu2RNfaiKKgJnwDuHMRlNFXzI/XhugZZl2maVW92YAa7lSXgFey7ctSXBykdgOz+hhga48OQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB4995 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: - 'saltlen' 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 CC: Ben Boeckel --- v3: Rename slen to saltlen, update Documentation/security/keys/core.rst. Documentation/security/keys/core.rst | 14 +++++++++++++- crypto/asymmetric_keys/asymmetric_type.c | 2 ++ include/linux/keyctl.h | 2 ++ security/keys/keyctl_pkey.c | 13 +++++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/Documentation/security/keys/core.rst b/Documentation/security/keys/core.rst index b3ed5c581034c..4bd774c56899e 100644 --- a/Documentation/security/keys/core.rst +++ b/Documentation/security/keys/core.rst @@ -1022,6 +1022,15 @@ The keyctl syscall functions are: which hash function was used, the hash function can be specified with this, eg. "hash=sha256". + ``mgfhash=`` In case of "RSASSA-PSS" ("enc=pss"), this specifies + the hash function used with the Mask Generation Function + to generate a signature, eg. "mgfhash=sha256". Supported + hashes are: sha1, sha224, sha256, sha384, and sha512. + + ``saltlen=`` In case of "RSASSA-PSS" ("enc=pss"), this + specifies the salt length as a u16, used to generate a + signature. Eg. "saltlen=32". + The ``__spare[]`` space in the parameter block must be set to 0. This is intended, amongst other things, to allow the passing of passphrases required to unlock a key. @@ -1700,6 +1709,8 @@ The structure has a number of fields, some of which are mandatory: __u32 in2_len; }; enum kernel_pkey_operation op : 8; + __u16 salt_len; + const char *mgf_hash_algo; }; This includes the key to be used; a string indicating the encoding to use @@ -1707,7 +1718,8 @@ The structure has a number of fields, some of which are mandatory: RSASSA-PKCS1-v1.5 or RSAES-PKCS1-v1.5 encoding or "raw" if no encoding); the name of the hash algorithm used to generate the data for a signature (if appropriate); the sizes of the input and output (or second input) - buffers; and the ID of the operation to be performed. + buffers; the ID of the operation to be performed; salt length to be used + in case of RSASSA-PSS; and hash algorithm used with MGF for RSASSA-PSS. For a given operation ID, the input and output buffers are used as follows:: diff --git a/crypto/asymmetric_keys/asymmetric_type.c b/crypto/asymmetric_keys/asymmetric_type.c index ad8af3d70ac04..2d3419509ec35 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->salt_len, + .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..b0122ac6e11c9 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; + __u16 salt_len; + 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..019f112474dcd 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_saltlen, /* "saltlen=" eg. "saltlen=32" */ + Opt_mgfhash, /* "mgfhash=" eg. "mgfhash=sha1" */ }; static const match_table_t param_keys = { { Opt_enc, "enc=%s" }, { Opt_hash, "hash=%s" }, + { Opt_saltlen, "saltlen=%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_saltlen: + if (kstrtou16(q, 0, ¶ms->salt_len)) + return -EINVAL; + break; + + case Opt_mgfhash: + params->mgf_hash_algo = q; + break; + default: return -EINVAL; }