OpenMP problem when using 3 or more threads (solved)

General OpenMP discussion

OpenMP problem when using 3 or more threads (solved)

Postby thegreatwall » Tue Mar 04, 2014 1:48 pm

Dear all,

I want to combine OpenMP and RSA_public_encrypt and RSA_private_decrypt routines. However, I was confused by a weird bug for a few days.

If I generated 2 threads for parallel encryption and decryption, everything works well. If I generated 3 or more threads, the RSA_public_encrypt routine works fine. All strings are successfully encrypted. However, the RSA_private_decrypt routine went wrong, that is, only one thread works properly, all the other threads failed
to decrypt some of the strings (decrypt_len=-1, rsa_eay_private_decrypt padding check failed). If there are 1000 strings and 4 threads, the total number of string failed to decrypt went around 710 (some times as low as around 200). So as expected, if I use 4 threads for parallel RSA_public_encrypt and one thread for RSA_private_decrypt, nothing went wrong.

It would be great if you could give some ideas as I think it might be something wrong when using the OpenMP. Thanks very much.

-------------------------------------------------------------------------------------------------------------------------------------------------------
RSA structure private key caches come info when it is first used, so it is not thread safe. The private key has to be duplicated or callback functions have to be used to avoid the race condition.

Thanks very much for your help and attention!
Last edited by thegreatwall on Wed Mar 05, 2014 10:11 am, edited 1 time in total.
thegreatwall
 
Posts: 2
Joined: Mon Mar 03, 2014 7:56 pm

Re: OpenMP problem when using 3 or more threads

Postby MarkB » Wed Mar 05, 2014 8:50 am

I think the problem is that RSA_private_decrypt is not thread-safe by default. See here: http://www.openssl.org/docs/crypto/threads.html
MarkB
 
Posts: 434
Joined: Thu Jan 08, 2009 10:12 am

Re: OpenMP problem when using 3 or more threads

Postby thegreatwall » Wed Mar 05, 2014 10:02 am

MarkB wrote:I think the problem is that RSA_private_decrypt is not thread-safe by default. See here: http://www.openssl.org/docs/crypto/threads.html


Thanks very much. You're right. The problem has been solved.
thegreatwall
 
Posts: 2
Joined: Mon Mar 03, 2014 7:56 pm


Return to Using OpenMP

Who is online

Users browsing this forum: No registered users and 8 guests