Skip to content

Commit

Permalink
Use ConstZero trait from num_traits (#573)
Browse files Browse the repository at this point in the history
  • Loading branch information
tarcieri committed Feb 8, 2024
1 parent 9b9e562 commit 4ff4105
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -22,7 +22,7 @@ subtle = { version = "2.5", default-features = false }
# optional dependencies
der = { version = "0.7", optional = true, default-features = false }
hybrid-array = { version = "0.2.0-rc.4", optional = true }
num-traits = { version = "0.2", default-features = false }
num-traits = { version = "0.2.18", default-features = false }
rand_core = { version = "0.6.4", optional = true }
rlp = { version = "0.5", optional = true, default-features = false }
serdect = { version = "0.2", optional = true, default-features = false }
Expand Down
12 changes: 12 additions & 0 deletions src/modular/const_monty_form.rs
Expand Up @@ -185,6 +185,18 @@ impl<MOD: ConstMontyParams<LIMBS>, const LIMBS: usize> ConstZero for ConstMontyF
const ZERO: Self = Self::ZERO;
}

impl<MOD: ConstMontyParams<LIMBS>, const LIMBS: usize> num_traits::Zero
for ConstMontyForm<MOD, LIMBS>
{
fn zero() -> Self {
Self::ZERO
}

fn is_zero(&self) -> bool {
self.ct_eq(&Self::ZERO).into()
}
}

#[cfg(feature = "rand_core")]
impl<MOD, const LIMBS: usize> Random for ConstMontyForm<MOD, LIMBS>
where
Expand Down
12 changes: 2 additions & 10 deletions src/traits.rs
Expand Up @@ -3,7 +3,7 @@
mod sealed;

pub use num_traits::{
WrappingAdd, WrappingMul, WrappingNeg, WrappingShl, WrappingShr, WrappingSub,
ConstZero, WrappingAdd, WrappingMul, WrappingNeg, WrappingShl, WrappingShr, WrappingSub,
};

pub(crate) use sealed::PrecomputeInverterWithAdjuster;
Expand Down Expand Up @@ -264,15 +264,7 @@ pub trait Zero: ConstantTimeEq + Sized {
}
}

/// Trait for associating a constant representing zero.
///
/// Types which impl this trait automatically receive a blanket impl of [`Zero`].
pub trait ConstZero: Zero {
/// The value `0`.
const ZERO: Self;
}

impl<T: ConstZero> Zero for T {
impl<T: ConstZero + ConstantTimeEq> Zero for T {
#[inline(always)]
fn zero() -> T {
Self::ZERO
Expand Down

0 comments on commit 4ff4105

Please sign in to comment.