Skip to content

Commit

Permalink
arithmetic: Allow use of N0 from outside of arithmetic.
Browse files Browse the repository at this point in the history
Allow N0 to be const-constructed and expose it outside of `arithmetic`
so that `ec` can start using it.
  • Loading branch information
briansmith committed Dec 2, 2023
1 parent ad1204e commit af471c9
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ mod constant;
pub mod bigint;

pub mod montgomery;

mod n0;

#[allow(dead_code)]
Expand Down
1 change: 0 additions & 1 deletion src/arithmetic/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/arithmetic/bigint/modulus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -126,7 +126,7 @@ impl<M> OwnedModulus<M> {
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);
Expand Down
7 changes: 3 additions & 4 deletions src/arithmetic/montgomery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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",
Expand Down
6 changes: 2 additions & 4 deletions src/arithmetic/n0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u64> for N0 {
#[inline]
fn from(n0: u64) -> Self {
pub const fn precalculated(n0: u64) -> Self {
#[cfg(target_pointer_width = "64")]
{
Self([n0, 0])
Expand Down

0 comments on commit af471c9

Please sign in to comment.