Blame src/hash/hash_win32.h

Packit Service 20376f
/*
Packit Service 20376f
 * Copyright (C) the libgit2 contributors. All rights reserved.
Packit Service 20376f
 *
Packit Service 20376f
 * This file is part of libgit2, distributed under the GNU GPL v2 with
Packit Service 20376f
 * a Linking Exception. For full terms see the included COPYING file.
Packit Service 20376f
 */
Packit Service 20376f
Packit Service 20376f
#ifndef INCLUDE_hash_win32_h__
Packit Service 20376f
#define INCLUDE_hash_win32_h__
Packit Service 20376f
Packit Service 20376f
#include "common.h"
Packit Service 20376f
#include "hash.h"
Packit Service 20376f
Packit Service 20376f
#include <wincrypt.h>
Packit Service 20376f
#include <strsafe.h>
Packit Service 20376f
Packit Service 20376f
enum hash_win32_prov_type {
Packit Service 20376f
	INVALID = 0,
Packit Service 20376f
	CRYPTOAPI,
Packit Service 20376f
	CNG
Packit Service 20376f
};
Packit Service 20376f
Packit Service 20376f
/*
Packit Service 20376f
 * CryptoAPI is available for hashing on Windows XP and newer.
Packit Service 20376f
 */
Packit Service 20376f
Packit Service 20376f
struct hash_cryptoapi_prov {
Packit Service 20376f
	HCRYPTPROV handle;
Packit Service 20376f
};
Packit Service 20376f
Packit Service 20376f
/*
Packit Service 20376f
 * CNG (bcrypt.dll) is significantly more performant than CryptoAPI and is
Packit Service 20376f
 * preferred, however it is only available on Windows 2008 and newer and
Packit Service 20376f
 * must therefore be dynamically loaded, and we must inline constants that
Packit Service 20376f
 * would not exist when building in pre-Windows 2008 environments.
Packit Service 20376f
 */
Packit Service 20376f
Packit Service 20376f
#define GIT_HASH_CNG_DLL_NAME           "bcrypt.dll"
Packit Service 20376f
Packit Service 20376f
/* BCRYPT_SHA1_ALGORITHM */
Packit Service 20376f
#define GIT_HASH_CNG_HASH_TYPE          L"SHA1"
Packit Service 20376f
Packit Service 20376f
/* BCRYPT_OBJECT_LENGTH */
Packit Service 20376f
#define GIT_HASH_CNG_HASH_OBJECT_LEN    L"ObjectLength"
Packit Service 20376f
Packit Service 20376f
/* BCRYPT_HASH_REUSEABLE_FLAGS */
Packit Service 20376f
#define GIT_HASH_CNG_HASH_REUSABLE      0x00000020
Packit Service 20376f
Packit Service 20376f
/* Function declarations for CNG */
Packit Service 20376f
typedef NTSTATUS (WINAPI *hash_win32_cng_open_algorithm_provider_fn)(
Packit Service 20376f
	HANDLE /* BCRYPT_ALG_HANDLE */ *phAlgorithm,
Packit Service 20376f
	LPCWSTR pszAlgId,
Packit Service 20376f
	LPCWSTR pszImplementation,
Packit Service 20376f
	DWORD dwFlags);
Packit Service 20376f
Packit Service 20376f
typedef NTSTATUS (WINAPI *hash_win32_cng_get_property_fn)(
Packit Service 20376f
	HANDLE /* BCRYPT_HANDLE */ hObject,
Packit Service 20376f
	LPCWSTR pszProperty,
Packit Service 20376f
	PUCHAR pbOutput,
Packit Service 20376f
	ULONG cbOutput,
Packit Service 20376f
	ULONG *pcbResult,
Packit Service 20376f
	ULONG dwFlags);
Packit Service 20376f
Packit Service 20376f
typedef NTSTATUS (WINAPI *hash_win32_cng_create_hash_fn)(
Packit Service 20376f
	HANDLE /* BCRYPT_ALG_HANDLE */ hAlgorithm,
Packit Service 20376f
	HANDLE /* BCRYPT_HASH_HANDLE */ *phHash,
Packit Service 20376f
	PUCHAR pbHashObject, ULONG cbHashObject,
Packit Service 20376f
	PUCHAR pbSecret,
Packit Service 20376f
	ULONG cbSecret,
Packit Service 20376f
	ULONG dwFlags);
