2 Implements the GetCryptoServices() API that retuns a pointer to the EDK II
5 Copyright (C) Microsoft Corporation. All rights reserved.
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include <Library/BaseLib.h>
11 #include <Library/DebugLib.h>
12 #include <Library/UefiBootServicesTableLib.h>
13 #include <Protocol/Crypto.h>
15 EDKII_CRYPTO_PROTOCOL
*mCryptoProtocol
= NULL
;
18 Internal worker function that returns the pointer to an EDK II Crypto
19 Protocol/PPI. The layout of the PPI, DXE Protocol, and SMM Protocol are
20 identical which allows the implementation of the BaseCryptLib functions that
21 call through a Protocol/PPI to be shared for the PEI, DXE, and SMM
24 This DXE implementation returns the pointer to the EDK II Crypto Protocol
25 that was found in the library constructor DxeCryptLibConstructor().
32 return (VOID
*)mCryptoProtocol
;
36 Locate the valid Crypto Protocol.
38 @param ImageHandle The firmware allocated handle for the EFI image.
39 @param SystemTable A pointer to the EFI System Table.
41 @retval EFI_SUCCESS The constructor executed correctly.
42 @retval EFI_NOT_FOUND Found no valid Crypto Protocol.
46 DxeCryptLibConstructor (
47 IN EFI_HANDLE ImageHandle
,
48 IN EFI_SYSTEM_TABLE
*SystemTable
54 Status
= gBS
->LocateProtocol (
55 &gEdkiiCryptoProtocolGuid
,
57 (VOID
**)&mCryptoProtocol
60 if (EFI_ERROR (Status
) || (mCryptoProtocol
== NULL
)) {
61 DEBUG ((DEBUG_ERROR
, "[DxeCryptLib] Failed to locate Crypto Protocol. Status = %r\n", Status
));
62 ASSERT_EFI_ERROR (Status
);
63 ASSERT (mCryptoProtocol
!= NULL
);
64 mCryptoProtocol
= NULL
;
68 Version
= mCryptoProtocol
->GetVersion ();
69 if (Version
< EDKII_CRYPTO_VERSION
) {
70 DEBUG ((DEBUG_ERROR
, "[DxeCryptLib] Crypto Protocol unsupported version %d\n", Version
));
71 ASSERT (Version
>= EDKII_CRYPTO_VERSION
);
72 mCryptoProtocol
= NULL
;