FreeRDP
bcrypt.h
1 
20 #ifndef WINPR_BCRYPT_H
21 #define WINPR_BCRYPT_H
22 
23 #ifdef _WIN32
24 #include <bcrypt.h>
25 #else
26 
27 #include <winpr/winpr.h>
28 #include <winpr/wtypes.h>
29 
30 typedef PVOID BCRYPT_HANDLE;
31 typedef PVOID BCRYPT_ALG_HANDLE;
32 typedef PVOID BCRYPT_KEY_HANDLE;
33 typedef PVOID BCRYPT_HASH_HANDLE;
34 typedef PVOID BCRYPT_SECRET_HANDLE;
35 
36 #define BCRYPT_RSA_ALGORITHM \
37  (const WCHAR*)"R\x00S\x00" \
38  "A\x00\x00"
39 #define BCRYPT_RSA_SIGN_ALGORITHM \
40  (const WCHAR*)"R\x00S\x00" \
41  "A\x00_\x00S\x00I\x00G\x00N\x00\x00"
42 #define BCRYPT_DH_ALGORITHM (const WCHAR*)"D\x00H\x00\x00"
43 #define BCRYPT_DSA_ALGORITHM \
44  (const WCHAR*)"D\x00S\x00" \
45  "A\x00\x00"
46 #define BCRYPT_RC2_ALGORITHM \
47  (const WCHAR*)"R\x00" \
48  "C\x002\x00\x00"
49 #define BCRYPT_RC4_ALGORITHM \
50  (const WCHAR*)"R\x00" \
51  "C\x004\x00\x00"
52 #define BCRYPT_AES_ALGORITHM \
53  (const WCHAR*)"A\x00" \
54  "E\x00S\x00\x00"
55 #define BCRYPT_DES_ALGORITHM \
56  (const WCHAR*)"D\x00" \
57  "E\x00S\x00\x00"
58 #define BCRYPT_DESX_ALGORITHM \
59  (const WCHAR*)"D\x00" \
60  "E\x00S\x00X\x00\x00"
61 #define BCRYPT_3DES_ALGORITHM \
62  (const WCHAR*)"3\x00" \
63  "D\x00" \
64  "E\x00S\x00\x00"
65 #define BCRYPT_3DES_112_ALGORITHM \
66  (const WCHAR*)"3\x00" \
67  "D\x00" \
68  "E\x00S\x00_\x001\x001\x002\x00\x00"
69 #define BCRYPT_MD2_ALGORITHM \
70  (const WCHAR*)"M\x00" \
71  "D\x002\x00\x00"
72 #define BCRYPT_MD4_ALGORITHM \
73  (const WCHAR*)"M\x00" \
74  "D\x004\x00\x00"
75 #define BCRYPT_MD5_ALGORITHM \
76  (const WCHAR*)"M\x00" \
77  "D\x005\x00\x00"
78 #define BCRYPT_SHA1_ALGORITHM \
79  (const WCHAR*)"S\x00H\x00" \
80  "A\x001\x00\x00"
81 #define BCRYPT_SHA256_ALGORITHM \
82  (const WCHAR*)"S\x00H\x00" \
83  "A\x002\x005\x006\x00\x00"
84 #define BCRYPT_SHA384_ALGORITHM \
85  (const WCHAR*)"S\x00H\x00" \
86  "A\x003\x008\x004\x00\x00"
87 #define BCRYPT_SHA512_ALGORITHM \
88  (const WCHAR*)"S\x00H\x00" \
89  "A\x005\x001\x002\x00\x00"
90 #define BCRYPT_AES_GMAC_ALGORITHM \
91  (const WCHAR*)"A\x00" \
92  "E\x00S\x00-\x00G\x00M\x00" \
93  "A\x00" \
94  "C\x00\x00"
95 #define BCRYPT_ECDSA_ALGORITHM \
96  (const WCHAR*)"E\x00" \
97  "C\x00" \
98  "D\x00S\x00" \
99  "A\x00\x00"
100 #define BCRYPT_ECDSA_P256_ALGORITHM \
101  (const WCHAR*)"E\x00" \
102  "C\x00" \
103  "D\x00S\x00" \
104  "A\x00_\x00P\x002\x005\x006\x00\x00"
105 #define BCRYPT_ECDSA_P384_ALGORITHM \
106  (const WCHAR*)"E\x00" \
107  "C\x00" \
108  "D\x00S\x00" \
109  "A\x00_\x00P\x003\x008\x004\x00\x00"
110 #define BCRYPT_ECDSA_P521_ALGORITHM \
111  (const WCHAR*)"E\x00" \
112  "C\x00" \
113  "D\x00S\x00" \
114  "A\x00_\x00P\x005\x002\x001\x00\x00"
115 #define BCRYPT_ECDH_P256_ALGORITHM \
116  (const WCHAR*)"E\x00" \
117  "C\x00" \
118  "D\x00S\x00" \
119  "A\x00_\x00P\x002\x005\x006\x00\x00"
120 #define BCRYPT_ECDH_P384_ALGORITHM \
121  (const WCHAR*)"E\x00" \
122  "C\x00" \
123  "D\x00S\x00" \
124  "A\x00_\x00P\x003\x008\x004\x00\x00"
125 #define BCRYPT_ECDH_P521_ALGORITHM \
126  (const WCHAR*)"E\x00" \
127  "C\x00" \
128  "D\x00S\x00" \
129  "A\x00_\x00P\x005\x002\x001\x00\x00"
130 #define BCRYPT_RNG_ALGORITHM (const WCHAR*)"R\x00N\x00G\x00\x00"
131 #define BCRYPT_RNG_FIPS186_DSA_ALGORITHM \
132  (const WCHAR*)"F\x00I\x00P\x00S\x001\x008\x006\x00" \
133  "D\x00S\x00" \
134  "A\x00R\x00N\x00G\x00\x00"
135 #define BCRYPT_RNG_DUAL_EC_ALGORITHM \
136  (const WCHAR*)"D\x00U\x00" \
137  "A\x00L\x00" \
138  "E\x00R\x00N\x00G\x00\x00"
139 
140 #define MS_PRIMITIVE_PROVIDER \
141  (const WCHAR*)"M\x00i\x00" \
142  "c\x00r\x00o\x00s\x00o\x00" \
143  "f\x00t\x00 " \
144  "\x00P\x00r\x00i\x00m\x00i\x00t\x00i\x00v\x00" \
145  "e\x00 " \
146  "\x00P\x00r\x00o\x00v\x00i\x00" \
147  "d\x00" \
148  "e\x00r\x00\x00"
149 
150 #define BCRYPT_ALG_HANDLE_HMAC_FLAG 0x00000008
151 #define BCRYPT_PROV_DISPATCH 0x00000001
152 
153 #define BCRYPT_OBJECT_LENGTH \
154  (const WCHAR*)"O\x00" \
155  "b\x00j\x00" \
156  "e\x00" \
157  "c\x00t\x00L\x00" \
158  "e\x00n\x00g\x00t\x00h\x00\x00"
159 #define BCRYPT_ALGORITHM_NAME \
160  (const WCHAR*)"A\x00l\x00g\x00o\x00r\x00i\x00t\x00h\x00m\x00N\x00" \
161  "a\x00m\x00" \
162  "e\x00\x00"
163 #define BCRYPT_PROVIDER_HANDLE \
164  (const WCHAR*)"P\x00r\x00o\x00v\x00i\x00" \
165  "d\x00" \
166  "e\x00r\x00H\x00" \
167  "a\x00n\x00" \
168  "d\x00l\x00" \
169  "e\x00\x00"
170 #define BCRYPT_CHAINING_MODE \
171  (const WCHAR*)"C\x00h\x00" \
172  "a\x00i\x00n\x00i\x00n\x00g\x00M\x00o\x00" \
173  "d\x00" \
174  "e\x00\x00"
175 #define BCRYPT_BLOCK_LENGTH \
176  (const WCHAR*)"B\x00l\x00o\x00" \
177  "c\x00k\x00L\x00" \
178  "e\x00n\x00g\x00t\x00h\x00\x00"
179 #define BCRYPT_KEY_LENGTH \
180  (const WCHAR*)"K\x00" \
181  "e\x00y\x00L\x00" \
182  "e\x00n\x00g\x00t\x00h\x00\x00"
183 #define BCRYPT_KEY_OBJECT_LENGTH \
184  (const WCHAR*)"K\x00" \
185  "e\x00y\x00O\x00" \
186  "b\x00j\x00" \
187  "e\x00" \
188  "c\x00t\x00L\x00" \
189  "e\x00n\x00g\x00t\x00h\x00" \
190  "\x00"
191 #define BCRYPT_KEY_STRENGTH \
192  (const WCHAR*)"K\x00" \
193  "e\x00y\x00S\x00t\x00r\x00" \
194  "e\x00n\x00g\x00t\x00h\x00\x00"
195 #define BCRYPT_KEY_LENGTHS \
196  (const WCHAR*)"K\x00" \
197  "e\x00y\x00L\x00" \
198  "e\x00n\x00g\x00t\x00h\x00s\x00\x00"
199 #define BCRYPT_BLOCK_SIZE_LIST \
200  (const WCHAR*)"B\x00l\x00o\x00" \
201  "c\x00k\x00S\x00i\x00z\x00" \
202  "e\x00L\x00i\x00s\x00t\x00\x00"
203 #define BCRYPT_EFFECTIVE_KEY_LENGTH \
204  (const WCHAR*)"E\x00" \
205  "f\x00" \
206  "f\x00" \
207  "e\x00" \
208  "c\x00t\x00i\x00v\x00" \
209  "e\x00K\x00" \
210  "e\x00y\x00L\x00" \
211  "e\x00n\x00g" \
212  "\x00t\x00h\x00\x00"
213 #define BCRYPT_HASH_LENGTH \
214  (const WCHAR*)"H\x00" \
215  "a\x00s\x00h\x00" \
216  "D\x00i\x00g\x00" \
217  "e\x00s\x00t\x00L\x00" \
218  "e\x00n\x00g\x00t\x00h" \
219  "\x00\x00"
220 #define BCRYPT_HASH_OID_LIST \
221  (const WCHAR*)"H\x00" \
222  "a\x00s\x00h\x00O\x00I\x00" \
223  "D\x00L\x00i\x00s\x00t\x00\x00"
224 #define BCRYPT_PADDING_SCHEMES \
225  (const WCHAR*)"P\x00" \
226  "a\x00" \
227  "d\x00" \
228  "d\x00i\x00n\x00g\x00S\x00" \
229  "c\x00h\x00" \
230  "e\x00m\x00" \
231  "e\x00s\x00\x00"
232 #define BCRYPT_SIGNATURE_LENGTH \
233  (const WCHAR*)"S\x00i\x00g\x00n\x00" \
234  "a\x00t\x00u\x00r\x00" \
235  "e\x00L\x00" \
236  "e\x00n\x00g\x00t\x00h\x00" \
237  "\x00"
238 #define BCRYPT_HASH_BLOCK_LENGTH \
239  (const WCHAR*)"H\x00" \
240  "a\x00s\x00h\x00" \
241  "B\x00l\x00o\x00" \
242  "c\x00k\x00L\x00" \
243  "e\x00n\x00g\x00t\x00h\x00" \
244  "\x00"
245 #define BCRYPT_AUTH_TAG_LENGTH \
246  (const WCHAR*)"A\x00u\x00t\x00h\x00T\x00" \
247  "a\x00g\x00L\x00" \
248  "e\x00n\x00g\x00t\x00h\x00\x00"
249 #define BCRYPT_PRIMITIVE_TYPE \
250  (const WCHAR*)"P\x00r\x00i\x00m\x00i\x00t\x00i\x00v\x00" \
251  "e\x00T\x00y\x00p\x00" \
252  "e\x00\x00"
253 #define BCRYPT_IS_KEYED_HASH \
254  (const WCHAR*)"I\x00s\x00K\x00" \
255  "e\x00y\x00" \
256  "e\x00" \
257  "d\x00H\x00" \
258  "a\x00s\x00h\x00\x00"
259 
260 #define BCRYPT_KEY_DATA_BLOB \
261  (const WCHAR*)"K\x00" \
262  "e\x00y\x00" \
263  "D\x00" \
264  "a\x00t\x00" \
265  "a\x00" \
266  "B\x00l\x00o\x00" \
267  "b\x00\x00"
268 
269 #define BCRYPT_BLOCK_PADDING 0x00000001
270 
271 #define BCRYPT_KEY_DATA_BLOB_MAGIC 0x4d42444b
272 #define BCRYPT_KEY_DATA_BLOB_VERSION1 0x1
273 
274 typedef struct
275 {
276  ULONG dwMagic;
277  ULONG dwVersion;
278  ULONG cbKeyData;
280 
281 #ifdef __cplusplus
282 extern "C"
283 {
284 #endif
285 
286  WINPR_API NTSTATUS BCryptOpenAlgorithmProvider(BCRYPT_ALG_HANDLE* phAlgorithm, LPCWSTR pszAlgId,
287  LPCWSTR pszImplementation, ULONG dwFlags);
288 
289  WINPR_API NTSTATUS BCryptCloseAlgorithmProvider(BCRYPT_ALG_HANDLE hAlgorithm, ULONG dwFlags);
290 
291  WINPR_API NTSTATUS BCryptGetProperty(BCRYPT_HANDLE hObject, LPCWSTR pszProperty,
292  PUCHAR pbOutput, ULONG cbOutput, ULONG* pcbResult,
293  ULONG dwFlags);
294 
295  WINPR_API NTSTATUS BCryptCreateHash(BCRYPT_ALG_HANDLE hAlgorithm, BCRYPT_HASH_HANDLE* phHash,
296  PUCHAR pbHashObject, ULONG cbHashObject, PUCHAR pbSecret,
297  ULONG cbSecret, ULONG dwFlags);
298 
299  WINPR_API NTSTATUS BCryptDestroyHash(BCRYPT_HASH_HANDLE hHash);
300 
301  WINPR_API NTSTATUS BCryptHashData(BCRYPT_HASH_HANDLE hHash, PUCHAR pbInput, ULONG cbInput,
302  ULONG dwFlags);
303 
304  WINPR_API NTSTATUS BCryptFinishHash(BCRYPT_HASH_HANDLE hHash, PUCHAR pbOutput, ULONG cbOutput,
305  ULONG dwFlags);
306 
307  WINPR_API NTSTATUS BCryptGenRandom(BCRYPT_ALG_HANDLE hAlgorithm, PUCHAR pbBuffer,
308  ULONG cbBuffer, ULONG dwFlags);
309 
310  WINPR_API NTSTATUS BCryptGenerateSymmetricKey(BCRYPT_ALG_HANDLE hAlgorithm,
311  BCRYPT_KEY_HANDLE* phKey, PUCHAR pbKeyObject,
312  ULONG cbKeyObject, PUCHAR pbSecret,
313  ULONG cbSecret, ULONG dwFlags);
314 
315  WINPR_API NTSTATUS BCryptGenerateKeyPair(BCRYPT_ALG_HANDLE hAlgorithm, BCRYPT_KEY_HANDLE* phKey,
316  ULONG dwLength, ULONG dwFlags);
317 
318  WINPR_API NTSTATUS BCryptImportKey(BCRYPT_ALG_HANDLE hAlgorithm, BCRYPT_KEY_HANDLE hImportKey,
319  LPCWSTR pszBlobType, BCRYPT_KEY_HANDLE* phKey,
320  PUCHAR pbKeyObject, ULONG cbKeyObject, PUCHAR pbInput,
321  ULONG cbInput, ULONG dwFlags);
322 
323  WINPR_API NTSTATUS BCryptDestroyKey(BCRYPT_KEY_HANDLE hKey);
324 
325  WINPR_API NTSTATUS BCryptEncrypt(BCRYPT_KEY_HANDLE hKey, PUCHAR pbInput, ULONG cbInput,
326  VOID* pPaddingInfo, PUCHAR pbIV, ULONG cbIV, PUCHAR pbOutput,
327  ULONG cbOutput, ULONG* pcbResult, ULONG dwFlags);
328 
329  WINPR_API NTSTATUS BCryptDecrypt(BCRYPT_KEY_HANDLE hKey, PUCHAR pbInput, ULONG cbInput,
330  VOID* pPaddingInfo, PUCHAR pbIV, ULONG cbIV, PUCHAR pbOutput,
331  ULONG cbOutput, ULONG* pcbResult, ULONG dwFlags);
332 
333 #ifdef __cplusplus
334 }
335 #endif
336 
337 #endif /* _WIN32 */
338 #endif /* WINPR_BCRYPT_H */