mdXhl.c (f778764443157b925d5c04050d2627cf0279606a) | mdXhl.c (c177a86b92568b54e8c344318159ba79d4c241e0) |
---|---|
1/* mdXhl.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 * ---------------------------------------------------------------------------- 8 * | 1/* mdXhl.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 * ---------------------------------------------------------------------------- 8 * |
9 * $Id: mdXhl.c,v 1.10 1997/02/22 15:07:23 peter Exp $ | 9 * $Id: mdXhl.c,v 1.11 1997/08/25 05:24:25 joerg Exp $ |
10 * 11 */ 12 13#include <sys/types.h> 14#include <fcntl.h> 15#include <unistd.h> 16 17#include <errno.h> 18#include <stdio.h> 19#include <stdlib.h> 20 21#include "mdX.h" 22 23char * 24MDXEnd(MDX_CTX *ctx, char *buf) 25{ 26 int i; | 10 * 11 */ 12 13#include <sys/types.h> 14#include <fcntl.h> 15#include <unistd.h> 16 17#include <errno.h> 18#include <stdio.h> 19#include <stdlib.h> 20 21#include "mdX.h" 22 23char * 24MDXEnd(MDX_CTX *ctx, char *buf) 25{ 26 int i; |
27 unsigned char digest[16]; | 27 unsigned char digest[LENGTH]; |
28 static const char hex[]="0123456789abcdef"; 29 30 if (!buf) | 28 static const char hex[]="0123456789abcdef"; 29 30 if (!buf) |
31 buf = malloc(33); | 31 buf = malloc(2*LENGTH + 1); |
32 if (!buf) 33 return 0; | 32 if (!buf) 33 return 0; |
34 MDXFinal(digest,ctx); 35 for (i=0;i<16;i++) { | 34 MDXFinal(digest, ctx); 35 for (i = 0; i < LENGTH; i++) { |
36 buf[i+i] = hex[digest[i] >> 4]; 37 buf[i+i+1] = hex[digest[i] & 0x0f]; 38 } 39 buf[i+i] = '\0'; 40 return buf; 41} 42 43char * | 36 buf[i+i] = hex[digest[i] >> 4]; 37 buf[i+i+1] = hex[digest[i] & 0x0f]; 38 } 39 buf[i+i] = '\0'; 40 return buf; 41} 42 43char * |
44MDXFile (const char *filename, char *buf) | 44MDXFile(const char *filename, char *buf) |
45{ 46 unsigned char buffer[BUFSIZ]; 47 MDX_CTX ctx; 48 int f,i,j; 49 50 MDXInit(&ctx); 51 f = open(filename,O_RDONLY); 52 if (f < 0) return 0; --- 19 unchanged lines hidden --- | 45{ 46 unsigned char buffer[BUFSIZ]; 47 MDX_CTX ctx; 48 int f,i,j; 49 50 MDXInit(&ctx); 51 f = open(filename,O_RDONLY); 52 if (f < 0) return 0; --- 19 unchanged lines hidden --- |