This library implements some hash and cryptographic algorithms.
Dependents: ES_CW2_Starter_JIN EMBEDDED_CW2 EMBEDDED_CW2_Final Spinnybois ... more
Fork of Crypto by
cipher/AES.h@8:a090264e9b2d, 2013-09-14 (annotated)
- Committer:
- feb11
- Date:
- Sat Sep 14 20:54:59 2013 +0000
- Revision:
- 8:a090264e9b2d
- Parent:
- 7:2dbbdfb08123
refactored public API for ciphers & added TDES
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); |
feb11 | 8:a090264e9b2d | 18 | AES(const AES_TYPE type, uint8_t *key, uint8_t *iv); |
feb11 | 8:a090264e9b2d | 19 | |
feb11 | 0:7a1237bd2d13 | 20 | private : |
feb11 | 0:7a1237bd2d13 | 21 | |
feb11 | 8:a090264e9b2d | 22 | virtual void encryptBlock(uint8_t *out, uint8_t *in); |
feb11 | 8:a090264e9b2d | 23 | virtual void decryptBlock(uint8_t *out, uint8_t *in); |
feb11 | 0:7a1237bd2d13 | 24 | |
feb11 | 0:7a1237bd2d13 | 25 | void keyExpansion(uint8_t *key); |
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 |