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
15 #include "md5_sha1_op.h"
17 #include "../md5/md5.h"
18 #include "../sha1/sha.h"
22 int OS_MD5_SHA1_File(char * fname, char *md5output, char *sha1output)
26 unsigned char buf[2048 +2];
27 unsigned char sha1_digest[SHA_DIGEST_LENGTH];
28 unsigned char md5_digest[16];
34 /* Clearing the memory. */
39 fp = fopen(fname,"r");
44 /* Initializing both hashes */
49 /* Updating for each one. */
50 while((n = fread(buf, 1, 2048, fp)) > 0)
53 SHA1_Update(&sha1_ctx, buf, (unsigned long)n);
54 MD5Update(&md5_ctx, buf, n);
57 SHA1_Final(&(sha1_digest[0]), &sha1_ctx);
58 MD5Final(md5_digest, &md5_ctx);
61 /* Setting output for md5. */
62 for(n = 0;n < 16; n++)
64 snprintf(md5output, 3, "%02x", md5_digest[n]);
68 /* Setting output for sha1. */
69 for (n = 0; n<SHA_DIGEST_LENGTH; n++)
71 snprintf(sha1output, 3, "%02x", sha1_digest[n]);