Section 15.37

Threshold and sentinel semantics

Definition

A threshold is an ordinary value of a setting that marks a decision boundary, as in “accept a key of at least 10 bytes”. A sentinel is a reserved value of the same setting that stands not for an amount but for a separate state, such as “check disabled”, “not set” or “unknown”. Threshold and sentinel semantics is the rule that says, for every value a field can hold, which of the two it is, and therefore what a comparison does with it.

The idea

A security policy stores the minimum encryption key size §7.27 in one byte. Bluetooth Low Energy (BLE) §7.1 allows encryption keys of 7 to 16 bytes, so the meaningful thresholds are 7 to 16. One tool writes 255 and means “no minimum: the check is disabled”. The device reads the same byte as an ordinary minimum and tests whether the key size is at least 255. No legal key passes, and every connection is refused. A device whose decoder reads 255 as “disabled” would instead have switched the check off and accepted a 7-byte key. Each program is correct by its own reading.

The core idea is that numeric order is not the order of meaning. 255 is larger than 16, but if 255 means “disabled”, it is the least strict setting, not the strictest. A field that mixes amounts and reserved states holds two kinds of values, and every program that touches it must sort a value into its kind before comparing or computing with it.

Sentinels are common. The C function getchar returns a character code from 0 to 255 or the sentinel EOF (end of file), a negative number meaning “no more input”. The function poll of POSIX (Portable Operating System Interface, the standard interface of Unix-like operating systems) takes a timeout §9.34 in milliseconds in which 0 means “do not wait” and a negative value means “wait forever”. A program that picks the smaller of two timeouts, min(-1, 1000), gets −1-1 and waits forever instead of at most one second.

How it works

  1. Define the ordinary domain: the values that are amounts, here the key sizes 7 to 16.

  2. Name every special state the field must express, such as Disabled (this check imposes nothing), Default (use the built-in value) and Unknown. Give each a reserved value outside the ordinary domain or, better, a separate field.

  3. Declare every other value invalid. With 7 to 16 as amounts and 255 as Disabled, the values 0 to 6 and 17 to 254 are neither.

  4. Decode before use. Turn the raw byte into a typed value, written here as Minimum(10)\mathrm{Minimum}(10) or Disabled\mathrm{Disabled}, before any comparison or arithmetic. Reject an invalid value when the policy is loaded instead of clamping it to the nearest legal value.

  5. Give each state its decision, including a field that is absent. A security check should fail closed §1.13: a missing or invalid setting leads to the stricter outcome, never to Disabled.

  6. Share one definition. The program that writes the policy, the validator, the program that enforces it, and every display or report must decode alike. Tie the decoding to a version number of the format, so that an older program does not read a reserved value added later as an amount.

A representation that cannot mix up the two kinds is safer than a convention on one integer: either two fields, one saying whether the check is enabled and one holding the minimum, or a tagged union, a value that carries a tag naming its kind and a number only for the kind that has one. Rust and Swift provide tagged unions directly, as enumerations whose variants carry data.

The same problem appears in a tri-state policy field: a yes-or-no setting with a third state, such as “not applicable”. Stored as 0, 1 and 2, the third state reads as “yes” to any program that treats every non-zero value as yes.

Worked example

Take a key of kk bytes, with legal sizes 7≤k≤167 \le k \le 16, ten sizes in all, since 16−7+1=1016 - 7 + 1 = 10. The field is decoded as above.

Tests for this field sit at its boundaries, where mistakes concentrate: raw values 6, 7, 16 and 17, the reserved value 255, one invalid value from each gap, and key sizes 6, 7, 16 and 17. This is boundary-value testing §10.31: each test sits just inside or just outside a boundary.

Stated precisely

