1 /* Copyright (C) 2009 Trend Micro Inc.
4 * This program is a free software; you can redistribute it
5 * and/or modify it under the terms of the GNU General Public
6 * License (version 2) as published by the FSF - Free Software
14 #include "headers/defs.h"
17 * Only use if OpenSSL is not available
18 #ifndef LIBOPENSSL_ENABLED
22 #include <openssl/sha.h>
29 int OS_SHA1_File(const char *fname, os_sha1 output, int mode)
33 unsigned char buf[2048 + 2];
34 unsigned char md[SHA_DIGEST_LENGTH];
37 memset(output, 0, 65);
40 fp = fopen(fname, mode == OS_BINARY ? "rb" : "r");
46 while ((n = fread(buf, 1, 2048, fp)) > 0) {
48 SHA1_Update(&c, buf, n);
51 SHA1_Final(&(md[0]), &c);
53 for (n = 0; n < SHA_DIGEST_LENGTH; n++) {
54 snprintf(output, 3, "%02x", md[n]);