58f94bd4988cf7a97cf2dd4222e6cd62513a88ed
galt
  Wed Apr 19 17:44:24 2017 -0700
Adding free opensource fast SHA1 from git. This is primarily inteded for hashing to quickly checking if files are identical. It can run quickly on a block of RAM or on a file. You can get raw binary values or hex string.

diff --git src/inc/gitSha1.h src/inc/gitSha1.h
new file mode 100644
index 0000000..db8cecf
--- /dev/null
+++ src/inc/gitSha1.h
@@ -0,0 +1,73 @@
+#ifndef GIT_SHA1
+/*
+ * sha1-git.h
+ *
+ * This code is based on the GIT SHA1 Implementation.
+ *
+ * Copyright (C) 2009 Linus Torvalds <torvalds@linux-foundation.org>
+ * Copyright (C) 2009 Nicolas Pitre <nico@cam.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ */
+
+/*
+ * SHA1 routine optimized to do word accesses rather than byte accesses,
+ * and to avoid unnecessary copies into the context array.
+ *
+ * This was initially based on the Mozilla SHA1 implementation, although
+ * none of the original Mozilla code remains.
+ */
+
+typedef struct {
+	unsigned long long size;
+	unsigned int h0,h1,h2,h3,h4;
+	unsigned int W[16];
+} blk_SHA_CTX;
+
+void blk_SHA1_Init(blk_SHA_CTX *ctx);
+void blk_SHA1_Update(blk_SHA_CTX *ctx, const void *dataIn, unsigned long len);
+void blk_SHA1_Final(unsigned char hashout[20], blk_SHA_CTX *ctx);
+
+#define git_SHA_CTX	blk_SHA_CTX
+#define git_SHA1_Init	blk_SHA1_Init
+#define git_SHA1_Update	blk_SHA1_Update
+#define git_SHA1_Final	blk_SHA1_Final
+#define SHA_DIGEST_LENGTH 20
+
+/* ============== Added by UCSC Genome Browser ============= */
+
+char *sha1ToHex(unsigned char hash[20]);
+/* Convert binary representation of sha1 to hex string. Do a freeMem on result when done. */
+
+
+void sha1ForFile(char *fileName, unsigned char hash[20]);
+/* Make sha1 hash from file */
+
+char *sha1HexForFile(char *fileName);
+/* Return Sha1 as Hex string */
+
+void sha1ForBuf(char *buffer, size_t bufSize, unsigned char hash[20]);
+/* Return sha1 hash of buffer. */
+
+char *sha1HexForBuf(char *buf, size_t bufSize);
+/* Return Sha1 as Hex string */
+
+char *sha1HexForString(char *string);
+/* Return sha sum of zero-terminated string. */
+
+#define GIT_SHA1
+#endif