Commit Diff


commit - e9ba3467c2b7dd17437afd611e1f2c98da726750
commit + 1362b0e3088fdb4d1c93ffbdd3a1fbbdc767a34b
blob - 5d8f4c8b71e72109e36cd63e72e3f77d6e211bdd
blob + a1a8e70bcff43bc951fef97bb37e60985bb35f76
--- got/Makefile
+++ got/Makefile
@@ -6,7 +6,7 @@ PROG=		got
 SRCS=		got.c blame.c commit_graph.c delta.c diff.c \
 		diffreg.c error.c fileindex.c object.c object_cache.c \
 		object_idset.c object_parse.c opentemp.c path.c pack.c \
-		privsep.c reference.c repository.c sha1.c worktree.c \
+		privsep.c reference.c repository.c hash.c worktree.c \
 		worktree_open.c inflate.c buf.c rcsutil.c diff3.c lockfile.c \
 		deflate.c object_create.c delta_cache.c fetch.c \
 		gotconfig.c diff_main.c diff_atomize_text.c \
blob - ef6f8e38e4cc6e4b1ea84fc72c54665a093b32ab
blob + cc4991565d1474d6bb048dff63d3db36b10e23c8
--- gotadmin/Makefile
+++ gotadmin/Makefile
@@ -8,7 +8,7 @@ SRCS=		gotadmin.c \
 		inflate.c lockfile.c object.c object_cache.c object_create.c \
 		object_idset.c object_parse.c opentemp.c pack.c pack_create.c \
 		path.c privsep.c reference.c repository.c repository_admin.c \
-		worktree_open.c sha1.c bloom.c murmurhash2.c ratelimit.c \
+		worktree_open.c hash.c bloom.c murmurhash2.c ratelimit.c \
 		sigs.c buf.c date.c object_open_privsep.c \
 		read_gitconfig_privsep.c read_gotconfig_privsep.c \
 		pack_create_privsep.c pollfd.c reference_parse.c
blob - de99e60620ea466b3e56f258e643d00a974595d6
blob + 6bb6b5159015671c4ebc4d29bbfa2a67e617c632
--- gotctl/Makefile
+++ gotctl/Makefile
@@ -3,7 +3,7 @@
 .include "../got-version.mk"
 
 PROG=		gotctl
-SRCS=		gotctl.c error.c imsg.c pollfd.c sha1.c
+SRCS=		gotctl.c error.c imsg.c pollfd.c hash.c
 
 MAN =		${PROG}.8
 
blob - 9e2f3a3fe6ecbd861b2a0fecf13026d61c3d475b
blob + b7c896f3faf9b3cbecc58d07a2ad7f76b9226064
--- gotd/Makefile
+++ gotd/Makefile
@@ -14,7 +14,7 @@ SRCS=		gotd.c auth.c repo_read.c repo_write.c log.c pr
 		object.c object_cache.c object_create.c object_idset.c \
 		object_open_io.c object_parse.c opentemp.c pack.c path.c \
 		read_gitconfig.c read_gotconfig.c reference.c repository.c  \
-		sha1.c sigs.c pack_create_io.c pollfd.c reference_parse.c \
+		hash.c sigs.c pack_create_io.c pollfd.c reference_parse.c \
 		repo_imsg.c pack_index.c session.c
 
 MAN =		${PROG}.conf.5 ${PROG}.8
blob - c12e64ed01b5786b4ea168e06564ba83b165dacc
blob + 8bfd851df2f50bc2a512a0606ffcc07bf5083ee6
--- gotd/gotd.c
+++ gotd/gotd.c
@@ -51,7 +51,7 @@
 #include "got_lib_delta.h"
 #include "got_lib_object.h"
 #include "got_lib_object_cache.h"
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 #include "got_lib_gitproto.h"
 #include "got_lib_pack.h"
 #include "got_lib_repository.h"
blob - 1526098d032a63b62e950b3ec2d761dfef242c87
blob + 400bb753d71571f27a4b7c68c143f3aee2209b84
--- gotd/repo_imsg.c
+++ gotd/repo_imsg.c
@@ -31,7 +31,7 @@
 #include "got_error.h"
 #include "got_object.h"
 
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 
 #include "gotd.h"
 #include "log.h"
blob - e7aaf4f5809b0239f3c570f96c02a85b48277309
blob + 7ef5ec6343df742b531c73d527320a8f84cc25ad
--- gotd/repo_read.c
+++ gotd/repo_read.c
@@ -41,7 +41,7 @@
 #include "got_lib_delta.h"
 #include "got_lib_object.h"
 #include "got_lib_object_idset.h"
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 #include "got_lib_pack.h"
 #include "got_lib_ratelimit.h"
 #include "got_lib_pack_create.h"
blob - e9fbea6290419b30580547344149d18c25027cce
blob + 629b1b93ecf342a5823646e9a768f6f28b82bd02
--- gotd/repo_write.c
+++ gotd/repo_write.c
@@ -52,7 +52,7 @@
 #include "got_lib_repository.h"
 #include "got_lib_poll.h"
 
-#include "got_lib_sha1.h" /* XXX temp include for debugging */
+#include "got_lib_hash.h" /* XXX temp include for debugging */
 
 #include "log.h"
 #include "gotd.h"
