Documentation

CslibFrontier.Crypto.Primitives.HQC.PKE

The ideal algebraic HQC public-key encryption core #

This file formalizes the binary algebra of HQC-PKE after its seeds and XOF streams have been expanded. It follows [GAMA+26], §3.6, Algorithms HQC-PKE.Keygen, HQC-PKE.Encrypt and HQC-PKE.Decrypt, pp. 38–40. The public ring is represented by bit strings and multiplication by Mathlib's circulant matrix-vector product, consistently with the HQC syndrome distributions.

The ideal key generator draws y, then x, uniformly at fixed weight ω, followed by uniform h; it publishes (h, s = x + h * y) and retains y as the secret key. Encryption draws (r₂, e, r₁) at weights (ωᵣ, ωₑ, ωᵣ) in the source order and returns (u, v) = (r₁ + h * r₂, Encode(m) + Truncate(s * r₂ + e, ℓ)). Here Truncate(_, ℓ) removes the last ℓ coordinates, so its result has length n - ℓ. Decryption applies Decode to v - Truncate(u * y, ℓ); subtraction is addition in the Boolean ring.

The decryption phase is the encoded message plus the retained prefix of e' = x * r₂ - r₁ * y + e. Consequently any decoder that corrects every error of weight at most Δ recovers the message whenever that retained error has weight at most Δ.

This is an ideal expanded-value model, not the byte-level scheme. In particular, it does not model seed splitting, XOF state, byte encodings, the concrete concatenated Reed–Muller/Reed–Solomon code, primitive-prime admissibility, the decryption-failure rate, or any PKE/KEM security claim.

Main definitions #

Main results #

References #

Parameters of the ideal algebraic HQC-PKE core. The source uses positive values and 0 < ℓ < n; this finite model also admits boundary cases, while retaining all sampling bounds needed to define the fixed-weight laws.

  • n : ℕ

    Length n of vectors in the quasi-cyclic ring.

  • k : ℕ

    Message length k.

  • ell : ℕ

    Number ℓ of trailing coordinates removed from ring words.

  • omega : ℕ

    Secret-vector weight ω.

  • omegaR : ℕ

    Encryption-vector weight ωᵣ.

  • omegaE : ℕ

    Encryption-error weight ωₑ.

  • delta : ℕ

    Number Δ of retained errors corrected by the code.

  • ell_le_n : self.ell ≤ self.n

    Truncation cannot remove more than the complete ring word.

  • omega_le_n : self.omega ≤ self.n

    Secret supports fit in the ring word.

  • omegaR_le_n : self.omegaR ≤ self.n

    Encryption-vector supports fit in the ring word.

  • omegaE_le_n : self.omegaE ≤ self.n

    Encryption-error supports fit in the ring word.

@[reducible, inline]

Length n - ℓ of the codeword and second ciphertext component.

@[reducible, inline]

A ring word in the ideal HQC algebra.

@[reducible, inline]

An HQC-PKE message.

@[reducible, inline]

A word in the image space of the inner error-correcting code.

An expanded HQC-PKE public key (h, s).

@[reducible, inline]

The expanded HQC-PKE secret key is the fixed-weight word y. The key-generation witness x is intentionally not part of the decryption key.

Explicit HQC-PKE encryption coins, in the source's sampling order (r₂, e, r₁).

  • r2 : RingWord P

    Second random fixed-weight ring word.

  • e : RingWord P

    Additive fixed-weight error.

  • r1 : RingWord P

    First random fixed-weight ring word.

@[instance_reducible]
def Cslib.Crypto.HQC.instDecidableEqPKECoins.decEq {P✝ : PKEParams} (x✝ x✝¹ : PKECoins P✝) :
Decidable (x✝ = x✝¹)

An expanded HQC-PKE ciphertext (u, v).

  • u : RingWord P

    Complete quasi-cyclic component u.

  • v : Codeword P

    Truncated codeword component v.

