Documentation

CslibFrontier.Crypto.Computational.LWE.Decoding

Scalar bit encoding, decoding, and binary noise bounds modulo 2 ^ w #

For modulus 2 ^ w, a bit μ is encoded as μ * 2 ^ (w - 1) (encodeBit) and decoded by selecting the half-open middle half [2 ^ w / 4, 3 * 2 ^ w / 4) of the canonical residue interval (decodeResidue, decode). Correctness holds whenever the additive integer error has magnitude strictly below one quarter of 2 ^ w (decode_eq_of_error). This module also hosts the common magnitude bound natAbs_binarySum_le for integer subset sums over Boolean coefficients.

Main definitions #

Main results #

References #

def Cslib.Crypto.LWE.encodeBit (w : ℕ) (μ : Bool) :
ZMod (2 ^ w)

Half-modulus encoding: false ↦ 0 and true ↦ 2 ^ (w - 1).

Decode a natural residue representative modulo 2 ^ w by selecting the half-open middle half [2 ^ w / 4, 3 * 2 ^ w / 4) of [0, 2 ^ w).

@[simp]
theorem Cslib.Crypto.LWE.decodeResidue_eq_true_iff (w value : ℕ) :
decodeResidue w value = true ↔ 2 ^ w ≤ 4 * value ∧ 4 * value < 3 * 2 ^ w

Characterization of decodeResidue as the middle half of [0, 2 ^ w).

@[simp]

At width zero, residue zero decodes to false.

Rounding a natural residue representative value modulo 2 ^ w via decodeResidue is computable in polynomial time for unary w and binary value.

def Cslib.Crypto.LWE.decode (w : ℕ) (x : ZMod (2 ^ w)) :

Decode the half-open middle half of the canonical residue interval as true.

@[simp]
theorem Cslib.Crypto.LWE.decode_eq_true_iff (w : ℕ) (x : ZMod (2 ^ w)) :
decode w x = true ↔ 2 ^ w ≤ 4 * x.val ∧ 4 * x.val < 3 * 2 ^ w

Characterization of decoding to true as the middle half of the canonical residue interval.

@[simp]
theorem Cslib.Crypto.LWE.decode_zero (x : ZMod (2 ^ 0)) :

Width zero has only the zero residue, which decodes to false.

theorem Cslib.Crypto.LWE.decode_one (x : ZMod (2 ^ 1)) :

At width one, the single bit is already the decoded message.

theorem Cslib.Crypto.LWE.decode_eq_xor_highBits {w : ℕ} (hw : 2 ≤ w) (x : ZMod (2 ^ w)) :
decode w x = (x.val.testBit (w - 1) ^^ x.val.testBit (w - 2))

The half-open middle interval is exactly the set where the two highest bits differ. This identity holds on every residue, including both quarter-boundary ties.

theorem Cslib.Crypto.LWE.decode_eq_of_error {w : ℕ} (hw : 0 < w) (μ : Bool) (error : ℤ) (herror : 4 * error.natAbs < 2 ^ w) :
decode w ↑(↑μ.toNat * 2 ^ (w - 1) + error) = μ

Decoding recovers a bit whenever its integer error has magnitude strictly below one quarter of the modulus. The strict inequality excludes the decoder's asymmetric ties.

theorem Cslib.Crypto.LWE.natAbs_binarySum_le_sum {κ : Type u_1} [Fintype κ] (bits : κ → Bool) (error : κ → ℤ) :
(∑ j : κ, ↑(bits j).toNat * error j).natAbs ≤ ∑ j : κ, (error j).natAbs

The magnitude of a binary-selected integer sum is at most the sum of term magnitudes.

theorem Cslib.Crypto.LWE.natAbs_binarySum_le {κ : Type u_1} [Fintype κ] (bits : κ → Bool) (error : κ → ℤ) {bound : ℕ} (herror : ∀ (j : κ), (error j).natAbs ≤ bound) :
(∑ j : κ, ↑(bits j).toNat * error j).natAbs ≤ Fintype.card κ * bound

Errors bounded uniformly by bound yield a binary-selected sum of magnitude at most |κ| * bound.