blob - 7afd805b08cfd8cb0a3ad7907289517cc972de3f
blob + 0f1974ec4bdd863d92c1000f762f39688d6abbca
--- gotd/session.c
+++ gotd/session.c
@@ -41,7 +41,7 @@
 #include "got_reference.h"
 #include "got_opentemp.h"
 
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 #include "got_lib_delta.h"
 #include "got_lib_object.h"
 #include "got_lib_object_cache.h"
blob - c4456b3590ca82fd05071e3b28f8372a45371af0
blob + 1c08fb04532cfc84480cbf12b006e5ade168d6ec
--- gotsh/Makefile
+++ gotsh/Makefile
@@ -3,7 +3,7 @@
 .include "../got-version.mk"
 
 PROG=		gotsh
-SRCS=		gotsh.c error.c pkt.c sha1.c serve.c path.c gitproto.c \
+SRCS=		gotsh.c error.c pkt.c hash.c serve.c path.c gitproto.c \
 		imsg.c pollfd.c reference_parse.c
 
 MAN =		${PROG}.1
blob - 3ff6327350055dfdcfeb3094e2836fcdcda955dc
blob + c2c364ff9f79098f7f41fb01b58642d7fa2661f9
--- gotwebd/Makefile
+++ gotwebd/Makefile
@@ -12,7 +12,7 @@ SRCS =		config.c sockets.c log.c gotwebd.c parse.y pro
 SRCS +=		blame.c commit_graph.c delta.c diff.c \
 		diffreg.c error.c fileindex.c object.c object_cache.c \
 		object_idset.c object_parse.c opentemp.c path.c pack.c \
-		privsep.c reference.c repository.c sha1.c worktree.c \
+		privsep.c reference.c repository.c hash.c worktree.c \
 		utf8.c inflate.c buf.c rcsutil.c diff3.c \
 		lockfile.c deflate.c object_create.c delta_cache.c \
 		gotconfig.c diff_main.c diff_atomize_text.c diff_myers.c \
blob - 58d428b99c43b2fba80028b6233bcd4ff6c7e4a4
blob + 05240d53214a844ee3d7b7d988783c9e4cfd7147
--- gotwebd/libexec/got-read-blob/Makefile
+++ gotwebd/libexec/got-read-blob/Makefile
@@ -3,7 +3,7 @@
 
 PROG=		got-read-blob
 SRCS=		got-read-blob.c error.c inflate.c object_parse.c \
-		path.c privsep.c sha1.c pollfd.c
+		path.c privsep.c hash.c pollfd.c
 
 CPPFLAGS = -I${.CURDIR}/../../../include -I${.CURDIR}/../../../lib
 LDADD = -lutil -lz
blob - 669332cc8be5487a26cc868b873f782c7e351623
blob + 1165c222b775505baa64d377371c136878c607c8
--- gotwebd/libexec/got-read-commit/Makefile
+++ gotwebd/libexec/got-read-commit/Makefile
@@ -3,7 +3,7 @@
 
 PROG=		got-read-commit
 SRCS=		got-read-commit.c error.c inflate.c object_parse.c \
-		path.c privsep.c sha1.c pollfd.c
+		path.c privsep.c hash.c pollfd.c
 
 CPPFLAGS = -I${.CURDIR}/../../../include -I${.CURDIR}/../../../lib
 LDADD = -lutil -lz
blob - d81d4666fc3206a3008ddfc673992c5ec3265bd9
blob + e7bc462853862dcc5569354205b83cfa255442c1
--- gotwebd/libexec/got-read-gitconfig/Makefile
+++ gotwebd/libexec/got-read-gitconfig/Makefile
@@ -3,7 +3,7 @@
 
 PROG=		got-read-gitconfig
 SRCS=		got-read-gitconfig.c error.c inflate.c object_parse.c \
-		path.c privsep.c sha1.c gitconfig.c pollfd.c
+		path.c privsep.c hash.c gitconfig.c pollfd.c
 
 CPPFLAGS = -I${.CURDIR}/../../../include -I${.CURDIR}/../../../lib
 LDADD = -lutil -lz
blob - abc9574b7efb93c971c76b3576970c8c19ba0e14
blob + dba200d19f6705b4dd9f5cd7a449af9a216da7f3
--- gotwebd/libexec/got-read-gotconfig/Makefile
+++ gotwebd/libexec/got-read-gotconfig/Makefile
@@ -3,7 +3,7 @@
 
 PROG=		got-read-gotconfig
 SRCS=		got-read-gotconfig.c error.c inflate.c object_parse.c \
-		path.c privsep.c sha1.c parse.y pollfd.c
+		path.c privsep.c hash.c parse.y pollfd.c
 
 CPPFLAGS = -I${.CURDIR}/../../../include -I${.CURDIR}/../../../lib \
 	-I${.CURDIR}/../../../libexec/got-read-gotconfig
blob - 1c3afaf56bad757cf3c8b9574bc12521adbda7bb
blob + 97907ead0bd33b477aa7c06d62d666b9c00564ab
--- gotwebd/libexec/got-read-object/Makefile
+++ gotwebd/libexec/got-read-object/Makefile
@@ -3,7 +3,7 @@
 
 PROG=		got-read-object
 SRCS=		got-read-object.c error.c inflate.c object_parse.c \
-		path.c privsep.c sha1.c pollfd.c
+		path.c privsep.c hash.c pollfd.c
 
 CPPFLAGS = -I${.CURDIR}/../../../include -I${.CURDIR}/../../../lib
 LDADD = -lutil -lz
