From af1a266670d040d2f4083ff309d732d648afba2a Mon Sep 17 00:00:00 2001 From: Angelos Mouzakitis Date: Tue, 10 Oct 2023 14:33:42 +0000 Subject: Add submodule dependency files Change-Id: Iaf8d18082d3991dec7c0ebbea540f092188eb4ec --- .../BaseCryptLibOnProtocolPpi/PeiCryptLib.c | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 roms/edk2/CryptoPkg/Library/BaseCryptLibOnProtocolPpi/PeiCryptLib.c (limited to 'roms/edk2/CryptoPkg/Library/BaseCryptLibOnProtocolPpi/PeiCryptLib.c') diff --git a/roms/edk2/CryptoPkg/Library/BaseCryptLibOnProtocolPpi/PeiCryptLib.c b/roms/edk2/CryptoPkg/Library/BaseCryptLibOnProtocolPpi/PeiCryptLib.c new file mode 100644 index 000000000..4fd0e4d3b --- /dev/null +++ b/roms/edk2/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 +#include +#include +#include +#include + +/** + 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; +} -- cgit