~ubuntu-branches/ubuntu/utopic/unrar-nonfree/utopic

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#ifndef _RIJNDAEL_H_
#define _RIJNDAEL_H_

/**************************************************************************
 * This code is based on Szymon Stefanek AES implementation:              *
 * http://www.esat.kuleuven.ac.be/~rijmen/rijndael/rijndael-cpplib.tar.gz *
 *                                                                        *
 * Dynamic tables generation is based on the Brian Gladman's work:        *
 * http://fp.gladman.plus.com/cryptography_technology/rijndael            *
 **************************************************************************/

#define _MAX_KEY_COLUMNS (256/32)
#define _MAX_ROUNDS      14
#define MAX_IV_SIZE      16

class Rijndael
{ 
  private:
    void keySched(byte key[_MAX_KEY_COLUMNS][4]);
    void keyEncToDec();
    void encrypt(const byte a[16], byte b[16]);
    void decrypt(const byte a[16], byte b[16]);
    void GenerateTables();

    int      m_uRounds;
    byte     m_initVector[MAX_IV_SIZE];
    byte     m_expandedKey[_MAX_ROUNDS+1][4][4];
  public:
    Rijndael();
    void Init(bool Encrypt,const byte *key,uint keyLen,const byte *initVector);
    size_t blockEncrypt(const byte *input, size_t inputLen, byte *outBuffer);
    size_t blockDecrypt(const byte *input, size_t inputLen, byte *outBuffer);
};
  
#endif // _RIJNDAEL_H_