Home | History | Annotate | Download | only in Crypto
      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 public:
     30   CAesCbcCoder(bool encodeMode, unsigned keySize);
     31   MY_UNKNOWN_IMP2(ICryptoProperties, ICompressSetCoderProperties)
     32   STDMETHOD(Init)();
     33   STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);
     34   STDMETHOD(SetKey)(const Byte *data, UInt32 size);
     35   STDMETHOD(SetInitVector)(const Byte *data, UInt32 size);
     36   STDMETHOD(SetCoderProperties)(const PROPID *propIDs, const PROPVARIANT *props, UInt32 numProps);
     37 };
     38 
     39 struct CAesCbcEncoder: public CAesCbcCoder
     40 {
     41   CAesCbcEncoder(unsigned keySize = 0): CAesCbcCoder(true, keySize) {}
     42 };
     43 
     44 struct CAesCbcDecoder: public CAesCbcCoder
     45 {
     46   CAesCbcDecoder(unsigned keySize = 0): CAesCbcCoder(false, keySize) {}
     47 };
     48 
     49 
     50 }
     51 
     52 #endif
     53