OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / user / unrar / rijndael.hpp
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   public:
19     enum Direction { Encrypt , Decrypt };
20   private:
21     void keySched(byte key[_MAX_KEY_COLUMNS][4]);
22     void keyEncToDec();
23     void encrypt(const byte a[16], byte b[16]);
24     void decrypt(const byte a[16], byte b[16]);
25     void GenerateTables();
26
27     Direction m_direction;
28     byte     m_initVector[MAX_IV_SIZE];
29     byte     m_expandedKey[_MAX_ROUNDS+1][4][4];
30   public:
31     Rijndael();
32     void init(Direction dir,const byte *key,byte *initVector);
33     int blockEncrypt(const byte *input, int inputLen, byte *outBuffer);
34     int blockDecrypt(const byte *input, int inputLen, byte *outBuffer);
35 };
36         
37 #endif // _RIJNDAEL_H_