]> git.proxmox.com Git - mirror_edk2.git/blobdiff - CryptoPkg/Library/BaseCryptLib/Hmac/CryptHmacSha1.c
1. Remove conducting ASSERT in BaseCryptLib.
[mirror_edk2.git] / CryptoPkg / Library / BaseCryptLib / Hmac / CryptHmacSha1.c
index ff9377c0d2f165c0b19f29f74da5b853dda01c56..58da2f3aecd5eb95cdd7817860d16a979d5e224e 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   HMAC-SHA1 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
@@ -37,7 +37,7 @@ HmacSha1GetContextSize (
   Initializes user-supplied memory pointed by HmacSha1Context as HMAC-SHA1 context for\r
   subsequent use.\r
 \r
-  If HmacSha1Context is NULL, then ASSERT().\r
+  If HmacSha1Context is NULL, then return FALSE.\r
 \r
   @param[out]  HmacSha1Context  Pointer to HMAC-SHA1 context being initialized.\r
   @param[in]   Key              Pointer to the user-supplied key.\r
@@ -56,9 +56,11 @@ HmacSha1Init (
   )\r
 {\r
   //\r
-  // ASSERT if HmacSha1Context is NULL.\r
+  // Check input parameters.\r
   //\r
-  ASSERT (HmacSha1Context != NULL);\r
+  if (HmacSha1Context == NULL) {\r
+    return FALSE;\r
+  }\r
 \r
   //\r
   // OpenSSL HMAC-SHA1 Context Initialization\r
@@ -72,8 +74,8 @@ HmacSha1Init (
 /**\r
   Makes a copy of an existing HMAC-SHA1 context.\r
 \r
-  If HmacSha1Context is NULL, then ASSERT().\r
-  If NewHmacSha1Context is NULL, then ASSERT().\r
+  If HmacSha1Context is NULL, then return FALSE.\r
+  If NewHmacSha1Context is NULL, then return FALSE.\r
 \r
   @param[in]  HmacSha1Context     Pointer to HMAC-SHA1 context being copied.\r
   @param[out] NewHmacSha1Context  Pointer to new HMAC-SHA1 context.\r
@@ -90,10 +92,11 @@ HmacSha1Duplicate (
   )\r
 {\r
   //\r
-  // ASSERT if HmacSha1Context or NewHmacSha1Context is NULL.\r
+  // Check input parameters.\r
   //\r
-  ASSERT (HmacSha1Context    != NULL);\r
-  ASSERT (NewHmacSha1Context != NULL);\r
+  if (HmacSha1Context == NULL || NewHmacSha1Context == NULL) {\r
+    return FALSE;\r
+  }\r
 \r
   CopyMem (NewHmacSha1Context, HmacSha1Context, sizeof (HMAC_CTX));\r
 \r
@@ -108,7 +111,7 @@ HmacSha1Duplicate (
   HMAC-SHA1 context should be already correctly intialized by HmacSha1Init(), and should not\r
   be finalized by HmacSha1Final(). Behavior with invalid context is undefined.\r
 \r
-  If HmacSha1Context is NULL, then ASSERT().\r
+  If HmacSha1Context is NULL, then return FALSE.\r
 \r
   @param[in, out]  HmacSha1Context Pointer to the HMAC-SHA1 context.\r
   @param[in]       Data            Pointer to the buffer containing the data to be digested.\r
@@ -127,15 +130,17 @@ HmacSha1Update (
   )\r
 {\r
   //\r
-  // ASSERT if HmacSha1Context is NULL\r
+  // Check input parameters.\r
   //\r
-  ASSERT (HmacSha1Context != NULL);\r
+  if (HmacSha1Context == 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
@@ -155,8 +160,8 @@ HmacSha1Update (
   HMAC-SHA1 context should be already correctly intialized by HmacSha1Init(), and should\r
   not be finalized by HmacSha1Final(). Behavior with invalid HMAC-SHA1 context is undefined.\r
 \r
-  If HmacSha1Context is NULL, then ASSERT().\r
-  If HmacValue is NULL, then ASSERT().\r
+  If HmacSha1Context is NULL, then return FALSE.\r
+  If HmacValue is NULL, then return FALSE.\r
 \r
   @param[in, out]  HmacSha1Context  Pointer to the HMAC-SHA1 context.\r
   @param[out]      HmacValue        Pointer to a buffer that receives the HMAC-SHA1 digest\r
@@ -176,10 +181,11 @@ HmacSha1Final (
   UINT32  Length;\r
 \r
   //\r
-  // ASSERT if HmacSha1Context is NULL or HmacValue is NULL\r
+  // Check input parameters.\r
   //\r
-  ASSERT (HmacSha1Context != NULL);\r
-  ASSERT (HmacValue != NULL);\r
+  if (HmacSha1Context == NULL || HmacValue == NULL) {\r
+    return FALSE;\r
+  }\r
 \r
   //\r
   // OpenSSL HMAC-SHA1 digest finalization\r