aboutsummaryrefslogtreecommitdiff
path: root/src/libs/dutil/WixToolset.DUtil/inc/cryputil.h
blob: 02492d8aeff00c585e3a1521fb3261932bfd5d59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#pragma once
// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.


#define ReleaseCryptMsg(p) if (p) { ::CryptMsgClose(p); p = NULL; }

#ifdef __cplusplus
extern "C" {
#endif


// Use CRYPTPROTECTMEMORY_BLOCK_SIZE, because it's larger and thus more restrictive than RTL_ENCRYPT_MEMORY_SIZE.
#define CRYP_ENCRYPT_MEMORY_SIZE CRYPTPROTECTMEMORY_BLOCK_SIZE
#define MD5_HASH_LEN 16
#define SHA1_HASH_LEN 20
#define SHA256_HASH_LEN 32
#define SHA512_HASH_LEN 64

typedef NTSTATUS (APIENTRY *PFN_RTLENCRYPTMEMORY)(
    __inout PVOID Memory,
    __in ULONG MemoryLength,
    __in ULONG OptionFlags
    );

typedef NTSTATUS (APIENTRY *PFN_RTLDECRYPTMEMORY)(
    __inout PVOID Memory,
    __in ULONG MemoryLength,
    __in ULONG OptionFlags
    );

typedef BOOL (APIENTRY *PFN_CRYPTPROTECTMEMORY)(
    __inout LPVOID pData,
    __in DWORD cbData,
    __in DWORD dwFlags
    );

typedef BOOL (APIENTRY *PFN_CRYPTUNPROTECTMEMORY)(
    __inout LPVOID pData,
    __in DWORD cbData,
    __in DWORD dwFlags
    );

// function declarations

HRESULT DAPI CrypInitialize();
void DAPI CrypUninitialize();

HRESULT DAPI CrypDecodeObject(
    __in_z LPCSTR szStructType,
    __in_ecount(cbData) const BYTE* pbData,
    __in DWORD cbData,
    __in DWORD dwFlags,
    __out LPVOID* ppvObject,
    __out_opt DWORD* pcbObject
    );

HRESULT DAPI CrypMsgGetParam(
    __in HCRYPTMSG hCryptMsg,
    __in DWORD dwType,
    __in DWORD dwIndex,
    __out LPVOID* ppvData,
    __out_opt DWORD* pcbData
    );

HRESULT DAPI CrypHashFile(
    __in_z LPCWSTR wzFilePath,
    __in DWORD dwProvType,
    __in ALG_ID algid,
    __out_bcount(cbHash) BYTE* pbHash,
    __in DWORD cbHash,
    __out_opt DWORD64* pqwBytesHashed
    );

HRESULT DAPI CrypHashFileHandle(
    __in HANDLE hFile,
    __in DWORD dwProvType,
    __in ALG_ID algid,
    __out_bcount(cbHash) BYTE* pbHash,
    __in DWORD cbHash,
    __out_opt DWORD64* pqwBytesHashed
    );

HRESULT DAPI CrypHashBuffer(
    __in_bcount(cbBuffer) const BYTE* pbBuffer,
    __in SIZE_T cbBuffer,
    __in DWORD dwProvType,
    __in ALG_ID algid,
    __out_bcount(cbHash) BYTE* pbHash,
    __in DWORD cbHash
    );

HRESULT DAPI CrypEncryptMemory(
    __inout LPVOID pData,
    __in DWORD cbData,
    __in DWORD dwFlags
    );

HRESULT DAPI CrypDecryptMemory(
    __inout LPVOID pData,
    __in DWORD cbData,
    __in DWORD dwFlags
    );

#ifdef __cplusplus
}
#endif