Documentation

CslibFrontier.Crypto.Primitives.HQC.SupportSampling

HQC support sampling #

SampleSupport2 first draws independent fixed-width words, scales each word by multiply-high into a shrinking interval, then processes the candidates in descending index order. A candidate already present among the corrected later entries is replaced by its index.

The word source here consists of independent fair bits. Relating an XOF to that ideal source is a separate cryptographic obligation. This module does not analyze decryption failure or security.

Main definitions #

Main results #

References #

def Cslib.Crypto.HQC.resolveSupport (offset : ℕ) {count : ℕ} :
(Fin count → ℕ) → Finset ℕ

Process candidates in descending index order. The recursive tail contains the already corrected later entries when the current candidate is tested for collision.

def Cslib.Crypto.HQC.scanSupport (offset : ℕ) {count : ℕ} :
(Fin count → ℕ) → Fin count → ℕ

The source array pass, including the complete increasing scan through corrected later entries. This retains the ordered array, whereas resolveSupport retains its support set.

theorem Cslib.Crypto.HQC.toFinset_scanSupport {offset count : ℕ} (candidates : Fin count → ℕ) :
(List.ofFn (scanSupport offset candidates)).toFinset = resolveSupport offset candidates

The source's nested array scan and membership-based descending resolver have exactly the same output support, even for candidates outside the sampling range.

theorem Cslib.Crypto.HQC.resolveSupport_mem_powersetCard {n offset count : ℕ} (candidates : Fin count → ℕ) (h : ∀ (j : Fin count), offset + ↑j ≤ candidates j ∧ candidates j < n) :
resolveSupport offset candidates ∈ Finset.powersetCard count (Finset.Ico offset n)

In-range candidates produce exactly count distinct positions in the interval.

Draw the whole candidate array in increasing order, then resolve collisions in reverse. The offset form permits induction on a suffix of the source array.

theorem Cslib.Crypto.HQC.eval_sampleSupportFrom_succ (draw : ℕ → ProbComp ℕ) (offset count : ℕ) :
(sampleSupportFrom draw offset (count + 1)).eval = (draw offset).eval.bind fun (r : ℕ) => PMF.map (fun (tail : Finset ℕ) => tail.collisionInsert offset r) (sampleSupportFrom draw (offset + 1) count).eval

One step of the candidate array followed by the recursive suffix and reverse resolution.

noncomputable def Cslib.Crypto.HQC.sampleCandidate (width n offset : ℕ) :

The source's line 5, using independent fair bits in place of the XOF words.

noncomputable def Cslib.Crypto.HQC.sampleSupport2 (width n count : ℕ) :

SampleSupport2 with count output positions. HQC uses width = 32.

noncomputable def Cslib.Crypto.HQC.idealCandidate (n offset : ℕ) :

Ideal uniform selection from the shrinking interval. The value outside a nonempty interval is only a totality convention; all uniformity theorems require offset + count ≤ n.

theorem Cslib.Crypto.HQC.eval_idealCandidate {n offset : ℕ} (h : offset < n) :

The ideal candidate is uniform on the complete shrinking interval.

theorem Cslib.Crypto.HQC.eval_idealSupport {n offset count : ℕ} (h : offset + count ≤ n) :

Independent exact uniform candidates give an exact uniform fixed-cardinality support.

theorem Cslib.Crypto.HQC.eval_sampleCandidate (width n offset : ℕ) :
(sampleCandidate width n offset).eval = PMF.map (fun (u : Fin (2 ^ width)) => offset + ↑u * (n - offset) / 2 ^ width) (Probability.PMF.uniformOfFintype (Fin (2 ^ width)))

A word consists of exactly width fair bits, and line 5 uses multiply-high.

theorem Cslib.Crypto.HQC.sampleCandidate_mem_Ico {width n offset r : ℕ} (h : offset < n) (hr : r ∈ (sampleCandidate width n offset).eval.support) :
r ∈ Finset.Ico offset n

Every actual candidate is in its shrinking interval.

theorem Cslib.Crypto.HQC.sampleSupport2_mem_powersetCard {width n count : ℕ} (h : count ≤ n) {S : Finset ℕ} (hS : S ∈ (sampleSupport2 width n count).eval.support) :

The actual finite-bit sampler always returns exactly the requested number of positions.

def Cslib.Crypto.HQC.supportFromWords (width n : ℕ) {count : ℕ} (words : Fin count → Fin (2 ^ width)) :

The deterministic output from a fixed array of bounded words. This is the formula on line 5 followed by the descending collision pass, without any distributional idealization.

theorem Cslib.Crypto.HQC.supportFromWords_mem_powersetCard {width n count : ℕ} (h : count ≤ n) (words : Fin count → Fin (2 ^ width)) :

Correctness holds for every bounded word array, independently of its distribution.

theorem Cslib.Crypto.HQC.supportFromWords_full (width n : ℕ) (words : Fin n → Fin (2 ^ width)) :

At full weight every word array produces the entire support.

At weight zero the program makes no random choices and returns the empty support.

theorem Cslib.Crypto.HQC.eval_sampleSupport2 (width n count : ℕ) :
(sampleSupport2 width n count).eval = PMF.map (supportFromWords width n) (Probability.PMF.uniformOfFintype (Fin count → Fin (2 ^ width)))

The actual algorithm is exactly its deterministic word-array map under independent uniform words. In particular, this law retains the multiply-high bias.