xref: /aosp_15_r20/external/lzma/CPP/7zip/Crypto/ZipCrypto.h (revision f6dc9357d832569d4d1f5d24eacdb3935a1ae8e6)
1 // Crypto/ZipCrypto.h
2 
3 #ifndef ZIP7_INC_CRYPTO_ZIP_CRYPTO_H
4 #define ZIP7_INC_CRYPTO_ZIP_CRYPTO_H
5 
6 #include "../../Common/MyCom.h"
7 
8 #include "../ICoder.h"
9 #include "../IPassword.h"
10 
11 namespace NCrypto {
12 namespace NZip {
13 
14 const unsigned kHeaderSize = 12;
15 
16 /* ICompressFilter::Init() does nothing for this filter.
17   Call to init:
18     Encoder:
19       CryptoSetPassword();
20       WriteHeader();
21     Decoder:
22       [CryptoSetPassword();]
23       ReadHeader();
24       [CryptoSetPassword();] Init_and_GetCrcByte();
25       [CryptoSetPassword();] Init_and_GetCrcByte();
26 */
27 
28 class CCipher:
29   public ICompressFilter,
30   public ICryptoSetPassword,
31   public CMyUnknownImp
32 {
33   Z7_COM_UNKNOWN_IMP_1(ICryptoSetPassword)
34   Z7_COM7F_IMP(Init())
35 public:
36   Z7_IFACE_COM7_IMP(ICryptoSetPassword)
37 protected:
38   UInt32 Key0;
39   UInt32 Key1;
40   UInt32 Key2;
41 
42   UInt32 KeyMem0;
43   UInt32 KeyMem1;
44   UInt32 KeyMem2;
45 
RestoreKeys()46   void RestoreKeys()
47   {
48     Key0 = KeyMem0;
49     Key1 = KeyMem1;
50     Key2 = KeyMem2;
51   }
52 
53 public:
~CCipher()54   virtual ~CCipher()
55   {
56     Key0 = KeyMem0 =
57     Key1 = KeyMem1 =
58     Key2 = KeyMem2 = 0;
59   }
60 };
61 
62 class CEncoder Z7_final: public CCipher
63 {
64   Z7_COM7F_IMP2(UInt32, Filter(Byte *data, UInt32 size))
65 public:
66   HRESULT WriteHeader_Check16(ISequentialOutStream *outStream, UInt16 crc);
67 };
68 
69 class CDecoder Z7_final: public CCipher
70 {
71   Z7_COM7F_IMP2(UInt32, Filter(Byte *data, UInt32 size))
72 public:
73   Byte _header[kHeaderSize];
74   HRESULT ReadHeader(ISequentialInStream *inStream);
75   void Init_BeforeDecode();
76 };
77 
78 }}
79 
80 #endif
81