]> git.proxmox.com Git - mirror_edk2.git/blobdiff - CryptoPkg/Library/BaseCryptLib/Hash/CryptSha1.c
Update CryptoPkg for new ciphers (HMAC, Block Cipher, etc) supports.
[mirror_edk2.git] / CryptoPkg / Library / BaseCryptLib / Hash / CryptSha1.c
index d77405930019363a77a887387e991edca1dfc37a..9a317ec14358f8e427ccbc4195474faf42e29227 100644 (file)
@@ -12,10 +12,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 **/\r
 \r
 \r
 **/\r
 \r
-#include <Library/BaseLib.h>\r
-#include <Library/DebugLib.h>\r
-\r
-#include <Library/BaseCryptLib.h>\r
+#include "InternalCryptLib.h"\r
 #include <openssl/sha.h>\r
 \r
 \r
 #include <openssl/sha.h>\r
 \r
 \r
@@ -37,23 +34,22 @@ Sha1GetContextSize (
   return (UINTN)(sizeof (SHA_CTX));\r
 }\r
 \r
   return (UINTN)(sizeof (SHA_CTX));\r
 }\r
 \r
-\r
 /**\r
 /**\r
-  Initializes user-supplied memory pointed by Sha1Context as the SHA-1 hash context for\r
+  Initializes user-supplied memory pointed by Sha1Context as SHA-1 hash context for\r
   subsequent use.\r
 \r
   If Sha1Context is NULL, then ASSERT().\r
 \r
   subsequent use.\r
 \r
   If Sha1Context is NULL, then ASSERT().\r
 \r
-  @param[in, out]  Sha1Context  Pointer to the SHA-1 Context being initialized.\r
+  @param[out]  Sha1Context  Pointer to SHA-1 context being initialized.\r
 \r
 \r
-  @retval TRUE   SHA-1 initialization succeeded.\r
-  @retval FALSE  SHA-1 initialization failed.\r
+  @retval TRUE   SHA-1 context initialization succeeded.\r
+  @retval FALSE  SHA-1 context initialization failed.\r
 \r
 **/\r
 BOOLEAN\r
 EFIAPI\r
 Sha1Init (\r
 \r
 **/\r
 BOOLEAN\r
 EFIAPI\r
 Sha1Init (\r
-  IN OUT  VOID  *Sha1Context\r
+  OUT  VOID  *Sha1Context\r
   )\r
 {\r
   //\r
   )\r
 {\r
   //\r
@@ -67,20 +63,47 @@ Sha1Init (
   return (BOOLEAN) (SHA1_Init ((SHA_CTX *)Sha1Context));\r
 }\r
 \r
   return (BOOLEAN) (SHA1_Init ((SHA_CTX *)Sha1Context));\r
 }\r
 \r
+/**\r
+  Makes a copy of an existing SHA-1 context.\r
+\r
+  If Sha1Context is NULL, then ASSERT().\r
+  If NewSha1Context is NULL, then ASSERT().\r
+\r
+  @param[in]  Sha1Context     Pointer to SHA-1 context being copied.\r
+  @param[out] NewSha1Context  Pointer to new SHA-1 context.\r
+\r
+  @retval TRUE   SHA-1 context copy succeeded.\r
+  @retval FALSE  SHA-1 context copy failed.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+Sha1Duplicate (\r
+  IN   CONST VOID  *Sha1Context,\r
+  OUT  VOID        *NewSha1Context\r
+  )\r
+{\r
+  CopyMem (NewSha1Context, Sha1Context, sizeof (SHA_CTX));\r
+\r
+  return TRUE;\r
+}\r
 \r
 /**\r
 \r
 /**\r
-  Performs SHA-1 digest on a data buffer of the specified length. This function can\r
-  be called multiple times to compute the digest of long or discontinuous data streams.\r
+  Digests the input data and updates SHA-1 context.\r
+\r
+  This function performs SHA-1 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-1 context should be already correctly intialized by Sha1Init(), and should not be finalized\r
+  by Sha1Final(). Behavior with invalid context is undefined.\r
 \r
   If Sha1Context is NULL, then ASSERT().\r
 \r
   @param[in, out]  Sha1Context  Pointer to the SHA-1 context.\r
   @param[in]       Data         Pointer to the buffer containing the data to be hashed.\r
 \r
   If Sha1Context is NULL, then ASSERT().\r
 \r
   @param[in, out]  Sha1Context  Pointer to the SHA-1 context.\r
   @param[in]       Data         Pointer to the buffer containing the data to be hashed.\r
-  @param[in]       DataLength   Length of Data buffer in bytes.\r
+  @param[in]       DataSize     Size of Data buffer in bytes.\r
 \r
   @retval TRUE   SHA-1 data digest succeeded.\r
 \r
   @retval TRUE   SHA-1 data digest succeeded.\r
-  @retval FALSE  Invalid SHA-1 context. After Sha1Final function has been called, the\r
-                 SHA-1 context cannot be reused.\r
+  @retval FALSE  SHA-1 data digest failed.\r
 \r
 **/\r
 BOOLEAN\r
 \r
 **/\r
 BOOLEAN\r
@@ -88,7 +111,7 @@ EFIAPI
 Sha1Update (\r
   IN OUT  VOID        *Sha1Context,\r
   IN      CONST VOID  *Data,\r
 Sha1Update (\r
   IN OUT  VOID        *Sha1Context,\r
   IN      CONST VOID  *Data,\r
-  IN      UINTN       DataLength\r
+  IN      UINTN       DataSize\r
   )\r
 {\r
   //\r
   )\r
 {\r
   //\r
@@ -100,24 +123,28 @@ Sha1Update (
   // ASSERT if invalid parameters, in case that only DataLength was checked in OpenSSL\r
   //\r
   if (Data == NULL) {\r
   // ASSERT if invalid parameters, in case that only DataLength was checked in OpenSSL\r
   //\r
   if (Data == NULL) {\r
-    ASSERT (DataLength == 0);\r
+    ASSERT (DataSize == 0);\r
   }\r
 \r
   //\r
   // OpenSSL SHA-1 Hash Update\r
   //\r
   }\r
 \r
   //\r
   // OpenSSL SHA-1 Hash Update\r
   //\r
-  return (BOOLEAN) (SHA1_Update ((SHA_CTX *)Sha1Context, Data, DataLength));\r
+  return (BOOLEAN) (SHA1_Update ((SHA_CTX *)Sha1Context, Data, DataSize));\r
 }\r
 \r
 }\r
 \r
-\r
 /**\r
 /**\r
-  Completes SHA-1 hash computation and retrieves the digest value into the specified\r
-  memory. After this function has been called, the SHA-1 context cannot be used again.\r
+  Completes computation of the SHA-1 digest value.\r
+\r
+  This function completes SHA-1 hash computation and retrieves the digest value into\r
+  the specified memory. After this function has been called, the SHA-1 context cannot\r
+  be used again.\r
+  SHA-1 context should be already correctly intialized by Sha1Init(), and should not be\r
+  finalized by Sha1Final(). Behavior with invalid SHA-1 context is undefined.\r
 \r
   If Sha1Context is NULL, then ASSERT().\r
   If HashValue is NULL, then ASSERT().\r
 \r
 \r
   If Sha1Context is NULL, then ASSERT().\r
   If HashValue is NULL, then ASSERT().\r
 \r
-  @param[in, out]  Sha1Context  Pointer to the SHA-1 context\r
+  @param[in, out]  Sha1Context  Pointer to the SHA-1 context.\r
   @param[out]      HashValue    Pointer to a buffer that receives the SHA-1 digest\r
                                 value (20 bytes).\r
 \r
   @param[out]      HashValue    Pointer to a buffer that receives the SHA-1 digest\r
                                 value (20 bytes).\r
 \r