Skip to content

Commit

Permalink
Make context a static variable so that it doesn't get created everytime
Browse files Browse the repository at this point in the history
  • Loading branch information
neilcook committed Jul 25, 2023
1 parent 7dc2c26 commit 0be7952
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions common/sodcrypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ std::string sodEncryptSym(const std::string& msg, const std::string& key, Sodium
int len;
int ciphertext_len;
// Each thread gets its own cipher context
thread_local auto ctx = std::unique_ptr<EVP_CIPHER_CTX, decltype(&EVP_CIPHER_CTX_free)>(nullptr, EVP_CIPHER_CTX_free);;
static thread_local auto ctx = std::unique_ptr<EVP_CIPHER_CTX, decltype(&EVP_CIPHER_CTX_free)>(nullptr, EVP_CIPHER_CTX_free);

if (key.length() != CHACHA20_POLY1305_KEY_SIZE) {
ostringstream err;
Expand Down Expand Up @@ -126,7 +126,7 @@ std::string sodDecryptSym(const std::string& msg, const std::string& key, Sodium
int len;
int plaintext_len;
// Each thread gets its own cipher context
thread_local auto ctx = std::unique_ptr<EVP_CIPHER_CTX, decltype(&EVP_CIPHER_CTX_free)>(nullptr, EVP_CIPHER_CTX_free);;
static thread_local auto ctx = std::unique_ptr<EVP_CIPHER_CTX, decltype(&EVP_CIPHER_CTX_free)>(nullptr, EVP_CIPHER_CTX_free);

if (key.length() != CHACHA20_POLY1305_KEY_SIZE) {
ostringstream err;
Expand Down

0 comments on commit 0be7952

Please sign in to comment.