Add context check and init in BaseCrypto2Hash().

Follow UEFI specification to add context check and init in BaseCrypto2Hash(), so that other function can get proper status on hash operation.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: "Yao, Jiewen" <Jiewen.Yao@intel.com>
Reviewed-by: "Zhang, Chao B" <chao.b.zhang@intel.com>


git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@18227 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Yao, Jiewen 2015-08-17 05:48:30 +00:00 committed by jyao1
parent 13a220a998
commit 099bff5def
1 changed files with 19 additions and 0 deletions

View File

@ -358,6 +358,7 @@ BaseCrypto2Hash (
UINTN CtxSize; UINTN CtxSize;
BOOLEAN Ret; BOOLEAN Ret;
EFI_STATUS Status; EFI_STATUS Status;
HASH2_INSTANCE_DATA *Instance;
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
@ -373,6 +374,13 @@ BaseCrypto2Hash (
if (HashInfo == NULL) { if (HashInfo == NULL) {
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
Instance = HASH2_INSTANCE_DATA_FROM_THIS(This);
if (Instance->HashContext != NULL) {
FreePool (Instance->HashContext);
}
Instance->HashInfoContext = NULL;
Instance->HashContext = NULL;
// //
// Start hash sequence // Start hash sequence
@ -392,6 +400,12 @@ BaseCrypto2Hash (
goto Done; goto Done;
} }
//
// Setup the context
//
Instance->HashContext = HashCtx;
Instance->HashInfoContext = HashInfo;
Ret = HashInfo->Update (HashCtx, Message, MessageSize); Ret = HashInfo->Update (HashCtx, Message, MessageSize);
if (!Ret) { if (!Ret) {
Status = EFI_OUT_OF_RESOURCES; Status = EFI_OUT_OF_RESOURCES;
@ -404,7 +418,12 @@ BaseCrypto2Hash (
goto Done; goto Done;
} }
Done: Done:
//
// Cleanup the context
//
FreePool (HashCtx); FreePool (HashCtx);
Instance->HashInfoContext = NULL;
Instance->HashContext = NULL;
return Status; return Status;
} }