xref: /aosp_15_r20/external/lzma/CPP/7zip/Crypto/Rar20Crypto.h (revision f6dc9357d832569d4d1f5d24eacdb3935a1ae8e6)
1 // Crypto/Rar20Crypto.h
2 
3 #ifndef ZIP7_INC_CRYPTO_RAR20_CRYPTO_H
4 #define ZIP7_INC_CRYPTO_RAR20_CRYPTO_H
5 
6 #include "../../Common/MyCom.h"
7 
8 #include "../ICoder.h"
9 
10 namespace NCrypto {
11 namespace NRar2 {
12 
13 /* ICompressFilter::Init() does nothing for this filter.
14    Call SetPassword() to initialize filter. */
15 
16 class CData
17 {
18   Byte SubstTable[256];
19   UInt32 Keys[4];
20 
SubstLong(UInt32 t)21   UInt32 SubstLong(UInt32 t) const
22   {
23     return (UInt32)SubstTable[(unsigned)t         & 255]
24         | ((UInt32)SubstTable[(unsigned)(t >>  8) & 255] << 8)
25         | ((UInt32)SubstTable[(unsigned)(t >> 16) & 255] << 16)
26         | ((UInt32)SubstTable[(unsigned)(t >> 24)      ] << 24);
27   }
28   void UpdateKeys(const Byte *data);
29   void CryptBlock(Byte *buf, bool encrypt);
30 public:
~CData()31   ~CData() { Wipe(); }
Wipe()32   void Wipe()
33   {
34     Z7_memset_0_ARRAY(SubstTable);
35     Z7_memset_0_ARRAY(Keys);
36   }
37 
EncryptBlock(Byte * buf)38   void EncryptBlock(Byte *buf) { CryptBlock(buf, true); }
DecryptBlock(Byte * buf)39   void DecryptBlock(Byte *buf) { CryptBlock(buf, false); }
40   void SetPassword(const Byte *password, unsigned passwordLen);
41 };
42 
43 class CDecoder Z7_final:
44   public ICompressFilter,
45   public CMyUnknownImp,
46   public CData
47 {
48   Z7_COM_UNKNOWN_IMP_0
49   Z7_IFACE_COM7_IMP(ICompressFilter)
50 };
51 
52 }}
53 
54 #endif
55