]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.c
Maintainers.txt: update mailing list information
[mirror_edk2.git] / SecurityPkg / Hash2DxeCrypto / Hash2DxeCrypto.c
index 6a7ecf2a2d15828f737652e90f23fcec0e1ca949..2b069a36c02b2e481e59bfe95f2d0cbf33511841 100644 (file)
@@ -2,14 +2,8 @@
   This module implements Hash2 Protocol.\r
 \r
 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>\r
-Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials are licensed and made available under\r
-the terms and conditions of the BSD License that accompanies this distribution.\r
-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) 2015 - 2018, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -64,7 +58,7 @@ BOOLEAN
 \r
   This function performs Hash 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
-  Hash context should be already correctly intialized by HashInit(), and should not be finalized\r
+  Hash context should be already correctly initialized by HashInit(), and should not be finalized\r
   by HashFinal(). Behavior with invalid context is undefined.\r
 \r
   If HashContext is NULL, then return FALSE.\r
@@ -358,6 +352,7 @@ BaseCrypto2Hash (
   UINTN                    CtxSize;\r
   BOOLEAN                  Ret;\r
   EFI_STATUS               Status;\r
+  HASH2_INSTANCE_DATA      *Instance;\r
 \r
   Status = EFI_SUCCESS;\r
 \r
@@ -374,6 +369,13 @@ BaseCrypto2Hash (
     return EFI_UNSUPPORTED;\r
   }\r
 \r
+  Instance = HASH2_INSTANCE_DATA_FROM_THIS(This);\r
+  if (Instance->HashContext != NULL) {\r
+    FreePool (Instance->HashContext);\r
+  }\r
+  Instance->HashInfoContext = NULL;\r
+  Instance->HashContext = NULL;\r
+\r
   //\r
   // Start hash sequence\r
   //\r
@@ -392,6 +394,12 @@ BaseCrypto2Hash (
     goto Done;\r
   }\r
 \r
+  //\r
+  // Setup the context\r
+  //\r
+  Instance->HashContext = HashCtx;\r
+  Instance->HashInfoContext = HashInfo;\r
+\r
   Ret = HashInfo->Update (HashCtx, Message, MessageSize);\r
   if (!Ret) {\r
     Status = EFI_OUT_OF_RESOURCES;\r
@@ -404,7 +412,12 @@ BaseCrypto2Hash (
     goto Done;\r
   }\r
 Done:\r
+  //\r
+  // Cleanup the context\r
+  //\r
   FreePool (HashCtx);\r
+  Instance->HashInfoContext = NULL;\r
+  Instance->HashContext = NULL;\r
   return Status;\r
 }\r
 \r
@@ -454,7 +467,7 @@ BaseCrypto2HashInit (
   // Consistency Check\r
   //\r
   Instance = HASH2_INSTANCE_DATA_FROM_THIS(This);\r
-  if ((Instance->HashContext != NULL) || (Instance->HashInfoContext != HashInfo)) {\r
+  if ((Instance->HashContext != NULL) || (Instance->HashInfoContext != NULL)) {\r
     return EFI_ALREADY_STARTED;\r
   }\r
 \r
@@ -481,6 +494,7 @@ BaseCrypto2HashInit (
   //\r
   Instance->HashContext = HashCtx;\r
   Instance->HashInfoContext = HashInfo;\r
+  Instance->Updated = FALSE;\r
 \r
   return EFI_SUCCESS;\r
 }\r
@@ -532,6 +546,8 @@ BaseCrypto2HashUpdate (
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
+  Instance->Updated = TRUE;\r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -571,7 +587,8 @@ BaseCrypto2HashFinal (
   // Consistency Check\r
   //\r
   Instance = HASH2_INSTANCE_DATA_FROM_THIS(This);\r
-  if ((Instance->HashContext == NULL) || (Instance->HashInfoContext == NULL)) {\r
+  if ((Instance->HashContext == NULL) || (Instance->HashInfoContext == NULL) ||\r
+      (!Instance->Updated)) {\r
     return EFI_NOT_READY;\r
   }\r
   HashInfo = Instance->HashInfoContext;\r
@@ -585,6 +602,7 @@ BaseCrypto2HashFinal (
   FreePool (HashCtx);\r
   Instance->HashInfoContext = NULL;\r
   Instance->HashContext = NULL;\r
+  Instance->Updated = FALSE;\r
 \r
   if (!Ret) {\r
     return EFI_OUT_OF_RESOURCES;\r