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 USE_SSE 20 void blockEncryptSSE(const byte *input,size_t numBlocks,byte *outBuffer); 21 void blockDecryptSSE(const byte *input, size_t numBlocks, byte *outBuffer); 22 23 bool AES_NI; 24 #endif 25 void keySched(byte key[_MAX_KEY_COLUMNS][4]); 26 void keyEncToDec(); 27 void GenerateTables(); 28 29 // RAR always uses CBC, but we may need to turn it off when calling 30 // this code from other archive formats with CTR and other modes. 31 bool CBCMode; 32 33 int m_uRounds; 34 byte m_initVector[MAX_IV_SIZE]; 35 byte m_expandedKey[_MAX_ROUNDS+1][4][4]; 36 public: 37 Rijndael(); 38 void Init(bool Encrypt,const byte *key,uint keyLen,const byte *initVector); 39 void blockEncrypt(const byte *input, size_t inputLen, byte *outBuffer); 40 void blockDecrypt(const byte *input, size_t inputLen, byte *outBuffer); SetCBCMode(bool Mode)41 void SetCBCMode(bool Mode) {CBCMode=Mode;} 42 }; 43 44 #endif // _RIJNDAEL_H_ 45