Nonce-based symmetric encryption and chosen-plaintext security #
A nonce-based cipher ([BS23], Section 5.5, printed pp. 201–202) consists of deterministic
encryption c = E(k, m, N) and deterministic decryption m = D(k, c, N) taking an explicit nonce
N alongside the message m, with correctness requiring D(k, E(k, m, N), N) = m (printed
p. 202). Section 9.5 (printed p. 378) extends both algorithms with an associated-data input d,
writing c = E(k, m, d, N) and D(k, c, d, N) (which outputs a message or reject).
NonceCipher K M D C N represents this general syntax with Option M decryption; plain
nonce-based encryption without associated data is the specialization D = Unit.
Unlike symmetricCPAGameOn / SymmetricINDCPAOn (SymmetricCPA.lean) and
SymmetricCipher.cpaGame / SymmetricCipher.INDCPA (Authenticated.lean), which model randomized
encryption without nonces (where multi-query CPA security requires ciphertext expansion,
SymmetricCipher.not_indcpa_of_ciphertext_length_eq), a NonceCipher is deterministic and relies
on nonce uniqueness across encryption queries to achieve CPA security with zero ciphertext
expansion.
Attack Game 5.3 ([BS23], Section 5.5, printed p. 202) and its associated-data extension
(Section 9.5, Definition 9.7, printed p. 378) restrict encryption queries to equal-length message
pairs in M and pairwise distinct nonces N_i ∈ N \ {N_1, …, N_{i-1}}. To totalize this game for
arbitrary adversaries without partial oracles or [Inhabited C], the typed left-or-right CPA
experiment NonceCipher.cpaExperiment maintains (ok, seen) : Bool × List N, starting from
(true, []):
- While
ok = true, on a query(pair, d, nonce)whose message pair satisfiesvalid pair.msg₀ pair.msg₁ = trueand whose nonce satisfiesvalidNonce nonce = trueandnonce ∉ seen, the challenger recordsnonce :: seenand returnssome (E.encrypt k (pair.select b) d nonce). - On any query with an inadmissible message pair, an invalid nonce, or a repeated nonce (or once
ok = false), the challenger setsok := falseand returnsnonewithout invokingE.encrypt. - When the adversary halts with
guess : Bool, the experiment outputsok && guess.
For every admissible, nonce-respecting adversary, ok stays true and every query returns
some (E.encrypt k (pair.select b) d nonce). Any run that submits an out-of-domain message pair,
an out-of-domain nonce, or a repeated nonce sets ok := false independently of the challenge bit
b, never calls E.encrypt outside its valid domain, requires no [Inhabited C], and outputs
false under both b = false and b = true, contributing zero distinguishing advantage.
NonceCipher.INDCPA defines asymptotic uniform chosen-plaintext security at D = Unit over bit
words (List Bool), adapting IsOraclePPT encBool distinguishers through the fixed canonical
word codec NonceCipher.unitCPACodec, which encodes (pair, (), nonce) as
frame pair.msg₀ ++ frame pair.msg₁ ++ nonce and encodes optional ciphertext replies via
encOption encBits. Fixing the codec avoids free codec parameters whose padding could make runtime
budgets vacuous.
This module provides definitions, the canonical word codec, and the ProbOracleComp.runWith
evaluation equation for cpaExperiment. Nonce-based counter mode, Theorem 5.6, and the
counter-overlap separation for unscaled nonces are in
CslibFrontier.Crypto.Computational.Encryption.NonceCTR (#5793); nonce-based ciphertext integrity
and AEAD (Attack Game 9.3, Definitions 9.8–9.9, printed p. 379) are deferred to their first
consumer in #5865.
Main definitions #
Cslib.Crypto.NonceCipher: deterministic nonce-based cipher with associated data.Cslib.Crypto.NonceCipher.Correct: decryption inverts encryption on all inputs.Cslib.Crypto.NonceCipher.cpaOracle,Cslib.Crypto.NonceCipher.cpaExperiment: stateful left-or-right CPA challenger and experiment.Cslib.Crypto.NonceCipher.decodeFramed,Cslib.Crypto.NonceCipher.unitCPACodec: total frame-prefix parser and canonical word codec forD = UnitCPA queries.Cslib.Crypto.NonceCipher.INDCPA: asymptotic uniform CPA security for word-level nonce-based ciphers.
References #
- D. Boneh, V. Shoup, A Graduate Course in Applied Cryptography, Version 0.6, Section 5.5 (syntax, Attack Game 5.3, Definition 5.3, and equation (5.30), printed pp. 201–202) and Section 9.5 (associated-data syntax and Definition 9.7, printed p. 378).
A deterministic nonce-based symmetric cipher with key space K, message space M,
associated-data space D, ciphertext space C, and nonce space N ([BS23],
Section 5.5, printed pp. 201–202, for D = Unit; Section 9.5, printed p. 378, with associated
data).
- encrypt : K → M → D → N → C
Deterministically encrypt message
mwith associated datadand noncenonceunder keyk. - decrypt : K → C → D → N → Option M
Deterministically decrypt ciphertext
cwith associated datadand noncenonceunder keyk, returningnoneon rejection.
Perfect decryption correctness ([BS23], Section 5.5, printed p. 202; Section 9.5, printed p. 378): decrypting a ciphertext under the same key, associated data, and nonce recovers the plaintext.
Stateful left-or-right challenge oracle for NonceCipher.cpaExperiment, totalizing the
equal-length and unique-nonce query rules of [BS23], Section 5.5, Attack Game 5.3
(printed p. 202) and Section 9.5, Definition 9.7 (printed p. 378). On state (ok, seen):
Typed left-or-right chosen-plaintext experiment for a nonce-based cipher, totalizing
[BS23], Section 5.5, Attack Game 5.3 (printed p. 202) and Section 9.5, Definition 9.7
(printed p. 378). Sample k ← sampleKey, run adversary from initial state (true, []) against
E.cpaOracle valid validNonce k b, and output ok && guess from the final (guess, ok, seen).
For admissible, nonce-respecting executions, ok remains true and every query returns
some (E.encrypt k (pair.select b) d nonce). Any execution submitting an inadmissible pair, an
invalid nonce, or a repeated nonce sets ok := false independently of b, never calls
E.encrypt outside its valid domain, requires no [Inhabited C], and outputs false for both
challenge bits b = false and b = true, contributing zero distinguishing advantage.
Output distribution of NonceCipher.cpaExperiment via ProbOracleComp.runWith.
Canonical word codec and asymptotic CPA security #
decodeFramed succeeds with (w, u) if and only if frame w ++ u = v.
Canonical parameter-free word codec for D = Unit nonce-based CPA queries:
encodes (pair, (), nonce) on the single word channel as
frame pair.msg₀ ++ frame pair.msg₁ ++ nonce, decodes two framed message prefixes followed by the
raw nonce suffix via decodeFramed, and encodes Option (List Bool) replies with
encOption encBits (none ↦ [], some ct ↦ true :: ct).
Adaptive chosen-plaintext security for a family of word-level nonce-based ciphers without
associated data ([BS23], Section 5.5, Attack Game 5.3 and Definition 5.3, printed p. 202),
against uniform strict IsOraclePPT encBool distinguishers adapted via unitCPACodec.