Skip to content

Commit

Permalink
bigint: Add modulus bit length to Modulus.
Browse files Browse the repository at this point in the history
  • Loading branch information
briansmith committed Nov 8, 2023
1 parent 5ed0a45 commit cbcac26
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/arithmetic/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use super::n0::N0;
pub(crate) use super::nonnegative::Nonnegative;
use crate::{
arithmetic::montgomery::*,
bits, c, cpu, error,
c, cpu, error,
limb::{self, Limb, LimbMask, LIMB_BITS},
polyfill::u64_from_usize,
};
Expand Down Expand Up @@ -305,8 +305,8 @@ impl<M> One<M, RR> {
// values, using `LIMB_BITS` here, rather than `N0::LIMBS_USED * LIMB_BITS`,
// is correct because R**2 will still be a multiple of the latter as
// `N0::LIMBS_USED` is either one or two.
fn newRR(m: &Modulus<M>, m_bits: bits::BitLength) -> Self {
let m_bits = m_bits.as_usize_bits();
fn newRR(m: &Modulus<M>) -> Self {
let m_bits = m.len_bits().as_usize_bits();
let r = (m_bits + (LIMB_BITS - 1)) / LIMB_BITS * LIMB_BITS;

// base = 2**(lg m - 1).
Expand Down
9 changes: 8 additions & 1 deletion src/arithmetic/bigint/modulus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,12 @@ impl<M> OwnedModulusWithOne<M> {
let partial = Modulus {
limbs: &n,
n0: n0.clone(),
len_bits,
m: PhantomData,
cpu_features,
};

One::newRR(&partial, len_bits)
One::newRR(&partial)
};

Ok(Self {
Expand Down Expand Up @@ -214,6 +215,7 @@ impl<M> OwnedModulusWithOne<M> {
Modulus {
limbs: &self.limbs,
n0: self.n0.clone(),
len_bits: self.len_bits,
m: PhantomData,
cpu_features: self.cpu_features,
}
Expand All @@ -233,6 +235,7 @@ impl<M: PublicModulus> OwnedModulusWithOne<M> {
pub struct Modulus<'a, M> {
limbs: &'a [Limb],
n0: N0,
len_bits: BitLength,
m: PhantomData<M>,
cpu_features: cpu::Features,
}
Expand Down Expand Up @@ -263,6 +266,10 @@ impl<M> Modulus<'_, M> {
&self.n0
}

pub fn len_bits(&self) -> BitLength {
self.len_bits
}

#[inline]
pub(crate) fn cpu_features(&self) -> cpu::Features {
self.cpu_features
Expand Down

0 comments on commit cbcac26

Please sign in to comment.