Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

ssh key generation takes very long sometimes #56

Closed
xemwebe opened this issue Jan 6, 2023 · 3 comments
Closed

ssh key generation takes very long sometimes #56

xemwebe opened this issue Jan 6, 2023 · 3 comments

Comments

@xemwebe
Copy link

xemwebe commented Jan 6, 2023

I use the following code to generate a ssh key pair:

RsaKeypair::random(rand::thread_rng(), 2048)

which takes usually a few seconds (e.g 2-5s cpu time), but sometimes much longer, e.g. up to 20s and more.
Since the time taken varies a lot, I suspect this might be due to lack of entropy, especially since the required time seems to be much longer in un-attended scenarios (e.g. automatic testing).

Is this a known (accepted?) phenomenon? Could the long duration be circumvented somehow, especially in automatic testing scenarios?

@tarcieri
Copy link
Member

tarcieri commented Jan 6, 2023

20s sounds like you're not using a --release build?

That said, RSA key generation is still known to be slow: RustCrypto/RSA#144

If you'd like faster key generation, using any of the elliptic curve keys, e.g. ECDSA/P-256 or Ed25519, should be instantaneous.

@xemwebe
Copy link
Author

xemwebe commented Jan 6, 2023

Yes indeed, the long times are only observed in debug builds? I was just observing this in my own tests.
For some reasons, I need RSA based key for compatibility, but since using --release fixes the issue, this issue could be closed, I guess.

Thanks for the fast help!

@xemwebe xemwebe closed this as completed Jan 6, 2023
@tarcieri
Copy link
Member

tarcieri commented Jan 6, 2023

In your workspace's Cargo.toml, you can also add something like:

[profile.dev]
opt-level = 2

...which will improve the speed at which tests run.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants