Optimize OpenSSL backend to avoid redundant reinitialization

It is best to pass as few parameters to EVP_*Init_ex() as possible.
Passing a key, IV, or cipher will cause redundant work to happen behind
the scenes as OpenSSL doesn't check whether they have actually changed.

This avoids a malloc()/free() and redoing AES key expansion for every
message that is encrypted and decrypted.
This commit is contained in:
Cameron Gutman
2021-04-22 17:34:48 -05:00
parent 29d2cc6d5b
commit 8354c403f4
2 changed files with 67 additions and 19 deletions

View File

@@ -14,7 +14,7 @@ typedef struct _PLT_CRYPTO_CONTEXT {
bool initialized;
mbedtls_cipher_context_t ctx;
#else
bool initialized; // Used for CBC only
bool initialized;
EVP_CIPHER_CTX* ctx;
#endif
} PLT_CRYPTO_CONTEXT, *PPLT_CRYPTO_CONTEXT;