Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Slow key generation #29

Closed
kaimast opened this issue Sep 29, 2019 · 7 comments
Closed

Slow key generation #29

kaimast opened this issue Sep 29, 2019 · 7 comments

Comments

@kaimast
Copy link

kaimast commented Sep 29, 2019

Hi all,

I have the following code snippet.

use rsa::RSAPrivateKey;
use rand::thread_rng;

let mut rng = thread_rng();
let private = RSAPrivateKey::new(&mut rng, 2048).unwrap();    

It sometimes takes about a second to execute, but most of the time it takes tens of seconds. Am I doing something wrong? Is there a different RNG that is faster?

Thanks!

@r10s
Copy link

r10s commented Sep 30, 2019

if you're running with the --release flag, things should be faster (typically few seconds).

but if you leave out this flag, things may take some tens of seconds.

at least this is what i've noticed for delta chat.

in general, creating a rsa-key seems to take some time, i was confused some time ago on that isseu as well (using openssl that time, see deltachat/deltachat-android#511 (comment) ) :)

@kaimast
Copy link
Author

kaimast commented Sep 30, 2019

Thanks for the feedback!

I can confirm that it is much faster in release mode. It should not be that slow in with debug symbols enabled though.

Or is this a rust specific problem that debug bulids are much much slower?

@r10s
Copy link

r10s commented Sep 30, 2019

Thanks for the feedback!

np

Or is this a rust specific problem that debug bulids are much much slower?

not sure about rust, but eg, e.g deltachat/deltachat-core#376 (comment) we encountered debug encryption being up to 20 times slower than release one - on c with openssl (not sure if this can be tweaked, we switched to rust then ;)

@newpavlov
Copy link
Member

@kaimast
dev profile uses the lowest optimization level by default, so it's not only debug symbols, i.e. you are measuring performance for binary without any optimizations whatsoever.

@olback
Copy link

olback commented Jan 28, 2020

I also ran into this problem. Turns out the Rust compiler is SUPER EFFICIENT when compiling a release. Generating a 2048 bit key in debug mode took arround 5 minutes, meanwhile in a release build it takes about 1 second.

@dignifiedquire
Copy link
Member

Closing, as this is expected behaviour

@kaimast
Copy link
Author

kaimast commented May 3, 2020

Would be great to keep this open. Key generation still takes several seconds in release mode for me. Looks like it's at least an order of magnitude slower than that of openssh. I am sure there are ways to improve upon this.

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

No branches or pull requests

5 participants