File: PeiCryptLib.c

package info (click to toggle)
edk2 2025.11-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 338,436 kB
  • sloc: ansic: 2,166,377; asm: 270,725; perl: 235,301; python: 149,900; sh: 34,744; cpp: 23,311; makefile: 3,334; pascal: 1,602; xml: 806; lisp: 35; ruby: 16; sed: 6; tcl: 4
file content (57 lines) | stat: -rw-r--r-- 1,710 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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;
}