Skip to content

Commit

Permalink
WIP: add expand mask function
Browse files Browse the repository at this point in the history
  • Loading branch information
marsella committed Dec 10, 2024
1 parent 7fc4dfb commit 4144e8f
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion Primitive/Asymmetric/Signature/ML_DSA/Specification.cry
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ parameter
* from [FIPS-203] Section 7.2, Algorithm 27.
*/
type γ1 : #
type constraint (2 ^^ (lg2 γ1) == γ1)
type constraint (fin γ1, 2 ^^ (lg2 γ1) == γ1)

/**
* Low-order rounding range; this defines how to round the signer's
Expand Down Expand Up @@ -765,6 +765,21 @@ ExpandS ρ = (s1, s2) where
s1 = [RejBoundedPoly (ρ # IntegerToBytes`{2} r) | r <- [0..ell-1]]
s2 = [RejBoundedPoly (ρ # IntegerToBytes`{2} (r + `ell)) | r <- [0..k-1]]

/**
* Sample a vector in `R^ell` such that each polynomial in `y` has coefficients
* in the range `[-γ1 + 1, γ1]`.
* [FIPS-204] Section 7.3, Algorithm 34.
*
* Note: This function requires that `μ` is non-negative.
*/
ExpandMask : [64]Byte -> Integer -> [ell]R
ExpandMask ρ μ = y where
type c = width (2 * γ1 - 1)
y = [BitUnpack`{γ1 - 1, γ1} v where
ρ' = ρ # IntegerToBytes`{2} (μ + r)
v = H`{32 * c} ρ'
| r <- [0..ell - 1]]

/**
* Decompose a set of integers mod `q` into a pair `(r1, r0)` such that
* `r === r1 * 2^d + r0 mod q`.
Expand Down

0 comments on commit 4144e8f

Please sign in to comment.