Section 13.2

Content-addressed identity

Definition

Content-addressed identity is the practice of naming data by a digest of its exact bytes instead of by its location or a chosen label. A digest is the short, fixed-length value that a cryptographic hash function §5.1, such as SHA-256 §5.2 (Secure Hash Algorithm with a 256-bit output), computes from data; different data give different digests in practice. Identical bytes therefore have one name wherever they are stored, and anyone holding the name can check a copy by recomputing its digest. The name shows sameness only, not authority or meaning.

The idea

A device downloads a file from https://example.com/firmware-v2.bin. That address names a location, and the bytes at a location can change: the server can be updated, a mirror can hold an old copy, and an attacker who controls the server can put anything there. A location name says where to look, not what will be found.

A content-addressed name works the other way round. It names what the bytes are, so it no longer matters where they come from. A copy fetched from an untrusted mirror, a cache or another machine is accepted if its digest equals the name and rejected otherwise. Git, the version-control system, stores every file, directory listing and commit under a digest computed from its content, and container image registries identify image layers the same way. Both can fetch objects from anywhere and still detect a wrong one.

Content addressing does not remove the need for trust; it moves the trust from the bytes to the name. The bytes may come from anyone, but the name must come from someone the receiver trusts: if an attacker chooses both the file and the digest it is compared with, the comparison succeeds and proves nothing. Nor does a digest say what the bytes are for. Whether a file is the approved firmware release, a test input or an old version with a known flaw is a statement that someone with authority must make and bind to the digest.

How it works

A publisher and a receiver use content addressing in five steps.

  1. Choose the bytes. The publisher fixes the exact bytes to publish and computes their digest hh.

  2. Bind the digest to a meaning. The publisher writes a statement that pairs hh with what the bytes are and what they may be used for, such as product, version and role: “release firmware, version 2.1, for board model X”. The publisher signs the statement with a digital signature §5.14, a value that only the holder of a private key can produce and that anyone holding the matching public key can check. A signed list of such pairs is called a signed manifest §13.4.

  3. Authenticate the statement. The receiver checks the signature with a public key it obtained earlier through a trusted route, for example one installed at manufacture. This step settles who vouches for hh.

  4. Check the role. The receiver checks that the statement permits the use it intends: the right product, the right role, and a version no older than the one it already holds, which is the check called anti-rollback §8.26.

  5. Check the bytes. The receiver fetches the bytes from any source, computes their digest and compares it with hh. Equal digests mean that these are the bytes the publisher named.

Worked example

The 4-byte string ABCD, the bytes 0x41, 0x42, 0x43 and 0x44, has this SHA-256 digest, written in hexadecimal:

e12e115acf4552b2568b55e93cbd39394c4ef81c82447fafc997882a02d23677

Changing only the last byte, to give ABCE, produces a digest with no visible relation to the first:

7ff1c8304512f393afdfe46f2f653f03f2f70abd3d97f0de2267cf34b9243165

Git names the same 4 bytes differently, because it uses SHA-1 (Secure Hash Algorithm §14.1 1) and hashes a short header before the content: the text blob 4, then a zero byte, then ABCD. The Git name of the content is therefore

a6bddc4a144046eddf2296a9a4c23d8fae600b15

The same content has different names under different naming rules, so a content-addressed name must state its rule. Many systems write the hash function into the name, as in sha256: followed by the 64 hexadecimal digits of the digest, which also lets a receiver refuse a function it does not accept.

Now an attacker replaces ABCD on a download page with WXYZ, and also replaces the digest printed beside the file with the SHA-256 digest of WXYZ:

21e32f5321cad49ab4cf78ba5ed231e0f36d0c78d34108fda1be939f33fba149

A receiver that compares the file with the digest on the same page finds a match, because the attacker chose both. The comparison is computed correctly, and it proves nothing about the publisher. A receiver that takes its reference from the publisher’s signed statement, which names the digest beginning e12e115a, finds that the downloaded file’s digest begins 21e32f53, and rejects the file.

