]> git.proxmox.com Git - mirror_edk2.git/blob - CryptoPkg/Library/BaseCryptLibOnProtocolPpi/DxeCryptLib.c
34d5f410b0710113608dd2d4777f846068c26a22
[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 EFI_STATUS
36 EFIAPI
37 DxeCryptLibConstructor (
38 IN EFI_HANDLE ImageHandle,
39 IN EFI_SYSTEM_TABLE *SystemTable
40 )
41 {
42 EFI_STATUS Status;
43 UINTN Version;
44
45 Status = gBS->LocateProtocol (
46 &gEdkiiCryptoProtocolGuid,
47 NULL,
48 (VOID **)&mCryptoProtocol
49 );
50
51 if (EFI_ERROR (Status) || mCryptoProtocol == NULL) {
52 DEBUG((DEBUG_ERROR, "[DxeCryptLib] Failed to locate Crypto Protocol. Status = %r\n", Status));
53 ASSERT_EFI_ERROR (Status);
54 ASSERT (mCryptoProtocol != NULL);
55 mCryptoProtocol = NULL;
56 return EFI_NOT_FOUND;
57 }
58
59 Version = mCryptoProtocol->GetVersion ();
60 if (Version < EDKII_CRYPTO_VERSION) {
61 DEBUG((DEBUG_ERROR, "[DxeCryptLib] Crypto Protocol unsupported version %d\n", Version));
62 ASSERT (Version >= EDKII_CRYPTO_VERSION);
63 mCryptoProtocol = NULL;
64 return EFI_NOT_FOUND;
65 }
66
67 return EFI_SUCCESS;
68 }