2 * Copyright (C) 2009-2012 the libgit2 contributors
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
8 #ifndef INCLUDE_hash_win32_h__
9 #define INCLUDE_hash_win32_h__
17 enum hash_win32_prov_type
{
24 * CryptoAPI is available for hashing on Windows XP and newer.
27 struct hash_cryptoapi_prov
{
32 * CNG (bcrypt.dll) is significantly more performant than CryptoAPI and is
33 * preferred, however it is only available on Windows 2008 and newer and
34 * must therefore be dynamically loaded, and we must inline constants that
35 * would not exist when building in pre-Windows 2008 environments.
38 #define GIT_HASH_CNG_DLL_NAME "bcrypt.dll"
40 /* BCRYPT_SHA1_ALGORITHM */
41 #define GIT_HASH_CNG_HASH_TYPE L"SHA1"
43 /* BCRYPT_OBJECT_LENGTH */
44 #define GIT_HASH_CNG_HASH_OBJECT_LEN L"ObjectLength"
46 /* BCRYPT_HASH_REUSEABLE_FLAGS */
47 #define GIT_HASH_CNG_HASH_REUSABLE 0x00000020
49 /* Function declarations for CNG */
50 typedef NTSTATUS (WINAPI
*hash_win32_cng_open_algorithm_provider_fn
)(
51 HANDLE
/* BCRYPT_ALG_HANDLE */ *phAlgorithm
,
53 LPCWSTR pszImplementation
,
56 typedef NTSTATUS (WINAPI
*hash_win32_cng_get_property_fn
)(
57 HANDLE
/* BCRYPT_HANDLE */ hObject
,
64 typedef NTSTATUS (WINAPI
*hash_win32_cng_create_hash_fn
)(
65 HANDLE
/* BCRYPT_ALG_HANDLE */ hAlgorithm
,
66 HANDLE
/* BCRYPT_HASH_HANDLE */ *phHash
,
67 PUCHAR pbHashObject
, ULONG cbHashObject
,
72 typedef NTSTATUS (WINAPI
*hash_win32_cng_finish_hash_fn
)(
73 HANDLE
/* BCRYPT_HASH_HANDLE */ hHash
,
78 typedef NTSTATUS (WINAPI
*hash_win32_cng_hash_data_fn
)(
79 HANDLE
/* BCRYPT_HASH_HANDLE */ hHash
,
84 typedef NTSTATUS (WINAPI
*hash_win32_cng_destroy_hash_fn
)(
85 HANDLE
/* BCRYPT_HASH_HANDLE */ hHash
);
87 typedef NTSTATUS (WINAPI
*hash_win32_cng_close_algorithm_provider_fn
)(
88 HANDLE
/* BCRYPT_ALG_HANDLE */ hAlgorithm
,
91 struct hash_cng_prov
{
95 /* Function pointers for CNG */
96 hash_win32_cng_open_algorithm_provider_fn open_algorithm_provider
;
97 hash_win32_cng_get_property_fn get_property
;
98 hash_win32_cng_create_hash_fn create_hash
;
99 hash_win32_cng_finish_hash_fn finish_hash
;
100 hash_win32_cng_hash_data_fn hash_data
;
101 hash_win32_cng_destroy_hash_fn destroy_hash
;
102 hash_win32_cng_close_algorithm_provider_fn close_algorithm_provider
;
104 HANDLE
/* BCRYPT_ALG_HANDLE */ handle
;
105 DWORD hash_object_size
;
108 struct git_hash_prov
{
109 enum hash_win32_prov_type type
;
112 struct hash_cryptoapi_prov cryptoapi
;
113 struct hash_cng_prov cng
;
119 struct hash_cryptoapi_ctx
{
121 HCRYPTHASH hash_handle
;
124 struct hash_cng_ctx
{
126 HANDLE
/* BCRYPT_HASH_HANDLE */ hash_handle
;
130 struct git_hash_ctx
{
131 enum hash_win32_prov_type type
;
135 struct hash_cryptoapi_ctx cryptoapi
;
136 struct hash_cng_ctx cng
;
140 #endif /* INCLUDE_hash_openssl_h__ */