1 // Crypto/MyAes.h 2 3 #ifndef __CRYPTO_MY_AES_H 4 #define __CRYPTO_MY_AES_H 5 6 #include "../../../C/Aes.h" 7 8 #include "../../Common/MyCom.h" 9 10 #include "../ICoder.h" 11 12 namespace NCrypto { 13 14 class CAesCbcCoder: 15 public ICompressFilter, 16 public ICryptoProperties, 17 public ICompressSetCoderProperties, 18 public CMyUnknownImp 19 { 20 AES_CODE_FUNC _codeFunc; 21 unsigned _offset; 22 unsigned _keySize; 23 bool _keyIsSet; 24 bool _encodeMode; 25 UInt32 _aes[AES_NUM_IVMRK_WORDS + 3]; 26 Byte _iv[AES_BLOCK_SIZE]; 27 28 bool SetFunctions(UInt32 algo); 29 30 public: 31 CAesCbcCoder(bool encodeMode, unsigned keySize); 32 ~CAesCbcCoder()33 virtual ~CAesCbcCoder() {}; // we need virtual destructor for derived classes 34 35 MY_UNKNOWN_IMP3(ICompressFilter, ICryptoProperties, ICompressSetCoderProperties) 36 37 INTERFACE_ICompressFilter(;) 38 39 STDMETHOD(SetKey)(const Byte *data, UInt32 size); 40 STDMETHOD(SetInitVector)(const Byte *data, UInt32 size); 41 42 STDMETHOD(SetCoderProperties)(const PROPID *propIDs, const PROPVARIANT *props, UInt32 numProps); 43 }; 44 45 struct CAesCbcEncoder: public CAesCbcCoder 46 { CAesCbcCoderCAesCbcEncoder47 CAesCbcEncoder(unsigned keySize = 0): CAesCbcCoder(true, keySize) {} 48 }; 49 50 struct CAesCbcDecoder: public CAesCbcCoder 51 { CAesCbcCoderCAesCbcDecoder52 CAesCbcDecoder(unsigned keySize = 0): CAesCbcCoder(false, keySize) {} 53 }; 54 55 } 56 57 #endif 58