~ubuntu-branches/ubuntu/lucid/unrar-nonfree/lucid

« back to all changes in this revision

Viewing changes to crypt.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Martin Meredith
  • Date: 2009-06-06 17:46:05 UTC
  • mfrom: (1.1.11 upstream) (5.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20090606174605-h4ciqxlpy39jmjx0
Tags: 1:3.9.3-1
* New upstream release
* Updated Copyright file (Closes: #531432)

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
 
42
42
 
43
43
 
44
 
void CryptData::DecryptBlock(byte *Buf,int Size)
 
44
void CryptData::DecryptBlock(byte *Buf,size_t Size)
45
45
{
46
46
  rin.blockDecrypt(Buf,Size,Buf);
47
47
}
185
185
#endif
186
186
 
187
187
 
188
 
void CryptData::SetCryptKeys(char *Password,byte *Salt,bool Encrypt,bool OldOnly,bool HandsOffHash)
 
188
void CryptData::SetCryptKeys(const char *Password,const byte *Salt,bool Encrypt,bool OldOnly,bool HandsOffHash)
189
189
{
190
190
  if (*Password==0)
191
191
    return;
202
202
    Key[3]=0xA4E7F123L;
203
203
    memset(Psw,0,sizeof(Psw));
204
204
#if defined(_WIN_32) && !defined(GUI)
205
 
    CharToOemBuff(Password,(char*)Psw,strlen(Password));
 
205
    CharToOemBuff(Password,(char*)Psw,(DWORD)strlen(Password));
206
206
#else
207
207
    strncpyz((char *)Psw,Password,ASIZE(Psw));
208
208
#endif
209
 
    int PswLength=strlen(Password);
 
209
    size_t PswLength=strlen(Password);
210
210
    memcpy(SubstTable,InitSubstTable,sizeof(SubstTable));
211
211
    for (int J=0;J<256;J++)
212
 
      for (int I=0;I<PswLength;I+=2)
 
212
      for (size_t I=0;I<PswLength;I+=2)
213
213
      {
214
214
        uint N1=(byte)CRCTab[(Psw[I]-J)&0xff];
215
215
        uint N2=(byte)CRCTab[(Psw[I+1]+J)&0xff];
216
216
        for (int K=1;N1!=N2;N1=(N1+1)&0xff,K++)
217
217
          Swap(&SubstTable[N1],&SubstTable[(N1+I+K)&0xff]);
218
218
      }
219
 
    for (int I=0;I<PswLength;I+=16)
 
219
    for (size_t I=0;I<PswLength;I+=16)
220
220
      EncryptBlock20(&Psw[I]);
221
221
#endif
222
222
    return;
223
223
  }
224
224
 
225
225
  bool Cached=false;
226
 
  for (int I=0;I<sizeof(Cache)/sizeof(Cache[0]);I++)
 
226
  for (int I=0;I<ASIZE(Cache);I++)
227
227
    if (strcmp(Cache[I].Password,Password)==0 &&
228
228
        (Salt==NULL && !Cache[I].SaltPresent || Salt!=NULL &&
229
229
        Cache[I].SaltPresent && memcmp(Cache[I].Salt,Salt,SALT_SIZE)==0) &&
242
242
    PswW[MAXPASSWORD-1]=0;
243
243
    byte RawPsw[2*MAXPASSWORD+SALT_SIZE];
244
244
    WideToRaw(PswW,RawPsw);
245
 
    int RawLength=2*strlenw(PswW);
 
245
    size_t RawLength=2*strlenw(PswW);
246
246
    if (Salt!=NULL)
247
247
    {
248
248
      memcpy(RawPsw+RawLength,Salt,SALT_SIZE);
287
287
 
288
288
 
289
289
#ifndef SFX_MODULE
290
 
void CryptData::SetOldKeys(char *Password)
 
290
void CryptData::SetOldKeys(const char *Password)
291
291
{
292
292
  uint PswCRC=CRC(0xffffffff,Password,strlen(Password));
293
293
  OldKey[0]=PswCRC&0xffff;