diff options
author | Caolán McNamara <caolanm@redhat.com> | 2020-07-20 10:23:38 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2020-07-20 12:23:42 +0200 |
commit | 92146170f1a317e69201f2c801325325182476d2 (patch) | |
tree | 5b1ce214d9dc8fac62b26d87326b22e4fe520a5e | |
parent | 57d6ba4e49ebe3adfcb471e34ac2d4be14e1bce3 (diff) |
fix --with-tls=openssl build with openssl upgrade
Change-Id: I0fece9f692637dc6948355c210534f5333fab7ed
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99030
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r-- | oox/source/crypto/CryptTools.cxx | 45 |
1 files changed, 36 insertions, 9 deletions
diff --git a/oox/source/crypto/CryptTools.cxx b/oox/source/crypto/CryptTools.cxx index 3b95616df18e..77b6f8c11988 100644 --- a/oox/source/crypto/CryptTools.cxx +++ b/oox/source/crypto/CryptTools.cxx @@ -27,16 +27,46 @@ namespace oox::crypto { #if USE_TLS_OPENSSL + +#if (OPENSSL_VERSION_NUMBER < 0x10100000L) + +static HMAC_CTX *HMAC_CTX_new(void) +{ + HMAC_CTX *pContext = new HMAC_CTX; + HMAC_CTX_init(pContext); + return pContext; +} + +static void HMAC_CTX_free(HMAC_CTX *pContext) +{ + HMAC_CTX_cleanup(pContext); + delete pContext; +} +#endif + +namespace +{ + struct cipher_delete + { + void operator()(EVP_CIPHER_CTX* p) { EVP_CIPHER_CTX_free(p); } + }; + + struct hmac_delete + { + void operator()(HMAC_CTX* p) { HMAC_CTX_free(p); } + }; +} + struct CryptoImpl { - std::unique_ptr<EVP_CIPHER_CTX> mpContext; - std::unique_ptr<HMAC_CTX> mpHmacContext; + std::unique_ptr<EVP_CIPHER_CTX, cipher_delete> mpContext; + std::unique_ptr<HMAC_CTX, hmac_delete> mpHmacContext; CryptoImpl() = default; void setupEncryptContext(std::vector<sal_uInt8>& key, std::vector<sal_uInt8>& iv, Crypto::CryptoType eType) { - mpContext.reset(new EVP_CIPHER_CTX); + mpContext.reset(EVP_CIPHER_CTX_new()); EVP_CIPHER_CTX_init(mpContext.get()); const EVP_CIPHER* cipher = getCipher(eType); @@ -52,7 +82,7 @@ struct CryptoImpl void setupDecryptContext(std::vector<sal_uInt8>& key, std::vector<sal_uInt8>& iv, Crypto::CryptoType eType) { - mpContext.reset(new EVP_CIPHER_CTX); + mpContext.reset(EVP_CIPHER_CTX_new()); EVP_CIPHER_CTX_init(mpContext.get()); const EVP_CIPHER* pCipher = getCipher(eType); @@ -78,8 +108,7 @@ struct CryptoImpl void setupCryptoHashContext(std::vector<sal_uInt8>& rKey, CryptoHashType eType) { - mpHmacContext.reset(new HMAC_CTX); - HMAC_CTX_init(mpHmacContext.get()); + mpHmacContext.reset(HMAC_CTX_new()); const EVP_MD* aEvpMd; switch (eType) { @@ -90,15 +119,13 @@ struct CryptoImpl case CryptoHashType::SHA512: aEvpMd = EVP_sha512(); break; } - HMAC_Init(mpHmacContext.get(), rKey.data(), rKey.size(), aEvpMd); + HMAC_Init_ex(mpHmacContext.get(), rKey.data(), rKey.size(), aEvpMd, nullptr); } ~CryptoImpl() { if (mpContext) EVP_CIPHER_CTX_cleanup(mpContext.get()); - if (mpHmacContext) - HMAC_CTX_cleanup(mpHmacContext.get()); } static const EVP_CIPHER* getCipher(Crypto::CryptoType type) |