Skip to content

Commit 6e777e6

Browse files
authored
common/crypto_openssl: load legacy provider in decrypt_rfbdes()
Commit f135856 added the same code to encrypt_rfbdes() Signed-off-by: Christian Hitz <christian.hitz@bbv.ch>
1 parent 042a816 commit 6e777e6

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

src/common/crypto_openssl.c

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,24 +115,45 @@ int encrypt_rfbdes(void *out, int *out_len, const unsigned char key[8], const vo
115115
int decrypt_rfbdes(void *out, int *out_len, const unsigned char key[8], const void *in, const size_t in_len)
116116
{
117117
int result = 0;
118-
EVP_CIPHER_CTX *des;
118+
EVP_CIPHER_CTX *des = NULL;
119119
unsigned char mungedkey[8];
120120
int i;
121+
#if (OPENSSL_VERSION_NUMBER >= 0x30000000L)
122+
OSSL_PROVIDER *providerLegacy = NULL;
123+
OSSL_PROVIDER *providerDefault = NULL;
124+
#endif
121125

122126
for (i = 0; i < 8; i++)
123127
mungedkey[i] = reverseByte(key[i]);
124128

129+
#if (OPENSSL_VERSION_NUMBER >= 0x30000000L)
130+
/* Load Multiple providers into the default (NULL) library context */
131+
if (!(providerLegacy = OSSL_PROVIDER_load(NULL, "legacy")))
132+
goto out;
133+
if (!(providerDefault = OSSL_PROVIDER_load(NULL, "default")))
134+
goto out;
135+
#endif
136+
125137
if(!(des = EVP_CIPHER_CTX_new()))
126138
goto out;
127139
if(!EVP_DecryptInit_ex(des, EVP_des_ecb(), NULL, mungedkey, NULL))
128140
goto out;
141+
if(!EVP_CIPHER_CTX_set_padding(des, 0))
142+
goto out;
129143
if(!EVP_DecryptUpdate(des, out, out_len, in, in_len))
130144
goto out;
131145

132146
result = 1;
133147

134148
out:
135-
EVP_CIPHER_CTX_free(des);
149+
if (des)
150+
EVP_CIPHER_CTX_free(des);
151+
#if (OPENSSL_VERSION_NUMBER >= 0x30000000L)
152+
if (providerLegacy)
153+
OSSL_PROVIDER_unload(providerLegacy);
154+
if (providerDefault)
155+
OSSL_PROVIDER_unload(providerDefault);
156+
#endif
136157
return result;
137158
}
138159

0 commit comments

Comments
 (0)