diff --git a/src/arithmetic.rs b/src/arithmetic.rs index 1a1061b740..e3dc6c4489 100644 --- a/src/arithmetic.rs +++ b/src/arithmetic.rs @@ -18,6 +18,7 @@ mod constant; pub mod bigint; pub mod montgomery; + mod n0; #[allow(dead_code)] diff --git a/src/arithmetic/bigint.rs b/src/arithmetic/bigint.rs index 9d2b9d4241..f058c88d20 100644 --- a/src/arithmetic/bigint.rs +++ b/src/arithmetic/bigint.rs @@ -41,7 +41,6 @@ pub(crate) use self::{ modulus::{Modulus, OwnedModulus, MODULUS_MAX_LIMBS}, private_exponent::PrivateExponent, }; -use super::n0::N0; use crate::{ arithmetic::montgomery::*, bits::BitLength, diff --git a/src/arithmetic/bigint/modulus.rs b/src/arithmetic/bigint/modulus.rs index dc7a9f880b..d10ff9c978 100644 --- a/src/arithmetic/bigint/modulus.rs +++ b/src/arithmetic/bigint/modulus.rs @@ -12,7 +12,7 @@ // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -use super::{super::n0::N0, BoxedLimbs, Elem, PublicModulus, Unencoded}; +use super::{BoxedLimbs, Elem, PublicModulus, Unencoded, N0}; use crate::{ bits::BitLength, cpu, error, @@ -126,7 +126,7 @@ impl OwnedModulus { debug_assert_eq!(LIMB_BITS, 32); n_mod_r |= u64::from(n[1]) << 32; } - N0::from(unsafe { bn_neg_inv_mod_r_u64(n_mod_r) }) + N0::precalculated(unsafe { bn_neg_inv_mod_r_u64(n_mod_r) }) }; let len_bits = limb::limbs_minimal_bits(&n); diff --git a/src/arithmetic/montgomery.rs b/src/arithmetic/montgomery.rs index 88a405a5c2..2f0fadf606 100644 --- a/src/arithmetic/montgomery.rs +++ b/src/arithmetic/montgomery.rs @@ -12,6 +12,8 @@ // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +pub use super::n0::N0; + // Indicates that the element is not encoded; there is no *R* factor // that needs to be canceled out. #[derive(Copy, Clone)] @@ -107,10 +109,7 @@ impl ProductEncoding for (RRR, RInverse) { } #[allow(unused_imports)] -use { - super::n0::N0, - crate::{bssl, c, limb::Limb}, -}; +use crate::{bssl, c, limb::Limb}; #[cfg(not(any( target_arch = "aarch64", diff --git a/src/arithmetic/n0.rs b/src/arithmetic/n0.rs index 0fe18727c7..fb3fb20ba8 100644 --- a/src/arithmetic/n0.rs +++ b/src/arithmetic/n0.rs @@ -16,16 +16,14 @@ use crate::limb::Limb; #[derive(Clone, Copy)] #[repr(transparent)] -pub(in super::super) struct N0([Limb; 2]); +pub struct N0([Limb; 2]); impl N0 { #[cfg(feature = "alloc")] pub(super) const LIMBS_USED: usize = 64 / crate::limb::LIMB_BITS; -} -impl From for N0 { #[inline] - fn from(n0: u64) -> Self { + pub const fn precalculated(n0: u64) -> Self { #[cfg(target_pointer_width = "64")] { Self([n0, 0])