blob - 9c1bf08b6d1c6cea526cdb38361ef89dfce5bc32
blob + 12228b03188af547ebf7a86b8f434b966ed06b98
--- gotwebd/libexec/got-read-pack/Makefile
+++ gotwebd/libexec/got-read-pack/Makefile
@@ -4,7 +4,7 @@
 PROG=		got-read-pack
 SRCS=		got-read-pack.c delta.c error.c inflate.c object_cache.c \
 		object_idset.c object_parse.c opentemp.c pack.c path.c \
-		privsep.c sha1.c delta_cache.c pollfd.c
+		privsep.c hash.c delta_cache.c pollfd.c
 
 CPPFLAGS = -I${.CURDIR}/../../../include -I${.CURDIR}/../../../lib
 LDADD = -lutil -lz
blob - 450ee15c54e4904304143c4129f1adf9fd085073
blob + e3695245b3e0161a86859b3cb3e10a413f4d74bb
--- gotwebd/libexec/got-read-tag/Makefile
+++ gotwebd/libexec/got-read-tag/Makefile
@@ -3,7 +3,7 @@
 
 PROG=		got-read-tag
 SRCS=		got-read-tag.c error.c inflate.c object_parse.c \
-		path.c privsep.c sha1.c pollfd.c
+		path.c privsep.c hash.c pollfd.c
 
 CPPFLAGS = -I${.CURDIR}/../../../include -I${.CURDIR}/../../../lib
 LDADD = -lutil -lz
blob - 20c0a23b3bf5a858afe4cd8a8e2d57c5194dd074
blob + db849065b699533903ca1e34443e2612c1983ec8
--- gotwebd/libexec/got-read-tree/Makefile
+++ gotwebd/libexec/got-read-tree/Makefile
@@ -3,7 +3,7 @@
 
 PROG=		got-read-tree
 SRCS=		got-read-tree.c error.c inflate.c object_parse.c \
-		path.c privsep.c sha1.c pollfd.c
+		path.c privsep.c hash.c pollfd.c
 
 CPPFLAGS = -I${.CURDIR}/../../../include -I${.CURDIR}/../../../lib
 LDADD = -lutil -lz
blob - eb65f2ee764ee40fc22cc4fd6cfb99a2acff8e21
blob + 91dc6717927c10d883778d59d55a91d909735204
--- lib/fetch.c
+++ lib/fetch.c
@@ -58,7 +58,7 @@
 #include "got_lib_object_parse.h"
 #include "got_lib_object_create.h"
 #include "got_lib_pack.h"
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 #include "got_lib_privsep.h"
 #include "got_lib_object_cache.h"
 #include "got_lib_repository.h"
