]> git.proxmox.com Git - mirror_edk2.git/blobdiff - CryptoPkg/Library/BaseCryptLib/Hmac/CryptHmacSha1.c
CryptoPkg: Fix typos in comments
[mirror_edk2.git] / CryptoPkg / Library / BaseCryptLib / Hmac / CryptHmacSha1.c
index 0298b80cc582e33f41f8a95ac40bc11ea137bfa5..e6602586acd0d3e358124cf28ef1b8ce92e347be 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
@@ -30,14 +30,14 @@ HmacSha1GetContextSize (
   //\r
   // Retrieves the OpenSSL HMAC-SHA1 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 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 || KeySize > INT_MAX) {\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
@@ -89,6 +91,13 @@ HmacSha1Duplicate (
   OUT  VOID        *NewHmacSha1Context\r
   )\r
 {\r
+  //\r
+  // Check input parameters.\r
+  //\r
+  if (HmacSha1Context == NULL || NewHmacSha1Context == NULL) {\r
+    return FALSE;\r
+  }\r
+\r
   CopyMem (NewHmacSha1Context, HmacSha1Context, sizeof (HMAC_CTX));\r
 \r
   return TRUE;\r
@@ -99,10 +108,10 @@ HmacSha1Duplicate (
 \r
   This function performs HMAC-SHA1 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-SHA1 context should be already correctly intialized by HmacSha1Init(), and should not\r
+  HMAC-SHA1 context should be already correctly initialized 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
@@ -121,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
@@ -146,11 +157,11 @@ HmacSha1Update (
   This function completes HMAC-SHA1 digest computation and retrieves the digest value into\r
   the specified memory. After this function has been called, the HMAC-SHA1 context cannot\r
   be used again.\r
-  HMAC-SHA1 context should be already correctly intialized by HmacSha1Init(), and should\r
+  HMAC-SHA1 context should be already correctly initialized 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
@@ -170,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