@@ -41,7 +41,7 @@ int check_pack_crc(struct packed_git *p, struct pack_window **w_curs,
41
41
} while (len );
42
42
43
43
index_crc = p -> index_data ;
44
- index_crc += 2 + 256 + p -> num_objects * (20 /4 ) + nr ;
44
+ index_crc += 2 + 256 + p -> num_objects * (the_hash_algo -> rawsz /4 ) + nr ;
45
45
46
46
return data_crc != ntohl (* index_crc );
47
47
}
@@ -54,7 +54,7 @@ static int verify_packfile(struct packed_git *p,
54
54
{
55
55
off_t index_size = p -> index_size ;
56
56
const unsigned char * index_base = p -> index_data ;
57
- git_SHA_CTX ctx ;
57
+ git_hash_ctx ctx ;
58
58
unsigned char hash [GIT_MAX_RAWSZ ], * pack_sig ;
59
59
off_t offset = 0 , pack_sig_ofs = 0 ;
60
60
uint32_t nr_objects , i ;
@@ -64,24 +64,24 @@ static int verify_packfile(struct packed_git *p,
64
64
if (!is_pack_valid (p ))
65
65
return error ("packfile %s cannot be accessed" , p -> pack_name );
66
66
67
- git_SHA1_Init (& ctx );
67
+ the_hash_algo -> init_fn (& ctx );
68
68
do {
69
69
unsigned long remaining ;
70
70
unsigned char * in = use_pack (p , w_curs , offset , & remaining );
71
71
offset += remaining ;
72
72
if (!pack_sig_ofs )
73
- pack_sig_ofs = p -> pack_size - 20 ;
73
+ pack_sig_ofs = p -> pack_size - the_hash_algo -> rawsz ;
74
74
if (offset > pack_sig_ofs )
75
75
remaining -= (unsigned int )(offset - pack_sig_ofs );
76
- git_SHA1_Update (& ctx , in , remaining );
76
+ the_hash_algo -> update_fn (& ctx , in , remaining );
77
77
} while (offset < pack_sig_ofs );
78
- git_SHA1_Final (hash , & ctx );
78
+ the_hash_algo -> final_fn (hash , & ctx );
79
79
pack_sig = use_pack (p , w_curs , pack_sig_ofs , NULL );
80
80
if (hashcmp (hash , pack_sig ))
81
- err = error ("%s SHA1 checksum mismatch" ,
81
+ err = error ("%s pack checksum mismatch" ,
82
82
p -> pack_name );
83
- if (hashcmp (index_base + index_size - 40 , pack_sig ))
84
- err = error ("%s SHA1 does not match its index" ,
83
+ if (hashcmp (index_base + index_size - the_hash_algo -> hexsz , pack_sig ))
84
+ err = error ("%s pack checksum does not match its index" ,
85
85
p -> pack_name );
86
86
unuse_pack (w_curs );
87
87
@@ -165,8 +165,8 @@ int verify_pack_index(struct packed_git *p)
165
165
{
166
166
off_t index_size ;
167
167
const unsigned char * index_base ;
168
- git_SHA_CTX ctx ;
169
- unsigned char sha1 [ 20 ];
168
+ git_hash_ctx ctx ;
169
+ unsigned char hash [ GIT_MAX_RAWSZ ];
170
170
int err = 0 ;
171
171
172
172
if (open_pack_index (p ))
@@ -175,11 +175,11 @@ int verify_pack_index(struct packed_git *p)
175
175
index_base = p -> index_data ;
176
176
177
177
/* Verify SHA1 sum of the index file */
178
- git_SHA1_Init (& ctx );
179
- git_SHA1_Update (& ctx , index_base , (unsigned int )(index_size - 20 ));
180
- git_SHA1_Final ( sha1 , & ctx );
181
- if (hashcmp (sha1 , index_base + index_size - 20 ))
182
- err = error ("Packfile index for %s SHA1 mismatch" ,
178
+ the_hash_algo -> init_fn (& ctx );
179
+ the_hash_algo -> update_fn (& ctx , index_base , (unsigned int )(index_size - the_hash_algo -> rawsz ));
180
+ the_hash_algo -> final_fn ( hash , & ctx );
181
+ if (hashcmp (hash , index_base + index_size - the_hash_algo -> rawsz ))
182
+ err = error ("Packfile index for %s hash mismatch" ,
183
183
p -> pack_name );
184
184
return err ;
185
185
}
0 commit comments