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