64 OUT UINT32 *OutputBufferSize,
65 OUT UINT32 *ScratchBufferSize,
66 OUT UINT16 *SectionAttribute
69 if (IS_SECTION2 (InputSection)) {
74 &gEfiCertTypeRsa2048Sha256Guid,
78 return EFI_INVALID_PARAMETER;
85 *ScratchBufferSize = 0;
92 &gEfiCertTypeRsa2048Sha256Guid,
96 return EFI_INVALID_PARAMETER;
103 *ScratchBufferSize = 0;
131 OUT VOID **OutputBuffer,
132 IN VOID *ScratchBuffer OPTIONAL,
133 OUT UINT32 *AuthenticationStatus
137 UINT32 OutputBufferSize;
138 VOID *DummyInterface;
140 BOOLEAN CryptoStatus;
143 UINTN PublicKeyBufferSize;
150 if (IS_SECTION2 (InputSection)) {
155 &gEfiCertTypeRsa2048Sha256Guid,
159 return EFI_INVALID_PARAMETER;
179 *AuthenticationStatus = EFI_AUTH_STATUS_IMAGE_SIGNED;
185 &gEfiCertTypeRsa2048Sha256Guid,
189 return EFI_INVALID_PARAMETER;
209 *AuthenticationStatus = EFI_AUTH_STATUS_IMAGE_SIGNED;
215 Status =
gBS->LocateProtocol (&gEfiSecurityPolicyProtocolGuid,
NULL, &DummyInterface);
216 if (!EFI_ERROR (Status)) {
233 if (!
CompareGuid (&gEfiHashAlgorithmSha256Guid, &CertBlockRsa2048Sha256->HashType)) {
234 DEBUG ((DEBUG_ERROR,
"DxeRsa2048Sha256: HASH type of section is not supported\n"));
235 *AuthenticationStatus |= EFI_AUTH_STATUS_TEST_FAILED;
243 if (HashContext ==
NULL) {
244 DEBUG ((DEBUG_ERROR,
"DxeRsa2048Sha256: Can not allocate hash context\n"));
245 *AuthenticationStatus |= EFI_AUTH_STATUS_TEST_FAILED;
255 DEBUG ((DEBUG_ERROR,
"DxeRsa2048Sha256: Sha256Init() failed\n"));
256 *AuthenticationStatus |= EFI_AUTH_STATUS_TEST_FAILED;
260 CryptoStatus =
Sha256Update (HashContext, &CertBlockRsa2048Sha256->PublicKey, sizeof (CertBlockRsa2048Sha256->PublicKey));
262 DEBUG ((DEBUG_ERROR,
"DxeRsa2048Sha256: Sha256Update() failed\n"));
263 *AuthenticationStatus |= EFI_AUTH_STATUS_TEST_FAILED;
269 DEBUG ((DEBUG_ERROR,
"DxeRsa2048Sha256: Sha256Final() failed\n"));
270 *AuthenticationStatus |= EFI_AUTH_STATUS_TEST_FAILED;
277 PublicKey = (UINT8 *)
PcdGetPtr (PcdRsa2048Sha256PublicKeyBuffer);
278 DEBUG ((DEBUG_VERBOSE,
"DxePcdRsa2048Sha256: PublicKeyBuffer = %p\n", PublicKey));
279 ASSERT (PublicKey !=
NULL);
280 DEBUG ((DEBUG_VERBOSE,
"DxePcdRsa2048Sha256: PublicKeyBuffer Token = %08x\n",
PcdToken (PcdRsa2048Sha256PublicKeyBuffer)));
281 PublicKeyBufferSize =
PcdGetSize (PcdRsa2048Sha256PublicKeyBuffer);
282 DEBUG ((DEBUG_VERBOSE,
"DxePcdRsa2048Sha256: PublicKeyBuffer Size = %08x\n", PublicKeyBufferSize));
284 CryptoStatus =
FALSE;
285 while (PublicKeyBufferSize != 0) {
296 DEBUG ((DEBUG_ERROR,
"DxeRsa2048Sha256: Public key in section is not supported\n"));
297 *AuthenticationStatus |= EFI_AUTH_STATUS_TEST_FAILED;
306 DEBUG ((DEBUG_ERROR,
"DxeRsa2048Sha256: RsaNew() failed\n"));
307 *AuthenticationStatus |= EFI_AUTH_STATUS_TEST_FAILED;
315 CryptoStatus =
RsaSetKey (Rsa,
RsaKeyN, CertBlockRsa2048Sha256->PublicKey, sizeof (CertBlockRsa2048Sha256->PublicKey));
317 DEBUG ((DEBUG_ERROR,
"DxeRsa2048Sha256: RsaSetKey(RsaKeyN) failed\n"));
318 *AuthenticationStatus |= EFI_AUTH_STATUS_TEST_FAILED;
324 DEBUG ((DEBUG_ERROR,
"DxeRsa2048Sha256: RsaSetKey(RsaKeyE) failed\n"));
325 *AuthenticationStatus |= EFI_AUTH_STATUS_TEST_FAILED;
335 DEBUG ((DEBUG_ERROR,
"DxeRsa2048Sha256: Sha256Init() failed\n"));
336 *AuthenticationStatus |= EFI_AUTH_STATUS_TEST_FAILED;
341 CryptoStatus =
Sha256Update (HashContext, *OutputBuffer, OutputBufferSize);
344 DEBUG ((DEBUG_ERROR,
"DxeRsa2048Sha256: Sha256Update() failed\n"));
345 *AuthenticationStatus |= EFI_AUTH_STATUS_TEST_FAILED;
351 DEBUG ((DEBUG_ERROR,
"DxeRsa2048Sha256: Sha256Final() failed\n"));
352 *AuthenticationStatus |= EFI_AUTH_STATUS_TEST_FAILED;
364 CertBlockRsa2048Sha256->Signature,
365 sizeof (CertBlockRsa2048Sha256->Signature)
372 DEBUG ((DEBUG_ERROR,
"DxeRsa2048Sha256: RsaPkcs1Verify() failed\n"));
373 *AuthenticationStatus |= EFI_AUTH_STATUS_TEST_FAILED;
384 if (HashContext !=
NULL) {
388 DEBUG ((DEBUG_VERBOSE,
"DxeRsa2048Sha256: Status = %r AuthenticationStatus = %08x\n", Status, *AuthenticationStatus));
410 &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)
#define EFI_AUTH_STATUS_PLATFORM_OVERRIDE
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
EFI_CERT_BLOCK_RSA_2048_SHA256 CertBlockRsa2048Sha256
RSA 2048-bit Signature.
EFI_GUID_DEFINED_SECTION2 GuidedSectionHeader
EFI guided section header.
EFI_GUID_DEFINED_SECTION GuidedSectionHeader
EFI guided section header.
EFI_CERT_BLOCK_RSA_2048_SHA256 CertBlockRsa2048Sha256
RSA 2048-bit Signature.