Coverage Report

Created: 2024-05-20 06:31

/src/clamav/libclamunrar/crypt1.cpp
Line
Count
Source (jump to first uncovered line)
1
extern uint CRCTab[256];
2
3
void CryptData::SetKey13(const char *Password)
4
0
{
5
0
  Key13[0]=Key13[1]=Key13[2]=0;
6
0
  for (size_t I=0;Password[I]!=0;I++)
7
0
  {
8
0
    byte P=Password[I];
9
0
    Key13[0]+=P;
10
0
    Key13[1]^=P;
11
0
    Key13[2]+=P;
12
0
    Key13[2]=(byte)rotls(Key13[2],1,8);
13
0
  }
14
0
}
15
16
17
void CryptData::SetKey15(const char *Password)
18
0
{
19
0
  InitCRC32(CRCTab);
20
0
  uint PswCRC=CRC32(0xffffffff,Password,strlen(Password));
21
0
  Key15[0]=PswCRC&0xffff;
22
0
  Key15[1]=(PswCRC>>16)&0xffff;
23
0
  Key15[2]=Key15[3]=0;
24
0
  for (size_t I=0;Password[I]!=0;I++)
25
0
  {
26
0
    byte P=Password[I];
27
0
    Key15[2]^=P^CRCTab[P];
28
0
    Key15[3]+=P+(CRCTab[P]>>16);
29
0
  }
30
0
}
31
32
33
void CryptData::SetAV15Encryption()
34
0
{
35
0
  InitCRC32(CRCTab);
36
0
  Method=CRYPT_RAR15;
37
0
  Key15[0]=0x4765;
38
0
  Key15[1]=0x9021;
39
0
  Key15[2]=0x7382;
40
0
  Key15[3]=0x5215;
41
0
}
42
43
44
void CryptData::SetCmt13Encryption()
45
6.27k
{
46
6.27k
  Method=CRYPT_RAR13;
47
6.27k
  Key13[0]=0;
48
6.27k
  Key13[1]=7;
49
6.27k
  Key13[2]=77;
50
6.27k
}
51
52
53
void CryptData::Decrypt13(byte *Data,size_t Count)
54
103k
{
55
24.2M
  while (Count--)
56
24.1M
  {
57
24.1M
    Key13[1]+=Key13[2];
58
24.1M
    Key13[0]+=Key13[1];
59
24.1M
    *Data-=Key13[0];
60
24.1M
    Data++;
61
24.1M
  }
62
103k
}
63
64
65
void CryptData::Crypt15(byte *Data,size_t Count)
66
0
{
67
0
  while (Count--)
68
0
  {
69
0
    Key15[0]+=0x1234;
70
0
    Key15[1]^=CRCTab[(Key15[0] & 0x1fe)>>1];
71
0
    Key15[2]-=CRCTab[(Key15[0] & 0x1fe)>>1]>>16;
72
0
    Key15[0]^=Key15[2];
73
0
    Key15[3]=rotrs(Key15[3]&0xffff,1,16)^Key15[1];
74
0
    Key15[3]=rotrs(Key15[3]&0xffff,1,16);
75
0
    Key15[0]^=Key15[3];
76
0
    *Data^=(byte)(Key15[0]>>8);
77
0
    Data++;
78
0
  }
79
0
}