mirror of https://github.com/acidanthera/audk.git
CryptoPkg/Library: Add BaseCryptLibOnProtocolPpi instances
https://bugzilla.tianocore.org/show_bug.cgi?id=2420 Based on the following package with changes to merge into CryptoPkg. https://github.com/microsoft/mu_plus/tree/dev/201908/SharedCryptoPkg Add the PeiCryptLib, DxeCryptLib, and SmmCryptLib instances of the BaseCryptLib library classes that are implemented using the services of EDK II Crypto Protocols/PPIs. These library instances all set a dependency expression on the EDK II Crypto Protocols/PPIs, so any modules that use these library instances are not dispatched until the modules that produce the EDK II Crypto Protocols/PPIs are dispatched. Cc: Jian J Wang <jian.j.wang@intel.com> Cc: Xiaoyu Lu <xiaoyux.lu@intel.com> Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com> Reviewed-by: Jian J Wang <jian.j.wang@intel.com>
This commit is contained in:
parent
cc1d13c922
commit
cd70de1cc0
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,12 @@
|
|||
// /** @file
|
||||
// BaseCryptLib and TlsLib using the services of the EDK II Crypto Protocol/PPI.
|
||||
//
|
||||
// Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
|
||||
//
|
||||
// SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
//
|
||||
// **/
|
||||
|
||||
#string STR_MODULE_ABSTRACT #language en-US "BaseCryptLib and TlsLib using the services of the EDK II Crypto Protocol/PPI"
|
||||
|
||||
#string STR_MODULE_DESCRIPTION #language en-US "BaseCryptLib and TlsLib using the services of the EDK II Crypto Protocol/PPI."
|
|
@ -0,0 +1,68 @@
|
|||
/** @file
|
||||
Implements the GetCryptoServices() API that retuns a pointer to the EDK II
|
||||
Crypto Protocol.
|
||||
|
||||
Copyright (C) Microsoft Corporation. All rights reserved.
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
**/
|
||||
#include <PiDxe.h>
|
||||
#include <Library/BaseLib.h>
|
||||
#include <Library/DebugLib.h>
|
||||
#include <Library/UefiBootServicesTableLib.h>
|
||||
#include <Protocol/Crypto.h>
|
||||
|
||||
EDKII_CRYPTO_PROTOCOL *mCryptoProtocol = NULL;
|
||||
|
||||
/**
|
||||
Internal worker function that returns the pointer to an EDK II Crypto
|
||||
Protocol/PPI. The layout of the PPI, DXE Protocol, and SMM Protocol are
|
||||
identical which allows the implementation of the BaseCryptLib functions that
|
||||
call through a Protocol/PPI to be shared for the PEI, DXE, and SMM
|
||||
implementations.
|
||||
|
||||
This DXE implementation returns the pointer to the EDK II Crypto Protocol
|
||||
that was found in the library constructor DxeCryptLibConstructor().
|
||||
**/
|
||||
VOID *
|
||||
GetCryptoServices (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
return (VOID *)mCryptoProtocol;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
DxeCryptLibConstructor (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINTN Version;
|
||||
|
||||
Status = gBS->LocateProtocol (
|
||||
&gEdkiiCryptoProtocolGuid,
|
||||
NULL,
|
||||
(VOID **)&mCryptoProtocol
|
||||
);
|
||||
|
||||
if (EFI_ERROR (Status) || mCryptoProtocol == NULL) {
|
||||
DEBUG((DEBUG_ERROR, "[DxeCryptLib] Failed to locate Crypto Protocol. Status = %r\n", Status));
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
ASSERT (mCryptoProtocol != NULL);
|
||||
mCryptoProtocol = NULL;
|
||||
return EFI_NOT_FOUND;
|
||||
}
|
||||
|
||||
Version = mCryptoProtocol->GetVersion ();
|
||||
if (Version < EDKII_CRYPTO_VERSION) {
|
||||
DEBUG((DEBUG_ERROR, "[DxeCryptLib] Crypto Protocol unsupported version %d\n", Version));
|
||||
ASSERT (Version >= EDKII_CRYPTO_VERSION);
|
||||
mCryptoProtocol = NULL;
|
||||
return EFI_NOT_FOUND;
|
||||
}
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
## @file
|
||||
# Implements the BaseCryptLib and TlsLib using the services of the EDK II Crypto
|
||||
# Protocol.
|
||||
#
|
||||
# Copyright (C) Microsoft Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
#
|
||||
##
|
||||
|
||||
[Defines]
|
||||
INF_VERSION = 0x0001001B
|
||||
BASE_NAME = DxeCryptLib
|
||||
MODULE_UNI_FILE = CryptLib.uni
|
||||
FILE_GUID = B38CBDA6-8017-4111-8232-9E8328DE82F6
|
||||
VERSION_STRING = 1.0
|
||||
MODULE_TYPE = DXE_DRIVER
|
||||
LIBRARY_CLASS = BaseCryptLib | DXE_DRIVER UEFI_DRIVER UEFI_APPLICATION
|
||||
LIBRARY_CLASS = TlsLib | DXE_DRIVER UEFI_DRIVER UEFI_APPLICATION
|
||||
CONSTRUCTOR = DxeCryptLibConstructor
|
||||
|
||||
#
|
||||
# The following information is for reference only and not required by the build tools.
|
||||
#
|
||||
# VALID_ARCHITECTURES = IA32 X64 ARM AARCH64
|
||||
#
|
||||
|
||||
[Packages]
|
||||
MdePkg/MdePkg.dec
|
||||
CryptoPkg/CryptoPkg.dec
|
||||
|
||||
[LibraryClasses]
|
||||
BaseLib
|
||||
DebugLib
|
||||
UefiBootServicesTableLib
|
||||
|
||||
[Sources]
|
||||
DxeCryptLib.c
|
||||
CryptLib.c
|
||||
|
||||
[Protocols]
|
||||
gEdkiiCryptoProtocolGuid ## CONSUMES
|
||||
|
||||
[Depex]
|
||||
gEdkiiCryptoProtocolGuid
|
|
@ -0,0 +1,57 @@
|
|||
/** @file
|
||||
Implements the GetCryptoServices() API that retuns a pointer to the EDK II
|
||||
Crypto PPI.
|
||||
|
||||
Copyright (C) Microsoft Corporation. All rights reserved.
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
**/
|
||||
#include <PiPei.h>
|
||||
#include <Library/BaseLib.h>
|
||||
#include <Library/DebugLib.h>
|
||||
#include <Library/PeiServicesLib.h>
|
||||
#include <Ppi/Crypto.h>
|
||||
|
||||
/**
|
||||
Internal worker function that returns the pointer to an EDK II Crypto
|
||||
Protocol/PPI. The layout of the PPI, DXE Protocol, and SMM Protocol are
|
||||
identical which allows the implementation of the BaseCryptLib functions that
|
||||
call through a Protocol/PPI to be shared for the PEI, DXE, and SMM
|
||||
implementations.
|
||||
|
||||
This PEI implementation looks up the EDK II Crypto PPI and verifies the
|
||||
version each time a crypto service is called, so it is compatible with XIP
|
||||
PEIMs.
|
||||
**/
|
||||
VOID *
|
||||
GetCryptoServices (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EDKII_CRYPTO_PPI *CryptoPpi;
|
||||
UINTN Version;
|
||||
|
||||
CryptoPpi = NULL;
|
||||
Status = PeiServicesLocatePpi (
|
||||
&gEdkiiCryptoPpiGuid,
|
||||
0,
|
||||
NULL,
|
||||
(VOID **)&CryptoPpi
|
||||
);
|
||||
if (EFI_ERROR (Status) || CryptoPpi == NULL) {
|
||||
DEBUG((DEBUG_ERROR, "[PeiCryptLib] Failed to locate Crypto PPI. Status = %r\n", Status));
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
ASSERT (CryptoPpi != NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Version = CryptoPpi->GetVersion ();
|
||||
if (Version < EDKII_CRYPTO_VERSION) {
|
||||
DEBUG((DEBUG_ERROR, "[PeiCryptLib] Crypto PPI unsupported version %d\n", Version));
|
||||
ASSERT (Version >= EDKII_CRYPTO_VERSION);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (VOID *)CryptoPpi;
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
## @file
|
||||
# Implements the BaseCryptLib and TlsLib using the services of the EDK II Crypto
|
||||
# PPI.
|
||||
#
|
||||
# Copyright (C) Microsoft Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
#
|
||||
##
|
||||
|
||||
[Defines]
|
||||
INF_VERSION = 0x0001001B
|
||||
BASE_NAME = PeiCryptLib
|
||||
MODULE_UNI_FILE = CryptLib.uni
|
||||
FILE_GUID = 3E8B50C6-F68C-4212-B903-94A10FE02399
|
||||
VERSION_STRING = 1.0
|
||||
MODULE_TYPE = PEIM
|
||||
LIBRARY_CLASS = BaseCryptLib | PEIM
|
||||
LIBRARY_CLASS = TlsLib | PEIM
|
||||
|
||||
#
|
||||
# The following information is for reference only and not required by the build tools.
|
||||
#
|
||||
# VALID_ARCHITECTURES = IA32 X64 ARM AARCH64
|
||||
#
|
||||
|
||||
[Packages]
|
||||
MdePkg/MdePkg.dec
|
||||
CryptoPkg/CryptoPkg.dec
|
||||
|
||||
[LibraryClasses]
|
||||
BaseLib
|
||||
DebugLib
|
||||
PeiServicesLib
|
||||
|
||||
[Sources]
|
||||
PeiCryptLib.c
|
||||
CryptLib.c
|
||||
|
||||
[Ppis]
|
||||
gEdkiiCryptoPpiGuid ## CONSUMES
|
||||
|
||||
[Depex]
|
||||
gEdkiiCryptoPpiGuid
|
|
@ -0,0 +1,79 @@
|
|||
/** @file
|
||||
Implements the GetCryptoServices() API that retuns a pointer to the EDK II
|
||||
SMM Crypto Protocol.
|
||||
|
||||
Copyright (C) Microsoft Corporation. All rights reserved.
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
**/
|
||||
|
||||
#include <PiSmm.h>
|
||||
#include <Library/BaseLib.h>
|
||||
#include <Library/DebugLib.h>
|
||||
#include <Library/SmmServicesTableLib.h>
|
||||
#include <Protocol/SmmCrypto.h>
|
||||
|
||||
EDKII_SMM_CRYPTO_PROTOCOL *mSmmCryptoProtocol = NULL;
|
||||
|
||||
/**
|
||||
Internal worker function that returns the pointer to an EDK II Crypto
|
||||
Protocol/PPI. The layout of the PPI, DXE Protocol, and SMM Protocol are
|
||||
identical which allows the implementation of the BaseCryptLib functions that
|
||||
call through a Protocol/PPI to be shared for the PEI, DXE, and SMM
|
||||
implementations.
|
||||
|
||||
This SMM implementation returns the pointer to the EDK II SMM Crypto Protocol
|
||||
that was found in the library constructor SmmCryptLibConstructor().
|
||||
**/
|
||||
VOID *
|
||||
GetCryptoServices (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
return (VOID *)mSmmCryptoProtocol;
|
||||
}
|
||||
|
||||
/**
|
||||
Constructor looks up the EDK II SMM Crypto Protocol and verifies that it is
|
||||
not NULL and has a high enough version value to support all the BaseCryptLib
|
||||
functions.
|
||||
|
||||
@param ImageHandle The firmware allocated handle for the EFI image.
|
||||
@param SystemTable A pointer to the EFI System Table.
|
||||
|
||||
@retval EFI_SUCCESS The EDK II SMM Crypto Protocol was found.
|
||||
@retval EFI_NOT_FOUND The EDK II SMM Crypto Protocol was not found.
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
SmmCryptLibConstructor (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINTN Version;
|
||||
|
||||
Status = gSmst->SmmLocateProtocol (
|
||||
&gEdkiiSmmCryptoProtocolGuid,
|
||||
NULL,
|
||||
(VOID **)&mSmmCryptoProtocol
|
||||
);
|
||||
if (EFI_ERROR (Status) || mSmmCryptoProtocol == NULL) {
|
||||
DEBUG((DEBUG_ERROR, "[SmmCryptLib] Failed to locate Crypto SMM Protocol. Status = %r\n", Status));
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
ASSERT (mSmmCryptoProtocol != NULL);
|
||||
mSmmCryptoProtocol = NULL;
|
||||
return EFI_NOT_FOUND;
|
||||
}
|
||||
|
||||
Version = mSmmCryptoProtocol->GetVersion ();
|
||||
if (Version < EDKII_CRYPTO_VERSION) {
|
||||
DEBUG((DEBUG_ERROR, "[SmmCryptLib] Crypto SMM Protocol unsupported version %d\n", Version));
|
||||
ASSERT (Version >= EDKII_CRYPTO_VERSION);
|
||||
mSmmCryptoProtocol = NULL;
|
||||
return EFI_NOT_FOUND;
|
||||
}
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
## @file
|
||||
# Implements the BaseCryptLib and TlsLib using the services of the EDK II Crypto
|
||||
# SMM Protocol.
|
||||
#
|
||||
# Copyright (C) Microsoft Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
#
|
||||
##
|
||||
|
||||
[Defines]
|
||||
INF_VERSION = 0x0001001B
|
||||
BASE_NAME = SmmCryptLib
|
||||
MODULE_UNI_FILE = CryptLib.uni
|
||||
FILE_GUID = 5CC6ECC9-E961-46A9-8D5C-6581A060DC0D
|
||||
VERSION_STRING = 1.0
|
||||
MODULE_TYPE = DXE_SMM_DRIVER
|
||||
LIBRARY_CLASS = BaseCryptLib | DXE_SMM_DRIVER
|
||||
LIBRARY_CLASS = TlsLib | DXE_SMM_DRIVER
|
||||
CONSTRUCTOR = SmmCryptLibConstructor
|
||||
|
||||
#
|
||||
# The following information is for reference only and not required by the build tools.
|
||||
#
|
||||
# VALID_ARCHITECTURES = IA32 X64 ARM AARCH64
|
||||
#
|
||||
|
||||
[Packages]
|
||||
MdePkg/MdePkg.dec
|
||||
CryptoPkg/CryptoPkg.dec
|
||||
|
||||
[LibraryClasses]
|
||||
BaseLib
|
||||
DebugLib
|
||||
SmmServicesTableLib
|
||||
|
||||
[Sources]
|
||||
SmmCryptLib.c
|
||||
CryptLib.c
|
||||
|
||||
[Protocols]
|
||||
gEdkiiSmmCryptoProtocolGuid ## CONSUMES
|
||||
|
||||
[Depex]
|
||||
gEdkiiSmmCryptoProtocolGuid
|
Loading…
Reference in New Issue