poulpy/src/modulus/montgomery.rs
src/modulus/montgomery.rsRaw
1use crate::modulus::barrett::BarrettPrecomp;
2
3/// Montgomery is a generic struct storing
4/// an element in the Montgomery domain.
5#[derive(Clone, Copy, Debug, PartialEq, Eq)]
6pub struct Montgomery<O>(pub O);
7
8/// Implements helper methods on the struct Montgomery<O>.
9impl<O> Montgomery<O>{
10
11 #[inline(always)]
12 pub fn new(lhs: O) -> Self{
13 Self(lhs)
14 }
15
16 #[inline(always)]
17 pub fn value(&self) -> &O{
18 &self.0
19 }
20
21 pub fn value_mut(&mut self) -> &mut O{
22 &mut self.0
23 }
24}
25
26/// MontgomeryPrecomp is a generic struct storing
27/// precomputations for Montgomery arithmetic.
28#[derive(Clone, Copy, Debug, PartialEq, Eq)]
29pub struct MontgomeryPrecomp<O>{
30 pub q: O,
31 pub barrett: BarrettPrecomp<O>,
32 pub q_inv: O,
33 pub one: Montgomery<O>,
34 pub minus_one: Montgomery<O>,
35}