Let R={0,1,…,255}R = \{0, 1, \dots, 255\} be the set of raw values a one-byte field can hold, and let L={7,8,…,16}L = \{7, 8, \dots, 16\} be the ordinary domain. The semantics of the field is a function σ\sigma that gives every raw value exactly one meaning: σ(r)=Minimum(r)\sigma(r) = \mathrm{Minimum}(r) for r∈Lr \in L, σ(255)=Disabled\sigma(255) = \mathrm{Disabled}, and σ(r)=Invalid\sigma(r) = \mathrm{Invalid} for every other rr. For a key of size kk, pass(k,Minimum(m))⇔k≥m,pass(k,Disabled)=true,\mathrm{pass}(k, \mathrm{Minimum}(m)) \iff k \ge m, \qquad \mathrm{pass}(k, \mathrm{Disabled}) = \text{true}, and a policy that contains Invalid\mathrm{Invalid} is rejected before any check runs. The contract has three parts: σ\sigma is total, giving every raw value a stated meaning, if only Invalid; every program that writes, checks, enforces or displays the field uses the same σ\sigma, fixed by the format version; and comparisons and arithmetic apply only to the number mm inside Minimum(m)\mathrm{Minimum}(m), never to a reserved raw value.

Strictness is the order of the sets of accepted sizes, which is set inclusion §15.40, not the order of raw values. Let Acc(v)\mathrm{Acc}(v) be the set of legal sizes that setting vv accepts, and let S⊂TS \subset T mean that every element of SS is in TT and TT has more elements. Then Acc(Minimum(16))={16}⊂Acc(Minimum(10))={10,…,16}⊂Acc(Disabled)={7,…,16}.\mathrm{Acc}(\mathrm{Minimum}(16)) = \{16\} \subset \mathrm{Acc}(\mathrm{Minimum}(10)) = \{10, \dots, 16\} \subset \mathrm{Acc}(\mathrm{Disabled}) = \{7, \dots, 16\}. From strictest to least strict, the raw values run 16, 10, 255: the largest number is the least strict setting.

Limits and common mistakes

A reserved value can collide with a real amount later. If a future format allows minimums up to 255, the sentinel 255 becomes ambiguous; a separate field or a tagged union avoids this.

Absent and invalid must not silently become Disabled or 0. A reader that turns a missing field into 0 and then tests k≥0k \ge 0 has disabled the check without anyone choosing to: a fail-open §1.14 outcome.

Floating-point numbers §4.49 have a built-in special value that behaves like a sentinel, NaN (not a number). Every ordered comparison with NaN is false, so if (x < min) reject lets a NaN through, while if (!(x >= min)) reject rejects it.

A sentinel is not a measurement. A timeout recorded as 65,535 in a column of response times §9.32 corrupts any average over that column; keep the status and the measured value in separate fields.

Authenticating the bytes does not fix their meaning. A message authentication code §5.7 (MAC) shows that the bytes came from a holder of the key, not that writer and reader decode them alike, so the format version must be among the authenticated bytes.

Repairing invalid values hides errors. Clamping the invalid value 200 to the nearest legal value, 16, turns a broken policy into the strictest one; a reader that instead replaces every invalid value by 7 turns it into the weakest. Either way, nobody learns that the policy was broken. Likewise, a report that prints “minimum key size: 255” misleads a reviewer; reports must print the decoded state.

Questions answered

Is a sentinel above every legal key size a strictest policy or a disabled comparison?

Neither by itself: a value above every legal key size has no meaning until the format’s specification says which it is, and the two readings give opposite results. Read as an ordinary minimum, such as 255 when legal sizes are 7 to 16 bytes, it requires a key size of at least 255, which no legal key meets, so every key is refused: a deny-all policy, stricter than the strictest real minimum of 16. Read as a reserved value meaning Disabled, it skips the comparison, so every legal size passes, the weakest, 7 bytes, included: the least strict setting.

To find out which it is, read the decoding in every program that writes, checks, enforces or displays the field, and test the reserved value together with the legal boundaries 7 and 16. If the programs disagree, the field is a defect whatever each reading intends. A sound design removes the question: it represents Disabled with a separate flag or a tagged value, rejects every raw value that is neither a legal size nor a declared reserved value, and makes a missing or invalid field fail closed.

Related entries: JSON Schema (§12.27), Boundary-value testing (§10.31), Authentication coverage (§5.41), Canonical record (§13.13), Encryption key size (§7.27), Fail closed (§1.13), Fail open (§1.14), Binary floating-point representation, special values, and rounding (§4.49), Set inclusion and policy order (§15.40).