make the bot print its name
[0verkill.git] / md5hl.c
blob6d53655df29272a1e083777c7ac4f1959f48e41e
1 /* md5hl.c
2 * ----------------------------------------------------------------------------
3 * "THE BEER-WARE LICENSE" (Revision 42):
4 * <phk@login.dkuug.dk> wrote this file. As long as you retain this notice you
5 * can do whatever you want with this stuff. If we meet some day, and you think
6 * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
7 * ----------------------------------------------------------------------------
9 * $Id: md5hl.c,v 1.8.2.1 1998/02/18 02:24:05 jkh Exp $
13 #include <sys/types.h>
14 #include <fcntl.h>
15 #ifndef WIN32
16 #include <unistd.h>
17 #endif
19 #include <errno.h>
20 #include <stdio.h>
21 #include <stdlib.h>
23 #include "md5.h"
24 #include "error.h"
26 char *
27 MD5End(MD5_CTX *ctx, char *buf)
29 int i;
30 unsigned char digest[MD5_HASHBYTES];
31 static const char hex[]="0123456789abcdef";
33 if (!buf)
34 buf = mem_alloc(33);
35 if (!buf)
36 return 0;
37 MD5Final(digest,ctx);
38 for (i=0;i<MD5_HASHBYTES;i++) {
39 buf[i+i] = hex[digest[i] >> 4];
40 buf[i+i+1] = hex[digest[i] & 0x0f];
42 buf[i+i] = '\0';
43 return buf;
46 char *
47 MD5File (const char *filename, char *buf)
49 unsigned char buffer[BUFSIZ];
50 MD5_CTX ctx;
51 int i,j;
52 FILE *f;
54 MD5Init(&ctx);
56 #ifndef WIN32
57 if (!(f = fopen(filename, "r")))
58 #else
59 printf("%s\n", filename);for(;;);
60 if (fopen_s(&f, filename, "r") != 0) /* tady to hnije .. */
61 #endif
62 return 0;
63 while ((i = fread(buffer,sizeof buffer,1,f)) > 0) {
64 MD5Update(&ctx,buffer,i);
66 j = errno;
67 fclose(f);
68 errno = j;
69 if (i < 0) return 0;
70 return MD5End(&ctx, buf);
73 char *
74 MD5Data (const unsigned char *data, unsigned int len, char *buf)
76 MD5_CTX ctx;
78 MD5Init(&ctx);
79 MD5Update(&ctx,data,len);
80 return MD5End(&ctx, buf);