=== Checksum Block (`CKSM`)

This block stores an array of checksums corresponding to the user data embedded in the image.
For media formats such as CompactDisc, the checksum is calculated over the complete sector—comprising the prefix, user data, and suffix—totaling 2352 bytes.

If the image is modified, the checksum block is considered outdated and should be either removed or excluded from the most recent index to ensure integrity.

==== Structure Definition

[source,c]
#define CHECKSUM_MAGIC 0x4D534B43
/**
 *     Checksum block, contains a checksum of all user data sectors (except for optical discs that is 2352 uint8_ts raw
 *     sector if available
 *  */
typedef struct ChecksumHeader
{
    uint32_t identifier;  ///< Block identifier, must be BlockType::ChecksumBlock.
    uint32_t length;      ///< Length in bytes of the payload (all entries + their digest data, excluding this header).
    uint8_t  entries;     ///< Number of checksum entries that follow in the payload.
} ChecksumHeader;

==== Field Descriptions

[cols="2,2,2,6",options="header"]
|===
|Type
|Size
|Name
|Description

|uint32_t
|4 bytes
|identifier
|The tracks block identifier, always `CKSM`

|uint32_t
|4 bytes
|length
|The length in bytes of the data following this header.

|uint8_t
|1 byte
|entries
|The number of entries following this header
|===

==== Checksum entries

[source,c]
/**Checksum entry, followed by checksum data itself */
typedef struct ChecksumEntry
{
    uint8_t  type;    ///< Algorithm used (value from \ref ChecksumAlgorithm).
    uint32_t length;  ///< Length in bytes of the digest that immediately follows this structure.
} ChecksumEntry;

==== Field Descriptions

[cols="2,2,2,6",options="header"]
|===
|Type
|Size
|Name
|Description

|uint8_t
|1 byte
|type
|Checksum algorithm.

|uint32_t
|4 bytes
|length
|Size in bytes of the checksum that immediately follows this entry.
|===

==== Checksum algorithms

[cols="2,2,6",options="header"]
|===
|Type
|Value
|Description

|Invalid
|0
|Invalid checksum entry, skip.

|Md5
|1
|MD5

|Sha1
|2
|SHA1

|Sha256
|3
|SHA-256

|SpamSum
|4
|SpamSum
|===
