utils: Add API for CRC validation
- Added the validation functions for `pldm_edac_crc32_validate`.
Motivation:
Checksum validation is a hazard for fuzzing. Provide an API that
allows us to adjust the implementation of the test depending on
whether we are building to fuzz the library implementation.
Change-Id: Iffd245fe5cbcadb1037cd1f5065ccc1da6502562
Signed-off-by: Carter Chen <carter.chen.wiwynn@gmail.com>
diff --git a/src/utils.h b/src/utils.h
new file mode 100644
index 0000000..6a027ca
--- /dev/null
+++ b/src/utils.h
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+#ifndef LIBPLDM_SRC_UTILS_H
+#define LIBPLDM_SRC_UTILS_H
+
+#include <errno.h>
+#include <stdint.h>
+#include <stddef.h>
+
+/**
+ * @brief Validate the CRC32 checksum of the given data.
+ *
+ * @param[in] expected The expected CRC32 value.
+ * @param[in] data Pointer to the data to validate.
+ * @param[in] size Size of the data in bytes.
+ * @return 0 if the checksum matches,
+ * -EUCLEAN if the checksum mismatches,
+ * -EINVAL if the arguments are invalid
+ */
+int pldm_edac_crc32_validate(uint32_t expected, const void *data, size_t size);
+#endif