2 Copyright (C) Andrew Tridgell 1996
3 Copyright (C) Paul Mackerras 1996
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 a simple 32 bit checksum that can be upadted from either end
25 (inspired by Mark Adler's Adler-32 checksum)
27 uint32 get_checksum1(char *buf,int len)
33 for (i = 0; i < len; i++) {
37 return (s1 & 0xffff) + (s2 << 16);
41 void get_checksum2(char *buf,int len,char *sum)
48 for(i = 0; i + 64 <= len; i += 64) {
50 MDupdate(&MD, buf2, 512);
52 bcopy(buf+i,buf2,len-i);
53 MDupdate(&MD, buf2, (len-i)*8);
54 SIVAL(sum,0,MD.buffer[0]);
55 SIVAL(sum,4,MD.buffer[1]);
56 SIVAL(sum,8,MD.buffer[2]);
57 SIVAL(sum,12,MD.buffer[3]);
60 void file_checksum(char *fname,char *sum,off_t size)
64 bzero(sum,SUM_LENGTH);
66 fd = open(fname,O_RDONLY);
69 buf = map_file(fd,size);
75 get_checksum2(buf,size,sum);