• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/MyBuffer2.h"
9 #include "../../Common/MyCom.h"
10 
11 #include "../ICoder.h"
12 
13 namespace NCrypto {
14 
15 class CAesCoder:
16   public ICompressFilter,
17   public ICryptoProperties,
18   #ifndef _SFX
19   public ICompressSetCoderProperties,
20   #endif
21   public CMyUnknownImp
22 {
23   AES_CODE_FUNC _codeFunc;
24   // unsigned _offset;
25   unsigned _keySize;
26   bool _keyIsSet;
27   bool _encodeMode;
28   bool _ctrMode;
29 
30   // UInt32 _aes[AES_NUM_IVMRK_WORDS + 3];
31   CAlignedBuffer _aes;
32 
33   Byte _iv[AES_BLOCK_SIZE];
34 
35   // UInt32 *Aes() { return _aes + _offset; }
Aes()36   UInt32 *Aes() { return (UInt32 *)(void *)(Byte *)_aes; }
37 
38   bool SetFunctions(UInt32 algo);
39 
40 public:
41   CAesCoder(bool encodeMode, unsigned keySize, bool ctrMode);
42 
~CAesCoder()43   virtual ~CAesCoder() {};   // we need virtual destructor for derived classes
44 
45   MY_QUERYINTERFACE_BEGIN2(ICompressFilter)
MY_QUERYINTERFACE_ENTRY(ICryptoProperties)46   MY_QUERYINTERFACE_ENTRY(ICryptoProperties)
47   #ifndef _SFX
48   MY_QUERYINTERFACE_ENTRY(ICompressSetCoderProperties)
49   #endif
50   MY_QUERYINTERFACE_END
51   MY_ADDREF_RELEASE
52 
53   INTERFACE_ICompressFilter(;)
54 
55   void SetKeySize(unsigned size) { _keySize = size; }
56 
57   STDMETHOD(SetKey)(const Byte *data, UInt32 size);
58   STDMETHOD(SetInitVector)(const Byte *data, UInt32 size);
59 
60   #ifndef _SFX
61   STDMETHOD(SetCoderProperties)(const PROPID *propIDs, const PROPVARIANT *props, UInt32 numProps);
62   #endif
63 };
64 
65 #ifndef _SFX
66 struct CAesCbcEncoder: public CAesCoder
67 {
CAesCoderCAesCbcEncoder68   CAesCbcEncoder(unsigned keySize = 0): CAesCoder(true, keySize, false) {}
69 };
70 #endif
71 
72 struct CAesCbcDecoder: public CAesCoder
73 {
CAesCoderCAesCbcDecoder74   CAesCbcDecoder(unsigned keySize = 0): CAesCoder(false, keySize, false) {}
75 };
76 
77 }
78 
79 #endif
80