Commit 8832172e by Patrick Steinhardt

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.
parent d46d3b53
...@@ -14,27 +14,27 @@ int git_hash_global_init(void) ...@@ -14,27 +14,27 @@ int git_hash_global_init(void)
int git_hash_ctx_init(git_hash_ctx *ctx) 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) 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) int git_hash_buf(git_oid *out, const void *data, size_t len)
......
...@@ -12,8 +12,6 @@ ...@@ -12,8 +12,6 @@
#include "git2/oid.h" #include "git2/oid.h"
typedef struct git_hash_ctx git_hash_ctx;
typedef struct { typedef struct {
void *data; void *data;
size_t len; size_t len;
...@@ -21,6 +19,12 @@ typedef struct { ...@@ -21,6 +19,12 @@ typedef struct {
#include "hash/sha1.h" #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_global_init(void);
int git_hash_ctx_init(git_hash_ctx *ctx); int git_hash_ctx_init(git_hash_ctx *ctx);
......
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
#include "common.h" #include "common.h"
typedef struct git_hash_sha1_ctx git_hash_sha1_ctx;
#if defined(GIT_SHA1_COLLISIONDETECT) #if defined(GIT_SHA1_COLLISIONDETECT)
# include "sha1/collisiondetect.h" # include "sha1/collisiondetect.h"
#elif defined(GIT_SHA1_COMMON_CRYPTO) #elif defined(GIT_SHA1_COMMON_CRYPTO)
...@@ -26,11 +28,11 @@ ...@@ -26,11 +28,11 @@
int git_hash_sha1_global_init(void); int git_hash_sha1_global_init(void);
int git_hash_sha1_ctx_init(git_hash_ctx *ctx); int git_hash_sha1_ctx_init(git_hash_sha1_ctx *ctx);
void git_hash_sha1_ctx_cleanup(git_hash_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_init(git_hash_sha1_ctx *c);
int git_hash_sha1_update(git_hash_ctx *c, const void *data, size_t len); 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_ctx *c); int git_hash_sha1_final(git_oid *out, git_hash_sha1_ctx *c);
#endif #endif
...@@ -12,31 +12,31 @@ int git_hash_sha1_global_init(void) ...@@ -12,31 +12,31 @@ int git_hash_sha1_global_init(void)
return 0; 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); 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); GIT_UNUSED(ctx);
} }
int git_hash_sha1_init(git_hash_ctx *ctx) int git_hash_sha1_init(git_hash_sha1_ctx *ctx)
{ {
assert(ctx); assert(ctx);
SHA1DCInit(&ctx->c); SHA1DCInit(&ctx->c);
return 0; 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); assert(ctx);
SHA1DCUpdate(&ctx->c, data, len); SHA1DCUpdate(&ctx->c, data, len);
return 0; 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); assert(ctx);
if (SHA1DCFinal(out->id, &ctx->c)) { if (SHA1DCFinal(out->id, &ctx->c)) {
......
...@@ -8,11 +8,11 @@ ...@@ -8,11 +8,11 @@
#ifndef INCLUDE_hash_sha1_collisiondetect_h__ #ifndef INCLUDE_hash_sha1_collisiondetect_h__
#define INCLUDE_hash_sha1_collisiondetect_h__ #define INCLUDE_hash_sha1_collisiondetect_h__
#include "hash.h" #include "hash/sha1.h"
#include "sha1dc/sha1.h" #include "sha1dc/sha1.h"
struct git_hash_ctx { struct git_hash_sha1_ctx {
SHA1_CTX c; SHA1_CTX c;
}; };
......
...@@ -14,24 +14,24 @@ int git_hash_sha1_global_init(void) ...@@ -14,24 +14,24 @@ int git_hash_sha1_global_init(void)
return 0; 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); 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); GIT_UNUSED(ctx);
} }
int git_hash_sha1_init(git_hash_ctx *ctx) int git_hash_sha1_init(git_hash_sha1_ctx *ctx)
{ {
assert(ctx); assert(ctx);
CC_SHA1_Init(&ctx->c); CC_SHA1_Init(&ctx->c);
return 0; 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; const unsigned char *data = _data;
...@@ -49,7 +49,7 @@ int git_hash_sha1_update(git_hash_ctx *ctx, const void *_data, size_t len) ...@@ -49,7 +49,7 @@ int git_hash_sha1_update(git_hash_ctx *ctx, const void *_data, size_t len)
return 0; 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); assert(ctx);
CC_SHA1_Final(out->id, &ctx->c); CC_SHA1_Final(out->id, &ctx->c);
......
...@@ -8,11 +8,11 @@ ...@@ -8,11 +8,11 @@
#ifndef INCLUDE_hash_sha1_common_crypto_h__ #ifndef INCLUDE_hash_sha1_common_crypto_h__
#define INCLUDE_hash_sha1_common_crypto_h__ #define INCLUDE_hash_sha1_common_crypto_h__
#include "hash.h" #include "hash/sha1.h"
#include <CommonCrypto/CommonDigest.h> #include <CommonCrypto/CommonDigest.h>
struct git_hash_ctx { struct git_hash_sha1_ctx {
CC_SHA1_CTX c; CC_SHA1_CTX c;
}; };
......
...@@ -111,7 +111,7 @@ ...@@ -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_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 ) #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 A,B,C,D,E;
unsigned int array[16]; unsigned int array[16];
...@@ -224,17 +224,17 @@ int git_hash_sha1_global_init(void) ...@@ -224,17 +224,17 @@ int git_hash_sha1_global_init(void)
return 0; 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); 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); 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; ctx->size = 0;
...@@ -248,7 +248,7 @@ int git_hash_sha1_init(git_hash_ctx *ctx) ...@@ -248,7 +248,7 @@ int git_hash_sha1_init(git_hash_ctx *ctx)
return 0; 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; 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) ...@@ -278,7 +278,7 @@ int git_hash_sha1_update(git_hash_ctx *ctx, const void *data, size_t len)
return 0; 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 }; static const unsigned char pad[64] = { 0x80 };
unsigned int padlen[2]; unsigned int padlen[2];
...@@ -289,8 +289,8 @@ int git_hash_sha1_final(git_oid *out, git_hash_ctx *ctx) ...@@ -289,8 +289,8 @@ int git_hash_sha1_final(git_oid *out, git_hash_ctx *ctx)
padlen[1] = htonl((uint32_t)(ctx->size << 3)); padlen[1] = htonl((uint32_t)(ctx->size << 3));
i = ctx->size & 63; i = ctx->size & 63;
git_hash_update(ctx, pad, 1+ (63 & (55 - i))); git_hash_sha1_update(ctx, pad, 1+ (63 & (55 - i)));
git_hash_update(ctx, padlen, 8); git_hash_sha1_update(ctx, padlen, 8);
/* Output hash */ /* Output hash */
for (i = 0; i < 5; i++) for (i = 0; i < 5; i++)
......
...@@ -8,9 +8,9 @@ ...@@ -8,9 +8,9 @@
#ifndef INCLUDE_hash_sha1_generic_h__ #ifndef INCLUDE_hash_sha1_generic_h__
#define 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 long long size;
unsigned int H[5]; unsigned int H[5];
unsigned int W[16]; unsigned int W[16];
......
...@@ -12,18 +12,18 @@ int git_hash_sha1_global_init(void) ...@@ -12,18 +12,18 @@ int git_hash_sha1_global_init(void)
return 0; 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); 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); assert(ctx);
mbedtls_sha1_free(&ctx->c); 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); assert(ctx);
mbedtls_sha1_init(&ctx->c); mbedtls_sha1_init(&ctx->c);
...@@ -31,14 +31,14 @@ int git_hash_sha1_init(git_hash_ctx *ctx) ...@@ -31,14 +31,14 @@ int git_hash_sha1_init(git_hash_ctx *ctx)
return 0; 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); assert(ctx);
mbedtls_sha1_update(&ctx->c, data, len); mbedtls_sha1_update(&ctx->c, data, len);
return 0; 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); assert(ctx);
mbedtls_sha1_finish(&ctx->c, out->id); mbedtls_sha1_finish(&ctx->c, out->id);
......
...@@ -8,11 +8,11 @@ ...@@ -8,11 +8,11 @@
#ifndef INCLUDE_hash_sha1_mbedtls_h__ #ifndef INCLUDE_hash_sha1_mbedtls_h__
#define INCLUDE_hash_sha1_mbedtls_h__ #define INCLUDE_hash_sha1_mbedtls_h__
#include "hash.h" #include "hash/sha1.h"
#include <mbedtls/sha1.h> #include <mbedtls/sha1.h>
struct git_hash_ctx { struct git_hash_sha1_ctx {
mbedtls_sha1_context c; mbedtls_sha1_context c;
}; };
......
...@@ -12,17 +12,17 @@ int git_hash_sha1_global_init(void) ...@@ -12,17 +12,17 @@ int git_hash_sha1_global_init(void)
return 0; 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); 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); GIT_UNUSED(ctx);
} }
int git_hash_sha1_init(git_hash_ctx *ctx) int git_hash_sha1_init(git_hash_sha1_ctx *ctx)
{ {
assert(ctx); assert(ctx);
...@@ -34,7 +34,7 @@ int git_hash_sha1_init(git_hash_ctx *ctx) ...@@ -34,7 +34,7 @@ int git_hash_sha1_init(git_hash_ctx *ctx)
return 0; 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); assert(ctx);
...@@ -46,7 +46,7 @@ int git_hash_sha1_update(git_hash_ctx *ctx, const void *data, size_t len) ...@@ -46,7 +46,7 @@ int git_hash_sha1_update(git_hash_ctx *ctx, const void *data, size_t len)
return 0; 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); assert(ctx);
......
...@@ -8,13 +8,11 @@ ...@@ -8,13 +8,11 @@
#ifndef INCLUDE_hash_sha1_openssl_h__ #ifndef INCLUDE_hash_sha1_openssl_h__
#define INCLUDE_hash_sha1_openssl_h__ #define INCLUDE_hash_sha1_openssl_h__
#include "common.h" #include "hash/sha1.h"
#include "hash.h"
#include <openssl/sha.h> #include <openssl/sha.h>
struct git_hash_ctx { struct git_hash_sha1_ctx {
SHA_CTX c; SHA_CTX c;
}; };
......
...@@ -136,7 +136,7 @@ int git_hash_sha1_global_init(void) ...@@ -136,7 +136,7 @@ int git_hash_sha1_global_init(void)
/* CryptoAPI: available in Windows XP and newer */ /* 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->type = CRYPTOAPI;
ctx->prov = &hash_prov; ctx->prov = &hash_prov;
...@@ -144,7 +144,7 @@ GIT_INLINE(int) hash_ctx_cryptoapi_init(git_hash_ctx *ctx) ...@@ -144,7 +144,7 @@ GIT_INLINE(int) hash_ctx_cryptoapi_init(git_hash_ctx *ctx)
return git_hash_sha1_init(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) if (ctx->ctx.cryptoapi.valid)
CryptDestroyHash(ctx->ctx.cryptoapi.hash_handle); CryptDestroyHash(ctx->ctx.cryptoapi.hash_handle);
...@@ -159,7 +159,7 @@ GIT_INLINE(int) hash_cryptoapi_init(git_hash_ctx *ctx) ...@@ -159,7 +159,7 @@ GIT_INLINE(int) hash_cryptoapi_init(git_hash_ctx *ctx)
return 0; 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; const BYTE *data = (BYTE *)_data;
...@@ -180,7 +180,7 @@ GIT_INLINE(int) hash_cryptoapi_update(git_hash_ctx *ctx, const void *_data, size ...@@ -180,7 +180,7 @@ GIT_INLINE(int) hash_cryptoapi_update(git_hash_ctx *ctx, const void *_data, size
return 0; 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; DWORD len = 20;
int error = 0; int error = 0;
...@@ -198,7 +198,7 @@ GIT_INLINE(int) hash_cryptoapi_final(git_oid *out, git_hash_ctx *ctx) ...@@ -198,7 +198,7 @@ GIT_INLINE(int) hash_cryptoapi_final(git_oid *out, git_hash_ctx *ctx)
return error; 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) if (ctx->ctx.cryptoapi.valid)
CryptDestroyHash(ctx->ctx.cryptoapi.hash_handle); CryptDestroyHash(ctx->ctx.cryptoapi.hash_handle);
...@@ -206,7 +206,7 @@ GIT_INLINE(void) hash_ctx_cryptoapi_cleanup(git_hash_ctx *ctx) ...@@ -206,7 +206,7 @@ GIT_INLINE(void) hash_ctx_cryptoapi_cleanup(git_hash_ctx *ctx)
/* CNG: Available in Windows Server 2008 and newer */ /* 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) if ((ctx->ctx.cng.hash_object = git__malloc(hash_prov.prov.cng.hash_object_size)) == NULL)
return -1; return -1;
...@@ -224,7 +224,7 @@ GIT_INLINE(int) hash_ctx_cng_init(git_hash_ctx *ctx) ...@@ -224,7 +224,7 @@ GIT_INLINE(int) hash_ctx_cng_init(git_hash_ctx *ctx)
return 0; 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]; BYTE hash[GIT_OID_RAWSZ];
...@@ -242,7 +242,7 @@ GIT_INLINE(int) hash_cng_init(git_hash_ctx *ctx) ...@@ -242,7 +242,7 @@ GIT_INLINE(int) hash_cng_init(git_hash_ctx *ctx)
return 0; 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; PBYTE data = (PBYTE)_data;
...@@ -261,7 +261,7 @@ GIT_INLINE(int) hash_cng_update(git_hash_ctx *ctx, const void *_data, size_t len ...@@ -261,7 +261,7 @@ GIT_INLINE(int) hash_cng_update(git_hash_ctx *ctx, const void *_data, size_t len
return 0; 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) { 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"); 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) ...@@ -273,7 +273,7 @@ GIT_INLINE(int) hash_cng_final(git_oid *out, git_hash_ctx *ctx)
return 0; 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); ctx->prov->prov.cng.destroy_hash(ctx->ctx.cng.hash_handle);
git__free(ctx->ctx.cng.hash_object); git__free(ctx->ctx.cng.hash_object);
...@@ -281,7 +281,7 @@ GIT_INLINE(void) hash_ctx_cng_cleanup(git_hash_ctx *ctx) ...@@ -281,7 +281,7 @@ GIT_INLINE(void) hash_ctx_cng_cleanup(git_hash_ctx *ctx)
/* Indirection between CryptoAPI and CNG */ /* 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; int error = 0;
...@@ -295,30 +295,30 @@ int git_hash_sha1_ctx_init(git_hash_ctx *ctx) ...@@ -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) if (hash_prov.type == INVALID && (error = git_hash_sha1_global_init()) < 0)
return error; 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); 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); assert(ctx && ctx->type);
return (ctx->type == CNG) ? hash_cng_init(ctx) : hash_cryptoapi_init(ctx); 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); assert(ctx && ctx->type);
return (ctx->type == CNG) ? hash_cng_update(ctx, data, len) : hash_cryptoapi_update(ctx, data, 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_ctx *ctx) int git_hash_sha1_final(git_oid *out, git_hash_sha1_ctx *ctx)
{ {
assert(ctx && ctx->type); assert(ctx && ctx->type);
return (ctx->type == CNG) ? hash_cng_final(out, ctx) : hash_cryptoapi_final(out, ctx); 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); assert(ctx);
......
...@@ -5,12 +5,10 @@ ...@@ -5,12 +5,10 @@
* a Linking Exception. For full terms see the included COPYING file. * a Linking Exception. For full terms see the included COPYING file.
*/ */
#ifndef INCLUDE_hash_hash_win32_h__ #ifndef INCLUDE_hash_sha1_win32_h__
#define INCLUDE_hash_hash_win32_h__ #define INCLUDE_hash_sha1_win32_h__
#include "common.h" #include "hash/sha1.h"
#include "hash.h"
#include <wincrypt.h> #include <wincrypt.h>
#include <strsafe.h> #include <strsafe.h>
...@@ -117,7 +115,7 @@ struct hash_cng_ctx { ...@@ -117,7 +115,7 @@ struct hash_cng_ctx {
PBYTE hash_object; PBYTE hash_object;
}; };
struct git_hash_ctx { struct git_hash_sha1_ctx {
enum hash_win32_prov_type type; enum hash_win32_prov_type type;
git_hash_prov *prov; git_hash_prov *prov;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment