|
MythTV
0.26-pre
|
00001 #define LENGTH 16 00002 /* md5hl.c 00003 * ---------------------------------------------------------------------------- 00004 * "THE BEER-WARE LICENSE" (Revision 42): 00005 * <phk@login.dkuug.dk> wrote this file. As long as you retain this notice you 00006 * can do whatever you want with this stuff. If we meet some day, and you think 00007 * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp 00008 * ---------------------------------------------------------------------------- 00009 */ 00010 00011 #include <stdio.h> 00012 #include <stdlib.h> 00013 #include "our_md5.h" 00014 #include "NetCommon.h" 00015 00016 #ifndef BUFSIZ //pocket pc 00017 #define BUFSIZ 255 00018 #endif 00019 00020 00021 char * 00022 our_MD5End(MD5_CTX *ctx, char *buf) 00023 { 00024 int i; 00025 unsigned char digest[LENGTH]; 00026 static const char hex[]="0123456789abcdef"; 00027 00028 if (!buf) 00029 buf = (char*)malloc(2*LENGTH + 1); 00030 if (!buf) 00031 return 0; 00032 our_MD5Final(digest, ctx); 00033 for (i = 0; i < LENGTH; i++) { 00034 buf[i+i] = hex[digest[i] >> 4]; 00035 buf[i+i+1] = hex[digest[i] & 0x0f]; 00036 } 00037 buf[i+i] = '\0'; 00038 return buf; 00039 } 00040 00041 char * 00042 our_MD5File(const char *filename, char *buf) 00043 { 00044 unsigned char buffer[BUFSIZ]; 00045 MD5_CTX ctx; 00046 int i; 00047 FILE* f; 00048 00049 our_MD5Init(&ctx); 00050 f = fopen(filename, "r"); 00051 if (f == NULL) return 0; 00052 while ((i = fread(buffer,1,sizeof buffer,f)) > 0) { 00053 ourMD5Update(&ctx,buffer,i); 00054 } 00055 fclose(f); 00056 if (i < 0) return 0; 00057 return our_MD5End(&ctx, buf); 00058 } 00059 00060 char * 00061 our_MD5Data (const unsigned char *data, unsigned int len, char *buf) 00062 { 00063 MD5_CTX ctx; 00064 00065 our_MD5Init(&ctx); 00066 ourMD5Update(&ctx,data,len); 00067 return our_MD5End(&ctx, buf); 00068 }
1.7.6.1