1 #ifndef _RIJNDAEL_H_ 2 #define _RIJNDAEL_H_ 3 4 /************************************************************************** 5 * This code is based on Szymon Stefanek AES implementation: * 6 * http://www.esat.kuleuven.ac.be/~rijmen/rijndael/rijndael-cpplib.tar.gz * 7 * * 8 * Dynamic tables generation is based on the Brian Gladman's work: * 9 * http://fp.gladman.plus.com/cryptography_technology/rijndael * 10 **************************************************************************/ 11 12 #define _MAX_KEY_COLUMNS (256/32) 13 #define _MAX_ROUNDS 14 14 #define MAX_IV_SIZE 16 15 16 class Rijndael 17 { 18 private: 19 #ifdef OPENSSL_AES 20 #if OPENSSL_VERSION_NUMBER < 0x10100000L 21 EVP_CIPHER_CTX ctx; 22 #else 23 EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new(); 24 #endif 25 #else // OPENSSL_AES 26 #ifdef USE_SSE 27 void blockEncryptSSE(const byte *input,size_t numBlocks,byte *outBuffer); 28 void blockDecryptSSE(const byte *input, size_t numBlocks, byte *outBuffer); 29 30 bool AES_NI; 31 #endif 32 void keySched(byte key[_MAX_KEY_COLUMNS][4]); 33 void keyEncToDec(); 34 void GenerateTables(); 35 #endif // OPENSSL_AES 36 37 // RAR always uses CBC, but we may need to turn it off when calling 38 // this code from other archive formats with CTR and other modes. 39 bool CBCMode; 40 41 int m_uRounds; 42 byte m_initVector[MAX_IV_SIZE]; 43 byte m_expandedKey[_MAX_ROUNDS+1][4][4]; 44 public: 45 Rijndael(); 46 void Init(bool Encrypt,const byte *key,uint keyLen,const byte *initVector); 47 void blockEncrypt(const byte *input, size_t inputLen, byte *outBuffer); 48 void blockDecrypt(const byte *input, size_t inputLen, byte *outBuffer); SetCBCMode(bool Mode)49 void SetCBCMode(bool Mode) {CBCMode=Mode;} 50 }; 51 52 #endif // _RIJNDAEL_H_ 53