62 OUT UINT32 *OutputBufferSize,
63 OUT UINT32 *ScratchBufferSize,
64 OUT UINT16 *SectionAttribute
67 if (IS_SECTION2 (InputSection)) {
72 &gEfiCertTypeRsa2048Sha256Guid,
76 return EFI_INVALID_PARAMETER;
83 *ScratchBufferSize = 0;
90 &gEfiCertTypeRsa2048Sha256Guid,
94 return EFI_INVALID_PARAMETER;
101 *ScratchBufferSize = 0;
129 OUT VOID **OutputBuffer,
130 IN VOID *ScratchBuffer OPTIONAL,
131 OUT UINT32 *AuthenticationStatus
135 UINT32 OutputBufferSize;
137 BOOLEAN CryptoStatus;
140 UINTN PublicKeyBufferSize;
147 if (IS_SECTION2 (InputSection)) {
152 &gEfiCertTypeRsa2048Sha256Guid,
156 return EFI_INVALID_PARAMETER;
176 *AuthenticationStatus = EFI_AUTH_STATUS_IMAGE_SIGNED;
182 &gEfiCertTypeRsa2048Sha256Guid,
186 return EFI_INVALID_PARAMETER;
206 *AuthenticationStatus = EFI_AUTH_STATUS_IMAGE_SIGNED;
217 if (!
CompareGuid (&gEfiHashAlgorithmSha256Guid, &CertBlockRsa2048Sha256->HashType)) {
218 DEBUG ((DEBUG_ERROR,
"PeiRsa2048Sha256: HASH type of section is not supported\n"));
219 *AuthenticationStatus |= EFI_AUTH_STATUS_TEST_FAILED;
227 if (HashContext ==
NULL) {
228 DEBUG ((DEBUG_ERROR,
"PeiRsa2048Sha256: Can not allocate hash context\n"));
229 *AuthenticationStatus |= EFI_AUTH_STATUS_TEST_FAILED;
239 DEBUG ((DEBUG_ERROR,
"PeiRsa2048Sha256: Sha256Init() failed\n"));
240 *AuthenticationStatus |= EFI_AUTH_STATUS_TEST_FAILED;
244 CryptoStatus =
Sha256Update (HashContext, &CertBlockRsa2048Sha256->PublicKey, sizeof (CertBlockRsa2048Sha256->PublicKey));
246 DEBUG ((DEBUG_ERROR,
"PeiRsa2048Sha256: Sha256Update() failed\n"));
247 *AuthenticationStatus |= EFI_AUTH_STATUS_TEST_FAILED;
253 DEBUG ((DEBUG_ERROR,
"PeiRsa2048Sha256: Sha256Final() failed\n"));
254 *AuthenticationStatus |= EFI_AUTH_STATUS_TEST_FAILED;
261 PublicKey = (UINT8 *)
PcdGetPtr (PcdRsa2048Sha256PublicKeyBuffer);
262 DEBUG ((DEBUG_VERBOSE,
"PeiPcdRsa2048Sha256: PublicKeyBuffer = %p\n", PublicKey));
263 ASSERT (PublicKey !=
NULL);
264 DEBUG ((DEBUG_VERBOSE,
"PeiPcdRsa2048Sha256: PublicKeyBuffer Token = %08x\n",
PcdToken (PcdRsa2048Sha256PublicKeyBuffer)));
265 PublicKeyBufferSize =
PcdGetSize (PcdRsa2048Sha256PublicKeyBuffer);
266 DEBUG ((DEBUG_VERBOSE,
"PeiPcdRsa2048Sha256: PublicKeyBuffer Size = %08x\n", PublicKeyBufferSize));
268 CryptoStatus =
FALSE;
269 while (PublicKeyBufferSize != 0) {
280 DEBUG ((DEBUG_ERROR,
"PeiRsa2048Sha256: Public key in section is not supported\n"));
281 *AuthenticationStatus |= EFI_AUTH_STATUS_TEST_FAILED;
290 DEBUG ((DEBUG_ERROR,
"PeiRsa2048Sha256: RsaNew() failed\n"));
291 *AuthenticationStatus |= EFI_AUTH_STATUS_TEST_FAILED;
299 CryptoStatus =
RsaSetKey (Rsa,
RsaKeyN, CertBlockRsa2048Sha256->PublicKey, sizeof (CertBlockRsa2048Sha256->PublicKey));
301 DEBUG ((DEBUG_ERROR,
"PeiRsa2048Sha256: RsaSetKey(RsaKeyN) failed\n"));
302 *AuthenticationStatus |= EFI_AUTH_STATUS_TEST_FAILED;
308 DEBUG ((DEBUG_ERROR,
"PeiRsa2048Sha256: RsaSetKey(RsaKeyE) failed\n"));
309 *AuthenticationStatus |= EFI_AUTH_STATUS_TEST_FAILED;
319 DEBUG ((DEBUG_ERROR,
"PeiRsa2048Sha256: Sha256Init() failed\n"));
320 *AuthenticationStatus |= EFI_AUTH_STATUS_TEST_FAILED;
325 CryptoStatus =
Sha256Update (HashContext, *OutputBuffer, OutputBufferSize);
328 DEBUG ((DEBUG_ERROR,
"PeiRsa2048Sha256: Sha256Update() failed\n"));
329 *AuthenticationStatus |= EFI_AUTH_STATUS_TEST_FAILED;
335 DEBUG ((DEBUG_ERROR,
"PeiRsa2048Sha256: Sha256Final() failed\n"));
336 *AuthenticationStatus |= EFI_AUTH_STATUS_TEST_FAILED;
348 CertBlockRsa2048Sha256->Signature,
349 sizeof (CertBlockRsa2048Sha256->Signature)
356 DEBUG ((DEBUG_ERROR,
"PeiRsa2048Sha256: RsaPkcs1Verify() failed\n"));
357 *AuthenticationStatus |= EFI_AUTH_STATUS_TEST_FAILED;
368 if (HashContext !=
NULL) {
372 DEBUG ((DEBUG_VERBOSE,
"PeiRsa2048Sha256: Status = %r AuthenticationStatus = %08x\n", Status, *AuthenticationStatus));
395 &gEfiCertTypeRsa2048Sha256Guid,
@ RsaKeyN
RSA public Modulus (N)
@ RsaKeyE
RSA Public exponent (e)
UINTN EFIAPI Sha256GetContextSize(VOID)
VOID *EFIAPI RsaNew(VOID)
BOOLEAN EFIAPI Sha256Init(OUT VOID *Sha256Context)
BOOLEAN EFIAPI Sha256Final(IN OUT VOID *Sha256Context, OUT UINT8 *HashValue)
#define SHA256_DIGEST_SIZE
BOOLEAN EFIAPI RsaSetKey(IN OUT VOID *RsaContext, IN RSA_KEY_TAG KeyTag, IN CONST UINT8 *BigNumber, IN UINTN BnSize)
BOOLEAN EFIAPI Sha256Update(IN OUT VOID *Sha256Context, IN CONST VOID *Data, IN UINTN DataSize)
VOID EFIAPI RsaFree(IN VOID *RsaContext)
BOOLEAN EFIAPI RsaPkcs1Verify(IN VOID *RsaContext, IN CONST UINT8 *MessageHash, IN UINTN HashSize, IN CONST UINT8 *Signature, IN UINTN SigSize)
INTN EFIAPI CompareMem(IN CONST VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
VOID EFIAPI FreePool(IN VOID *Buffer)
#define DEBUG(Expression)
#define PcdGetSize(TokenName)
#define PcdToken(TokenName)
#define PcdGetPtr(TokenName)
#define EFI_GUIDED_SECTION_PROCESSING_REQUIRED
#define SECTION_SIZE(SectionHeaderPtr)
VOID * EFI_PEI_FILE_HANDLE
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)