Update comments in aes.hpp
[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                 static const unsigned int Nb = 4;
33
34                 /* Key size in words -- can be 4, 6, or 8. */
35                 const unsigned int Nk;
36
37                 /* Number of rounds -- depends on key size. */
38                 const unsigned int Nr;
39
40                 wordArray keySchedule;
41
42                 void KeyExpansion (const byteArray& key, wordArray& w) const;
43                 word SubWord (const word& input) const;
44                 word RotWord (const word& input) const;
45                 wordArray GetRoundKey (const int round) const;
46
47                 void SubBytes (byteArray& state) const;
48                 void ShiftRows (byteArray& state) const;
49                 void MixColumns (byteArray& state) const;
50                 void AddRoundKey (byteArray& state, const wordArray& w) const;
51
52                 void InvSubBytes (byteArray& state) const;
53                 void InvShiftRows (byteArray& state) const;
54                 void InvMixColumns (byteArray& state) const;
55
56 };
57
58 #endif /* AES_HPP */
59
60 /* vim: set ts=4 sts=4 sw=4 noet tw=112: */