|
|
@@ -77,7 +77,11 @@ namespace
|
|
|
|
|
|
private:
|
|
|
const EVP_CIPHER* _pCipher;
|
|
|
- EVP_CIPHER_CTX _ctx;
|
|
|
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
|
|
|
+ EVP_CIPHER_CTX* _pContext;
|
|
|
+#else
|
|
|
+ EVP_CIPHER_CTX _context;
|
|
|
+#endif
|
|
|
ByteVec _key;
|
|
|
ByteVec _iv;
|
|
|
};
|
|
|
@@ -92,30 +96,52 @@ namespace
|
|
|
_key(key),
|
|
|
_iv(iv)
|
|
|
{
|
|
|
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
|
|
|
+ _pContext = EVP_CIPHER_CTX_new();
|
|
|
EVP_CipherInit(
|
|
|
- &_ctx,
|
|
|
+ _pContext,
|
|
|
_pCipher,
|
|
|
&_key[0],
|
|
|
_iv.empty() ? 0 : &_iv[0],
|
|
|
(dir == DIR_ENCRYPT) ? 1 : 0);
|
|
|
+#else
|
|
|
+ EVP_CipherInit(
|
|
|
+ &_context,
|
|
|
+ _pCipher,
|
|
|
+ &_key[0],
|
|
|
+ _iv.empty() ? 0 : &_iv[0],
|
|
|
+ (dir == DIR_ENCRYPT) ? 1 : 0);
|
|
|
+#endif
|
|
|
}
|
|
|
|
|
|
|
|
|
CryptoTransformImpl::~CryptoTransformImpl()
|
|
|
{
|
|
|
- EVP_CIPHER_CTX_cleanup(&_ctx);
|
|
|
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
|
|
|
+ EVP_CIPHER_CTX_cleanup(_pContext);
|
|
|
+#else
|
|
|
+ EVP_CIPHER_CTX_cleanup(&_context);
|
|
|
+#endif
|
|
|
}
|
|
|
|
|
|
|
|
|
std::size_t CryptoTransformImpl::blockSize() const
|
|
|
{
|
|
|
- return EVP_CIPHER_CTX_block_size(&_ctx);
|
|
|
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
|
|
|
+ return EVP_CIPHER_CTX_block_size(_pContext);
|
|
|
+#else
|
|
|
+ return EVP_CIPHER_CTX_block_size(&_context);
|
|
|
+#endif
|
|
|
}
|
|
|
|
|
|
|
|
|
int CryptoTransformImpl::setPadding(int padding)
|
|
|
{
|
|
|
- return EVP_CIPHER_CTX_set_padding(&_ctx, padding);
|
|
|
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
|
|
|
+ return EVP_CIPHER_CTX_block_size(_pContext);
|
|
|
+#else
|
|
|
+ return EVP_CIPHER_CTX_set_padding(&_context, padding);
|
|
|
+#endif
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -128,13 +154,21 @@ namespace
|
|
|
poco_assert (outputLength >= (inputLength + blockSize() - 1));
|
|
|
|
|
|
int outLen = static_cast<int>(outputLength);
|
|
|
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
|
|
|
int rc = EVP_CipherUpdate(
|
|
|
- &_ctx,
|
|
|
+ _pContext,
|
|
|
output,
|
|
|
&outLen,
|
|
|
input,
|
|
|
static_cast<int>(inputLength));
|
|
|
-
|
|
|
+#else
|
|
|
+ int rc = EVP_CipherUpdate(
|
|
|
+ &_context,
|
|
|
+ output,
|
|
|
+ &outLen,
|
|
|
+ input,
|
|
|
+ static_cast<int>(inputLength));
|
|
|
+#endif
|
|
|
if (rc == 0)
|
|
|
throwError();
|
|
|
|
|
|
@@ -153,7 +187,11 @@ 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);
|
|
|
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
|
|
|
+ int rc = EVP_CipherFinal_ex(_pContext, output, &len);
|
|
|
+#else
|
|
|
+ int rc = EVP_CipherFinal_ex(&_context, output, &len);
|
|
|
+#endif
|
|
|
|
|
|
if (rc == 0)
|
|
|
throwError();
|