]> git.proxmox.com Git - mirror_edk2.git/blobdiff - FmpDevicePkg/FmpDxe/DetectTestKey.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / FmpDevicePkg / FmpDxe / DetectTestKey.c
index 6dedbdfaee28e0fbaf495736370b60c051bb801e..75dfce16bb208e3daab91746ad5bad51071d77cd 100644 (file)
@@ -1,36 +1,13 @@
 /** @file\r
   Detects if PcdFmpDevicePkcs7CertBufferXdr contains a test key.\r
 \r
-  Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>\r
-\r
-  Redistribution and use in source and binary forms, with or without\r
-  modification, are permitted provided that the following conditions are met:\r
-  1. Redistributions of source code must retain the above copyright notice,\r
-  this list of conditions and the following disclaimer.\r
-  2. Redistributions in binary form must reproduce the above copyright notice,\r
-  this list of conditions and the following disclaimer in the documentation\r
-  and/or other materials provided with the distribution.\r
-\r
-  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND\r
-  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
-  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
-  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\r
-  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
-  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
-  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\r
-  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE\r
-  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\r
-  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+  Copyright (c) 2018 - 2019, Intel Corporation. All rights reserved.<BR>\r
+\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
-#include <PiDxe.h>\r
-#include <Library/DebugLib.h>\r
-#include <Library/BaseLib.h>\r
-#include <Library/BaseMemoryLib.h>\r
-#include <Library/PcdLib.h>\r
-#include <Library/MemoryAllocationLib.h>\r
-#include <Library/BaseCryptLib.h>\r
+#include "FmpDxe.h"\r
 \r
 /**\r
   Check to see if any of the keys in PcdFmpDevicePkcs7CertBufferXdr matches\r
@@ -53,12 +30,14 @@ DetectTestKey (
   UINT8    *PublicKeyDataXdrEnd;\r
   VOID     *HashContext;\r
   UINT8    Digest[SHA256_DIGEST_SIZE];\r
+  UINTN    TestKeyDigestSize;\r
 \r
   //\r
-  // If PcdFmpDeviceTestKeySha256Digest is not exacty SHA256_DIGEST_SIZE bytes,\r
+  // If PcdFmpDeviceTestKeySha256Digest is not exactly SHA256_DIGEST_SIZE bytes,\r
   // then skip the test key detection.\r
   //\r
-  if (PcdGetSize (PcdFmpDeviceTestKeySha256Digest) != SHA256_DIGEST_SIZE) {\r
+  TestKeyDigestSize = PcdGetSize (PcdFmpDeviceTestKeySha256Digest);\r
+  if (TestKeyDigestSize != SHA256_DIGEST_SIZE) {\r
     return;\r
   }\r
 \r
@@ -75,7 +54,7 @@ DetectTestKey (
   //\r
   PublicKeyDataXdr    = PcdGetPtr (PcdFmpDevicePkcs7CertBufferXdr);\r
   PublicKeyDataXdrEnd = PublicKeyDataXdr + PcdGetSize (PcdFmpDevicePkcs7CertBufferXdr);\r
-  if (PublicKeyDataXdr == NULL || PublicKeyDataXdr == PublicKeyDataXdrEnd) {\r
+  if ((PublicKeyDataXdr == NULL) || (PublicKeyDataXdr == PublicKeyDataXdrEnd)) {\r
     return;\r
   }\r
 \r
@@ -97,6 +76,7 @@ DetectTestKey (
       //\r
       break;\r
     }\r
+\r
     //\r
     // Read key length stored in big endian format\r
     //\r
@@ -121,10 +101,12 @@ DetectTestKey (
       TestKeyUsed = TRUE;\r
       break;\r
     }\r
+\r
     if (!Sha256Update (HashContext, PublicKeyDataXdr, PublicKeyDataLength)) {\r
       TestKeyUsed = TRUE;\r
       break;\r
     }\r
+\r
     if (!Sha256Final (HashContext, Digest)) {\r
       TestKeyUsed = TRUE;\r
       break;\r
@@ -142,7 +124,7 @@ DetectTestKey (
     // Point to start of next key\r
     //\r
     PublicKeyDataXdr += PublicKeyDataLength;\r
-    PublicKeyDataXdr = (UINT8 *)ALIGN_POINTER (PublicKeyDataXdr, sizeof (UINT32));\r
+    PublicKeyDataXdr  = (UINT8 *)ALIGN_POINTER (PublicKeyDataXdr, sizeof (UINT32));\r
   }\r
 \r
   //\r
@@ -154,13 +136,13 @@ DetectTestKey (
   }\r
 \r
   //\r
-  // If test key detected or an error occured checking for the test key, then\r
+  // If test key detected or an error occurred checking for the test key, then\r
   // set PcdTestKeyUsed to TRUE.\r
   //\r
   if (TestKeyUsed) {\r
-    DEBUG ((DEBUG_INFO, "FmpDxe: Test key detected in PcdFmpDevicePkcs7CertBufferXdr.\n"));\r
+    DEBUG ((DEBUG_INFO, "FmpDxe(%s): Test key detected in PcdFmpDevicePkcs7CertBufferXdr.\n", mImageIdName));\r
     PcdSetBoolS (PcdTestKeyUsed, TRUE);\r
   } else {\r
-    DEBUG ((DEBUG_INFO, "FmpDxe: No test key detected in PcdFmpDevicePkcs7CertBufferXdr.\n"));\r
+    DEBUG ((DEBUG_INFO, "FmpDxe(%s): No test key detected in PcdFmpDevicePkcs7CertBufferXdr.\n", mImageIdName));\r
   }\r
 }\r