1
0

rijndael.hpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #ifndef _RIJNDAEL_H_
  2. #define _RIJNDAEL_H_
  3. /**************************************************************************
  4. * This code is based on Szymon Stefanek public domain AES implementation *
  5. **************************************************************************/
  6. #define _MAX_KEY_COLUMNS (256/32)
  7. #define _MAX_ROUNDS 14
  8. #define MAX_IV_SIZE 16
  9. class Rijndael
  10. {
  11. private:
  12. #ifdef USE_SSE
  13. void blockEncryptSSE(const byte *input,size_t numBlocks,byte *outBuffer);
  14. void blockDecryptSSE(const byte *input, size_t numBlocks, byte *outBuffer);
  15. bool AES_NI;
  16. #endif
  17. void keySched(byte key[_MAX_KEY_COLUMNS][4]);
  18. void keyEncToDec();
  19. void GenerateTables();
  20. // RAR always uses CBC, but we may need to turn it off when calling
  21. // this code from other archive formats with CTR and other modes.
  22. bool CBCMode;
  23. int m_uRounds;
  24. byte m_initVector[MAX_IV_SIZE];
  25. byte m_expandedKey[_MAX_ROUNDS+1][4][4];
  26. public:
  27. Rijndael();
  28. void Init(bool Encrypt,const byte *key,uint keyLen,const byte *initVector);
  29. void blockEncrypt(const byte *input, size_t inputLen, byte *outBuffer);
  30. void blockDecrypt(const byte *input, size_t inputLen, byte *outBuffer);
  31. void SetCBCMode(bool Mode) {CBCMode=Mode;}
  32. };
  33. #endif // _RIJNDAEL_H_