]> git.proxmox.com Git - mirror_edk2.git/blobdiff - CryptoPkg/Library/BaseCryptLib/Hash/CryptSha512.c
CryptoPkg: Apply uncrustify changes
[mirror_edk2.git] / CryptoPkg / Library / BaseCryptLib / Hash / CryptSha512.c
index 491f45dce62384c063c296340335ca159230e831..59e5708465880969dff81cf2670eee277e1f9194 100644 (file)
@@ -1,14 +1,8 @@
 /** @file\r
   SHA-384 and SHA-512 Digest Wrapper Implementations over OpenSSL.\r
 \r
-Copyright (c) 2014, 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
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+Copyright (c) 2014 - 2016, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -30,7 +24,7 @@ Sha384GetContextSize (
   //\r
   // Retrieves OpenSSL SHA-384 Context Size\r
   //\r
-  return (UINTN) (sizeof (SHA512_CTX));\r
+  return (UINTN)(sizeof (SHA512_CTX));\r
 }\r
 \r
 /**\r
@@ -61,7 +55,7 @@ Sha384Init (
   //\r
   // OpenSSL SHA-384 Context Initialization\r
   //\r
-  return (BOOLEAN) (SHA384_Init ((SHA512_CTX *) Sha384Context));\r
+  return (BOOLEAN)(SHA384_Init ((SHA512_CTX *)Sha384Context));\r
 }\r
 \r
 /**\r
@@ -89,7 +83,7 @@ Sha384Duplicate (
   //\r
   // Check input parameters.\r
   //\r
-  if (Sha384Context == NULL || NewSha384Context == NULL) {\r
+  if ((Sha384Context == NULL) || (NewSha384Context == NULL)) {\r
     return FALSE;\r
   }\r
 \r
@@ -103,7 +97,7 @@ Sha384Duplicate (
 \r
   This function performs SHA-384 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
-  SHA-384 context should be already correctly intialized by Sha384Init(), and should not be finalized\r
+  SHA-384 context should be already correctly initialized by Sha384Init(), and should not be finalized\r
   by Sha384Final(). Behavior with invalid context is undefined.\r
 \r
   If Sha384Context is NULL, then return FALSE.\r
@@ -134,14 +128,14 @@ Sha384Update (
   //\r
   // Check invalid parameters, in case that only DataLength was checked in OpenSSL\r
   //\r
-  if (Data == NULL && DataSize != 0) {\r
+  if ((Data == NULL) && (DataSize != 0)) {\r
     return FALSE;\r
   }\r
 \r
   //\r
   // OpenSSL SHA-384 Hash Update\r
   //\r
-  return (BOOLEAN) (SHA384_Update ((SHA512_CTX *) Sha384Context, Data, DataSize));\r
+  return (BOOLEAN)(SHA384_Update ((SHA512_CTX *)Sha384Context, Data, DataSize));\r
 }\r
 \r
 /**\r
@@ -150,7 +144,7 @@ Sha384Update (
   This function completes SHA-384 hash computation and retrieves the digest value into\r
   the specified memory. After this function has been called, the SHA-384 context cannot\r
   be used again.\r
-  SHA-384 context should be already correctly intialized by Sha384Init(), and should not be\r
+  SHA-384 context should be already correctly initialized by Sha384Init(), and should not be\r
   finalized by Sha384Final(). Behavior with invalid SHA-384 context is undefined.\r
 \r
   If Sha384Context is NULL, then return FALSE.\r
@@ -174,14 +168,61 @@ Sha384Final (
   //\r
   // Check input parameters.\r
   //\r
-  if (Sha384Context == NULL || HashValue == NULL) {\r
+  if ((Sha384Context == NULL) || (HashValue == NULL)) {\r
     return FALSE;\r
   }\r
 \r
   //\r
   // OpenSSL SHA-384 Hash Finalization\r
   //\r
-  return (BOOLEAN) (SHA384_Final (HashValue, (SHA512_CTX *) Sha384Context));\r
+  return (BOOLEAN)(SHA384_Final (HashValue, (SHA512_CTX *)Sha384Context));\r
+}\r
+\r
+/**\r
+  Computes the SHA-384 message digest of a input data buffer.\r
+\r
+  This function performs the SHA-384 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 SHA-384 digest\r
+                           value (48 bytes).\r
+\r
+  @retval TRUE   SHA-384 digest computation succeeded.\r
+  @retval FALSE  SHA-384 digest computation failed.\r
+  @retval FALSE  This interface is not supported.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+Sha384HashAll (\r
+  IN   CONST VOID  *Data,\r
+  IN   UINTN       DataSize,\r
+  OUT  UINT8       *HashValue\r
+  )\r
+{\r
+  //\r
+  // Check input parameters.\r
+  //\r
+  if (HashValue == NULL) {\r
+    return FALSE;\r
+  }\r
+\r
+  if ((Data == NULL) && (DataSize != 0)) {\r
+    return FALSE;\r
+  }\r
+\r
+  //\r
+  // OpenSSL SHA-384 Hash Computation.\r
+  //\r
+  if (SHA384 (Data, DataSize, HashValue) == NULL) {\r
+    return FALSE;\r
+  } else {\r
+    return TRUE;\r
+  }\r
 }\r
 \r
 /**\r
@@ -199,7 +240,7 @@ Sha512GetContextSize (
   //\r
   // Retrieves OpenSSL SHA-512 Context Size\r
   //\r
-  return (UINTN) (sizeof (SHA512_CTX));\r
+  return (UINTN)(sizeof (SHA512_CTX));\r
 }\r
 \r
 /**\r
@@ -230,7 +271,7 @@ Sha512Init (
   //\r
   // OpenSSL SHA-512 Context Initialization\r
   //\r
-  return (BOOLEAN) (SHA512_Init ((SHA512_CTX *) Sha512Context));\r
+  return (BOOLEAN)(SHA512_Init ((SHA512_CTX *)Sha512Context));\r
 }\r
 \r
 /**\r
@@ -258,7 +299,7 @@ Sha512Duplicate (
   //\r
   // Check input parameters.\r
   //\r
-  if (Sha512Context == NULL || NewSha512Context == NULL) {\r
+  if ((Sha512Context == NULL) || (NewSha512Context == NULL)) {\r
     return FALSE;\r
   }\r
 \r
@@ -272,7 +313,7 @@ Sha512Duplicate (
 \r
   This function performs SHA-512 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
-  SHA-512 context should be already correctly intialized by Sha512Init(), and should not be finalized\r
+  SHA-512 context should be already correctly initialized by Sha512Init(), and should not be finalized\r
   by Sha512Final(). Behavior with invalid context is undefined.\r
 \r
   If Sha512Context is NULL, then return FALSE.\r
@@ -303,14 +344,14 @@ Sha512Update (
   //\r
   // Check invalid parameters, in case that only DataLength was checked in OpenSSL\r
   //\r
-  if (Data == NULL && DataSize != 0) {\r
+  if ((Data == NULL) && (DataSize != 0)) {\r
     return FALSE;\r
   }\r
 \r
   //\r
   // OpenSSL SHA-512 Hash Update\r
   //\r
-  return (BOOLEAN) (SHA512_Update ((SHA512_CTX *) Sha512Context, Data, DataSize));\r
+  return (BOOLEAN)(SHA512_Update ((SHA512_CTX *)Sha512Context, Data, DataSize));\r
 }\r
 \r
 /**\r
@@ -319,7 +360,7 @@ Sha512Update (
   This function completes SHA-512 hash computation and retrieves the digest value into\r
   the specified memory. After this function has been called, the SHA-512 context cannot\r
   be used again.\r
-  SHA-512 context should be already correctly intialized by Sha512Init(), and should not be\r
+  SHA-512 context should be already correctly initialized by Sha512Init(), and should not be\r
   finalized by Sha512Final(). Behavior with invalid SHA-512 context is undefined.\r
 \r
   If Sha512Context is NULL, then return FALSE.\r
@@ -343,12 +384,59 @@ Sha512Final (
   //\r
   // Check input parameters.\r
   //\r
-  if (Sha512Context == NULL || HashValue == NULL) {\r
+  if ((Sha512Context == NULL) || (HashValue == NULL)) {\r
     return FALSE;\r
   }\r
 \r
   //\r
   // OpenSSL SHA-512 Hash Finalization\r
   //\r
-  return (BOOLEAN) (SHA384_Final (HashValue, (SHA512_CTX *) Sha512Context));\r
+  return (BOOLEAN)(SHA384_Final (HashValue, (SHA512_CTX *)Sha512Context));\r
+}\r
+\r
+/**\r
+  Computes the SHA-512 message digest of a input data buffer.\r
+\r
+  This function performs the SHA-512 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 SHA-512 digest\r
+                           value (64 bytes).\r
+\r
+  @retval TRUE   SHA-512 digest computation succeeded.\r
+  @retval FALSE  SHA-512 digest computation failed.\r
+  @retval FALSE  This interface is not supported.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+Sha512HashAll (\r
+  IN   CONST VOID  *Data,\r
+  IN   UINTN       DataSize,\r
+  OUT  UINT8       *HashValue\r
+  )\r
+{\r
+  //\r
+  // Check input parameters.\r
+  //\r
+  if (HashValue == NULL) {\r
+    return FALSE;\r
+  }\r
+\r
+  if ((Data == NULL) && (DataSize != 0)) {\r
+    return FALSE;\r
+  }\r
+\r
+  //\r
+  // OpenSSL SHA-512 Hash Computation.\r
+  //\r
+  if (SHA512 (Data, DataSize, HashValue) == NULL) {\r
+    return FALSE;\r
+  } else {\r
+    return TRUE;\r
+  }\r
 }\r