security/tpm/tss/tcg-2.0: Use tlcl_get_hash_size_from_algo() for hash size

mashal_TPMT_HA() uses size of SHA-256 hash.
Use tlcll_get_hash_size_from_algo() to determince the hash size.

BUG=N/A
TEST=Build binary and verified logging on Facebook FBG-1701

Change-Id: I739260e13e9cd10a61d52e13e8741b12ec868d7f
Signed-off-by: Frans Hendriks <fhendriks@eltan.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/33251
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Lance Zhao <lance.zhao@gmail.com>
Reviewed-by: Felix Held <felix-coreboot@felixheld.de>
diff --git a/src/security/tpm/tss/tcg-2.0/tss.c b/src/security/tpm/tss/tcg-2.0/tss.c
index 08a7caa..16e40fe 100644
--- a/src/security/tpm/tss/tcg-2.0/tss.c
+++ b/src/security/tpm/tss/tcg-2.0/tss.c
@@ -352,6 +352,38 @@
 	}
 }
 
+uint16_t tlcl_get_hash_size_from_algo(TPMI_ALG_HASH hash_algo)
+{
+	uint16_t value;
+
+	switch (hash_algo) {
+	case TPM_ALG_ERROR:
+		value = 1;
+		break;
+	case TPM_ALG_SHA1:
+		value = SHA1_DIGEST_SIZE;
+		break;
+	case TPM_ALG_SHA256:
+		value = SHA256_DIGEST_SIZE;
+		break;
+	case TPM_ALG_SHA384:
+		value = SHA384_DIGEST_SIZE;
+		break;
+	case TPM_ALG_SHA512:
+		value = SHA512_DIGEST_SIZE;
+		break;
+	case TPM_ALG_SM3_256:
+		value = SM3_256_DIGEST_SIZE;
+		break;
+	default:
+		printk(BIOS_SPEW, "%s: unknown hash algorithm %d\n", __func__,
+		hash_algo);
+		value = 0;
+	};
+
+	return value;
+}
+
 uint32_t tlcl_disable_platform_hierarchy(void)
 {
 	struct tpm2_response *response;