Skip to content

Commit f135856

Browse files
authored
common/crypto_openssl: fix build with openssl >= 3.0.0
DES encryption is considered legacy and is no longer available by default. To use it legacy provider must be load.
1 parent 80ea6bc commit f135856

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

common/crypto_openssl.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
#include <openssl/dh.h>
2929
#include <openssl/evp.h>
3030
#include <openssl/rand.h>
31+
#if (OPENSSL_VERSION_NUMBER >= 0x30000000L)
32+
#include <openssl/provider.h>
33+
#endif
3134
#include "crypto.h"
3235

3336
static unsigned char reverseByte(unsigned char b) {
@@ -69,13 +72,25 @@ void random_bytes(void *out, size_t len)
6972
int encrypt_rfbdes(void *out, int *out_len, const unsigned char key[8], const void *in, const size_t in_len)
7073
{
7174
int result = 0;
72-
EVP_CIPHER_CTX *des;
75+
EVP_CIPHER_CTX *des = NULL;
7376
unsigned char mungedkey[8];
7477
int i;
78+
#if (OPENSSL_VERSION_NUMBER >= 0x30000000L)
79+
OSSL_PROVIDER *providerLegacy = NULL;
80+
OSSL_PROVIDER *providerDefault = NULL;
81+
#endif
7582

7683
for (i = 0; i < 8; i++)
7784
mungedkey[i] = reverseByte(key[i]);
7885

86+
#if (OPENSSL_VERSION_NUMBER >= 0x30000000L)
87+
/* Load Multiple providers into the default (NULL) library context */
88+
if (!(providerLegacy = OSSL_PROVIDER_load(NULL, "legacy")))
89+
goto out;
90+
if (!(providerDefault = OSSL_PROVIDER_load(NULL, "default")))
91+
goto out;
92+
#endif
93+
7994
if(!(des = EVP_CIPHER_CTX_new()))
8095
goto out;
8196
if(!EVP_EncryptInit_ex(des, EVP_des_ecb(), NULL, mungedkey, NULL))
@@ -86,7 +101,14 @@ int encrypt_rfbdes(void *out, int *out_len, const unsigned char key[8], const vo
86101
result = 1;
87102

88103
out:
89-
EVP_CIPHER_CTX_free(des);
104+
if (des)
105+
EVP_CIPHER_CTX_free(des);
106+
#if (OPENSSL_VERSION_NUMBER >= 0x30000000L)
107+
if (providerLegacy)
108+
OSSL_PROVIDER_unload(providerLegacy);
109+
if (providerDefault)
110+
OSSL_PROVIDER_unload(providerDefault);
111+
#endif
90112
return result;
91113
}
92114

0 commit comments

Comments
 (0)