20 #ifndef WINPR_BCRYPT_H
21 #define WINPR_BCRYPT_H
27 #include <winpr/winpr.h>
28 #include <winpr/wtypes.h>
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;
36 #define BCRYPT_RSA_ALGORITHM \
37 (const WCHAR*)"R\x00S\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" \
46 #define BCRYPT_RC2_ALGORITHM \
47 (const WCHAR*)"R\x00" \
49 #define BCRYPT_RC4_ALGORITHM \
50 (const WCHAR*)"R\x00" \
52 #define BCRYPT_AES_ALGORITHM \
53 (const WCHAR*)"A\x00" \
55 #define BCRYPT_DES_ALGORITHM \
56 (const WCHAR*)"D\x00" \
58 #define BCRYPT_DESX_ALGORITHM \
59 (const WCHAR*)"D\x00" \
61 #define BCRYPT_3DES_ALGORITHM \
62 (const WCHAR*)"3\x00" \
65 #define BCRYPT_3DES_112_ALGORITHM \
66 (const WCHAR*)"3\x00" \
68 "E\x00S\x00_\x001\x001\x002\x00\x00"
69 #define BCRYPT_MD2_ALGORITHM \
70 (const WCHAR*)"M\x00" \
72 #define BCRYPT_MD4_ALGORITHM \
73 (const WCHAR*)"M\x00" \
75 #define BCRYPT_MD5_ALGORITHM \
76 (const WCHAR*)"M\x00" \
78 #define BCRYPT_SHA1_ALGORITHM \
79 (const WCHAR*)"S\x00H\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" \
95 #define BCRYPT_ECDSA_ALGORITHM \
96 (const WCHAR*)"E\x00" \
100 #define BCRYPT_ECDSA_P256_ALGORITHM \
101 (const WCHAR*)"E\x00" \
104 "A\x00_\x00P\x002\x005\x006\x00\x00"
105 #define BCRYPT_ECDSA_P384_ALGORITHM \
106 (const WCHAR*)"E\x00" \
109 "A\x00_\x00P\x003\x008\x004\x00\x00"
110 #define BCRYPT_ECDSA_P521_ALGORITHM \
111 (const WCHAR*)"E\x00" \
114 "A\x00_\x00P\x005\x002\x001\x00\x00"
115 #define BCRYPT_ECDH_P256_ALGORITHM \
116 (const WCHAR*)"E\x00" \
119 "A\x00_\x00P\x002\x005\x006\x00\x00"
120 #define BCRYPT_ECDH_P384_ALGORITHM \
121 (const WCHAR*)"E\x00" \
124 "A\x00_\x00P\x003\x008\x004\x00\x00"
125 #define BCRYPT_ECDH_P521_ALGORITHM \
126 (const WCHAR*)"E\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" \
134 "A\x00R\x00N\x00G\x00\x00"
135 #define BCRYPT_RNG_DUAL_EC_ALGORITHM \
136 (const WCHAR*)"D\x00U\x00" \
138 "E\x00R\x00N\x00G\x00\x00"
140 #define MS_PRIMITIVE_PROVIDER \
141 (const WCHAR*)"M\x00i\x00" \
142 "c\x00r\x00o\x00s\x00o\x00" \
144 "\x00P\x00r\x00i\x00m\x00i\x00t\x00i\x00v\x00" \
146 "\x00P\x00r\x00o\x00v\x00i\x00" \
150 #define BCRYPT_ALG_HANDLE_HMAC_FLAG 0x00000008
151 #define BCRYPT_PROV_DISPATCH 0x00000001
153 #define BCRYPT_OBJECT_LENGTH \
154 (const WCHAR*)"O\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" \
163 #define BCRYPT_PROVIDER_HANDLE \
164 (const WCHAR*)"P\x00r\x00o\x00v\x00i\x00" \
170 #define BCRYPT_CHAINING_MODE \
171 (const WCHAR*)"C\x00h\x00" \
172 "a\x00i\x00n\x00i\x00n\x00g\x00M\x00o\x00" \
175 #define BCRYPT_BLOCK_LENGTH \
176 (const WCHAR*)"B\x00l\x00o\x00" \
178 "e\x00n\x00g\x00t\x00h\x00\x00"
179 #define BCRYPT_KEY_LENGTH \
180 (const WCHAR*)"K\x00" \
182 "e\x00n\x00g\x00t\x00h\x00\x00"
183 #define BCRYPT_KEY_OBJECT_LENGTH \
184 (const WCHAR*)"K\x00" \
189 "e\x00n\x00g\x00t\x00h\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" \
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" \
208 "c\x00t\x00i\x00v\x00" \
213 #define BCRYPT_HASH_LENGTH \
214 (const WCHAR*)"H\x00" \
217 "e\x00s\x00t\x00L\x00" \
218 "e\x00n\x00g\x00t\x00h" \
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" \
228 "d\x00i\x00n\x00g\x00S\x00" \
232 #define BCRYPT_SIGNATURE_LENGTH \
233 (const WCHAR*)"S\x00i\x00g\x00n\x00" \
234 "a\x00t\x00u\x00r\x00" \
236 "e\x00n\x00g\x00t\x00h\x00" \
238 #define BCRYPT_HASH_BLOCK_LENGTH \
239 (const WCHAR*)"H\x00" \
243 "e\x00n\x00g\x00t\x00h\x00" \
245 #define BCRYPT_AUTH_TAG_LENGTH \
246 (const WCHAR*)"A\x00u\x00t\x00h\x00T\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" \
253 #define BCRYPT_IS_KEYED_HASH \
254 (const WCHAR*)"I\x00s\x00K\x00" \
258 "a\x00s\x00h\x00\x00"
260 #define BCRYPT_KEY_DATA_BLOB \
261 (const WCHAR*)"K\x00" \
269 #define BCRYPT_BLOCK_PADDING 0x00000001
271 #define BCRYPT_KEY_DATA_BLOB_MAGIC 0x4d42444b
272 #define BCRYPT_KEY_DATA_BLOB_VERSION1 0x1
286 WINPR_API NTSTATUS BCryptOpenAlgorithmProvider(BCRYPT_ALG_HANDLE* phAlgorithm, LPCWSTR pszAlgId,
287 LPCWSTR pszImplementation, ULONG dwFlags);
289 WINPR_API NTSTATUS BCryptCloseAlgorithmProvider(BCRYPT_ALG_HANDLE hAlgorithm, ULONG dwFlags);
291 WINPR_API NTSTATUS BCryptGetProperty(BCRYPT_HANDLE hObject, LPCWSTR pszProperty,
292 PUCHAR pbOutput, ULONG cbOutput, ULONG* pcbResult,
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);
299 WINPR_API NTSTATUS BCryptDestroyHash(BCRYPT_HASH_HANDLE hHash);
301 WINPR_API NTSTATUS BCryptHashData(BCRYPT_HASH_HANDLE hHash, PUCHAR pbInput, ULONG cbInput,
304 WINPR_API NTSTATUS BCryptFinishHash(BCRYPT_HASH_HANDLE hHash, PUCHAR pbOutput, ULONG cbOutput,
307 WINPR_API NTSTATUS BCryptGenRandom(BCRYPT_ALG_HANDLE hAlgorithm, PUCHAR pbBuffer,
308 ULONG cbBuffer, ULONG dwFlags);
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);
315 WINPR_API NTSTATUS BCryptGenerateKeyPair(BCRYPT_ALG_HANDLE hAlgorithm, BCRYPT_KEY_HANDLE* phKey,
316 ULONG dwLength, ULONG dwFlags);
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);
323 WINPR_API NTSTATUS BCryptDestroyKey(BCRYPT_KEY_HANDLE hKey);
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);
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);