$OpenBSD: patch-rijndael_cpp,v 1.1 2012/04/08 16:36:12 naddy Exp $
--- rijndael.cpp.orig	Wed Mar  2 08:43:12 2011
+++ rijndael.cpp	Fri Apr  6 00:32:04 2012
@@ -7,6 +7,8 @@
  **************************************************************************/
 #include "rar.hpp"
 
+#ifndef OPENSSL
+
 const int uKeyLenInBytes=16, m_uRounds=10;
 
 static byte S[256],S5[256],rcon[30];
@@ -54,6 +56,7 @@ inline void Copy128(byte *dest,const byte *src)
 #endif
 }
 
+#endif // OPENSSL
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 // API
@@ -61,13 +64,21 @@ inline void Copy128(byte *dest,const byte *src)
 
 Rijndael::Rijndael()
 {
+#ifndef OPENSSL
   if (S[0]==0)
     GenerateTables();
+#endif
 }
 
 
 void Rijndael::init(Direction dir,const byte * key,byte * initVector)
 {
+#ifdef OPENSSL
+  EVP_CIPHER_CTX_init(&ctx);
+  EVP_CipherInit_ex(&ctx, EVP_aes_128_cbc(), NULL, key, initVector,
+    dir == Decrypt ? 0 : 1);
+  EVP_CIPHER_CTX_set_padding(&ctx, 0);
+#else
   m_direction = dir;
 
   byte keyMatrix[_MAX_KEY_COLUMNS][4];
@@ -82,6 +93,7 @@ void Rijndael::init(Direction dir,const byte * key,byt
 
   if(m_direction == Decrypt)
     keyEncToDec();
+#endif // OPENSSL
 }
 
 
@@ -91,6 +103,11 @@ size_t Rijndael::blockDecrypt(const byte *input, size_
   if (input == 0 || inputLen <= 0)
     return 0;
 
+#ifdef OPENSSL
+  int outLen;
+  EVP_CipherUpdate(&ctx, outBuffer, &outLen, input, inputLen);
+  return outLen;
+#else
   byte block[16], iv[4][4];
   memcpy(iv,m_initVector,16); 
 
@@ -113,9 +130,11 @@ size_t Rijndael::blockDecrypt(const byte *input, size_
   memcpy(m_initVector,iv,16);
   
   return 16*numBlocks;
+#endif // OPENSSL
 }
 
 
+#ifndef OPENSSL
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 // ALGORITHM
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -296,3 +315,5 @@ void Rijndael::GenerateTables()
     U1[b][0]=U2[b][1]=U3[b][2]=U4[b][3]=T5[i][0]=T6[i][1]=T7[i][2]=T8[i][3]=FFmul0e(b);
   }
 }
+
+#endif // OPENSSL
