multithreading question

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

multithreading question

Jørgen Hovland
Hi,

I have a question about the use of openssl, EVP_CIPHER_CTXs, in a
multithreaded environment.
I have N threads calling a function that contains an EVP_CIPHER_CTX,
ctx_init, EVP_CipherUpdate/Final and then Cleanup.
The CTX is only used by that same thread calling the function.

Must all N threads call CRYPTO_set_locking_callback before use?
If so, can/should the callback function point to the same lock/mutexes for
all threads or should they have their own lock per thread?


When I'm not calling set_locking_callback at all I get of course coredumps;
#0  0x402a6ba1 in kill () from /lib/libc.so.6
#1  0x4002381d in pthread_kill () from /lib/libpthread.so.0
#2  0x40023b9b in raise () from /lib/libpthread.so.0
#3  0x402a80ec in abort () from /lib/libc.so.6
#4  0x403ddf0c in OpenSSLDie () from /usr/lib/libcrypto.so.0.9.7
#5  0x00000100 in ?? ()
#6  0x404a0f94 in __JCR_LIST__ () from /usr/lib/libcrypto.so.0.9.7
#7  0x40432639 in EVP_EncryptUpdate () from /usr/lib/libcrypto.so.0.9.7

When I only called set_locking_callback from the main thread I saw that the
locking function was never called, probably because it is the other threads
that are working with the EVP and not the main thread?

I am using win32, win64 and linux.

Cheers,

J

______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [hidden email]
Automated List Manager                           [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: multithreading question

Dr. Stephen Henson
On Sun, Sep 04, 2005, Jrgen Hovland wrote:

> Hi,
>
> I have a question about the use of openssl, EVP_CIPHER_CTXs, in a
> multithreaded environment.
> I have N threads calling a function that contains an EVP_CIPHER_CTX,
> ctx_init, EVP_CipherUpdate/Final and then Cleanup.
> The CTX is only used by that same thread calling the function.
>

I'm not sure what you mean by that description. An EVP_CIPHER_CTX by its very
nature should not be shared between threads.

> Must all N threads call CRYPTO_set_locking_callback before use?
> If so, can/should the callback function point to the same lock/mutexes for
> all threads or should they have their own lock per thread?
>

It should be set once before starting any threads.

Steve.
--
Dr Stephen N. Henson. Email, S/MIME and PGP keys: see homepage
OpenSSL project core developer and freelance consultant.
Funding needed! Details on homepage.
Homepage: http://www.drh-consultancy.demon.co.uk
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [hidden email]
Automated List Manager                           [hidden email]