X-Git-Url: https://wimlib.net/git/?p=wimlib;a=blobdiff_plain;f=src%2Fsha1.c;h=f989005a2ffcb7b17c7a294cefc4e30d46ad3fca;hp=b787942891014dcc36c155f8983bf38f508b7e19;hb=2e44f90c21db693058037f83f92ad136c818ce9d;hpb=276f9f9f9658f4a8bafd6216db46760abe8c848d diff --git a/src/sha1.c b/src/sha1.c index b7879428..f989005a 100644 --- a/src/sha1.c +++ b/src/sha1.c @@ -23,10 +23,12 @@ * along with wimlib; if not, see http://www.gnu.org/licenses/. */ -#include "util.h" -#include "wimlib.h" -#include "sha1.h" -#include "endianness.h" +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "wimlib/sha1.h" + #include /* The SHA1 support in wimlib can use an external libcrypto (part of openssl) or @@ -66,7 +68,8 @@ sha1_update(SHA_CTX *context, const void *data, size_t len) { sha1_update_intel((int*)&context->state, data, len / 64); size_t j = (context->count[0] >> 3) & 63; - if ((context->count[0] += len << 3) < (len << 3)) context->count[1]++; + if ((context->count[0] += len << 3) < (len << 3)) + context->count[1]++; context->count[1] += (len >> 29); } #include @@ -209,47 +212,3 @@ sha1_buffer(const void *buffer, size_t len, u8 md[SHA1_HASH_SIZE]) } #endif /* !WITH_LIBCRYPTO */ - -static int -sha1_stream(FILE *fp, u8 md[SHA1_HASH_SIZE]) -{ - char buf[BUFFER_SIZE]; - size_t bytes_read; - SHA_CTX ctx; - sha1_init(&ctx); - while (1) { - bytes_read = fread(buf, 1, sizeof(buf), fp); - sha1_update(&ctx, buf, bytes_read); - if (bytes_read < sizeof(buf)) { - if (ferror(fp)) - return WIMLIB_ERR_READ; - break; - } - } - sha1_final(md, &ctx); - return 0; - -} - -/* Calculates the SHA1 message digest of a file. @md must point to a buffer of - * length 20 bytes into which the message digest is written. */ -int -sha1sum(const tchar *filename, u8 md[SHA1_HASH_SIZE]) -{ - FILE *fp; - int ret; - - fp = tfopen(filename, T("rb")); - if (!fp) { - ERROR_WITH_ERRNO("Cannot open the file `%"TS"' for reading", - filename); - return WIMLIB_ERR_OPEN; - } - ret = sha1_stream(fp, md); - if (ret != 0) { - ERROR_WITH_ERRNO("Error calculating SHA1 message digest of " - "`%"TS"'", filename); - } - fclose(fp); - return ret; -}