packages feed

hlibgit2 0.18.0.1 → 0.18.0.2

raw patch · 4 files changed

+211/−1 lines, 4 files

Files

hlibgit2.cabal view
@@ -1,5 +1,5 @@ Name:                hlibgit2-Version:             0.18.0.1+Version:             0.18.0.2 Synopsis:            Low-level bindings to libgit2 Description:         Bindings to libgit2 v0.18.0. License-file:        LICENSE@@ -15,6 +15,7 @@   libgit2/include/git2.h   libgit2/include/git2/*.h   libgit2/src/*.h+  libgit2/src/hash/*.h   libgit2/src/unix/*.h   libgit2/src/win32/*.h   libgit2/src/xdiff/*.h
+ libgit2/src/hash/hash_generic.h view
@@ -0,0 +1,24 @@+/*+ * Copyright (C) the libgit2 contributors. All rights reserved.+ *+ * This file is part of libgit2, distributed under the GNU GPL v2 with+ * a Linking Exception. For full terms see the included COPYING file.+ */++#ifndef INCLUDE_hash_generic_h__+#define INCLUDE_hash_generic_h__++#include "hash.h"++struct git_hash_ctx {+    unsigned long long size;+    unsigned int H[5];+    unsigned int W[16];+};++#define git_hash_global_init() 0+#define git_hash_global_shutdown() /* noop */+#define git_hash_ctx_init(ctx) git_hash_init(ctx)+#define git_hash_ctx_cleanup(ctx)++#endif /* INCLUDE_hash_generic_h__ */
+ libgit2/src/hash/hash_openssl.h view
@@ -0,0 +1,45 @@+/*+ * Copyright (C) the libgit2 contributors. All rights reserved.+ *+ * This file is part of libgit2, distributed under the GNU GPL v2 with+ * a Linking Exception. For full terms see the included COPYING file.+ */++#ifndef INCLUDE_hash_openssl_h__+#define INCLUDE_hash_openssl_h__++#include "hash.h"++#include <openssl/sha.h>++struct git_hash_ctx {+	SHA_CTX c;+};++#define git_hash_global_init() 0+#define git_hash_global_shutdown() /* noop */+#define git_hash_ctx_init(ctx) git_hash_init(ctx)+#define git_hash_ctx_cleanup(ctx)++GIT_INLINE(int) git_hash_init(git_hash_ctx *ctx)+{+	assert(ctx);+	SHA1_Init(&ctx->c);+	return 0;+}++GIT_INLINE(int) git_hash_update(git_hash_ctx *ctx, const void *data, size_t len)+{+	assert(ctx);+	SHA1_Update(&ctx->c, data, len);+	return 0;+}++GIT_INLINE(int) git_hash_final(git_oid *out, git_hash_ctx *ctx)+{+	assert(ctx);+	SHA1_Final(out->id, &ctx->c);+	return 0;+}++#endif /* INCLUDE_hash_openssl_h__ */
+ libgit2/src/hash/hash_win32.h view
@@ -0,0 +1,140 @@+/*+ * Copyright (C) the libgit2 contributors. All rights reserved.+ *+ * This file is part of libgit2, distributed under the GNU GPL v2 with+ * a Linking Exception. For full terms see the included COPYING file.+ */++#ifndef INCLUDE_hash_win32_h__+#define INCLUDE_hash_win32_h__++#include "common.h"+#include "hash.h"++#include <wincrypt.h>+#include <strsafe.h>++enum hash_win32_prov_type {+	INVALID = 0,+	CRYPTOAPI,+	CNG+};++/*+ * CryptoAPI is available for hashing on Windows XP and newer.+ */++struct hash_cryptoapi_prov {+	HCRYPTPROV handle;+};++/*+ * CNG (bcrypt.dll) is significantly more performant than CryptoAPI and is+ * preferred, however it is only available on Windows 2008 and newer and+ * must therefore be dynamically loaded, and we must inline constants that+ * would not exist when building in pre-Windows 2008 environments.+ */++#define GIT_HASH_CNG_DLL_NAME           "bcrypt.dll"++/* BCRYPT_SHA1_ALGORITHM */+#define GIT_HASH_CNG_HASH_TYPE          L"SHA1"++/* BCRYPT_OBJECT_LENGTH */+#define GIT_HASH_CNG_HASH_OBJECT_LEN    L"ObjectLength"++/* BCRYPT_HASH_REUSEABLE_FLAGS */+#define GIT_HASH_CNG_HASH_REUSABLE      0x00000020++/* Function declarations for CNG */+typedef NTSTATUS (WINAPI *hash_win32_cng_open_algorithm_provider_fn)(+    HANDLE /* BCRYPT_ALG_HANDLE */ *phAlgorithm,+    LPCWSTR pszAlgId,+    LPCWSTR pszImplementation,+    DWORD dwFlags);++typedef NTSTATUS (WINAPI *hash_win32_cng_get_property_fn)(+	HANDLE /* BCRYPT_HANDLE */ hObject,+	LPCWSTR pszProperty,+	PUCHAR pbOutput,+	ULONG cbOutput,+	ULONG *pcbResult,+	ULONG dwFlags);++typedef NTSTATUS (WINAPI *hash_win32_cng_create_hash_fn)(+	HANDLE /* BCRYPT_ALG_HANDLE */ hAlgorithm,+	HANDLE /* BCRYPT_HASH_HANDLE */ *phHash,+	PUCHAR pbHashObject, ULONG cbHashObject,+	PUCHAR pbSecret,+	ULONG cbSecret,+	ULONG dwFlags);++typedef NTSTATUS (WINAPI *hash_win32_cng_finish_hash_fn)(+	HANDLE /* BCRYPT_HASH_HANDLE */ hHash,+	PUCHAR pbOutput,+	ULONG cbOutput,+	ULONG dwFlags);++typedef NTSTATUS (WINAPI *hash_win32_cng_hash_data_fn)(+	HANDLE /* BCRYPT_HASH_HANDLE */ hHash,+	PUCHAR pbInput,+	ULONG cbInput,+	ULONG dwFlags);++typedef NTSTATUS (WINAPI *hash_win32_cng_destroy_hash_fn)(+	HANDLE /* BCRYPT_HASH_HANDLE */ hHash);++typedef NTSTATUS (WINAPI *hash_win32_cng_close_algorithm_provider_fn)(+	HANDLE /* BCRYPT_ALG_HANDLE */ hAlgorithm,+	ULONG dwFlags);++struct hash_cng_prov {+	/* DLL for CNG */+	HINSTANCE dll;++	/* Function pointers for CNG */+	hash_win32_cng_open_algorithm_provider_fn open_algorithm_provider;+	hash_win32_cng_get_property_fn get_property;+	hash_win32_cng_create_hash_fn create_hash;+	hash_win32_cng_finish_hash_fn finish_hash;+	hash_win32_cng_hash_data_fn hash_data;+	hash_win32_cng_destroy_hash_fn destroy_hash;+	hash_win32_cng_close_algorithm_provider_fn close_algorithm_provider;++	HANDLE /* BCRYPT_ALG_HANDLE */ handle;+	DWORD hash_object_size;+};++struct git_hash_prov {+	enum hash_win32_prov_type type;++	union {+		struct hash_cryptoapi_prov cryptoapi;+		struct hash_cng_prov cng;+	} prov;+};++/* Hash contexts */++struct hash_cryptoapi_ctx {+	bool valid;+	HCRYPTHASH hash_handle;+};++struct hash_cng_ctx {+	bool updated;+	HANDLE /* BCRYPT_HASH_HANDLE */ hash_handle;+	PBYTE hash_object;+};++struct git_hash_ctx {+	enum hash_win32_prov_type type;+	git_hash_prov *prov;++	union {+		struct hash_cryptoapi_ctx cryptoapi;+		struct hash_cng_ctx cng;+	} ctx;+};++#endif /* INCLUDE_hash_openssl_h__ */