From: "brian m. carlson" <sandals@crustytoothpaste.net>
To: git@vger.kernel.org
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>,
"Patryk Obara" <patryk.obara@gmail.com>,
"Jeff King" <peff@peff.net>,
"Eric Sunshine" <sunshine@sunshineco.com>
Subject: [PATCH v2 07/12] pack-check: convert various uses of SHA-1 to abstract forms
Date: Thu, 1 Feb 2018 02:18:43 +0000 [thread overview]
Message-ID: <20180201021848.533188-8-sandals@crustytoothpaste.net> (raw)
In-Reply-To: <20180201021848.533188-1-sandals@crustytoothpaste.net>
Convert various explicit calls to use SHA-1 functions and constants to
references to the_hash_algo. Make several strings more generic with
respect to the hash algorithm used.
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
pack-check.c | 32 ++++++++++++++++----------------
1 file changed, 16 insertions(+), 16 deletions(-)
diff --git a/pack-check.c b/pack-check.c
index 073c1fbd46..403a572567 100644
--- a/pack-check.c
+++ b/pack-check.c
@@ -41,7 +41,7 @@ int check_pack_crc(struct packed_git *p, struct pack_window **w_curs,
} while (len);
index_crc = p->index_data;
- index_crc += 2 + 256 + p->num_objects * (20/4) + nr;
+ index_crc += 2 + 256 + p->num_objects * (the_hash_algo->rawsz/4) + nr;
return data_crc != ntohl(*index_crc);
}
@@ -54,7 +54,7 @@ static int verify_packfile(struct packed_git *p,
{
off_t index_size = p->index_size;
const unsigned char *index_base = p->index_data;
- git_SHA_CTX ctx;
+ git_hash_ctx ctx;
unsigned char hash[GIT_MAX_RAWSZ], *pack_sig;
off_t offset = 0, pack_sig_ofs = 0;
uint32_t nr_objects, i;
@@ -64,24 +64,24 @@ static int verify_packfile(struct packed_git *p,
if (!is_pack_valid(p))
return error("packfile %s cannot be accessed", p->pack_name);
- git_SHA1_Init(&ctx);
+ the_hash_algo->init_fn(&ctx);
do {
unsigned long remaining;
unsigned char *in = use_pack(p, w_curs, offset, &remaining);
offset += remaining;
if (!pack_sig_ofs)
- pack_sig_ofs = p->pack_size - 20;
+ pack_sig_ofs = p->pack_size - the_hash_algo->rawsz;
if (offset > pack_sig_ofs)
remaining -= (unsigned int)(offset - pack_sig_ofs);
- git_SHA1_Update(&ctx, in, remaining);
+ the_hash_algo->update_fn(&ctx, in, remaining);
} while (offset < pack_sig_ofs);
- git_SHA1_Final(hash, &ctx);
+ the_hash_algo->final_fn(hash, &ctx);
pack_sig = use_pack(p, w_curs, pack_sig_ofs, NULL);
if (hashcmp(hash, pack_sig))
- err = error("%s SHA1 checksum mismatch",
+ err = error("%s pack checksum mismatch",
p->pack_name);
- if (hashcmp(index_base + index_size - 40, pack_sig))
- err = error("%s SHA1 does not match its index",
+ if (hashcmp(index_base + index_size - the_hash_algo->hexsz, pack_sig))
+ err = error("%s pack checksum does not match its index",
p->pack_name);
unuse_pack(w_curs);
@@ -165,8 +165,8 @@ int verify_pack_index(struct packed_git *p)
{
off_t index_size;
const unsigned char *index_base;
- git_SHA_CTX ctx;
- unsigned char sha1[20];
+ git_hash_ctx ctx;
+ unsigned char hash[GIT_MAX_RAWSZ];
int err = 0;
if (open_pack_index(p))
@@ -175,11 +175,11 @@ int verify_pack_index(struct packed_git *p)
index_base = p->index_data;
/* Verify SHA1 sum of the index file */
- git_SHA1_Init(&ctx);
- git_SHA1_Update(&ctx, index_base, (unsigned int)(index_size - 20));
- git_SHA1_Final(sha1, &ctx);
- if (hashcmp(sha1, index_base + index_size - 20))
- err = error("Packfile index for %s SHA1 mismatch",
+ the_hash_algo->init_fn(&ctx);
+ the_hash_algo->update_fn(&ctx, index_base, (unsigned int)(index_size - the_hash_algo->rawsz));
+ the_hash_algo->final_fn(hash, &ctx);
+ if (hashcmp(hash, index_base + index_size - the_hash_algo->rawsz))
+ err = error("Packfile index for %s hash mismatch",
p->pack_name);
return err;
}
next prev parent reply other threads:[~2018-02-01 2:19 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-01 2:18 [PATCH v2 00/12] object_id part 11 (the_hash_algo) brian m. carlson
2018-02-01 2:18 ` [PATCH v2 01/12] hash: move SHA-1 macros to hash.h brian m. carlson
2018-02-02 19:39 ` Junio C Hamano
2018-02-01 2:18 ` [PATCH v2 02/12] hash: create union for hash context allocation brian m. carlson
2018-02-01 2:18 ` [PATCH v2 03/12] builtin/index-pack: improve hash function abstraction brian m. carlson
2018-02-01 2:18 ` [PATCH v2 04/12] builtin/unpack-objects: switch uses of SHA-1 to the_hash_algo brian m. carlson
2018-02-01 2:18 ` [PATCH v2 05/12] sha1_file: " brian m. carlson
2018-02-01 2:18 ` [PATCH v2 06/12] fast-import: switch various " brian m. carlson
2018-02-01 2:18 ` brian m. carlson [this message]
2018-02-01 2:18 ` [PATCH v2 08/12] pack-write: switch various SHA-1 values to abstract forms brian m. carlson
2018-02-01 2:18 ` [PATCH v2 09/12] read-cache: abstract away uses of SHA-1 brian m. carlson
2018-02-01 2:18 ` [PATCH v2 10/12] csum-file: rename sha1file to hashfile brian m. carlson
2018-02-01 2:18 ` [PATCH v2 11/12] csum-file: abstract uses of SHA-1 brian m. carlson
2018-02-01 2:18 ` [PATCH v2 12/12] bulk-checkin: abstract SHA-1 usage brian m. carlson
2018-02-01 22:06 ` [PATCH v2 00/12] object_id part 11 (the_hash_algo) Stefan Beller
2018-02-02 19:46 ` Junio C Hamano
2018-02-06 0:34 ` brian m. carlson
2018-02-06 14:52 ` Junio C Hamano
2018-02-08 2:48 ` [PATCH v2] hash: update obsolete reference to SHA1_HEADER brian m. carlson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180201021848.533188-8-sandals@crustytoothpaste.net \
--to=sandals@crustytoothpaste.net \
--cc=git@vger.kernel.org \
--cc=patryk.obara@gmail.com \
--cc=pclouds@gmail.com \
--cc=peff@peff.net \
--cc=sunshine@sunshineco.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).