From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by mx.groups.io with SMTP id smtpd.web10.1041.1648250921590027422 for ; Fri, 25 Mar 2022 16:28:43 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=Kiy3fe7a; spf=pass (domain: intel.com, ip: 192.55.52.93, mailfrom: judah.vang@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1648250923; x=1679786923; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XElp9+mnvfKYEhJG+PBCD6Jla21zoVp4xvrGwcb2N5Y=; b=Kiy3fe7aFivoCdYQBryEBppAbHt6VPTqjizibxUYNCNYBCPLL8ARNcD6 iirX5TzYc4FDWhd+q37jZZY+wt+5z7csHHTLIFqaZ0Z5eF83F7p8WeRBd Zuxbi33ZhR3HLCo7DSuwC2kyESM7+HlFTEzVuTIc/bgRmg+cbrD7j+iVf +E2caSJ1xzYbN9+UtknfoLgsohuFGwUI74k/G6C2KYHt786xTfI+14N84 C618mv+wI1rVhvNZSB4mIA4eeJgbqwzjU/PK8KtRKxs12k+Z99CY7iYII So6hYuYWJ94JwQp5bAnGZTwMzChQEpNcq0bnHEeYcUPLy+Znv4uKaX89J g==; X-IronPort-AV: E=McAfee;i="6200,9189,10297"; a="256309524" X-IronPort-AV: E=Sophos;i="5.90,211,1643702400"; d="scan'208";a="256309524" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Mar 2022 16:28:42 -0700 X-IronPort-AV: E=Sophos;i="5.90,211,1643702400"; d="scan'208";a="638366574" Received: from jvang-mobl.amr.corp.intel.com ([10.212.95.18]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Mar 2022 16:28:42 -0700 From: "Judah Vang" To: devel@edk2.groups.io Cc: Judah Vang , Jian J Wang , Jiewen Yao , Nishant C Mistry Subject: [PATCH v1 15/28] SecurityPkg: Add VariableKey library function Date: Fri, 25 Mar 2022 16:28:12 -0700 Message-Id: <20220325232825.2167-11-judah.vang@intel.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20220325232825.2167-1-judah.vang@intel.com> References: <20220325232825.2167-1-judah.vang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2594 Provide VariableKey function that retrieves the key for integrity and/or confidentiality of variables Cc: Jian J Wang Cc: Jiewen Yao Cc: Nishant C Mistry Signed-off-by: Judah Vang --- SecurityPkg/Library/VariableKeyLib/VariableKeyLib.inf | 36 ++++++++++++ SecurityPkg/Library/VariableKeyLib/VariableKeyLib.c | 59 ++++++++++++++++++++ 2 files changed, 95 insertions(+) diff --git a/SecurityPkg/Library/VariableKeyLib/VariableKeyLib.inf b/SecurityPkg/Library/VariableKeyLib/VariableKeyLib.inf new file mode 100644 index 000000000000..f62c80ce9943 --- /dev/null +++ b/SecurityPkg/Library/VariableKeyLib/VariableKeyLib.inf @@ -0,0 +1,36 @@ +## @file +# Provides default implementation of VariableKeyLib. +# +# Copyright (c) 2022, Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION = 0x00010029 + BASE_NAME = VariableKeyLib + FILE_GUID = 7DF5A0BA-1DBB-4E67-A9F7-9FCCB1F9D250 + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = VariableKeyLib + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 Arm AArch64 +# + +[Sources] + VariableKeyLib.c + +[Packages] + MdePkg/MdePkg.dec + SecurityPkg/SecurityPkg.dec + +[LibraryClasses] + BaseLib + DebugLib + +[PpiS] + gKeyServicePpiGuid ## CONSUMES + diff --git a/SecurityPkg/Library/VariableKeyLib/VariableKeyLib.c b/SecurityPkg/Library/VariableKeyLib/VariableKeyLib.c new file mode 100644 index 000000000000..31b22782cb0c --- /dev/null +++ b/SecurityPkg/Library/VariableKeyLib/VariableKeyLib.c @@ -0,0 +1,59 @@ +/** @file + VariableKeyLib implementation. + +Copyright (c) 2022, Intel Corporation. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include + +#include +#include +#include + +#include + +#define VAR_KEY_SALT L"Key for RPMC Variable" +#define VAR_KEY_SALT_SIZE sizeof (VAR_KEY_SALT) + +/** + Retrieves the key for integrity and/or confidentiality of variables. + + @param[out] VariableKey A pointer to pointer for the variable key buffer. + @param[in] VariableKeySize The size in bytes of the variable key. + + @retval EFI_SUCCESS The variable key was returned. + @retval EFI_DEVICE_ERROR An error occurred while attempting to get the variable key. + @retval EFI_ACCESS_DENIED The function was invoked after locking the key interface. + @retval EFI_UNSUPPORTED The variable key is not supported in the current boot configuration. +**/ +EFI_STATUS +EFIAPI +GetVariableKey ( + OUT VOID *VariableKey, + IN UINTN VariableKeySize + ) +{ + EFI_STATUS Status; + KEY_SERVICE_PPI *KeyService; + + Status = PeiServicesLocatePpi ( + &gKeyServicePpiGuid, + 0, + NULL, + (void **)&KeyService + ); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + return Status; + } + + Status = KeyService->GenerateKey ( + (UINT8 *)VAR_KEY_SALT, + VAR_KEY_SALT_SIZE, + VariableKey, + VariableKeySize + ); + return Status; +} -- 2.26.2.windows.1