crypt.hpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #ifndef _RAR_CRYPT_
  2. #define _RAR_CRYPT_
  3. enum { OLD_DECODE=0,OLD_ENCODE=1,NEW_CRYPT=2 };
  4. struct CryptKeyCacheItem
  5. {
  6. #ifndef _SFX_RTL_
  7. CryptKeyCacheItem()
  8. {
  9. *Password=0;
  10. }
  11. ~CryptKeyCacheItem()
  12. {
  13. memset(AESKey,0,sizeof(AESKey));
  14. memset(AESInit,0,sizeof(AESInit));
  15. memset(Password,0,sizeof(Password));
  16. }
  17. #endif
  18. byte AESKey[16],AESInit[16];
  19. wchar Password[MAXPASSWORD];
  20. bool SaltPresent;
  21. byte Salt[SALT_SIZE];
  22. bool HandsOffHash;
  23. };
  24. class CryptData
  25. {
  26. private:
  27. void Encode13(byte *Data,uint Count);
  28. void Decode13(byte *Data,uint Count);
  29. void Crypt15(byte *Data,uint Count);
  30. void UpdKeys(byte *Buf);
  31. void Swap(byte *Ch1,byte *Ch2);
  32. void SetOldKeys(const char *Password);
  33. Rijndael rin;
  34. byte SubstTable[256];
  35. uint Key[4];
  36. ushort OldKey[4];
  37. byte PN1,PN2,PN3;
  38. byte AESKey[16],AESInit[16];
  39. static CryptKeyCacheItem Cache[4];
  40. static int CachePos;
  41. public:
  42. void SetCryptKeys(const wchar *Password,const byte *Salt,bool Encrypt,bool OldOnly,bool HandsOffHash);
  43. void SetAV15Encryption();
  44. void SetCmt13Encryption();
  45. void EncryptBlock20(byte *Buf);
  46. void DecryptBlock20(byte *Buf);
  47. void EncryptBlock(byte *Buf,size_t Size);
  48. void DecryptBlock(byte *Buf,size_t Size);
  49. void Crypt(byte *Data,uint Count,int Method);
  50. static void SetSalt(byte *Salt,int SaltSize);
  51. };
  52. #endif