]> git.proxmox.com Git - mirror_edk2.git/blob - CryptoPkg/Library/BaseCryptLibOnProtocolPpi/DxeCryptLib.c
CryptoPkg: Apply uncrustify changes
[mirror_edk2.git] / CryptoPkg / Library / BaseCryptLibOnProtocolPpi / DxeCryptLib.c
1 /** @file
2 Implements the GetCryptoServices() API that retuns a pointer to the EDK II
3 Crypto Protocol.
4
5 Copyright (C) Microsoft Corporation. All rights reserved.
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9 #include <PiDxe.h>
10 #include <Library/BaseLib.h>
11 #include <Library/DebugLib.h>
12 #include <Library/UefiBootServicesTableLib.h>
13 #include <Protocol/Crypto.h>
14
15 EDKII_CRYPTO_PROTOCOL *mCryptoProtocol = NULL;
16
17 /**
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
22 implementations.
23
24 This DXE implementation returns the pointer to the EDK II Crypto Protocol
25 that was found in the library constructor DxeCryptLibConstructor().
26 **/
27 VOID *
28 GetCryptoServices (
29 VOID
30 )
31 {
32 return (VOID *)mCryptoProtocol;
33 }
34
35 /**
36 Locate the valid Crypto Protocol.
37
38 @param ImageHandle The firmware allocated handle for the EFI image.
39 @param SystemTable A pointer to the EFI System Table.
40
41 @retval EFI_SUCCESS The constructor executed correctly.
42 @retval EFI_NOT_FOUND Found no valid Crypto Protocol.
43 **/
44 EFI_STATUS
45 EFIAPI
46 DxeCryptLibConstructor (
47 IN EFI_HANDLE ImageHandle,
48 IN EFI_SYSTEM_TABLE *SystemTable
49 )
50 {
51 EFI_STATUS Status;
52 UINTN Version;
53
54 Status = gBS->LocateProtocol (
55 &gEdkiiCryptoProtocolGuid,
56 NULL,
57 (VOID **)&mCryptoProtocol
58 );
59
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;
65 return EFI_NOT_FOUND;
66 }
67
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;
73 return EFI_NOT_FOUND;
74 }
75
76 return EFI_SUCCESS;
77 }