Fork of François Berder Crypto, fixed AES CBC and small rework

Dependents:   AES_example shaun_larada Smartage

Fork of Crypto by Francois Berder

Committer:
Geremia
Date:
Wed Jan 28 17:55:13 2015 +0000
Revision:
16:4399e2e6260b
Parent:
15:6093fc19aad6
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?

UserRevisionLine numberNew contents of line
feb11 8:a090264e9b2d 1 #ifndef BLOCK_CIPHER_H
feb11 8:a090264e9b2d 2 #define BLOCK_CIPHER_H
feb11 8:a090264e9b2d 3
feb11 8:a090264e9b2d 4 #include "Cipher.h"
feb11 8:a090264e9b2d 5
feb11 8:a090264e9b2d 6 enum BLOCK_CIPHER_MODE
feb11 8:a090264e9b2d 7 {
feb11 8:a090264e9b2d 8 ECB_MODE,
Geremia 15:6093fc19aad6 9 CBC_MODE,
Geremia 15:6093fc19aad6 10 PCBC_MODE
feb11 8:a090264e9b2d 11 };
feb11 8:a090264e9b2d 12
feb11 8:a090264e9b2d 13 class BlockCipher : public Cipher
feb11 8:a090264e9b2d 14 {
feb11 8:a090264e9b2d 15 public :
feb11 8:a090264e9b2d 16
feb11 8:a090264e9b2d 17 BlockCipher(uint32_t bs, BLOCK_CIPHER_MODE m, uint8_t *iv = 0);
feb11 8:a090264e9b2d 18 virtual ~BlockCipher();
feb11 8:a090264e9b2d 19
feb11 8:a090264e9b2d 20 virtual CIPHER_TYPE getType() const;
feb11 8:a090264e9b2d 21 uint32_t getBlockSize() const;
Geremia 15:6093fc19aad6 22 void setIV(uint8_t *iv);
feb11 8:a090264e9b2d 23
feb11 8:a090264e9b2d 24 virtual void encrypt(uint8_t *out, uint8_t *in, uint32_t length);
feb11 8:a090264e9b2d 25 virtual void decrypt(uint8_t *out, uint8_t *in, uint32_t length);
feb11 8:a090264e9b2d 26
feb11 8:a090264e9b2d 27 protected :
feb11 8:a090264e9b2d 28
feb11 8:a090264e9b2d 29 virtual void encryptBlock(uint8_t *out, uint8_t *in) = 0;
feb11 8:a090264e9b2d 30 virtual void decryptBlock(uint8_t *out, uint8_t *in) = 0;
feb11 8:a090264e9b2d 31
feb11 8:a090264e9b2d 32 private :
feb11 8:a090264e9b2d 33
feb11 8:a090264e9b2d 34 uint32_t blockSize;
feb11 8:a090264e9b2d 35 BLOCK_CIPHER_MODE mode;
feb11 8:a090264e9b2d 36 uint8_t *IV;
Geremia 15:6093fc19aad6 37 uint8_t *tmpIV;
Geremia 15:6093fc19aad6 38 uint8_t *tmpdatain;
Geremia 15:6093fc19aad6 39 uint8_t *tmpdata;
feb11 8:a090264e9b2d 40 };
feb11 8:a090264e9b2d 41
feb11 8:a090264e9b2d 42 #endif