20 #ifndef WINPR_WINCRYPT_H
21 #define WINPR_WINCRYPT_H
23 #include <winpr/winpr.h>
24 #include <winpr/wtypes.h>
26 #include <winpr/error.h>
34 #ifndef ALG_TYPE_RESERVED7
35 #define ALG_TYPE_RESERVED7 (7 << 9)
38 #if !defined(NTDDI_VERSION) || (NTDDI_VERSION <= 0x05010200)
39 #define ALG_SID_SHA_256 12
40 #define ALG_SID_SHA_384 13
41 #define ALG_SID_SHA_512 14
42 #define CALG_SHA_256 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA_256)
43 #define CALG_SHA_384 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA_384)
44 #define CALG_SHA_512 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA_512)
51 typedef ULONG_PTR NCRYPT_HANDLE;
52 typedef ULONG_PTR NCRYPT_PROV_HANDLE;
53 typedef ULONG_PTR NCRYPT_KEY_HANDLE;
54 typedef ULONG_PTR NCRYPT_HASH_HANDLE;
55 typedef ULONG_PTR NCRYPT_SECRET_HANDLE;
59 #define GET_ALG_CLASS(x) (x & (7 << 13))
60 #define GET_ALG_TYPE(x) (x & (15 << 9))
61 #define GET_ALG_SID(x) (x & (511))
63 #define ALG_CLASS_ANY (0)
64 #define ALG_CLASS_SIGNATURE (1 << 13)
65 #define ALG_CLASS_MSG_ENCRYPT (2 << 13)
66 #define ALG_CLASS_DATA_ENCRYPT (3 << 13)
67 #define ALG_CLASS_HASH (4 << 13)
68 #define ALG_CLASS_KEY_EXCHANGE (5 << 13)
69 #define ALG_CLASS_ALL (7 << 13)
71 #define ALG_TYPE_ANY (0)
72 #define ALG_TYPE_DSS (1 << 9)
73 #define ALG_TYPE_RSA (2 << 9)
74 #define ALG_TYPE_BLOCK (3 << 9)
75 #define ALG_TYPE_STREAM (4 << 9)
76 #define ALG_TYPE_DH (5 << 9)
77 #define ALG_TYPE_SECURECHANNEL (6 << 9)
79 #define ALG_SID_ANY (0)
81 #define ALG_SID_RSA_ANY 0
82 #define ALG_SID_RSA_PKCS 1
83 #define ALG_SID_RSA_MSATWORK 2
84 #define ALG_SID_RSA_ENTRUST 3
85 #define ALG_SID_RSA_PGP 4
87 #define ALG_SID_DSS_ANY 0
88 #define ALG_SID_DSS_PKCS 1
89 #define ALG_SID_DSS_DMS 2
92 #define ALG_SID_3DES 3
93 #define ALG_SID_DESX 4
94 #define ALG_SID_IDEA 5
95 #define ALG_SID_CAST 6
96 #define ALG_SID_SAFERSK64 7
97 #define ALG_SID_SAFERSK128 8
98 #define ALG_SID_3DES_112 9
99 #define ALG_SID_CYLINK_MEK 12
100 #define ALG_SID_RC5 13
102 #define ALG_SID_AES_128 14
103 #define ALG_SID_AES_192 15
104 #define ALG_SID_AES_256 16
105 #define ALG_SID_AES 17
107 #define ALG_SID_SKIPJACK 10
108 #define ALG_SID_TEK 11
110 #define CRYPT_MODE_CBCI 6
111 #define CRYPT_MODE_CFBP 7
112 #define CRYPT_MODE_OFBP 8
113 #define CRYPT_MODE_CBCOFM 9
114 #define CRYPT_MODE_CBCOFMI 10
116 #define ALG_SID_RC2 2
118 #define ALG_SID_RC4 1
119 #define ALG_SID_SEAL 2
121 #define ALG_SID_DH_SANDF 1
122 #define ALG_SID_DH_EPHEM 2
123 #define ALG_SID_AGREED_KEY_ANY 3
124 #define ALG_SID_KEA 4
126 #define ALG_SID_ECDH 5
128 #define ALG_SID_MD2 1
129 #define ALG_SID_MD4 2
130 #define ALG_SID_MD5 3
131 #define ALG_SID_SHA 4
132 #define ALG_SID_SHA1 4
133 #define ALG_SID_MAC 5
134 #define ALG_SID_RIPEMD 6
135 #define ALG_SID_RIPEMD160 7
136 #define ALG_SID_SSL3SHAMD5 8
137 #define ALG_SID_HMAC 9
138 #define ALG_SID_TLS1PRF 10
140 #define ALG_SID_HASH_REPLACE_OWF 11
142 #define ALG_SID_SHA_256 12
143 #define ALG_SID_SHA_384 13
144 #define ALG_SID_SHA_512 14
146 #define ALG_SID_SSL3_MASTER 1
147 #define ALG_SID_SCHANNEL_MASTER_HASH 2
148 #define ALG_SID_SCHANNEL_MAC_KEY 3
149 #define ALG_SID_PCT1_MASTER 4
150 #define ALG_SID_SSL2_MASTER 5
151 #define ALG_SID_TLS1_MASTER 6
152 #define ALG_SID_SCHANNEL_ENC_KEY 7
154 #define ALG_SID_ECMQV 1
156 #define CALG_MD2 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MD2)
157 #define CALG_MD4 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MD4)
158 #define CALG_MD5 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MD5)
159 #define CALG_SHA (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA)
160 #define CALG_SHA1 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA1)
161 #define CALG_MAC (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MAC)
162 #define CALG_RSA_SIGN (ALG_CLASS_SIGNATURE | ALG_TYPE_RSA | ALG_SID_RSA_ANY)
163 #define CALG_DSS_SIGN (ALG_CLASS_SIGNATURE | ALG_TYPE_DSS | ALG_SID_DSS_ANY)
165 #define CALG_NO_SIGN (ALG_CLASS_SIGNATURE | ALG_TYPE_ANY | ALG_SID_ANY)
167 #define CALG_RSA_KEYX (ALG_CLASS_KEY_EXCHANGE | ALG_TYPE_RSA | ALG_SID_RSA_ANY)
168 #define CALG_DES (ALG_CLASS_DATA_ENCRYPT | ALG_TYPE_BLOCK | ALG_SID_DES)
169 #define CALG_3DES_112 (ALG_CLASS_DATA_ENCRYPT | ALG_TYPE_BLOCK | ALG_SID_3DES_112)
170 #define CALG_3DES (ALG_CLASS_DATA_ENCRYPT | ALG_TYPE_BLOCK | ALG_SID_3DES)
171 #define CALG_DESX (ALG_CLASS_DATA_ENCRYPT | ALG_TYPE_BLOCK | ALG_SID_DESX)
172 #define CALG_RC2 (ALG_CLASS_DATA_ENCRYPT | ALG_TYPE_BLOCK | ALG_SID_RC2)
173 #define CALG_RC4 (ALG_CLASS_DATA_ENCRYPT | ALG_TYPE_STREAM | ALG_SID_RC4)
174 #define CALG_SEAL (ALG_CLASS_DATA_ENCRYPT | ALG_TYPE_STREAM | ALG_SID_SEAL)
175 #define CALG_DH_SF (ALG_CLASS_KEY_EXCHANGE | ALG_TYPE_DH | ALG_SID_DH_SANDF)
176 #define CALG_DH_EPHEM (ALG_CLASS_KEY_EXCHANGE | ALG_TYPE_DH | ALG_SID_DH_EPHEM)
177 #define CALG_AGREEDKEY_ANY (ALG_CLASS_KEY_EXCHANGE | ALG_TYPE_DH | ALG_SID_AGREED_KEY_ANY)
178 #define CALG_KEA_KEYX (ALG_CLASS_KEY_EXCHANGE | ALG_TYPE_DH | ALG_SID_KEA)
179 #define CALG_HUGHES_MD5 (ALG_CLASS_KEY_EXCHANGE | ALG_TYPE_ANY | ALG_SID_MD5)
180 #define CALG_SKIPJACK (ALG_CLASS_DATA_ENCRYPT | ALG_TYPE_BLOCK | ALG_SID_SKIPJACK)
181 #define CALG_TEK (ALG_CLASS_DATA_ENCRYPT | ALG_TYPE_BLOCK | ALG_SID_TEK)
182 #define CALG_CYLINK_MEK (ALG_CLASS_DATA_ENCRYPT | ALG_TYPE_BLOCK | ALG_SID_CYLINK_MEK)
183 #define CALG_SSL3_SHAMD5 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SSL3SHAMD5)
184 #define CALG_SSL3_MASTER (ALG_CLASS_MSG_ENCRYPT | ALG_TYPE_SECURECHANNEL | ALG_SID_SSL3_MASTER)
185 #define CALG_SCHANNEL_MASTER_HASH \
186 (ALG_CLASS_MSG_ENCRYPT | ALG_TYPE_SECURECHANNEL | ALG_SID_SCHANNEL_MASTER_HASH)
187 #define CALG_SCHANNEL_MAC_KEY \
188 (ALG_CLASS_MSG_ENCRYPT | ALG_TYPE_SECURECHANNEL | ALG_SID_SCHANNEL_MAC_KEY)
189 #define CALG_SCHANNEL_ENC_KEY \
190 (ALG_CLASS_MSG_ENCRYPT | ALG_TYPE_SECURECHANNEL | ALG_SID_SCHANNEL_ENC_KEY)
191 #define CALG_PCT1_MASTER (ALG_CLASS_MSG_ENCRYPT | ALG_TYPE_SECURECHANNEL | ALG_SID_PCT1_MASTER)
192 #define CALG_SSL2_MASTER (ALG_CLASS_MSG_ENCRYPT | ALG_TYPE_SECURECHANNEL | ALG_SID_SSL2_MASTER)
193 #define CALG_TLS1_MASTER (ALG_CLASS_MSG_ENCRYPT | ALG_TYPE_SECURECHANNEL | ALG_SID_TLS1_MASTER)
194 #define CALG_RC5 (ALG_CLASS_DATA_ENCRYPT | ALG_TYPE_BLOCK | ALG_SID_RC5)
195 #define CALG_HMAC (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_HMAC)
196 #define CALG_TLS1PRF (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_TLS1PRF)
198 #define CALG_HASH_REPLACE_OWF (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_HASH_REPLACE_OWF)
199 #define CALG_AES_128 (ALG_CLASS_DATA_ENCRYPT | ALG_TYPE_BLOCK | ALG_SID_AES_128)
200 #define CALG_AES_192 (ALG_CLASS_DATA_ENCRYPT | ALG_TYPE_BLOCK | ALG_SID_AES_192)
201 #define CALG_AES_256 (ALG_CLASS_DATA_ENCRYPT | ALG_TYPE_BLOCK | ALG_SID_AES_256)
202 #define CALG_AES (ALG_CLASS_DATA_ENCRYPT | ALG_TYPE_BLOCK | ALG_SID_AES)
204 #define CALG_SHA_256 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA_256)
205 #define CALG_SHA_384 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA_384)
206 #define CALG_SHA_512 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA_512)
208 #define CALG_ECDH (ALG_CLASS_KEY_EXCHANGE | ALG_TYPE_DH | ALG_SID_ECDH)
209 #define CALG_ECMQV (ALG_CLASS_KEY_EXCHANGE | ALG_TYPE_ANY | ALG_SID_ECMQV)
264 typedef void* HCERTSTORE;
265 typedef ULONG_PTR HCRYPTPROV;
266 typedef ULONG_PTR HCRYPTPROV_LEGACY;
270 DWORD dwCertEncodingType;
274 HCERTSTORE hCertStore;
278 #if !defined(AT_KEYEXCHANGE)
279 #define AT_KEYEXCHANGE (1)
281 #if !defined(AT_SIGNATURE)
282 #define AT_SIGNATURE (2)
284 #if !defined(AT_AUTHENTICATE)
285 #define AT_AUTHENTICATE (3)
288 #define CERT_ENCODING_TYPE_MASK 0x0000FFFF
289 #define CMSG_ENCODING_TYPE_MASK 0xFFFF0000
290 #define GET_CERT_ENCODING_TYPE(x) (x & CERT_ENCODING_TYPE_MASK)
291 #define GET_CMSG_ENCODING_TYPE(x) (x & CMSG_ENCODING_TYPE_MASK)
293 #define CRYPT_ASN_ENCODING 0x00000001
294 #define CRYPT_NDR_ENCODING 0x00000002
295 #define X509_ASN_ENCODING 0x00000001
296 #define X509_NDR_ENCODING 0x00000002
297 #define PKCS_7_ASN_ENCODING 0x00010000
298 #define PKCS_7_NDR_ENCODING 0x00020000
300 #define CERT_KEY_PROV_HANDLE_PROP_ID 1
301 #define CERT_KEY_PROV_INFO_PROP_ID 2
302 #define CERT_SHA1_HASH_PROP_ID 3
303 #define CERT_MD5_HASH_PROP_ID 4
304 #define CERT_HASH_PROP_ID CERT_SHA1_HASH_PROP_ID
305 #define CERT_KEY_CONTEXT_PROP_ID 5
306 #define CERT_KEY_SPEC_PROP_ID 6
307 #define CERT_IE30_RESERVED_PROP_ID 7
308 #define CERT_PUBKEY_HASH_RESERVED_PROP_ID 8
309 #define CERT_ENHKEY_USAGE_PROP_ID 9
310 #define CERT_CTL_USAGE_PROP_ID CERT_ENHKEY_USAGE_PROP_ID
311 #define CERT_NEXT_UPDATE_LOCATION_PROP_ID 10
312 #define CERT_FRIENDLY_NAME_PROP_ID 11
313 #define CERT_PVK_FILE_PROP_ID 12
314 #define CERT_DESCRIPTION_PROP_ID 13
315 #define CERT_ACCESS_STATE_PROP_ID 14
316 #define CERT_SIGNATURE_HASH_PROP_ID 15
317 #define CERT_SMART_CARD_DATA_PROP_ID 16
318 #define CERT_EFS_PROP_ID 17
319 #define CERT_FORTEZZA_DATA_PROP_ID 18
320 #define CERT_ARCHIVED_PROP_ID 19
321 #define CERT_KEY_IDENTIFIER_PROP_ID 20
322 #define CERT_AUTO_ENROLL_PROP_ID 21
323 #define CERT_PUBKEY_ALG_PARA_PROP_ID 22
324 #define CERT_CROSS_CERT_DIST_POINTS_PROP_ID 23
325 #define CERT_ISSUER_PUBLIC_KEY_MD5_HASH_PROP_ID 24
326 #define CERT_SUBJECT_PUBLIC_KEY_MD5_HASH_PROP_ID 25
327 #define CERT_ENROLLMENT_PROP_ID 26
328 #define CERT_DATE_STAMP_PROP_ID 27
329 #define CERT_ISSUER_SERIAL_NUMBER_MD5_HASH_PROP_ID 28
330 #define CERT_SUBJECT_NAME_MD5_HASH_PROP_ID 29
331 #define CERT_EXTENDED_ERROR_INFO_PROP_ID 30
332 #define CERT_RENEWAL_PROP_ID 64
333 #define CERT_ARCHIVED_KEY_HASH_PROP_ID 65
334 #define CERT_AUTO_ENROLL_RETRY_PROP_ID 66
335 #define CERT_AIA_URL_RETRIEVED_PROP_ID 67
336 #define CERT_AUTHORITY_INFO_ACCESS_PROP_ID 68
337 #define CERT_BACKED_UP_PROP_ID 69
338 #define CERT_OCSP_RESPONSE_PROP_ID 70
339 #define CERT_REQUEST_ORIGINATOR_PROP_ID 71
340 #define CERT_SOURCE_LOCATION_PROP_ID 72
341 #define CERT_SOURCE_URL_PROP_ID 73
342 #define CERT_NEW_KEY_PROP_ID 74
343 #define CERT_OCSP_CACHE_PREFIX_PROP_ID 75
344 #define CERT_SMART_CARD_ROOT_INFO_PROP_ID 76
345 #define CERT_NO_AUTO_EXPIRE_CHECK_PROP_ID 77
346 #define CERT_NCRYPT_KEY_HANDLE_PROP_ID 78
347 #define CERT_HCRYPTPROV_OR_NCRYPT_KEY_HANDLE_PROP_ID 79
348 #define CERT_SUBJECT_INFO_ACCESS_PROP_ID 80
349 #define CERT_CA_OCSP_AUTHORITY_INFO_ACCESS_PROP_ID 81
350 #define CERT_CA_DISABLE_CRL_PROP_ID 82
351 #define CERT_ROOT_PROGRAM_CERT_POLICIES_PROP_ID 83
352 #define CERT_ROOT_PROGRAM_NAME_CONSTRAINTS_PROP_ID 84
353 #define CERT_SUBJECT_OCSP_AUTHORITY_INFO_ACCESS_PROP_ID 85
354 #define CERT_SUBJECT_DISABLE_CRL_PROP_ID 86
355 #define CERT_CEP_PROP_ID 87
356 #define CERT_SIGN_HASH_CNG_ALG_PROP_ID 89
357 #define CERT_SCARD_PIN_ID_PROP_ID 90
358 #define CERT_SCARD_PIN_INFO_PROP_ID 91
359 #define CERT_SUBJECT_PUB_KEY_BIT_LENGTH_PROP_ID 92
360 #define CERT_PUB_KEY_CNG_ALG_BIT_LENGTH_PROP_ID 93
361 #define CERT_ISSUER_PUB_KEY_BIT_LENGTH_PROP_ID 94
362 #define CERT_ISSUER_CHAIN_SIGN_HASH_CNG_ALG_PROP_ID 95
363 #define CERT_ISSUER_CHAIN_PUB_KEY_CNG_ALG_BIT_LENGTH_PROP_ID 96
364 #define CERT_NO_EXPIRE_NOTIFICATION_PROP_ID 97
365 #define CERT_AUTH_ROOT_SHA256_HASH_PROP_ID 98
366 #define CERT_NCRYPT_KEY_HANDLE_TRANSFER_PROP_ID 99
367 #define CERT_HCRYPTPROV_TRANSFER_PROP_ID 100
368 #define CERT_SMART_CARD_READER_PROP_ID 101
369 #define CERT_SEND_AS_TRUSTED_ISSUER_PROP_ID 102
370 #define CERT_KEY_REPAIR_ATTEMPTED_PROP_ID 103
371 #define CERT_DISALLOWED_FILETIME_PROP_ID 104
372 #define CERT_ROOT_PROGRAM_CHAIN_POLICIES_PROP_ID 105
373 #define CERT_SMART_CARD_READER_NON_REMOVABLE_PROP_ID 106
374 #define CERT_SHA256_HASH_PROP_ID 107
375 #define CERT_SCEP_SERVER_CERTS_PROP_ID 108
376 #define CERT_SCEP_RA_SIGNATURE_CERT_PROP_ID 109
377 #define CERT_SCEP_RA_ENCRYPTION_CERT_PROP_ID 110
378 #define CERT_SCEP_CA_CERT_PROP_ID 111
379 #define CERT_SCEP_SIGNER_CERT_PROP_ID 112
380 #define CERT_SCEP_NONCE_PROP_ID 113
381 #define CERT_SCEP_ENCRYPT_HASH_CNG_ALG_PROP_ID 114
382 #define CERT_SCEP_FLAGS_PROP_ID 115
383 #define CERT_SCEP_GUID_PROP_ID 116
384 #define CERT_SERIALIZABLE_KEY_CONTEXT_PROP_ID 117
385 #define CERT_ISOLATED_KEY_PROP_ID 118
386 #define CERT_SERIAL_CHAIN_PROP_ID 119
387 #define CERT_KEY_CLASSIFICATION_PROP_ID 120
388 #define CERT_OCSP_MUST_STAPLE_PROP_ID 121
389 #define CERT_DISALLOWED_ENHKEY_USAGE_PROP_ID 122
390 #define CERT_NONCOMPLIANT_ROOT_URL_PROP_ID 123
391 #define CERT_PIN_SHA256_HASH_PROP_ID 124
392 #define CERT_CLR_DELETE_KEY_PROP_ID 125
393 #define CERT_NOT_BEFORE_FILETIME_PROP_ID 126
394 #define CERT_NOT_BEFORE_ENHKEY_USAGE_PROP_ID 127
396 #define CERT_FIRST_RESERVED_PROP_ID 107
397 #define CERT_LAST_RESERVED_PROP_ID 0x00007fff
398 #define CERT_FIRST_USER_PROP_ID 0x8000
399 #define CERT_LAST_USER_PROP_ID 0x0000ffff
401 #define CERT_COMPARE_MASK 0xFFFF
402 #define CERT_COMPARE_SHIFT 16
403 #define CERT_COMPARE_ANY 0
404 #define CERT_COMPARE_SHA1_HASH 1
405 #define CERT_COMPARE_NAME 2
406 #define CERT_COMPARE_ATTR 3
407 #define CERT_COMPARE_MD5_HASH 4
408 #define CERT_COMPARE_PROPERTY 5
409 #define CERT_COMPARE_PUBLIC_KEY 6
410 #define CERT_COMPARE_HASH CERT_COMPARE_SHA1_HASH
411 #define CERT_COMPARE_NAME_STR_A 7
412 #define CERT_COMPARE_NAME_STR_W 8
413 #define CERT_COMPARE_KEY_SPEC 9
414 #define CERT_COMPARE_ENHKEY_USAGE 10
415 #define CERT_COMPARE_CTL_USAGE CERT_COMPARE_ENHKEY_USAGE
416 #define CERT_COMPARE_SUBJECT_CERT 11
417 #define CERT_COMPARE_ISSUER_OF 12
418 #define CERT_COMPARE_EXISTING 13
419 #define CERT_COMPARE_SIGNATURE_HASH 14
420 #define CERT_COMPARE_KEY_IDENTIFIER 15
421 #define CERT_COMPARE_CERT_ID 16
422 #define CERT_COMPARE_CROSS_CERT_DIST_POINTS 17
423 #define CERT_COMPARE_PUBKEY_MD5_HASH 18
424 #define CERT_COMPARE_SUBJECT_INFO_ACCESS 19
425 #define CERT_COMPARE_HASH_STR 20
426 #define CERT_COMPARE_HAS_PRIVATE_KEY 21
428 #define CERT_FIND_ANY (CERT_COMPARE_ANY << CERT_COMPARE_SHIFT)
429 #define CERT_FIND_SHA1_HASH (CERT_COMPARE_SHA1_HASH << CERT_COMPARE_SHIFT)
430 #define CERT_FIND_MD5_HASH (CERT_COMPARE_MD5_HASH << CERT_COMPARE_SHIFT)
431 #define CERT_FIND_SIGNATURE_HASH (CERT_COMPARE_SIGNATURE_HASH << CERT_COMPARE_SHIFT)
432 #define CERT_FIND_KEY_IDENTIFIER (CERT_COMPARE_KEY_IDENTIFIER << CERT_COMPARE_SHIFT)
433 #define CERT_FIND_HASH CERT_FIND_SHA1_HASH
434 #define CERT_FIND_PROPERTY (CERT_COMPARE_PROPERTY << CERT_COMPARE_SHIFT)
435 #define CERT_FIND_PUBLIC_KEY (CERT_COMPARE_PUBLIC_KEY << CERT_COMPARE_SHIFT)
436 #define CERT_FIND_SUBJECT_NAME (CERT_COMPARE_NAME << CERT_COMPARE_SHIFT | CERT_INFO_SUBJECT_FLAG)
437 #define CERT_FIND_SUBJECT_ATTR (CERT_COMPARE_ATTR << CERT_COMPARE_SHIFT | CERT_INFO_SUBJECT_FLAG)
438 #define CERT_FIND_ISSUER_NAME (CERT_COMPARE_NAME << CERT_COMPARE_SHIFT | CERT_INFO_ISSUER_FLAG)
439 #define CERT_FIND_ISSUER_ATTR (CERT_COMPARE_ATTR << CERT_COMPARE_SHIFT | CERT_INFO_ISSUER_FLAG)
440 #define CERT_FIND_SUBJECT_STR_A \
441 (CERT_COMPARE_NAME_STR_A << CERT_COMPARE_SHIFT | CERT_INFO_SUBJECT_FLAG)
442 #define CERT_FIND_SUBJECT_STR_W \
443 (CERT_COMPARE_NAME_STR_W << CERT_COMPARE_SHIFT | CERT_INFO_SUBJECT_FLAG)
444 #define CERT_FIND_SUBJECT_STR CERT_FIND_SUBJECT_STR_W
445 #define CERT_FIND_ISSUER_STR_A \
446 (CERT_COMPARE_NAME_STR_A << CERT_COMPARE_SHIFT | CERT_INFO_ISSUER_FLAG)
447 #define CERT_FIND_ISSUER_STR_W \
448 (CERT_COMPARE_NAME_STR_W << CERT_COMPARE_SHIFT | CERT_INFO_ISSUER_FLAG)
449 #define CERT_FIND_ISSUER_STR CERT_FIND_ISSUER_STR_W
450 #define CERT_FIND_KEY_SPEC (CERT_COMPARE_KEY_SPEC << CERT_COMPARE_SHIFT)
451 #define CERT_FIND_ENHKEY_USAGE (CERT_COMPARE_ENHKEY_USAGE << CERT_COMPARE_SHIFT)
452 #define CERT_FIND_CTL_USAGE CERT_FIND_ENHKEY_USAGE
453 #define CERT_FIND_SUBJECT_CERT (CERT_COMPARE_SUBJECT_CERT << CERT_COMPARE_SHIFT)
454 #define CERT_FIND_ISSUER_OF (CERT_COMPARE_ISSUER_OF << CERT_COMPARE_SHIFT)
455 #define CERT_FIND_EXISTING (CERT_COMPARE_EXISTING << CERT_COMPARE_SHIFT)
456 #define CERT_FIND_CERT_ID (CERT_COMPARE_CERT_ID << CERT_COMPARE_SHIFT)
457 #define CERT_FIND_CROSS_CERT_DIST_POINTS (CERT_COMPARE_CROSS_CERT_DIST_POINTS << CERT_COMPARE_SHIFT)
458 #define CERT_FIND_PUBKEY_MD5_HASH (CERT_COMPARE_PUBKEY_MD5_HASH << CERT_COMPARE_SHIFT)
459 #define CERT_FIND_SUBJECT_INFO_ACCESS (CERT_COMPARE_SUBJECT_INFO_ACCESS << CERT_COMPARE_SHIFT)
460 #define CERT_FIND_HASH_STR (CERT_COMPARE_HASH_STR << CERT_COMPARE_SHIFT)
461 #define CERT_FIND_HAS_PRIVATE_KEY (CERT_COMPARE_HAS_PRIVATE_KEY << CERT_COMPARE_SHIFT)
463 #define CERT_FIND_OPTIONAL_ENHKEY_USAGE_FLAG 0x1
464 #define CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG 0x2
465 #define CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG 0x4
466 #define CERT_FIND_NO_ENHKEY_USAGE_FLAG 0x8
467 #define CERT_FIND_OR_ENHKEY_USAGE_FLAG 0x10
468 #define CERT_FIND_VALID_ENHKEY_USAGE_FLAG 0x20
469 #define CERT_FIND_OPTIONAL_CTL_USAGE_FLAG CERT_FIND_OPTIONAL_ENHKEY_USAGE_FLAG
470 #define CERT_FIND_EXT_ONLY_CTL_USAGE_FLAG CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG
471 #define CERT_FIND_PROP_ONLY_CTL_USAGE_FLAG CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG
472 #define CERT_FIND_NO_CTL_USAGE_FLAG CERT_FIND_NO_ENHKEY_USAGE_FLAG
473 #define CERT_FIND_OR_CTL_USAGE_FLAG CERT_FIND_OR_ENHKEY_USAGE_FLAG
474 #define CERT_FIND_VALID_CTL_USAGE_FLAG CERT_FIND_VALID_ENHKEY_USAGE_FLAG
476 #define CERT_NAME_EMAIL_TYPE 1
477 #define CERT_NAME_RDN_TYPE 2
478 #define CERT_NAME_ATTR_TYPE 3
479 #define CERT_NAME_SIMPLE_DISPLAY_TYPE 4
480 #define CERT_NAME_FRIENDLY_DISPLAY_TYPE 5
481 #define CERT_NAME_DNS_TYPE 6
482 #define CERT_NAME_URL_TYPE 7
483 #define CERT_NAME_UPN_TYPE 8
485 #define CERT_NAME_ISSUER_FLAG 0x1
486 #define CERT_NAME_DISABLE_IE4_UTF8_FLAG 0x00010000
488 #define CERT_NAME_SEARCH_ALL_NAMES_FLAG 0x2
490 #define CERT_STORE_PROV_MSG ((LPCSTR)1)
491 #define CERT_STORE_PROV_MEMORY ((LPCSTR)2)
492 #define CERT_STORE_PROV_FILE ((LPCSTR)3)
493 #define CERT_STORE_PROV_REG ((LPCSTR)4)
494 #define CERT_STORE_PROV_PKCS7 ((LPCSTR)5)
495 #define CERT_STORE_PROV_SERIALIZED ((LPCSTR)6)
496 #define CERT_STORE_PROV_FILENAME_A ((LPCSTR)7)
497 #define CERT_STORE_PROV_FILENAME_W ((LPCSTR)8)
498 #define CERT_STORE_PROV_FILENAME CERT_STORE_PROV_FILENAME_W
499 #define CERT_STORE_PROV_SYSTEM_A ((LPCSTR)9)
500 #define CERT_STORE_PROV_SYSTEM_W ((LPCSTR)10)
501 #define CERT_STORE_PROV_SYSTEM CERT_STORE_PROV_SYSTEM_W
502 #define CERT_STORE_PROV_COLLECTION ((LPCSTR)11)
503 #define CERT_STORE_PROV_SYSTEM_REGISTRY_A ((LPCSTR)12)
504 #define CERT_STORE_PROV_SYSTEM_REGISTRY_W ((LPCSTR)13)
505 #define CERT_STORE_PROV_SYSTEM_REGISTRY CERT_STORE_PROV_SYSTEM_REGISTRY_W
506 #define CERT_STORE_PROV_PHYSICAL_W ((LPCSTR)14)
507 #define CERT_STORE_PROV_PHYSICAL CERT_STORE_PROV_PHYSICAL_W
508 #define CERT_STORE_PROV_SMART_CARD_W ((LPCSTR)15)
509 #define CERT_STORE_PROV_SMART_CARD CERT_STORE_PROV_SMART_CARD_W
510 #define CERT_STORE_PROV_LDAP_W ((LPCSTR)16)
511 #define CERT_STORE_PROV_LDAP CERT_STORE_PROV_LDAP_W
512 #define CERT_STORE_PROV_PKCS12 ((LPCSTR)17)
513 #define sz_CERT_STORE_PROV_MEMORY "Memory"
514 #define sz_CERT_STORE_PROV_FILENAME_W "File"
515 #define sz_CERT_STORE_PROV_FILENAME sz_CERT_STORE_PROV_FILENAME_W
516 #define sz_CERT_STORE_PROV_SYSTEM_W "System"
517 #define sz_CERT_STORE_PROV_SYSTEM sz_CERT_STORE_PROV_SYSTEM_W
518 #define sz_CERT_STORE_PROV_PKCS7 "PKCS7"
519 #define sz_CERT_STORE_PROV_PKCS12 "PKCS12"
520 #define sz_CERT_STORE_PROV_SERIALIZED "Serialized"
521 #define sz_CERT_STORE_PROV_COLLECTION "Collection"
522 #define sz_CERT_STORE_PROV_SYSTEM_REGISTRY_W "SystemRegistry"
523 #define sz_CERT_STORE_PROV_SYSTEM_REGISTRY sz_CERT_STORE_PROV_SYSTEM_REGISTRY_W
524 #define sz_CERT_STORE_PROV_PHYSICAL_W "Physical"
525 #define sz_CERT_STORE_PROV_PHYSICAL sz_CERT_STORE_PROV_PHYSICAL_W
526 #define sz_CERT_STORE_PROV_SMART_CARD_W "SmartCard"
527 #define sz_CERT_STORE_PROV_SMART_CARD sz_CERT_STORE_PROV_SMART_CARD_W
528 #define sz_CERT_STORE_PROV_LDAP_W "Ldap"
529 #define sz_CERT_STORE_PROV_LDAP sz_CERT_STORE_PROV_LDAP_W
531 #define CERT_STORE_SIGNATURE_FLAG 0x00000001
532 #define CERT_STORE_TIME_VALIDITY_FLAG 0x00000002
533 #define CERT_STORE_REVOCATION_FLAG 0x00000004
534 #define CERT_STORE_NO_CRL_FLAG 0x00010000
535 #define CERT_STORE_NO_ISSUER_FLAG 0x00020000
536 #define CERT_STORE_BASE_CRL_FLAG 0x00000100
537 #define CERT_STORE_DELTA_CRL_FLAG 0x00000200
539 #define CERT_STORE_NO_CRYPT_RELEASE_FLAG 0x00000001
540 #define CERT_STORE_SET_LOCALIZED_NAME_FLAG 0x00000002
541 #define CERT_STORE_DEFER_CLOSE_UNTIL_LAST_FREE_FLAG 0x00000004
542 #define CERT_STORE_DELETE_FLAG 0x00000010
543 #define CERT_STORE_UNSAFE_PHYSICAL_FLAG 0x00000020
544 #define CERT_STORE_SHARE_STORE_FLAG 0x00000040
545 #define CERT_STORE_SHARE_CONTEXT_FLAG 0x00000080
546 #define CERT_STORE_MANIFOLD_FLAG 0x00000100
547 #define CERT_STORE_ENUM_ARCHIVED_FLAG 0x00000200
548 #define CERT_STORE_UPDATE_KEYID_FLAG 0x00000400
549 #define CERT_STORE_BACKUP_RESTORE_FLAG 0x00000800
550 #define CERT_STORE_READONLY_FLAG 0x00008000
551 #define CERT_STORE_OPEN_EXISTING_FLAG 0x00004000
552 #define CERT_STORE_CREATE_NEW_FLAG 0x00002000
553 #define CERT_STORE_MAXIMUM_ALLOWED_FLAG 0x00001000
555 #define CERT_SYSTEM_STORE_MASK 0xFFFF0000
556 #define CERT_SYSTEM_STORE_RELOCATE_FLAG 0x80000000
557 #define CERT_SYSTEM_STORE_UNPROTECTED_FLAG 0x40000000
558 #define CERT_SYSTEM_STORE_DEFER_READ_FLAG 0x20000000
559 #define CERT_SYSTEM_STORE_LOCATION_MASK 0x00FF0000
560 #define CERT_SYSTEM_STORE_LOCATION_SHIFT 16
561 #define CERT_SYSTEM_STORE_CURRENT_USER_ID 1
562 #define CERT_SYSTEM_STORE_LOCAL_MACHINE_ID 2
563 #define CERT_SYSTEM_STORE_CURRENT_SERVICE_ID 4
564 #define CERT_SYSTEM_STORE_SERVICES_ID 5
565 #define CERT_SYSTEM_STORE_USERS_ID 6
566 #define CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY_ID 7
567 #define CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY_ID 8
568 #define CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE_ID 9
570 #define CERT_SYSTEM_STORE_CURRENT_USER \
571 (CERT_SYSTEM_STORE_CURRENT_USER_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT)
572 #define CERT_SYSTEM_STORE_LOCAL_MACHINE \
573 (CERT_SYSTEM_STORE_LOCAL_MACHINE_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT)
574 #define CERT_SYSTEM_STORE_CURRENT_SERVICE \
575 (CERT_SYSTEM_STORE_CURRENT_SERVICE_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT)
576 #define CERT_SYSTEM_STORE_SERVICES \
577 (CERT_SYSTEM_STORE_SERVICES_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT)
578 #define CERT_SYSTEM_STORE_USERS (CERT_SYSTEM_STORE_USERS_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT)
579 #define CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY \
580 (CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT)
581 #define CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY \
582 (CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT)
583 #define CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE \
584 (CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT)
586 WINPR_API HCERTSTORE CertOpenStore(LPCSTR lpszStoreProvider, DWORD dwMsgAndCertEncodingType,
587 HCRYPTPROV_LEGACY hCryptProv, DWORD dwFlags,
const void* pvPara);
589 WINPR_API HCERTSTORE CertOpenSystemStoreW(HCRYPTPROV_LEGACY hProv, LPCWSTR szSubsystemProtocol);
590 WINPR_API HCERTSTORE CertOpenSystemStoreA(HCRYPTPROV_LEGACY hProv, LPCSTR szSubsystemProtocol);
592 WINPR_API BOOL CertCloseStore(HCERTSTORE hCertStore, DWORD dwFlags);
595 #define CertOpenSystemStore CertOpenSystemStoreW
597 #define CertOpenSystemStore CertOpenSystemStoreA
605 WINPR_API
PCCERT_CONTEXT CertFindCertificateInStore(HCERTSTORE hCertStore,
606 DWORD dwCertEncodingType, DWORD dwFindFlags,
607 DWORD dwFindType,
const void* pvFindPara,
610 WINPR_API
PCCERT_CONTEXT CertEnumCertificatesInStore(HCERTSTORE hCertStore,
613 WINPR_API DWORD CertGetNameStringW(
PCCERT_CONTEXT pCertContext, DWORD dwType, DWORD dwFlags,
614 void* pvTypePara, LPWSTR pszNameString, DWORD cchNameString);
615 WINPR_API DWORD CertGetNameStringA(
PCCERT_CONTEXT pCertContext, DWORD dwType, DWORD dwFlags,
616 void* pvTypePara, LPSTR pszNameString, DWORD cchNameString);
623 #define CertGetNameString CertGetNameStringW
625 #define CertGetNameString CertGetNameStringA
632 #define CRYPTPROTECTMEMORY_BLOCK_SIZE 16
634 #define CRYPTPROTECTMEMORY_SAME_PROCESS 0x00000000
635 #define CRYPTPROTECTMEMORY_CROSS_PROCESS 0x00000001
636 #define CRYPTPROTECTMEMORY_SAME_LOGON 0x00000002
638 #define CRYPTPROTECT_PROMPT_ON_UNPROTECT 0x00000001
639 #define CRYPTPROTECT_PROMPT_ON_PROTECT 0x00000002
640 #define CRYPTPROTECT_PROMPT_RESERVED 0x00000004
641 #define CRYPTPROTECT_PROMPT_STRONG 0x00000008
642 #define CRYPTPROTECT_PROMPT_REQUIRE_STRONG 0x00000010
644 #define CRYPTPROTECT_UI_FORBIDDEN 0x1
645 #define CRYPTPROTECT_LOCAL_MACHINE 0x4
646 #define CRYPTPROTECT_CRED_SYNC 0x8
647 #define CRYPTPROTECT_AUDIT 0x10
648 #define CRYPTPROTECT_NO_RECOVERY 0x20
649 #define CRYPTPROTECT_VERIFY_PROTECTION 0x40
650 #define CRYPTPROTECT_CRED_REGENERATE 0x80
652 #define CRYPTPROTECT_FIRST_RESERVED_FLAGVAL 0x0FFFFFFF
653 #define CRYPTPROTECT_LAST_RESERVED_FLAGVAL 0xFFFFFFFF
663 #define CRYPTPROTECT_DEFAULT_PROVIDER \
665 0xdf9d8cd0, 0x1501, 0x11d1, \
667 0x8c, 0x7a, 0x00, 0xc0, 0x4f, 0xc2, 0x97, 0xeb \
676 WINPR_API BOOL CryptProtectMemory(LPVOID pData, DWORD cbData, DWORD dwFlags);
677 WINPR_API BOOL CryptUnprotectMemory(LPVOID pData, DWORD cbData, DWORD dwFlags);
679 WINPR_API BOOL CryptProtectData(
DATA_BLOB* pDataIn, LPCWSTR szDataDescr,
680 DATA_BLOB* pOptionalEntropy, PVOID pvReserved,
683 WINPR_API BOOL CryptUnprotectData(
DATA_BLOB* pDataIn, LPWSTR* ppszDataDescr,
684 DATA_BLOB* pOptionalEntropy, PVOID pvReserved,
692 #define CRYPT_STRING_BASE64HEADER 0x00000000
693 #define CRYPT_STRING_BASE64 0x00000001
694 #define CRYPT_STRING_BINARY 0x00000002
695 #define CRYPT_STRING_BASE64REQUESTHEADER 0x00000003
696 #define CRYPT_STRING_HEX 0x00000004
697 #define CRYPT_STRING_HEXASCII 0x00000005
698 #define CRYPT_STRING_BASE64_ANY 0x00000006
699 #define CRYPT_STRING_ANY 0x00000007
700 #define CRYPT_STRING_HEX_ANY 0x00000008
701 #define CRYPT_STRING_BASE64X509CRLHEADER 0x00000009
702 #define CRYPT_STRING_HEXADDR 0x0000000A
703 #define CRYPT_STRING_HEXASCIIADDR 0x0000000B
704 #define CRYPT_STRING_HEXRAW 0x0000000C
706 #define CRYPT_STRING_HASHDATA 0x10000000
707 #define CRYPT_STRING_STRICT 0x20000000
708 #define CRYPT_STRING_NOCRLF 0x40000000
709 #define CRYPT_STRING_NOCR 0x80000000
711 WINPR_API BOOL CryptStringToBinaryW(LPCWSTR pszString, DWORD cchString, DWORD dwFlags,
712 BYTE* pbBinary, DWORD* pcbBinary, DWORD* pdwSkip,
714 WINPR_API BOOL CryptStringToBinaryA(LPCSTR pszString, DWORD cchString, DWORD dwFlags,
715 BYTE* pbBinary, DWORD* pcbBinary, DWORD* pdwSkip,
718 WINPR_API BOOL CryptBinaryToStringW(CONST BYTE* pbBinary, DWORD cbBinary, DWORD dwFlags,
719 LPWSTR pszString, DWORD* pcchString);
720 WINPR_API BOOL CryptBinaryToStringA(CONST BYTE* pbBinary, DWORD cbBinary, DWORD dwFlags,
721 LPSTR pszString, DWORD* pcchString);
724 #define CryptStringToBinary CryptStringToBinaryW
725 #define CryptBinaryToString CryptBinaryToStringW
727 #define CryptStringToBinary CryptStringToBinaryA
728 #define CryptBinaryToString CryptBinaryToStringA
733 #ifndef ALG_SID_ECDSA
734 #define ALG_SID_ECDSA 3
735 #define CALG_ECDSA (ALG_CLASS_SIGNATURE | ALG_TYPE_DSS | ALG_SID_ECDSA)