patch genisoimage multi extent
[platform/upstream/cdrkit.git] / genisoimage / rsync.c
1 /*
2  * This file has been modified for the cdrkit suite.
3  *
4  * The behaviour and appearence of the program code below can differ to a major
5  * extent from the version distributed by the original author(s).
6  *
7  * For details, see Changelog file distributed with the cdrkit package. If you
8  * received this file from another source then ask the distributing person for
9  * a log of modifications.
10  *
11  */
12
13 #include "genisoimage.h"
14 #include "utypes.h"
15 #include <ctype.h>
16 #include <mconfig.h>
17
18 /* Borrowed from jigdo; original notice:
19
20    These are purely random, no patterns or anything... (I hope)
21
22    I do not claim copyright for the actual numbers below, you may use them
23    for a re-implementation of the algorithm under a license of your choice.
24    -- Richard Atterer. */
25 static UInt32_t charTable[256] = {
26   0x51d65c0f, 0x083cd94b, 0x77f73dd8, 0xa0187d36,
27   0x29803d07, 0x7ea8ac0e, 0xea4c16c9, 0xfc576443,
28   0x6213df29, 0x1c012392, 0xb38946ae, 0x2e20ca31,
29   0xe4dc532f, 0xcb281c47, 0x8508b6a5, 0xb93c210d,
30   0xef02b5f3, 0x66548c74, 0x9ae2deab, 0x3b59f472,
31   0x4e546447, 0x45232d1f, 0x0ac0a4b1, 0x6c4c264b,
32   0x5d24ce84, 0x0f2752cc, 0xa35c7ac7, 0x3e31af51,
33   0x79675a59, 0x581f0e81, 0x49053122, 0x7339c9d8,
34   0xf9833565, 0xa3dbe5b3, 0xcc06eeb9, 0x92d0671c,
35   0x3eb220a7, 0x64864eae, 0xca100872, 0xc50977a1,
36   0xd90378e1, 0x7a36cab9, 0x15c15f4b, 0x8b9ef749,
37   0xcc1432dc, 0x1ec578ed, 0x27e6e092, 0xbb06db8f,
38   0x67f661ac, 0x8dd1a3db, 0x2a0ca16b, 0xb229ab84,
39   0x127a3337, 0x347d846f, 0xe1ea4b50, 0x008dbb91,
40   0x414c1426, 0xd2be76f0, 0x08789a39, 0xb4d93e30,
41   0x61667760, 0x8871bee9, 0xab7da12d, 0xe3c58620,
42   0xe9fdfbbe, 0x64fb04f7, 0x8cc5bbf0, 0xf5272d30,
43   0x8f161b50, 0x11122b05, 0x7695e72e, 0xa1c5d169,
44   0x1bfd0e20, 0xef7e6169, 0xf652d08e, 0xa9d0f139,
45   0x2f70aa04, 0xae2c7d6d, 0xa3cb9241, 0x3ae7d364,
46   0x348788f8, 0xf483b8f1, 0x55a011da, 0x189719dc,
47   0xb0c5d723, 0x8b344e33, 0x300d46eb, 0xd44fe34f,
48   0x1a2016c1, 0x66ce4cd7, 0xa45ea5e3, 0x55cb708a,
49   0xbce430df, 0xb01ae6e0, 0x3551163b, 0x2c5b157a,
50   0x574c4209, 0x430fd0e4, 0x3387e4a5, 0xee1d7451,
51   0xa9635623, 0x873ab89b, 0xb96bc6aa, 0x59898937,
52   0xe646c6e7, 0xb79f8792, 0x3f3235d8, 0xef1b5acf,
53   0xd975b22b, 0x427acce6, 0xe47a2411, 0x75f8c1e8,
54   0xa63f799d, 0x53886ad8, 0x9b2d6d32, 0xea822016,
55   0xcdee2254, 0xd98bcd98, 0x2933a544, 0x961f379f,
56   0x49219792, 0xc61c360f, 0x77cc0c64, 0x7b872046,
57   0xb91c7c12, 0x7577154b, 0x196573be, 0xf788813f,
58   0x41e2e56a, 0xec3cd244, 0x8c7401f1, 0xc2e805fe,
59   0xe8872fbe, 0x9e2faf7d, 0x6766456b, 0x888e2197,
60   0x28535c6d, 0x2ce45f3f, 0x24261d2a, 0xd6faab8b,
61   0x7a7b42b8, 0x15f0f6fa, 0xfe1711df, 0x7e5685a6,
62   0x00930268, 0x74755331, 0x1998912c, 0x7b60498b,
63   0x501a5786, 0x92ace0f6, 0x1d9752fe, 0x5a731add,
64   0x5b3b44fc, 0x473673f9, 0xa42c0321, 0xd82f9f18,
65   0xb4b225da, 0xfc89ece2, 0x072e1130, 0x5772aae3,
66   0x29010857, 0x542c970c, 0x94f67fe5, 0x71209e9b,
67   0xdb97ea39, 0x2689b41b, 0xae815804, 0xfc5e2651,
68   0xd4521674, 0x48ed979a, 0x2f617da3, 0xc350353d,
69   0xc3accd94, 0xbd8d313a, 0xc61a8e77, 0xf34940a4,
70   0x8d2c6b0f, 0x0f0e7225, 0x39e183db, 0xd19ebba9,
71   0x6a0f37b9, 0xd18922f3, 0x106420c5, 0xaa5a640b,
72   0x7cf0d273, 0xcf3238a7, 0x3b33204f, 0x476be7bb,
73   0x09d23bca, 0xbe84b2f7, 0xb7a3bace, 0x2528cee1,
74   0x3dcaa1dd, 0x900ad31a, 0xf21dea6d, 0x9ce51463,
75   0xf1540bba, 0x0fab1bdd, 0x89cfb79a, 0x01a2a6e6,
76   0x6f85d67c, 0xd1669ec4, 0x355db722, 0x00ebd5c4,
77   0x926eb385, 0x69ead869, 0x0da2b122, 0x402779fe,
78   0xdaed92d0, 0x57e9aabb, 0x3df64854, 0xfcc774b5,
79   0x2e1740ed, 0xa615e024, 0xf7bac938, 0x377dfd1a,
80   0xd0559d66, 0x25499be8, 0x2d8f2006, 0xfaa9e486,
81   0x95e980e7, 0x82aeba67, 0x5a7f2561, 0xbc60dff6,
82   0x6c8739a2, 0x7ec59a8b, 0x9998f265, 0xdfe37e5e,
83   0xb47cee1e, 0x4dd8bc9e, 0x35c57e09, 0x07850b63,
84   0x06eadbcb, 0x6c1f2956, 0x01685c2c, 0xf5725eef,
85   0xf13b98b5, 0xaab739c2, 0x200b1da2, 0xa716b98b,
86   0xd9ee3058, 0x76acf20b, 0x2f259e04, 0xed11658b,
87   0x1532b331, 0x0ab43204, 0xf0beb023, 0xb1685483,
88   0x58cbdc4f, 0x079384d3, 0x049b141c, 0xc38184b9,
89   0xaf551d9a, 0x66222560, 0x059deeca, 0x535f99e2
90 };
91
92 unsigned long long rsync64(unsigned char *mem, size_t size)
93 {
94     UInt32_t a = 0;
95     UInt32_t b = 0;
96     unsigned char *limit = mem + size;
97     unsigned long long result = 0;
98
99     while (mem < limit)
100     {
101         a += charTable[*mem++];
102         b += a;
103     }
104
105     a = a & 0xffffffff; /* Just in case uint32 can be 64 bits */
106     b = b & 0xffffffff;
107
108     result = ((unsigned long long)b << 32) | a;
109
110     return result;
111 }
112