Section 1.9

Integrity

Definition

Integrity is the security property that data, or the state of a system, changes only in authorized ways. Where an attacker can reach the data, in transit or in storage, integrity in practice means detection: the receiver can tell whether the bytes it holds are exactly the bytes an authorized party produced, and rejects them otherwise. The check always covers specific bytes. A checksum §4.32 detects accidental errors only; deliberate changes need a check value that an attacker cannot recompute, such as a message authentication code §5.7 or a digital signature §5.14.

The idea

A controller sends the command “pay 10 to account A” over a network that an attacker controls. Encryption alone does not stop the attacker. With a cipher that combines a stream of key bits with the plaintext by exclusive or, as stream ciphers do, flipping a ciphertext bit flips the same plaintext bit, so an attacker who knows where the account letter sits can turn A into B without reading anything. A guarantee that nobody can read the message is not a guarantee that nobody can change it. Integrity is the separate question: can the message change without the receiver noticing?

A tamper-evident seal on an envelope is a fair picture. The seal does not stop anyone from opening the envelope, but a broken seal shows that someone did, and the recipient refuses the letter. The picture stops being accurate in one way: a cryptographic check covers only the bytes it was computed over, not the whole envelope, so any field left outside it can change freely. One limit carries over unchanged: an intact seal says nothing about when the letter was sealed, so an old, genuine letter delivered a second time looks just as valid, and the same holds for a check value.

How it works

The sender computes a short check value over the bytes to protect and sends it with them. The receiver recomputes or verifies the check value over the bytes it received and rejects the message on any mismatch. The mechanisms differ in who can compute a valid check value.

The receiver then follows a fixed order.

  1. Determine the exact bytes that the check value covers. The protocol defines this list, called the authentication coverage §5.41.

  2. Verify the check value over those bytes before any field is used to make a decision.

  3. On a mismatch, reject the whole message and keep nothing from it.

  4. Parse and act on the same bytes that were verified, not on a second copy that something could have changed between the check and the use. That gap is called a time-of-check to time-of-use §9.26 (TOCTOU) error.

Every field that changes what the receiver does, or how it reads the rest of the message, must lie inside the covered bytes: the identity of the intended receiver, the operation, the format version, every length field, the payload, and a freshness value such as a counter. A field outside the covered bytes is outside the guarantee.

Worked example

A message has two bytes: an operation code 0x01, meaning pay, and an amount 0x0A, which is 10 in decimal. The sender appends an 8-bit checksum, the sum of the bytes modulo 256: 0x01 plus 0x0A is 0x0B. An attacker changes the amount to 0x63, which is 99, and replaces the checksum with 0x01 plus 0x63, which is 0x64. The receiver adds the two bytes, gets 0x64, finds a match and pays 99. The checksum works against accidents and gives no protection against a deliberate change.

Replace the checksum with a tt-bit MAC tag. For an ideal MAC, one whose tags look like random values to anyone without the key, an attacker can only guess the tag of a changed message, and one guess is right with probability 2−t2^{-t}. A deliberately tiny 4-bit tag has 24=162^4 = 16 possible values, so one guess succeeds with probability 1/16=0.06251/16 = 0.0625, or 6.25%. A 32-bit tag has 232=4,294,967,2962^{32} = 4{,}294{,}967{,}296 possible values. A receiver that lets the attacker try 1,000 guesses per second for a whole day allows 1,000×86,400=86,400,0001{,}000 \times 86{,}400 = 86{,}400{,}000 guesses, and the chance that at least one succeeds is at most 86,400,000/4,294,967,296≈0.02086{,}400{,}000 / 4{,}294{,}967{,}296 \approx 0.020, about 2%. With a 128-bit tag, the same day of guessing succeeds with probability at most 86,400,000/212886{,}400{,}000 / 2^{128}, about 2.5×10−312.5 \times 10^{-31}.

Now the failure that the question below asks about. A payment message has three parts: a 1-byte account number, a 2-byte amount and a tag. The sender computes the tag over the amount only. The genuine message carries the account 0x0A (account 10), the amount 0x00 0x0A (10) and the tag TT, the MAC of the two amount bytes. The attacker changes the account byte to 0x0B (account 11) and leaves everything else alone. The receiver computes the MAC of the two amount bytes, gets TT again, accepts, and pays 10 to account 11. The cryptography worked perfectly; the account byte was never protected.

