Skip to main content

decompose

Function decompose 

Source
pub fn decompose(r: i32, gamma2: i32) -> (i32, i32)
Expand description

Decompose a coefficient into high and low parts.

Implements Algorithm 36 of FIPS 204 (Decompose). Given r in [0, q-1] and gamma2, computes (r1, r0) such that r = r1 * alpha + r0 where alpha = 2 * gamma2 and r0 lies in the centered range (-alpha/2, alpha/2]. A special case handles r1 * alpha == q - 1 to keep r1 in the valid range.

  • r: coefficient to decompose (should be in [0, q-1]).
  • gamma2: half the decomposition modulus (parameter-set dependent).

Returns (r1, r0).