Data integrity means detecting unauthorized or unnoticed alteration. When downloading a file, compare its hash with a securely communicated digest; otherwise, an attacker can replace both the file and its hash. section 2.1 section 2.4.4
Hash-based integrity follows a small set of practical rules:
- Hashing the same input produces the same fixed-length digest, while a tiny input change produces a radically different output. section 2.1
- A digest helps prevent substitution when second pre-image resistance makes another matching file infeasible. section 2.1
- A plain hash does not establish integrity unless the digest itself is obtained securely; HMAC adds a shared secret. section 2.4.4 section 3.2
Checking a downloaded file
Run `openssl dgst -sha256 downloaded_file` and compare the resulting hexadecimal digest with the trusted value published for the file. BitTorrent applies the same idea chunk by chunk before reassembling a download. section 2.1 section 2.4.3
Figure 2.1 A web page linking to an external website containing a file. The external website cannot modify the content of the file because the first page provides a hash or digest of the file, which ensures the integrity over the downloaded file.
A diagram shows how a trusted web page supplies a digest for a file hosted elsewhere, preserving integrity during download. section 2.1

