A last case passes every integrity check. The attacker records yesterday’s genuine message, with its correct tag, and sends it again today. The bytes are exactly the bytes the key holder produced, so verification succeeds and the receiver pays a second time. Integrity says that the bytes are unchanged, not that they are new. Stopping this replay attack §1.26 needs a freshness value inside the covered bytes, such as a counter that the receiver requires to be larger than the last one it accepted.

Stated precisely

For a MAC, the standard security notion is existential unforgeability under chosen-message attack. The attacker may obtain valid tags for any messages it chooses. It wins if it then produces a message it never asked about, together with a tag that verifies. The MAC is called (s,q,v,ε)(s, q, v, \varepsilon)-secure when every attacker that runs for at most ss steps, requests at most qq tags and submits at most vv candidate pairs to the verifier wins with probability at most ε\varepsilon. Online guessing consists of exactly these verification queries: for an ideal tt-bit tag, ε\varepsilon is at most about v⋅2−tv \cdot 2^{-t}, the bound computed in the worked example. In use, ε\varepsilon must stay tiny for every ss, qq and vv that an attacker could afford.

The receiver’s guarantee is then this. Let mm be the covered bytes that the receiver verified and kk the key. If the tag on mm verifies under kk, then mm is exactly a byte string that a holder of kk tagged. The guarantee needs three assumptions: kk is uniformly random, kk is known only to authorized parties, and the MAC is unforgeable. The guarantee says nothing about bytes outside mm, about whether mm was tagged for this receiver or this purpose, about when mm was tagged, or about whether its content is correct.

For a digest, let HH be the hash function, xx the original object, and d=H(x)d = H(x) the digest that the receiver obtained over a channel the attacker cannot change. If the receiver accepts an object x′x' only when H(x′)=dH(x') = d, then x′=xx' = x unless the attacker found a different input with the same digest. If the attacker had no influence over xx, such an input is a second preimage, and second-preimage resistance §5.4 makes finding one infeasible. If the attacker could shape xx before dd was fixed, for example by submitting the object for publication, the attacker could have prepared two objects with one digest in advance. The guarantee then needs collision resistance §5.5, the infeasibility of finding any two inputs with the same digest. If the attacker can replace dd as well, no property of HH helps: the attacker computes the digest of its own object.

Integrity also has a meaning about information flow: data from a less trusted source must not influence more trusted state. K. J. Biba stated this in 1977 as two rules for a model of integrity levels: a process may not read data of lower integrity than its own, and may not write data of higher integrity than its own [445]. Practical systems let untrusted input influence trusted state only after a check vouches for it, which is called integrity endorsement §1.49.

Limits and common mistakes

A matching checksum or digest proves nothing against an attacker who can change both the data and the check value.

Integrity covers only the bytes inside the check. Fields outside it, and the way the receiver interprets the covered bytes, are not protected.

Integrity is not freshness. A genuine old message passes every integrity check.

Integrity is not authorization §1.7 and not correctness. A holder of a valid key can produce harmful but authentic data, and a thief who steals a key produces forgeries that verify.

Integrity is not availability §1.10. An attacker who changes or drops messages cannot make the receiver accept them, but can make the receiver reject everything.

A tag comparison that stops at the first differing byte leaks, through its running time, how many leading bytes of a guess were right. Tags are compared with a constant-time comparison §4.33, one that takes the same time whatever the bytes are.

Questions answered

Can an attacker change a field excluded from the authentication §1.6 input?

Yes. An attacker can change a field that lies outside the authentication input, the exact bytes over which the tag or signature was computed, and the check still succeeds, because the check never looked at that field. For example, if a payment message tags the amount but not the account number, the attacker rewrites the account number and the receiver accepts the message with its genuine tag. The strength of the cryptography does not matter: a 256-bit tag protects exactly the bytes it covers and nothing else.

There are two remedies. Put into the authentication input every field that affects what the receiver does or how it reads the message: the intended receiver, the operation, the format version, every length field, the payload and a freshness counter. Or make the receiver ignore the uncovered field completely. A field may stay outside the authentication input only if no value of that field can change the receiver’s behavior.

Related entries: Cryptographic hash function (§5.1), Second-preimage resistance (§5.4), Collision resistance (§5.5), Message authentication code (MAC) (§5.7), HMAC (§5.8), Digital signature (§5.14), Authenticated encryption (AEAD) (§5.16), Merkle trees and authenticated data structures (§5.43), Authentication coverage (§5.41), Replay attack (§1.26), Constant-time comparison (§4.33). Further reading: [7, 8, 67, 445].