hash: split into generic and SHA1-specific interface As a preparatory step to allow multiple hashing APIs to exist at the same time, split the hashing functions into one layer for generic hashing and one layer for SHA1-specific hashing. Right now, this is simply an additional indirection layer that doesn't yet serve any purpose. In the future, the generic API will be extended to allow for choosing which hash to use, though, by simply passing an enum to the hash context initialization function. This is necessary as a first step to be ready for Git's move to SHA256.
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
diff --git a/src/hash.c b/src/hash.c
index cc6676d..a3cb1c4 100644
--- a/src/hash.c
+++ b/src/hash.c
@@ -7,6 +7,36 @@
#include "hash.h"
+int git_hash_global_init(void)
+{
+ return git_hash_sha1_global_init();
+}
+
+int git_hash_ctx_init(git_hash_ctx *ctx)
+{
+ return git_hash_sha1_ctx_init(ctx);
+}
+
+void git_hash_ctx_cleanup(git_hash_ctx *ctx)
+{
+ git_hash_sha1_ctx_cleanup(ctx);
+}
+
+int git_hash_init(git_hash_ctx *c)
+{
+ return git_hash_sha1_init(c);
+}
+
+int git_hash_update(git_hash_ctx *c, const void *data, size_t len)
+{
+ return git_hash_sha1_update(c, data, len);
+}
+
+int git_hash_final(git_oid *out, git_hash_ctx *c)
+{
+ return git_hash_sha1_final(out, c);
+}
+
int git_hash_buf(git_oid *out, const void *data, size_t len)
{
git_hash_ctx ctx;
diff --git a/src/hash/sha1.h b/src/hash/sha1.h
index db0e5c1..38a4464 100644
--- a/src/hash/sha1.h
+++ b/src/hash/sha1.h
@@ -24,4 +24,13 @@
# include "sha1/generic.h"
#endif
+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_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);
+
#endif
diff --git a/src/hash/sha1/collisiondetect.c b/src/hash/sha1/collisiondetect.c
index 79ec4e5..e0c3db6 100644
--- a/src/hash/sha1/collisiondetect.c
+++ b/src/hash/sha1/collisiondetect.c
@@ -7,36 +7,36 @@
#include "collisiondetect.h"
-int git_hash_global_init(void)
+int git_hash_sha1_global_init(void)
{
return 0;
}
-int git_hash_ctx_init(git_hash_ctx *ctx)
+int git_hash_sha1_ctx_init(git_hash_ctx *ctx)
{
- return git_hash_init(ctx);
+ return git_hash_sha1_init(ctx);
}
-void git_hash_ctx_cleanup(git_hash_ctx *ctx)
+void git_hash_sha1_ctx_cleanup(git_hash_ctx *ctx)
{
GIT_UNUSED(ctx);
}
-int git_hash_init(git_hash_ctx *ctx)
+int git_hash_sha1_init(git_hash_ctx *ctx)
{
assert(ctx);
SHA1DCInit(&ctx->c);
return 0;
}
-int git_hash_update(git_hash_ctx *ctx, const void *data, size_t len)
+int git_hash_sha1_update(git_hash_ctx *ctx, const void *data, size_t len)
{
assert(ctx);
SHA1DCUpdate(&ctx->c, data, len);
return 0;
}
-int git_hash_final(git_oid *out, git_hash_ctx *ctx)
+int git_hash_sha1_final(git_oid *out, git_hash_ctx *ctx)
{
assert(ctx);
if (SHA1DCFinal(out->id, &ctx->c)) {
diff --git a/src/hash/sha1/common_crypto.c b/src/hash/sha1/common_crypto.c
index 2fa5218..3539fd0 100644
--- a/src/hash/sha1/common_crypto.c
+++ b/src/hash/sha1/common_crypto.c
@@ -9,29 +9,29 @@
#define CC_LONG_MAX ((CC_LONG)-1)
-int git_hash_global_init(void)
+int git_hash_sha1_global_init(void)
{
return 0;
}
-int git_hash_ctx_init(git_hash_ctx *ctx)
+int git_hash_sha1_ctx_init(git_hash_ctx *ctx)
{
- return git_hash_init(ctx);
+ return git_hash_sha1_init(ctx);
}
-void git_hash_ctx_cleanup(git_hash_ctx *ctx)
+void git_hash_sha1_ctx_cleanup(git_hash_ctx *ctx)
{
GIT_UNUSED(ctx);
}
-int git_hash_init(git_hash_ctx *ctx)
+int git_hash_sha1_init(git_hash_ctx *ctx)
{
assert(ctx);
CC_SHA1_Init(&ctx->c);
return 0;
}
-int git_hash_update(git_hash_ctx *ctx, const void *_data, size_t len)
+int git_hash_sha1_update(git_hash_ctx *ctx, const void *_data, size_t len)
{
const unsigned char *data = _data;
@@ -49,7 +49,7 @@ int git_hash_update(git_hash_ctx *ctx, const void *_data, size_t len)
return 0;
}
-int git_hash_final(git_oid *out, git_hash_ctx *ctx)
+int git_hash_sha1_final(git_oid *out, git_hash_ctx *ctx)
{
assert(ctx);
CC_SHA1_Final(out->id, &ctx->c);
diff --git a/src/hash/sha1/generic.c b/src/hash/sha1/generic.c
index 157b918..a5a9f4c 100644
--- a/src/hash/sha1/generic.c
+++ b/src/hash/sha1/generic.c
@@ -219,22 +219,22 @@ static void hash__block(git_hash_ctx *ctx, const unsigned int *data)
ctx->H[4] += E;
}
-int git_hash_global_init(void)
+int git_hash_sha1_global_init(void)
{
return 0;
}
-int git_hash_ctx_init(git_hash_ctx *ctx)
+int git_hash_sha1_ctx_init(git_hash_ctx *ctx)
{
- return git_hash_init(ctx);
+ return git_hash_sha1_init(ctx);
}
-void git_hash_ctx_cleanup(git_hash_ctx *ctx)
+void git_hash_sha1_ctx_cleanup(git_hash_ctx *ctx)
{
GIT_UNUSED(ctx);
}
-int git_hash_init(git_hash_ctx *ctx)
+int git_hash_sha1_init(git_hash_ctx *ctx)
{
ctx->size = 0;
@@ -248,7 +248,7 @@ int git_hash_init(git_hash_ctx *ctx)
return 0;
}
-int git_hash_update(git_hash_ctx *ctx, const void *data, size_t len)
+int git_hash_sha1_update(git_hash_ctx *ctx, const void *data, size_t len)
{
unsigned int lenW = ctx->size & 63;
@@ -278,7 +278,7 @@ int git_hash_update(git_hash_ctx *ctx, const void *data, size_t len)
return 0;
}
-int git_hash_final(git_oid *out, git_hash_ctx *ctx)
+int git_hash_sha1_final(git_oid *out, git_hash_ctx *ctx)
{
static const unsigned char pad[64] = { 0x80 };
unsigned int padlen[2];
diff --git a/src/hash/sha1/mbedtls.c b/src/hash/sha1/mbedtls.c
index 1215197..8ebf940 100644
--- a/src/hash/sha1/mbedtls.c
+++ b/src/hash/sha1/mbedtls.c
@@ -7,23 +7,23 @@
#include "mbedtls.h"
-int git_hash_global_init(void)
+int git_hash_sha1_global_init(void)
{
return 0;
}
-int git_hash_ctx_init(git_hash_ctx *ctx)
+int git_hash_sha1_ctx_init(git_hash_ctx *ctx)
{
- return git_hash_init(ctx);
+ return git_hash_sha1_init(ctx);
}
-void git_hash_ctx_cleanup(git_hash_ctx *ctx)
+void git_hash_sha1_ctx_cleanup(git_hash_ctx *ctx)
{
assert(ctx);
mbedtls_sha1_free(&ctx->c);
}
-int git_hash_init(git_hash_ctx *ctx)
+int git_hash_sha1_init(git_hash_ctx *ctx)
{
assert(ctx);
mbedtls_sha1_init(&ctx->c);
@@ -31,14 +31,14 @@ int git_hash_init(git_hash_ctx *ctx)
return 0;
}
-int git_hash_update(git_hash_ctx *ctx, const void *data, size_t len)
+int git_hash_sha1_update(git_hash_ctx *ctx, const void *data, size_t len)
{
assert(ctx);
mbedtls_sha1_update(&ctx->c, data, len);
return 0;
}
-int git_hash_final(git_oid *out, git_hash_ctx *ctx)
+int git_hash_sha1_final(git_oid *out, git_hash_ctx *ctx)
{
assert(ctx);
mbedtls_sha1_finish(&ctx->c, out->id);
diff --git a/src/hash/sha1/openssl.c b/src/hash/sha1/openssl.c
index fd3a4da..d93cd8b 100644
--- a/src/hash/sha1/openssl.c
+++ b/src/hash/sha1/openssl.c
@@ -7,22 +7,22 @@
#include "openssl.h"
-int git_hash_global_init(void)
+int git_hash_sha1_global_init(void)
{
return 0;
}
-int git_hash_ctx_init(git_hash_ctx *ctx)
+int git_hash_sha1_ctx_init(git_hash_ctx *ctx)
{
- return git_hash_init(ctx);
+ return git_hash_sha1_init(ctx);
}
-void git_hash_ctx_cleanup(git_hash_ctx *ctx)
+void git_hash_sha1_ctx_cleanup(git_hash_ctx *ctx)
{
GIT_UNUSED(ctx);
}
-int git_hash_init(git_hash_ctx *ctx)
+int git_hash_sha1_init(git_hash_ctx *ctx)
{
assert(ctx);
@@ -34,7 +34,7 @@ int git_hash_init(git_hash_ctx *ctx)
return 0;
}
-int git_hash_update(git_hash_ctx *ctx, const void *data, size_t len)
+int git_hash_sha1_update(git_hash_ctx *ctx, const void *data, size_t len)
{
assert(ctx);
@@ -46,7 +46,7 @@ int git_hash_update(git_hash_ctx *ctx, const void *data, size_t len)
return 0;
}
-int git_hash_final(git_oid *out, git_hash_ctx *ctx)
+int git_hash_sha1_final(git_oid *out, git_hash_ctx *ctx)
{
assert(ctx);
diff --git a/src/hash/sha1/win32.c b/src/hash/sha1/win32.c
index 0dac9be..8814ac3 100644
--- a/src/hash/sha1/win32.c
+++ b/src/hash/sha1/win32.c
@@ -119,7 +119,7 @@ static void sha1_shutdown(void)
hash_cryptoapi_prov_shutdown();
}
-int git_hash_global_init(void)
+int git_hash_sha1_global_init(void)
{
int error = 0;
@@ -141,7 +141,7 @@ GIT_INLINE(int) hash_ctx_cryptoapi_init(git_hash_ctx *ctx)
ctx->type = CRYPTOAPI;
ctx->prov = &hash_prov;
- return git_hash_init(ctx);
+ return git_hash_sha1_init(ctx);
}
GIT_INLINE(int) hash_cryptoapi_init(git_hash_ctx *ctx)
@@ -281,7 +281,7 @@ GIT_INLINE(void) hash_ctx_cng_cleanup(git_hash_ctx *ctx)
/* Indirection between CryptoAPI and CNG */
-int git_hash_ctx_init(git_hash_ctx *ctx)
+int git_hash_sha1_ctx_init(git_hash_ctx *ctx)
{
int error = 0;
@@ -292,7 +292,7 @@ int git_hash_ctx_init(git_hash_ctx *ctx)
* initialized with git_libgit2_init. Otherwise, it must be initialized
* at first use.
*/
- if (hash_prov.type == INVALID && (error = git_hash_global_init()) < 0)
+ if (hash_prov.type == INVALID && (error = git_hash_sha1_global_init()) < 0)
return error;
memset(ctx, 0x0, sizeof(git_hash_ctx));
@@ -300,25 +300,25 @@ int git_hash_ctx_init(git_hash_ctx *ctx)
return (hash_prov.type == CNG) ? hash_ctx_cng_init(ctx) : hash_ctx_cryptoapi_init(ctx);
}
-int git_hash_init(git_hash_ctx *ctx)
+int git_hash_sha1_init(git_hash_ctx *ctx)
{
assert(ctx && ctx->type);
return (ctx->type == CNG) ? hash_cng_init(ctx) : hash_cryptoapi_init(ctx);
}
-int git_hash_update(git_hash_ctx *ctx, const void *data, size_t len)
+int git_hash_sha1_update(git_hash_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_final(git_oid *out, git_hash_ctx *ctx)
+int git_hash_sha1_final(git_oid *out, git_hash_ctx *ctx)
{
assert(ctx && ctx->type);
return (ctx->type == CNG) ? hash_cng_final(out, ctx) : hash_cryptoapi_final(out, ctx);
}
-void git_hash_ctx_cleanup(git_hash_ctx *ctx)
+void git_hash_sha1_ctx_cleanup(git_hash_ctx *ctx)
{
assert(ctx);