Hello,
I have a simple example code to decrypt an encrypted message using rsa_private(). I use memory_buffer_alloc_init(), in order to use a static memory for the computation. I want to run my code concurrently. My code works with a single pthread. However, when I try to run more than one thread my program fails to decrypt.
** I check the same code without memory_buffer_alloc_init(), it works concurrently, without any issues at all.
Therefore, I believe, the issue that I'm facing is coming from the use of static memory(e.g. memory_buffer_alloc_init()). The documentation of memorry_buffer_alloc.h shows,
/**
* \brief Initialize use of stack-based memory allocator.
* The stack-based allocator does memory management inside the
* presented buffer and does not call malloc() and free().
* It sets the global polarssl_malloc() and polarssl_free() pointers
* to its own functions.
* (Provided polarssl_malloc() and polarssl_free() are thread-safe if
* POLARSSL_THREADING_C is defined)
*
* \note This code is not optimized and provides a straight-forward
* implementation of a stack-based memory allocator.
*
* \param buf buffer to use as heap
* \param len size of the buffer
*
* \return 0 if successful
*/
So, I added the following configuration to the config.h file
1. #define POLARSSL_THREADING_PTHREAD
2. #define POLARSSL_THREADING_C
But I'm still getting errors while decrypting. Any help on how to fix this? or what else should I add into the config.h file to make
memory_buffer_alloc_init() thread-safe? Here is my sample code:
https://pastebin.com/uyW3vknt
Thanks,
Shariful