Commit 8832172e9b73bc4edf938fbac6db850eef436699

Patrick Steinhardt 2019-02-22T14:32:40

hash: move SHA1 implementations to its own hashing context Create a separate `git_hash_sha1_ctx` structure that is specific to the SHA1 implementation and move all SHA1 functions over to use that one instead of the generic `git_hash_ctx`. The `git_hash_ctx` for now simply has a union containing this single SHA1 implementation, only, without any mechanism to distinguish between different algortihms.

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
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
diff --git a/src/hash.c b/src/hash.c
index a3cb1c4..7d9a41a 100644
--- a/src/hash.c
+++ b/src/hash.c
@@ -14,27 +14,27 @@ int git_hash_global_init(void)
 
 int git_hash_ctx_init(git_hash_ctx *ctx)
 {
-	return git_hash_sha1_ctx_init(ctx);
+	return git_hash_sha1_ctx_init(&ctx->sha1);
 }
 
 void git_hash_ctx_cleanup(git_hash_ctx *ctx)
 {
-	git_hash_sha1_ctx_cleanup(ctx);
+	git_hash_sha1_ctx_cleanup(&ctx->sha1);
 }
 
-int git_hash_init(git_hash_ctx *c)
+int git_hash_init(git_hash_ctx *ctx)
 {
-	return git_hash_sha1_init(c);
+	return git_hash_sha1_init(&ctx->sha1);
 }
 
-int git_hash_update(git_hash_ctx *c, const void *data, size_t len)
+int git_hash_update(git_hash_ctx *ctx, const void *data, size_t len)
 {
-	return git_hash_sha1_update(c, data, len);
+	return git_hash_sha1_update(&ctx->sha1, data, len);
 }
 
-int git_hash_final(git_oid *out, git_hash_ctx *c)
+int git_hash_final(git_oid *out, git_hash_ctx *ctx)
 {
-	return git_hash_sha1_final(out, c);
+	return git_hash_sha1_final(out, &ctx->sha1);
 }
 
 int git_hash_buf(git_oid *out, const void *data, size_t len)
diff --git a/src/hash.h b/src/hash.h
index ddd0ea2..18fb5d6 100644
--- a/src/hash.h
+++ b/src/hash.h
@@ -12,8 +12,6 @@
 
 #include "git2/oid.h"
 
-typedef struct git_hash_ctx git_hash_ctx;
-
 typedef struct {
 	void *data;
 	size_t len;
@@ -21,6 +19,12 @@ typedef struct {
 
 #include "hash/sha1.h"
 
+typedef struct git_hash_ctx {
+	union {
+		git_hash_sha1_ctx sha1;
+	};
+} git_hash_ctx;
+
 int git_hash_global_init(void);
 
 int git_hash_ctx_init(git_hash_ctx *ctx);
diff --git a/src/hash/sha1.h b/src/hash/sha1.h
index 38a4464..fb8d62f 100644
--- a/src/hash/sha1.h
+++ b/src/hash/sha1.h
@@ -10,6 +10,8 @@
 
 #include "common.h"
 
+typedef struct git_hash_sha1_ctx git_hash_sha1_ctx;
+
 #if defined(GIT_SHA1_COLLISIONDETECT)
 # include "sha1/collisiondetect.h"
 #elif defined(GIT_SHA1_COMMON_CRYPTO)
@@ -26,11 +28,11 @@
 
 int git_hash_sha1_global_init(void);
 
-int git_hash_sha1_ctx_init(git_hash_ctx *ctx);
-void git_hash_sha1_ctx_cleanup(git_hash_ctx *ctx);
+int git_hash_sha1_ctx_init(git_hash_sha1_ctx *ctx);
+void git_hash_sha1_ctx_cleanup(git_hash_sha1_ctx *ctx);
 
-int git_hash_sha1_init(git_hash_ctx *c);
-int git_hash_sha1_update(git_hash_ctx *c, const void *data, size_t len);
-int git_hash_sha1_final(git_oid *out, git_hash_ctx *c);
+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);
 
 #endif
diff --git a/src/hash/sha1/collisiondetect.c b/src/hash/sha1/collisiondetect.c
index e0c3db6..e6a1267 100644
--- a/src/hash/sha1/collisiondetect.c
+++ b/src/hash/sha1/collisiondetect.c
@@ -12,31 +12,31 @@ int git_hash_sha1_global_init(void)
 	return 0;
 }
 
