Remove 'using namespace std;'
[aes.git] / aes.hpp
1 #ifndef AES_HPP
2 #define AES_HPP
3
4 #include <vector>
5 #include <cstdio>
6 #include <string>
7 #include <iostream>
8
9 // Byte and Byte Array types
10 typedef unsigned char byte;
11 typedef std::vector<byte> byteArray;
12
13 // Word and Word Array types
14 typedef unsigned int word;
15 typedef std::vector<word> wordArray;
16
17 // Exceptions
18 class incorrectKeySizeException { };
19 class incorrectTextSizeException { };
20 class badStateArrayException { };
21
22 class AES
23 {
24         public:
25                 AES (const byteArray& key);
26
27                 byteArray encrypt (const byteArray& plaintext) const;
28                 byteArray decrypt (const byteArray& ciphertext) const;
29
30         private:
31                 /* Block size in words -- Always constant in AES.
32                  *
33                  * We also might as well make this static and share it between
34                  * all instances of AES. */
35                 static const unsigned int Nb = 4;
36
37                 /* Key size in words -- can be 4, 6, or 8.
38                  *
39                  * Once it is set by the constructor, it will never change */
40                 const unsigned int Nk;
41
42                 /* Number of rounds -- depends on key size.
43                  *
44                  * Once it is set by the constructor, it will never change */
45                 const unsigned int Nr;
46
47                 wordArray keySchedule;
48
49                 void KeyExpansion (const byteArray& key, wordArray& w) const;
50                 word SubWord (const word& input) const;
51                 word RotWord (const word& input) const;
52                 wordArray GetRoundKey (const int round) const;
53
54                 void SubBytes (byteArray& state) const;
55                 void ShiftRows (byteArray& state) const;
56                 void MixColumns (byteArray& state) const;
57                 void AddRoundKey (byteArray& state, const wordArray& w) const;
58
59                 void InvSubBytes (byteArray& state) const;
60                 void InvShiftRows (byteArray& state) const;
61                 void InvMixColumns (byteArray& state) const;
62
63 };
64
65 #endif /* AES_HPP */
66
67 /* vim: set ts=4 sts=4 sw=4 noet tw=112: */