]> git.proxmox.com Git - mirror_edk2.git/commitdiff
CryptoPkg/BaseCryptLib: Add MARCO to disable the deprecated MD5
authorZhichao Gao <zhichao.gao@intel.com>
Mon, 15 Jun 2020 08:06:17 +0000 (16:06 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Mon, 29 Jun 2020 05:25:55 +0000 (05:25 +0000)
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1682

MD5 is deprecated but it is required for compatible issue.
So add a MARCO for the platform to disable the usage of MD5 for
security.

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Xiaoyu Lu <xiaoyux.lu@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Siyuan Fu <siyuan.fu@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Signed-off-by: Zhichao Gao <zhichao.gao@intel.com>
Reviewed-by: Jian J Wang <jian.j.wang@intel.com>
CryptoPkg/Driver/Crypto.c
CryptoPkg/Include/Library/BaseCryptLib.h
CryptoPkg/Library/BaseCryptLib/Hash/CryptMd5.c
CryptoPkg/Library/BaseCryptLibOnProtocolPpi/CryptLib.c

index 73ae56675548add2e26245c9ebfed08a3c78c07a..7e7e31a35e25b33fb3fcdcd4e19d278c36ee20ea 100644 (file)
@@ -243,6 +243,154 @@ DeprecatedCryptoServiceMd4HashAll (
   return BaseCryptLibServiceDeprecated ("Md4HashAll"), FALSE;\r
 }\r
 \r
+#ifdef DISABLE_MD5_DEPRECATED_INTERFACES\r
+/**\r
+  Retrieves the size, in bytes, of the context buffer required for MD5 hash operations.\r
+\r
+  If this interface is not supported, then return zero.\r
+\r
+  @retval  0   This interface is not supported.\r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+DeprecatedCryptoServiceMd5GetContextSize (\r
+  VOID\r
+  )\r
+{\r
+  return BaseCryptLibServiceDeprecated ("Md5GetContextSize"), 0;\r
+}\r
+\r
+/**\r
+  Initializes user-supplied memory pointed by Md5Context as MD5 hash context for\r
+  subsequent use.\r
+\r
+  If Md5Context is NULL, then return FALSE.\r
+  If this interface is not supported, then return FALSE.\r
+\r
+  @param[out]  Md5Context  Pointer to MD5 context being initialized.\r
+\r
+  @retval FALSE  This interface is not supported.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+DeprecatedCryptoServiceMd5Init (\r
+  OUT  VOID  *Md5Context\r
+  )\r
+{\r
+  return BaseCryptLibServiceDeprecated ("Md5Init"), FALSE;\r
+}\r
+\r
+/**\r
+  Makes a copy of an existing MD5 context.\r
+\r
+  If Md5Context is NULL, then return FALSE.\r
+  If NewMd5Context is NULL, then return FALSE.\r
+  If this interface is not supported, then return FALSE.\r
+\r
+  @param[in]  Md5Context     Pointer to MD5 context being copied.\r
+  @param[out] NewMd5Context  Pointer to new MD5 context.\r
+\r
+  @retval FALSE  This interface is not supported.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+DeprecatedCryptoServiceMd5Duplicate (\r
+  IN   CONST VOID  *Md5Context,\r
+  OUT  VOID        *NewMd5Context\r
+  )\r
+{\r
+  return BaseCryptLibServiceDeprecated ("Md5Init"), FALSE;\r
+}\r
+\r
+/**\r
+  Digests the input data and updates MD5 context.\r
+\r
+  This function performs MD5 digest on a data buffer of the specified size.\r
+  It can be called multiple times to compute the digest of long or discontinuous data streams.\r
+  MD5 context should be already correctly initialized by Md5Init(), and should not be finalized\r
+  by Md5Final(). Behavior with invalid context is undefined.\r
+\r
+  If Md5Context is NULL, then return FALSE.\r
+  If this interface is not supported, then return FALSE.\r
+\r
+  @param[in, out]  Md5Context  Pointer to the MD5 context.\r
+  @param[in]       Data        Pointer to the buffer containing the data to be hashed.\r
+  @param[in]       DataSize    Size of Data buffer in bytes.\r
+\r
+  @retval FALSE  This interface is not supported.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+DeprecatedCryptoServiceMd5Update (\r
+  IN OUT  VOID        *Md5Context,\r
+  IN      CONST VOID  *Data,\r
+  IN      UINTN       DataSize\r
+  )\r
+{\r
+  return BaseCryptLibServiceDeprecated ("Md5Init"), FALSE;\r
+}\r
+\r
+/**\r
+  Completes computation of the MD5 digest value.\r
+\r
+  This function completes MD5 hash computation and retrieves the digest value into\r
+  the specified memory. After this function has been called, the MD5 context cannot\r
+  be used again.\r
+  MD5 context should be already correctly initialized by Md5Init(), and should not be\r
+  finalized by Md5Final(). Behavior with invalid MD5 context is undefined.\r
+\r
+  If Md5Context is NULL, then return FALSE.\r
+  If HashValue is NULL, then return FALSE.\r
+  If this interface is not supported, then return FALSE.\r
+\r
+  @param[in, out]  Md5Context  Pointer to the MD5 context.\r
+  @param[out]      HashValue   Pointer to a buffer that receives the MD5 digest\r
+                               value (16 bytes).\r
+\r
+  @retval FALSE  This interface is not supported.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+DeprecatedCryptoServiceMd5Final (\r
+  IN OUT  VOID   *Md5Context,\r
+  OUT     UINT8  *HashValue\r
+  )\r
+{\r
+  return BaseCryptLibServiceDeprecated ("Md5Final"), FALSE;\r
+}\r
+\r
+/**\r
+  Computes the MD5 message digest of a input data buffer.\r
+\r
+  This function performs the MD5 message digest of a given data buffer, and places\r
+  the digest value into the specified memory.\r
+\r
+  If this interface is not supported, then return FALSE.\r
+\r
+  @param[in]   Data        Pointer to the buffer containing the data to be hashed.\r
+  @param[in]   DataSize    Size of Data buffer in bytes.\r
+  @param[out]  HashValue   Pointer to a buffer that receives the MD5 digest\r
+                           value (16 bytes).\r
+\r
+  @retval FALSE  This interface is not supported.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+DeprecatedCryptoServiceMd5HashAll (\r
+  IN   CONST VOID  *Data,\r
+  IN   UINTN       DataSize,\r
+  OUT  UINT8       *HashValue\r
+  )\r
+{\r
+  return BaseCryptLibServiceDeprecated ("Md5HashAll"), FALSE;\r
+}\r
+#else\r
 /**\r
   Retrieves the size, in bytes, of the context buffer required for MD5 hash operations.\r
 \r
@@ -400,6 +548,7 @@ CryptoServiceMd5HashAll (
 {\r
   return CALL_BASECRYPTLIB (Md5.Services.HashAll, Md5HashAll, (Data, DataSize, HashValue), FALSE);\r
 }\r
+#endif\r
 \r
 /**\r
   Retrieves the size, in bytes, of the context buffer required for SHA-1 hash operations.\r
@@ -4194,6 +4343,15 @@ const EDKII_CRYPTO_PROTOCOL mEdkiiCrypto = {
   DeprecatedCryptoServiceMd4Update,\r
   DeprecatedCryptoServiceMd4Final,\r
   DeprecatedCryptoServiceMd4HashAll,\r
+#ifdef DISABLE_MD5_DEPRECATED_INTERFACES\r
+  /// Md5 - deprecated and unsupported\r
+  DeprecatedCryptoServiceMd5GetContextSize,\r
+  DeprecatedCryptoServiceMd5Init,\r
+  DeprecatedCryptoServiceMd5Duplicate,\r
+  DeprecatedCryptoServiceMd5Update,\r
+  DeprecatedCryptoServiceMd5Final,\r
+  DeprecatedCryptoServiceMd5HashAll,\r
+#else\r
   /// Md5\r
   CryptoServiceMd5GetContextSize,\r
   CryptoServiceMd5Init,\r
@@ -4201,6 +4359,7 @@ const EDKII_CRYPTO_PROTOCOL mEdkiiCrypto = {
   CryptoServiceMd5Update,\r
   CryptoServiceMd5Final,\r
   CryptoServiceMd5HashAll,\r
+#endif\r
   /// Pkcs\r
   CryptoServicePkcs1v2Encrypt,\r
   CryptoServicePkcs5HashPassword,\r
index 1b1ffa75ef5e1b8605d2e7c3699465f9eaedb07f..36483d1d2d615278e39db42301ff9f2a0089b856 100644 (file)
@@ -72,6 +72,7 @@ typedef enum {
 //    One-Way Cryptographic Hash Primitives\r
 //=====================================================================================\r
 \r
+#ifndef DISABLE_MD5_DEPRECATED_INTERFACES\r
 /**\r
   Retrieves the size, in bytes, of the context buffer required for MD5 hash operations.\r
 \r
@@ -211,6 +212,7 @@ Md5HashAll (
   IN   UINTN       DataSize,\r
   OUT  UINT8       *HashValue\r
   );\r
+#endif\r
 \r
 /**\r
   Retrieves the size, in bytes, of the context buffer required for SHA-1 hash operations.\r
index 0e0d0ec54d2d48827bd22c590d5210aeefbd0474..b85e7f4d12acbc57661d021110cc72a85bd4cf27 100644 (file)
@@ -9,7 +9,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 #include "InternalCryptLib.h"\r
 #include <openssl/md5.h>\r
 \r
-\r
+#ifndef DISABLE_MD5_DEPRECATED_INTERFACES\r
 /**\r
   Retrieves the size, in bytes, of the context buffer required for MD5 hash operations.\r
 \r
@@ -223,3 +223,4 @@ Md5HashAll (
     return TRUE;\r
   }\r
 }\r
+#endif\r
index a614b61ed48e2a2efe35efb3761c7f69c9e1bfef..8897fd25e6caad718d3963a364eded8b18a20de5 100644 (file)
@@ -99,6 +99,7 @@ CryptoServiceNotAvailable (
 //    One-Way Cryptographic Hash Primitives\r
 //=====================================================================================\r
 \r
+#ifndef DISABLE_MD5_DEPRECATED_INTERFACES\r
 /**\r
   Retrieves the size, in bytes, of the context buffer required for MD5 hash operations.\r
 \r
@@ -256,6 +257,7 @@ Md5HashAll (
 {\r
   CALL_CRYPTO_SERVICE (Md5HashAll, (Data, DataSize, HashValue), FALSE);\r
 }\r
+#endif\r
 \r
 /**\r
   Retrieves the size, in bytes, of the context buffer required for SHA-1 hash operations.\r