crypto_bigint/modular/monty_form/
neg.rs

1//! Negations of integers in Montgomery form with a modulus set at runtime.
2
3use super::MontyForm;
4use core::ops::Neg;
5
6impl<const LIMBS: usize> MontyForm<LIMBS> {
7    /// Negates the number.
8    pub const fn neg(&self) -> Self {
9        Self {
10            montgomery_form: self.montgomery_form.neg_mod(self.params.modulus.as_ref()),
11            params: self.params,
12        }
13    }
14}
15
16impl<const LIMBS: usize> Neg for MontyForm<LIMBS> {
17    type Output = Self;
18    fn neg(self) -> Self {
19        MontyForm::neg(&self)
20    }
21}
22
23impl<const LIMBS: usize> Neg for &MontyForm<LIMBS> {
24    type Output = MontyForm<LIMBS>;
25    fn neg(self) -> MontyForm<LIMBS> {
26        MontyForm::neg(self)
27    }
28}