75 UINTN PublicKeyBufferSize;
79 DEBUG ((DEBUG_INFO,
"FmpAuthenticatedHandlerRsa2048Sha256 - Image: 0x%08x - 0x%08x\n", (
UINTN)Image, (
UINTN)ImageSize));
87 if (!
CompareGuid (&CertBlockRsa2048Sha256->HashType, &gEfiHashAlgorithmSha256Guid)) {
88 DEBUG ((DEBUG_ERROR,
"FmpAuthenticatedHandlerRsa2048Sha256 - HashType: %g, expect - %g\n", &CertBlockRsa2048Sha256->HashType, &gEfiHashAlgorithmSha256Guid));
99 if (HashContext ==
NULL) {
100 CryptoStatus =
FALSE;
101 DEBUG ((DEBUG_ERROR,
"FmpAuthenticatedHandlerRsa2048Sha256: Can not allocate hash context\n"));
112 DEBUG ((DEBUG_ERROR,
"FmpAuthenticatedHandlerRsa2048Sha256: Sha256Init() failed\n"));
117 CryptoStatus =
Sha256Update (HashContext, &CertBlockRsa2048Sha256->PublicKey, sizeof (CertBlockRsa2048Sha256->PublicKey));
119 DEBUG ((DEBUG_ERROR,
"FmpAuthenticatedHandlerRsa2048Sha256: Sha256Update() failed\n"));
126 DEBUG ((DEBUG_ERROR,
"FmpAuthenticatedHandlerRsa2048Sha256: Sha256Final() failed\n"));
134 PublicKey = (VOID *)PublicKeyData;
135 PublicKeyBufferSize = PublicKeyDataLength;
136 CryptoStatus =
FALSE;
137 while (PublicKeyBufferSize != 0) {
148 DEBUG ((DEBUG_ERROR,
"FmpAuthenticatedHandlerRsa2048Sha256: Public key in section is not supported\n"));
158 CryptoStatus =
FALSE;
159 DEBUG ((DEBUG_ERROR,
"FmpAuthenticatedHandlerRsa2048Sha256: RsaNew() failed\n"));
168 CryptoStatus =
RsaSetKey (Rsa,
RsaKeyN, CertBlockRsa2048Sha256->PublicKey, sizeof (CertBlockRsa2048Sha256->PublicKey));
170 DEBUG ((DEBUG_ERROR,
"FmpAuthenticatedHandlerRsa2048Sha256: RsaSetKey(RsaKeyN) failed\n"));
177 DEBUG ((DEBUG_ERROR,
"FmpAuthenticatedHandlerRsa2048Sha256: RsaSetKey(RsaKeyE) failed\n"));
188 DEBUG ((DEBUG_ERROR,
"FmpAuthenticatedHandlerRsa2048Sha256: Sha256Init() failed\n"));
196 (UINT8 *)Image +
sizeof (Image->MonotonicCount) + Image->AuthInfo.Hdr.dwLength,
197 ImageSize - sizeof (Image->MonotonicCount) - Image->AuthInfo.Hdr.dwLength
200 DEBUG ((DEBUG_ERROR,
"FmpAuthenticatedHandlerRsa2048Sha256: Sha256Update() failed\n"));
207 (UINT8 *)&Image->MonotonicCount,
208 sizeof (Image->MonotonicCount)
211 DEBUG ((DEBUG_ERROR,
"FmpAuthenticatedHandlerRsa2048Sha256: Sha256Update() failed\n"));
218 DEBUG ((DEBUG_ERROR,
"FmpAuthenticatedHandlerRsa2048Sha256: Sha256Final() failed\n"));
230 CertBlockRsa2048Sha256->Signature,
231 sizeof (CertBlockRsa2048Sha256->Signature)
237 DEBUG ((DEBUG_ERROR,
"FmpAuthenticatedHandlerRsa2048Sha256: RsaPkcs1Verify() failed\n"));
242 DEBUG ((DEBUG_INFO,
"FmpAuthenticatedHandlerRsa2048Sha256: PASS verification\n"));
254 if (HashContext !=
NULL) {
308 if ((Image ==
NULL) || (ImageSize == 0)) {
313 DEBUG ((DEBUG_ERROR,
"PublicKeyDataLength is not multiple SHA256 size\n"));
318 DEBUG ((DEBUG_ERROR,
"AuthenticateFmpImage - ImageSize too small\n"));
323 DEBUG ((DEBUG_ERROR,
"AuthenticateFmpImage - dwLength too small\n"));
327 if ((
UINTN)Image->AuthInfo.Hdr.dwLength > MAX_UINTN - sizeof (UINT64)) {
328 DEBUG ((DEBUG_ERROR,
"AuthenticateFmpImage - dwLength too big\n"));
332 if (ImageSize <=
sizeof (Image->MonotonicCount) + Image->AuthInfo.Hdr.dwLength) {
333 DEBUG ((DEBUG_ERROR,
"AuthenticateFmpImage - ImageSize too small\n"));
337 if (Image->AuthInfo.Hdr.wRevision != 0x0200) {
338 DEBUG ((DEBUG_ERROR,
"AuthenticateFmpImage - wRevision: 0x%02x, expect - 0x%02x\n", (
UINTN)Image->AuthInfo.Hdr.wRevision, (
UINTN)0x0200));
342 if (Image->AuthInfo.Hdr.wCertificateType != WIN_CERT_TYPE_EFI_GUID) {
343 DEBUG ((DEBUG_ERROR,
"AuthenticateFmpImage - wCertificateType: 0x%02x, expect - 0x%02x\n", (
UINTN)Image->AuthInfo.Hdr.wCertificateType, (
UINTN)WIN_CERT_TYPE_EFI_GUID));
347 CertType = &Image->AuthInfo.CertType;
348 DEBUG ((DEBUG_INFO,
"AuthenticateFmpImage - CertType: %g\n", CertType));
350 if (
CompareGuid (&gEfiCertTypeRsa2048Sha256Guid, CertType)) {
@ 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)
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)
RETURN_STATUS EFIAPI AuthenticateFmpImage(IN EFI_FIRMWARE_IMAGE_AUTHENTICATION *Image, IN UINTN ImageSize, IN CONST UINT8 *PublicKeyData, IN UINTN PublicKeyDataLength)
RETURN_STATUS FmpAuthenticatedHandlerRsa2048Sha256(IN EFI_FIRMWARE_IMAGE_AUTHENTICATION *Image, IN UINTN ImageSize, IN CONST UINT8 *PublicKeyData, IN UINTN PublicKeyDataLength)
STATIC CONST UINT8 mRsaE[]
#define RETURN_UNSUPPORTED
#define RETURN_OUT_OF_RESOURCES
#define RETURN_SECURITY_VIOLATION
#define OFFSET_OF(TYPE, Field)
#define RETURN_INVALID_PARAMETER
#define DEBUG(Expression)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)