Identify which nonce property the operation requires
A nonce is a value intended for one-time use within a particular operation or protocol scope. Uniqueness and unpredictability requirements depend on that scope. This lesson focuses on authenticated-encryption calls that require distinct nonces under one key. A nonce, secret key, random authentication token, salt and initialization vector are not interchangeable labels.
Some nonces can be sent publicly with ciphertext. Public visibility does not permit reuse. A construction allowing a predictable counter also does not automatically satisfy an authentication challenge requiring unpredictability. Avoid both “anything random works” and “a secret value may repeat.” List uniqueness, unpredictability, length and association with a key separately, then consult the selected algorithm and protocol contract.
Construct the two-sender collision
Two senders sharing key K and both starting a counter at zero collide on their first nonce. Local uniqueness does not establish uniqueness across every encryption under that key. A fixed sender field plus a per-sender counter only works when the fixed fields are distinct within the shared-key scope.
A teaching split of thirty-two sender bits and sixty-four counter bits totals ninety-six bits, but is not a universal format recommendation. A counter must not wrap into earlier values. Cloning a device configuration can also duplicate its supposedly distinct sender field. Uniqueness therefore depends on allocation and lifecycle policy, not only field width. State who assigns identities and what happens at exhaustion before treating the construction as a valid nonce source.
| Field | Illustrative width | Required condition |
|---|---|---|
| Sender ID | 32 bits | Distinct among senders sharing the key |
| Counter | 64 bits | No rollback or wrap under the same ID |
| Total | 96 bits | Matches the selected scheme's constraints |
Preserve uniqueness across restart
After sender A uses zero through nine, restarting its in-memory counter at zero repeats values under the same key. A volatile increment alone provides no cross-restart guarantee. One possible allocation strategy reserves and persists a range before use, skipping unused numbers after interruption. Contiguous numbering is less important than nonreuse in this setting.
Changing only a key label while retaining the same key bytes does not create a new cryptographic scope. Distinguish key identity from key material. Multiple processes, backup rollback and device restoration need the same reasoning. Explain which allocation state is made durable before use instead of merely saying the counter was saved. The lesson analyzes nonce-source conditions rather than providing an independently invented encryption library.
Random generation still has collision probability
For n uniform b-bit draws, collision risk is not described only by one draw's probability. There are n(n minus one)/2 distinct pairs. In an appropriate low-collision approximation, dividing that pair count by2^b gives a useful scale. Biased generation or cloned generator state also invalidates the independent-uniform assumption.
This is not a claim that random nonces are universally wrong. Check the selected algorithm's lengths, usage limits and acceptable collision risk. Unpredictability additionally requires a suitable entropy source when the protocol needs it. Seeing no repeats in a modest test does not prove uniqueness for every future use. Distinguish deterministic allocation guarantees from probabilistic collision analysis and from tests of one particular generated sequence.
Separate encryption nonce reuse from ciphertext retransmission
Calling encryption again on another plaintext or authentication context with the same key/nonce violates the relevant uniqueness requirement. Retransmitting identical ciphertext bytes already produced is a different event. The protocol must still decide whether replay is acceptable. Unique encryption nonces alone do not guarantee that a receiver applies one business operation only once.
Compare this with operation IDs and Inbox processing: cryptographic invocation uniqueness and business-effect deduplication protect different boundaries. A valid ciphertext can still be replayed unless the protocol supplies appropriate receiver state or freshness rules. Do not treat adding a nonce as complete replay prevention. Explain authenticated integrity, replay handling and application idempotence separately, especially when cancellation or retries cause identical messages to appear again.
Return to the selected algorithm’s contract
Modes such as GCM specify concrete requirements for keys, nonces, tags and usage limits. Do not turn the teaching allocation diagram into a custom encryption scheme or arbitrarily truncate fields. Prefer the selected library or protocol interface and follow its preconditions. Even an API generating nonces automatically needs a clear shared-key and restored-state contract.
Check primary AEAD and mode specifications instead of generalizing from terminology. Those sources support understanding the requirement; they do not mean a real service's key management has been audited. This lesson uses no user keys or real messages. Solve the two-sender counter examples and state precisely what must stay secret, what must remain distinct and which shared scope the condition covers. Those distinctions are the intended practical result.
Exercise: identify the allocation scope
If A and B share a key and each counts zero, one, two, local nonrepetition is insufficient. Values repeat across encryptions under that key. A sender-field construction needs genuinely distinct assignments and a restart policy that does not reuse counter values within the same key scope.
Renaming K1 to K2 without changing key bytes does not fix reuse. Nor does the presence of a nonce automatically make applying a replayed ciphertext's business operation twice safe. Replay and idempotence require their own contract. Explain uniqueness, unpredictability, actual key material and retransmission as separate questions. The answer should identify the violated scope rather than simply recommending a longer or more random-looking value.