1 // Crypto/ZipStrong.h 2 3 #ifndef ZIP7_INC_CRYPTO_ZIP_STRONG_H 4 #define ZIP7_INC_CRYPTO_ZIP_STRONG_H 5 6 #include "../../Common/MyBuffer2.h" 7 8 #include "../IPassword.h" 9 10 #include "MyAes.h" 11 12 namespace NCrypto { 13 namespace NZipStrong { 14 15 /* ICompressFilter::Init() does nothing for this filter. 16 Call to init: 17 Decoder: 18 [CryptoSetPassword();] 19 ReadHeader(); 20 [CryptoSetPassword();] Init_and_CheckPassword(); 21 [CryptoSetPassword();] Init_and_CheckPassword(); 22 */ 23 24 struct CKeyInfo 25 { 26 Byte MasterKey[32]; 27 UInt32 KeySize; 28 29 void SetPassword(const Byte *data, UInt32 size); 30 WipeCKeyInfo31 void Wipe() 32 { 33 Z7_memset_0_ARRAY(MasterKey); 34 } 35 }; 36 37 38 const unsigned kAesPadAllign = AES_BLOCK_SIZE; 39 40 Z7_CLASS_IMP_COM_2( 41 CDecoder 42 , ICompressFilter 43 , ICryptoSetPassword 44 ) 45 CAesCbcDecoder *_cbcDecoder; 46 CMyComPtr<ICompressFilter> _aesFilter; 47 CKeyInfo _key; 48 CAlignedBuffer _bufAligned; 49 50 UInt32 _ivSize; 51 Byte _iv[16]; 52 UInt32 _remSize; 53 public: 54 HRESULT ReadHeader(ISequentialInStream *inStream, UInt32 crc, UInt64 unpackSize); 55 HRESULT Init_and_CheckPassword(bool &passwOK); GetPadSize(UInt32 packSize32)56 UInt32 GetPadSize(UInt32 packSize32) const 57 { 58 // Padding is to align to blockSize of cipher. 59 // Change it, if is not AES 60 return kAesPadAllign - (packSize32 & (kAesPadAllign - 1)); 61 } 62 CDecoder(); ~CDecoder()63 ~CDecoder() { Wipe(); } Wipe()64 void Wipe() 65 { 66 Z7_memset_0_ARRAY(_iv); 67 _key.Wipe(); 68 } 69 }; 70 71 }} 72 73 #endif 74