diff --git a/src/arithmetic/bigint.rs b/src/arithmetic/bigint.rs index 75ce9ad641..c4fc37ce82 100644 --- a/src/arithmetic/bigint.rs +++ b/src/arithmetic/bigint.rs @@ -170,6 +170,10 @@ impl BoxedLimbs { m: PhantomData, } } + + fn into_limbs(self) -> Box<[Limb]> { + self.limbs + } } /// A modulus *s* that is smaller than another modulus *l* so every element of @@ -534,7 +538,7 @@ pub(crate) fn elem_exp_vartime( #[cfg(not(target_arch = "x86_64"))] pub fn elem_exp_consttime( base: Elem, - exponent: &PrivateExponent, + exponent: &PrivateExponent, m: &Modulus, ) -> Result, error::Unspecified> { use crate::limb::Window; @@ -629,7 +633,7 @@ pub fn elem_inverse_consttime( #[cfg(target_arch = "x86_64")] pub fn elem_exp_consttime( base: Elem, - exponent: &PrivateExponent, + exponent: &PrivateExponent, m: &Modulus, ) -> Result, error::Unspecified> { // Pretty much all the math here requires CPU feature detection to have diff --git a/src/arithmetic/bigint/private_exponent.rs b/src/arithmetic/bigint/private_exponent.rs index 7366f9ea4a..f0f5e34e9f 100644 --- a/src/arithmetic/bigint/private_exponent.rs +++ b/src/arithmetic/bigint/private_exponent.rs @@ -13,17 +13,16 @@ // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. use super::{elem_add, elem_sub, limb, BoxedLimbs, Limb, LimbMask, Modulus, Prime}; - use crate::error; +use alloc::boxed::Box; -// `M` represents the prime modulus for which the exponent is in the interval -// [1, `m` - 1). -pub struct PrivateExponent { - limbs: BoxedLimbs, +pub struct PrivateExponent { + limbs: Box<[Limb]>, } -impl PrivateExponent { - pub fn from_be_bytes_padded( +impl PrivateExponent { + // `p` is the modulus for which the exponent is in the interval [1, `p` - 1). + pub fn from_be_bytes_padded( input: untrusted::Input, p: &Modulus, ) -> Result { @@ -41,22 +40,22 @@ impl PrivateExponent { return Err(error::Unspecified); } - Ok(Self { limbs: dP }) + Ok(Self { + limbs: dP.into_limbs(), + }) } #[inline] pub(super) fn limbs(&self) -> &[Limb] { &self.limbs } -} -impl PrivateExponent { // Returns `p - 2`. - pub(super) fn for_flt(p: &Modulus) -> Self { + pub(super) fn for_flt(p: &Modulus

) -> Self { let two = elem_add(p.one(), p.one(), p); let p_minus_2 = elem_sub(p.zero(), &two, p); Self { - limbs: p_minus_2.limbs, + limbs: p_minus_2.limbs.into_limbs(), } } } diff --git a/src/rsa/keypair.rs b/src/rsa/keypair.rs index c351f157de..ef05960838 100644 --- a/src/rsa/keypair.rs +++ b/src/rsa/keypair.rs @@ -462,7 +462,7 @@ impl signature::KeyPair for KeyPair { struct PrivatePrime { modulus: bigint::Modulus, - exponent: bigint::PrivateExponent, + exponent: bigint::PrivateExponent, } impl PrivatePrime {