]> git.proxmox.com Git - mirror_edk2.git/blame - CryptoPkg/Library/BaseCryptLibOnProtocolPpi/PeiCryptLib.c
CryptoPkg/Library: Add BaseCryptLibOnProtocolPpi instances
[mirror_edk2.git] / CryptoPkg / Library / BaseCryptLibOnProtocolPpi / PeiCryptLib.c
CommitLineData
cd70de1c
MK
1/** @file\r
2 Implements the GetCryptoServices() API that retuns a pointer to the EDK II\r
3 Crypto PPI.\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 <PiPei.h>\r
10#include <Library/BaseLib.h>\r
11#include <Library/DebugLib.h>\r
12#include <Library/PeiServicesLib.h>\r
13#include <Ppi/Crypto.h>\r
14\r
15/**\r
16 Internal worker function that returns the pointer to an EDK II Crypto\r
17 Protocol/PPI. The layout of the PPI, DXE Protocol, and SMM Protocol are\r
18 identical which allows the implementation of the BaseCryptLib functions that\r
19 call through a Protocol/PPI to be shared for the PEI, DXE, and SMM\r
20 implementations.\r
21\r
22 This PEI implementation looks up the EDK II Crypto PPI and verifies the\r
23 version each time a crypto service is called, so it is compatible with XIP\r
24 PEIMs.\r
25**/\r
26VOID *\r
27GetCryptoServices (\r
28 VOID\r
29 )\r
30{\r
31 EFI_STATUS Status;\r
32 EDKII_CRYPTO_PPI *CryptoPpi;\r
33 UINTN Version;\r
34\r
35 CryptoPpi = NULL;\r
36 Status = PeiServicesLocatePpi (\r
37 &gEdkiiCryptoPpiGuid,\r
38 0,\r
39 NULL,\r
40 (VOID **)&CryptoPpi\r
41 );\r
42 if (EFI_ERROR (Status) || CryptoPpi == NULL) {\r
43 DEBUG((DEBUG_ERROR, "[PeiCryptLib] Failed to locate Crypto PPI. Status = %r\n", Status));\r
44 ASSERT_EFI_ERROR (Status);\r
45 ASSERT (CryptoPpi != NULL);\r
46 return NULL;\r
47 }\r
48\r
49 Version = CryptoPpi->GetVersion ();\r
50 if (Version < EDKII_CRYPTO_VERSION) {\r
51 DEBUG((DEBUG_ERROR, "[PeiCryptLib] Crypto PPI unsupported version %d\n", Version));\r
52 ASSERT (Version >= EDKII_CRYPTO_VERSION);\r
53 return NULL;\r
54 }\r
55\r
56 return (VOID *)CryptoPpi;\r
57}\r