/* This service abstracts the capability to do a hash operation on a data buffer. */
EFI_STATUS EFIAPI TcgDxeHashAll(IN EFI_TCG_PROTOCOL *This, IN UINT8 *HashData, IN UINT64 HashDataLen, IN TCG_ALGORITHM_ID AlgorithmId, IN OUT UINT64 *HashedDataLen, IN OUT UINT8 **HashedDataResult)
/* This service abstracts the capability to do a hash operation on a data buffer. */
EFI_STATUS EFIAPI TcgDxeHashAll(IN EFI_TCG_PROTOCOL *This, IN UINT8 *HashData, IN UINT64 HashDataLen, IN TCG_ALGORITHM_ID AlgorithmId, IN OUT UINT64 *HashedDataLen, IN OUT UINT8 **HashedDataResult)
{
  if ((HashedDataLen == NULL) || (HashedDataResult == NULL)) {
    return EFI_INVALID_PARAMETER;
  }
  switch (AlgorithmId) {
    case TPM_ALG_SHA:
      if (*HashedDataLen == 0) {
        *HashedDataLen    = sizeof (TPM_DIGEST);
        *HashedDataResult = AllocatePool ((UINTN)*HashedDataLen);
        if (*HashedDataResult == NULL) {
          return EFI_OUT_OF_RESOURCES;
        }
      }
      if (*HashedDataLen < sizeof (TPM_DIGEST)) {
        *HashedDataLen = sizeof (TPM_DIGEST);
        return EFI_BUFFER_TOO_SMALL;
      }
      *HashedDataLen = sizeof (TPM_DIGEST);
      if (*HashedDataResult == NULL) {
        *HashedDataResult = AllocatePool ((UINTN)*HashedDataLen);
      }
      return TpmCommHashAll (
               HashData,
               (UINTN)HashDataLen,
               (TPM_DIGEST *)*HashedDataResult
               );
    default:
      return EFI_UNSUPPORTED;
  }
}