mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 21:26:41 +01:00
Added Barrett & fixed Montgomery, added tests
This commit is contained in:
@@ -1,19 +1,28 @@
|
||||
use num_bigint::BigUint;
|
||||
use num_traits::cast::ToPrimitive;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub struct BarrettPrecomp<O>(O, O);
|
||||
|
||||
impl<O> BarrettPrecomp<O>{
|
||||
|
||||
#[inline(always)]
|
||||
pub fn new(a:O, b: O) -> Self{
|
||||
Self(a, b)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn value_hi(&self) -> &O{
|
||||
&self.0
|
||||
&self.1
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn value_lo(&self) -> &O{
|
||||
&self.1
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl BarrettPrecomp<u64>{
|
||||
pub fn new(q: u64) -> BarrettPrecomp<u64> {
|
||||
let mut big_r = BigUint::parse_bytes(b"100000000000000000000000000000000", 16).unwrap();
|
||||
big_r = big_r / BigUint::from(q);
|
||||
let lo = (&big_r & BigUint::from(u64::MAX)).to_u64().unwrap();
|
||||
let hi = (big_r >> 64u64).to_u64().unwrap();
|
||||
Self(lo, hi)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user