From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mx.groups.io with SMTP id smtpd.web10.2605.1655100472548311259 for ; Sun, 12 Jun 2022 23:07:53 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=OT9yA9br; spf=pass (domain: intel.com, ip: 134.134.136.100, mailfrom: hao.a.wu@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1655100472; x=1686636472; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=pipLeQvARDXWkF3BHA3hxnrSalxY8jg+prM8xj6NFRg=; b=OT9yA9broP71maUdwzGZc1uzfGcmVWotz8BZ8kOgPhSd5RSOZrFSNp89 pdtMfYG2W6hoSi1bL7uzdwytKcpxepYRejYCn2pRmHL05FZNqZql6Uj4W Jnx6ImavH89K0P/P/8ODvyaiW9xG1moixAzfvBISdH/SxGqrjcJ3Ih4+X rpgtPw6e6YyMzsgMHR18Z7tFc+aq3+35i0O9FpOqIY9zqIOY1xsBIGq9+ p8P2pea1QO7MnqRru59cnkns9MXXat41hlqeZqe0NAz8QzAwhlzlNdZUs HFBxBewrdNRnQUE7VPYGou6OmYQPK8pYbQnAYBRE8rzVcBejAQJu4cU6o g==; X-IronPort-AV: E=McAfee;i="6400,9594,10376"; a="342154474" X-IronPort-AV: E=Sophos;i="5.91,296,1647327600"; d="scan'208";a="342154474" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jun 2022 23:07:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.91,296,1647327600"; d="scan'208";a="685851632" Received: from fmsmsx602.amr.corp.intel.com ([10.18.126.82]) by fmsmga002.fm.intel.com with ESMTP; 12 Jun 2022 23:07:43 -0700 Received: from fmsmsx608.amr.corp.intel.com (10.18.126.88) 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.2308.27; Sun, 12 Jun 2022 23:07:43 -0700 Received: from fmsmsx608.amr.corp.intel.com (10.18.126.88) by fmsmsx608.amr.corp.intel.com (10.18.126.88) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27; Sun, 12 Jun 2022 23:07:43 -0700 Received: from FMSEDG603.ED.cps.intel.com (10.1.192.133) by fmsmsx608.amr.corp.intel.com (10.18.126.88) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27 via Frontend Transport; Sun, 12 Jun 2022 23:07:43 -0700 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (104.47.73.172) by edgegateway.intel.com (192.55.55.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2308.27; Sun, 12 Jun 2022 23:07:42 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=G+iRcXH42u+/5m8zm65TeTe8oihmySjEwHggHZUDj4zTbvxor9bMAoHhbzWn92KSCJK+kHYFm8gVdq9C+6H+gjo4iQYRoVH2wJoNnKEG6YO9dOCcDBYJiNhgL8gc3LhIrU9+e64dHruZcc02hE6DHTM+b2o2V6uRBbokoM9NAieY68FcSyCIlLcHP6pmS6y+B/QcL22i4hkceaYM0aEuZJL/2JDPR3TXt9nSogOgOmuXAjdIrmeOl5EHy3PA2+Pnq1v4/S46toWb/Ho38QKCOzWmVM1mfs8aZSnQvGTIX7NYpn8ZSCUSw020II0u3uWmI6PX0TWI/dzG0oDYRh0igg== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=2Q6qVYkYLmurrphrdH8xaqdz4442oprd2Ext+oxcjEI=; b=ks4oIyE5dhPfR+A8JostQgd3a+cBjnYfDWlQN17XQ/g0fyA7UKxDtHiApernSF6W9zbmC3MZaistMN/fWolmauDgUz7jE6J+4gi49jfoCmr5JErhEOCiDv8c2NDWB+tTZ90JoLeXS/qo3jylnSrZvANupEt8OMwwdOv1L4vZC97jWs+vVBi8pVDO0QKLKwKhd+Zl20UQPG7IqMAXl/DNU0YDJfwuUolZbQhGHVxun1VcsMJXZPo7H7ozP9prPhivgvirt5DYxm05minkhIAKZ2Yp8BRjF1h1wYMLFoyrc2Ik0Bq++rTrqFmTt/28bVypQ/fS1+eTAPxVRR9j+aU+FA== 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 Received: from DM6PR11MB4025.namprd11.prod.outlook.com (2603:10b6:5:197::31) by MWHPR11MB1903.namprd11.prod.outlook.com (2603:10b6:300:10e::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.19; Mon, 13 Jun 2022 06:07:40 +0000 Received: from DM6PR11MB4025.namprd11.prod.outlook.com ([fe80::c473:f30f:6b1f:c5ec]) by DM6PR11MB4025.namprd11.prod.outlook.com ([fe80::c473:f30f:6b1f:c5ec%5]) with mapi id 15.20.5332.020; Mon, 13 Jun 2022 06:07:40 +0000 From: "Wu, Hao A" To: "devel@edk2.groups.io" , "Vang, Judah" CC: "Wang, Jian J" , "Gao, Liming" , "Mistry, Nishant C" Subject: Re: [edk2-devel] [PATCH v3 06/28] MdeModulePkg: Add new include files Thread-Topic: [edk2-devel] [PATCH v3 06/28] MdeModulePkg: Add new include files Thread-Index: AQHYe8bGwk62WagpEkG4pFIGSX0lfK1H9w4A Date: Mon, 13 Jun 2022 06:07:40 +0000 Message-ID: References: <20220609060322.3491-1-judah.vang@intel.com> <20220609060322.3491-7-judah.vang@intel.com> In-Reply-To: <20220609060322.3491-7-judah.vang@intel.com> Accept-Language: en-US, zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-reaction: no-action dlp-version: 11.5.1.3 authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: d2f9effb-ee9d-443c-b005-08da4d0305aa x-ms-traffictypediagnostic: MWHPR11MB1903:EE_ x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: i17dBLS+WdUxR/fLfy+cic+SX49LwNlQbIUJWMJbFf6ZLg9j6wbgVPLUTjupzZnkC/cUsZZ++jLijcsUiOO4ijdj8IDIO/GwRRXJ13K+1CtJERW9qj4+RT0/nuDcWlvOB60XJzMvDYKi5N+TXw7LESoI4PGV7zmFuhHFhvX7eBD6+odrkOj6zD9ykBRMw6UnMRXC800wGkjE6t9/mGQxppQshINatj2H4xL8Fy68hSUG2waT0cW5n9/TtBystUmXXpWdut5rglPWCDRBZ8ER/pm/0OM7WBKWYFbnb6OSu+KCidOdUQq2SaoQeIf8Jhr8EhxT2Qe6HIrWTx7F0hL1F/ueK3ouLrtUnJjxNNKJXhFmp+v6BLFCnONYEht0pg86CJhw0wMJCN0+fiQUiJv8DTjzbHdbzA+OV19CJPyF54ND8OaT9klza45zfKbQle+mRdGovHf0FJFVRmKOycrzZffm+BLwAyZb3BDZFAoUIWzvd0DNosyrCeJZepVoVDES2aQV0fS9sq3hmvn3QW+eGNJ4DiWMN9UEJY9Web2NOdiNlPPbTJvJ9VtuzfnZtYfu5QyBjxrq52uQZG68Bxvfk1yFVu36GSUmzcMmKXQbALBLS7op6SzTxtttY1NU0sshssa6EF+pytUXE1Xl/oZfmFsJ/zIR5LzUXwN4azOXvC3uSRNBDS86UcES8DTMf15nhHfVcJe5DRJ+2MJ5Lmfrj2skOEVdy4iekE04kDkg8txHvVBltDIBAwqVXJEbPL8nZ//Nd/cTTMmCy1zLexQgA7aBAVHIze8zhiZILr+NZCWAJhMDWoUDOuRIBlLAd3EnF11UOiIUlJrDuSKbIz3XDsnd8ca8C2R4URSuuNzQLfs= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR11MB4025.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(366004)(86362001)(38100700002)(8936002)(38070700005)(508600001)(5660300002)(33656002)(82960400001)(2906002)(30864003)(52536014)(966005)(316002)(122000001)(110136005)(6636002)(71200400001)(76116006)(66476007)(8676002)(64756008)(66556008)(4326008)(107886003)(66446008)(66946007)(186003)(55016003)(83380400001)(53546011)(7696005)(54906003)(6506007)(9686003)(26005)(579004)(559001)(266184004);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?v7A+Koo4KFWTKKa3Hss/dpMhJnXavr0wc8rVRwLhPzYq9A8baGEfRfRollkO?= =?us-ascii?Q?2ui/b+tNTZ0JV1Gehd1veQUx7nEuyR32msz7qN+9cxk45fKVuNsck3kUSBfM?= =?us-ascii?Q?6xvizBbUEvJcnd86Y7sTA8aq0WEvOjesK24MnC/V7TqABHizJGL8hSRKaP1t?= =?us-ascii?Q?kMnPMfBGAQf0ZCw/vWj3M1kCt/Vq4pkkDF/jA4kBe/MtzKxkfHRiMEMM6GK6?= =?us-ascii?Q?UKAehFq7FvydUwgiti6605GxRedUTiXS1r/QFHd+Dl3l5Vgm1onR/exxm9QY?= =?us-ascii?Q?/hZq3GNh2dSToRvtlJSoSA95MCQflzuD2oqUbgafNeeBEw7yGq4AS1nvb1yM?= =?us-ascii?Q?zV76StkP8zckorfMMjjDxS4fgfZ2KHs9D3KYSJ6dLvNWSo7cwKBFzkABizG8?= =?us-ascii?Q?LWpeG4PuyBMF4SHpUcoJersaxNMlbdaV3FiYpAZEPjxrlrd4QgpQlOBcgRbX?= =?us-ascii?Q?kc/aoM2PjKh2/GU0PXefG278A7WZszzYBa704vjTzNEiX5jxiY1moSlR8CuZ?= =?us-ascii?Q?1RFDFCchawy8yCWCw8LFaGgD49JtHM/1H8bRZP71zjVOIefUeXOl2MavWxu3?= =?us-ascii?Q?NRn+7IzEgxi3ChI22ALbJ95m1HuhwfACLmEYAIOuZcNm6c1zncmA+Bm1bP0S?= =?us-ascii?Q?B/fMFTgP2zt1ZmkuhudO6L4Pnw1JZpOSyg1a1zD6msn3jmY8FwkgiMdBBnA6?= =?us-ascii?Q?XdLBDfmWcw1YJ0V9n7HaKb7cVpb1tyO9FQzRgIvOzhuftM362KH8vWjQrvic?= =?us-ascii?Q?Hah412//8eW6t1V8fbyxInOzcyNHDLZIo9CMYNJgTj9oMPzpzvSJi/eoZqKk?= =?us-ascii?Q?Y07kEdkR8SGeYuoVy/S4Q08mR+uxtcOYf0GCP7v0fyEf7wGasGi3HjWYXbz7?= =?us-ascii?Q?46nM8UnvlYDhS3lPYSm4BWZE8VSF+6Vb6yMH9OmVngPBdf/Bgx7AbUuyQ2rK?= =?us-ascii?Q?GNpedgIvSxdZcZG16slqvUL1hMiJhtrdcHf2Hbeg+XaFk35F1ED/KySFpJPm?= =?us-ascii?Q?8uNFOICfbIhhxvEkMxUO6a8uw86Ei5RJyejEUuNW7A1X5pKuAZYUY3UI4qmT?= =?us-ascii?Q?Vp6hdXn0Ce2KZzgdTKyggYjsx4s5L3KVet+/yrH/O/BBg5B1IeRXK3mb74ig?= =?us-ascii?Q?wpHSsnf01FjZ6QWS5p/k4bsudK8hsFhlOznuwSjd14VDyx7tKhhUynkZpIlL?= =?us-ascii?Q?QRWV7j/VjRwipFypMLC+cPDI/YS0yyggPl7wKWed8mtAE11OTaV70BH0ePZf?= =?us-ascii?Q?vlGFwYD/XQobt8S/4lGNAwtFvLyEIEpRo2dD9ujhgBdTP2PW6eDBO2x3D5LU?= =?us-ascii?Q?7kznYUtJLTYiNd9JtBs2iIs4d/pTqsXXxiLnE3OfyaNj9lo9+6VnTZ4oMwZk?= =?us-ascii?Q?KflRf+oMlqopHThgGXpUeAY5yVHd2uCtJe4NLR1tE3rZj423uNUbw2YcAWkI?= =?us-ascii?Q?ijY1jduPoY3gfYjYM9Vz9MwlV+1eqfy1i9Q8dYvg8ojaKJAxZHYqpChva+Rh?= =?us-ascii?Q?gDGG/oJmbdRaqRTVPUGIGLfFfriP1r9SRGUk6QNIbdtIexh1kaARhjaMciOS?= =?us-ascii?Q?TcQ4W1nxygW1UX/N20ORHG/GtazdF5E51MRllLezhSs4mwHdFvP76DFzZ5xg?= =?us-ascii?Q?InHmzHPmudJEHsPJCgfGOhcKn4mH24gb0L07tzG4WomTrDB1IU3UUtBhobhX?= =?us-ascii?Q?KoSuzfWdMR7JQaM4ToIwB7ZSXxn4Romw7fPb59ddqLClAOrmjwUn8C0h+2JP?= =?us-ascii?Q?yWSojvuCAA=3D=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM6PR11MB4025.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: d2f9effb-ee9d-443c-b005-08da4d0305aa X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Jun 2022 06:07:40.1034 (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: 1Wpjci24KUL3xu1OqXrwuDAELL9qmIlo8BczUAHwg7NQtmS7lZO6kgs7s00pNBdFqD0f7jlDuJrfVZ2/JiRpjA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR11MB1903 Return-Path: hao.a.wu@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Please refer to inline comment below (tagged as "[Hao]"): > -----Original Message----- > From: devel@edk2.groups.io On Behalf Of Judah Vang > Sent: Thursday, June 9, 2022 2:03 PM > To: devel@edk2.groups.io > Cc: Wang, Jian J ; Gao, Liming > ; Mistry, Nishant C > Subject: [edk2-devel] [PATCH v3 06/28] MdeModulePkg: Add new include file= s >=20 > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2594 >=20 > Add EncryptionVariableLib.h for providing encryption and > decryption services for protected variables. > Add ProtectedVariableLib.h for providing integrity or > variables. >=20 > Cc: Jian J Wang > Cc: Liming Gao > Cc: Nishant C Mistry > Signed-off-by: Jian J Wang > Signed-off-by: Nishant C Mistry > Signed-off-by: Judah Vang > --- > MdeModulePkg/Include/Library/EncryptionVariableLib.h | 165 +++++ > MdeModulePkg/Include/Library/ProtectedVariableLib.h | 700 > ++++++++++++++++++++ > 2 files changed, 865 insertions(+) >=20 > diff --git a/MdeModulePkg/Include/Library/EncryptionVariableLib.h > b/MdeModulePkg/Include/Library/EncryptionVariableLib.h > new file mode 100644 > index 000000000000..c7740e659dcf > --- /dev/null > +++ b/MdeModulePkg/Include/Library/EncryptionVariableLib.h > @@ -0,0 +1,165 @@ > +/** @file > + Provides services to encrypt/decrypt variables. > + > +Copyright (c) 2022, Intel Corporation. All rights reserved.
> +SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > +#ifndef ENCRYPTION_VARIABLE_LIB_H_ > +#define ENCRYPTION_VARIABLE_LIB_H_ > + > +#include > + > +#include > + > +#include > + > +#define ENC_TYPE_NULL 0 > +#define ENC_TYPE_AES TPM_ALG_AES > + > +typedef struct _VARIABLE_ENCRYPTION_FLAGS { > + BOOLEAN Auth; // Variable is authenticated or not > + BOOLEAN DecryptInPlace; // Do decryption in place > + BOOLEAN Protected; // Variable is protected or not > +} VARIABLE_ENCRYPTION_FLAGS; > + > +typedef struct _VARIABLE_ENCRYPTION_INFO { > + AUTH_VARIABLE_INFO Header; // Authenticated varab= ile header > + VARIABLE_HEADER *Buffer; // Pointer to variable= buffer > + UINT64 StoreIndex; // Variable store inde= x > + VOID *PlainData; // Pointer to plain da= ta > + UINT32 PlainDataSize; // Size of plain data > + VOID *CipherData; // Pointer to cipher d= ata > + UINT32 CipherDataSize; // Size of cipher data > + UINT32 CipherHeaderSize; // Size of cipher head= er > + UINT32 CipherDataType; // Type of cipher data > + VOID *Key; // Pointer to encrypt/= decrypt key > + UINT32 KeySize; // Size of key > + VARIABLE_ENCRYPTION_FLAGS Flags; // Encryption flags > +} VARIABLE_ENCRYPTION_INFO; > + > +/** > + Encrypt variable data. > + > + @param[in, out] VarInfo Pointer to structure containing detailed > information about a variable. > + > + @retval EFI_SUCCESS Function successfully executed. > + @retval EFI_INVALID_PARAMETER If ProtectedVarLibContextIn =3D=3D N= ULL or > ProtectedVarLibContextOut =3D=3D NULL. > + @retval EFI_OUT_OF_RESOURCES Fail to allocate enough resource. > + @retval EFI_UNSUPPORTED Unsupported to process authenticated > variable. > + > +**/ > +EFI_STATUS > +EFIAPI > +EncryptVariable ( > + IN OUT VARIABLE_ENCRYPTION_INFO *VarInfo > + ); > + > +/** > + Decrypt variable data. > + > + If VarEncInfo->CipherData is not NULL, it must holds the cipher data t= o be > + decrypted. Otherwise, assume the cipher data from variable data buffer= , i.e. > + VarEncInfo->Header.Data. > + > + If VarEncInfo->Flags.DecryptInPlace is TRUE, the decrypted data will b= e put > + back in the same buffer as cipher buffer got above, after encryption h= eader, > + which helps to identify later if the data in buffer is decrypted or no= t. This > + can avoid repeat decryption when accessing the same variable more than > once. > + > + If VarEncInfo->Flags.DecryptInPlace is FALSE, VarEncInfo->PlainData mu= st be > + passed in with a valid buffer with VarEncInfo->PlainDataSize set corre= ctly > + with its size. > + > + Note the VarEncInfo->PlainData is always pointing to the buffer addres= s with > + decrypted data without encryption header, and VarEncInfo->PlainDataSiz= e is > + always the size of original variable data, if this function returned > + successfully. > + > + @param[in, out] VarInfo Pointer to structure containing detailed > + information about a variable. > + > + @retval EFI_SUCCESS Variable was decrypted successfully. > + @retval EFI_INVALID_PARAMETER Variable information in VarEncInfo is > invalid. > + @retval EFI_BUFFER_TOO_SMALL VarEncInfo->PlainData is not NULL but > + VarEncInfo->PlainDataSize is too small= . > + @retval EFI_ABORTED Uknown error occurred during decryptin= g. > + @retval EFI_OUT_OF_RESOURCES Fail to allocate enough resource. > + @retval EFI_COMPROMISED_DATA The cipher header is not valid. > + @retval EFI_UNSUPPORTED Unsupported to encrypt variable. > + > +**/ > +EFI_STATUS > +EFIAPI > +DecryptVariable ( > + IN OUT VARIABLE_ENCRYPTION_INFO *VarInfo > + ); > + > +/** > + Get cipher information about a variable, including plaindata size, > + cipher algorithm type, etc. > + > + For data passed in with VarEncInfo, > + > + VarEncInfo->Header.Data > + - The variable data in normal variable structure. > + VarEncInfo->Header.DataSize > + - The size of variable data. > + > + For data passed out with VarEncInfo (valid only if EFI_SUCCESS is retu= rned), > + > + VarEncInfo->CipherDataType > + - ENC_TYPE_NULL, if the variable is not encrypted or has been decr= ypted; > + - ENC_TYPE_AES, if the variable is encrypted. > + VarEncInfo->CipherHeaderSize > + - Size of cipher header put before encrypted or decrypted data. > + VarEncInfo->PlainData > + - NULL, if the variable is encrypted; Or > + - pointer to original variable data, if the variable has been decr= ypted. > + VarEncInfo->PlainDataSize > + - The size of original variable data > + VarEncInfo->CipherData > + - NULL, if the variable is decrypted; Or > + - pointer to start of encrypted variable data, including encryptio= n header; > + VarEncInfo->CipherDataSize > + - The size of encrypted variable data, including encryption header= . > + > + @param[in, out] VarInfo Pointer to structure containing detailed > + information about a variable. > + > + @retval EFI_SUCCESS The information was retrieved successf= ully. > + @retval EFI_INVALID_PARAMETER Variable information in VarEncInfo is > invalid. > + @retval EFI_NOT_FOUND No cipher information recognized. > + @retval EFI_UNSUPPORTED Unsupported interface. > + > +**/ > +EFI_STATUS > +EFIAPI > +GetCipherDataInfo ( > + IN OUT VARIABLE_ENCRYPTION_INFO *VarInfo > + ); > + > +/** > + Force set cipher information for a variable, like plaindata size, > + cipher algorithm type, cipher data etc. > + > + The destination buffer must be passed via VarEncInfo->Header.Data. > + > + This method is only used to update and/or change plain data informatio= n. > + > + @param[in, out] VarInfo Pointer to structure containing detailed > + information about a variable. > + > + @retval EFI_SUCCESS The information was updated successful= ly. > + @retval EFI_INVALID_PARAMETER Variable information in VarEncInfo is > invalid. > + @retval EFI_UNSUPPORTED If this method is not supported. > + > +**/ > +EFI_STATUS > +EFIAPI > +SetCipherDataInfo ( > + IN OUT VARIABLE_ENCRYPTION_INFO *VarInfo > + ); > + > +#endif //_ENCRYPTION_VARIABLE_LIB_H_ > diff --git a/MdeModulePkg/Include/Library/ProtectedVariableLib.h > b/MdeModulePkg/Include/Library/ProtectedVariableLib.h > new file mode 100644 > index 000000000000..2f57b4ebbc70 > --- /dev/null > +++ b/MdeModulePkg/Include/Library/ProtectedVariableLib.h > @@ -0,0 +1,700 @@ > +/** @file > + Defines interfaces of protected variable services for non-volatile var= iable > + storage. > + > +Copyright (c) 2020 - 2022, Intel Corporation. All rights reserved.
> +SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > +#ifndef PROTECTED_VARIABLE_LIB_H_ > +#define PROTECTED_VARIABLE_LIB_H_ > + > +#include > +#include > + > +#include > + > +#include > +#include > + > +#include > +#include > + > +#pragma pack(1) > + > +typedef struct _VARIABLE_DIGEST_FLAGS { > + BOOLEAN Auth; // Authenticated variable f= ormat > + BOOLEAN Valid; // Valid variable data in c= urrent variable > + BOOLEAN Protected; // Protected variable (used= in calculating > HMAC) > + BOOLEAN Encrypted; // Encrypted variable > + BOOLEAN Freeable; // Memory reserved for curr= ent node can > be freed > + BOOLEAN CacheIndexAhead; // Indicates if CacheIndex = is Ahead > relative to Global structure > + BOOLEAN Reserved[2]; // Reserved fields > +} VARIABLE_DIGEST_FLAGS; > + > +typedef struct _VARIABLE_DIGEST { > + /// > + /// Pointer to digest of next variable in a pre-defined rule of order = for > + /// integration verification. In other words, the final HMAC of all > + /// protected variables is calculated by concatenating digest of each > + /// variable in the order of this singly linked list. > + /// > + EFI_PHYSICAL_ADDRESS Prev; > + EFI_PHYSICAL_ADDRESS Next; > + /// > + /// Index to variable in physical store, used to locate the variable d= irectly > + /// inside the store (Implementation dependent). > + /// > + EFI_PHYSICAL_ADDRESS StoreIndex; > + /// > + /// Index to variable in memory cache, used to locate the variable dir= ectly > + /// inside the cache (Implementation dependent). > + /// > + EFI_PHYSICAL_ADDRESS CacheIndex; > + > + /// > + /// Pointer to Cache offset within Global Structure > + /// > + UINT32 CacheOffset; > + > + /// > + /// Frequently accessed information relating to the variable. > + /// > + UINT16 DigestSize; // Size of digest value > + UINT16 NameSize; // Size of variable name > + UINT32 DataSize; // Size of variable data > + UINT32 PlainDataSize; // Size of plain data of curre= nt variable (if > encrypted) > + UINT32 State; // State of current variable > + UINT32 Attributes; // Attributes of current varia= ble > + > + EFI_GUID VendorGuid; // GUID > + VARIABLE_DIGEST_FLAGS Flags; // Variable digest flags > + // > + // Data with variable length are put at the end of this structure. > + // > + // CHAR16 VariableName[NameSize/2]; > + // UINT8 DigestValue[DigestSize]; > +} VARIABLE_DIGEST; > + > +#pragma pack() > + > +#define VAR_DIG_NAMEOFF(VarDig) (sizeof (VARIABLE_DIGEST)) > +#define VAR_DIG_DIGOFF(VarDig) (VAR_DIG_NAMEOFF (VarDig) + (VarDig)- > >NameSize) > + > +#define VAR_DIG_END(VarDig) (VAR_DIG_DIGOFF (VarDig) + (VarDig)- > >DigestSize) > + > +#define VAR_DIG_VALUE(VarDig) (VOID *)((UINTN)(VarDig) + > VAR_DIG_DIGOFF (VarDig)) > +#define VAR_DIG_NAME(VarDig) (CHAR16 *)((UINTN)(VarDig) + > VAR_DIG_NAMEOFF (VarDig)) > +#define VAR_DIG_GUID(VarDig) &(VAR_DIG_PTR (VarDig)->VendorGuid) > + > +#define VAR_DIG_PTR(Addr) ((VARIABLE_DIGEST *)(UINTN)(Addr)) > +#define VAR_DIG_ADR(Ptr) ((EFI_PHYSICAL_ADDRESS)(UINTN)(Ptr)) > +#define VAR_DIG_NEXT(VarDig) (VAR_DIG_PTR ((VarDig)->Next)) > +#define VAR_DIG_PREV(VarDig) (VAR_DIG_PTR ((VarDig)->Prev)) > + > +#define VAR_INDEX_INVALID ((UINT64)(-1)) > + > +#define VAR_HDR_PTR(Addr) ((VARIABLE_HEADER *)(UINTN)(Addr)) > + > +typedef VARIABLE_ENCRYPTION_INFO PROTECTED_VARIABLE_INFO; > + > +/** > + > + This function writes data to the NV variable storage at given position= . > + > + Note: Per current variable service architecture, only SMM is allowed t= o > + (directly) change NV variable storage. > + > + @param VariableInfo Pointer to structure holding details o= f a variable. > + @param Offset Offset to the given variable to write = from. > + @param Size Size of data to be written. > + @param Buffer Pointer to the buffer from which data = is written. > + > + @retval EFI_INVALID_PARAMETER Invalid parameters passed in. > + @retval EFI_UNSUPPORTED Updating NV variable storage is not > supported. > + @retval EFI_OUT_OF_RESOURCES Not enough resource to complete the > operation. > + @retval EFI_SUCCESS Variable store successfully updated. > + > +**/ > +typedef > +EFI_STATUS > +(EFIAPI *PROTECTED_VAR_LIB_UPDATE_VARIABLE_STORE)( > + IN PROTECTED_VARIABLE_INFO *VariableInfo, > + IN UINTN Offset, > + IN UINT32 Size, > + IN UINT8 *Buffer > + ); > + > +/** > + Update the variable region with Variable information. > + > + @param[in] AuthVariableInfo Pointer AUTH_VARIABLE_INFO structure= for > + input of the variable. > + > + @retval EFI_SUCCESS The update operation is success. > + @retval EFI_INVALID_PARAMETER Invalid parameter. > + @retval EFI_WRITE_PROTECTED Variable is write-protected. > + @retval EFI_OUT_OF_RESOURCES There is not enough resource. > + > +**/ > +typedef > +EFI_STATUS > +(EFIAPI *PROTECTED_VAR_LIB_UPDATE_VARIABLE)( > + IN AUTH_VARIABLE_INFO *AuthVariableInfo > + ); > + > +/** > + > + Retrieve details about a variable and return them in VariableInfo->Hea= der. > + > + If VariableInfo->Address is given, this function will calculate its of= fset > + relative to given variable storage via VariableStore; Otherwise, it wi= ll try > + other internal variable storages or cached copies. It's assumed that, = for all > + copies of NV variable storage, all variables are stored in the same re= lative > + position. If VariableInfo->Address is found in the range of any storag= e copies, > + its offset relative to that storage should be the same in other copies= . > + > + If VariableInfo->Offset is given (non-zero) but not VariableInfo->Addr= ess, > + this function will return the variable memory address inside VariableS= tore, > + if given, via VariableInfo->Address; Otherwise, the address of other s= torage > + copies will be returned, if any. > + > + For a new variable whose offset has not been determined, a value of -1= as > + VariableInfo->Offset should be passed to skip the offset calculation. > + > + @param VariableInfo Pointer to variable information. > + > + @retval EFI_INVALID_PARAMETER VariableInfo is NULL or both VariableIn= fo- > >Address > + and VariableInfo->Offset are NULL (0). > + @retval EFI_NOT_FOUND If given Address or Offset is out of ra= nge of > + any given or internal storage copies. > + @retval EFI_SUCCESS Variable details are retrieved successf= ully. [Hao]: For the above description: "VariableInfo->Index" -> "VariableInfo->StoreIndex" Best Regards, Hao Wu > + > +**/ > +typedef > +EFI_STATUS > +(EFIAPI *PROTECTED_VAR_LIB_GET_VAR_INFO)( > + IN OUT PROTECTED_VARIABLE_INFO *VariableInfo > + ); > + > +/** > + > + Retrieve details of the variable next to given variable within Variabl= eStore. > + > + If VarInfo->Address is NULL, the first one in VariableStore is returne= d. > + > + VariableStart and/or VariableEnd can be given optionally for the situa= tion > + in which the valid storage space is smaller than the VariableStore->Si= ze. > + This usually happens when PEI variable services make a compact variabl= e > + cache to save memory, which cannot make use VariableStore->Size to > determine > + the correct variable storage range. > + > + @param VariableStore Pointer to a variable storage. It's op= tional. > + @param VariableStart Start point of valid range in Variable= Store. > + @param VariableEnd End point of valid range in VariableSt= ore. > + @param VariableInfo Pointer to variable information. > + > + @retval EFI_INVALID_PARAMETER VariableInfo or VariableStore is NULL. > + @retval EFI_NOT_FOUND If the end of VariableStore is reached. > + @retval EFI_SUCCESS The next variable is retrieved successf= ully. > + > +**/ > +typedef > +EFI_STATUS > +(EFIAPI *PROTECTED_VAR_LIB_GET_NEXT_VAR_INFO)( > + IN OUT PROTECTED_VARIABLE_INFO *VariableInfo > + ); > + > +typedef > +EFI_STATUS > +(EFIAPI *DIGEST_METHOD_CALLBACK)( > + IN VARIABLE_HEADER *Variable, > + IN OUT VARIABLE_DIGEST *Digest > + ); > + > +/** > + > + Initialize a memory copy of NV variable storage. > + > + To save memory consumption (especially in PEI phase), it's allowed to = cache > + only valid variables. In such case, an index table recording offset of= each > + valid variables could be employed. The index table makes sure the cach= ed > copy > + to be synchronized with the original copy in NV variable storage. To a= void > + TOCTOU issue, once the variables are cached in memory and verified, NV > + variable storage should not be used to read variable information. The = cached > + copy should be used instead. > + > + If StoreCacheBase is not given, this function should return the requir= ed > + cache size and valid variable number, if VariableNumber is not NULL. T= hen > + the caller can prepare correct cache buffer and index table buffer bef= ore > + next calling. > + > + @param[in] CacheBase Base address of NV variable storage ca= che. > + @param[in] CacheSize Size of CacheBuffer. > + @param[out] CacheSize Size of required cache buffer. > + @param[out] DigBuffer Base address of digest of each variabl= e. > + @param[in, out] DigBufferSize Digest size of one variable if DigestB= uffer is > NULL. > + Size of DigestBuffer if DigestBuffer i= s NOT NULL. > + @param[out] DigSize Required size of DigestBuffer if Diges= tBuffer is > NULL. > + @param[out] DigMethod Method used to generate digest for eac= h > variable. > + @param[out] VarNumber Number of valid variables. > + @param[out] AuthFlag Auth-variable indicator. > + > + @retval EFI_INVALID_PARAMETER CacheSize is NULL; Or, > + StoreCacheBase is 0 but *CacheSize it = not. > + @retval EFI_VOLUME_CORRUPTED If original NV variable storage is > corrupted. > + @retval EFI_BUFFER_TOO_SMALL If *CacheSize is smaller than required > memory. > + @retval EFI_SUCCESS The cached variable storage is initial= ized. > + > +**/ > +typedef > +EFI_STATUS > +(EFIAPI *PROTECTED_VAR_LIB_INIT_VAR_STORE)( > + OUT VOID *CacheBase OPTIONAL, > + IN OUT UINT32 *CacheSize OPTIONAL, > + OUT VOID *DigBuffer OPTIONAL, > + IN OUT UINT32 *DigBufferSize OPTIONAL, > + IN UINT32 DigSize OPTIONAL, > + IN DIGEST_METHOD_CALLBACK DigMethod OPTIONAL, > + OUT UINT32 *VarNumber OPTIONAL, > + OUT BOOLEAN *AuthFlag OPTIONAL > + ); > + > +/** > + > + Initiate a variable retrieval in SMM environment from non-SMM environm= ent. > + > + This is usually required in BS/RT environment when local cached copy i= s in > + encrypted form. Variable decryption can only be done in SMM environmen= t. > + > + @param[in] VariableName Name of Variable to be found. > + @param[in] VendorGuid Variable vendor GUID. > + @param[out] Attributes Attribute value of the variable fou= nd. > + @param[in, out] DataSize Size of Data found. If size is less= than the > + data, this value contains the requi= red size. > + @param[out] Data Data pointer. > + > + @retval EFI_SUCCESS Found the specified variable. > + @retval EFI_INVALID_PARAMETER Invalid parameter. > + @retval EFI_NOT_FOUND The specified variable could not be= found. > + > +**/ > +typedef > +EFI_STATUS > +(EFIAPI *PROTECTED_VAR_LIB_FIND_VAR_SMM)( > + IN CHAR16 *VariableName, > + IN EFI_GUID *VendorGuid, > + OUT UINT32 *Attributes OPTIONAL, > + IN OUT UINTN *DataSize, > + OUT VOID *Data OPTIONAL > + ); > + > +/** > + Check if a variable is user variable or not. > + > + @param[in] Variable Pointer to variable header. > + > + @retval TRUE User variable. > + @retval FALSE System variable. > + > +**/ > +typedef > +BOOLEAN > +(EFIAPI *PROTECTED_VAR_LIB_IS_USER_VAR)( > + IN VARIABLE_HEADER *Variable > + ); > + > +/** > + Check if a HOB variable store is available or not. > + > + @retval EFI_NOT_READY HOB variable store info not available. > + @retval EFI_NOT_FOUND HOB variable store is NOT available. > + @retval EFI_SUCCESS HOB variable store is available. > +**/ > +typedef > +EFI_STATUS > +(EFIAPI *PROTECTED_VAR_LIB_HOB_STORE_AVAILABLE)( > + VOID > + ); > + > +typedef enum { > + FromPeiModule, > + FromBootServiceModule, > + FromRuntimeModule, > + FromSmmModule > +} VARIABLE_SERVICE_USER; > + > +#pragma pack(1) > + > +#define PROTECTED_VARIABLE_CONTEXT_IN_STRUCT_VERSION 0x02 > + > +typedef struct _PROTECTED_VARIABLE_CONTEXT_IN { > + UINT32 StructVersion; > + UINT32 StructSize; > + UINT32 MaxVariableSize; > + > + VARIABLE_SERVICE_USER VariableServiceUser; > + > + PROTECTED_VAR_LIB_FIND_VAR_SMM FindVariableSmm; > + PROTECTED_VAR_LIB_GET_VAR_INFO GetVariableInfo; > + PROTECTED_VAR_LIB_GET_NEXT_VAR_INFO GetNextVariableInfo; > + PROTECTED_VAR_LIB_UPDATE_VARIABLE_STORE UpdateVariableStore; > + PROTECTED_VAR_LIB_UPDATE_VARIABLE UpdateVariable; > + PROTECTED_VAR_LIB_HOB_STORE_AVAILABLE > IsHobVariableStoreAvailable; > +} PROTECTED_VARIABLE_CONTEXT_IN; > + > +#pragma pack() > + > +/** > + > + Initialization for protected variable services. > + > + If this initialization failed upon any error, the whole variable servi= ces > + should not be used. A system reset might be needed to re-construct NV > + variable storage to be the default state. > + > + @param[in] ContextIn Pointer to variable service context needed by > + protected variable. > + > + @retval EFI_SUCCESS Protected variable services are read= y. > + @retval EFI_INVALID_PARAMETER If ContextIn =3D=3D NULL or somethin= g > missing or > + mismatching in the content in Contex= tIn. > + @retval EFI_COMPROMISED_DATA If failed to check integrity of prot= ected > variables. > + @retval EFI_OUT_OF_RESOURCES Fail to allocate enough resource. > + @retval EFI_UNSUPPORTED Unsupported to process protected var= iable. > + > +**/ > +EFI_STATUS > +EFIAPI > +ProtectedVariableLibInitialize ( > + IN PROTECTED_VARIABLE_CONTEXT_IN *ContextIn > + ); > + > +/** > + > + An alternative version of ProtectedVariableLibGetData to get plain dat= a, if > + encrypted, from given variable, for different use cases. > + > + @param[in,out] VarInfo Pointer to structure containing variab= le > information. > + > + @retval EFI_SUCCESS Found the specified variable. > + @retval EFI_INVALID_PARAMETER VarInfo is NULL or both VarInfo- > >Address and > + VarInfo->Offset are invalid. > + @retval EFI_NOT_FOUND The specified variable could not be = found. > + > +**/ > +EFI_STATUS > +EFIAPI > +ProtectedVariableLibGetByInfo ( > + IN OUT PROTECTED_VARIABLE_INFO *VarInfo > + ); > + > +/** > + This service retrieves a variable's value using its name and GUID. > + > + Read the specified variable from the UEFI variable store. If the Data > + buffer is too small to hold the contents of the variable, the error > + EFI_BUFFER_TOO_SMALL is returned and DataSize is set to the required b= uffer > + size to obtain the data. > + > + @param VariableName A pointer to a null-terminated string th= at is the > variable's name. > + @param VariableGuid A pointer to an EFI_GUID that is the var= iable's > GUID. The combination of > + VariableGuid and VariableName must be un= ique. > + @param Attributes If non-NULL, on return, points to the va= riable's > attributes. > + @param DataSize On entry, points to the size in bytes of= the Data > buffer. > + On return, points to the size of the dat= a returned in Data. > + @param Data Points to the buffer which will hold the= returned > variable value. > + May be NULL with a zero DataSize in orde= r to determine the > size of the buffer needed. > + > + @retval EFI_SUCCESS The variable was read successfully. > + @retval EFI_NOT_FOUND The variable was be found. > + @retval EFI_BUFFER_TOO_SMALL The DataSize is too small for the result= ing > data. > + DataSize is updated with the size requir= ed for > + the specified variable. > + @retval EFI_INVALID_PARAMETER VariableName, VariableGuid, DataSize or > Data is NULL. > + @retval EFI_DEVICE_ERROR The variable could not be retrieved beca= use of > a device error. > + > +**/ > +EFI_STATUS > +EFIAPI > +ProtectedVariableLibGetByName ( > + IN CONST CHAR16 *VariableName, > + IN CONST EFI_GUID *VariableGuid, > + OUT UINT32 *Attributes, > + IN OUT UINTN *DataSize, > + OUT VOID *Data OPTIONAL > + ); > + > +/** > + > + Retrieve plain data, if encrypted, of given variable. > + > + If variable encryption is employed, this function will initiate a SMM = request > + to get the plain data. Due to security consideration, the decryption c= an only > + be done in SMM environment. > + > + @param[in] Variable Pointer to header of a Variable. > + @param[out] Data Pointer to plain data of the given = variable. > + @param[in, out] DataSize Size of data returned or data buffe= r needed. > + @param[in] AuthFlag Auth-variable indicator. > + > + @retval EFI_SUCCESS Found the specified variable. > + @retval EFI_INVALID_PARAMETER Invalid parameter. > + @retval EFI_NOT_FOUND The specified variable could not be= found. > + @retval EFI_BUFFER_TOO_SMALL If *DataSize is smaller than needed= . > + > +**/ > +EFI_STATUS > +EFIAPI > +ProtectedVariableLibGetByBuffer ( > + IN VARIABLE_HEADER *Variable, > + IN OUT VOID *Data, > + IN OUT UINT32 *DataSize, > + IN BOOLEAN AuthFlag > + ); > + > +/** > + > + Prepare for variable update. > + > + This is needed only once during current boot to mitigate replay attack= . Its > + major job is to advance RPMC (Replay Protected Monotonic Counter). > + > + @retval EFI_SUCCESS Variable is ready to update hereafter. > + @retval EFI_UNSUPPORTED Updating variable is not supported. > + @retval EFI_DEVICE_ERROR Error in advancing RPMC. > + > +**/ > +EFI_STATUS > +EFIAPI > +ProtectedVariableLibWriteInit ( > + VOID > + ); > + > +/** > + > + Update a variable with protection provided by this library. > + > + If variable encryption is employed, the new variable data will be encr= ypted > + before being written to NV variable storage. > + > + A special variable, called "MetaDataHmacVar", will always be updated a= long > + with variable being updated to reflect the changes (HMAC value) of all > + protected valid variables. The only exceptions, currently, are variabl= e > + "MetaDataHmacVar" itself and variable "VarErrorLog". > + > + The buffer passed by NewVariable must be double of maximum variable si= ze, > + which allows to pass the "MetaDataHmacVar" back to caller along with > encrypted > + new variable data, if any. This can make sure the new variable data an= d > + "MetaDataHmacVar" can be written at almost the same time to reduce the > chance > + of compromising the integrity. > + > + If *NewVariableSize is zero, it means to delete variable passed by Cur= rVariable > + and/or CurrVariableInDel. "MetaDataHmacVar" will be updated as well in= such > + case because of less variables in storage. NewVariable should be alway= s > passed > + in to convey new "MetaDataHmacVar" back. > + > + @param[in,out] CurrVariable Variable to be updated. It's NULL = if > + adding a new variable. > + @param[in,out] CurrVariableInDel In-delete-transition copy of updat= ing > variable. > + @param[in] NewVariable Buffer of new variable data. > + @param[out] NewVariable Buffer of "MetaDataHmacVar" and ne= w > + variable (encrypted). > + @param[in] NewVariableSize Size of NewVariable. > + @param[out] NewVariableSize Size of (encrypted) NewVariable an= d > + "MetaDataHmacVar". > + > + @retval EFI_SUCCESS The variable is updated with protectio= n > successfully. > + @retval EFI_INVALID_PARAMETER NewVariable is NULL. > + @retval EFI_NOT_FOUND Information missing to finish the oper= ation. > + @retval EFI_ABORTED Failed to encrypt variable or calculat= e HMAC. > + @retval EFI_NOT_READY The RPMC device is not yet initialized= . > + @retval EFI_DEVICE_ERROR The RPMC device has error in updating. > + @retval EFI_ACCESS_DENIED The given variable is not allowed to u= pdate. > + Currently this only happens on updatin= g > + "MetaDataHmacVar" from code outside of= this > + library. > + > +**/ > +EFI_STATUS > +EFIAPI > +ProtectedVariableLibUpdate ( > + IN OUT VARIABLE_HEADER *CurrVariable OPTIONAL, > + IN OUT VARIABLE_HEADER *CurrVariableInDel OPTIONAL, > + IN OUT VARIABLE_HEADER *NewVariable, > + IN OUT UINTN *NewVariableSize > + ); > + > +/** > + > + Finalize a variable updating after it's written to NV variable storage > + successfully. > + > + This usually includes works like increasing RPMC, synchronizing local = cache, > + updating new position of "MetaDataHmacVar", deleting old copy of > "MetaDataHmacVar" > + completely, etc. > + > + @param[in] NewVariable Buffer of new variables and > MetaDataHmacVar. > + @param[in] VariableSize Size of buffer pointed by NewVariabl= e. > + @param[in] Offset Offset to NV variable storage from w= here the > new > + variable and MetaDataHmacVar have be= en written. > + > + @retval EFI_SUCCESS No problem in winding up the variable writ= e > operation. > + @retval Others Failed to updating state of old copy of up= dated > + variable, or failed to increase RPMC, etc. > + > +**/ > +EFI_STATUS > +EFIAPI > +ProtectedVariableLibWriteFinal ( > + IN VARIABLE_HEADER *NewVariable, > + IN UINTN VariableSize, > + IN UINT64 StoreIndex > + ); > + > +/** > + Return the request variable name and GUID as per StoreIndex. > + > + This function is called multiple times to retrieve the VariableName > + and VariableGuid of all variables currently available in the system. > + On each call, the previous results are passed into the interface, > + and, on return, the interface returns the data for the next > + interface. When the entire variable list has been returned, > + EFI_NOT_FOUND is returned. > + > + @param This A pointer to this instance of the > EFI_PEI_READ_ONLY_VARIABLE2_PPI. > + > + @param VariableNameSize On entry, points to the size of the buffer p= ointed > to by VariableName. > + On return, the size of the variable name buf= fer. > + @param VariableName On entry, a pointer to a null-terminated str= ing that > is the variable's name. > + On return, points to the next variable's nul= l-terminated name > string. > + @param VariableGuid On entry, a pointer to an EFI_GUID that is t= he > variable's GUID. > + On return, a pointer to the next variable's = GUID. > + > + @retval EFI_SUCCESS The variable was read successfully. > + @retval EFI_NOT_FOUND The variable could not be found. > + @retval EFI_BUFFER_TOO_SMALL The VariableNameSize is too small for th= e > resulting > + data. VariableNameSize is updated with t= he size > + required for the specified variable. > + @retval EFI_INVALID_PARAMETER VariableName, VariableGuid or > + VariableNameSize is NULL. > + @retval EFI_DEVICE_ERROR The variable could not be retrieved beca= use of > a device error. > + > +**/ > +EFI_STATUS > +EFIAPI > +ProtectedVariableLibFind ( > + IN OUT PROTECTED_VARIABLE_INFO *VarInfo > + ); > + > +/** > + Return the next variable name and GUID. > + > + This function is called multiple times to retrieve the VariableName > + and VariableGuid of all variables currently available in the system. > + On each call, the previous results are passed into the interface, > + and, on return, the interface returns the data for the next > + interface. When the entire variable list has been returned, > + EFI_NOT_FOUND is returned. > + > + @param VariableNameSize On entry, points to the size of the buffer p= ointed > to by VariableName. > + On return, the size of the variable name buf= fer. > + @param VariableName On entry, a pointer to a null-terminated str= ing that > is the variable's name. > + On return, points to the next variable's nul= l-terminated name > string. > + @param VariableGuid On entry, a pointer to an EFI_GUID that is t= he > variable's GUID. > + On return, a pointer to the next variable's = GUID. > + > + @retval EFI_SUCCESS The variable was read successfully. > + @retval EFI_NOT_FOUND The variable could not be found. > + @retval EFI_BUFFER_TOO_SMALL The VariableNameSize is too small for th= e > resulting > + data. VariableNameSize is updated with t= he size > + required for the specified variable. > + @retval EFI_INVALID_PARAMETER VariableName, VariableGuid or > + VariableNameSize is NULL. > + @retval EFI_DEVICE_ERROR The variable could not be retrieved beca= use of > a device error. > + > +**/ > +EFI_STATUS > +EFIAPI > +ProtectedVariableLibFindNext ( > + IN OUT UINTN *VariableNameSize, > + IN OUT CHAR16 *VariableName, > + IN OUT EFI_GUID *VariableGuid > + ); > + > +/** > + Find variable via information in data structure PROTECTED_VARIABLE_INF= O. > + > + If VarInfo->StoreIndex is given and valid, always used it to search v= ariable > + in store. Otherwise, search the variable via variable name and guid p= ointed > + by VarInfo->Header.VariableName and VarInfo->Header.VendorGuid. > + > + @param VarInfo Pointer to data containing variable information. > + > + @return EFI_SUCCESS Found the variable. > + @return EFI_INVALID_PARAMETER No valid variable information is given. > + @return EFI_NOT_FOUND The given variable was not found or no m= ore > + variables available. > +**/ > +EFI_STATUS > +EFIAPI > +ProtectedVariableLibFindNextEx ( > + IN OUT PROTECTED_VARIABLE_INFO *VarInfo > + ); > + > +/** > + Refresh variable information changed by variable service. > + > + @param Variable Pointer to buffer of the updated variable. > + @param VariableSize Size of variable pointed by Variable. > + @param StoreIndex New index of the variable in store. > + @param RefreshData Flag to indicate if the variable has been upda= ted. > + > + @return EFI_SUCCESS No error occurred in updating. > + @return EFI_NOT_FOUND The given variable was not found in > + ProtectedVariableLib. > +**/ > +EFI_STATUS > +EFIAPI > +ProtectedVariableLibRefresh ( > + IN VARIABLE_HEADER *Variable, > + IN UINTN VariableSize, > + IN UINT64 StoreIndex, > + IN BOOLEAN RefreshData > + ); > + > +/** > + Refresh variable information changed by variable service. > + > + @param Buffer Pointer to a pointer of buffer. > + @param NumElements Pointer to number of elements in list. > + > + > + @return EFI_SUCCESS Successfully retrieved sorted list. > + @return others Unsuccessful. > + > +**/ > +EFI_STATUS > +EFIAPI > +ProtectedVariableLibGetSortedList ( > + IN OUT EFI_PHYSICAL_ADDRESS **Buffer, > + IN OUT UINTN *NumElements > + ); > + > +/** > + > + Determine if the variable is the HMAC variable > + > + @param VariableName Pointer to variable name. > + > + @return TRUE Variable is HMAC variable > + @return FALSE Variable is not HMAC variable > + > +**/ > +BOOLEAN > +ProtectedVariableLibIsHmac ( > + IN CHAR16 *VariableName > + ); > + > +#endif > -- > 2.35.1.windows.2 >=20 >=20 >=20 >=20 >=20