1 /* $OSSEC, os_crypto/md5_op.c, v0.2, 2005/09/17, Daniel B. Cid$ */
3 /* Copyright (C) 2009 Trend Micro Inc.
6 * This program is a free software; you can redistribute it
7 * and/or modify it under the terms of the GNU General Public
8 * License (version 2) as published by the FSF - Free Software
12 /* v0.2 (2005/09/17): char fixes (signal)
16 /* OS_crypto/md5 Library.
17 * APIs for many crypto operations.
25 int OS_MD5_File(char * fname, char * output)
29 unsigned char buf[1024 +1];
30 unsigned char digest[16];
36 fp = fopen(fname,"r");
43 while((n = fread(buf, 1, sizeof(buf) -1, fp)) > 0)
46 MD5Update(&ctx,buf,n);
49 MD5Final(digest, &ctx);
51 for(n = 0;n < 16; n++)
53 snprintf(output, 3, "%02x", digest[n]);
64 int OS_MD5_Str(char * str, char * output)
66 unsigned char digest[16];
74 MD5Update(&ctx,(unsigned char *)str,strlen(str));
76 MD5Final(digest, &ctx);
81 snprintf(output, 3, "%02x", digest[n]);