win32.h 1.19 KB
Newer Older
1
/*
Edward Thomson committed
2
 * Copyright (C) the libgit2 contributors. All rights reserved.
3 4 5 6 7
 *
 * This file is part of libgit2, distributed under the GNU GPL v2 with
 * a Linking Exception. For full terms see the included COPYING file.
 */

8 9
#ifndef INCLUDE_hash_win32_h__
#define INCLUDE_hash_win32_h__
10

11
#include "hash/sha.h"
12 13 14

#include <wincrypt.h>

15 16 17 18 19
typedef enum {
	GIT_HASH_WIN32_INVALID = 0,
	GIT_HASH_WIN32_CRYPTOAPI,
	GIT_HASH_WIN32_CNG
} git_hash_win32_provider_t;
20

21
struct git_hash_win32_cryptoapi_ctx {
22 23 24 25
	bool valid;
	HCRYPTHASH hash_handle;
};

26
struct git_hash_win32_cng_ctx {
27 28 29 30 31
	bool updated;
	HANDLE /* BCRYPT_HASH_HANDLE */ hash_handle;
	PBYTE hash_object;
};

32 33
typedef struct {
	ALG_ID algorithm;
34 35

	union {
36 37
		struct git_hash_win32_cryptoapi_ctx cryptoapi;
		struct git_hash_win32_cng_ctx cng;
38
	} ctx;
39 40
} git_hash_win32_ctx;

41 42 43 44 45 46 47
/*
 * Gets/sets the current hash provider (cng or cryptoapi).  This is only
 * for testing purposes.
 */
git_hash_win32_provider_t git_hash_win32_provider(void);
int git_hash_win32_set_provider(git_hash_win32_provider_t provider);

48 49 50
#ifdef GIT_SHA1_WIN32
struct git_hash_sha1_ctx {
	git_hash_win32_ctx win32;
51
};
52 53 54 55 56 57 58
#endif

#ifdef GIT_SHA256_WIN32
struct git_hash_sha256_ctx {
	git_hash_win32_ctx win32;
};
#endif
59

60
#endif