arnaucube
arnaucube/poulpyPublic Self-hosted repository
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/// Default instantiation.
27impl<O> Default for  Montgomery<O> where O:Default {
28    fn default() -> Self {
29        Self {
30            0: O::default(),
31        }
32    }
33}
34
35/// MontgomeryPrecomp is a generic struct storing 
36/// precomputations for Montgomery arithmetic.
37#[derive(Clone, Copy, Debug, PartialEq, Eq)]
38pub struct MontgomeryPrecomp<O>{
39    pub q: O,
40    pub two_q: O,
41    pub four_q: O,
42    pub barrett: BarrettPrecomp<O>,
43    pub q_inv: O,
44    pub one: Montgomery<O>,
45    pub minus_one: Montgomery<O>,
46}