summaryrefslogtreecommitdiffstats
path: root/CryptoPkg/Library/BaseCryptLibOnProtocolPpi/PeiCryptLib.c
diff options
context:
space:
mode:
authorMichael D Kinney <michael.d.kinney@intel.com>2019-11-21 09:24:53 -0800
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2020-02-07 16:32:13 +0000
commitcd70de1cc0c954dd9608e63093fac0d4f50be630 (patch)
tree3e1247c095fc701db4caeb69769a441fca0c2dcb /CryptoPkg/Library/BaseCryptLibOnProtocolPpi/PeiCryptLib.c
parentcc1d13c9228d988071834b12c8494efb28b55802 (diff)
downloadedk2-cd70de1cc0c954dd9608e63093fac0d4f50be630.tar.gz
edk2-cd70de1cc0c954dd9608e63093fac0d4f50be630.tar.bz2
edk2-cd70de1cc0c954dd9608e63093fac0d4f50be630.zip
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>
Diffstat (limited to 'CryptoPkg/Library/BaseCryptLibOnProtocolPpi/PeiCryptLib.c')
-rw-r--r--CryptoPkg/Library/BaseCryptLibOnProtocolPpi/PeiCryptLib.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/CryptoPkg/Library/BaseCryptLibOnProtocolPpi/PeiCryptLib.c b/CryptoPkg/Library/BaseCryptLibOnProtocolPpi/PeiCryptLib.c
new file mode 100644
index 0000000000..4fd0e4d3bb
--- /dev/null
+++ b/CryptoPkg/Library/BaseCryptLibOnProtocolPpi/PeiCryptLib.c
@@ -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;
+}