Core/Crypto: Fixed loading legacy openssl provider for RC4 on windows

This commit is contained in:
Shauren
2022-06-14 23:18:42 +02:00
parent 13c44517da
commit 3fa46c6dc1
6 changed files with 34 additions and 33 deletions

View File

@@ -18,24 +18,16 @@
#include "ARC4.h"
#include "Errors.h"
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
#include <openssl/provider.h>
#endif
Trinity::Crypto::ARC4::ARC4() : _ctx(EVP_CIPHER_CTX_new())
{
EVP_CIPHER const* cipher;
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
_libCtx = OSSL_LIB_CTX_new();
_legacyProvider = OSSL_PROVIDER_load(_libCtx, "legacy");
cipher = EVP_CIPHER_fetch(_libCtx, "RC4", "");
_cipher = EVP_CIPHER_fetch(nullptr, "RC4", nullptr);
#else
cipher = EVP_rc4();
_cipher = EVP_rc4();
#endif
EVP_CIPHER_CTX_init(_ctx);
int result = EVP_EncryptInit_ex(_ctx, cipher, nullptr, nullptr, nullptr);
int result = EVP_EncryptInit_ex(_ctx, _cipher, nullptr, nullptr, nullptr);
ASSERT(result == 1);
}
@@ -44,8 +36,7 @@ Trinity::Crypto::ARC4::~ARC4()
EVP_CIPHER_CTX_free(_ctx);
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
OSSL_PROVIDER_unload(_legacyProvider);
OSSL_LIB_CTX_free(_libCtx);
EVP_CIPHER_free(_cipher);
#endif
}