Skip to content

Commit 51890dd

Browse files
authored
module-lattice: impl ctutils::CtEq for Polynomial, Vector, and NttMatrix (#285)
1 parent 77b51ef commit 51890dd

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

module-lattice/src/algebra.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,19 @@ impl<F: Field> Neg for &Polynomial<F> {
230230
}
231231
}
232232

233+
#[cfg(feature = "ctutils")]
234+
impl<F: Field> CtEq for Polynomial<F>
235+
where
236+
F::Int: CtEq,
237+
{
238+
fn ct_eq(&self, other: &Self) -> Choice {
239+
self.0.ct_eq(&other.0)
240+
}
241+
}
242+
243+
#[cfg(feature = "ctutils")]
244+
impl<F: Field<Int: CtEq>> CtEqSlice for Polynomial<F> {}
245+
233246
/// A `Vector` is a vector of polynomials from `R_q` of length `K`.
234247
///
235248
/// Vectors can be added, subtracted, negated, and multiplied by field elements.
@@ -303,6 +316,19 @@ impl<F: Field, K: ArraySize> Neg for &Vector<F, K> {
303316
}
304317
}
305318

319+
#[cfg(feature = "ctutils")]
320+
impl<F: Field, K: ArraySize> CtEq for Vector<F, K>
321+
where
322+
F::Int: CtEq,
323+
{
324+
fn ct_eq(&self, other: &Self) -> Choice {
325+
self.0.ct_eq(&other.0)
326+
}
327+
}
328+
329+
#[cfg(feature = "ctutils")]
330+
impl<F: Field<Int: CtEq>, K: ArraySize> CtEqSlice for Vector<F, K> {}
331+
306332
/// An `NttPolynomial` is a member of the NTT algebra `T_q = Z_q[X]^256` of 256-tuples of field
307333
/// elements.
308334
///
@@ -537,3 +563,16 @@ where
537563
NttVector(self.0.iter().map(|x| x * rhs).collect())
538564
}
539565
}
566+
567+
#[cfg(feature = "ctutils")]
568+
impl<F: Field, K: ArraySize, L: ArraySize> CtEq for NttMatrix<F, K, L>
569+
where
570+
F::Int: CtEq,
571+
{
572+
fn ct_eq(&self, other: &Self) -> Choice {
573+
self.0.ct_eq(&other.0)
574+
}
575+
}
576+
577+
#[cfg(feature = "ctutils")]
578+
impl<F: Field<Int: CtEq>, K: ArraySize, L: ArraySize> CtEqSlice for NttMatrix<F, K, L> {}

0 commit comments

Comments
 (0)