Suppose instead that the signed statement lists ABCD as a test input, not as firmware. A receiver that downloads ABCD finds a valid signature and a matching digest. Installing those bytes as firmware is still wrong, because the publisher vouched for them in one role only.

Stated precisely

Let HH be the hash function, xx the bytes received, hh the reference digest, and rr the role in which the receiver wants to use xx. Let SS be a statement that binds hh to a set of permitted roles, signed with a private key whose public key kk the receiver trusted before this exchange. The receiver accepts xx for role rr exactly when three conditions hold: the signature on SS verifies under kk; SS binds hh to rr; and H(x)=hH(x) = h.

The equation H(x)=hH(x) = h alone shows only that xx has the digest hh. It identifies xx as the publisher’s bytes under four assumptions.

  1. hh is authentic: it is the digest the publisher chose. The signature provides this; the hash function cannot.

  2. HH is second-preimage resistant §5.4: given the publisher’s bytes, nobody can find different bytes with the same digest.

  3. If an attacker can influence which bytes the publisher signs, HH is also collision resistant §5.5: nobody can find any two different inputs with the same digest. Without this property the attacker could prepare two files with one digest, have the harmless one approved, and deliver the other.

  4. The private signing key is secret, and the signature scheme cannot be forged.

For a hash function with nn-bit digests and no known weakness, the best generic attack needs about 2n2^{n} evaluations to find a second preimage and about 2n/22^{n/2} to find a collision; the second figure is the birthday bound §5.6, since among about 2n/22^{n/2} random nn-bit values two are likely to be equal. For SHA-256 the figures are about 22562^{256} and 21282^{128}. A name truncated to tt bits keeps only about 2t2^{t} and 2t/22^{t/2}.

Limits and common mistakes

A digest shows sameness, not goodness. Equal digests show that the bytes are the ones named, not that they are safe, correct, approved or current.

A digest published beside the file, on the same page or server, detects accidental corruption in transfer, not an attacker who controls that page or server.

An old reference can be authentic. A validly signed statement for version 1.0 still verifies after version 1.0 is found to be flawed, so the statement needs a version number or an expiry date, and the receiver must refuse versions older than the one it holds.

The bytes checked must be the bytes used. A program that checks a file’s digest and then reads the file again by name leaves a window in which the file can be swapped, a time-of-check to time-of-use §9.26 (TOCTOU) error. Read the bytes once into storage that nothing else can change, then check and use that copy.

A broken hash function breaks the naming. Practical collisions are known for MD5 (Message-Digest Algorithm 5) and for SHA-1; the first public SHA-1 collision was announced in 2017 [312]. A content address built on such a function is unsafe wherever an attacker can choose the content.

Content addressing gives identical bytes a single name even when they serve different purposes, so permission granted for one purpose must not be read as permission for another.

Questions answered

Who authenticates the reference digest and the meaning of the artifact?

A party that the receiver already trusts authenticates both the reference digest and the meaning of the artifact; the hash comparison authenticates neither. The reference digest is the expected value that the digest of the received bytes is compared with. Usually the trusted party is the publisher, who signs a statement pairing the digest with what the artifact is and what it may be used for: product, version and role. The receiver verifies the signature with a public key it obtained earlier through a trusted route, such as installation at manufacture. Other trusted routes are a protected channel to the publisher, or a record the receiver made itself when it first accepted the artifact.

The hash comparison then does one job: it shows that the bytes in hand are the bytes the trusted statement names. A digest supplied beside the file by the same untrusted source authenticates nothing, because whoever chose the file also chose the digest. The meaning, too, comes only from the signed statement. A digest identifies bytes and says nothing about whether they are firmware, a test input or an outdated release.

Related entries: Cryptographic hash function (§5.1), Integrity (§1.9), Cryptographic digest versus path identity (§13.3), Manifest (§13.4), Digital signature (§5.14), Second-preimage resistance (§5.4), Collision resistance (§5.5), Rollback versus anti-rollback (§8.26). Further reading: [7, 312].