Skip to content

Continue refactoring of RSA crate internals#304

Merged
tarcieri merged 8 commits intoRustCrypto:masterfrom
lumag:no-primitive
Apr 23, 2023
Merged

Continue refactoring of RSA crate internals#304
tarcieri merged 8 commits intoRustCrypto:masterfrom
lumag:no-primitive

Conversation

@lumag
Copy link
Copy Markdown
Contributor

@lumag lumag commented Apr 19, 2023

Further refactoring of the RSA crate. Clean up internal interfaces, split software RSA implementation from the wrapping code.

lumag added 6 commits April 19, 2023 20:39
Make generate_multi_prime_key_with_exp() generic enough to generate
abstract key structure. Rewrite RsaPrivateKey constructors to use
RsaPrivateKey::from_components().

Signed-off-by: Dmitry Baryshkov <[email protected]>
Move PublicKeyParts to the separate module.

Signed-off-by: Dmitry Baryshkov <[email protected]>
Make internals.rs generic enough to be moved to the algorithms module.

Signed-off-by: Dmitry Baryshkov <[email protected]>
Separate software RSA implementation to separate module under
crate::algorithms.

Signed-off-by: Dmitry Baryshkov <[email protected]>
Now as raw_int_encryption_primitive() and raw_int_decryption_primitive()
became simple wrappers around properly defined functions we can inline
them and always use software RSA algorithm from src::algorithms::rsa.rs.

Signed-off-by: Dmitry Baryshkov <[email protected]>
internals.rs now contains only small functions related to BigUint to
Vec<u8> conversion. Move them to src/algorithms/pad.rs and get rid of
internals.rs

Signed-off-by: Dmitry Baryshkov <[email protected]>
@lumag
Copy link
Copy Markdown
Contributor Author

lumag commented Apr 19, 2023

cc @dignifiedquire @tarcieri @str4d

Comment thread src/algorithms/rsa.rs Outdated
Comment thread src/lib.rs
While it is expected that the functions inside algorithms crates might
be useful (and used) by other parties, they are low level functions and
as such impose a high risk of being misused. Protect all of them with
pub(crate) to prevent them from being exposed by mistake.

Also add big fat warnings to raw RSA functions, which should never be
used unless authors knows exactly what they are using.

Signed-off-by: Dmitry Baryshkov <[email protected]>
@tarcieri
Copy link
Copy Markdown
Member

@lumag
Copy link
Copy Markdown
Contributor Author

lumag commented Apr 19, 2023 via email

@tarcieri tarcieri requested a review from dignifiedquire April 19, 2023 23:44
@tarcieri tarcieri merged commit 5746648 into RustCrypto:master Apr 23, 2023
tchebb pushed a commit to tchebb/RSA that referenced this pull request Jul 21, 2023
External access to these functions was removed in RustCrypto#304 when the old
`internals` module and `expose-internals` feature were removed. There
are some valid use cases for them, though (see RustCrypto#351), so let's bring
back a subset of what was in `internals` using the same naming and
documentation conventions that the aes crate uses for its hazardous
functions.

Much of the added or changed documentation is derived from that in aes.

Fixes RustCrypto#351.
tarcieri pushed a commit that referenced this pull request Jul 23, 2023
External access to these functions was removed in #304 when the old
`internals` module and `expose-internals` feature were removed. There
are some valid use cases for them, though (see #351), so let's bring
back a subset of what was in `internals` using the same naming and
documentation conventions that the aes crate uses for its hazardous
functions.

Much of the added or changed documentation is derived from that in
the `aes` crate.

Fixes #351.
flihp added a commit to flihp/pki-playground that referenced this pull request Nov 9, 2023
In versions of the rsa crate >= 0.9 the
`generate_multi_prime_key_with_exp` functions are no longer public.
Their reasons for doing so are here:
RustCrypto/RSA#304 but the TLDR; is: so no one
hurts themselves.

The closest analog available is `RsaPrivateKey::new_with_exp` but it
doesn't allow us to specify the number of primes. Internally it hard
codes this value to '2' which is our current default. None of our
example configs set this value and they probably shouldn't so this
commit removes the `num-primes` config option from the RsaKeyConfig.

This changes the config file structure so this commit bumps the version
number too.
flihp added a commit to oxidecomputer/pki-playground that referenced this pull request Nov 10, 2023
In versions of the rsa crate >= 0.9 the
`generate_multi_prime_key_with_exp` functions are no longer public.
Their reasons for doing so are here:
RustCrypto/RSA#304 but the TLDR; is: so no one
hurts themselves.

The closest analog available is `RsaPrivateKey::new_with_exp` but it
doesn't allow us to specify the number of primes. Internally it hard
codes this value to '2' which is our current default. None of our
example configs set this value and they probably shouldn't so this
commit removes the `num-primes` config option from the RsaKeyConfig.

This changes the config file structure so this commit bumps the version
number too.
takumi-earth pushed a commit to earthlings-dev/RSA that referenced this pull request Jan 27, 2026
* feat: decouple key generation and random generation

Make generate_multi_prime_key_with_exp() generic enough to generate
abstract key structure. Rewrite RsaPrivateKey constructors to use
RsaPrivateKey::from_components().

* feat: move key-related traits to separate module

Move PublicKeyParts to the separate module.

* feat: stop using RsaPrivateKey in internals.rs

Make internals.rs generic enough to be moved to the algorithms module.

* feat: move soft RSA implementation to crate::algorithms::rsa.rs

Separate software RSA implementation to separate module under
crate::algorithms.

* key: drop raw_int_*_primitive wrappers

Now as raw_int_encryption_primitive() and raw_int_decryption_primitive()
became simple wrappers around properly defined functions we can inline
them and always use software RSA algorithm from src::algorithms::rsa.rs.

* feat: move internals.rs to src/algortihms/pad.rs

internals.rs now contains only small functions related to BigUint to
Vec<u8> conversion. Move them to src/algorithms/pad.rs and get rid of
internals.rs

* algorithms: protect all functions with pub(crate)

While it is expected that the functions inside algorithms crates might
be useful (and used) by other parties, they are low level functions and
as such impose a high risk of being misused. Protect all of them with
pub(crate) to prevent them from being exposed by mistake.

Also add big fat warnings to raw RSA functions, which should never be
used unless authors knows exactly what they are using.

Signed-off-by: Dmitry Baryshkov <[email protected]>
takumi-earth pushed a commit to earthlings-dev/RSA that referenced this pull request Jan 27, 2026
…pto#352)

External access to these functions was removed in RustCrypto#304 when the old
`internals` module and `expose-internals` feature were removed. There
are some valid use cases for them, though (see RustCrypto#351), so let's bring
back a subset of what was in `internals` using the same naming and
documentation conventions that the aes crate uses for its hazardous
functions.

Much of the added or changed documentation is derived from that in
the `aes` crate.

Fixes RustCrypto#351.
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