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@8:a090264e9b2d, 2013-09-14 (annotated)
- Committer:
- feb11
- Date:
- Sat Sep 14 20:54:59 2013 +0000
- Revision:
- 8:a090264e9b2d
refactored public API for ciphers & added TDES
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 | } |