2 Copyright (C) Andrew Tridgell 2002
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 simple front-end functions to mdfour code
24 static struct mdfour md;
26 void hash_buffer(const char *s, int len)
28 mdfour_update(&md, (unsigned char *)s, len);
36 void hash_string(const char *s)
38 hash_buffer(s, strlen(s));
43 hash_buffer((char *)&x, sizeof(x));
46 /* add contents of a file to the hash */
47 void hash_file(const char *fname)
52 fd = open(fname, O_RDONLY|O_BINARY);
54 cc_log("Failed to open %s\n", fname);
58 while ((n = read(fd, buf, sizeof(buf))) > 0) {
64 /* return the hash result as a static string */
65 char *hash_result(void)
67 unsigned char sum[16];
72 mdfour_result(&md, sum);
75 sprintf(&ret[i*2], "%02x", (unsigned)sum[i]);
77 sprintf(&ret[i*2], "-%u", (unsigned)md.totalN);