liveBook · Manning

Data integrity

As explained in Real-World Cryptography

Integrity is the property that data has not been altered in an unauthorized or undetected way.

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

How Real-World Cryptography covers it

How deep it goes
Explains hashing behavior, second pre-image resistance, secure digest distribution, HMAC use, and replay limitations without covering replay prevention.
Examples
Uses OpenSSL SHA-256 checks, BitTorrent chunk verification, Tor onion addresses, and Rust HMAC message exchange.
What you can do after
Apply it via OpenSSL, chunk digests, or HMAC to detect altered files and messages.
How it connects
Connects hash functions, second pre-image resistance, message authentication codes, HMAC, BitTorrent, and Tor.

Also explained in

Compare how 18 books explain data integrity →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Real-World Cryptography. The section links point to the parts of the book it draws on.