| 27 | |
| 28 | |
| 29 | void CryptData::SetKey20(const char *Password) |
| 30 | { |
| 31 | InitCRC32(CRCTab); |
| 32 | |
| 33 | char Psw[MAXPASSWORD]; |
| 34 | strncpyz(Psw,Password,ASIZE(Psw)); // We'll need to modify it below. |
| 35 | size_t PswLength=strlen(Psw); |
| 36 | |
| 37 | Key20[0]=0xD3A3B879L; |
| 38 | Key20[1]=0x3F6D12F7L; |
| 39 | Key20[2]=0x7515A235L; |
| 40 | Key20[3]=0xA4E7F123L; |
| 41 | |
| 42 | memcpy(SubstTable20,InitSubstTable20,sizeof(SubstTable20)); |
| 43 | for (uint J=0;J<256;J++) |
| 44 | for (size_t I=0;I<PswLength;I+=2) |
| 45 | { |
| 46 | uint N1=(byte)CRCTab [ (byte(Password[I]) - J) &0xff]; |
| 47 | uint N2=(byte)CRCTab [ (byte(Password[I+1]) + J) &0xff]; |
| 48 | for (int K=1;N1!=N2;N1=(N1+1)&0xff,K++) |
| 49 | Swap20(&SubstTable20[N1],&SubstTable20[(N1+I+K)&0xff]); |
| 50 | } |
| 51 | |
| 52 | // Incomplete last block of password must be zero padded. |
| 53 | if ((PswLength & CRYPT_BLOCK_MASK)!=0) |
| 54 | for (size_t I=PswLength;I<=(PswLength|CRYPT_BLOCK_MASK);I++) |
| 55 | Psw[I]=0; |
| 56 | |
| 57 | for (size_t I=0;I<PswLength;I+=CRYPT_BLOCK_SIZE) |
| 58 | EncryptBlock20((byte *)Psw+I); |
| 59 | } |
| 60 | |
| 61 | |
| 62 | void CryptData::EncryptBlock20(byte *Buf) |