Imported Upstream version 9.20
[platform/upstream/7zip.git] / CPP / 7zip / Crypto / Rar20Crypto.h
1 // Crypto/Rar20Crypto.h\r
2 \r
3 #ifndef __CRYPTO_RAR20_CRYPTO_H\r
4 #define __CRYPTO_RAR20_CRYPTO_H\r
5 \r
6 #include "Common/MyCom.h"\r
7 \r
8 #include "../ICoder.h"\r
9 #include "../IPassword.h"\r
10 \r
11 namespace NCrypto {\r
12 namespace NRar20 {\r
13 \r
14 class CData\r
15 {\r
16   Byte SubstTable[256];\r
17   UInt32 Keys[4];\r
18   \r
19   UInt32 SubstLong(UInt32 t)\r
20   {\r
21     return (UInt32)SubstTable[(int)t & 255] |\r
22            ((UInt32)SubstTable[(int)(t >> 8) & 255] << 8) |\r
23            ((UInt32)SubstTable[(int)(t >> 16) & 255] << 16) |\r
24            ((UInt32)SubstTable[(int)(t >> 24) & 255] << 24);\r
25   }\r
26   void UpdateKeys(const Byte *data);\r
27   void CryptBlock(Byte *buf, bool encrypt);\r
28 public:\r
29   void EncryptBlock(Byte *buf) { CryptBlock(buf, true); }\r
30   void DecryptBlock(Byte *buf) { CryptBlock(buf, false); }\r
31   void SetPassword(const Byte *password, UInt32 passwordLen);\r
32 };\r
33 \r
34 class CDecoder:\r
35   public ICompressFilter,\r
36   public ICryptoSetPassword,\r
37   public CMyUnknownImp\r
38 {\r
39   CData _cipher;\r
40 public:\r
41   MY_UNKNOWN_IMP1(ICryptoSetPassword)\r
42 \r
43   STDMETHOD(Init)();\r
44   STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);\r
45   STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size);\r
46 };\r
47 \r
48 }}\r
49 \r
50 #endif\r