package common // An element of our base ring R which are polynomials over Z_q modulo // the equation Xᴺ = -1, where q=2²³ - 2¹³ + 1 and N=256. // // Coefficients aren't always reduced. See Normalize(). type Poly [N]uint32 // Reduces each of the coefficients to <2q. func (p *Poly) reduceLe2QGeneric() { for i := uint(0); i < N; i++ { p[i] = ReduceLe2Q(p[i]) } } // Reduce each of the coefficients to > 31) // Sets x to {0, 1, ..., (Q-1)/2, (Q-1)/2, ..., 1} x = int32((Q-1)/2) - x if uint32(x) >= bound { return true } } return false } // Splits p into p1 and p0 such that [i]p1 * 2ᴰ + [i]p0 = [i]p // with -2ᴰ⁻¹ < [i]p0 ≤ 2ᴰ⁻¹. Returns p0 + Q and p1. // // Requires the coefficients of p to be normalized. func (p *Poly) Power2Round(p0PlusQ, p1 *Poly) { for i := 0; i < N; i++ { p0PlusQ[i], p1[i] = power2round(p[i]) } } // Sets p to the polynomial whose coefficients are the pointwise multiplication // of those of a and b. The coefficients of p are bounded by 2q. // // Assumes a and b are in Montgomery form and that the pointwise product // of each coefficient is below 2³² q. func (p *Poly) mulHatGeneric(a, b *Poly) { for i := 0; i < N; i++ { p[i] = montReduceLe2Q(uint64(a[i]) * uint64(b[i])) } } // Sets p to 2ᵈ q without reducing. // // So it requires the coefficients of p to be less than 2³²⁻ᴰ. func (p *Poly) mulBy2toDGeneric(q *Poly) { for i := 0; i < N; i++ { p[i] = q[i] << D } }