summaryrefslogtreecommitdiff
path: root/net/freerdp1/files/patch-winpr_libwinpr_crypto_crypto.c
blob: e95843135763f9fccede7ae77f6d79a49b7df232 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
--- winpr/libwinpr/crypto/crypto.c.orig	2018-11-06 02:41:23 UTC
+++ winpr/libwinpr/crypto/crypto.c
@@ -177,20 +177,37 @@ BOOL CryptProtectMemory(LPVOID pData, DWORD cbData, DW
 
 	SecureZeroMemory(randomKey, sizeof(randomKey));
 
+#if OPENSSL_VERSION_NUMBER >= 0x1010000fL
+	pMemBlock->enc = EVP_CIPHER_CTX_new();
+	pMemBlock->dec = EVP_CIPHER_CTX_new();
+
+	EVP_CIPHER_CTX_init(pMemBlock->enc);
+	EVP_EncryptInit_ex(pMemBlock->enc, EVP_aes_256_cbc(), NULL, pMemBlock->key, pMemBlock->iv);
+
+	EVP_CIPHER_CTX_init(pMemBlock->dec);
+	EVP_DecryptInit_ex(pMemBlock->dec, EVP_aes_256_cbc(), NULL, pMemBlock->key, pMemBlock->iv);
+#else
 	EVP_CIPHER_CTX_init(&(pMemBlock->enc));
 	EVP_EncryptInit_ex(&(pMemBlock->enc), EVP_aes_256_cbc(), NULL, pMemBlock->key, pMemBlock->iv);
 
 	EVP_CIPHER_CTX_init(&(pMemBlock->dec));
 	EVP_DecryptInit_ex(&(pMemBlock->dec), EVP_aes_256_cbc(), NULL, pMemBlock->key, pMemBlock->iv);
+#endif
 
 	/* AES Encryption */
 
 	cbOut = pMemBlock->cbData + AES_BLOCK_SIZE - 1;
 	pCipherText = (BYTE*) malloc(cbOut);
 
+#if OPENSSL_VERSION_NUMBER >= 0x1010000fL
+	EVP_EncryptInit_ex(pMemBlock->enc, NULL, NULL, NULL, NULL);
+	EVP_EncryptUpdate(pMemBlock->enc, pCipherText, &cbOut, pMemBlock->pData, pMemBlock->cbData);
+	EVP_EncryptFinal_ex(pMemBlock->enc, pCipherText + cbOut, &cbFinal);
+#else
 	EVP_EncryptInit_ex(&(pMemBlock->enc), NULL, NULL, NULL, NULL);
 	EVP_EncryptUpdate(&(pMemBlock->enc), pCipherText, &cbOut, pMemBlock->pData, pMemBlock->cbData);
 	EVP_EncryptFinal_ex(&(pMemBlock->enc), pCipherText + cbOut, &cbFinal);
+#endif
 
 	CopyMemory(pMemBlock->pData, pCipherText, pMemBlock->cbData);
 	free(pCipherText);
@@ -233,9 +250,15 @@ BOOL CryptUnprotectMemory(LPVOID pData, DWORD cbData, 
 	ListDictionary_Remove(g_ProtectedMemoryBlocks, pData);
 
 	/* AES Cleanup */
-
+#if OPENSSL_VERSION_NUMBER >= 0x1010000fL
+	EVP_CIPHER_CTX_cleanup(pMemBlock->enc);
+	EVP_CIPHER_CTX_cleanup(pMemBlock->dec);
+	EVP_CIPHER_CTX_free(pMemBlock->enc);
+	EVP_CIPHER_CTX_free(pMemBlock->dec);
+#else
 	EVP_CIPHER_CTX_cleanup(&(pMemBlock->enc));
 	EVP_CIPHER_CTX_cleanup(&(pMemBlock->dec));
+#endif
 
 	free(pMemBlock);