Skip to content

add RSA key size to SignatureAlgorithm - #452

Closed
jgreeer wants to merge 1 commit into
rustls:mainfrom
jgreeer:rsa-key-size-sig-algos
Closed

jgreeer wants to merge 1 commit into
rustls:mainfrom
jgreeer:rsa-key-size-sig-algos

Conversation

@jgreeer

@jgreeer jgreeer commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR adds support for having separate SignatureAlgorithm values for different key sizes. It adds a field rsa_key_size to the SignatureAlgorithm struct. We create a static SignatureAlgorithm struct for each combination of hash (SHA256, SHA384, SHA512) + key size (2048, 3072, 4096) adding 6 new algorithms. As a side effect, we have to pass rsa_key_size: None to the other algorithm structs.

The reason for this change is in key_pair.rs, you can now use the generate_for method to generate RSA key pairs of different key sizes by giving different SignatureAlgorithm arguments. This removes the need for generate_rsa_for, so we deprecate it in the same way RcgenError was. Since RsaKeySize is always used now, we removed the aws-lc-rs and crypto gating.

The rsa_key_size field is not used it the identity of the key, because it would mess up loading the key, and we don't want to mess with the OID. At load time, like in from_der_and_sign_algo, the user can give an RSA SigAlg value of any key size since the key size is later retrieved using rsa_key_pair_public_modulus_len.

Tests

We add a test in lib.rs to verify that RSA algs of different key sizes are equal to each other.

@jgreeer
jgreeer force-pushed the rsa-key-size-sig-algos branch from 6498b14 to a8096fa Compare September 9, 2026 22:03

@djc djc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this makes sense with some tweaks?

Comment thread rcgen/src/key_pair.rs Outdated
Comment thread rcgen/src/sign_algo.rs

@djc djc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please squash the commits into a single one.

@jgreeer
jgreeer force-pushed the rsa-key-size-sig-algos branch from 20f6bb9 to 7e099fc Compare September 11, 2026 15:03
@jgreeer
jgreeer force-pushed the rsa-key-size-sig-algos branch from 7e099fc to 0ef545c Compare September 21, 2026 16:57
@jgreeer
jgreeer force-pushed the rsa-key-size-sig-algos branch from 0ef545c to 7d92be0 Compare September 21, 2026 17:17
@jgreeer

jgreeer commented Sep 21, 2026

Copy link
Copy Markdown
Contributor Author

@djc i think this is good to merge now, i've integrated the changes from #453 and e6c421b

@cpu

cpu commented Sep 21, 2026 •

Copy link
Copy Markdown
Member

I'm a bit hesitant about this branch. I don't think we should continue to conflate signature identity with key generation policy, I think they should be modeled separately. Have you looked at what that might involve as a potential alternative? I was giving similar feedback in #448 (comment)

@jgreeer

jgreeer commented Sep 21, 2026

Copy link
Copy Markdown
Contributor Author

I'm a bit hesitant about this branch. I don't think we should continue to conflate signature identity with key generation policy, I think they should be modeled separately. Have you looked at what that might involve as a potential alternative? I was giving similar feedback in #448 (comment)

that's fair. this PR seems to go in the opposite direction of the feedback you gave. we're ultimately just trying to get rid of generate_rsa_for and instead have the functionality in generate_for. i think splitting SignatureAlgorithm into two is a good idea. maybe as an alternative we have another enum, something like KeyPairAlgorithim, that is only used as the argument to the generate function. i think this would achieve the clearest seperation of which enum is supposed to do what. or i guess it would probably have another name since we're getting rid of KeyPair.

@djc

djc commented Sep 22, 2026

Copy link
Copy Markdown
Member

that's fair. this PR seems to go in the opposite direction of the feedback you gave. we're ultimately just trying to get rid of generate_rsa_for and instead have the functionality in generate_for. i think splitting SignatureAlgorithm into two is a good idea. maybe as an alternative we have another enum, something like KeyPairAlgorithim, that is only used as the argument to the generate function. i think this would achieve the clearest seperation of which enum is supposed to do what. or i guess it would probably have another name since we're getting rid of KeyPair.

Yup -- sorry for leading you astray. Do you have a chance to implement what @cpu was proposing in #448?

@jgreeer

jgreeer commented Sep 22, 2026

Copy link
Copy Markdown
Contributor Author

that's fair. this PR seems to go in the opposite direction of the feedback you gave. we're ultimately just trying to get rid of generate_rsa_for and instead have the functionality in generate_for. i think splitting SignatureAlgorithm into two is a good idea. maybe as an alternative we have another enum, something like KeyPairAlgorithim, that is only used as the argument to the generate function. i think this would achieve the clearest seperation of which enum is supposed to do what. or i guess it would probably have another name since we're getting rid of KeyPair.

Yup -- sorry for leading you astray. Do you have a chance to implement what @cpu was proposing in #448?

sure!

@jgreeer jgreeer closed this Sep 22, 2026
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.

3 participants