RSA Key Gen: Fast in Test App, Slow in Real App.

View: New views
6 Messages — Rating Filter:   Alert me  

RSA Key Gen: Fast in Test App, Slow in Real App.

by jitspoe :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I made a test app to test RSA key generation and whatnot using gcrypt directly.  Generating a 128bit key pair is almost instant in the test app.  It takes less than a second.  When I try using it in my real application (a game), however, it takes several seconds to generate the key.  The libraries and function calls are identical.  Any idea what the causes for the speed differences are?  I'm using Visual Studio 7.0 on Windows XP.  I'm not using secure memory or multithreading.

Re: RSA Key Gen: Fast in Test App, Slow in Real App.

by Bugzilla from bradh@frogmouth.net :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tuesday 19 September 2006 12:35, jitspoe wrote:
> I made a test app to test RSA key generation and whatnot using gcrypt
> directly.  Generating a 128bit key pair is almost instant in the test app.
> It takes less than a second.  When I try using it in my real application (a
> game), however, it takes several seconds to generate the key.  The
> libraries and function calls are identical.  Any idea what the causes for
> the speed differences are?  I'm using Visual Studio 7.0 on Windows XP.  I'm
> not using secure memory or multithreading.
On the face of it, you are doing something different between your test
application and the real application. Try cutting down a copy of your real
application towards your test application.

You really haven't provided enough information to say more. However generating
RSA keys "instantly" sounds a bit suspicious - perhaps you should review your
code again.

Brad


_______________________________________________
Gcrypt-devel mailing list
Gcrypt-devel@...
http://lists.gnupg.org/mailman/listinfo/gcrypt-devel

attachment0 (196 bytes) Download Attachment

Re: RSA Key Gen: Fast in Test App, Slow in Real App.

by jitspoe :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Brad Hards wrote:
On the face of it, you are doing something different between your test
application and the real application. Try cutting down a copy of your real
application towards your test application.

You really haven't provided enough information to say more. However generating
RSA keys "instantly" sounds a bit suspicious - perhaps you should review your
code again.

Brad
Thanks for the reply.  Sorry if I didn't elaborate enough.  The test code and the application code are identical.  The only difference is that one is standalone, just for testing the functions, and the other is embedded into my application.  The same gcrypt functions are called and in the same order.  All I'm doing is generating a 128bit RSA key pair.  I can post the source code if you're interested.  Once the first RSA key has been generated, generating another is almost instant, so I'm guessing it's initializing some kind of prime table.  I haven't delved into the gcrypt code to find out.

Re: RSA Key Gen: Fast in Test App, Slow in Real App.

by Werner Koch :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thu,  5 Oct 2006 04:52, jitspoe said:

> All I'm doing is generating a 128bit RSA key pair.  I can post the source
> code if you're interested.  Once the first RSA key has been generated,
> generating another is almost instant, so I'm guessing it's initializing some
> kind of prime table.  I haven't delved into the gcrypt code to find out.

That is because the entropy pool of the RNG has been filled and the
second key utilizes the left over entropy.  Make sure to properly
setup the RNG.

BTW, a 128 bit RSA key is pretty useless except for learning how to
break it.


Salam-Shalom,

   Werner


_______________________________________________
Gcrypt-devel mailing list
Gcrypt-devel@...
http://lists.gnupg.org/mailman/listinfo/gcrypt-devel

Re: RSA Key Gen: Fast in Test App, Slow in Real App.

by jitspoe :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Werner Koch wrote:
That is because the entropy pool of the RNG has been filled and the
second key utilizes the left over entropy.  Make sure to properly
setup the RNG.

BTW, a 128 bit RSA key is pretty useless except for learning how to
break it.


Salam-Shalom,

   Werner
Thanks for the reply.  I'm aware that 128bit RSA isn't very powerful, but in the way I was planning to use it, it didn't need to be.  I'm just sending a single random string  for verification purposes.  I actually realized that RSA wasn't even necessary and just went with some simple hashing instead, but I'm still curious about the key generation time.

Is there any documentation on how to set up the RNG?  What do I need to call?  gcry_fast_random_poll()?  I couldn't find anything else that looked like an initialization function.

Re: RSA Key Gen: Fast in Test App, Slow in Real App.

by jitspoe :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

You were correct about it being the RNG.  I found that simply calling gcry_randomize() paused for several seconds.  The slow_gatherer_windowsNT() function seems to be the culprit.  More specifically, the RegQueryValueEx(HKEY_PERFORMANCE_DATA, "Global", NULL, NULL, (LPBYTE) pPerfData, &dwSize); call.  I guess the console app didn't use this for whatever reason?  Any suggestions on how I would improve this performance?  Looking through the code, the only way I see to do it would be to create a seed file.