To answer my own question, after checking the documentation,
I think that the answer is NO, you can't give the same buffers
to multiple threads.
I would appreciate if anyone can confirm this, because I've faced
some pretty weird bugs (which are not deterministic, I mean in the
most cases my program seems to work correctly, but in some cases
it doesn't) and I can't find why!
"In particular, being configured for threads support does not
imply that all OpenSSL objects are thread-safe.
To emphasize: most objects are not safe for simultaneous use."
On Thu, Jul 20, 2023 at 12:21 AM Dim Xr <dimxrss@xxxxxxxxx> wrote:
Hi all!At the moment I'm experimenting with OpenSSL-3.1.0, and I'mtrying to encrypt in parallel a block of data.Let's say that I have a block of 4096 bytes stored in a buffer.Can I pass to worker threads a pointer to this buffer (let' callit input_buf), a pointer to an output buffer (let's call it output_buf)and a corresponding tweak value and let them work in parallel?So each thread (in short) will compute something like (error handlingis abbreviated):cipher = EVP_CIPHER_fetch(NULL, "AES-256-XTS", NULL);EVP_EncryptInit_ex2(ctx, cipher, key, NULL, NULL);EVP_EncryptInit_ex2(ctx, NULL, NULL, tweak, NULL);EVP_EncryptUpdate(ctx, outbuf + relative_bytes, &encrypt_size,input_buf + relative_bytes, inputsize);To put it another way, can multiple threads work **on the sameinput and output buffers** (but in different regions of course) inparallel?Thanks,Dimitris