Update archivers/unrar to version 5.30,5
[dports.git] / archivers / unrar / files / patch-rijndael.cpp
1 --- rijndael.cpp.orig   2014-06-10 17:14:06 UTC
2 +++ rijndael.cpp
3 @@ -7,6 +7,8 @@
4   ***************************************************************************/
5  #include "rar.hpp"
6  
7 +#ifndef OPENSSL_AES
8 +
9  #ifdef USE_SSE
10  #include <wmmintrin.h>
11  #endif
12 @@ -56,6 +58,7 @@
13  #endif
14  }
15  
16 +#endif // OPENSSL_AES
17  
18  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
19  // API
20 @@ -63,14 +66,35 @@
21  
22  Rijndael::Rijndael()
23  {
24 +#ifndef OPENSSL_AES
25    if (S[0]==0)
26      GenerateTables();
27 +#endif // OPENSSL_AES
28    CBCMode = true; // Always true for RAR.
29  }
30  
31  
32  void Rijndael::Init(bool Encrypt,const byte *key,uint keyLen,const byte * initVector)
33  {
34 +#ifdef OPENSSL_AES
35 +  const EVP_CIPHER *cipher;
36 +  switch(keyLen)
37 +  {
38 +    case 128:
39 +      cipher = EVP_aes_128_cbc();
40 +      break;
41 +    case 192:
42 +      cipher = EVP_aes_192_cbc();
43 +      break;
44 +    case 256:
45 +      cipher = EVP_aes_256_cbc();
46 +      break;
47 +  }
48 +
49 +  EVP_CIPHER_CTX_init(&ctx);
50 +  EVP_CipherInit_ex(&ctx, cipher, NULL, key, initVector, Encrypt);
51 +  EVP_CIPHER_CTX_set_padding(&ctx, 0);
52 +#else // OPENSSL_AES
53  #ifdef USE_SSE
54    // Check SSE here instead of constructor, so if object is a part of some
55    // structure memset'ed before use, this variable is not lost.
56 @@ -111,6 +135,7 @@
57  
58    if(!Encrypt)
59      keyEncToDec();
60 +#endif // OPENSSL_AES
61  }
62  
63  
64 @@ -120,6 +145,11 @@
65    if (inputLen <= 0)
66      return;
67  
68 +#ifdef OPENSSL_AES
69 +  int outLen;
70 +  EVP_CipherUpdate(&ctx, outBuffer, &outLen, input, inputLen);
71 +  return;
72 +#else // OPENSSL_AES
73    size_t numBlocks=inputLen/16;
74  #ifdef USE_SSE
75    if (AES_NI)
76 @@ -182,6 +212,8 @@
77    }
78  
79    memcpy(m_initVector,iv,16);
80 +
81 +#endif // OPENSSL_AES
82  }
83  
84  
85 @@ -217,7 +249,7 @@
86  }
87  #endif
88  
89 -
90 +#ifndef OPENSSL_AES
91  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
92  // ALGORITHM
93  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
94 @@ -357,7 +389,7 @@
95      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);
96    }
97  }
98 -
99 +#endif // OPENSSL_AES
100  
101  #if 0
102  static void TestRijndael();