diff options
Diffstat (limited to 'CPP/7zip/Crypto/ZipCrypto.h')
-rw-r--r-- | CPP/7zip/Crypto/ZipCrypto.h | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/CPP/7zip/Crypto/ZipCrypto.h b/CPP/7zip/Crypto/ZipCrypto.h new file mode 100644 index 0000000..d2fe4c4 --- /dev/null +++ b/CPP/7zip/Crypto/ZipCrypto.h | |||
@@ -0,0 +1,80 @@ | |||
1 | // Crypto/ZipCrypto.h | ||
2 | |||
3 | #ifndef __CRYPTO_ZIP_CRYPTO_H | ||
4 | #define __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 | protected: | ||
34 | UInt32 Key0; | ||
35 | UInt32 Key1; | ||
36 | UInt32 Key2; | ||
37 | |||
38 | UInt32 KeyMem0; | ||
39 | UInt32 KeyMem1; | ||
40 | UInt32 KeyMem2; | ||
41 | |||
42 | void RestoreKeys() | ||
43 | { | ||
44 | Key0 = KeyMem0; | ||
45 | Key1 = KeyMem1; | ||
46 | Key2 = KeyMem2; | ||
47 | } | ||
48 | |||
49 | public: | ||
50 | MY_UNKNOWN_IMP1(ICryptoSetPassword) | ||
51 | STDMETHOD(Init)(); | ||
52 | STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size); | ||
53 | |||
54 | virtual ~CCipher() | ||
55 | { | ||
56 | Key0 = KeyMem0 = | ||
57 | Key1 = KeyMem1 = | ||
58 | Key2 = KeyMem2 = 0; | ||
59 | } | ||
60 | }; | ||
61 | |||
62 | class CEncoder: public CCipher | ||
63 | { | ||
64 | public: | ||
65 | STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size); | ||
66 | HRESULT WriteHeader_Check16(ISequentialOutStream *outStream, UInt16 crc); | ||
67 | }; | ||
68 | |||
69 | class CDecoder: public CCipher | ||
70 | { | ||
71 | public: | ||
72 | Byte _header[kHeaderSize]; | ||
73 | STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size); | ||
74 | HRESULT ReadHeader(ISequentialInStream *inStream); | ||
75 | void Init_BeforeDecode(); | ||
76 | }; | ||
77 | |||
78 | }} | ||
79 | |||
80 | #endif | ||