]>
Commit | Line | Data |
---|---|---|
cd70de1c MK |
1 | /** @file\r |
2 | Implements the GetCryptoServices() API that retuns a pointer to the EDK II\r | |
3 | Crypto Protocol.\r | |
4 | \r | |
5 | Copyright (C) Microsoft Corporation. All rights reserved.\r | |
6 | SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
7 | \r | |
8 | **/\r | |
9 | #include <PiDxe.h>\r | |
10 | #include <Library/BaseLib.h>\r | |
11 | #include <Library/DebugLib.h>\r | |
12 | #include <Library/UefiBootServicesTableLib.h>\r | |
13 | #include <Protocol/Crypto.h>\r | |
14 | \r | |
15 | EDKII_CRYPTO_PROTOCOL *mCryptoProtocol = NULL;\r | |
16 | \r | |
17 | /**\r | |
18 | Internal worker function that returns the pointer to an EDK II Crypto\r | |
19 | Protocol/PPI. The layout of the PPI, DXE Protocol, and SMM Protocol are\r | |
20 | identical which allows the implementation of the BaseCryptLib functions that\r | |
21 | call through a Protocol/PPI to be shared for the PEI, DXE, and SMM\r | |
22 | implementations.\r | |
23 | \r | |
24 | This DXE implementation returns the pointer to the EDK II Crypto Protocol\r | |
25 | that was found in the library constructor DxeCryptLibConstructor().\r | |
26 | **/\r | |
27 | VOID *\r | |
28 | GetCryptoServices (\r | |
29 | VOID\r | |
30 | )\r | |
31 | {\r | |
32 | return (VOID *)mCryptoProtocol;\r | |
33 | }\r | |
34 | \r | |
8acb61df G |
35 | /**\r |
36 | Locate the valid Crypto Protocol.\r | |
37 | \r | |
38 | @param ImageHandle The firmware allocated handle for the EFI image.\r | |
39 | @param SystemTable A pointer to the EFI System Table.\r | |
40 | \r | |
41 | @retval EFI_SUCCESS The constructor executed correctly.\r | |
42 | @retval EFI_NOT_FOUND Found no valid Crypto Protocol.\r | |
43 | **/\r | |
cd70de1c MK |
44 | EFI_STATUS\r |
45 | EFIAPI\r | |
46 | DxeCryptLibConstructor (\r | |
47 | IN EFI_HANDLE ImageHandle,\r | |
48 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
49 | )\r | |
50 | {\r | |
51 | EFI_STATUS Status;\r | |
52 | UINTN Version;\r | |
53 | \r | |
54 | Status = gBS->LocateProtocol (\r | |
55 | &gEdkiiCryptoProtocolGuid,\r | |
56 | NULL,\r | |
57 | (VOID **)&mCryptoProtocol\r | |
58 | );\r | |
59 | \r | |
60 | if (EFI_ERROR (Status) || mCryptoProtocol == NULL) {\r | |
61 | DEBUG((DEBUG_ERROR, "[DxeCryptLib] Failed to locate Crypto Protocol. Status = %r\n", Status));\r | |
62 | ASSERT_EFI_ERROR (Status);\r | |
63 | ASSERT (mCryptoProtocol != NULL);\r | |
64 | mCryptoProtocol = NULL;\r | |
65 | return EFI_NOT_FOUND;\r | |
66 | }\r | |
67 | \r | |
68 | Version = mCryptoProtocol->GetVersion ();\r | |
69 | if (Version < EDKII_CRYPTO_VERSION) {\r | |
70 | DEBUG((DEBUG_ERROR, "[DxeCryptLib] Crypto Protocol unsupported version %d\n", Version));\r | |
71 | ASSERT (Version >= EDKII_CRYPTO_VERSION);\r | |
72 | mCryptoProtocol = NULL;\r | |
73 | return EFI_NOT_FOUND;\r | |
74 | }\r | |
75 | \r | |
76 | return EFI_SUCCESS;\r | |
77 | }\r |