Skip to content

Commit d39c2db

Browse files
use Uint::rem_wide in MontyParams::new and remove extra trait bounds
Signed-off-by: Andrew Whitehead <cywolf@gmail.com>
1 parent fc1d067 commit d39c2db

1 file changed

Lines changed: 3 additions & 11 deletions

File tree

src/modular/monty_form.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use super::{
1515
reduction::montgomery_reduction,
1616
safegcd::invert_mod_u64,
1717
};
18-
use crate::{Concat, ConstChoice, Limb, Monty, NonZero, Odd, Split, U64, Uint, Word};
18+
use crate::{ConstChoice, Limb, Monty, Odd, U64, Uint, Word};
1919
use mul::DynMontyMultiplier;
2020
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq};
2121

@@ -35,11 +35,7 @@ pub struct MontyParams<const LIMBS: usize> {
3535
pub(super) mod_leading_zeros: u32,
3636
}
3737

38-
impl<const LIMBS: usize, const WIDE_LIMBS: usize> MontyParams<LIMBS>
39-
where
40-
Uint<LIMBS>: Concat<Output = Uint<WIDE_LIMBS>>,
41-
Uint<WIDE_LIMBS>: Split<Output = Uint<LIMBS>>,
42-
{
38+
impl<const LIMBS: usize> MontyParams<LIMBS> {
4339
/// Instantiates a new set of `MontyParams` representing the given odd `modulus`.
4440
pub const fn new(modulus: Odd<Uint<LIMBS>>) -> Self {
4541
// `R mod modulus` where `R = 2^BITS`.
@@ -49,11 +45,7 @@ where
4945
.wrapping_add(&Uint::ONE);
5046

5147
// `R^2 mod modulus`, used to convert integers to Montgomery form.
52-
let r2 = one
53-
.square()
54-
.rem(&NonZero(modulus.0.concat(&Uint::ZERO)))
55-
.split()
56-
.0;
48+
let r2 = Uint::rem_wide(one.square_wide(), modulus.as_nz_ref());
5749

5850
// The inverse of the modulus modulo 2**64
5951
let mod_inv = U64::from_u64(invert_mod_u64(modulus.as_ref().as_words()));

0 commit comments

Comments
 (0)