~ubuntu-branches/ubuntu/wily/unrar-nonfree/wily-proposed

« back to all changes in this revision

Viewing changes to crc.cpp

  • Committer: Package Import Robot
  • Author(s): Nick Andrik
  • Date: 2013-01-21 23:07:40 UTC
  • mfrom: (1.2.13)
  • Revision ID: package-import@ubuntu.com-20130121230740-yky1izwyj5x16wq1
Tags: 1:4.2.4-0.1
* Non-maintainer upload

* New upstream release (Closes: #687839)

* Add shared library binary and headers packages
  - Add entries into control file
  - Add libunrar0.{install,link,symbols} files
  - Add libunrar0-dev.install file
  - Patch missing binary object targets for library building
    (fix_missing_symbols)
  - Rename previous unrar-nonfree.{1,dirs,install,prerm,postint} file to
    unrar.* ones
  - Make sure libunrar.so is built (Closes: #485492, LP: #390263)
* Converted package to CDBS:
  - Simplified rules file
  - Added cdbs build-deps
* Added hardening support (Closes: #694611)
  - Updated compatibility version to 9
  - Added versioned dpkg-dev build-dep
* Updated copyright information:
  - Machine-readable format
  - Added missing files/licenses
* General maintentance:
  - Moved the homepage field in cortol file to the appropriate place
  - Bumped standards version to 3.9.4
  - Remove versioned conflict dependency

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// This CRC function is based on Intel Slicing-by-8 algorithm.
 
2
//
 
3
// Original Intel Slicing-by-8 code is available here:
 
4
//
 
5
//    http://sourceforge.net/projects/slicing-by-8/
 
6
//
 
7
// Original Intel Slicing-by-8 code is licensed as:
 
8
//    
 
9
//    Copyright (c) 2004-2006 Intel Corporation - All Rights Reserved
 
10
//    
 
11
//    This software program is licensed subject to the BSD License, 
 
12
//    available at http://www.opensource.org/licenses/bsd-license.html
 
13
 
 
14
 
1
15
#include "rar.hpp"
2
16
 
 
17
// CRCTab duplicates crc_tables[0], but we still need it to decrypt
 
18
// old version RAR archives. GUI code might use it for ZIP encryption.
3
19
uint CRCTab[256];
4
20
 
 
21
static uint crc_tables[8][256]; // Tables for Slicing-by-8.
 
22
 
5
23
void InitCRC()
6
24
{
7
 
  for (int I=0;I<256;I++)
 
25
  for (uint I=0;I<256;I++) // Build the classic CRC32 lookup table.
8
26
  {
9
27
    uint C=I;
10
 
    for (int J=0;J<8;J++)
 
28
    for (uint J=0;J<8;J++)
11
29
      C=(C & 1) ? (C>>1)^0xEDB88320L : (C>>1);
12
 
    CRCTab[I]=C;
 
30
    CRCTab[I]=crc_tables[0][I]=C;
13
31
  }
 
32
 
 
33
        for (uint I=0;I<=256;I++) // Build additional lookup tables.
 
34
  {
 
35
                uint C=crc_tables[0][I];
 
36
                for (uint J=1;J<8;J++)
 
37
    {
 
38
                        C=crc_tables[0][(byte)C]^(C>>8);
 
39
                        crc_tables[J][I]=C;
 
40
                }
 
41
        }
14
42
}
15
43
 
16
44
 
20
48
    InitCRC();
21
49
  byte *Data=(byte *)Addr;
22
50
 
23
 
#if defined(LITTLE_ENDIAN) && defined(PRESENT_INT32) && defined(ALLOW_NOT_ALIGNED_INT)
24
 
  while (Size>0 && ((long)Data & 7))
25
 
  {
26
 
    StartCRC=CRCTab[(byte)(StartCRC^Data[0])]^(StartCRC>>8);
27
 
    Size--;
28
 
    Data++;
29
 
  }
30
 
  while (Size>=8)
31
 
  {
32
 
    StartCRC^=*(uint32 *)Data;
33
 
    StartCRC=CRCTab[(byte)StartCRC]^(StartCRC>>8);
34
 
    StartCRC=CRCTab[(byte)StartCRC]^(StartCRC>>8);
35
 
    StartCRC=CRCTab[(byte)StartCRC]^(StartCRC>>8);
36
 
    StartCRC=CRCTab[(byte)StartCRC]^(StartCRC>>8);
37
 
    StartCRC^=*(uint32 *)(Data+4);
38
 
    StartCRC=CRCTab[(byte)StartCRC]^(StartCRC>>8);
39
 
    StartCRC=CRCTab[(byte)StartCRC]^(StartCRC>>8);
40
 
    StartCRC=CRCTab[(byte)StartCRC]^(StartCRC>>8);
41
 
    StartCRC=CRCTab[(byte)StartCRC]^(StartCRC>>8);
42
 
    Data+=8;
43
 
    Size-=8;
44
 
  }
 
51
  // Align Data to 8 for better performance.
 
52
  for (;Size>0 && ((long)Data & 7);Size--,Data++)
 
53
    StartCRC=crc_tables[0][(byte)(StartCRC^Data[0])]^(StartCRC>>8);
 
54
 
 
55
  for (;Size>=8;Size-=8,Data+=8)
 
56
  {
 
57
#ifdef BIG_ENDIAN
 
58
                StartCRC ^= Data[0]|(Data[1] << 8)|(Data[2] << 16)|(Data[3] << 24);
 
59
#else
 
60
                StartCRC ^= *(uint32 *) Data;
45
61
#endif
46
 
 
47
 
  for (size_t I=0;I<Size;I++)
48
 
    StartCRC=CRCTab[(byte)(StartCRC^Data[I])]^(StartCRC>>8);
 
62
                StartCRC = crc_tables[7][(byte) StartCRC       ] ^
 
63
               crc_tables[6][(byte)(StartCRC >> 8) ] ^
 
64
               crc_tables[5][(byte)(StartCRC >> 16)] ^
 
65
               crc_tables[4][(byte)(StartCRC >> 24)] ^
 
66
               crc_tables[3][Data[4]] ^
 
67
               crc_tables[2][Data[5]] ^
 
68
               crc_tables[1][Data[6]] ^
 
69
               crc_tables[0][Data[7]];
 
70
        }
 
71
 
 
72
  for (;Size>0;Size--,Data++) // Process left data.
 
73
    StartCRC=crc_tables[0][(byte)(StartCRC^Data[0])]^(StartCRC>>8);
 
74
 
49
75
  return(StartCRC);
50
76
}
51
77
 
 
78
 
52
79
#ifndef SFX_MODULE
 
80
// For RAR 1.4 archives in case somebody still has them.
53
81
ushort OldCRC(ushort StartCRC,const void *Addr,size_t Size)
54
82
{
55
83
  byte *Data=(byte *)Addr;