Fork of François Berder Crypto, fixed AES CBC and small rework
Dependents: AES_example shaun_larada Smartage
Fork of Crypto by
cipher/AES.h@15:6093fc19aad6, 2015-01-28 (annotated)
- Committer:
- Geremia
- Date:
- Wed Jan 28 17:15:32 2015 +0000
- Revision:
- 15:6093fc19aad6
- Parent:
- 8:a090264e9b2d
AES: bugfixed CBC, added PCBC, added public setIV(iv), moved keyExpansion() to public
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
feb11 | 0:7a1237bd2d13 | 1 | #ifndef AES_H |
feb11 | 0:7a1237bd2d13 | 2 | #define AES_H |
feb11 | 0:7a1237bd2d13 | 3 | |
feb11 | 8:a090264e9b2d | 4 | #include "BlockCipher.h" |
feb11 | 0:7a1237bd2d13 | 5 | |
feb11 | 0:7a1237bd2d13 | 6 | enum AES_TYPE |
feb11 | 0:7a1237bd2d13 | 7 | { |
feb11 | 0:7a1237bd2d13 | 8 | AES_128 = 4, |
feb11 | 0:7a1237bd2d13 | 9 | AES_192 = 6, |
feb11 | 0:7a1237bd2d13 | 10 | AES_256 = 8 |
feb11 | 0:7a1237bd2d13 | 11 | }; |
feb11 | 0:7a1237bd2d13 | 12 | |
feb11 | 8:a090264e9b2d | 13 | class AES : public BlockCipher |
feb11 | 0:7a1237bd2d13 | 14 | { |
feb11 | 0:7a1237bd2d13 | 15 | public : |
feb11 | 0:7a1237bd2d13 | 16 | |
feb11 | 0:7a1237bd2d13 | 17 | AES(const AES_TYPE type, uint8_t *key); |
Geremia | 15:6093fc19aad6 | 18 | AES(const AES_TYPE type, uint8_t *key, uint8_t *iv, BLOCK_CIPHER_MODE m=CBC_MODE); |
Geremia | 15:6093fc19aad6 | 19 | void keyExpansion(uint8_t *key); |
Geremia | 15:6093fc19aad6 | 20 | |
feb11 | 0:7a1237bd2d13 | 21 | private : |
feb11 | 0:7a1237bd2d13 | 22 | |
feb11 | 8:a090264e9b2d | 23 | virtual void encryptBlock(uint8_t *out, uint8_t *in); |
feb11 | 8:a090264e9b2d | 24 | virtual void decryptBlock(uint8_t *out, uint8_t *in); |
feb11 | 0:7a1237bd2d13 | 25 | |
feb11 | 0:7a1237bd2d13 | 26 | uint32_t rotWord(uint32_t w); |
feb11 | 0:7a1237bd2d13 | 27 | uint32_t invRotWord(uint32_t w); |
feb11 | 0:7a1237bd2d13 | 28 | uint32_t subWord(uint32_t w); |
feb11 | 0:7a1237bd2d13 | 29 | void subBytes(); |
feb11 | 0:7a1237bd2d13 | 30 | void invSubBytes(); |
feb11 | 0:7a1237bd2d13 | 31 | void shiftRows(); |
feb11 | 0:7a1237bd2d13 | 32 | void invShiftRows(); |
feb11 | 0:7a1237bd2d13 | 33 | void mul(uint8_t *r); |
feb11 | 0:7a1237bd2d13 | 34 | void invMul(uint8_t *r); |
feb11 | 0:7a1237bd2d13 | 35 | void mixColumns(); |
feb11 | 0:7a1237bd2d13 | 36 | void invMixColumns(); |
feb11 | 0:7a1237bd2d13 | 37 | void addRoundKey(int round); |
feb11 | 0:7a1237bd2d13 | 38 | |
feb11 | 0:7a1237bd2d13 | 39 | uint8_t state[16]; |
feb11 | 0:7a1237bd2d13 | 40 | uint32_t w[60]; |
feb11 | 0:7a1237bd2d13 | 41 | uint8_t nr,nk; |
feb11 | 0:7a1237bd2d13 | 42 | }; |
feb11 | 0:7a1237bd2d13 | 43 | |
feb11 | 0:7a1237bd2d13 | 44 | #endif |