Index: rijndael.cpp
--- rijndael.cpp.orig
+++ rijndael.cpp
@@ -3,6 +3,8 @@
  **************************************************************************/
 #include "rar.hpp"
 
+#ifndef OPENSSL_AES
+
 #ifdef USE_SSE
 #include <wmmintrin.h>
 #endif
@@ -75,6 +77,7 @@ inline void Copy128(byte *dest,const byte *src)
 #endif
 }
 
+#endif // OPENSSL_AES
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 // API
@@ -82,14 +85,45 @@ inline void Copy128(byte *dest,const byte *src)
 
 Rijndael::Rijndael()
 {
+#ifdef OPENSSL_AES
+  ctx = NULL;
+#else
   if (S5[0]==0)
     GenerateTables();
+#endif
   CBCMode = true; // Always true for RAR.
 }
 
+#ifdef OPENSSL_AES
+Rijndael::~Rijndael()
+{
+  EVP_CIPHER_CTX_free(ctx);
+}
+#endif
 
 void Rijndael::Init(bool Encrypt,const byte *key,uint keyLen,const byte * initVector)
 {
+#ifdef OPENSSL_AES
+  const EVP_CIPHER *cipher;
+  switch(keyLen)
+  {
+    case 128:
+      cipher = EVP_aes_128_cbc();
+      break;
+    case 192:
+      cipher = EVP_aes_192_cbc();
+      break;
+    case 256:
+      cipher = EVP_aes_256_cbc();
+      break;
+  }
+
+  ctx = EVP_CIPHER_CTX_new();
+  if (ctx == NULL)
+    throw std::bad_alloc();
+  EVP_CipherInit_ex(ctx, cipher, NULL, key, initVector, Encrypt);
+  EVP_CIPHER_CTX_set_padding(ctx, 0);
+#else
   // Check SIMD here instead of constructor, so if object is a part of some
   // structure memset'ed before use, these variables are not lost.
 #if defined(USE_SSE)
@@ -141,6 +175,7 @@ void Rijndael::Init(bool Encrypt,const byte *key,uint 
 
   if(!Encrypt)
     keyEncToDec();
+#endif // OPENSSL_AES
 }
 
 
@@ -149,6 +184,11 @@ void Rijndael::blockEncrypt(const byte *input,size_t i
   if (inputLen <= 0)
     return;
 
+#ifdef OPENSSL_AES
+  int outLen;
+  EVP_CipherUpdate(ctx, outBuffer, &outLen, input, inputLen);
+  return;
+#else // OPENSSL_AES
   size_t numBlocks = inputLen/16;
 #if defined(USE_SSE)
   if (AES_NI)
@@ -213,9 +253,11 @@ void Rijndael::blockEncrypt(const byte *input,size_t i
     input += 16;
   }
   Copy128(m_initVector,prevBlock);
+#endif // OPENSSL_AES
 }
 
 
+#ifndef OPENSSL_AES
 #ifdef USE_SSE
 void Rijndael::blockEncryptSSE(const byte *input,size_t numBlocks,byte *outBuffer)
 {
@@ -281,6 +323,7 @@ void Rijndael::blockEncryptNeon(const byte *input,size
   return;
 }
 #endif
+#endif // OPENSSL_AES
 
   
 void Rijndael::blockDecrypt(const byte *input, size_t inputLen, byte *outBuffer)
@@ -288,6 +331,11 @@ void Rijndael::blockDecrypt(const byte *input, size_t 
   if (inputLen <= 0)
     return;
 
+#ifdef OPENSSL_AES
+  int outLen;
+  EVP_CipherUpdate(ctx, outBuffer, &outLen, input, inputLen);
+  return;
+#else
   size_t numBlocks=inputLen/16;
 #if defined(USE_SSE)
   if (AES_NI)
@@ -356,9 +404,11 @@ void Rijndael::blockDecrypt(const byte *input, size_t 
   }
 
   memcpy(m_initVector,iv,16);
+#endif // OPENSSL_AES
 }
 
 
+#ifndef OPENSSL_AES
 #ifdef USE_SSE
 void Rijndael::blockDecryptSSE(const byte *input, size_t numBlocks, byte *outBuffer)
 {
@@ -425,8 +475,10 @@ void Rijndael::blockDecryptNeon(const byte *input, siz
   memcpy(m_initVector,iv,16);
 }
 #endif
+#endif // OPENSSL_AES
 
 
+#ifndef OPENSSL_AES
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 // ALGORITHM
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -556,6 +608,7 @@ void Rijndael::GenerateTables()
   }
 }
 
+#endif // OPENSSL_AES
 
 #if 0
 static void TestRijndael();
