]> git.proxmox.com Git - mirror_edk2.git/blobdiff - CryptoPkg/Library/BaseCryptLib/Hmac/CryptHmacMd5.c
CryptoPkg/BaseCryptLib: Make comments consistent with the function
[mirror_edk2.git] / CryptoPkg / Library / BaseCryptLib / Hmac / CryptHmacMd5.c
index 5386072c388eed9824fce4dee96b47239c3cdcd9..61750616c8638eb02550c78632a291b2ae99a1ee 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   HMAC-MD5 Wrapper Implementation over OpenSSL.\r
 \r
-Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -30,14 +30,14 @@ HmacMd5GetContextSize (
   //\r
   // Retrieves the OpenSSL HMAC-MD5 Context Size\r
   //\r
-  return (UINTN)(sizeof (HMAC_CTX));\r
+  return (UINTN) (sizeof (HMAC_CTX));\r
 }\r
 \r
 /**\r
   Initializes user-supplied memory pointed by HmacMd5Context as HMAC-MD5 context for\r
   subsequent use.\r
 \r
-  If HmacMd5Context is NULL, then ASSERT().\r
+  If HmacMd5Context is NULL, then return FALSE.\r
 \r
   @param[out]  HmacMd5Context  Pointer to HMAC-MD5 context being initialized.\r
   @param[in]   Key             Pointer to the user-supplied key.\r
@@ -56,9 +56,11 @@ HmacMd5Init (
   )\r
 {\r
   //\r
-  // ASSERT if HmacMd5Context is NULL.\r
+  // Check input parameters.\r
   //\r
-  ASSERT (HmacMd5Context != NULL);\r
+  if (HmacMd5Context == NULL || KeySize > INT_MAX) {\r
+    return FALSE;\r
+  }\r
 \r
   //\r
   // OpenSSL HMAC-MD5 Context Initialization\r
@@ -72,8 +74,8 @@ HmacMd5Init (
 /**\r
   Makes a copy of an existing HMAC-MD5 context.\r
 \r
-  If HmacMd5Context is NULL, then ASSERT().\r
-  If NewHmacMd5Context is NULL, then ASSERT().\r
+  If HmacMd5Context is NULL, then return FALSE.\r
+  If NewHmacMd5Context is NULL, then return FALSE.\r
 \r
   @param[in]  HmacMd5Context     Pointer to HMAC-MD5 context being copied.\r
   @param[out] NewHmacMd5Context  Pointer to new HMAC-MD5 context.\r
@@ -90,10 +92,11 @@ HmacMd5Duplicate (
   )\r
 {\r
   //\r
-  // ASSERT if HmacMd5Context or NewHmacMd5Context is NULL.\r
+  // Check input parameters.\r
   //\r
-  ASSERT (HmacMd5Context    != NULL);\r
-  ASSERT (NewHmacMd5Context != NULL);\r
+  if (HmacMd5Context == NULL || NewHmacMd5Context == NULL) {\r
+    return FALSE;\r
+  }\r
   \r
   CopyMem (NewHmacMd5Context, HmacMd5Context, sizeof (HMAC_CTX));\r
 \r
@@ -105,10 +108,10 @@ HmacMd5Duplicate (
 \r
   This function performs HMAC-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
-  HMAC-MD5 context should be already correctly intialized by HmacMd5Init(), and should not be\r
+  HMAC-MD5 context should be already correctly initialized by HmacMd5Init(), and should not be\r
   finalized by HmacMd5Final(). Behavior with invalid context is undefined.\r
 \r
-  If HmacMd5Context is NULL, then ASSERT().\r
+  If HmacMd5Context is NULL, then return FALSE.\r
 \r
   @param[in, out]  HmacMd5Context  Pointer to the HMAC-MD5 context.\r
   @param[in]       Data            Pointer to the buffer containing the data to be digested.\r
@@ -127,15 +130,17 @@ HmacMd5Update (
   )\r
 {\r
   //\r
-  // ASSERT if HmacMd5Context is NULL\r
+  // Check input parameters.\r
   //\r
-  ASSERT (HmacMd5Context != NULL);\r
+  if (HmacMd5Context == NULL) {\r
+    return FALSE;\r
+  }\r
 \r
   //\r
-  // ASSERT if invalid parameters, in case that only DataLength was checked in OpenSSL\r
+  // Check invalid parameters, in case that only DataLength was checked in OpenSSL\r
   //\r
-  if (Data == NULL) {\r
-    ASSERT (DataSize == 0);\r
+  if (Data == NULL && DataSize != 0) {\r
+    return FALSE;\r
   }\r
 \r
   //\r
@@ -152,11 +157,11 @@ HmacMd5Update (
   This function completes HMAC-MD5 digest computation and retrieves the digest value into\r
   the specified memory. After this function has been called, the HMAC-MD5 context cannot\r
   be used again.\r
-  HMAC-MD5 context should be already correctly intialized by HmacMd5Init(), and should not be\r
+  HMAC-MD5 context should be already correctly initialized by HmacMd5Init(), and should not be\r
   finalized by HmacMd5Final(). Behavior with invalid HMAC-MD5 context is undefined.\r
 \r
-  If HmacMd5Context is NULL, then ASSERT().\r
-  If HmacValue is NULL, then ASSERT().\r
+  If HmacMd5Context is NULL, then return FALSE.\r
+  If HmacValue is NULL, then return FALSE.\r
 \r
   @param[in, out]  HmacMd5Context  Pointer to the HMAC-MD5 context.\r
   @param[out]      HmacValue       Pointer to a buffer that receives the HMAC-MD5 digest\r
@@ -176,10 +181,11 @@ HmacMd5Final (
   UINT32  Length;\r
 \r
   //\r
-  // ASSERT if HmacMd5Context is NULL or HmacValue is NULL\r
+  // Check input parameters.\r
   //\r
-  ASSERT (HmacMd5Context != NULL);\r
-  ASSERT (HmacValue != NULL);\r
+  if (HmacMd5Context == NULL || HmacValue == NULL) {\r
+    return FALSE;\r
+  }\r
 \r
   //\r
   // OpenSSL HMAC-MD5 digest finalization\r