Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 26 additions & 23 deletions src/modular/monty_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,15 @@ impl<const LIMBS: usize> FixedMontyParams<LIMBS> {
pub(crate) mod boxed {
use super::MontyParams;
use crate::{Limb, Odd, U64, Word};
use alloc::sync::Arc;
use core::fmt::{self, Debug};

#[cfg(feature = "zeroize")]
use zeroize::Zeroize;

/// Parameters to efficiently go to/from the Montgomery form for an odd modulus whose size and value
/// are both chosen at runtime.
#[derive(Clone, Eq, PartialEq)]
pub struct BoxedMontyParams(Arc<MontyParams<crate::uint::boxed::BoxedUint>>);
pub struct BoxedMontyParams(MontyParams<crate::uint::boxed::BoxedUint>);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This defeats the point of having a newtype at all. If we're not using the Arc then this should just be:

Suggested change
pub struct BoxedMontyParams(MontyParams<crate::uint::boxed::BoxedUint>);
pub type BoxedMontyParams = MontyParams<crate::uint::boxed::BoxedUint>;


impl BoxedMontyParams {
/// Instantiates a new set of [`BoxedMontyParams`] representing the given `modulus`.
Expand All @@ -249,16 +251,13 @@ pub(crate) mod boxed {

let mod_leading_zeros = modulus.as_ref().leading_zeros().min(Word::BITS - 1);

Self(
MontyParams {
modulus,
one,
r2,
mod_inv,
mod_leading_zeros,
}
.into(),
)
Self(MontyParams {
modulus,
one,
r2,
mod_inv,
mod_leading_zeros,
})
}

/// Instantiates a new set of [`BoxedMontyParams`] representing the given `modulus`.
Expand Down Expand Up @@ -286,16 +285,13 @@ pub(crate) mod boxed {

let mod_leading_zeros = modulus.as_ref().leading_zeros().min(Word::BITS - 1);

Self(
MontyParams {
modulus,
one,
r2,
mod_inv,
mod_leading_zeros,
}
.into(),
)
Self(MontyParams {
modulus,
one,
r2,
mod_inv,
mod_leading_zeros,
})
}

/// Modulus value.
Expand Down Expand Up @@ -345,7 +341,14 @@ pub(crate) mod boxed {

impl From<MontyParams<crate::uint::boxed::BoxedUint>> for BoxedMontyParams {
fn from(params: MontyParams<crate::uint::boxed::BoxedUint>) -> Self {
Self(params.into())
Self(params)
}
}

#[cfg(feature = "zeroize")]
impl Zeroize for BoxedMontyParams {
fn zeroize(&mut self) {
self.0.zeroize();
}
}
}
Expand Down