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
58
59
60
61
62
63
64
65
66
67
68
|
$NetBSD: patch-Crypto_src_CipherImpl.cpp,v 1.1 2020/03/27 02:08:11 joerg Exp $
--- Crypto/src/CipherImpl.cpp.orig 2020-03-27 00:11:42.909559121 +0000
+++ Crypto/src/CipherImpl.cpp
@@ -77,7 +77,7 @@ namespace
private:
const EVP_CIPHER* _pCipher;
- EVP_CIPHER_CTX _ctx;
+ EVP_CIPHER_CTX *_ctx;
ByteVec _key;
ByteVec _iv;
};
@@ -92,9 +92,10 @@ namespace
_key(key),
_iv(iv)
{
- EVP_CipherInit(
- &_ctx,
- _pCipher,
+ _ctx = EVP_CIPHER_CTX_new();
+ EVP_CipherInit_ex(
+ _ctx,
+ _pCipher, NULL,
&_key[0],
_iv.empty() ? 0 : &_iv[0],
(dir == DIR_ENCRYPT) ? 1 : 0);
@@ -103,19 +104,19 @@ namespace
CryptoTransformImpl::~CryptoTransformImpl()
{
- EVP_CIPHER_CTX_cleanup(&_ctx);
+ EVP_CIPHER_CTX_free(_ctx);
}
std::size_t CryptoTransformImpl::blockSize() const
{
- return EVP_CIPHER_CTX_block_size(&_ctx);
+ return EVP_CIPHER_CTX_block_size(_ctx);
}
int CryptoTransformImpl::setPadding(int padding)
{
- return EVP_CIPHER_CTX_set_padding(&_ctx, padding);
+ return EVP_CIPHER_CTX_set_padding(_ctx, padding);
}
@@ -129,7 +130,7 @@ namespace
int outLen = static_cast<int>(outputLength);
int rc = EVP_CipherUpdate(
- &_ctx,
+ _ctx,
output,
&outLen,
input,
@@ -153,7 +154,7 @@ namespace
// Use the '_ex' version that does not perform implicit cleanup since we
// will call EVP_CIPHER_CTX_cleanup() from the dtor as there is no
// guarantee that finalize() will be called if an error occurred.
- int rc = EVP_CipherFinal_ex(&_ctx, output, &len);
+ int rc = EVP_CipherFinal_ex(_ctx, output, &len);
if (rc == 0)
throwError();
|