--- /dev/null
+/** @file\r
+ Implements the GetCryptoServices() API that retuns a pointer to the EDK II\r
+ Crypto Protocol.\r
+\r
+ Copyright (C) Microsoft Corporation. All rights reserved.\r
+ SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+#include <PiDxe.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Protocol/Crypto.h>\r
+\r
+EDKII_CRYPTO_PROTOCOL *mCryptoProtocol = NULL;\r
+\r
+/**\r
+ Internal worker function that returns the pointer to an EDK II Crypto\r
+ Protocol/PPI. The layout of the PPI, DXE Protocol, and SMM Protocol are\r
+ identical which allows the implementation of the BaseCryptLib functions that\r
+ call through a Protocol/PPI to be shared for the PEI, DXE, and SMM\r
+ implementations.\r
+\r
+ This DXE implementation returns the pointer to the EDK II Crypto Protocol\r
+ that was found in the library constructor DxeCryptLibConstructor().\r
+**/\r
+VOID *\r
+GetCryptoServices (\r
+ VOID\r
+ )\r
+{\r
+ return (VOID *)mCryptoProtocol;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+DxeCryptLibConstructor (\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_SYSTEM_TABLE *SystemTable\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ UINTN Version;\r
+\r
+ Status = gBS->LocateProtocol (\r
+ &gEdkiiCryptoProtocolGuid,\r
+ NULL,\r
+ (VOID **)&mCryptoProtocol\r
+ );\r
+\r
+ if (EFI_ERROR (Status) || mCryptoProtocol == NULL) {\r
+ DEBUG((DEBUG_ERROR, "[DxeCryptLib] Failed to locate Crypto Protocol. Status = %r\n", Status));\r
+ ASSERT_EFI_ERROR (Status);\r
+ ASSERT (mCryptoProtocol != NULL);\r
+ mCryptoProtocol = NULL;\r
+ return EFI_NOT_FOUND;\r
+ }\r
+\r
+ Version = mCryptoProtocol->GetVersion ();\r
+ if (Version < EDKII_CRYPTO_VERSION) {\r
+ DEBUG((DEBUG_ERROR, "[DxeCryptLib] Crypto Protocol unsupported version %d\n", Version));\r
+ ASSERT (Version >= EDKII_CRYPTO_VERSION);\r
+ mCryptoProtocol = NULL;\r
+ return EFI_NOT_FOUND;\r
+ }\r
+\r
+ return EFI_SUCCESS;\r
+}\r