Remove the last ℓ coordinates of a ring word, retaining the prefix of length n - ℓ.

theorem Cslib.Crypto.HQC.truncate_add (P : PKEParams) (x y : RingWord P) :
truncate P (x + y) = truncate P x + truncate P y

Truncation commutes with Boolean-ring addition.

The ideal fixed-weight ring-word sampler, obtained from the already verified ideal HQC support sampler.

The ideal ring-word sampler is exactly uniform on the requested weight layer.

Every supported ideal sample has exactly the requested weight.

The expanded public key determined by public word h and secret witnesses x, y.

Ideal expanded HQC-PKE key generation. It samples y before x, as the source does, and returns only y as the decryption key.

Every supported key pair has fixed-weight witnesses for the published syndrome, while the actual secret key is exactly the sampled y.

Expectation under ideal expanded key generation, exposing the exact source order y, x, then h without exposing the sampler implementation itself.

Ideal HQC-PKE encryption-coin sampling, in source order r₂, e, then r₁.

theorem Cslib.Crypto.HQC.pkeSampleCoins_expect (P : PKEParams) (score : PKECoins P → ENNReal) :
(pkeSampleCoins P).expect score = (sampleFixedWeight P P.omegaR).expect fun (r2 : RingWord P) => (sampleFixedWeight P P.omegaE).expect fun (e : RingWord P) => (sampleFixedWeight P P.omegaR).expect fun (r1 : RingWord P) => score { r2 := r2, e := e, r1 := r1 }

Expectation under ideal encryption-coin sampling, exposing the exact independent source order r₂, e, then r₁ without exposing the sampler implementation itself.

Every supported encryption coin triple has exactly the source's three fixed weights.

def Cslib.Crypto.HQC.pkeEncrypt (P : PKEParams) (encode : PKEMessage P → Codeword P) (pk : PKEPublicKey P) (m : PKEMessage P) (coins : PKECoins P) :

Deterministic expanded HQC-PKE encryption.

The word supplied to the error-correcting decoder during decryption. Subtraction in the source is addition in the Boolean ring.

Deterministic expanded HQC-PKE decryption.

The complete error word from the source's correctness calculation. Its two subtractions are additions because the coefficient ring is Boolean.

theorem Cslib.Crypto.HQC.pkeDecryptInput_encrypt (P : PKEParams) (encode : PKEMessage P → Codeword P) (h x y : RingWord P) (m : PKEMessage P) (coins : PKECoins P) :
pkeDecryptInput P y (pkeEncrypt P encode (expandedPublicKey P h x y) m coins) = encode m + truncate P (pkeDecryptionNoise P x y coins)

HQC-PKE decryption phase. For an honestly formed expanded key and ciphertext, the decoder input is the encoded message plus the retained prefix of e' = x * r₂ - r₁ * y + e.

def Cslib.Crypto.HQC.DecoderCorrects (P : PKEParams) (encode : PKEMessage P → Codeword P) (decode : Codeword P → PKEMessage P) :

A decoder corrects up to Δ errors when it recovers every message from its encoding plus any error word of Hamming weight at most Δ. This follows the plain encoder/decoder convention used by the binary symmetric channel API, without introducing a separate code hierarchy.

theorem Cslib.Crypto.HQC.pkeDecrypt_encrypt_eq_of_weight_le (P : PKEParams) (encode : PKEMessage P → Codeword P) (decode : Codeword P → PKEMessage P) (hcorrect : DecoderCorrects P encode decode) (h x y : RingWord P) (m : PKEMessage P) (coins : PKECoins P) (hnoise : BitString.weight (truncate P (pkeDecryptionNoise P x y coins)) ≤ P.delta) :
pkeDecrypt P decode y (pkeEncrypt P encode (expandedPublicKey P h x y) m coins) = m

Deterministic bounded-error correctness of ideal HQC-PKE.

The ideal algebraic HQC core as an explicit-coin public-key encryption scheme. Decryption is total, so its result is wrapped in some.