@@ -42,15 +42,19 @@ bool OldEncrypt(const CKeyingMaterial& vchPlaintext, std::vector<unsigned char>
42
42
int nCLen = nLen + AES_BLOCK_SIZE, nFLen = 0 ;
43
43
vchCiphertext = std::vector<unsigned char > (nCLen);
44
44
45
- EVP_CIPHER_CTX ctx;
45
+ EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new ();
46
+
47
+ if (!ctx) return false ;
46
48
47
49
bool fOk = true ;
48
50
49
- EVP_CIPHER_CTX_init (&ctx);
50
- if (fOk ) fOk = EVP_EncryptInit_ex (&ctx, EVP_aes_256_cbc (), NULL , chKey, chIV) != 0 ;
51
- if (fOk ) fOk = EVP_EncryptUpdate (&ctx, &vchCiphertext[0 ], &nCLen, &vchPlaintext[0 ], nLen) != 0 ;
52
- if (fOk ) fOk = EVP_EncryptFinal_ex (&ctx, (&vchCiphertext[0 ]) + nCLen, &nFLen) != 0 ;
53
- EVP_CIPHER_CTX_cleanup (&ctx);
51
+ EVP_CIPHER_CTX_init (ctx);
52
+ if (fOk ) fOk = EVP_EncryptInit_ex (ctx, EVP_aes_256_cbc (), NULL , chKey, chIV) != 0 ;
53
+ if (fOk ) fOk = EVP_EncryptUpdate (ctx, &vchCiphertext[0 ], &nCLen, &vchPlaintext[0 ], nLen) != 0 ;
54
+ if (fOk ) fOk = EVP_EncryptFinal_ex (ctx, (&vchCiphertext[0 ]) + nCLen, &nFLen) != 0 ;
55
+ EVP_CIPHER_CTX_cleanup (ctx);
56
+
57
+ EVP_CIPHER_CTX_free (ctx);
54
58
55
59
if (!fOk ) return false ;
56
60
@@ -66,15 +70,19 @@ bool OldDecrypt(const std::vector<unsigned char>& vchCiphertext, CKeyingMaterial
66
70
67
71
vchPlaintext = CKeyingMaterial (nPLen);
68
72
69
- EVP_CIPHER_CTX ctx;
73
+ EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new ();
74
+
75
+ if (!ctx) return false ;
70
76
71
77
bool fOk = true ;
72
78
73
- EVP_CIPHER_CTX_init (&ctx);
74
- if (fOk ) fOk = EVP_DecryptInit_ex (&ctx, EVP_aes_256_cbc (), NULL , chKey, chIV) != 0 ;
75
- if (fOk ) fOk = EVP_DecryptUpdate (&ctx, &vchPlaintext[0 ], &nPLen, &vchCiphertext[0 ], nLen) != 0 ;
76
- if (fOk ) fOk = EVP_DecryptFinal_ex (&ctx, (&vchPlaintext[0 ]) + nPLen, &nFLen) != 0 ;
77
- EVP_CIPHER_CTX_cleanup (&ctx);
79
+ EVP_CIPHER_CTX_init (ctx);
80
+ if (fOk ) fOk = EVP_DecryptInit_ex (ctx, EVP_aes_256_cbc (), NULL , chKey, chIV) != 0 ;
81
+ if (fOk ) fOk = EVP_DecryptUpdate (ctx, &vchPlaintext[0 ], &nPLen, &vchCiphertext[0 ], nLen) != 0 ;
82
+ if (fOk ) fOk = EVP_DecryptFinal_ex (ctx, (&vchPlaintext[0 ]) + nPLen, &nFLen) != 0 ;
83
+ EVP_CIPHER_CTX_cleanup (ctx);
84
+
85
+ EVP_CIPHER_CTX_free (ctx);
78
86
79
87
if (!fOk ) return false ;
80
88
0 commit comments