12 typedef unsigned long UInt32_t;
14 /* Borrowed from jigdo; original notice:
16 These are purely random, no patterns or anything... (I hope)
18 I do not claim copyright for the actual numbers below, you may use them
19 for a re-implementation of the algorithm under a license of your choice.
20 -- Richard Atterer. */
21 static UInt32_t charTable[256] = {
22 0x51d65c0f, 0x083cd94b, 0x77f73dd8, 0xa0187d36,
23 0x29803d07, 0x7ea8ac0e, 0xea4c16c9, 0xfc576443,
24 0x6213df29, 0x1c012392, 0xb38946ae, 0x2e20ca31,
25 0xe4dc532f, 0xcb281c47, 0x8508b6a5, 0xb93c210d,
26 0xef02b5f3, 0x66548c74, 0x9ae2deab, 0x3b59f472,
27 0x4e546447, 0x45232d1f, 0x0ac0a4b1, 0x6c4c264b,
28 0x5d24ce84, 0x0f2752cc, 0xa35c7ac7, 0x3e31af51,
29 0x79675a59, 0x581f0e81, 0x49053122, 0x7339c9d8,
30 0xf9833565, 0xa3dbe5b3, 0xcc06eeb9, 0x92d0671c,
31 0x3eb220a7, 0x64864eae, 0xca100872, 0xc50977a1,
32 0xd90378e1, 0x7a36cab9, 0x15c15f4b, 0x8b9ef749,
33 0xcc1432dc, 0x1ec578ed, 0x27e6e092, 0xbb06db8f,
34 0x67f661ac, 0x8dd1a3db, 0x2a0ca16b, 0xb229ab84,
35 0x127a3337, 0x347d846f, 0xe1ea4b50, 0x008dbb91,
36 0x414c1426, 0xd2be76f0, 0x08789a39, 0xb4d93e30,
37 0x61667760, 0x8871bee9, 0xab7da12d, 0xe3c58620,
38 0xe9fdfbbe, 0x64fb04f7, 0x8cc5bbf0, 0xf5272d30,
39 0x8f161b50, 0x11122b05, 0x7695e72e, 0xa1c5d169,
40 0x1bfd0e20, 0xef7e6169, 0xf652d08e, 0xa9d0f139,
41 0x2f70aa04, 0xae2c7d6d, 0xa3cb9241, 0x3ae7d364,
42 0x348788f8, 0xf483b8f1, 0x55a011da, 0x189719dc,
43 0xb0c5d723, 0x8b344e33, 0x300d46eb, 0xd44fe34f,
44 0x1a2016c1, 0x66ce4cd7, 0xa45ea5e3, 0x55cb708a,
45 0xbce430df, 0xb01ae6e0, 0x3551163b, 0x2c5b157a,
46 0x574c4209, 0x430fd0e4, 0x3387e4a5, 0xee1d7451,
47 0xa9635623, 0x873ab89b, 0xb96bc6aa, 0x59898937,
48 0xe646c6e7, 0xb79f8792, 0x3f3235d8, 0xef1b5acf,
49 0xd975b22b, 0x427acce6, 0xe47a2411, 0x75f8c1e8,
50 0xa63f799d, 0x53886ad8, 0x9b2d6d32, 0xea822016,
51 0xcdee2254, 0xd98bcd98, 0x2933a544, 0x961f379f,
52 0x49219792, 0xc61c360f, 0x77cc0c64, 0x7b872046,
53 0xb91c7c12, 0x7577154b, 0x196573be, 0xf788813f,
54 0x41e2e56a, 0xec3cd244, 0x8c7401f1, 0xc2e805fe,
55 0xe8872fbe, 0x9e2faf7d, 0x6766456b, 0x888e2197,
56 0x28535c6d, 0x2ce45f3f, 0x24261d2a, 0xd6faab8b,
57 0x7a7b42b8, 0x15f0f6fa, 0xfe1711df, 0x7e5685a6,
58 0x00930268, 0x74755331, 0x1998912c, 0x7b60498b,
59 0x501a5786, 0x92ace0f6, 0x1d9752fe, 0x5a731add,
60 0x5b3b44fc, 0x473673f9, 0xa42c0321, 0xd82f9f18,
61 0xb4b225da, 0xfc89ece2, 0x072e1130, 0x5772aae3,
62 0x29010857, 0x542c970c, 0x94f67fe5, 0x71209e9b,
63 0xdb97ea39, 0x2689b41b, 0xae815804, 0xfc5e2651,
64 0xd4521674, 0x48ed979a, 0x2f617da3, 0xc350353d,
65 0xc3accd94, 0xbd8d313a, 0xc61a8e77, 0xf34940a4,
66 0x8d2c6b0f, 0x0f0e7225, 0x39e183db, 0xd19ebba9,
67 0x6a0f37b9, 0xd18922f3, 0x106420c5, 0xaa5a640b,
68 0x7cf0d273, 0xcf3238a7, 0x3b33204f, 0x476be7bb,
69 0x09d23bca, 0xbe84b2f7, 0xb7a3bace, 0x2528cee1,
70 0x3dcaa1dd, 0x900ad31a, 0xf21dea6d, 0x9ce51463,
71 0xf1540bba, 0x0fab1bdd, 0x89cfb79a, 0x01a2a6e6,
72 0x6f85d67c, 0xd1669ec4, 0x355db722, 0x00ebd5c4,
73 0x926eb385, 0x69ead869, 0x0da2b122, 0x402779fe,
74 0xdaed92d0, 0x57e9aabb, 0x3df64854, 0xfcc774b5,
75 0x2e1740ed, 0xa615e024, 0xf7bac938, 0x377dfd1a,
76 0xd0559d66, 0x25499be8, 0x2d8f2006, 0xfaa9e486,
77 0x95e980e7, 0x82aeba67, 0x5a7f2561, 0xbc60dff6,
78 0x6c8739a2, 0x7ec59a8b, 0x9998f265, 0xdfe37e5e,
79 0xb47cee1e, 0x4dd8bc9e, 0x35c57e09, 0x07850b63,
80 0x06eadbcb, 0x6c1f2956, 0x01685c2c, 0xf5725eef,
81 0xf13b98b5, 0xaab739c2, 0x200b1da2, 0xa716b98b,
82 0xd9ee3058, 0x76acf20b, 0x2f259e04, 0xed11658b,
83 0x1532b331, 0x0ab43204, 0xf0beb023, 0xb1685483,
84 0x58cbdc4f, 0x079384d3, 0x049b141c, 0xc38184b9,
85 0xaf551d9a, 0x66222560, 0x059deeca, 0x535f99e2
88 unsigned long long rsync64(unsigned char *mem, size_t size)
92 unsigned char *limit = mem + size;
93 unsigned long long result = 0;
97 a += charTable[*mem++];
101 a = a & 0xffffffff; // Just in case uint32 can be 64 bits
104 result = ((unsigned long long)b << 32) | a;
109 #define BUF_SIZE 1024
112 #define MIN(x,y) ( ((x) < (y)) ? (x) : (y))
115 static int rsyncsum_file(char *filename)
119 unsigned long long rsum = 0;
120 char *base64_sum = NULL;
124 /* Check if we're reading from stdin */
125 if (!strcmp("-", filename))
129 fprintf(stderr, "\r %-75.75s", filename);
130 file = fopen(filename, "rb");
139 fprintf(stderr, "Unable to open file %s; error %d\n", filename, errno);
149 memset(buf, 0, BUF_SIZE);
151 used = fread(buf, 1, BUF_SIZE, file);
155 rsum = rsync64((unsigned char *)buf, BUF_SIZE);
160 printf("%llx\n", rsum);
162 base64_sum = base64_dump((unsigned char *)&rsum, 8);
167 printf("%s %s\n", base64_sum, filename);
171 printf("%s\n", base64_sum);
178 int main(int argc, char **argv)
182 for (i = 1; i < argc; i++)
183 (void) rsyncsum_file(argv[i]);