1 | /** @file
|
---|
2 | Implements the GetCryptoServices() API that retuns a pointer to the EDK II
|
---|
3 | SMM Crypto Protocol.
|
---|
4 |
|
---|
5 | Copyright (c) 2024, American Megatrends International LLC. All rights reserved.<BR>
|
---|
6 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
7 |
|
---|
8 | **/
|
---|
9 |
|
---|
10 | #include <PiMm.h>
|
---|
11 | #include <Library/BaseLib.h>
|
---|
12 | #include <Library/DebugLib.h>
|
---|
13 | #include <Library/MmServicesTableLib.h>
|
---|
14 | #include <Protocol/SmmCrypto.h>
|
---|
15 |
|
---|
16 | EDKII_SMM_CRYPTO_PROTOCOL *mSmmCryptoProtocol = NULL;
|
---|
17 |
|
---|
18 | /**
|
---|
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
|
---|
23 | implementations.
|
---|
24 |
|
---|
25 | This SMM implementation returns the pointer to the EDK II SMM Crypto Protocol
|
---|
26 | that was found in the library constructor SmmCryptLibConstructor().
|
---|
27 | **/
|
---|
28 | VOID *
|
---|
29 | GetCryptoServices (
|
---|
30 | VOID
|
---|
31 | )
|
---|
32 | {
|
---|
33 | return (VOID *)mSmmCryptoProtocol;
|
---|
34 | }
|
---|
35 |
|
---|
36 | /**
|
---|
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
|
---|
39 | functions.
|
---|
40 |
|
---|
41 | @param ImageHandle The firmware allocated handle for the EFI image.
|
---|
42 | @param MmSystemTable A pointer to the MM System Table.
|
---|
43 |
|
---|
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.
|
---|
46 | **/
|
---|
47 | EFI_STATUS
|
---|
48 | EFIAPI
|
---|
49 | StandaloneMmCryptLibConstructor (
|
---|
50 | IN EFI_HANDLE ImageHandle,
|
---|
51 | IN EFI_MM_SYSTEM_TABLE *MmSystemTable
|
---|
52 | )
|
---|
53 | {
|
---|
54 | EFI_STATUS Status;
|
---|
55 | UINTN Version;
|
---|
56 |
|
---|
57 | Status = gMmst->MmLocateProtocol (
|
---|
58 | &gEdkiiSmmCryptoProtocolGuid,
|
---|
59 | NULL,
|
---|
60 | (VOID **)&mSmmCryptoProtocol
|
---|
61 | );
|
---|
62 | if (EFI_ERROR (Status) || (mSmmCryptoProtocol == NULL)) {
|
---|
63 | DEBUG ((DEBUG_ERROR, "[StandaloneMmCryptLib] Failed to locate Crypto SMM Protocol. Status = %r\n", Status));
|
---|
64 | ASSERT_EFI_ERROR (Status);
|
---|
65 | ASSERT (mSmmCryptoProtocol != NULL);
|
---|
66 | mSmmCryptoProtocol = NULL;
|
---|
67 | return EFI_NOT_FOUND;
|
---|
68 | }
|
---|
69 |
|
---|
70 | Version = mSmmCryptoProtocol->GetVersion ();
|
---|
71 | if (Version < EDKII_CRYPTO_VERSION) {
|
---|
72 | DEBUG ((DEBUG_ERROR, "[StandaloneMmCryptLib] Crypto SMM Protocol unsupported version %d\n", Version));
|
---|
73 | ASSERT (Version >= EDKII_CRYPTO_VERSION);
|
---|
74 | mSmmCryptoProtocol = NULL;
|
---|
75 | return EFI_NOT_FOUND;
|
---|
76 | }
|
---|
77 |
|
---|
78 | return EFI_SUCCESS;
|
---|
79 | }
|
---|