/** @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
//\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
)\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
/**\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
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
\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
)\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
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
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