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
11 #include <Library/BaseLib.h>
12 #include <Library/DebugLib.h>
13 #include <Library/SmmServicesTableLib.h>
14 #include <Protocol/SmmCrypto.h>
16 EDKII_SMM_CRYPTO_PROTOCOL
*mSmmCryptoProtocol
= NULL
;
19 Internal worker function that returns the pointer to an EDK II Crypto
20 Protocol/PPI. The layout of the PPI, DXE Protocol, and SMM Protocol are
21 identical which allows the implementation of the BaseCryptLib functions that
22 call through a Protocol/PPI to be shared for the PEI, DXE, and SMM
25 This SMM implementation returns the pointer to the EDK II SMM Crypto Protocol
26 that was found in the library constructor SmmCryptLibConstructor().
33 return (VOID
*)mSmmCryptoProtocol
;
37 Constructor looks up the EDK II SMM Crypto Protocol and verifies that it is
38 not NULL and has a high enough version value to support all the BaseCryptLib
41 @param ImageHandle The firmware allocated handle for the EFI image.
42 @param SystemTable A pointer to the EFI System Table.
44 @retval EFI_SUCCESS The EDK II SMM Crypto Protocol was found.
45 @retval EFI_NOT_FOUND The EDK II SMM Crypto Protocol was not found.
49 SmmCryptLibConstructor (
50 IN EFI_HANDLE ImageHandle
,
51 IN EFI_SYSTEM_TABLE
*SystemTable
57 Status
= gSmst
->SmmLocateProtocol (
58 &gEdkiiSmmCryptoProtocolGuid
,
60 (VOID
**)&mSmmCryptoProtocol
62 if (EFI_ERROR (Status
) || mSmmCryptoProtocol
== NULL
) {
63 DEBUG((DEBUG_ERROR
, "[SmmCryptLib] Failed to locate Crypto SMM Protocol. Status = %r\n", Status
));
64 ASSERT_EFI_ERROR (Status
);
65 ASSERT (mSmmCryptoProtocol
!= NULL
);
66 mSmmCryptoProtocol
= NULL
;
70 Version
= mSmmCryptoProtocol
->GetVersion ();
71 if (Version
< EDKII_CRYPTO_VERSION
) {
72 DEBUG((DEBUG_ERROR
, "[SmmCryptLib] Crypto SMM Protocol unsupported version %d\n", Version
));
73 ASSERT (Version
>= EDKII_CRYPTO_VERSION
);
74 mSmmCryptoProtocol
= NULL
;