blob - /dev/null
blob + faf9e8a717096264c717436f464e9b6cbf22d64e (mode 644)
--- /dev/null
+++ lib/got_lib_hash.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#define GOT_SHA1_STRING_ZERO "0000000000000000000000000000000000000000"
+#define GOT_SHA256_STRING_ZERO "0000000000000000000000000000000000000000000000000000000000000000"
+
+int got_parse_xdigit(uint8_t *, const char *);
+
+int got_parse_sha1_digest(uint8_t *, const char *);
+char *got_sha1_digest_to_str(const uint8_t *, char *, size_t);
+
+int got_parse_sha256_digest(uint8_t *, const char *);
+char *got_sha256_digest_to_str(const uint8_t *, char *, size_t);
blob - faf9e8a717096264c717436f464e9b6cbf22d64e (mode 644)
blob + /dev/null
--- lib/got_lib_sha1.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#define GOT_SHA1_STRING_ZERO "0000000000000000000000000000000000000000"
-#define GOT_SHA256_STRING_ZERO "0000000000000000000000000000000000000000000000000000000000000000"
-
-int got_parse_xdigit(uint8_t *, const char *);
-
-int got_parse_sha1_digest(uint8_t *, const char *);
-char *got_sha1_digest_to_str(const uint8_t *, char *, size_t);
-
-int got_parse_sha256_digest(uint8_t *, const char *);
-char *got_sha256_digest_to_str(const uint8_t *, char *, size_t);
blob - /dev/null
blob + 64485ff6dfa3d6b53ae14ed4929b4464fff2160f (mode 644)
--- /dev/null
+++ lib/hash.c
@@ -0,0 +1,128 @@
+/*
+ * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+#include <sha1.h>
+#include <sha2.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <limits.h>
+
+#include "got_lib_hash.h"
+
+int
+got_parse_xdigit(uint8_t *val, const char *hex)
+{
+	char *ep;
+	long lval;
+
+	errno = 0;
+	lval = strtol(hex, &ep, 16);
+	if (hex[0] == '\0' || *ep != '\0')
+		return 0;
+	if (errno == ERANGE && (lval == LONG_MAX || lval == LONG_MIN))
+		return 0;
+
+	*val = (uint8_t)lval;
+	return 1;
+}
+
+int
+got_parse_sha1_digest(uint8_t *digest, const char *line)
+{
+	uint8_t b = 0;
+	char hex[3] = {'\0', '\0', '\0'};
+	int i, j;
+
+	for (i = 0; i < SHA1_DIGEST_LENGTH; i++) {
+		if (line[0] == '\0' || line[1] == '\0')
+			return 0;
+		for (j = 0; j < 2; j++) {
+			hex[j] = *line;
+			line++;
+		}
+		if (!got_parse_xdigit(&b, hex))
+			return 0;
+		digest[i] = b;
+	}
+
+	return 1;
+}
+
+char *
+got_sha1_digest_to_str(const uint8_t *digest, char *buf, size_t size)
+{
+	char *p = buf;
+	char hex[3];
+	int i;
+
+	if (size < SHA1_DIGEST_STRING_LENGTH)
+		return NULL;
+
+	for (i = 0; i < SHA1_DIGEST_LENGTH; i++) {
+		snprintf(hex, sizeof(hex), "%.2x", digest[i]);
+		p[0] = hex[0];
+		p[1] = hex[1];
+		p += 2;
+	}
+	p[0] = '\0';
+
+	return buf;
+}
+
+int
+got_parse_sha256_digest(uint8_t *digest, const char *line)
+{
+	uint8_t b = 0;
+	char hex[3] = {'\0', '\0', '\0'};
+	int i, j;
+
+	for (i = 0; i < SHA256_DIGEST_LENGTH; i++) {
+		if (line[0] == '\0' || line[1] == '\0')
+			return 0;
+		for (j = 0; j < 2; j++) {
+			hex[j] = *line;
+			line++;
+		}
+		if (!got_parse_xdigit(&b, hex))
+			return 0;
+		digest[i] = b;
+	}
+
+	return 1;
+}
+
+char *
+got_sha256_digest_to_str(const uint8_t *digest, char *buf, size_t size)
+{
+	char *p = buf;
+	char hex[3];
+	int i;
+
+	if (size < SHA256_DIGEST_STRING_LENGTH)
+		return NULL;
+
+	for (i = 0; i < SHA256_DIGEST_LENGTH; i++) {
+		snprintf(hex, sizeof(hex), "%.2x", digest[i]);
+		p[0] = hex[0];
+		p[1] = hex[1];
+		p += 2;
+	}
+	p[0] = '\0';
+
+	return buf;
+}
blob - d24ed1273775e870e596058bd87ae6d7513d575e
blob + 6ce635e299cfb8a3b1d2cc29df47893282d7e9e6
--- lib/object.c
+++ lib/object.c
@@ -40,7 +40,7 @@
 #include "got_opentemp.h"
 #include "got_path.h"
 
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 #include "got_lib_delta.h"
 #include "got_lib_inflate.h"
 #include "got_lib_object.h"
blob - 5970ef187d413a47e65fae15c0395d2d476c9c75
blob + 559839987c1189a29404277bd6cfc773f938df71
--- lib/object_create.c
+++ lib/object_create.c
@@ -39,7 +39,7 @@
 #include "got_path.h"
 #include "got_sigs.h"
 
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 #include "got_lib_deflate.h"
 #include "got_lib_delta.h"
 #include "got_lib_object.h"
blob - ea0c9504eee74230a6d934d80b6e22eba99cd29a
blob + d55b66e81877a6e05c07a226ffbd0453235a5780
--- lib/object_parse.c
+++ lib/object_parse.c
@@ -43,7 +43,7 @@
 #include "got_opentemp.h"
 #include "got_path.h"
 
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 #include "got_lib_delta.h"
 #include "got_lib_inflate.h"
 #include "got_lib_object.h"
blob - eed8dc27810b38fc43463c4d44795ce817ccda5f
blob + 0048ae629a38010d410c22c71c21498ebe088357
--- lib/pack.c
+++ lib/pack.c
@@ -40,7 +40,7 @@
 #include "got_object.h"
 #include "got_path.h"
 
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 #include "got_lib_delta.h"
 #include "got_lib_delta_cache.h"
 #include "got_lib_inflate.h"
blob - b8ed4fd9e151796a95b816ff7107c85ff24a4054
blob + 1a2c4fdd7b26a9c941627e4eecd38bbd768ce35a
--- lib/pack_index.c
+++ lib/pack_index.c
@@ -44,7 +44,7 @@
 #include "got_error.h"
 #include "got_object.h"
 
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 #include "got_lib_delta.h"
 #include "got_lib_inflate.h"
 #include "got_lib_object.h"
blob - 77e1cfb7d3eb6c26f617d2e54ebf77e7f7f9c77c
blob + e6f4a149822160b5f8f31472e5749bb81e9bfa10
--- lib/patch.c
+++ lib/patch.c
@@ -53,7 +53,7 @@
 #include "got_lib_diff.h"
 #include "got_lib_object.h"
 #include "got_lib_privsep.h"
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 
 #define MIN(a, b) ((a) < (b) ? (a) : (b))
 
blob - e03ebbea58c6e4561964654bdbcde534f9ee5440
blob + aaa7df19451129acb5dbcfbda0fa6a8a6a9a3ed6
--- lib/privsep.c
+++ lib/privsep.c
@@ -40,7 +40,7 @@
 #include "got_path.h"
 #include "got_repository.h"
 
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 #include "got_lib_delta.h"
 #include "got_lib_inflate.h"
 #include "got_lib_object.h"
blob - c1afdfc4a88f8d1113a98ff84a8eb20f48876b7d
blob + b2335b7991e5216b74c9a6a5d47ff2c83463b3da
--- lib/reference.c
+++ lib/reference.c
@@ -39,7 +39,7 @@
 #include "got_opentemp.h"
 #include "got_path.h"
 
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 #include "got_lib_delta.h"
 #include "got_lib_inflate.h"
 #include "got_lib_object.h"
blob - 0754181c966dd6e0dec04ea2f73f3c40781a534d
blob + 0bd411b20d1f896f8ebc8062476aa5c3c3593dcc
--- lib/repository.c
+++ lib/repository.c
@@ -61,7 +61,7 @@
 #include "got_lib_object_create.h"
 #include "got_lib_pack.h"
 #include "got_lib_privsep.h"
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 #include "got_lib_object_cache.h"
 #include "got_lib_repository.h"
 #include "got_lib_gotconfig.h"
blob - eb7818373870859025a89faa27de1391c0f08222
blob + 7e0ddba625186dea09ae82437000192bbe37b659
--- lib/repository_admin.c
+++ lib/repository_admin.c
@@ -54,7 +54,7 @@
 #include "got_lib_repository.h"
 #include "got_lib_ratelimit.h"
 #include "got_lib_pack_create.h"
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 #include "got_lib_lockfile.h"
 
 #ifndef nitems
blob - 6816ca47d643bed04b6a0dc4d49b3b910f679a40
blob + 1480d9c8e1c4a040e0916004b9a70fe808b48f4f
--- lib/send.c
+++ lib/send.c
@@ -61,7 +61,7 @@
 #include "got_lib_object_parse.h"
 #include "got_lib_object_create.h"
 #include "got_lib_pack.h"
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 #include "got_lib_privsep.h"
 #include "got_lib_object_cache.h"
 #include "got_lib_repository.h"
blob - ed7199b2a6aa7854793bd775cf8cb0140a7b7936
blob + eba5987fa2e3e7da18812041236ffef62f62f1c2
--- lib/serve.c
+++ lib/serve.c
@@ -40,7 +40,7 @@
 #include "got_lib_pkt.h"
 #include "got_lib_dial.h"
 #include "got_lib_gitproto.h"
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 #include "got_lib_poll.h"
 
 #include "gotd.h"
blob - 78088ef7e3d68c1934326f353ffd25066d280bfe (mode 644)
blob + /dev/null
--- lib/sha1.c
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#include <sys/types.h>
-#include <sha1.h>
-#include <sha2.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <limits.h>
-
-#include "got_lib_sha1.h"
-
-int
-got_parse_xdigit(uint8_t *val, const char *hex)
-{
-	char *ep;
-	long lval;
-
-	errno = 0;
-	lval = strtol(hex, &ep, 16);
-	if (hex[0] == '\0' || *ep != '\0')
-		return 0;
-	if (errno == ERANGE && (lval == LONG_MAX || lval == LONG_MIN))
-		return 0;
-
-	*val = (uint8_t)lval;
-	return 1;
-}
-
-int
-got_parse_sha1_digest(uint8_t *digest, const char *line)
-{
-	uint8_t b = 0;
-	char hex[3] = {'\0', '\0', '\0'};
-	int i, j;
-
-	for (i = 0; i < SHA1_DIGEST_LENGTH; i++) {
-		if (line[0] == '\0' || line[1] == '\0')
-			return 0;
-		for (j = 0; j < 2; j++) {
-			hex[j] = *line;
-			line++;
-		}
-		if (!got_parse_xdigit(&b, hex))
-			return 0;
-		digest[i] = b;
-	}
-
-	return 1;
-}
-
-char *
-got_sha1_digest_to_str(const uint8_t *digest, char *buf, size_t size)
-{
-	char *p = buf;
-	char hex[3];
-	int i;
-
-	if (size < SHA1_DIGEST_STRING_LENGTH)
-		return NULL;
-
-	for (i = 0; i < SHA1_DIGEST_LENGTH; i++) {
-		snprintf(hex, sizeof(hex), "%.2x", digest[i]);
-		p[0] = hex[0];
-		p[1] = hex[1];
-		p += 2;
-	}
-	p[0] = '\0';
-
-	return buf;
-}
-
-int
-got_parse_sha256_digest(uint8_t *digest, const char *line)
-{
-	uint8_t b = 0;
-	char hex[3] = {'\0', '\0', '\0'};
-	int i, j;
-
-	for (i = 0; i < SHA256_DIGEST_LENGTH; i++) {
-		if (line[0] == '\0' || line[1] == '\0')
-			return 0;
-		for (j = 0; j < 2; j++) {
-			hex[j] = *line;
-			line++;
-		}
-		if (!got_parse_xdigit(&b, hex))
-			return 0;
-		digest[i] = b;
-	}
-
-	return 1;
-}
-
-char *
-got_sha256_digest_to_str(const uint8_t *digest, char *buf, size_t size)
-{
-	char *p = buf;
-	char hex[3];
-	int i;
-
-	if (size < SHA256_DIGEST_STRING_LENGTH)
-		return NULL;
-
-	for (i = 0; i < SHA256_DIGEST_LENGTH; i++) {
-		snprintf(hex, sizeof(hex), "%.2x", digest[i]);
-		p[0] = hex[0];
-		p[1] = hex[1];
-		p += 2;
-	}
-	p[0] = '\0';
-
-	return buf;
-}
blob - 60178ad6f72c73b3c9d7c52c9ff829674de131eb
blob + 1f932f79a0cd132c97e0fae7a01a281cb9af043f
--- lib/worktree.c
+++ lib/worktree.c
@@ -47,7 +47,7 @@
 #include "got_diff.h"
 
 #include "got_lib_worktree.h"
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 #include "got_lib_fileindex.h"
 #include "got_lib_inflate.h"
 #include "got_lib_delta.h"
blob - 7158a0e8c0ec73671b1e74d1affd3176244fbe9e
blob + ae942231a4113ed60cf12a3cd075564ca02dd988
--- libexec/got-fetch-pack/Makefile
+++ libexec/got-fetch-pack/Makefile
@@ -4,7 +4,7 @@
 
 PROG=		got-fetch-pack
 SRCS=		got-fetch-pack.c error.c inflate.c object_parse.c \
-		path.c privsep.c sha1.c pkt.c gitproto.c ratelimit.c \
+		path.c privsep.c hash.c pkt.c gitproto.c ratelimit.c \
 		pollfd.c
 
 CPPFLAGS = -I${.CURDIR}/../../include -I${.CURDIR}/../../lib
blob - 22af160220d6eabc763925228e07bc312c96e16e
blob + fbc02e4caea9ef2a975ba8f5a69e128e0f676925
--- libexec/got-fetch-pack/got-fetch-pack.c
+++ libexec/got-fetch-pack/got-fetch-pack.c
@@ -43,7 +43,7 @@
 #include "got_fetch.h"
 #include "got_reference.h"
 
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 #include "got_lib_delta.h"
 #include "got_lib_object.h"
 #include "got_lib_object_parse.h"
blob - c2f4952a5ecb70a6ecdb061eef225def26c15c75
blob + 92a354326a20f1fee1023a18f5b058b069586c0a
--- libexec/got-index-pack/Makefile
+++ libexec/got-index-pack/Makefile
@@ -4,7 +4,7 @@
 
 PROG=		got-index-pack
 SRCS=		got-index-pack.c error.c inflate.c object_parse.c object_idset.c \
-		delta_cache.c delta.c pack.c path.c privsep.c sha1.c ratelimit.c \
+		delta_cache.c delta.c pack.c path.c privsep.c hash.c ratelimit.c \
 		pack_index.c pollfd.c
 
 CPPFLAGS = -I${.CURDIR}/../../include -I${.CURDIR}/../../lib
blob - 10fa486bce699c88c8487b34007e1ab262a1d1a8
blob + 23ce4ec071efb8c72e90c5c8eca304ea20056375
--- libexec/got-read-blob/Makefile
+++ libexec/got-read-blob/Makefile
@@ -4,7 +4,7 @@
 
 PROG=		got-read-blob
 SRCS=		got-read-blob.c error.c inflate.c object_parse.c \
-		path.c privsep.c sha1.c pollfd.c
+		path.c privsep.c hash.c pollfd.c
 
 CPPFLAGS = -I${.CURDIR}/../../include -I${.CURDIR}/../../lib
 
blob - dec93a8e7676ff3c05faf46924a6572bf79f53ea
blob + f13607515ea61ff5d111d7206363d56b58d23aa3
--- libexec/got-read-commit/Makefile
+++ libexec/got-read-commit/Makefile
@@ -4,7 +4,7 @@
 
 PROG=		got-read-commit
 SRCS=		got-read-commit.c error.c inflate.c object_parse.c \
-		path.c privsep.c sha1.c pollfd.c
+		path.c privsep.c hash.c pollfd.c
 
 CPPFLAGS = -I${.CURDIR}/../../include -I${.CURDIR}/../../lib
 
blob - 06fd0ccf9175b92f3f512b27d34a8a5831d48edd
blob + 0d5a81cd2be10724bfca5d40fe59053215b749e3
--- libexec/got-read-commit/got-read-commit.c
+++ libexec/got-read-commit/got-read-commit.c
@@ -39,7 +39,7 @@
 #include "got_lib_object.h"
 #include "got_lib_object_parse.h"
 #include "got_lib_privsep.h"
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 
 static volatile sig_atomic_t sigint_received;
 
blob - 25a30ce385a81305898d16ab8b87121528f7e630
blob + 5aa516cfcc8b0ad54ab77d31ee508cf18811d3e4
--- libexec/got-read-gitconfig/Makefile
+++ libexec/got-read-gitconfig/Makefile
@@ -4,7 +4,7 @@
 
 PROG=		got-read-gitconfig
 SRCS=		got-read-gitconfig.c error.c inflate.c object_parse.c \
-		path.c privsep.c sha1.c gitconfig.c pollfd.c
+		path.c privsep.c hash.c gitconfig.c pollfd.c
 
 CPPFLAGS = -I${.CURDIR}/../../include -I${.CURDIR}/../../lib
 
blob - ea559ac400e6c69dfb837d062a2dce93c449ba46
blob + 8cc878c329d0556ead75d394fec706c1b95d416e
--- libexec/got-read-gotconfig/Makefile
+++ libexec/got-read-gotconfig/Makefile
@@ -4,7 +4,7 @@
 
 PROG=		got-read-gotconfig
 SRCS=		got-read-gotconfig.c error.c inflate.c object_parse.c \
-		path.c privsep.c sha1.c parse.y pollfd.c
+		path.c privsep.c hash.c parse.y pollfd.c
 
 CPPFLAGS = -I${.CURDIR}/../../include -I${.CURDIR}/../../lib -I${.CURDIR}
 
blob - 1e6ac4a2c151ff6879da233913d87c73a8f74d31
blob + 73b38413ebe7843e58920f98b259e1505bf4b1f5
--- libexec/got-read-object/Makefile
+++ libexec/got-read-object/Makefile
@@ -4,7 +4,7 @@
 
 PROG=		got-read-object
 SRCS=		got-read-object.c error.c inflate.c object_parse.c \
-		path.c privsep.c sha1.c pollfd.c
+		path.c privsep.c hash.c pollfd.c
 
 CPPFLAGS = -I${.CURDIR}/../../include -I${.CURDIR}/../../lib
 
blob - 45455f641f9fb218d9f0b5d8509545f391463427
blob + 4396edfaac8ae4bf97e83da86f49717f922fdee0
--- libexec/got-read-object/got-read-object.c
+++ libexec/got-read-object/got-read-object.c
@@ -39,7 +39,7 @@
 #include "got_lib_object.h"
 #include "got_lib_object_parse.h"
 #include "got_lib_privsep.h"
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 
 #ifndef nitems
 #define nitems(_a) (sizeof(_a) / sizeof((_a)[0]))
blob - 2d45d0f0c9ea5186421438239984f9606128b553
blob + 23067a70e47387cb0d2dc4cbafc14e62e542a662
--- libexec/got-read-pack/Makefile
+++ libexec/got-read-pack/Makefile
@@ -5,7 +5,7 @@
 PROG=		got-read-pack
 SRCS=		got-read-pack.c delta.c error.c inflate.c object_cache.c \
 		object_idset.c object_parse.c opentemp.c pack.c path.c \
-		privsep.c sha1.c delta_cache.c pollfd.c
+		privsep.c hash.c delta_cache.c pollfd.c
 
 CPPFLAGS = -I${.CURDIR}/../../include -I${.CURDIR}/../../lib
 
blob - dbd3afa62f25910a42da355909407617dc6c1be7
blob + a9a8b307200d2da9499202b060147e7f7933d122
--- libexec/got-read-patch/Makefile
+++ libexec/got-read-patch/Makefile
@@ -4,7 +4,7 @@
 
 PROG=		got-read-patch
 SRCS=		got-read-patch.c error.c inflate.c object_parse.c \
-		path.c privsep.c sha1.c pollfd.c
+		path.c privsep.c hash.c pollfd.c
 
 CPPFLAGS = -I${.CURDIR}/../../include -I${.CURDIR}/../../lib
 
blob - e5ac12f4b2c21aec7fcbb05d9dd0b32cb70c59ba
blob + 4849e5e3e5d7c3c90f43a4b6a30f2e39b23f2820
--- libexec/got-read-patch/got-read-patch.c
+++ libexec/got-read-patch/got-read-patch.c
@@ -57,7 +57,7 @@
 #include "got_lib_delta.h"
 #include "got_lib_object.h"
 #include "got_lib_privsep.h"
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 
 struct imsgbuf ibuf;
 
blob - 54a41c2feaca0262542136fa53e0e55842246d6a
blob + e8e772933d6d6a5e5df33d1a2339dd897f353b1b
--- libexec/got-read-tag/Makefile
+++ libexec/got-read-tag/Makefile
@@ -4,7 +4,7 @@
 
 PROG=		got-read-tag
 SRCS=		got-read-tag.c error.c inflate.c object_parse.c \
-		path.c privsep.c sha1.c pollfd.c
+		path.c privsep.c hash.c pollfd.c
 
 CPPFLAGS = -I${.CURDIR}/../../include -I${.CURDIR}/../../lib
 
blob - 0eba8437b5a4386da5c346a01bf741aa1b1ecd33
blob + 9a510beab9f689e0356e77e698d30b666c6f4521
--- libexec/got-read-tag/got-read-tag.c
+++ libexec/got-read-tag/got-read-tag.c
@@ -39,7 +39,7 @@
 #include "got_lib_object.h"
 #include "got_lib_object_parse.h"
 #include "got_lib_privsep.h"
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 
 static volatile sig_atomic_t sigint_received;
 
blob - 4312c216c70d94a4b1678f9cca0fd1d41608c347
blob + 17c93154615fbf085466a3685f96d9058b259ec9
--- libexec/got-read-tree/Makefile
+++ libexec/got-read-tree/Makefile
@@ -4,7 +4,7 @@
 
 PROG=		got-read-tree
 SRCS=		got-read-tree.c error.c inflate.c object_parse.c \
-		path.c privsep.c sha1.c pollfd.c
+		path.c privsep.c hash.c pollfd.c
 
 CPPFLAGS = -I${.CURDIR}/../../include -I${.CURDIR}/../../lib
 
blob - dadab5108323c038a93c499449fdab2599dda988
blob + b8c40928c6dbf801b5730c92cd5ada9803a890d1
--- libexec/got-read-tree/got-read-tree.c
+++ libexec/got-read-tree/got-read-tree.c
@@ -40,7 +40,7 @@
 #include "got_lib_object.h"
 #include "got_lib_object_parse.h"
 #include "got_lib_privsep.h"
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 
 static volatile sig_atomic_t sigint_received;
 
blob - 07a27f7715950303cc9130d9ed1920c3bd9ec96c
blob + ab90d8b29f892ebe8290f3c9234bd433093bd865
--- libexec/got-send-pack/Makefile
+++ libexec/got-send-pack/Makefile
@@ -4,7 +4,7 @@
 
 PROG=		got-send-pack
 SRCS=		got-send-pack.c error.c inflate.c object_parse.c \
-		path.c privsep.c sha1.c pkt.c gitproto.c ratelimit.c \
+		path.c privsep.c hash.c pkt.c gitproto.c ratelimit.c \
 		pollfd.c reference_parse.c
 
 CPPFLAGS = -I${.CURDIR}/../../include -I${.CURDIR}/../../lib
blob - 15b98df355844b669a0b2b03e176d448c4389ab7
blob + baca0291979ba2ef5ff6c55f19704c125b04cfb0
--- libexec/got-send-pack/got-send-pack.c
+++ libexec/got-send-pack/got-send-pack.c
@@ -44,7 +44,7 @@
 #include "got_fetch.h"
 #include "got_reference.h"
 
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 #include "got_lib_delta.h"
 #include "got_lib_object.h"
 #include "got_lib_object_parse.h"
blob - ed3e1ede4a34e7f539a89738ca6f2d6b40947627
blob + 8a10ca7f0f192fe130ccee7c37a65976de2015cd
--- regress/delta/Makefile
+++ regress/delta/Makefile
@@ -1,7 +1,7 @@
 .PATH:${.CURDIR}/../../lib
 
 PROG = delta_test
-SRCS = delta.c error.c opentemp.c path.c inflate.c sha1.c delta_test.c pollfd.c
+SRCS = delta.c error.c opentemp.c path.c inflate.c hash.c delta_test.c pollfd.c
 
 CPPFLAGS = -I${.CURDIR}/../../include -I${.CURDIR}/../../lib
 LDADD = -lz
blob - 3685d581c00c312631e3fc1877509c48999690d4
blob + f3966cf83a031580b28e5ed8418ca3f6e0bc8285
--- regress/deltify/Makefile
+++ regress/deltify/Makefile
@@ -1,7 +1,7 @@
 .PATH:${.CURDIR}/../../lib
 
 PROG = deltify_test
-SRCS = deltify.c error.c opentemp.c sha1.c deltify_test.c murmurhash2.c
+SRCS = deltify.c error.c opentemp.c hash.c deltify_test.c murmurhash2.c
 
 CPPFLAGS = -I${.CURDIR}/../../include -I${.CURDIR}/../../lib
 LDADD = -lz
blob - 70bf4f896a17b76140e11c227248938fe1c0ac7a
blob + 4c3c7abb0a9b0de487050e9bc9149cb0d46f9749
--- regress/fetch/Makefile
+++ regress/fetch/Makefile
@@ -1,7 +1,7 @@
 .PATH:${.CURDIR}/../../lib
 
 PROG = fetch_test
-SRCS = error.c privsep.c reference.c sha1.c object.c object_parse.c path.c \
+SRCS = error.c privsep.c reference.c hash.c object.c object_parse.c path.c \
 	opentemp.c repository.c lockfile.c object_cache.c pack.c inflate.c \
 	deflate.c delta.c delta_cache.c object_idset.c object_create.c \
 	fetch.c gotconfig.c dial.c fetch_test.c bloom.c murmurhash2.c sigs.c \
blob - e4defb763447ad087297a8dbd741450eb4563f04
blob + c024c69ae8a0fd18330ae5c8f6dc6b872026966e
--- regress/fetch/fetch_test.c
+++ regress/fetch/fetch_test.c
@@ -35,7 +35,7 @@
 #include "got_dial.h"
 
 #include "got_lib_object_idset.h"
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 #include "got_lib_inflate.h"
 #include "got_lib_delta.h"
 
blob - f835e9f283dceca9d301438c5813505b06d0aa43
blob + 6b78a4717b9682af0793283e080f4458ab6a8b8e
--- regress/idset/Makefile
+++ regress/idset/Makefile
@@ -1,7 +1,7 @@
 .PATH:${.CURDIR}/../../lib
 
 PROG = idset_test
-SRCS = error.c sha1.c object_idset.c inflate.c path.c object_parse.c \
+SRCS = error.c hash.c object_idset.c inflate.c path.c object_parse.c \
 	idset_test.c pollfd.c
 
 CPPFLAGS = -I${.CURDIR}/../../include -I${.CURDIR}/../../lib
blob - 6fa68647b0f7b935511c15ee7e5ec773edc53b0b
blob + 42ee0e11ca38c06f090798d42182c197fcb40c02
--- regress/idset/idset_test.c
+++ regress/idset/idset_test.c
@@ -31,7 +31,7 @@
 #include "got_object.h"
 
 #include "got_lib_object_idset.h"
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 #include "got_lib_inflate.h"
 #include "got_lib_delta.h"
 #include "got_lib_object.h"
blob - 2ea8b5866c6983923940261d1e513e73e8ebdb41
blob + 48798edb84f6cf7908ba8c63705fb66aa2bdd23a
--- regress/path/Makefile
+++ regress/path/Makefile
@@ -1,7 +1,7 @@
 .PATH:${.CURDIR}/../../lib
 
 PROG = path_test
-SRCS = error.c path.c sha1.c path_test.c
+SRCS = error.c path.c hash.c path_test.c
 
 CPPFLAGS = -I${.CURDIR}/../../include -I${.CURDIR}/../../lib
 LDADD = -lutil -lz
blob - 426283795a3cb7ae2b87d51af958f4315f3a5f30
blob + 89e400f4320fe358711e282ef7a72ddfa0b30e80
--- tog/Makefile
+++ tog/Makefile
@@ -6,7 +6,7 @@ PROG=		tog
 SRCS=		tog.c blame.c commit_graph.c delta.c diff.c \
 		diffreg.c error.c fileindex.c object.c object_cache.c \
 		object_idset.c object_parse.c opentemp.c path.c pack.c \
-		privsep.c reference.c repository.c sha1.c worktree.c \
+		privsep.c reference.c repository.c hash.c worktree.c \
 		worktree_open.c utf8.c inflate.c buf.c rcsutil.c diff3.c \
 		lockfile.c deflate.c object_create.c delta_cache.c \
 		gotconfig.c diff_main.c diff_atomize_text.c \