Skip to content

Commit df8b716

Browse files
authored
Rename MontyParams::new => ::new_vartime (#516)
For consistency with `BoxedMontyParams::new_vartime` and our general labeling strategy.
1 parent 4cfc8c1 commit df8b716

File tree

8 files changed

+15
-17
lines changed

8 files changed

+15
-17
lines changed

benches/monty.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ fn bench_montgomery_conversion<M: Measurement>(group: &mut BenchmarkGroup<'_, M>
1515
group.bench_function("MontyParams creation", |b| {
1616
b.iter_batched(
1717
|| Odd::<U256>::random(&mut OsRng),
18-
|modulus| black_box(MontyParams::new(modulus)),
18+
|modulus| black_box(MontyParams::new_vartime(modulus)),
1919
BatchSize::SmallInput,
2020
)
2121
});
2222

23-
let params = MontyParams::new(Odd::<U256>::random(&mut OsRng));
23+
let params = MontyParams::new_vartime(Odd::<U256>::random(&mut OsRng));
2424
group.bench_function("MontyForm creation", |b| {
2525
b.iter_batched(
2626
|| Odd::<U256>::random(&mut OsRng),
@@ -29,7 +29,7 @@ fn bench_montgomery_conversion<M: Measurement>(group: &mut BenchmarkGroup<'_, M>
2929
)
3030
});
3131

32-
let params = MontyParams::new(Odd::<U256>::random(&mut OsRng));
32+
let params = MontyParams::new_vartime(Odd::<U256>::random(&mut OsRng));
3333
group.bench_function("MontyForm retrieve", |b| {
3434
b.iter_batched(
3535
|| MontyForm::new(&U256::random(&mut OsRng), params),
@@ -40,7 +40,7 @@ fn bench_montgomery_conversion<M: Measurement>(group: &mut BenchmarkGroup<'_, M>
4040
}
4141

4242
fn bench_montgomery_ops<M: Measurement>(group: &mut BenchmarkGroup<'_, M>) {
43-
let params = MontyParams::new(Odd::<U256>::random(&mut OsRng));
43+
let params = MontyParams::new_vartime(Odd::<U256>::random(&mut OsRng));
4444

4545
group.bench_function("invert, U256", |b| {
4646
b.iter_batched(

src/modular/monty_form.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@ pub struct MontyParams<const LIMBS: usize> {
3333
}
3434

3535
impl<const LIMBS: usize> MontyParams<LIMBS> {
36-
/// Instantiates a new set of `MontyParams` representing the given `modulus` if it is odd.
37-
///
38-
/// Returns `None` if the provided modulus is not odd.
39-
pub fn new(modulus: Odd<Uint<LIMBS>>) -> Self {
36+
/// Instantiates a new set of `MontyParams` representing the given odd `modulus`.
37+
pub fn new_vartime(modulus: Odd<Uint<LIMBS>>) -> Self {
4038
// `R mod modulus` where `R = 2^BITS`.
4139
// Represents 1 in Montgomery form.
4240
let one = Uint::MAX
@@ -201,7 +199,7 @@ impl<const LIMBS: usize> Monty for MontyForm<LIMBS> {
201199
type Params = MontyParams<LIMBS>;
202200

203201
fn new_params(modulus: Odd<Self::Integer>) -> Self::Params {
204-
MontyParams::new(modulus)
202+
MontyParams::new_vartime(modulus)
205203
}
206204

207205
fn new(value: Self::Integer, params: Self::Params) -> Self {

src/modular/monty_form/add.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ mod tests {
7070

7171
#[test]
7272
fn add_overflow() {
73-
let params = MontyParams::new(Odd::<U256>::from_be_hex(
73+
let params = MontyParams::new_vartime(Odd::<U256>::from_be_hex(
7474
"ffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551",
7575
));
7676

src/modular/monty_form/inv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ mod tests {
114114
use crate::{Invert, Inverter, Odd, PrecomputeInverter, U256};
115115

116116
fn params() -> MontyParams<{ U256::LIMBS }> {
117-
MontyParams::new(Odd::<U256>::from_be_hex(
117+
MontyParams::new_vartime(Odd::<U256>::from_be_hex(
118118
"15477BCCEFE197328255BFA79A1217899016D927EF460F4FF404029D24FA4409",
119119
))
120120
}

src/modular/monty_form/sub.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ mod tests {
7070

7171
#[test]
7272
fn sub_overflow() {
73-
let params = MontyParams::new(Odd::<U256>::from_be_hex(
73+
let params = MontyParams::new_vartime(Odd::<U256>::from_be_hex(
7474
"ffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551",
7575
));
7676

src/uint/mul_mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl<const LIMBS: usize> Uint<LIMBS> {
2020
// It's worth potentially exploring other approaches to improve efficiency.
2121
match p.to_odd().into() {
2222
Some(odd_p) => {
23-
let params = MontyParams::new(odd_p);
23+
let params = MontyParams::new_vartime(odd_p);
2424
let lhs = MontyForm::new(self, params);
2525
let rhs = MontyForm::new(rhs, params);
2626
let ret = lhs * rhs;

tests/monty_form.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ prop_compose! {
3333
n = n.wrapping_add(&U256::one());
3434
}
3535

36-
MontyParams::new(Odd::new(n).expect("modulus ensured odd"))
36+
MontyParams::new_vartime(Odd::new(n).expect("modulus ensured odd"))
3737
}
3838
}
3939

tests/uint.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ proptest! {
402402

403403
let expected = to_uint(a_bi.modpow(&b_bi, &p_bi));
404404

405-
let params = MontyParams::new(P);
405+
let params = MontyParams::new_vartime(P);
406406
let a_m = MontyForm::new(&a, params);
407407
let actual = a_m.pow(&b).retrieve();
408408

@@ -419,7 +419,7 @@ proptest! {
419419

420420
let expected = to_uint(a_bi.modpow(&b_bi, &p_bi));
421421

422-
let params = MontyParams::new(P);
422+
let params = MontyParams::new_vartime(P);
423423
let a_m = MontyForm::new(&a, params);
424424
let actual = a_m.pow_bounded_exp(&b, exponent_bits.into()).retrieve();
425425

@@ -440,7 +440,7 @@ proptest! {
440440
};
441441
let expected = to_uint(expected);
442442

443-
let params = MontyParams::new(P);
443+
let params = MontyParams::new_vartime(P);
444444
let a_m = MontyForm::new(&a, params);
445445
let actual = a_m.div_by_2().retrieve();
446446

0 commit comments

Comments
 (0)