Search code examples
c++multithreadingencryptioncryptographycrypto++

can crypto++ use [Private]key object be used simultaneously [in multi threads]


supposed we have global CryptoPP::ECIES<CryptoPP::ECP>::PrivateKey mykey initialized object ,and have 10 threads that run CryptoPP::ECIES<CryptoPP::ECP>::Encryptor myencrypto(mykey) for making a encryptor object by assigning key from mykey object

the assigner takes mykey as reference

do i need a Mutex to make sure that only one thread uses mykey at a time , or multi threads can assign enryptor from key object simultaneously without any problem (if yes , is that guaranteed)

(please note that threads only assign from the mykey simultaneously none of them modify it(my code doesn't don't know if the cryptoPP assigner does ))


Solution

  • After not receiving an answer i picked the mutex locks from my code and tested a few time when PrivateKey object was used simultaneously by multi thread for initializing mutli encryptors

    i was getting a assert at intger.cpp (cryptoPP lib source file) at line 2910

    CRYPTOPP_ASSERT(bcLen <= N);
    

    tested about 10 times ,and go the same assert , putted the mutex locks again and the assert was gone (in release mood i was getting 0xc000005 (access denied) at ntdll.dll because HeapFree() fucntion were being called with wrong argument