summaryrefslogtreecommitdiff
path: root/src/hash
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2019-04-05 10:59:46 +0200
committerPatrick Steinhardt <ps@pks.im>2019-06-24 18:33:22 +0200
commitd46d3b539b3e0ed3871d2ac22271a6469ed7c215 (patch)
treefabc2088d4b49234b5ed4c035a68e38e8e09661f /src/hash
parentfda206228f5df603a6fc3a81092e36850d4879b2 (diff)
downloadlibgit2-d46d3b539b3e0ed3871d2ac22271a6469ed7c215.tar.gz
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.
Diffstat (limited to 'src/hash')
-rw-r--r--src/hash/sha1.h9
-rw-r--r--src/hash/sha1/collisiondetect.c14
-rw-r--r--src/hash/sha1/common_crypto.c14
-rw-r--r--src/hash/sha1/generic.c14
-rw-r--r--src/hash/sha1/mbedtls.c14
-rw-r--r--src/hash/sha1/openssl.c14
-rw-r--r--src/hash/sha1/win32.c16
7 files changed, 52 insertions, 43 deletions
diff --git a/src/hash/sha1.h b/src/hash/sha1.h
index db0e5c195..38a4464be 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 79ec4e549..e0c3db642 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 2fa52183a..3539fd012 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 157b9183e..a5a9f4cc8 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 1215197de..8ebf9409b 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 fd3a4daa4..d93cd8b05 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 0dac9becb..8814ac3a6 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);