Question
What does a digest match prove about a consumed artifact?
Short answer
A digest match proves only byte identity: the bytes the consumer hashed are, beyond any practical doubt, the bytes from which the reference digest was computed. Two assumptions carry that conclusion: no one can find different bytes with the same digest, and the reference digest came from a source the consumer trusts, by a route an attacker cannot alter. The match does not prove who made the bytes, that this consumer may use them in this way, that they are the current version, or that they are correct or safe.
Terms in the question
Artifact: a file or other sequence of bytes that one step produces and a later step uses, such as a program image, a configuration file or a dataset.
Consumed: read and acted on, for example run, installed, parsed or published.
Digest: the output of a cryptographic hash function §5.1, a function that maps input of any length to a short value of fixed length in such a way that, in practice, nobody can find two inputs with the same value. SHA-256 §5.2 (Secure Hash Algorithm with a 256-bit output) produces 32-byte digests.
Digest match: the consumer computes the digest of the bytes it holds and finds it equal to a reference digest, an expected value obtained separately, for example from a manifest §13.4, a list that names each item of a package together with its digest.
Prove: here, what the consumer may conclude from the match alone, with no further check.
Full answer
What the comparison establishes. Write for the hash function, for the bytes the consumer holds and for the reference digest, which its author computed from bytes . A match means . If differed from , the two would be different inputs with the same digest. For SHA-256 nobody knows how to find such a pair. A different input picked at random matches a given digest with probability about , and the best known general method of finding any two inputs with the same digest needs about hash computations. The consumer therefore concludes that .
Two properties of the hash function back that conclusion, in two different situations.
Second-preimage resistance §5.4: given , nobody can find a different input with the same digest. This suffices when an honest party produced .
Collision resistance §5.5: nobody can find any two different inputs with the same digest. This is needed when an attacker could influence itself, for example by getting a harmless file approved and later substituting a harmful file with the same digest.
SHA-1 (Secure Hash Algorithm 1) lost collision resistance in practice in 2017, when researchers published two different PDF files with the same SHA-1 digest [312].
The match inherits all its meaning from the reference. The conclusion is only that equals whatever was computed from. If an attacker can choose , the attacker computes from a harmful file, and the match proves nothing about origin. This happens whenever the artifact and its digest come from the same place: a compromised download server serves a harmful file together with the correct digest of that harmful file. The origin of the bytes is established by protecting the reference, not by the hash. The reference can be protected by a digital signature §5.14 made with a key the consumer already trusts, by a digest built into the consumer in advance, or by a separate channel that the attacker cannot change.
What a match leaves open.
Authority. Authorization §1.7 is the decision that a given party may use given bytes in a given way. A digest names bytes; it grants no permission. The same bytes can be approved as a document to display and forbidden as a program to run. The signed approval must therefore name the role of the bytes as well as their digest, and the consumer must check the role.
Freshness. An old version still matches its own digest. An attacker who sends again a correctly signed old manifest together with its old, vulnerable artifact passes both the signature check and the digest check. Only a comparison with the lowest version the consumer still accepts, called anti-rollback §8.26, stops it. Update systems such as TUF §21.10 (The Update Framework) also give signed metadata an expiry time, so that a consumer detects an attacker who keeps showing it old metadata.
Correctness and safety. A digest matches a malformed or malicious file as readily as a good one, if that file is the one that was hashed. Parsing and validating the content are separate checks.
Production history. The digest says nothing about which source code and which build produced the bytes. Nor does it tell a copy from the original: a rule that requires the exact file a given step produced cannot be checked with a digest, because a byte-identical copy from elsewhere has the same digest.
Identity at the time of use. The match covers the bytes that were hashed, at the moment they were hashed. Suppose the consumer hashes a file that it finds by its path, then opens the path again to use the file. An attacker who replaces the file, or a symbolic link §13.10 along the path, in between makes the consumer use different bytes. This is a time-of-check to time-of-use §9.26 (TOCTOU) error. Reading through one file descriptor §15.21, the handle that the OS gives for one open file, removes the race on the path, but not a writer who changes the file itself. The full repair is to read the bytes once into memory that nothing else can change, hash that copy and use that copy.
Correct use. A consumer that relies on a digest checks, in this order: the protection of the reference, such as a signature made with a trusted key; that the signed statement allows this artifact, in this role, on this consumer; that the version is not below the lowest accepted one; that the digest of the one copy it read matches; and that the content parses and passes validation. It then uses that same copy.
Worked example
The SHA-256 digest of the three ASCII bytes abc is
ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad
Changing only the last byte, which gives abd, produces
a52d159f262b2c6ddb724a61840befc36eb30c88877a4030b65cbe86298449c9
The two digests share no visible pattern. A one-byte change produces an unrelated digest, which is why equal digests identify the exact bytes.
A device stores the lowest firmware version it accepts: 7. A year ago the vendor signed manifest version 5. It lists image with SHA-256 digest and the role “firmware for model X”. Version 5 has a known flaw. An attacker who recorded that update sends it to the device again. The device runs four checks.
The signature on the manifest verifies with the vendor’s public key. Pass: the vendor really signed this manifest.
The SHA-256 digest of the received image equals . Pass: the image is exactly the one the vendor signed for.
The role “firmware for model X” matches this device and the intended use. Pass.
The version must not be below the stored lowest version, and is false. Reject.
The checks of origin and integrity §1.9 both passed. Only the freshness check §1.26 stopped the downgrade. Without check 4, the device installs a genuine, authenticated, byte-exact image with a known flaw.
The same vendor also signed an entry for a help page, with digest and the role “document”. An installer that accepted any signed entry with a matching digest would accept the bytes of the help page as firmware to run. Check 3 rejects them, because their entry names the role “document”, not “firmware for model X”.
Follow-up questions and limits
Does a match with a checksum §4.32 prove the same thing? No. A non-cryptographic checksum such as a CRC (cyclic redundancy check) detects accidental errors, but an attacker can easily construct different bytes with the same CRC value. A CRC match therefore proves nothing against an attacker.
Are two artifacts with equal digests the same object? They hold the same bytes. They may still be different copies, with different histories, owners and permissions.
Does a signature make the digest unnecessary? No. The signature covers the manifest, and the manifest covers the artifact only through the digest it lists. Each check covers one link of the chain from the signer to the bytes in use.
This answer does not cover how the trusted key is distributed, protected or replaced, or how the content of an artifact is validated.
Fullest treatment: Content integrity versus input authority (§15.34).
Related entries: Integrity (§1.9), Content-addressed identity (§13.2), File descriptor versus pathname (§15.21), Namespace and symlink resolution (§13.9), Cryptographic digest versus path identity (§13.3), Rollback versus anti-rollback (§8.26), Collision resistance (§5.5), Digital signature (§5.14), Time-of-check to time-of-use (TOCTOU) (§9.26). Further reading: [7, 312].