Skip to content

Commit 40e1750

Browse files
authored
Support for cryptographic operations with larger keys (#595)
Cherry picked copy of #594 from 0-9-x
1 parent f6b836a commit 40e1750

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/key.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ impl RsaPublicKey {
228228

229229
/// Create a new public key from its components.
230230
pub fn new_with_max_size(n: BoxedUint, e: BoxedUint, max_size: usize) -> Result<Self> {
231-
check_public_with_max_size(&n, &e, max_size)?;
231+
check_public_with_max_size(&n, &e, Some(max_size))?;
232232

233233
let n_odd = Odd::new(n.clone())
234234
.into_option()
@@ -673,14 +673,16 @@ impl PrivateKeyParts for RsaPrivateKey {
673673
/// Check that the public key is well formed and has an exponent within acceptable bounds.
674674
#[inline]
675675
pub fn check_public(public_key: &impl PublicKeyParts) -> Result<()> {
676-
check_public_with_max_size(public_key.n(), public_key.e(), RsaPublicKey::MAX_SIZE)
676+
check_public_with_max_size(public_key.n(), public_key.e(), None)
677677
}
678678

679679
/// Check that the public key is well formed and has an exponent within acceptable bounds.
680680
#[inline]
681-
fn check_public_with_max_size(n: &BoxedUint, e: &BoxedUint, max_size: usize) -> Result<()> {
682-
if n.bits_vartime() as usize > max_size {
683-
return Err(Error::ModulusTooLarge);
681+
fn check_public_with_max_size(n: &BoxedUint, e: &BoxedUint, max_size: Option<usize>) -> Result<()> {
682+
if let Some(max_size) = max_size {
683+
if n.bits_vartime() as usize > max_size {
684+
return Err(Error::ModulusTooLarge);
685+
}
684686
}
685687

686688
if e >= n || n.is_even().into() || n.is_zero().into() {

0 commit comments

Comments
 (0)