unrarsrc  6.1.7
About: unrar extracts, views and tests the contents of archives created with the RAR archiver.
  Fossies Dox: unrarsrc-6.1.7.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

crypt.hpp
Go to the documentation of this file.
1#ifndef _RAR_CRYPT_
2#define _RAR_CRYPT_
3
4
7};
8
9#define SIZE_SALT50 16
10#define SIZE_SALT30 8
11#define SIZE_INITV 16
12#define SIZE_PSWCHECK 8
13#define SIZE_PSWCHECK_CSUM 4
14
15#define CRYPT_BLOCK_SIZE 16
16#define CRYPT_BLOCK_MASK (CRYPT_BLOCK_SIZE-1) // 0xf
17
18#define CRYPT5_KDF_LG2_COUNT 15 // LOG2 of PDKDF2 iteration count.
19#define CRYPT5_KDF_LG2_COUNT_MAX 24 // LOG2 of maximum accepted iteration count.
20#define CRYPT_VERSION 0 // Supported encryption version.
21
22
24{
26 {
29 byte Key[32];
30 uint Lg2Count; // Log2 of PBKDF2 repetition count.
33 };
34
36 {
39 byte Key[16];
40 byte Init[16];
42 };
43
44
45 private:
46 void SetKey13(const char *Password);
47 void Decrypt13(byte *Data,size_t Count);
48
49 void SetKey15(const char *Password);
50 void Crypt15(byte *Data,size_t Count);
51
52 void SetKey20(const char *Password);
53 void Swap20(byte *Ch1,byte *Ch2);
54 void UpdKeys20(byte *Buf);
55 void EncryptBlock20(byte *Buf);
56 void DecryptBlock20(byte *Buf);
57
58 void SetKey30(bool Encrypt,SecPassword *Password,const wchar *PwdW,const byte *Salt);
59 void SetKey50(bool Encrypt,SecPassword *Password,const wchar *PwdW,const byte *Salt,const byte *InitV,uint Lg2Cnt,byte *HashKey,byte *PswCheck);
60
63
66
68
70
71 uint CRCTab[256]; // For RAR 1.5 and RAR 2.0 encryption.
72
73 byte SubstTable20[256];
75
76 byte Key13[3];
78 public:
79 CryptData();
80 ~CryptData();
81 bool SetCryptKeys(bool Encrypt,CRYPT_METHOD Method,SecPassword *Password,
82 const byte *Salt,const byte *InitV,uint Lg2Cnt,
83 byte *HashKey,byte *PswCheck);
84 void SetAV15Encryption();
85 void SetCmt13Encryption();
86 void EncryptBlock(byte *Buf,size_t Size);
87 void DecryptBlock(byte *Buf,size_t Size);
88 static void SetSalt(byte *Salt,size_t SaltSize);
89};
90
91void GetRnd(byte *RndBuf,size_t BufSize);
92
93void hmac_sha256(const byte *Key,size_t KeyLength,const byte *Data,
94 size_t DataLength,byte *ResDigest);
95void pbkdf2(const byte *pass, size_t pass_len, const byte *salt,
96 size_t salt_len,byte *key, byte *Value1, byte *Value2,
97 uint rounds);
98
99void ConvertHashToMAC(HashValue *Value,byte *Key);
100
101#endif
void EncryptBlock20(byte *Buf)
Definition: crypt2.cpp:62
KDF3CacheItem KDF3Cache[4]
Definition: crypt.hpp:61
void SetKey13(const char *Password)
Definition: crypt1.cpp:3
CryptData()
Definition: crypt.cpp:11
void Decrypt13(byte *Data, size_t Count)
Definition: crypt1.cpp:53
void SetKey20(const char *Password)
Definition: crypt2.cpp:29
void Swap20(byte *Ch1, byte *Ch2)
Definition: crypt2.cpp:128
uint KDF3CachePos
Definition: crypt.hpp:62
byte Key13[3]
Definition: crypt.hpp:76
bool SetCryptKeys(bool Encrypt, CRYPT_METHOD Method, SecPassword *Password, const byte *Salt, const byte *InitV, uint Lg2Cnt, byte *HashKey, byte *PswCheck)
Definition: crypt.cpp:55
static void SetSalt(byte *Salt, size_t SaltSize)
ushort Key15[4]
Definition: crypt.hpp:77
uint CRCTab[256]
Definition: crypt.hpp:71
uint KDF5CachePos
Definition: crypt.hpp:65
void SetKey30(bool Encrypt, SecPassword *Password, const wchar *PwdW, const byte *Salt)
Definition: crypt3.cpp:1
void SetCmt13Encryption()
Definition: crypt1.cpp:44
byte SubstTable20[256]
Definition: crypt.hpp:73
void EncryptBlock(byte *Buf, size_t Size)
~CryptData()
Definition: crypt.cpp:22
void UpdKeys20(byte *Buf)
Definition: crypt2.cpp:116
uint Key20[4]
Definition: crypt.hpp:74
CRYPT_METHOD Method
Definition: crypt.hpp:67
void SetAV15Encryption()
Definition: crypt1.cpp:33
void DecryptBlock20(byte *Buf)
Definition: crypt2.cpp:88
void SetKey50(bool Encrypt, SecPassword *Password, const wchar *PwdW, const byte *Salt, const byte *InitV, uint Lg2Cnt, byte *HashKey, byte *PswCheck)
Definition: crypt5.cpp:131
void DecryptBlock(byte *Buf, size_t Size)
Definition: crypt.cpp:31
KDF5CacheItem KDF5Cache[4]
Definition: crypt.hpp:64
Rijndael rin
Definition: crypt.hpp:69
void Crypt15(byte *Data, size_t Count)
Definition: crypt1.cpp:65
void SetKey15(const char *Password)
Definition: crypt1.cpp:17
void GetRnd(byte *RndBuf, size_t BufSize)
Definition: crypt.cpp:113
CRYPT_METHOD
Definition: crypt.hpp:5
@ CRYPT_RAR13
Definition: crypt.hpp:6
@ CRYPT_RAR20
Definition: crypt.hpp:6
@ CRYPT_RAR15
Definition: crypt.hpp:6
@ CRYPT_RAR50
Definition: crypt.hpp:6
@ CRYPT_NONE
Definition: crypt.hpp:6
@ CRYPT_RAR30
Definition: crypt.hpp:6
void ConvertHashToMAC(HashValue *Value, byte *Key)
Definition: crypt5.cpp:192
void hmac_sha256(const byte *Key, size_t KeyLength, const byte *Data, size_t DataLength, byte *ResDigest)
#define SIZE_SALT50
Definition: crypt.hpp:9
#define SIZE_SALT30
Definition: crypt.hpp:10
void pbkdf2(const byte *pass, size_t pass_len, const byte *salt, size_t salt_len, byte *key, byte *Value1, byte *Value2, uint rounds)
Definition: crypt5.cpp:85
wchar_t wchar
Definition: rartypes.hpp:13
unsigned int uint
Definition: rartypes.hpp:8
uint16_t ushort
Definition: rartypes.hpp:7
#define SHA256_DIGEST_SIZE
Definition: sha256.hpp:4
byte HashKeyValue[SHA256_DIGEST_SIZE]
Definition: crypt.hpp:32
byte PswCheckValue[SHA256_DIGEST_SIZE]
Definition: crypt.hpp:31