-int git_hash_sha1_ctx_init(git_hash_ctx *ctx)
+int git_hash_sha1_ctx_init(git_hash_sha1_ctx *ctx)
 {
 	return git_hash_sha1_init(ctx);
 }
 
-void git_hash_sha1_ctx_cleanup(git_hash_ctx *ctx)
+void git_hash_sha1_ctx_cleanup(git_hash_sha1_ctx *ctx)
 {
 	GIT_UNUSED(ctx);
 }
 
-int git_hash_sha1_init(git_hash_ctx *ctx)
+int git_hash_sha1_init(git_hash_sha1_ctx *ctx)
 {
 	assert(ctx);
 	SHA1DCInit(&ctx->c);
 	return 0;
 }
 
-int git_hash_sha1_update(git_hash_ctx *ctx, const void *data, size_t len)
+int git_hash_sha1_update(git_hash_sha1_ctx *ctx, const void *data, size_t len)
 {
 	assert(ctx);
 	SHA1DCUpdate(&ctx->c, data, len);
 	return 0;
 }
 
-int git_hash_sha1_final(git_oid *out, git_hash_ctx *ctx)
+int git_hash_sha1_final(git_oid *out, git_hash_sha1_ctx *ctx)
 {
 	assert(ctx);
 	if (SHA1DCFinal(out->id, &ctx->c)) {
diff --git a/src/hash/sha1/collisiondetect.h b/src/hash/sha1/collisiondetect.h
index 3dc30fe..eb88e86 100644
--- a/src/hash/sha1/collisiondetect.h
+++ b/src/hash/sha1/collisiondetect.h
@@ -8,11 +8,11 @@
 #ifndef INCLUDE_hash_sha1_collisiondetect_h__
 #define INCLUDE_hash_sha1_collisiondetect_h__
 
-#include "hash.h"
+#include "hash/sha1.h"
 
 #include "sha1dc/sha1.h"
 
-struct git_hash_ctx {
+struct git_hash_sha1_ctx {
 	SHA1_CTX c;
 };
 
diff --git a/src/hash/sha1/common_crypto.c b/src/hash/sha1/common_crypto.c
index 3539fd0..0449a3c 100644
--- a/src/hash/sha1/common_crypto.c
+++ b/src/hash/sha1/common_crypto.c
@@ -14,24 +14,24 @@ int git_hash_sha1_global_init(void)
 	return 0;
 }
 
-int git_hash_sha1_ctx_init(git_hash_ctx *ctx)
+int git_hash_sha1_ctx_init(git_hash_sha1_ctx *ctx)
 {
 	return git_hash_sha1_init(ctx);
 }
 
-void git_hash_sha1_ctx_cleanup(git_hash_ctx *ctx)
+void git_hash_sha1_ctx_cleanup(git_hash_sha1_ctx *ctx)
 {
 	GIT_UNUSED(ctx);
 }
 
-int git_hash_sha1_init(git_hash_ctx *ctx)
+int git_hash_sha1_init(git_hash_sha1_ctx *ctx)
 {
 	assert(ctx);
 	CC_SHA1_Init(&ctx->c);
 	return 0;
 }
 
-int git_hash_sha1_update(git_hash_ctx *ctx, const void *_data, size_t len)
+int git_hash_sha1_update(git_hash_sha1_ctx *ctx, const void *_data, size_t len)
 {
 	const unsigned char *data = _data;
 
@@ -49,7 +49,7 @@ int git_hash_sha1_update(git_hash_ctx *ctx, const void *_data, size_t len)
 	return 0;
 }
 
-int git_hash_sha1_final(git_oid *out, git_hash_ctx *ctx)
+int git_hash_sha1_final(git_oid *out, git_hash_sha1_ctx *ctx)
 {
 	assert(ctx);
 	CC_SHA1_Final(out->id, &ctx->c);
diff --git a/src/hash/sha1/common_crypto.h b/src/hash/sha1/common_crypto.h
index 3be8828..a5fcfb3 100644
--- a/src/hash/sha1/common_crypto.h
+++ b/src/hash/sha1/common_crypto.h
@@ -8,11 +8,11 @@
 #ifndef INCLUDE_hash_sha1_common_crypto_h__
 #define INCLUDE_hash_sha1_common_crypto_h__
 
-#include "hash.h"
+#include "hash/sha1.h"
 
 #include <CommonCrypto/CommonDigest.h>
 
-struct git_hash_ctx {
+struct git_hash_sha1_ctx {
 	CC_SHA1_CTX c;
 };
 
diff --git a/src/hash/sha1/generic.c b/src/hash/sha1/generic.c
index a5a9f4c..607fe3a 100644
--- a/src/hash/sha1/generic.c
+++ b/src/hash/sha1/generic.c
@@ -111,7 +111,7 @@
 #define T_40_59(t, A, B, C, D, E) SHA_ROUND(t, SHA_MIX, ((B&C)+(D&(B^C))) , 0x8f1bbcdc, A, B, C, D, E )
 #define T_60_79(t, A, B, C, D, E) SHA_ROUND(t, SHA_MIX, (B^C^D) , 0xca62c1d6, A, B, C, D, E )
 
-static void hash__block(git_hash_ctx *ctx, const unsigned int *data)
+static void hash__block(git_hash_sha1_ctx *ctx, const unsigned int *data)
 {
 	unsigned int A,B,C,D,E;
 	unsigned int array[16];
@@ -224,17 +224,17 @@ int git_hash_sha1_global_init(void)
 	return 0;
 }
 
-int git_hash_sha1_ctx_init(git_hash_ctx *ctx)
+int git_hash_sha1_ctx_init(git_hash_sha1_ctx *ctx)
 {
 	return git_hash_sha1_init(ctx);
 }
 
-void git_hash_sha1_ctx_cleanup(git_hash_ctx *ctx)
+void git_hash_sha1_ctx_cleanup(git_hash_sha1_ctx *ctx)
 {
 	GIT_UNUSED(ctx);
 }
 
-int git_hash_sha1_init(git_hash_ctx *ctx)
+int git_hash_sha1_init(git_hash_sha1_ctx *ctx)
 {
 	ctx->size = 0;
 
@@ -248,7 +248,7 @@ int git_hash_sha1_init(git_hash_ctx *ctx)
 	return 0;
 }
 
-int git_hash_sha1_update(git_hash_ctx *ctx, const void *data, size_t len)
+int git_hash_sha1_update(git_hash_sha1_ctx *ctx, const void *data, size_t len)
 {
 	unsigned int lenW = ctx->size & 63;
 
@@ -278,7 +278,7 @@ int git_hash_sha1_update(git_hash_ctx *ctx, const void *data, size_t len)
 	return 0;
 }
 
-int git_hash_sha1_final(git_oid *out, git_hash_ctx *ctx)
+int git_hash_sha1_final(git_oid *out, git_hash_sha1_ctx *ctx)
 {
 	static const unsigned char pad[64] = { 0x80 };
 	unsigned int padlen[2];
@@ -289,8 +289,8 @@ int git_hash_sha1_final(git_oid *out, git_hash_ctx *ctx)
 	padlen[1] = htonl((uint32_t)(ctx->size << 3));
 
 	i = ctx->size & 63;
-	git_hash_update(ctx, pad, 1+ (63 & (55 - i)));
-	git_hash_update(ctx, padlen, 8);
+	git_hash_sha1_update(ctx, pad, 1+ (63 & (55 - i)));
+	git_hash_sha1_update(ctx, padlen, 8);
 
 	/* Output hash */
 	for (i = 0; i < 5; i++)
diff --git a/src/hash/sha1/generic.h b/src/hash/sha1/generic.h
index 041b9ef..e4cc602 100644
--- a/src/hash/sha1/generic.h
+++ b/src/hash/sha1/generic.h
@@ -8,9 +8,9 @@
 #ifndef INCLUDE_hash_sha1_generic_h__
 #define INCLUDE_hash_sha1_generic_h__
 
-#include "hash.h"
+#include "hash/sha1.h"
 
-struct git_hash_ctx {
+struct git_hash_sha1_ctx {
 	unsigned long long size;
 	unsigned int H[5];
 	unsigned int W[16];
diff --git a/src/hash/sha1/mbedtls.c b/src/hash/sha1/mbedtls.c
index 8ebf940..e44343f 100644
--- a/src/hash/sha1/mbedtls.c
+++ b/src/hash/sha1/mbedtls.c
@@ -12,18 +12,18 @@ int git_hash_sha1_global_init(void)
 	return 0;
 }
 
-int git_hash_sha1_ctx_init(git_hash_ctx *ctx)
+int git_hash_sha1_ctx_init(git_hash_sha1_ctx *ctx)
 {
 	return git_hash_sha1_init(ctx);
 }
 
-void git_hash_sha1_ctx_cleanup(git_hash_ctx *ctx)
+void git_hash_sha1_ctx_cleanup(git_hash_sha1_ctx *ctx)
 {
     assert(ctx);
     mbedtls_sha1_free(&ctx->c);
 }
 
-int git_hash_sha1_init(git_hash_ctx *ctx)
+int git_hash_sha1_init(git_hash_sha1_ctx *ctx)
 {
     assert(ctx);
     mbedtls_sha1_init(&ctx->c);
@@ -31,14 +31,14 @@ int git_hash_sha1_init(git_hash_ctx *ctx)
     return 0;
 }
 
-int git_hash_sha1_update(git_hash_ctx *ctx, const void *data, size_t len)
+int git_hash_sha1_update(git_hash_sha1_ctx *ctx, const void *data, size_t len)
 {
     assert(ctx);
     mbedtls_sha1_update(&ctx->c, data, len);
     return 0;
 }
 
-int git_hash_sha1_final(git_oid *out, git_hash_ctx *ctx)
+int git_hash_sha1_final(git_oid *out, git_hash_sha1_ctx *ctx)
 {
     assert(ctx);
     mbedtls_sha1_finish(&ctx->c, out->id);
diff --git a/src/hash/sha1/mbedtls.h b/src/hash/sha1/mbedtls.h
index d066cbd..15f7462 100644
--- a/src/hash/sha1/mbedtls.h
+++ b/src/hash/sha1/mbedtls.h
@@ -8,11 +8,11 @@
 #ifndef INCLUDE_hash_sha1_mbedtls_h__
 #define INCLUDE_hash_sha1_mbedtls_h__
 
-#include "hash.h"
+#include "hash/sha1.h"
 
 #include <mbedtls/sha1.h>
 
-struct git_hash_ctx {
+struct git_hash_sha1_ctx {
     mbedtls_sha1_context c;
 };
 
diff --git a/src/hash/sha1/openssl.c b/src/hash/sha1/openssl.c
index d93cd8b..ba3212f 100644
--- a/src/hash/sha1/openssl.c
+++ b/src/hash/sha1/openssl.c
@@ -12,17 +12,17 @@ int git_hash_sha1_global_init(void)
 	return 0;
 }
 
-int git_hash_sha1_ctx_init(git_hash_ctx *ctx)
+int git_hash_sha1_ctx_init(git_hash_sha1_ctx *ctx)
 {
 	return git_hash_sha1_init(ctx);
 }
 
-void git_hash_sha1_ctx_cleanup(git_hash_ctx *ctx)
+void git_hash_sha1_ctx_cleanup(git_hash_sha1_ctx *ctx)
 {
 	GIT_UNUSED(ctx);
 }
 
-int git_hash_sha1_init(git_hash_ctx *ctx)
+int git_hash_sha1_init(git_hash_sha1_ctx *ctx)
 {
 	assert(ctx);
 
@@ -34,7 +34,7 @@ int git_hash_sha1_init(git_hash_ctx *ctx)
 	return 0;
 }
 
-int git_hash_sha1_update(git_hash_ctx *ctx, const void *data, size_t len)
+int git_hash_sha1_update(git_hash_sha1_ctx *ctx, const void *data, size_t len)
 {
 	assert(ctx);
 
@@ -46,7 +46,7 @@ int git_hash_sha1_update(git_hash_ctx *ctx, const void *data, size_t len)
 	return 0;
 }
 
-int git_hash_sha1_final(git_oid *out, git_hash_ctx *ctx)
+int git_hash_sha1_final(git_oid *out, git_hash_sha1_ctx *ctx)
 {
 	assert(ctx);
 
diff --git a/src/hash/sha1/openssl.h b/src/hash/sha1/openssl.h
index f2ec581..a223ca0 100644
--- a/src/hash/sha1/openssl.h
+++ b/src/hash/sha1/openssl.h
@@ -8,13 +8,11 @@
 #ifndef INCLUDE_hash_sha1_openssl_h__
 #define INCLUDE_hash_sha1_openssl_h__
 
-#include "common.h"
-
-#include "hash.h"
+#include "hash/sha1.h"
 
 #include <openssl/sha.h>
 
-struct git_hash_ctx {
+struct git_hash_sha1_ctx {
 	SHA_CTX c;
 };
 
diff --git a/src/hash/sha1/win32.c b/src/hash/sha1/win32.c
index 8814ac3..1b944e2 100644
--- a/src/hash/sha1/win32.c
+++ b/src/hash/sha1/win32.c
@@ -136,7 +136,7 @@ int git_hash_sha1_global_init(void)
 
 /* CryptoAPI: available in Windows XP and newer */
 
-GIT_INLINE(int) hash_ctx_cryptoapi_init(git_hash_ctx *ctx)
+GIT_INLINE(int) hash_ctx_cryptoapi_init(git_hash_sha1_ctx *ctx)
 {
 	ctx->type = CRYPTOAPI;
 	ctx->prov = &hash_prov;
@@ -144,7 +144,7 @@ GIT_INLINE(int) hash_ctx_cryptoapi_init(git_hash_ctx *ctx)
 	return git_hash_sha1_init(ctx);
 }
 
-GIT_INLINE(int) hash_cryptoapi_init(git_hash_ctx *ctx)
+GIT_INLINE(int) hash_cryptoapi_init(git_hash_sha1_ctx *ctx)
 {
 	if (ctx->ctx.cryptoapi.valid)
 		CryptDestroyHash(ctx->ctx.cryptoapi.hash_handle);
@@ -159,7 +159,7 @@ GIT_INLINE(int) hash_cryptoapi_init(git_hash_ctx *ctx)
 	return 0;
 }
 
-GIT_INLINE(int) hash_cryptoapi_update(git_hash_ctx *ctx, const void *_data, size_t len)
+GIT_INLINE(int) hash_cryptoapi_update(git_hash_sha1_ctx *ctx, const void *_data, size_t len)
 {
 	const BYTE *data = (BYTE *)_data;
 
@@ -180,7 +180,7 @@ GIT_INLINE(int) hash_cryptoapi_update(git_hash_ctx *ctx, const void *_data, size
 	return 0;
 }
 
-GIT_INLINE(int) hash_cryptoapi_final(git_oid *out, git_hash_ctx *ctx)
+GIT_INLINE(int) hash_cryptoapi_final(git_oid *out, git_hash_sha1_ctx *ctx)
 {
 	DWORD len = 20;
 	int error = 0;
@@ -198,7 +198,7 @@ GIT_INLINE(int) hash_cryptoapi_final(git_oid *out, git_hash_ctx *ctx)
 	return error;
 }
 
-GIT_INLINE(void) hash_ctx_cryptoapi_cleanup(git_hash_ctx *ctx)
+GIT_INLINE(void) hash_ctx_cryptoapi_cleanup(git_hash_sha1_ctx *ctx)
 {
 	if (ctx->ctx.cryptoapi.valid)
 		CryptDestroyHash(ctx->ctx.cryptoapi.hash_handle);
@@ -206,7 +206,7 @@ GIT_INLINE(void) hash_ctx_cryptoapi_cleanup(git_hash_ctx *ctx)
 
 /* CNG: Available in Windows Server 2008 and newer */
 
-GIT_INLINE(int) hash_ctx_cng_init(git_hash_ctx *ctx)
+GIT_INLINE(int) hash_ctx_cng_init(git_hash_sha1_ctx *ctx)
 {
 	if ((ctx->ctx.cng.hash_object = git__malloc(hash_prov.prov.cng.hash_object_size)) == NULL)
 		return -1;
@@ -224,7 +224,7 @@ GIT_INLINE(int) hash_ctx_cng_init(git_hash_ctx *ctx)
 	return 0;
 }
 
-GIT_INLINE(int) hash_cng_init(git_hash_ctx *ctx)
+GIT_INLINE(int) hash_cng_init(git_hash_sha1_ctx *ctx)
 {
 	BYTE hash[GIT_OID_RAWSZ];
 
@@ -242,7 +242,7 @@ GIT_INLINE(int) hash_cng_init(git_hash_ctx *ctx)
 	return 0;
 }
 
-GIT_INLINE(int) hash_cng_update(git_hash_ctx *ctx, const void *_data, size_t len)
+GIT_INLINE(int) hash_cng_update(git_hash_sha1_ctx *ctx, const void *_data, size_t len)
 {
 	PBYTE data = (PBYTE)_data;
 
@@ -261,7 +261,7 @@ GIT_INLINE(int) hash_cng_update(git_hash_ctx *ctx, const void *_data, size_t len
 	return 0;
 }
 
-GIT_INLINE(int) hash_cng_final(git_oid *out, git_hash_ctx *ctx)
+GIT_INLINE(int) hash_cng_final(git_oid *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) {
 		git_error_set(GIT_ERROR_OS, "hash could not be finished");
@@ -273,7 +273,7 @@ GIT_INLINE(int) hash_cng_final(git_oid *out, git_hash_ctx *ctx)
 	return 0;
 }
 
-GIT_INLINE(void) hash_ctx_cng_cleanup(git_hash_ctx *ctx)
+GIT_INLINE(void) hash_ctx_cng_cleanup(git_hash_sha1_ctx *ctx)
 {
 	ctx->prov->prov.cng.destroy_hash(ctx->ctx.cng.hash_handle);
 	git__free(ctx->ctx.cng.hash_object);
@@ -281,7 +281,7 @@ GIT_INLINE(void) hash_ctx_cng_cleanup(git_hash_ctx *ctx)
 
 /* Indirection between CryptoAPI and CNG */
 
-int git_hash_sha1_ctx_init(git_hash_ctx *ctx)
+int git_hash_sha1_ctx_init(git_hash_sha1_ctx *ctx)
 {
 	int error = 0;
 
@@ -295,30 +295,30 @@ int git_hash_sha1_ctx_init(git_hash_ctx *ctx)
 	if (hash_prov.type == INVALID && (error = git_hash_sha1_global_init()) < 0)
 		return error;
 
-	memset(ctx, 0x0, sizeof(git_hash_ctx));
+	memset(ctx, 0x0, sizeof(git_hash_sha1_ctx));
 
 	return (hash_prov.type == CNG) ? hash_ctx_cng_init(ctx) : hash_ctx_cryptoapi_init(ctx);
 }
 
-int git_hash_sha1_init(git_hash_ctx *ctx)
+int git_hash_sha1_init(git_hash_sha1_ctx *ctx)
 {
 	assert(ctx && ctx->type);
 	return (ctx->type == CNG) ? hash_cng_init(ctx) : hash_cryptoapi_init(ctx);
 }
 
-int git_hash_sha1_update(git_hash_ctx *ctx, const void *data, size_t len)
+int git_hash_sha1_update(git_hash_sha1_ctx *ctx, const void *data, size_t len)
 {
 	assert(ctx && ctx->type);
 	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_ctx *ctx)
+int git_hash_sha1_final(git_oid *out, git_hash_sha1_ctx *ctx)
 {
 	assert(ctx && ctx->type);
 	return (ctx->type == CNG) ? hash_cng_final(out, ctx) : hash_cryptoapi_final(out, ctx);
 }
 
-void git_hash_sha1_ctx_cleanup(git_hash_ctx *ctx)
+void git_hash_sha1_ctx_cleanup(git_hash_sha1_ctx *ctx)
 {
 	assert(ctx);
 
diff --git a/src/hash/sha1/win32.h b/src/hash/sha1/win32.h
index e4970ce..791d20a 100644
--- a/src/hash/sha1/win32.h
+++ b/src/hash/sha1/win32.h
@@ -5,12 +5,10 @@
  * a Linking Exception. For full terms see the included COPYING file.
  */
 
-#ifndef INCLUDE_hash_hash_win32_h__
-#define INCLUDE_hash_hash_win32_h__
+#ifndef INCLUDE_hash_sha1_win32_h__
+#define INCLUDE_hash_sha1_win32_h__
 
-#include "common.h"
-
-#include "hash.h"
+#include "hash/sha1.h"
 
 #include <wincrypt.h>
 #include <strsafe.h>
@@ -117,7 +115,7 @@ struct hash_cng_ctx {
 	PBYTE hash_object;
 };
 
-struct git_hash_ctx {
+struct git_hash_sha1_ctx {
 	enum hash_win32_prov_type type;
 	git_hash_prov *prov;