pldm: Add verify CRC value of the BIOS table

Add a checksum methods to the BIOS table and verify the integrity
of the BIOS table.

Tested: add the UTest method and pass the test.

Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I57849714b0450b65fd894f767b15ab47de8cde89
diff --git a/libpldm/bios_table.c b/libpldm/bios_table.c
index e4e7d96..58c331b 100644
--- a/libpldm/bios_table.c
+++ b/libpldm/bios_table.c
@@ -1117,3 +1117,19 @@
 	pldm_bios_table_iter_free(iter);
 	return rc;
 }
+
+bool pldm_bios_table_checksum(const uint8_t *table, size_t size)
+{
+	if (table == NULL)
+		return false;
+
+	// 12: BIOSStringHandle(uint16) + BIOSStringLength(uint16) +
+	//     Variable(4) + checksum(uint32)
+	if (size < 12)
+		return false;
+
+	uint32_t src_crc = le32toh(*(uint32_t *)(table + size - 4));
+	uint32_t dst_crc = crc32(table, size - 4);
+
+	return src_crc == dst_crc;
+}
diff --git a/libpldm/bios_table.h b/libpldm/bios_table.h
index fe964ee..284efcb 100644
--- a/libpldm/bios_table.h
+++ b/libpldm/bios_table.h
@@ -714,6 +714,13 @@
     const void *src_table, size_t src_length, void *dest_table,
     size_t *dest_length, const void *entry, size_t entry_length);
 
+/** @brief Verify the crc value of the complete table
+ *  @param[in] table - Pointer to a buffer of a bios table
+ *  @param[in] size - Size of the buffer of a bios table
+ *  @return true: crc value is correct
+ */
+bool pldm_bios_table_checksum(const uint8_t *table, size_t size);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/libpldm/tests/libpldm_bios_table_test.cpp b/libpldm/tests/libpldm_bios_table_test.cpp
index aeb1ac3..a307264 100644
--- a/libpldm/tests/libpldm_bios_table_test.cpp
+++ b/libpldm/tests/libpldm_bios_table_test.cpp
@@ -1120,3 +1120,17 @@
                            0x66, 0x00, 0x6d, 0x81, 0x4a, 0xb6};
     EXPECT_EQ(attrValTable, expectedTable);
 }
+
+TEST(BIOSTableChecksum, testBIOSTableChecksum)
+{
+    std::vector<uint8_t> stringTable{
+        1,   0,                  /* string handle*/
+        5,   0,                  /* string length */
+        'T', 'a', 'b', 'l', 'e', /* string */
+    };
+
+    buildTable(stringTable);
+
+    EXPECT_EQ(true,
+              pldm_bios_table_checksum(stringTable.data(), stringTable.size()));
+}