Commit 31ecaca2d3e87d20782a54cb319f5c19e6c6e62f

Edward Thomson 2021-09-30T08:11:40

hash: hash functions operate on byte arrays not git_oids Separate the concerns of the hash functions from the git_oid functions. The git_oid structure will need to understand either SHA1 or SHA256; the hash functions should only deal with the appropriate one of these.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
diff --git a/src/commit_graph.c b/src/commit_graph.c
index 8bb2397..df760b5 100644
--- a/src/commit_graph.c
+++ b/src/commit_graph.c
@@ -230,7 +230,7 @@ int git_commit_graph_file_parse(
 		return commit_graph_error("wrong commit-graph size");
 	git_oid_cpy(&file->checksum, (git_oid *)(data + trailer_offset));
 
-	if (git_hash_buf(&cgraph_checksum, data, (size_t)trailer_offset, GIT_HASH_ALGORITHM_SHA1) < 0)
+	if (git_hash_buf(cgraph_checksum.id, data, (size_t)trailer_offset, GIT_HASH_ALGORITHM_SHA1) < 0)
 		return commit_graph_error("could not calculate signature");
 	if (!git_oid_equal(&cgraph_checksum, &file->checksum))
 		return commit_graph_error("index signature mismatch");
@@ -1132,7 +1132,7 @@ static int commit_graph_write(
 		goto cleanup;
 
 	/* Finalize the checksum and write the trailer. */
-	error = git_hash_final(&cgraph_checksum, &ctx);
+	error = git_hash_final(cgraph_checksum.id, &ctx);
 	if (error < 0)
 		goto cleanup;
 	error = write_cb((const char *)&cgraph_checksum, sizeof(cgraph_checksum), cb_data);
diff --git a/src/config_file.c b/src/config_file.c
index e1adb2c..2f83a40 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -144,7 +144,7 @@ static int config_file_is_modified(int *modified, config_file *file)
 	if ((error = git_futils_readbuffer(&buf, file->path)) < 0)
 		goto out;
 
-	if ((error = git_hash_buf(&hash, buf.ptr, buf.size, GIT_HASH_ALGORITHM_SHA1)) < 0)
+	if ((error = git_hash_buf(hash.id, buf.ptr, buf.size, GIT_HASH_ALGORITHM_SHA1)) < 0)
 		goto out;
 
 	if (!git_oid_equal(&hash, &file->checksum)) {
@@ -869,7 +869,7 @@ static int config_file_read(
 		goto out;
 
 	git_futils_filestamp_set_from_stat(&file->stamp, &st);
-	if ((error = git_hash_buf(&file->checksum, contents.ptr, contents.size, GIT_HASH_ALGORITHM_SHA1)) < 0)
+	if ((error = git_hash_buf(file->checksum.id, contents.ptr, contents.size, GIT_HASH_ALGORITHM_SHA1)) < 0)
 		goto out;
 
 	if ((error = config_file_read_buffer(entries, repo, file, level, depth,
diff --git a/src/diff.c b/src/diff.c
index 4434d37..44b67ee 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -269,7 +269,7 @@ static int flush_hunk(git_oid *result, git_hash_ctx *ctx)
 	unsigned short carry = 0;
 	int error, i;
 
-	if ((error = git_hash_final(&hash, ctx)) < 0 ||
+	if ((error = git_hash_final(hash.id, ctx)) < 0 ||
 	    (error = git_hash_init(ctx)) < 0)
 		return error;
 
diff --git a/src/filebuf.c b/src/filebuf.c
index 40cd9a4..4296b22 100644
--- a/src/filebuf.c
+++ b/src/filebuf.c
@@ -397,7 +397,7 @@ int git_filebuf_hash(git_oid *oid, git_filebuf *file)
 	if (verify_last_error(file) < 0)
 		return -1;
 
-	git_hash_final(oid, &file->digest);
+	git_hash_final(oid->id, &file->digest);
 	git_hash_ctx_cleanup(&file->digest);
 	file->compute_digest = 0;
 
diff --git a/src/futils.c b/src/futils.c
index 5d120ea..138fc2c 100644
--- a/src/futils.c
+++ b/src/futils.c
@@ -216,7 +216,7 @@ int git_futils_readbuffer_updated(
 	p_close(fd);
 
 	if (checksum) {
-		if ((error = git_hash_buf(&checksum_new, buf.ptr, buf.size, GIT_HASH_ALGORITHM_SHA1)) < 0) {
+		if ((error = git_hash_buf(checksum_new.id, buf.ptr, buf.size, GIT_HASH_ALGORITHM_SHA1)) < 0) {
 			git_buf_dispose(&buf);
 			return error;
 		}
diff --git a/src/hash.c b/src/hash.c
index 2f11a88..222eadf 100644
--- a/src/hash.c
+++ b/src/hash.c
@@ -66,7 +66,7 @@ int git_hash_update(git_hash_ctx *ctx, const void *data, size_t len)
 	return -1;
 }
 
-int git_hash_final(git_oid *out, git_hash_ctx *ctx)
+int git_hash_final(unsigned char *out, git_hash_ctx *ctx)
 {
 	switch (ctx->algorithm) {
 	case GIT_HASH_ALGORITHM_SHA1:
@@ -80,7 +80,7 @@ int git_hash_final(git_oid *out, git_hash_ctx *ctx)
 }
 
 int git_hash_buf(
-	git_oid *out,
+	unsigned char *out,
 	const void *data,
 	size_t len,
 	git_hash_algorithm_t algorithm)
@@ -100,7 +100,7 @@ int git_hash_buf(
 }
 
 int git_hash_vec(
-	git_oid *out,
+	unsigned char *out,
 	git_buf_vec *vec,
 	size_t n,
 	git_hash_algorithm_t algorithm)
diff --git a/src/hash.h b/src/hash.h
index 7938e3b..ec91fa4 100644
--- a/src/hash.h
+++ b/src/hash.h
@@ -11,6 +11,7 @@
 #include "common.h"
 
 #include "git2/oid.h"
+#include "hash/sha1.h"
 
 typedef struct {
 	void *data;
@@ -22,8 +23,6 @@ typedef enum {
 	GIT_HASH_ALGORITHM_SHA1
 } git_hash_algorithm_t;
 
-#include "hash/sha1.h"
-
 typedef struct git_hash_ctx {
 	union {
 		git_hash_sha1_ctx sha1;
@@ -38,9 +37,9 @@ void git_hash_ctx_cleanup(git_hash_ctx *ctx);
 
 int git_hash_init(git_hash_ctx *c);
 int git_hash_update(git_hash_ctx *c, const void *data, size_t len);
-int git_hash_final(git_oid *out, git_hash_ctx *c);
+int git_hash_final(unsigned char *out, git_hash_ctx *c);
 
-int git_hash_buf(git_oid *out, const void *data, size_t len, git_hash_algorithm_t algorithm);
-int git_hash_vec(git_oid *out, git_buf_vec *vec, size_t n, git_hash_algorithm_t algorithm);
+int git_hash_buf(unsigned char *out, const void *data, size_t len, git_hash_algorithm_t algorithm);
+int git_hash_vec(unsigned char *out, git_buf_vec *vec, size_t n, git_hash_algorithm_t algorithm);
 
 #endif
diff --git a/src/hash/sha1.h b/src/hash/sha1.h
index fb8d62f..4b4dae3 100644
--- a/src/hash/sha1.h
+++ b/src/hash/sha1.h
@@ -26,6 +26,8 @@ typedef struct git_hash_sha1_ctx git_hash_sha1_ctx;
 # include "sha1/generic.h"
 #endif
 
+#define GIT_HASH_SHA1_SIZE 20
+
 int git_hash_sha1_global_init(void);
 
 int git_hash_sha1_ctx_init(git_hash_sha1_ctx *ctx);
@@ -33,6 +35,6 @@ void git_hash_sha1_ctx_cleanup(git_hash_sha1_ctx *ctx);
 
 int git_hash_sha1_init(git_hash_sha1_ctx *c);
 int git_hash_sha1_update(git_hash_sha1_ctx *c, const void *data, size_t len);
-int git_hash_sha1_final(git_oid *out, git_hash_sha1_ctx *c);
+int git_hash_sha1_final(unsigned char *out, git_hash_sha1_ctx *c);
 
 #endif
diff --git a/src/hash/sha1/collisiondetect.c b/src/hash/sha1/collisiondetect.c
index 722ebf3..ec7059c 100644
--- a/src/hash/sha1/collisiondetect.c
+++ b/src/hash/sha1/collisiondetect.c
@@ -36,10 +36,10 @@ int git_hash_sha1_update(git_hash_sha1_ctx *ctx, const void *data, size_t len)
 	return 0;
 }
 
-int git_hash_sha1_final(git_oid *out, git_hash_sha1_ctx *ctx)
+int git_hash_sha1_final(unsigned char *out, git_hash_sha1_ctx *ctx)
 {
 	GIT_ASSERT_ARG(ctx);
-	if (SHA1DCFinal(out->id, &ctx->c)) {
+	if (SHA1DCFinal(out, &ctx->c)) {
 		git_error_set(GIT_ERROR_SHA1, "SHA1 collision attack detected");
 		return -1;
 	}
diff --git a/src/hash/sha1/common_crypto.c b/src/hash/sha1/common_crypto.c
index 4250e0b..9d608f4 100644
--- a/src/hash/sha1/common_crypto.c
+++ b/src/hash/sha1/common_crypto.c
@@ -49,9 +49,9 @@ int git_hash_sha1_update(git_hash_sha1_ctx *ctx, const void *_data, size_t len)
 	return 0;
 }
 
-int git_hash_sha1_final(git_oid *out, git_hash_sha1_ctx *ctx)
+int git_hash_sha1_final(unsigned char *out, git_hash_sha1_ctx *ctx)
 {
 	GIT_ASSERT_ARG(ctx);
-	CC_SHA1_Final(out->id, &ctx->c);
+	CC_SHA1_Final(out, &ctx->c);
 	return 0;
 }
diff --git a/src/hash/sha1/generic.c b/src/hash/sha1/generic.c
index 607fe3a..85b34c5 100644
--- a/src/hash/sha1/generic.c
+++ b/src/hash/sha1/generic.c
@@ -278,7 +278,7 @@ int git_hash_sha1_update(git_hash_sha1_ctx *ctx, const void *data, size_t len)
 	return 0;
 }
 
-int git_hash_sha1_final(git_oid *out, git_hash_sha1_ctx *ctx)
+int git_hash_sha1_final(unsigned char *out, git_hash_sha1_ctx *ctx)
 {
 	static const unsigned char pad[64] = { 0x80 };
 	unsigned int padlen[2];
@@ -294,7 +294,7 @@ int git_hash_sha1_final(git_oid *out, git_hash_sha1_ctx *ctx)
 
 	/* Output hash */
 	for (i = 0; i < 5; i++)
-		put_be32(out->id + i*4, ctx->H[i]);
+		put_be32(out + i*4, ctx->H[i]);
 
 	return 0;
 }
diff --git a/src/hash/sha1/mbedtls.c b/src/hash/sha1/mbedtls.c
index 04e7da5..56016be 100644
--- a/src/hash/sha1/mbedtls.c
+++ b/src/hash/sha1/mbedtls.c
@@ -38,9 +38,9 @@ int git_hash_sha1_update(git_hash_sha1_ctx *ctx, const void *data, size_t len)
 	return 0;
 }
 
-int git_hash_sha1_final(git_oid *out, git_hash_sha1_ctx *ctx)
+int git_hash_sha1_final(unsigned char *out, git_hash_sha1_ctx *ctx)
 {
 	GIT_ASSERT_ARG(ctx);
-	mbedtls_sha1_finish(&ctx->c, out->id);
+	mbedtls_sha1_finish(&ctx->c, out);
 	return 0;
 }
diff --git a/src/hash/sha1/openssl.c b/src/hash/sha1/openssl.c
index 68d9611..64bf99b 100644
--- a/src/hash/sha1/openssl.c
+++ b/src/hash/sha1/openssl.c
@@ -46,11 +46,11 @@ int git_hash_sha1_update(git_hash_sha1_ctx *ctx, const void *data, size_t len)
 	return 0;
 }
 
-int git_hash_sha1_final(git_oid *out, git_hash_sha1_ctx *ctx)
+int git_hash_sha1_final(unsigned char *out, git_hash_sha1_ctx *ctx)
 {
 	GIT_ASSERT_ARG(ctx);
 
-	if (SHA1_Final(out->id, &ctx->c) != 1) {
+	if (SHA1_Final(out, &ctx->c) != 1) {
 		git_error_set(GIT_ERROR_SHA1, "hash_openssl: failed to finalize hash");
 		return -1;
 	}
diff --git a/src/hash/sha1/win32.c b/src/hash/sha1/win32.c
index a6e7061..b89dfba 100644
--- a/src/hash/sha1/win32.c
+++ b/src/hash/sha1/win32.c
@@ -181,14 +181,14 @@ GIT_INLINE(int) hash_cryptoapi_update(git_hash_sha1_ctx *ctx, const void *_data,
 	return 0;
 }
 
-GIT_INLINE(int) hash_cryptoapi_final(git_oid *out, git_hash_sha1_ctx *ctx)
+GIT_INLINE(int) hash_cryptoapi_final(unsigned char *out, git_hash_sha1_ctx *ctx)
 {
-	DWORD len = 20;
+	DWORD len = GIT_HASH_SHA1_SIZE;
 	int error = 0;
 
 	GIT_ASSERT(ctx->ctx.cryptoapi.valid);
 
-	if (!CryptGetHashParam(ctx->ctx.cryptoapi.hash_handle, HP_HASHVAL, out->id, &len, 0)) {
+	if (!CryptGetHashParam(ctx->ctx.cryptoapi.hash_handle, HP_HASHVAL, out, &len, 0)) {
 		git_error_set(GIT_ERROR_OS, "legacy hash data could not be finished");
 		error = -1;
 	}
@@ -262,9 +262,9 @@ GIT_INLINE(int) hash_cng_update(git_hash_sha1_ctx *ctx, const void *_data, size_
 	return 0;
 }
 
-GIT_INLINE(int) hash_cng_final(git_oid *out, git_hash_sha1_ctx *ctx)
+GIT_INLINE(int) hash_cng_final(unsigned char *out, git_hash_sha1_ctx *ctx)
 {
-	if (ctx->prov->prov.cng.finish_hash(ctx->ctx.cng.hash_handle, out->id, GIT_OID_RAWSZ, 0) < 0) {
+	if (ctx->prov->prov.cng.finish_hash(ctx->ctx.cng.hash_handle, out, GIT_HASH_SHA1_SIZE, 0) < 0) {
 		git_error_set(GIT_ERROR_OS, "hash could not be finished");
 		return -1;
 	}
@@ -315,7 +315,7 @@ int git_hash_sha1_update(git_hash_sha1_ctx *ctx, const void *data, size_t len)
 	return (ctx->type == CNG) ? hash_cng_update(ctx, data, len) : hash_cryptoapi_update(ctx, data, len);
 }
 
-int git_hash_sha1_final(git_oid *out, git_hash_sha1_ctx *ctx)
+int git_hash_sha1_final(unsigned char *out, git_hash_sha1_ctx *ctx)
 {
 	GIT_ASSERT_ARG(ctx);
 	GIT_ASSERT_ARG(ctx->type);
diff --git a/src/index.c b/src/index.c
index 838f43c..2e24fff 100644
--- a/src/index.c
+++ b/src/index.c
@@ -2648,7 +2648,7 @@ static int parse_index(git_index *index, const char *buffer, size_t buffer_size)
 
 	/* Precalculate the SHA1 of the files's contents -- we'll match it to
 	 * the provided SHA1 in the footer */
-	git_hash_buf(&checksum_calculated, buffer, buffer_size - INDEX_FOOTER_SIZE, GIT_HASH_ALGORITHM_SHA1);
+	git_hash_buf(checksum_calculated.id, buffer, buffer_size - INDEX_FOOTER_SIZE, GIT_HASH_ALGORITHM_SHA1);
 
 	/* Parse header */
 	if ((error = read_header(&header, buffer)) < 0)
diff --git a/src/indexer.c b/src/indexer.c
index c3b1aee..16ed7bf 100644
--- a/src/indexer.c
+++ b/src/indexer.c
@@ -426,7 +426,7 @@ static int store_object(git_indexer *idx)
 	pentry = git__calloc(1, sizeof(struct git_pack_entry));
 	GIT_ERROR_CHECK_ALLOC(pentry);
 
-	if (git_hash_final(&oid, &idx->hash_ctx)) {
+	if (git_hash_final(oid.id, &idx->hash_ctx)) {
 		git__free(pentry);
 		goto on_error;
 	}
@@ -1183,7 +1183,7 @@ int git_indexer_commit(git_indexer *idx, git_indexer_progress *stats)
 	git_oid_fromraw(&file_hash, packfile_trailer);
 	git_mwindow_close(&w);
 
-	git_hash_final(&trailer_hash, &idx->trailer);
+	git_hash_final(trailer_hash.id, &idx->trailer);
 	if (git_oid_cmp(&file_hash, &trailer_hash)) {
 		git_error_set(GIT_ERROR_INDEXER, "packfile trailer mismatch");
 		return -1;
@@ -1204,7 +1204,7 @@ int git_indexer_commit(git_indexer *idx, git_indexer_progress *stats)
 		if (update_header_and_rehash(idx, stats) < 0)
 			return -1;
 
-		git_hash_final(&trailer_hash, &idx->trailer);
+		git_hash_final(trailer_hash.id, &idx->trailer);
 		write_at(idx, &trailer_hash, idx->pack->mwf.size - GIT_OID_RAWSZ, GIT_OID_RAWSZ);
 	}
 
diff --git a/src/midx.c b/src/midx.c
index 7ef8524..cd3c98c 100644
--- a/src/midx.c
+++ b/src/midx.c
@@ -212,7 +212,7 @@ int git_midx_parse(
 		return midx_error("wrong index size");
 	git_oid_cpy(&idx->checksum, (git_oid *)(data + trailer_offset));
 
-	if (git_hash_buf(&idx_checksum, data, (size_t)trailer_offset, GIT_HASH_ALGORITHM_SHA1) < 0)
+	if (git_hash_buf(idx_checksum.id, data, (size_t)trailer_offset, GIT_HASH_ALGORITHM_SHA1) < 0)
 		return midx_error("could not calculate signature");
 	if (!git_oid_equal(&idx_checksum, &idx->checksum))
 		return midx_error("index signature mismatch");
@@ -819,7 +819,7 @@ static int midx_write(
 		goto cleanup;
 
 	/* Finalize the checksum and write the trailer. */
-	error = git_hash_final(&idx_checksum, &ctx);
+	error = git_hash_final(idx_checksum.id, &ctx);
 	if (error < 0)
 		goto cleanup;
 	error = write_cb((const char *)&idx_checksum, sizeof(idx_checksum), cb_data);
diff --git a/src/odb.c b/src/odb.c
index c247808..baa2873 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -136,7 +136,7 @@ int git_odb__hashobj(git_oid *id, git_rawobj *obj)
 	vec[1].data = obj->data;
 	vec[1].len = obj->len;
 
-	return git_hash_vec(id, vec, 2, GIT_HASH_ALGORITHM_SHA1);
+	return git_hash_vec(id->id, vec, 2, GIT_HASH_ALGORITHM_SHA1);
 }
 
 
@@ -237,7 +237,7 @@ int git_odb__hashfd(git_oid *out, git_file fd, size_t size, git_object_t type)
 		goto done;
 	}
 
-	error = git_hash_final(out, &ctx);
+	error = git_hash_final(out->id, &ctx);
 
 done:
 	git_hash_ctx_cleanup(&ctx);
@@ -1607,7 +1607,7 @@ int git_odb_stream_finalize_write(git_oid *out, git_odb_stream *stream)
 		return git_odb_stream__invalid_length(stream,
 			"stream_finalize_write()");
 
-	git_hash_final(out, stream->hash_ctx);
+	git_hash_final(out->id, stream->hash_ctx);
 
 	if (git_odb__freshen(stream->backend->odb, out))
 		return 0;
diff --git a/src/pack-objects.c b/src/pack-objects.c
index 560f57d..d89a4e7 100644
--- a/src/pack-objects.c
+++ b/src/pack-objects.c
@@ -664,7 +664,7 @@ static int write_pack(git_packbuilder *pb,
 		pb->nr_remaining -= pb->nr_written;
 	} while (pb->nr_remaining && i < pb->nr_objects);
 
-	if ((error = git_hash_final(&entry_oid, &pb->ctx)) < 0)
+	if ((error = git_hash_final(entry_oid.id, &pb->ctx)) < 0)
 		goto done;
 
 	error = write_cb(entry_oid.id, GIT_OID_RAWSZ, cb_data);
diff --git a/tests/core/sha1.c b/tests/core/sha1.c
index aa35193..92582d6 100644
--- a/tests/core/sha1.c
+++ b/tests/core/sha1.c
@@ -13,7 +13,7 @@ void test_core_sha1__cleanup(void)
 	cl_fixture_cleanup(FIXTURE_DIR);
 }
 
-static int sha1_file(git_oid *oid, const char *filename)
+static int sha1_file(git_oid *out, const char *filename)
 {
 	git_hash_ctx ctx;
 	char buf[2048];
@@ -31,7 +31,7 @@ static int sha1_file(git_oid *oid, const char *filename)
 	cl_assert_equal_i(0, read_len);
 	p_close(fd);
 
-	ret = git_hash_final(oid, &ctx);
+	ret = git_hash_final(out->id, &ctx);
 	git_hash_ctx_cleanup(&ctx);
 
 	return ret;
diff --git a/tests/object/raw/hash.c b/tests/object/raw/hash.c
index e9a6476..3be1f83 100644
--- a/tests/object/raw/hash.c
+++ b/tests/object/raw/hash.c
@@ -30,14 +30,14 @@ void test_object_raw_hash__hash_by_blocks(void)
 
 	/* should already be init'd */
 	cl_git_pass(git_hash_update(&ctx, hello_text, strlen(hello_text)));
-	cl_git_pass(git_hash_final(&id2, &ctx));
+	cl_git_pass(git_hash_final(id2.id, &ctx));
 	cl_git_pass(git_oid_fromstr(&id1, hello_id));
 	cl_assert(git_oid_cmp(&id1, &id2) == 0);
 
 	/* reinit should permit reuse */
 	cl_git_pass(git_hash_init(&ctx));
 	cl_git_pass(git_hash_update(&ctx, bye_text, strlen(bye_text)));
-	cl_git_pass(git_hash_final(&id2, &ctx));
+	cl_git_pass(git_hash_final(id2.id, &ctx));
 	cl_git_pass(git_oid_fromstr(&id1, bye_id));
 	cl_assert(git_oid_cmp(&id1, &id2) == 0);
 
@@ -49,7 +49,7 @@ void test_object_raw_hash__hash_buffer_in_single_call(void)
 	git_oid id1, id2;
 
 	cl_git_pass(git_oid_fromstr(&id1, hello_id));
-	git_hash_buf(&id2, hello_text, strlen(hello_text), GIT_HASH_ALGORITHM_SHA1);
+	git_hash_buf(id2.id, hello_text, strlen(hello_text), GIT_HASH_ALGORITHM_SHA1);
 	cl_assert(git_oid_cmp(&id1, &id2) == 0);
 }
 
@@ -65,7 +65,7 @@ void test_object_raw_hash__hash_vector(void)
 	vec[1].data = hello_text+4;
 	vec[1].len  = strlen(hello_text)-4;
 
-	git_hash_vec(&id2, vec, 2, GIT_HASH_ALGORITHM_SHA1);
+	git_hash_vec(id2.id, vec, 2, GIT_HASH_ALGORITHM_SHA1);
 
 	cl_assert(git_oid_cmp(&id1, &id2) == 0);
 }
diff --git a/tests/object/raw/short.c b/tests/object/raw/short.c
index 626c965..e8d2cf5 100644
--- a/tests/object/raw/short.c
+++ b/tests/object/raw/short.c
@@ -33,7 +33,7 @@ static int insert_sequential_oids(
 
 	for (i = 0; i < n; ++i) {
 		p_snprintf(numbuf, sizeof(numbuf), "%u", (unsigned int)i);
-		git_hash_buf(&oid, numbuf, strlen(numbuf), GIT_HASH_ALGORITHM_SHA1);
+		git_hash_buf(oid.id, numbuf, strlen(numbuf), GIT_HASH_ALGORITHM_SHA1);
 
 		oids[i] = git__malloc(GIT_OID_HEXSZ + 1);
 		cl_assert(oids[i]);
diff --git a/tests/odb/largefiles.c b/tests/odb/largefiles.c
index 03b183c..ff82291 100644
--- a/tests/odb/largefiles.c
+++ b/tests/odb/largefiles.c
@@ -119,7 +119,7 @@ void test_odb_largefiles__streamread(void)
 
 	cl_assert_equal_sz(LARGEFILE_SIZE, total);
 
-	git_hash_final(&read_oid, &hash);
+	git_hash_final(read_oid.id, &hash);
 
 	cl_assert_equal_oid(&oid, &read_oid);
 
diff --git a/tests/pack/packbuilder.c b/tests/pack/packbuilder.c
index 42d446a..5d93ede 100644
--- a/tests/pack/packbuilder.c
+++ b/tests/pack/packbuilder.c
@@ -128,7 +128,7 @@ void test_pack_packbuilder__create_pack(void)
 
 	cl_git_pass(git_hash_ctx_init(&ctx, GIT_HASH_ALGORITHM_SHA1));
 	cl_git_pass(git_hash_update(&ctx, buf.ptr, buf.size));
-	cl_git_pass(git_hash_final(&hash, &ctx));
+	cl_git_pass(git_hash_final(hash.id, &ctx));
 	git_hash_ctx_cleanup(&ctx);
 
 	git_buf_dispose(&path);