Commit Diff


commit - 82f7e4c89aedcb1b224d85a6a5f2ae78b16bc943
commit + b74bd7ab16a541c7e40d2f73187e0455f5416bb2
blob - 4ddc5aac63e46a5562147f8b561c4dea76cad65c
blob + 2b4f0096cb70775318867148bcf81b8dfbdb3a6c
--- lib/got_lib_inflate.h
+++ lib/got_lib_inflate.h
@@ -21,11 +21,17 @@ struct got_inflate_checksum {
 	/* If not NULL, mix input bytes into this SHA1 context. */
 	SHA1_CTX *input_sha1;
 
+	/* If not NULL, mix input bytes into this hash context. */
+	struct got_hash *input_ctx;
+
 	/* If not NULL, mix output bytes into this CRC checksum. */
 	uint32_t *output_crc;
 
 	/* If not NULL, mix output bytes into this SHA1 context. */
 	SHA1_CTX *output_sha1;
+
+	/* If not NULL, mix output bytes into this hash context. */
+	struct got_hash *output_ctx;
 };
 
 struct got_inflate_buf {
blob - a7430b2862ad5a27a62c256b504986391d92854d
blob + adf582371c406cc4a2a79408bde3913ff792159f
--- lib/inflate.c
+++ lib/inflate.c
@@ -31,6 +31,7 @@
 #include "got_object.h"
 #include "got_path.h"
 
+#include "got_lib_hash.h"
 #include "got_lib_inflate.h"
 #include "got_lib_poll.h"
 
@@ -94,6 +95,9 @@ csum_input(struct got_inflate_checksum *csum, const ui
 
 	if (csum->input_sha1)
 		SHA1Update(csum->input_sha1, buf, len);
+
+	if (csum->input_ctx)
+		got_hash_update(csum->input_ctx, buf, len);
 }
 
 static void
@@ -104,6 +108,9 @@ csum_output(struct got_inflate_checksum *csum, const u
 
 	if (csum->output_sha1)
 		SHA1Update(csum->output_sha1, buf, len);
+
+	if (csum->output_ctx)
+		got_hash_update(csum->output_ctx, buf, len);
 }
 
 const struct got_error *
blob - 0c0ec97bfd02838440149781f11c2183bc65419f
blob + a5bc20986b8717cb89c1b8dbaf04600d65a17802
--- lib/object_parse.c
+++ lib/object_parse.c
@@ -290,8 +290,8 @@ got_object_read_raw(uint8_t **outbuf, off_t *size, siz
 	const struct got_error *err = NULL;
 	struct got_object *obj;
 	struct got_inflate_checksum csum;
-	uint8_t sha1[SHA1_DIGEST_LENGTH];
-	SHA1_CTX sha1_ctx;
+	uint8_t hash[GOT_OBJECT_ID_MAXLEN];
+	struct got_hash ctx;
 	size_t len, consumed;
 	FILE *f = NULL;
 
@@ -299,9 +299,9 @@ got_object_read_raw(uint8_t **outbuf, off_t *size, siz
 	*size = 0;
 	*hdrlen = 0;
 
-	SHA1Init(&sha1_ctx);
+	got_hash_init(&ctx, GOT_HASH_SHA1);
 	memset(&csum, 0, sizeof(csum));
-	csum.output_sha1 = &sha1_ctx;
+	csum.output_ctx = &ctx;
 
 	if (lseek(infd, SEEK_SET, 0) == -1)
 		return got_error_from_errno("lseek");
@@ -342,8 +342,8 @@ got_object_read_raw(uint8_t **outbuf, off_t *size, siz
 		goto done;
 	}
 
-	SHA1Final(sha1, &sha1_ctx);
-	if (memcmp(expected_id->sha1, sha1, SHA1_DIGEST_LENGTH) != 0) {
+	got_hash_final(&ctx, hash);
+	if (got_hash_cmp(&ctx, expected_id->sha1, hash) != 0) {
 		err = got_error_checksum(expected_id);
 		goto done;
 	}
@@ -753,18 +753,18 @@ got_object_read_commit(struct got_commit_object **comm
 	size_t len;
 	uint8_t *p;
 	struct got_inflate_checksum csum;
-	SHA1_CTX sha1_ctx;
+	struct got_hash ctx;
 	struct got_object_id id;
 
-	SHA1Init(&sha1_ctx);
+	got_hash_init(&ctx, GOT_HASH_SHA1);
 	memset(&csum, 0, sizeof(csum));
-	csum.output_sha1 = &sha1_ctx;
+	csum.output_ctx = &ctx;
 
 	err = got_inflate_to_mem_fd(&p, &len, NULL, &csum, expected_size, fd);
 	if (err)
 		return err;
 
-	SHA1Final(id.sha1, &sha1_ctx);
+	got_hash_final(&ctx, id.sha1);
 	if (got_object_id_cmp(expected_id, &id) != 0) {
 		err = got_error_checksum(expected_id);
 		goto done;
@@ -922,18 +922,18 @@ got_object_read_tree(struct got_parsed_tree_entry **en
 	struct got_object *obj = NULL;
 	size_t len;
 	struct got_inflate_checksum csum;
-	SHA1_CTX sha1_ctx;
+	struct got_hash ctx;
 	struct got_object_id id;
 
-	SHA1Init(&sha1_ctx);
+	got_hash_init(&ctx, GOT_HASH_SHA1);
 	memset(&csum, 0, sizeof(csum));
-	csum.output_sha1 = &sha1_ctx;
+	csum.output_ctx = &ctx;
 
 	err = got_inflate_to_mem_fd(p, &len, NULL, &csum, 0, fd);
 	if (err)
 		return err;
 
-	SHA1Final(id.sha1, &sha1_ctx);
+	got_hash_final(&ctx, id.sha1);
 	if (got_object_id_cmp(expected_id, &id) != 0) {
 		err = got_error_checksum(expected_id);
 		goto done;
@@ -1164,19 +1164,19 @@ got_object_read_tag(struct got_tag_object **tag, int f
 	size_t len;
 	uint8_t *p;
 	struct got_inflate_checksum csum;
-	SHA1_CTX sha1_ctx;
+	struct got_hash ctx;
 	struct got_object_id id;
 
-	SHA1Init(&sha1_ctx);
+	got_hash_init(&ctx, GOT_HASH_SHA1);
 	memset(&csum, 0, sizeof(csum));
-	csum.output_sha1 = &sha1_ctx;
+	csum.output_ctx = &ctx;
 
 	err = got_inflate_to_mem_fd(&p, &len, NULL, &csum,
 	    expected_size, fd);
 	if (err)
 		return err;
 
-	SHA1Final(id.sha1, &sha1_ctx);
+	got_hash_final(&ctx, id.sha1);
 	if (got_object_id_cmp(expected_id, &id) != 0) {
 		err = got_error_checksum(expected_id);
 		goto done;
blob - ed8291ef577fe09d4957c03653a00c031b0cb0dd
blob + 3c3632addec15ad4cda044f1a67ebddc26480865
--- libexec/got-read-blob/got-read-blob.c
+++ libexec/got-read-blob/got-read-blob.c
@@ -35,6 +35,7 @@
 #include "got_object.h"
 
 #include "got_lib_delta.h"
+#include "got_lib_hash.h"
 #include "got_lib_inflate.h"
 #include "got_lib_object.h"
 #include "got_lib_object_parse.h"
@@ -77,11 +78,11 @@ main(int argc, char *argv[])
 		struct got_object_id id;
 		struct got_object_id expected_id;
 		struct got_inflate_checksum csum;
-		SHA1_CTX sha1_ctx;
+		struct got_hash ctx;
 
-		SHA1Init(&sha1_ctx);
+		got_hash_init(&ctx, GOT_HASH_SHA1);
 		memset(&csum, 0, sizeof(csum));
-		csum.output_sha1 = &sha1_ctx;
+		csum.output_ctx = &ctx;
 
 		memset(&imsg, 0, sizeof(imsg));
 		imsg.fd = -1;
@@ -170,7 +171,7 @@ main(int argc, char *argv[])
 			if (err)
 				goto done;
 		}
-		SHA1Final(id.sha1, &sha1_ctx);
+		got_hash_final(&ctx, id.sha1);
 		if (got_object_id_cmp(&expected_id, &id) != 0) {
 			err = got_error_checksum(&expected_id);
 			goto done;