diff options
Diffstat (limited to 'CryptoPkg/Library')
-rw-r--r-- | CryptoPkg/Library/BaseCryptLibOnProtocolPpi/StandaloneMmCryptLib.c | 79 | ||||
-rw-r--r-- | CryptoPkg/Library/BaseCryptLibOnProtocolPpi/StandaloneMmCryptLib.inf | 45 |
2 files changed, 124 insertions, 0 deletions
diff --git a/CryptoPkg/Library/BaseCryptLibOnProtocolPpi/StandaloneMmCryptLib.c b/CryptoPkg/Library/BaseCryptLibOnProtocolPpi/StandaloneMmCryptLib.c new file mode 100644 index 0000000000..184333f8af --- /dev/null +++ b/CryptoPkg/Library/BaseCryptLibOnProtocolPpi/StandaloneMmCryptLib.c @@ -0,0 +1,79 @@ +/** @file
+ Implements the GetCryptoServices() API that retuns a pointer to the EDK II
+ SMM Crypto Protocol.
+
+ Copyright (c) 2024, American Megatrends International LLC. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <PiMm.h>
+#include <Library/BaseLib.h>
+#include <Library/DebugLib.h>
+#include <Library/MmServicesTableLib.h>
+#include <Protocol/SmmCrypto.h>
+
+EDKII_SMM_CRYPTO_PROTOCOL *mSmmCryptoProtocol = NULL;
+
+/**
+ Internal worker function that returns the pointer to an EDK II Crypto
+ Protocol/PPI. The layout of the PPI, DXE Protocol, and SMM Protocol are
+ identical which allows the implementation of the BaseCryptLib functions that
+ call through a Protocol/PPI to be shared for the PEI, DXE, and SMM
+ implementations.
+
+ This SMM implementation returns the pointer to the EDK II SMM Crypto Protocol
+ that was found in the library constructor SmmCryptLibConstructor().
+**/
+VOID *
+GetCryptoServices (
+ VOID
+ )
+{
+ return (VOID *)mSmmCryptoProtocol;
+}
+
+/**
+ Constructor looks up the EDK II SMM Crypto Protocol and verifies that it is
+ not NULL and has a high enough version value to support all the BaseCryptLib
+ functions.
+
+ @param ImageHandle The firmware allocated handle for the EFI image.
+ @param MmSystemTable A pointer to the MM System Table.
+
+ @retval EFI_SUCCESS The EDK II SMM Crypto Protocol was found.
+ @retval EFI_NOT_FOUND The EDK II SMM Crypto Protocol was not found.
+**/
+EFI_STATUS
+EFIAPI
+StandaloneMmCryptLibConstructor (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_MM_SYSTEM_TABLE *MmSystemTable
+ )
+{
+ EFI_STATUS Status;
+ UINTN Version;
+
+ Status = gMmst->MmLocateProtocol (
+ &gEdkiiSmmCryptoProtocolGuid,
+ NULL,
+ (VOID **)&mSmmCryptoProtocol
+ );
+ if (EFI_ERROR (Status) || (mSmmCryptoProtocol == NULL)) {
+ DEBUG ((DEBUG_ERROR, "[StandaloneMmCryptLib] Failed to locate Crypto SMM Protocol. Status = %r\n", Status));
+ ASSERT_EFI_ERROR (Status);
+ ASSERT (mSmmCryptoProtocol != NULL);
+ mSmmCryptoProtocol = NULL;
+ return EFI_NOT_FOUND;
+ }
+
+ Version = mSmmCryptoProtocol->GetVersion ();
+ if (Version < EDKII_CRYPTO_VERSION) {
+ DEBUG ((DEBUG_ERROR, "[StandaloneMmCryptLib] Crypto SMM Protocol unsupported version %d\n", Version));
+ ASSERT (Version >= EDKII_CRYPTO_VERSION);
+ mSmmCryptoProtocol = NULL;
+ return EFI_NOT_FOUND;
+ }
+
+ return EFI_SUCCESS;
+}
diff --git a/CryptoPkg/Library/BaseCryptLibOnProtocolPpi/StandaloneMmCryptLib.inf b/CryptoPkg/Library/BaseCryptLibOnProtocolPpi/StandaloneMmCryptLib.inf new file mode 100644 index 0000000000..b229e75582 --- /dev/null +++ b/CryptoPkg/Library/BaseCryptLibOnProtocolPpi/StandaloneMmCryptLib.inf @@ -0,0 +1,45 @@ +## @file
+# Implements the BaseCryptLib and TlsLib using the services of the EDK II Crypto
+# SMM Protocol for Stdandalone MM.
+#
+# Copyright (c) 2024, American Megatrends International LLC. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ INF_VERSION = 0x0001001B
+ BASE_NAME = StandaloneMmCryptLib
+ MODULE_UNI_FILE = CryptLib.uni
+ FILE_GUID = FA7EB4FD-7B3B-4FE4-BA95-1CE47CD0BE3E
+ VERSION_STRING = 1.0
+ PI_SPECIFICATION_VERSION = 0x00010032
+ MODULE_TYPE = MM_STANDALONE
+ LIBRARY_CLASS = BaseCryptLib | MM_STANDALONE
+ LIBRARY_CLASS = TlsLib | MM_STANDALONE
+ CONSTRUCTOR = StandaloneMmCryptLibConstructor
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64 ARM AARCH64
+#
+
+[Packages]
+ MdePkg/MdePkg.dec
+ CryptoPkg/CryptoPkg.dec
+
+[LibraryClasses]
+ BaseLib
+ DebugLib
+ MmServicesTableLib
+
+[Sources]
+ StandaloneMmCryptLib.c
+ CryptLib.c
+
+[Protocols]
+ gEdkiiSmmCryptoProtocolGuid ## CONSUMES
+
+[Depex]
+ gEdkiiSmmCryptoProtocolGuid
|