/** @file\r
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
} EFI_HASH_INFO;\r
\r
EFI_HASH_INFO mHashInfo[] = {\r
+ {&gEfiHashAlgorithmMD5Guid, sizeof(EFI_MD5_HASH2), Md5GetContextSize, Md5Init, Md5Update, Md5Final },\r
{&gEfiHashAlgorithmSha1Guid, sizeof(EFI_SHA1_HASH2), Sha1GetContextSize, Sha1Init, Sha1Update, Sha1Final },\r
{&gEfiHashAlgorithmSha256Guid, sizeof(EFI_SHA256_HASH2), Sha256GetContextSize, Sha256Init, Sha256Update, Sha256Final },\r
{&gEfiHashAlgorithmSha384Guid, sizeof(EFI_SHA384_HASH2), Sha384GetContextSize, Sha384Init, Sha384Update, Sha384Final },\r
UINTN CtxSize;\r
BOOLEAN Ret;\r
EFI_STATUS Status;\r
+ HASH2_INSTANCE_DATA *Instance;\r
\r
Status = EFI_SUCCESS;\r
\r
if (HashInfo == NULL) {\r
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
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
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
// 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
//\r
Instance->HashContext = HashCtx;\r
Instance->HashInfoContext = HashInfo;\r
+ Instance->Updated = FALSE;\r
\r
return EFI_SUCCESS;\r
}\r
return EFI_OUT_OF_RESOURCES;\r
}\r
\r
+ Instance->Updated = TRUE;\r
+\r
return EFI_SUCCESS;\r
}\r
\r
// 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
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