rijndael.hpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #ifndef _RIJNDAEL_H_
  2. #define _RIJNDAEL_H_
  3. /**************************************************************************
  4. * This code is based on Szymon Stefanek AES implementation: *
  5. * http://www.esat.kuleuven.ac.be/~rijmen/rijndael/rijndael-cpplib.tar.gz *
  6. * *
  7. * Dynamic tables generation is based on the Brian Gladman's work: *
  8. * http://fp.gladman.plus.com/cryptography_technology/rijndael *
  9. **************************************************************************/
  10. #define _MAX_KEY_COLUMNS (256/32)
  11. #define _MAX_ROUNDS 14
  12. #define MAX_IV_SIZE 16
  13. class Rijndael
  14. {
  15. public:
  16. enum Direction { Encrypt , Decrypt };
  17. private:
  18. void keySched(byte key[_MAX_KEY_COLUMNS][4]);
  19. void keyEncToDec();
  20. void encrypt(const byte a[16], byte b[16]);
  21. void decrypt(const byte a[16], byte b[16]);
  22. void GenerateTables();
  23. Direction m_direction;
  24. byte m_initVector[MAX_IV_SIZE];
  25. byte m_expandedKey[_MAX_ROUNDS+1][4][4];
  26. public:
  27. Rijndael();
  28. void init(Direction dir,const byte *key,byte *initVector);
  29. size_t blockEncrypt(const byte *input, size_t inputLen, byte *outBuffer);
  30. size_t blockDecrypt(const byte *input, size_t inputLen, byte *outBuffer);
  31. };
  32. #endif // _RIJNDAEL_H_