X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?p=ossec-hids.git;a=blobdiff_plain;f=src%2Fos_crypto%2Fmd5%2Fmd5_op.c;fp=src%2Fos_crypto%2Fmd5%2Fmd5_op.c;h=c299aa47e4e3e91fda12f8c667adee07f189100d;hp=6785697a11bc2a08e08bbe1b8442784dc0d4c2d0;hb=3f728675941dc69d4e544d3a880a56240a6e394a;hpb=927951d1c1ad45ba9e7325f07d996154a91c911b diff --git a/src/os_crypto/md5/md5_op.c b/src/os_crypto/md5/md5_op.c old mode 100755 new mode 100644 index 6785697..c299aa4 --- a/src/os_crypto/md5/md5_op.c +++ b/src/os_crypto/md5/md5_op.c @@ -1,5 +1,3 @@ -/* $OSSEC, os_crypto/md5_op.c, v0.2, 2005/09/17, Daniel B. Cid$ */ - /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * @@ -9,80 +7,68 @@ * Foundation */ -/* v0.2 (2005/09/17): char fixes (signal) - * v0.1 (2004/08/09) - */ - -/* OS_crypto/md5 Library. - * APIs for many crypto operations. +/* OS_crypto/md5 Library + * APIs for many crypto operations */ - #include #include + +#include "md5_op.h" #include "md5.h" +#include "headers/defs.h" + -int OS_MD5_File(char * fname, char * output) +int OS_MD5_File(const char *fname, os_md5 output, int mode) { FILE *fp; MD5_CTX ctx; - unsigned char buf[1024 +1]; + unsigned char buf[1024 + 1]; unsigned char digest[16]; - int n; + size_t n; - memset(output,0, 33); + memset(output, 0, 33); buf[1024] = '\0'; - fp = fopen(fname,"r"); - if(!fp) - { - return(-1); + fp = fopen(fname, mode == OS_BINARY ? "rb" : "r"); + if (!fp) { + return (-1); } MD5Init(&ctx); - while((n = fread(buf, 1, sizeof(buf) -1, fp)) > 0) - { + while ((n = fread(buf, 1, sizeof(buf) - 1, fp)) > 0) { buf[n] = '\0'; - MD5Update(&ctx,buf,n); + MD5Update(&ctx, buf, (unsigned)n); } MD5Final(digest, &ctx); - for(n = 0;n < 16; n++) - { + for (n = 0; n < 16; n++) { snprintf(output, 3, "%02x", digest[n]); - output+=2; + output += 2; } - /* Closing it */ fclose(fp); - return(0); + return (0); } -/* EOF */ -int OS_MD5_Str(char * str, char * output) +int OS_MD5_Str(const char *str, os_md5 output) { unsigned char digest[16]; int n; MD5_CTX ctx; - MD5Init(&ctx); - - MD5Update(&ctx,(unsigned char *)str,strlen(str)); - + MD5Update(&ctx, (const unsigned char *)str, (unsigned)strlen(str)); MD5Final(digest, &ctx); output[32] = '\0'; - for(n = 0;n < 16;n++) - { + for (n = 0; n < 16; n++) { snprintf(output, 3, "%02x", digest[n]); - output+=2; + output += 2; } - return(0); + return (0); } - -/* EOF */