From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mx.groups.io with SMTP id smtpd.web12.6310.1618968528789610842 for ; Tue, 20 Apr 2021 18:28:49 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=KoOgh9Pz; spf=pass (domain: intel.com, ip: 134.134.136.20, mailfrom: jiewen.yao@intel.com) IronPort-SDR: ZfITneXuvnUYpAK1PnFlsz5cThWc8VYL9Tn4tqyz7lJ32gmAnSLtcqFqrGyG5hF0rr1AFjDVuL MIaT1KxkI0AQ== X-IronPort-AV: E=McAfee;i="6200,9189,9960"; a="182754411" X-IronPort-AV: E=Sophos;i="5.82,238,1613462400"; d="scan'208";a="182754411" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Apr 2021 18:28:36 -0700 IronPort-SDR: d+xPRRV3hTXm7u6aAKGQrtvbwsojuguBkdF/a3IHIL+yYPrJ6SKjU/9jyTEqlhaPmSQqACo1XF b+3CPO8acr7Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,238,1613462400"; d="scan'208";a="602750614" Received: from fmsmsx606.amr.corp.intel.com ([10.18.126.86]) by orsmga005.jf.intel.com with ESMTP; 20 Apr 2021 18:28:36 -0700 Received: from fmsmsx602.amr.corp.intel.com (10.18.126.82) by fmsmsx606.amr.corp.intel.com (10.18.126.86) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2106.2; Tue, 20 Apr 2021 18:28:35 -0700 Received: from fmsedg602.ED.cps.intel.com (10.1.192.136) by fmsmsx602.amr.corp.intel.com (10.18.126.82) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2106.2 via Frontend Transport; Tue, 20 Apr 2021 18:28:35 -0700 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (104.47.58.171) by edgegateway.intel.com (192.55.55.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2106.2; Tue, 20 Apr 2021 18:28:34 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hwFZYGZ+zFrbW3SJcEazTafVLd6eq90rJhKro3PxL8k5lXVMEpGEixGnH9hwNAALpr8uK7t73NKk55/LHb9igB35Lw17aJvfsmfDafdx4DiBczZ+4KXQ6Givrxi9dBYGk6dOLW0YWe/3VwZfe/zSWCQv9sAfyLAl95js5rpeuw9Dm48XH5uoMX+UJRUgDCAlI/MBkAgjCFOuHR5GKS+bK+kJ5D8Us7kZ5aM1USvV7cGLV57vjRtDxC2WiEB87B7Cbo0b3zPsxo40PAfOqDHLIoS5lvdX79XyykNe3ZxGve+1MZ1l2MJnEMlH4cEd5kyNg9WLaa2JMT+oOX7szjNZrg== 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=li2MiWjERI6micy/rpBEm+XefhtkSDd5P0RsIkSG7No=; b=j9gylftx6V71lYMWeDMaZx4lXyK+qW2DMkJvIKerU+iUhHMXT/3OlNNJbxaWbAi9oCBgFGSLDG4jfko52sLelARFeJyjKh/g++SrFejaQB4zCVSaXhvt4Cbg1Swk6rUF9Lffld45Xh/RB+MnB4oCdLJ5dLGt5jYASHFnfYAzAJUwylH7FqJ4S6aATUzcD97kB1tvN0GH5G9lJl4RXD999BwT8weeOAqy+wfrnVam/WMflzJ0A6FU9qyutnBx7izcZ22diXfYT8AWW+3TD/5UvWaNeSpjHWJqF5yiVURodQNPvc8ZmnN2L7EnKhSMf8qK/lxcJ6e3uYhe3iY3ieMLFg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=li2MiWjERI6micy/rpBEm+XefhtkSDd5P0RsIkSG7No=; b=KoOgh9Pzy+Lo3kXMUISX8QO0WpdHBM/Lq393heYjliyPLUFiWNSSKZby1ytszs46b81npts7LX3CodGLDN/lCmY6/5ZI1x1ZXnh07CRlCTwBE0YmtmQ0VfkNTugaA5peU45s7tre5kFa+jhBAqvuNEZpssJC5MUUnlWkqS8IMbo= Received: from BY5PR11MB4166.namprd11.prod.outlook.com (2603:10b6:a03:191::25) by BYAPR11MB3541.namprd11.prod.outlook.com (2603:10b6:a03:f5::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16; Wed, 21 Apr 2021 01:28:32 +0000 Received: from BY5PR11MB4166.namprd11.prod.outlook.com ([fe80::c9d9:1b92:3014:6f17]) by BY5PR11MB4166.namprd11.prod.outlook.com ([fe80::c9d9:1b92:3014:6f17%3]) with mapi id 15.20.4042.024; Wed, 21 Apr 2021 01:28:32 +0000 From: "Yao, Jiewen" To: "Agrawal, Sachin" , "devel@edk2.groups.io" CC: "Wang, Jian J" , "Lu, XiaoyuX" , "Jiang, Guomin" Subject: Re: [PATCH v1 1/1] CryptoPkg: BaseCryptLib: Add RSA PSS verify support Thread-Topic: [PATCH v1 1/1] CryptoPkg: BaseCryptLib: Add RSA PSS verify support Thread-Index: AQHXNYklz3Rjg2QaiUSFN9fpAiRHjqq8rqtAgABREACAABsoEIAAayyAgACmqYA= Date: Wed, 21 Apr 2021 01:28:32 +0000 Message-ID: References: <20210420020150.29212-1-sachin.agrawal@intel.com> <20210420020150.29212-2-sachin.agrawal@intel.com> In-Reply-To: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-version: 11.5.1.3 dlp-product: dlpe-windows dlp-reaction: no-action authentication-results: intel.com; dkim=none (message not signed) header.d=none;intel.com; dmarc=none action=none header.from=intel.com; x-originating-ip: [192.198.147.195] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 4664958e-fb4a-4afe-88d1-08d90464c67f x-ms-traffictypediagnostic: BYAPR11MB3541: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:10000; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: Nks7e5mPgM1gFLUGxQGUi8G8rHZtxiIonyBOxx56/tDC72BTzTTp7/t49AxsMJJAGP1U8ifu3KNtoZllkDDADyrrwP6vBASeval7f+QnfRMFbCYi9QOn55CLRVRfZWdvcvNWKpnJB7JCc8Lf/AaKbLnqBo1jvMfTqFPDTv79Zm3P7cTqCbeOCpI/Nzz6iDEDMm3moR5nbiJTLpM3xQdrSclKT8Df7Da7SsQsNT+Yh+PtwfKkpRitt6kKYsEb+n5N9ZjqHDuvtDzi/YaeHHxQzfsbIvMybo7mYHRr858+jimiVhUAoXS0kFIxqD/MfCEqxOQV1EQWHFG3BXT6CW+ENwJ2I3lvLrlKm/x23sn1/g5C1C8ay4IIqN5yAe5uyTs0iDqIyJJo+udyydCf5g5oiADtdIE8ydmiXliwyykYkYeBCWJ+LhHGndPUnxh3Jsxg4tMYFLuKa2GgjFWH+Ea7yAUWmomcmgGT5yV0fuJONtcp5ucPlyWqcYtkBuvqUH3L1oSGg4bTOSaG8TENnXWN3D6bP3HjgHEzLZCUoSdIHR4YlRkRW+MDIk39D2XDyClFEgJzREZoKwM78OA8t/molP2xWaENC6CgQaMvkNQ5cB8Jy4WH5vdPtC1uJSGnoRAvMefaZaTsadjQAhzLcTIZA0RdzHhsF7VMuAYBGQ8/F6TZ7+RIMOxY331C87XJ/CrHc2ZSWMTtE2q9Va1Cm/bFHuCscIyE1SCR/yfqwOea2Xo= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR11MB4166.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(39860400002)(396003)(136003)(376002)(366004)(346002)(30864003)(9686003)(76116006)(52536014)(64756008)(8936002)(66446008)(66556008)(54906003)(66946007)(5660300002)(15650500001)(53546011)(66476007)(8676002)(83380400001)(71200400001)(478600001)(122000001)(966005)(55016002)(316002)(6506007)(33656002)(86362001)(2906002)(4326008)(38100700002)(7696005)(107886003)(110136005)(26005)(186003)(15398625002);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata: =?koi8-r?Q?OW78j3K2XafCFZDFqyRheWdtABNv6ej7v/irvrG6noVodzrMOp6EhTGfxAytcB?= =?koi8-r?Q?RY6fKydPBzsCYodmHv7fRTW2WLcSy1ifJLiHdAkbRNFyExJwBTEIWl3BAU2ned?= =?koi8-r?Q?F5/9O6Wm3TNHKMfyrCoGaJhK/SCbL+34hAVMhDq6/1dfRUAQbC0rCeJkBwHYYy?= =?koi8-r?Q?TOBKVOF27sLFDHWXD5bbC23Y8Cl8Rb0IiCtMoAwUNwW7uJKvHhi4vC9Xm4YuYt?= =?koi8-r?Q?DZJI6u/Laf/q062qrTWc6CkGwq5oqNlfQOaMVL8qR9gnVe12v6tzR3tmnvnWcE?= =?koi8-r?Q?waqJ1EsU6S0ttTsnCZTc91QtcJWF9RMI7CqW8W1ZGNW2fvXKgbEJUVImRDzQPs?= =?koi8-r?Q?LgTAdoLNd4oGLOHbxdvkiHh4/10cPlpeN3x9WMlYY/87XDRCBIWEjUw7eURR7d?= =?koi8-r?Q?0b4OKuYOzkyl2Pp/Ixu84tz6j1T4FWMZLjRHv7GzN9QFFu/1/YV+UKXmCS6Pq7?= =?koi8-r?Q?/LceqEFZtdUcUoiHGi8ILbEPTh3Rr53LSOdpy7BVo85UxwkIG6Of+ABJgeOi1u?= =?koi8-r?Q?qTZuGXIdEWN+RdSX2mzieVyxfmhyiF7AHajQquepT3sGz1xG1voJ1gJJhG7KhO?= =?koi8-r?Q?C/PDWB3kaFsT0mNJCUymtCqRwDyJbBpEnfEo3dyElBwG+g8eXIrv+GtEkl9M1k?= =?koi8-r?Q?wau7nVaDuh8Bovlyt9+Zr0/Qtv8x7AUxcdxANI1p8QDsjSL1nHg3M1M+Z1AJiM?= =?koi8-r?Q?WDlELPLZ6Ih7X3g2N11ev5y8vzBDwx7jRFnlZ3WhZ0U6nHbCIVekYu4XzR/RDe?= =?koi8-r?Q?WiKBcRIO/BgYiZl0SDoSHPsDfk3/4nmiIl7E63cXnqegT+pUBEs1T/hopVBVan?= =?koi8-r?Q?f/DlNC1eKF7nCZO6Otbq61sDnOlfphAFfD45onnBHJwldo8xldLcsHoaFBVH0f?= =?koi8-r?Q?92hpBq4e7J+KhNMQm8EkzviPPV6AQV+0ZDH1ASevUxDKU3ctGuqcGvk3ARzbej?= =?koi8-r?Q?EwlEiX2Seak0QhD9DOjPR73vWIhZjqWivvxHF1J2xdshZfHpTHGbu5POwtI3lm?= =?koi8-r?Q?YpagaRPqeLNwb6SF3JX9hUQO0tPFg5XqRuwQPztYcz3gE3y48AIgYYclGCat8S?= =?koi8-r?Q?COvE9IcPz6YboDbonb51CiBOYQu/EJUyL/XuynrlVCsd1CNp9JaxihWzf3hIfZ?= =?koi8-r?Q?GYiUuZ+1U+2WgBHpqPQ43K1EHgkDe8r31kk+ZpbySsUmwu+txQfJFeK39wJ0Cj?= =?koi8-r?Q?MJtiLpvGIlnGMabufF2E7a3Yx1Hl1Ih5irruxJCKQLJxNurD0IG8t9omPhDz1c?= =?koi8-r?Q?G54EYMNp5ty9kUcK6mYgCXoQTll+c/3vPwkseagoIS?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BY5PR11MB4166.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4664958e-fb4a-4afe-88d1-08d90464c67f X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Apr 2021 01:28:32.1434 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 4uLNWBOMORZdUrcwAx4O8+eysaJqN1PLfCtXepd6mOH0KhEyFtRV0jEJOHRtrr3OAbdQ2Bjh6O80iMJkOlnnSg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR11MB3541 Return-Path: jiewen.yao@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="koi8-r" Content-Transfer-Encoding: quoted-printable HI Sachin Sorry, I forget to add link for the reference. 1) TPM2 Library Specification, part 2 structure (https://trustedcomputinggr= oup.org/wp-content/uploads/TCG_TPM2_r1p64_Part2_Structures_15may2021.pdf) d= escribes the PSS salt length. For the TPM_ALG_RSAPSS signing scheme, ... .... The salt size is always the largest salt value that will fit into the available space. 2) NIST FIPS 186-5 draft (https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.= 186-5-draft.pdf) and NIST FIPS 186-4 (https://doi.org/10.6028/NIST.FIPS.186= -4) says: For RSASSA-PSS, the length (in bytes) of the salt (sLen) shall satisfy 0 =98 sLen =98 hLen 3) TCG FIPS 140-2 Guidance for TPM2 (https://trustedcomputinggroup.org/reso= urce/tcg-fips-140-2-guidance-for-tpm-2-0/) mentions: Language in [1] Part 1 Appendix B.7 RSASSA_PSS indicates: "For both restricted and unrestricted signing keys, the random salt len= gth will be the largest size allowed by the key size and message digest size. NOTE If the TPM implementation is required to be compliant with FIPS 186-4,= then the random salt length will be the largest size allowed by that specification." 4) TLS1.3 - RFC8446 (https://datatracker.ietf.org/doc/rfc8446/) has below. RSASSA-PSS PSS algorithms:=20 The length of the Salt MUST be equal to the length of the digest algorithm. My view is that, TLS 1.3 and TPM FIPS mode require salt length =3D=3D hash = length, explicitly. May I know that in your production, which salt length you choose in signing= ? If you also choose salt length =3D=3D hash length, then I would recommend m= ake the default behavior to be HASH_LEN instead of AUTO. Also, may I recommend we add RsaPssSign API as well? Please also add the new API to the crypto test unit test. I notice that crypto implementation (such as openssl, mbedtls) has API to l= et caller indicate what is the expected salt length. The caller may want AU= TO or MAX in their special environment. I am OK to add another API later (s= uch as RsaPssVerifyEx) to satisfy that need, if there is real use case. > -----Original Message----- > From: Agrawal, Sachin > Sent: Tuesday, April 20, 2021 11:20 PM > To: Yao, Jiewen ; devel@edk2.groups.io > Cc: Wang, Jian J ; Lu, XiaoyuX > ; Jiang, Guomin > Subject: RE: [PATCH v1 1/1] CryptoPkg: BaseCryptLib: Add RSA PSS verify > support >=20 > Hi Jiewen, >=20 > I reviewed RFC 8017 and I could not find any specific 'recommendations' o= n > salt length to be used during signing with PSS encoding scheme. > However, in Section D.5.2.2.1(Notes 2) of IEEE 1363a-2004, it is recommen= ded > to use salt length atleast equal to the hash digest length. >=20 > We can modify the current API to take a additional parameter as salt leng= th > and ONLY pursue verification operation if Salt length is atleast equal to= digest > length. > This will act as a hardening mechanism for Edk2 as it will accept signatu= res > only with 'appropriate' salt lengths. >=20 > Let me know if this is fine and I will push a corresponding patch. >=20 > Thx > Sachin >=20 >=20 > -----Original Message----- > From: Yao, Jiewen > Sent: Tuesday, April 20, 2021 2:12 AM > To: Agrawal, Sachin ; devel@edk2.groups.io > Cc: Wang, Jian J ; Lu, XiaoyuX > ; Jiang, Guomin > Subject: RE: [PATCH v1 1/1] CryptoPkg: BaseCryptLib: Add RSA PSS verify > support >=20 > Right. That has PROs and CONs. >=20 > On one hand, that allows maximum compatibility, salt could be HASH_SIZE o= r > MAX, or even 0 ? >=20 > On the other hand, what if the consumer only wants to accept a specific > length? E.g. TPM in FIPS mode and TLS requires SaltLength=3D=3DHashLength= . >=20 > Thank you > Yao Jiewen >=20 >=20 > > -----Original Message----- > > From: Agrawal, Sachin > > Sent: Tuesday, April 20, 2021 3:19 PM > > To: Yao, Jiewen ; devel@edk2.groups.io > > Cc: Wang, Jian J ; Lu, XiaoyuX > > ; Jiang, Guomin > > Subject: RE: [PATCH v1 1/1] CryptoPkg: BaseCryptLib: Add RSA PSS > > verify support > > > > Hi Jiewen, > > > > From Section 9.1 in RFC 8017: > > " Note that the verification operation follows reverse steps to recover > > salt and then forward steps to recompute and compare H." > > > > Therefore, salt length can be inferred from the PSS block structure > > during verification operation. > > > > I opted for 'RSA_PSS_SALTLEN_AUTO' as it will allow Edk2 to verify PSS > > signatures of any salt lengths. > > > > Thanks > > Sachin > > > > -----Original Message----- > > From: Yao, Jiewen > > Sent: Monday, April 19, 2021 7:30 PM > > To: Agrawal, Sachin ; devel@edk2.groups.io > > Cc: Wang, Jian J ; Lu, XiaoyuX > > ; Jiang, Guomin > > Subject: RE: [PATCH v1 1/1] CryptoPkg: BaseCryptLib: Add RSA PSS > > verify support > > > > Hi Sachin > > May I know why you hardcode PSS salt length to be > RSA_PSS_SALTLEN_AUTO ? > > > > Thank you > > Yao Jiewen > > > > > > > -----Original Message----- > > > From: Agrawal, Sachin > > > Sent: Tuesday, April 20, 2021 10:02 AM > > > To: devel@edk2.groups.io > > > Cc: Yao, Jiewen ; Wang, Jian J > > > ; Lu, XiaoyuX ; Jiang, > > > Guomin ; Agrawal, Sachin > > > > > > Subject: [PATCH v1 1/1] CryptoPkg: BaseCryptLib: Add RSA PSS verify > > > support > > > > > > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3314 > > > > > > This patch uses Openssl's EVP API's to perform RSASSA-PSS > > > verification of a binary blob. > > > > > > Cc: Jiewen Yao > > > Cc: Jian J Wang > > > Cc: Xiaoyu Lu > > > Cc: Guomin Jiang > > > > > > Signed-off-by: Sachin Agrawal > > > --- > > > CryptoPkg/Library/BaseCryptLib/Pk/CryptRsaPss.c | 139 > > > ++++++++++++++++++++ > > > CryptoPkg/Library/BaseCryptLib/Pk/CryptRsaPssNull.c | 43 ++++++ > > > CryptoPkg/Include/Library/BaseCryptLib.h | 27 ++++ > > > CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf | 1 + > > > CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf | 1 + > > > CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf | 1 + > > > CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf | 1 + > > > 7 files changed, 213 insertions(+) > > > > > > diff --git a/CryptoPkg/Library/BaseCryptLib/Pk/CryptRsaPss.c > > > b/CryptoPkg/Library/BaseCryptLib/Pk/CryptRsaPss.c > > > new file mode 100644 > > > index 000000000000..acf5eb689cd8 > > > --- /dev/null > > > +++ b/CryptoPkg/Library/BaseCryptLib/Pk/CryptRsaPss.c > > > @@ -0,0 +1,139 @@ > > > +/** @file > > > + RSA Asymmetric Cipher Wrapper Implementation over OpenSSL. > > > + > > > + This file implements following APIs which provide basic capabiliti= es for > RSA: > > > + 1) RsaPssVerify > > > + > > > +Copyright (c) 2021, Intel Corporation. All rights reserved.
> > > +SPDX-License-Identifier: BSD-2-Clause-Patent > > > + > > > +**/ > > > + > > > +#include "InternalCryptLib.h" > > > + > > > +#include > > > +#include > > > +#include > > > +#include > > > + > > > + > > > +/** > > > + Retrieve a pointer to EVP message digest object. > > > + > > > + @param[in] DigestLen Length of the message digest. > > > + > > > +**/ > > > +static > > > +EVP_MD* > > > +GetEvpMD ( > > > + IN UINT16 DigestLen > > > + ) > > > +{ > > > + switch (DigestLen){ > > > + case SHA256_DIGEST_SIZE: > > > + return EVP_sha256(); > > > + break; > > > + case SHA384_DIGEST_SIZE: > > > + return EVP_sha384(); > > > + break; > > > + case SHA512_DIGEST_SIZE: > > > + return EVP_sha512(); > > > + break; > > > + default: > > > + return NULL; > > > + } > > > +} > > > + > > > + > > > +/** > > > + Verifies the RSA signature with RSASSA-PSS signature scheme > > > +defined in RFC > > > 8017. > > > + Implementation determines salt length automatically from the > > > + signature > > > encoding. > > > + Mask generation function is the same as the message digest algorit= hm. > > > + > > > + @param[in] RsaContext Pointer to RSA context for signature > verification. > > > + @param[in] Message Pointer to octet message to be verifie= d. > > > + @param[in] MsgSize Size of the message in bytes. > > > + @param[in] Signature Pointer to RSASSA-PSS signature to be = verified. > > > + @param[in] SigSize Size of signature in bytes. > > > + @param[in] DigestLen Length of digest for RSA operation. > > > + > > > + @retval TRUE Valid signature encoded in RSASSA-PSS. > > > + @retval FALSE Invalid signature or invalid RSA context. > > > + > > > +**/ > > > +BOOLEAN > > > +EFIAPI > > > +RsaPssVerify ( > > > + IN VOID *RsaContext, > > > + IN CONST UINT8 *Message, > > > + IN UINTN MsgSize, > > > + IN CONST UINT8 *Signature, > > > + IN UINTN SigSize, > > > + IN UINT16 DigestLen > > > + ) > > > +{ > > > + BOOLEAN Result; > > > + EVP_PKEY *pEvpRsaKey =3D NULL; > > > + EVP_MD_CTX *pEvpVerifyCtx =3D NULL; > > > + EVP_PKEY_CTX *pKeyCtx =3D NULL; > > > + CONST EVP_MD *HashAlg =3D NULL; > > > + > > > + if (RsaContext =3D=3D NULL) { > > > + return FALSE; > > > + } > > > + if (Message =3D=3D NULL || MsgSize =3D=3D 0 || MsgSize > INT_MAX) = { > > > + return FALSE; > > > + } > > > + if (Signature =3D=3D NULL || SigSize =3D=3D 0 || SigSize > INT_MAX= ) { > > > + return FALSE; > > > + } > > > + > > > + HashAlg =3D GetEvpMD(DigestLen); > > > + > > > + if (HashAlg =3D=3D NULL) { > > > + return FALSE; > > > + } > > > + > > > + pEvpRsaKey =3D EVP_PKEY_new(); > > > + if (pEvpRsaKey =3D=3D NULL) { > > > + goto _Exit; > > > + } > > > + > > > + EVP_PKEY_set1_RSA(pEvpRsaKey, RsaContext); > > > + > > > + pEvpVerifyCtx =3D EVP_MD_CTX_create(); if (pEvpVerifyCtx =3D=3D N= ULL) { > > > + goto _Exit; > > > + } > > > + > > > + Result =3D EVP_DigestVerifyInit(pEvpVerifyCtx, &pKeyCtx, HashAlg, > > > + NULL, > > > pEvpRsaKey) > 0; > > > + if (pKeyCtx =3D=3D NULL) { > > > + goto _Exit; > > > + } > > > + > > > + if (Result) { > > > + Result =3D EVP_PKEY_CTX_set_rsa_padding(pKeyCtx, > > > RSA_PKCS1_PSS_PADDING) > 0; > > > + } > > > + if (Result) { > > > + Result =3D EVP_PKEY_CTX_set_rsa_pss_saltlen(pKeyCtx, > > > RSA_PSS_SALTLEN_AUTO) > 0; > > > + } > > > + if (Result) { > > > + Result =3D EVP_PKEY_CTX_set_rsa_mgf1_md(pKeyCtx, HashAlg) > 0; = } > > > + if (Result) { > > > + Result =3D EVP_DigestVerifyUpdate(pEvpVerifyCtx, Message, > > > (UINT32)MsgSize) > 0; > > > + } > > > + if (Result) { > > > + Result =3D EVP_DigestVerifyFinal(pEvpVerifyCtx, Signature, > > > + (UINT32)SigSize) > 0; } > > > + > > > +_Exit : > > > + if (pEvpRsaKey) { > > > + EVP_PKEY_free(pEvpRsaKey); > > > + } > > > + if (pEvpVerifyCtx) { > > > + EVP_MD_CTX_destroy(pEvpVerifyCtx); > > > + } > > > + > > > + return Result; > > > +} > > > diff --git a/CryptoPkg/Library/BaseCryptLib/Pk/CryptRsaPssNull.c > > > b/CryptoPkg/Library/BaseCryptLib/Pk/CryptRsaPssNull.c > > > new file mode 100644 > > > index 000000000000..8d84b4c1426c > > > --- /dev/null > > > +++ b/CryptoPkg/Library/BaseCryptLib/Pk/CryptRsaPssNull.c > > > @@ -0,0 +1,43 @@ > > > +/** @file > > > + RSA-PSS Asymmetric Cipher Wrapper Implementation over OpenSSL. > > > + > > > + This file does not provide real capabilities for following APIs in= RSA > handling: > > > + 1) RsaPssVerify > > > + > > > +Copyright (c) 2021, Intel Corporation. All rights reserved.
> > > +SPDX-License-Identifier: BSD-2-Clause-Patent > > > + > > > +**/ > > > + > > > +#include "InternalCryptLib.h" > > > + > > > +/** > > > + Verifies the RSA signature with RSASSA-PSS signature scheme > > > +defined in RFC > > > 8017. > > > + Implementation determines salt length automatically from the > > > + signature > > > encoding. > > > + Mask generation function is the same as the message digest algorit= hm. > > > + > > > + @param[in] RsaContext Pointer to RSA context for signature > verification. > > > + @param[in] Message Pointer to octet message to be verifie= d. > > > + @param[in] MsgSize Size of the message in bytes. > > > + @param[in] Signature Pointer to RSASSA-PSS signature to be = verified. > > > + @param[in] SigSize Size of signature in bytes. > > > + @param[in] DigestLen Length of digest for RSA operation. > > > + > > > + @retval TRUE Valid signature encoded in RSASSA-PSS. > > > + @retval FALSE Invalid signature or invalid RSA context. > > > + > > > +**/ > > > +BOOLEAN > > > +EFIAPI > > > +RsaPssVerify ( > > > + IN VOID *RsaContext, > > > + IN CONST UINT8 *Message, > > > + IN UINTN MsgSize, > > > + IN CONST UINT8 *Signature, > > > + IN UINTN SigSize, > > > + IN UINT16 DigestLen > > > + ) > > > +{ > > > + ASSERT (FALSE); > > > + return FALSE; > > > +} > > > diff --git a/CryptoPkg/Include/Library/BaseCryptLib.h > > > b/CryptoPkg/Include/Library/BaseCryptLib.h > > > index 496121e6a4ed..36d560b8d691 100644 > > > --- a/CryptoPkg/Include/Library/BaseCryptLib.h > > > +++ b/CryptoPkg/Include/Library/BaseCryptLib.h > > > @@ -1363,6 +1363,33 @@ RsaPkcs1Verify ( > > > IN UINTN SigSize > > > ); > > > > > > +/** > > > + Verifies the RSA signature with RSASSA-PSS signature scheme > > > +defined in RFC > > > 8017. > > > + Implementation determines salt length automatically from the > > > + signature > > > encoding. > > > + Mask generation function is the same as the message digest algorit= hm. > > > + > > > + @param[in] RsaContext Pointer to RSA context for signature > verification. > > > + @param[in] Message Pointer to octet message to be verifie= d. > > > + @param[in] MsgSize Size of the message in bytes. > > > + @param[in] Signature Pointer to RSASSA-PSS signature to be = verified. > > > + @param[in] SigSize Size of signature in bytes. > > > + @param[in] DigestLen Length of digest for RSA operation. > > > + > > > + @retval TRUE Valid signature encoded in RSASSA-PSS. > > > + @retval FALSE Invalid signature or invalid RSA context. > > > + > > > +**/ > > > +BOOLEAN > > > +EFIAPI > > > +RsaPssVerify ( > > > + IN VOID *RsaContext, > > > + IN CONST UINT8 *Message, > > > + IN UINTN MsgSize, > > > + IN CONST UINT8 *Signature, > > > + IN UINTN SigSize, > > > + IN UINT16 DigestLen > > > + ); > > > + > > > /** > > > Retrieve the RSA Private Key from the password-protected PEM key d= ata. > > >