Skip to content

Conversation

@hko-s
Copy link
Contributor

@hko-s hko-s commented Oct 15, 2025

Currently, this crate allows instantiation of public keys larger than 4096 bit (via RsaPublicKey::new_with_max_size), but doing cryptographic operations with such public keys fails in key::check_public, which always checks the modulus size against the constant RsaPublicKey::MAX_SIZE.

Also, there's no public API to instantiate larger private keys, or to do cryptographic operations with them.

I think it would be nice to cap both public and private key sizes to 4096 bit by default, but to allow opt-in creation of larger keys (complete with working cryptographic operations).

@tarcieri
Copy link
Member

You don't need a max_size carrier on the public key. It's checked at construction time, so once constructed there's no need to use it again.

@hko-s
Copy link
Contributor Author

hko-s commented Oct 15, 2025

You don't need a max_size carrier on the public key. It's checked at construction time, so once constructed there's no need to use it again.

Thanks, sounds good!

I was hesitant to drop the modulus size check that currently happens in check_public_with_max_size:

    if public_key.n().bits() > max_size {
        return Err(Error::ModulusTooLarge);
    }

If we can safely drop that bit of logic when doing cryptographic operations, I'm all for it (but I myself couldn't judge if it is safe).

@tarcieri
Copy link
Member

RsaPrivateKey's constructor can construct an RsaPublicKey without applying the public key size checks (it can apply its own size checks separately), but all existing APIs on RsaPublicKey should still apply the checks

@hko-s
Copy link
Contributor Author

hko-s commented Oct 15, 2025

I've modified the approach. Cryptographic operations now don't fail for keys larger than 4096 bit, while at least RsaPublicKey::new still enforces the 4096 bit size limit for the modulus.

If this direction seems roughly right, I'm happy to attempt whatever additional cleanup might be required.

Copy link
Member

@tarcieri tarcieri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems fine

@tarcieri tarcieri changed the title WIP: support for cryptographic operations with larger keys upport for cryptographic operations with larger keys Oct 15, 2025
@tarcieri tarcieri changed the title upport for cryptographic operations with larger keys Support for cryptographic operations with larger keys Oct 15, 2025
@tarcieri tarcieri merged commit c1f00a3 into RustCrypto:0-9-x Oct 15, 2025
9 checks passed
@hko-s
Copy link
Contributor Author

hko-s commented Oct 15, 2025

Awesome, thanks!

tarcieri pushed a commit that referenced this pull request Oct 17, 2025
@hko-s hko-s deleted the max_size branch November 1, 2025 08:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants