2.1 Hash Function

The primary objective of a hash function is to generate a unique digital identifier for a given set of data, akin to a ‘fingerprint’. Unlike error detection codes, each data set must be associated with a distinct identifier.

To ensure the integrity of firmware, its unique identifier is calculated and appended to the file. Upon reception of the firmware and its associated identifier, the bootloader recalculates the identifier and compares it to the original to confirm that the firmware remains unmodified.

Operationally, a hash function accepts an input of variable length and produces an output of a predetermined size, known as a message digest. It possesses several critical attributes, such as excellent diffusion, which ensures a significantly different output with even the slightest change in input.

Figure 2-1. Firmware Hashing

Despite the fixed output size, which theoretically limits the possibility of generating a unique digest for every conceivable piece of data, hash functions are designed to make it exceedingly difficult to find two distinct messages that yield the same digest, effectively simulating uniqueness for practical purposes.

One limitation of relying solely on hashing for firmware is that it can be performed by anyone, allowing a potential attacker to alter the file and recalculate the hash, thereby rendering the bootloader unable to detect the modification.

However, employing a hash function can still be an effective method to verify firmware integrity during runtime and prevent the execution of a compromised application.