Fork of François Berder Crypto, fixed AES CBC and small rework
Dependents: AES_example shaun_larada Smartage
Fork of Crypto by
cipher/TDES.cpp@16:4399e2e6260b, 2015-01-28 (annotated)
- Committer:
- Geremia
- Date:
- Wed Jan 28 17:55:13 2015 +0000
- Revision:
- 16:4399e2e6260b
- Parent:
- 8:a090264e9b2d
AES: bugfixed CBC, added PCBC (i could add CFB and OFB if needed), added public setIV(), moved keyExpansion() to public, in and out buffers can be the same
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
feb11 | 8:a090264e9b2d | 1 | #include "TDES.h" |
feb11 | 8:a090264e9b2d | 2 | |
feb11 | 8:a090264e9b2d | 3 | TDES::TDES(uint8_t *key1, uint8_t *key2, uint8_t *key3): |
feb11 | 8:a090264e9b2d | 4 | BlockCipher(8,ECB_MODE), |
feb11 | 8:a090264e9b2d | 5 | a(key1), |
feb11 | 8:a090264e9b2d | 6 | b(key2), |
feb11 | 8:a090264e9b2d | 7 | c(key3) |
feb11 | 8:a090264e9b2d | 8 | { |
feb11 | 8:a090264e9b2d | 9 | |
feb11 | 8:a090264e9b2d | 10 | } |
feb11 | 8:a090264e9b2d | 11 | |
feb11 | 8:a090264e9b2d | 12 | TDES::TDES(uint8_t *key1, uint8_t *key2, uint8_t *key3, uint8_t *iv): |
feb11 | 8:a090264e9b2d | 13 | BlockCipher(8,CBC_MODE,iv), |
feb11 | 8:a090264e9b2d | 14 | a(key1), |
feb11 | 8:a090264e9b2d | 15 | b(key2), |
feb11 | 8:a090264e9b2d | 16 | c(key3) |
feb11 | 8:a090264e9b2d | 17 | { |
feb11 | 8:a090264e9b2d | 18 | |
feb11 | 8:a090264e9b2d | 19 | } |
feb11 | 8:a090264e9b2d | 20 | |
feb11 | 8:a090264e9b2d | 21 | void TDES::encryptBlock(uint8_t *out, uint8_t *in) |
feb11 | 8:a090264e9b2d | 22 | { |
feb11 | 8:a090264e9b2d | 23 | uint8_t tmp[8], tmp2[8]; |
feb11 | 8:a090264e9b2d | 24 | a.encryptBlock(tmp,in); |
feb11 | 8:a090264e9b2d | 25 | b.decryptBlock(tmp2,tmp); |
feb11 | 8:a090264e9b2d | 26 | c.encryptBlock(out, tmp2); |
feb11 | 8:a090264e9b2d | 27 | } |
feb11 | 8:a090264e9b2d | 28 | |
feb11 | 8:a090264e9b2d | 29 | void TDES::decryptBlock(uint8_t *out, uint8_t *in) |
feb11 | 8:a090264e9b2d | 30 | { |
feb11 | 8:a090264e9b2d | 31 | uint8_t tmp[8], tmp2[8]; |
feb11 | 8:a090264e9b2d | 32 | c.decryptBlock(tmp, in); |
feb11 | 8:a090264e9b2d | 33 | b.encryptBlock(tmp2, tmp); |
feb11 | 8:a090264e9b2d | 34 | a.decryptBlock(out, tmp2); |
feb11 | 8:a090264e9b2d | 35 | } |