Packit Service 20376f
Packit Service 20376f
typedef NTSTATUS (WINAPI *hash_win32_cng_finish_hash_fn)(
Packit Service 20376f
	HANDLE /* BCRYPT_HASH_HANDLE */ hHash,
Packit Service 20376f
	PUCHAR pbOutput,
Packit Service 20376f
	ULONG cbOutput,
Packit Service 20376f
	ULONG dwFlags);
Packit Service 20376f
Packit Service 20376f
typedef NTSTATUS (WINAPI *hash_win32_cng_hash_data_fn)(
Packit Service 20376f
	HANDLE /* BCRYPT_HASH_HANDLE */ hHash,
Packit Service 20376f
	PUCHAR pbInput,
Packit Service 20376f
	ULONG cbInput,
Packit Service 20376f
	ULONG dwFlags);
Packit Service 20376f
Packit Service 20376f
typedef NTSTATUS (WINAPI *hash_win32_cng_destroy_hash_fn)(
Packit Service 20376f
	HANDLE /* BCRYPT_HASH_HANDLE */ hHash);
Packit Service 20376f
Packit Service 20376f
typedef NTSTATUS (WINAPI *hash_win32_cng_close_algorithm_provider_fn)(
Packit Service 20376f
	HANDLE /* BCRYPT_ALG_HANDLE */ hAlgorithm,
Packit Service 20376f
	ULONG dwFlags);
Packit Service 20376f
Packit Service 20376f
struct hash_cng_prov {
Packit Service 20376f
	/* DLL for CNG */
Packit Service 20376f
	HINSTANCE dll;
Packit Service 20376f
Packit Service 20376f
	/* Function pointers for CNG */
Packit Service 20376f
	hash_win32_cng_open_algorithm_provider_fn open_algorithm_provider;
Packit Service 20376f
	hash_win32_cng_get_property_fn get_property;
Packit Service 20376f
	hash_win32_cng_create_hash_fn create_hash;
Packit Service 20376f
	hash_win32_cng_finish_hash_fn finish_hash;
Packit Service 20376f
	hash_win32_cng_hash_data_fn hash_data;
Packit Service 20376f
	hash_win32_cng_destroy_hash_fn destroy_hash;
Packit Service 20376f
	hash_win32_cng_close_algorithm_provider_fn close_algorithm_provider;
Packit Service 20376f
Packit Service 20376f
	HANDLE /* BCRYPT_ALG_HANDLE */ handle;
Packit Service 20376f
	DWORD hash_object_size;
Packit Service 20376f
};
Packit Service 20376f
Packit Service 20376f
struct git_hash_prov {
Packit Service 20376f
	enum hash_win32_prov_type type;
Packit Service 20376f
Packit Service 20376f
	union {
Packit Service 20376f
		struct hash_cryptoapi_prov cryptoapi;
Packit Service 20376f
		struct hash_cng_prov cng;
Packit Service 20376f
	} prov;
Packit Service 20376f
};
Packit Service 20376f
Packit Service 20376f
/* Hash contexts */
Packit Service 20376f
Packit Service 20376f
struct hash_cryptoapi_ctx {
Packit Service 20376f
	bool valid;
Packit Service 20376f
	HCRYPTHASH hash_handle;
Packit Service 20376f
};
Packit Service 20376f
Packit Service 20376f
struct hash_cng_ctx {
Packit Service 20376f
	bool updated;
Packit Service 20376f
	HANDLE /* BCRYPT_HASH_HANDLE */ hash_handle;
Packit Service 20376f
	PBYTE hash_object;
Packit Service 20376f
};
Packit Service 20376f
Packit Service 20376f
struct git_hash_ctx {
Packit Service 20376f
	enum hash_win32_prov_type type;
Packit Service 20376f
	git_hash_prov *prov;
Packit Service 20376f
Packit Service 20376f
	union {
Packit Service 20376f
		struct hash_cryptoapi_ctx cryptoapi;
Packit Service 20376f
		struct hash_cng_ctx cng;
Packit Service 20376f
	} ctx;
Packit Service 20376f
};
Packit Service 20376f
Packit Service 20376f
#endif /* INCLUDE_hash_openssl_h__ */