Skip to content

Commit 759684d

Browse files
authored
BoxedMontyForm: always use Arc for params (#645)
`Arc` was previously gated on `std` but is available as `alloc::sync::Arc`. Since `BoxedMontyForm` depends on `alloc` anyway, we can unconditionally use `Arc` for the params. Using `Arc` avoids having to clone/duplicate the params every time a new `BoxedMontyForm` value is made with the same params.
1 parent c18700e commit 759684d

File tree

2 files changed

+2
-18
lines changed

2 files changed

+2
-18
lines changed

src/modular/boxed_monty_form.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ use super::{
1313
Retrieve,
1414
};
1515
use crate::{BoxedUint, Limb, Monty, Odd, Word};
16-
17-
#[cfg(feature = "std")]
18-
use std::sync::Arc;
16+
use alloc::sync::Arc;
1917

2018
#[cfg(feature = "zeroize")]
2119
use zeroize::Zeroize;
@@ -123,12 +121,6 @@ pub struct BoxedMontyForm {
123121
montgomery_form: BoxedUint,
124122

125123
/// Montgomery form parameters.
126-
#[cfg(not(feature = "std"))]
127-
params: BoxedMontyParams,
128-
129-
/// Montgomery form parameters.
130-
// Uses `Arc` when `std` is available.
131-
#[cfg(feature = "std")]
132124
params: Arc<BoxedMontyParams>,
133125
}
134126

src/modular/boxed_monty_form/inv.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@ use crate::{
55
modular::BoxedBernsteinYangInverter, Invert, Inverter, PrecomputeInverter,
66
PrecomputeInverterWithAdjuster,
77
};
8+
use alloc::sync::Arc;
89
use core::fmt;
910
use subtle::CtOption;
1011

11-
#[cfg(feature = "std")]
12-
use std::sync::Arc;
13-
1412
impl BoxedMontyForm {
1513
/// Computes `self^-1` representing the multiplicative inverse of `self`.
1614
/// I.e. `self * self^-1 = 1`.
@@ -45,12 +43,6 @@ pub struct BoxedMontyFormInverter {
4543
inverter: BoxedBernsteinYangInverter,
4644

4745
/// Residue parameters.
48-
#[cfg(not(feature = "std"))]
49-
params: BoxedMontyParams,
50-
51-
/// Residue parameters.
52-
// Uses `Arc` when `std` is available.
53-
#[cfg(feature = "std")]
5446
params: Arc<BoxedMontyParams>,
5547
}
5648

0 commit comments

Comments
 (0)