1 /**
2  * Windows API header module
3  *
4  * Translated from MinGW Windows headers
5  *
6  * Authors: Stewart Gordon
7  * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
8  * Source: $(DRUNTIMESRC core/sys/windows/_wincrypt.d)
9  */
10 /// Automatically imported and edited from the druntime module
11 /// core.sys.windows.wincrypt for the auto-generated win32 package.
12 module win32.wincrypt;
13 //version (Windows):
14 @system:
15 version (Win32_UseLib) pragma(lib, "advapi32");
16 
17 version (ANSI) {} else version = Unicode;
18 
19 import win32.w32api, win32.winbase, win32.windef;
20 
21 /* FIXME:
22  *  Types of some constants
23  *  Types of macros
24  *  Inits of various "size" and "version" members
25  *  Why are some #ifdefs commented out?
26  */
27 
28 const TCHAR[]
29     MS_DEF_PROV = "Microsoft Base Cryptographic Provider v1.0",
30     MS_ENHANCED_PROV = "Microsoft Enhanced Cryptographic Provider v1.0",
31     MS_STRONG_PROV = "Microsoft Strong Cryptographic Provider",
32     MS_DEF_RSA_SIG_PROV = "Microsoft RSA Signature Cryptographic Provider",
33     MS_DEF_RSA_SCHANNEL_PROV = "Microsoft RSA SChannel Cryptographic Provider",
34     MS_DEF_DSS_PROV = "Microsoft Base DSS Cryptographic Provider",
35     MS_DEF_DSS_DH_PROV
36       = "Microsoft Base DSS and Diffie-Hellman Cryptographic Provider",
37     MS_ENH_DSS_DH_PROV
38       = "Microsoft Enhanced DSS and Diffie-Hellman Cryptographic Provider",
39     MS_DEF_DH_SCHANNEL_PROV = "Microsoft DH SChannel Cryptographic Provider",
40     MS_SCARD_PROV = "Microsoft Base Smart Card Crypto Provider";
41 
42 static if (_WIN32_WINNT > 0x501) {
43 const TCHAR[] MS_ENH_RSA_AES_PROV
44       = "Microsoft Enhanced RSA and AES Cryptographic Provider";
45 } else static if (_WIN32_WINNT == 0x501) {
46 const TCHAR[] MS_ENH_RSA_AES_PROV
47       = "Microsoft Enhanced RSA and AES Cryptographic Provider (Prototype)";
48 }
49 
50 ALG_ID GET_ALG_CLASS()(ALG_ID x) { return x & 0xE000; }
51 ALG_ID GET_ALG_TYPE ()(ALG_ID x) { return x & 0x1E00; }
52 ALG_ID GET_ALG_SID  ()(ALG_ID x) { return x & 0x01FF; }
53 
54 enum : ALG_ID {
55     ALG_CLASS_ANY           = 0,
56     ALG_CLASS_SIGNATURE     = 0x2000,
57     ALG_CLASS_MSG_ENCRYPT   = 0x4000,
58     ALG_CLASS_DATA_ENCRYPT  = 0x6000,
59     ALG_CLASS_HASH          = 0x8000,
60     ALG_CLASS_KEY_EXCHANGE  = 0xA000,
61     ALG_CLASS_ALL           = 0xE000
62 }
63 
64 enum : ALG_ID {
65     ALG_TYPE_ANY           = 0,
66     ALG_TYPE_DSS           = 0x0200,
67     ALG_TYPE_RSA           = 0x0400,
68     ALG_TYPE_BLOCK         = 0x0600,
69     ALG_TYPE_STREAM        = 0x0800,
70     ALG_TYPE_DH            = 0x0A00,
71     ALG_TYPE_SECURECHANNEL = 0x0C00
72 }
73 
74 enum : ALG_ID {
75     ALG_SID_ANY          =  0,
76     ALG_SID_RSA_ANY      =  0,
77     ALG_SID_RSA_PKCS,
78     ALG_SID_RSA_MSATWORK,
79     ALG_SID_RSA_ENTRUST,
80     ALG_SID_RSA_PGP,  // =  4
81     ALG_SID_DSS_ANY      =  0,
82     ALG_SID_DSS_PKCS,
83     ALG_SID_DSS_DMS,  // =  2
84     ALG_SID_DES          =  1,
85     ALG_SID_3DES         =  3,
86     ALG_SID_DESX,
87     ALG_SID_IDEA,
88     ALG_SID_CAST,
89     ALG_SID_SAFERSK64,
90     ALG_SID_SAFERSK128,
91     ALG_SID_3DES_112,
92     ALG_SID_SKIPJACK,
93     ALG_SID_TEK,
94     ALG_SID_CYLINK_MEK,
95     ALG_SID_RC5,      // = 13
96     ALG_SID_RC2          =  2,
97     ALG_SID_RC4          =  1,
98     ALG_SID_SEAL         =  2,
99     ALG_SID_MD2          =  1,
100     ALG_SID_MD4,
101     ALG_SID_MD5,
102     ALG_SID_SHA,
103     ALG_SID_MAC,
104     ALG_SID_RIPEMD,
105     ALG_SID_RIPEMD160,
106     ALG_SID_SSL3SHAMD5,
107     ALG_SID_HMAC,
108     ALG_SID_TLS1PRF,  // = 10
109     ALG_SID_AES_128      = 14,
110     ALG_SID_AES_192,
111     ALG_SID_AES_256,
112     ALG_SID_AES,      // = 17
113     ALG_SID_EXAMPLE      = 80
114 }
115 
116 enum : ALG_ID {
117     CALG_MD2        = ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MD2,
118     CALG_MD4        = ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MD4,
119     CALG_MD5        = ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MD5,
120     CALG_SHA        = ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA,
121     CALG_SHA1       = CALG_SHA,
122     CALG_MAC        = ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MAC,
123     CALG_3DES       = ALG_CLASS_DATA_ENCRYPT | ALG_TYPE_BLOCK | 3,
124     CALG_CYLINK_MEK = ALG_CLASS_DATA_ENCRYPT | ALG_TYPE_BLOCK | 12,
125     CALG_SKIPJACK   = ALG_CLASS_DATA_ENCRYPT | ALG_TYPE_BLOCK | 10,
126     CALG_KEA_KEYX   = ALG_CLASS_KEY_EXCHANGE | ALG_TYPE_STREAM | ALG_TYPE_DSS | 4,
127     CALG_RSA_SIGN   = ALG_CLASS_SIGNATURE | ALG_TYPE_RSA | ALG_SID_RSA_ANY,
128     CALG_DSS_SIGN   = ALG_CLASS_SIGNATURE | ALG_TYPE_DSS | ALG_SID_DSS_ANY,
129     CALG_RSA_KEYX   = ALG_CLASS_KEY_EXCHANGE | ALG_TYPE_RSA | ALG_SID_RSA_ANY,
130     CALG_DES        = ALG_CLASS_DATA_ENCRYPT | ALG_TYPE_BLOCK | ALG_SID_DES,
131     CALG_RC2        = ALG_CLASS_DATA_ENCRYPT | ALG_TYPE_BLOCK | ALG_SID_RC2,
132     CALG_RC4        = ALG_CLASS_DATA_ENCRYPT | ALG_TYPE_STREAM | ALG_SID_RC4,
133     CALG_SEAL       = ALG_CLASS_DATA_ENCRYPT | ALG_TYPE_STREAM | ALG_SID_SEAL,
134     CALG_DH_EPHEM   = ALG_CLASS_KEY_EXCHANGE | ALG_TYPE_STREAM | ALG_TYPE_DSS
135                       | ALG_SID_DSS_DMS,
136     CALG_DESX       = ALG_CLASS_DATA_ENCRYPT | ALG_TYPE_BLOCK | ALG_SID_DESX,
137 // is undefined ALG_CLASS_DHASH in MinGW - presuming typo
138     CALG_TLS1PRF    = ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_TLS1PRF,
139     CALG_AES_128    = ALG_CLASS_DATA_ENCRYPT | ALG_TYPE_BLOCK | ALG_SID_AES_128,
140     CALG_AES_192    = ALG_CLASS_DATA_ENCRYPT | ALG_TYPE_BLOCK | ALG_SID_AES_192,
141     CALG_AES_256    = ALG_CLASS_DATA_ENCRYPT | ALG_TYPE_BLOCK | ALG_SID_AES_256,
142     CALG_AES        = ALG_CLASS_DATA_ENCRYPT | ALG_TYPE_BLOCK | ALG_SID_AES,
143 }
144 
145 enum {
146     CRYPT_VERIFYCONTEXT = 0xF0000000,
147 }
148 
149 enum {
150     CRYPT_NEWKEYSET = 8,
151     CRYPT_DELETEKEYSET = 16,
152     CRYPT_MACHINE_KEYSET = 32,
153     CRYPT_SILENT = 64,
154 }
155 
156 enum {
157     CRYPT_EXPORTABLE = 1,
158     CRYPT_USER_PROTECTED = 2,
159     CRYPT_CREATE_SALT = 4,
160     CRYPT_UPDATE_KEY = 8,
161 }
162 
163 enum {
164     SIMPLEBLOB = 1,
165     PUBLICKEYBLOB = 6,
166     PRIVATEKEYBLOB = 7,
167     PLAINTEXTKEYBLOB = 8,
168     OPAQUEKEYBLOB = 9,
169     PUBLICKEYBLOBEX = 10,
170     SYMMETRICWRAPKEYBLOB = 11,
171 }
172 
173 enum {
174     AT_KEYEXCHANGE = 1,
175     AT_SIGNATURE = 2,
176 }
177 
178 enum {
179     CRYPT_USERDATA = 1,
180 }
181 
182 enum {
183     PKCS5_PADDING = 1,
184 }
185 
186 enum {
187     CRYPT_MODE_CBC = 1,
188     CRYPT_MODE_ECB = 2,
189     CRYPT_MODE_OFB = 3,
190     CRYPT_MODE_CFB = 4,
191     CRYPT_MODE_CTS = 5,
192     CRYPT_MODE_CBCI = 6,
193     CRYPT_MODE_CFBP = 7,
194     CRYPT_MODE_OFBP = 8,
195     CRYPT_MODE_CBCOFM = 9,
196     CRYPT_MODE_CBCOFMI = 10,
197 }
198 
199 enum {
200     CRYPT_ENCRYPT = 1,
201     CRYPT_DECRYPT = 2,
202     CRYPT_EXPORT = 4,
203     CRYPT_READ = 8,
204     CRYPT_WRITE = 16,
205     CRYPT_MAC = 32,
206 }
207 
208 enum {
209     HP_ALGID = 1,
210     HP_HASHVAL = 2,
211     HP_HASHSIZE = 4,
212     HP_HMAC_INFO = 5,
213 }
214 
215 enum {
216     CRYPT_FAILED = FALSE,
217     CRYPT_SUCCEED = TRUE,
218 }
219 
220 bool RCRYPT_SUCCEEDED()(BOOL r) { return r==CRYPT_SUCCEED; }
221 bool RCRYPT_FAILED()(BOOL r) { return r==CRYPT_FAILED; }
222 
223 enum {
224     PP_ENUMALGS = 1,
225     PP_ENUMCONTAINERS = 2,
226     PP_IMPTYPE = 3,
227     PP_NAME = 4,
228     PP_VERSION = 5,
229     PP_CONTAINER = 6,
230     PP_CHANGE_PASSWORD  = 7,
231     PP_KEYSET_SEC_DESCR = 8,
232     PP_CERTCHAIN    = 9,
233     PP_KEY_TYPE_SUBTYPE = 10,
234     PP_PROVTYPE = 16,
235     PP_KEYSTORAGE   = 17,
236     PP_APPLI_CERT   = 18,
237     PP_SYM_KEYSIZE  = 19,
238     PP_SESSION_KEYSIZE  = 20,
239     PP_UI_PROMPT    = 21,
240     PP_ENUMALGS_EX  = 22,
241     PP_ENUMMANDROOTS = 25,
242     PP_ENUMELECTROOTS = 26,
243     PP_KEYSET_TYPE = 27,
244     PP_ADMIN_PIN = 31,
245     PP_KEYEXCHANGE_PIN = 32,
246     PP_SIGNATURE_PIN = 33,
247     PP_SIG_KEYSIZE_INC = 34,
248     PP_KEYX_KEYSIZE_INC = 35,
249     PP_UNIQUE_CONTAINER = 36,
250     PP_SGC_INFO = 37,
251     PP_USE_HARDWARE_RNG = 38,
252     PP_KEYSPEC = 39,
253     PP_ENUMEX_SIGNING_PROT = 40,
254 }
255 
256 enum {
257     CRYPT_FIRST = 1,
258     CRYPT_NEXT = 2,
259 }
260 
261 enum {
262     CRYPT_IMPL_HARDWARE = 1,
263     CRYPT_IMPL_SOFTWARE = 2,
264     CRYPT_IMPL_MIXED = 3,
265     CRYPT_IMPL_UNKNOWN = 4,
266 }
267 
268 enum {
269     PROV_RSA_FULL = 1,
270     PROV_RSA_SIG = 2,
271     PROV_DSS = 3,
272     PROV_FORTEZZA = 4,
273     PROV_MS_MAIL = 5,
274     PROV_SSL = 6,
275     PROV_STT_MER = 7,
276     PROV_STT_ACQ = 8,
277     PROV_STT_BRND = 9,
278     PROV_STT_ROOT = 10,
279     PROV_STT_ISS = 11,
280     PROV_RSA_SCHANNEL = 12,
281     PROV_DSS_DH = 13,
282     PROV_EC_ECDSA_SIG = 14,
283     PROV_EC_ECNRA_SIG = 15,
284     PROV_EC_ECDSA_FULL = 16,
285     PROV_EC_ECNRA_FULL = 17,
286     PROV_DH_SCHANNEL = 18,
287     PROV_SPYRUS_LYNKS = 20,
288     PROV_RNG = 21,
289     PROV_INTEL_SEC = 22,
290     PROV_RSA_AES = 24,
291     MAXUIDLEN = 64,
292 }
293 
294 enum {
295     CUR_BLOB_VERSION = 2,
296 }
297 
298 enum {
299     X509_ASN_ENCODING = 1,
300     PKCS_7_ASN_ENCODING  = 65536,
301 }
302 
303 enum {
304     CERT_V1 = 0,
305     CERT_V2 = 1,
306     CERT_V3 = 2,
307 }
308 
309 enum {
310     CERT_E_CHAINING = (-2146762486),
311     CERT_E_CN_NO_MATCH = (-2146762481),
312     CERT_E_EXPIRED = (-2146762495),
313     CERT_E_PURPOSE = (-2146762490),
314     CERT_E_REVOCATION_FAILURE = (-2146762482),
315     CERT_E_REVOKED = (-2146762484),
316     CERT_E_ROLE = (-2146762493),
317     CERT_E_UNTRUSTEDROOT = (-2146762487),
318     CERT_E_UNTRUSTEDTESTROOT = (-2146762483),
319     CERT_E_VALIDITYPERIODNESTING = (-2146762494),
320     CERT_E_WRONG_USAGE = (-2146762480),
321     CERT_E_PATHLENCONST = (-2146762492),
322     CERT_E_CRITICAL = (-2146762491),
323     CERT_E_ISSUERCHAINING = (-2146762489),
324     CERT_E_MALFORMED = (-2146762488),
325     CRYPT_E_REVOCATION_OFFLINE = (-2146885613),
326     CRYPT_E_REVOKED = (-2146885616),
327     TRUST_E_BASIC_CONSTRAINTS = (-2146869223),
328     TRUST_E_CERT_SIGNATURE = (-2146869244),
329     TRUST_E_FAIL = (-2146762485),
330 }
331 
332 enum {
333     CERT_TRUST_NO_ERROR = 0,
334     CERT_TRUST_IS_NOT_TIME_VALID = 1,
335     CERT_TRUST_IS_NOT_TIME_NESTED = 2,
336     CERT_TRUST_IS_REVOKED = 4,
337     CERT_TRUST_IS_NOT_SIGNATURE_VALID = 8,
338     CERT_TRUST_IS_NOT_VALID_FOR_USAGE = 16,
339     CERT_TRUST_IS_UNTRUSTED_ROOT = 32,
340     CERT_TRUST_REVOCATION_STATUS_UNKNOWN = 64,
341     CERT_TRUST_IS_CYCLIC = 128,
342     CERT_TRUST_IS_PARTIAL_CHAIN = 65536,
343     CERT_TRUST_CTL_IS_NOT_TIME_VALID = 131072,
344     CERT_TRUST_CTL_IS_NOT_SIGNATURE_VALID = 262144,
345     CERT_TRUST_CTL_IS_NOT_VALID_FOR_USAGE = 524288,
346 }
347 
348 enum {
349     CERT_TRUST_HAS_EXACT_MATCH_ISSUER = 1,
350     CERT_TRUST_HAS_KEY_MATCH_ISSUER = 2,
351     CERT_TRUST_HAS_NAME_MATCH_ISSUER = 4,
352     CERT_TRUST_IS_SELF_SIGNED = 8,
353     CERT_TRUST_IS_COMPLEX_CHAIN = 65536,
354 }
355 
356 enum {
357     CERT_CHAIN_POLICY_BASE              = cast(LPCSTR) 1,
358     CERT_CHAIN_POLICY_AUTHENTICODE      = cast(LPCSTR) 2,
359     CERT_CHAIN_POLICY_AUTHENTICODE_TS   = cast(LPCSTR) 3,
360     CERT_CHAIN_POLICY_SSL               = cast(LPCSTR) 4,
361     CERT_CHAIN_POLICY_BASIC_CONSTRAINTS = cast(LPCSTR) 5,
362     CERT_CHAIN_POLICY_NT_AUTH           = cast(LPCSTR) 6,
363 }
364 
365 enum {
366     USAGE_MATCH_TYPE_AND = 0,
367     USAGE_MATCH_TYPE_OR = 1,
368 }
369 
370 enum {
371     CERT_SIMPLE_NAME_STR = 1,
372     CERT_OID_NAME_STR = 2,
373     CERT_X500_NAME_STR = 3,
374 }
375 enum {
376     CERT_NAME_STR_SEMICOLON_FLAG = 1073741824,
377     CERT_NAME_STR_CRLF_FLAG = 134217728,
378     CERT_NAME_STR_NO_PLUS_FLAG = 536870912,
379     CERT_NAME_STR_NO_QUOTING_FLAG = 268435456,
380     CERT_NAME_STR_REVERSE_FLAG = 33554432,
381     CERT_NAME_STR_ENABLE_T61_UNICODE_FLAG = 131072,
382 }
383 
384 enum {
385     CERT_FIND_ANY = 0,
386     CERT_FIND_CERT_ID = 1048576,
387     CERT_FIND_CTL_USAGE = 655360,
388     CERT_FIND_ENHKEY_USAGE = 655360,
389     CERT_FIND_EXISTING = 851968,
390     CERT_FIND_HASH = 65536,
391     CERT_FIND_ISSUER_ATTR = 196612,
392     CERT_FIND_ISSUER_NAME = 131076,
393     CERT_FIND_ISSUER_OF = 786432,
394     CERT_FIND_KEY_IDENTIFIER = 983040,
395     CERT_FIND_KEY_SPEC = 589824,
396     CERT_FIND_MD5_HASH = 262144,
397     CERT_FIND_PROPERTY = 327680,
398     CERT_FIND_PUBLIC_KEY = 393216,
399     CERT_FIND_SHA1_HASH = 65536,
400     CERT_FIND_SIGNATURE_HASH = 917504,
401     CERT_FIND_SUBJECT_ATTR = 196615,
402     CERT_FIND_SUBJECT_CERT = 720896,
403     CERT_FIND_SUBJECT_NAME = 131079,
404     CERT_FIND_SUBJECT_STR_A = 458759,
405     CERT_FIND_SUBJECT_STR_W = 524295,
406     CERT_FIND_ISSUER_STR_A = 458756,
407     CERT_FIND_ISSUER_STR_W = 524292,
408 }
409 
410 enum {
411     CERT_FIND_OR_ENHKEY_USAGE_FLAG = 16,
412     CERT_FIND_OPTIONAL_ENHKEY_USAGE_FLAG  = 1,
413     CERT_FIND_NO_ENHKEY_USAGE_FLAG  = 8,
414     CERT_FIND_VALID_ENHKEY_USAGE_FLAG  = 32,
415     CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG  = 2,
416 }
417 
418 enum {
419     CERT_CASE_INSENSITIVE_IS_RDN_ATTRS_FLAG  = 2,
420     CERT_UNICODE_IS_RDN_ATTRS_FLAG = 1,
421     CERT_CHAIN_FIND_BY_ISSUER = 1,
422 }
423 
424 enum {
425     CERT_CHAIN_FIND_BY_ISSUER_COMPARE_KEY_FLAG = 1,
426     CERT_CHAIN_FIND_BY_ISSUER_COMPLEX_CHAIN_FLAG = 2,
427     CERT_CHAIN_FIND_BY_ISSUER_CACHE_ONLY_URL_FLAG = 4,
428     CERT_CHAIN_FIND_BY_ISSUER_LOCAL_MACHINE_FLAG = 8,
429     CERT_CHAIN_FIND_BY_ISSUER_NO_KEY_FLAG = 16384,
430     CERT_CHAIN_FIND_BY_ISSUER_CACHE_ONLY_FLAG = 32768,
431 }
432 
433 enum {
434     CERT_STORE_PROV_SYSTEM = 10,
435     CERT_SYSTEM_STORE_LOCAL_MACHINE = 131072,
436 }
437 
438 enum {
439     szOID_PKIX_KP_SERVER_AUTH = "4235600",
440     szOID_SERVER_GATED_CRYPTO = "4235658",
441     szOID_SGC_NETSCAPE = "2.16.840.1.113730.4.1",
442     szOID_PKIX_KP_CLIENT_AUTH = "1.3.6.1.5.5.7.3.2",
443 }
444 
445 enum {
446     CRYPT_NOHASHOID = 0x00000001,
447     CRYPT_NO_SALT = 0x10,
448     CRYPT_PREGEN = 0x40,
449 }
450 
451 enum {
452     CRYPT_RECIPIENT = 0x10,
453     CRYPT_INITIATOR = 0x40,
454     CRYPT_ONLINE = 0x80,
455     CRYPT_SF = 0x100,
456     CRYPT_CREATE_IV = 0x200,
457     CRYPT_KEK = 0x400,
458     CRYPT_DATA_KEY = 0x800,
459     CRYPT_VOLATILE = 0x1000,
460     CRYPT_SGCKEY = 0x2000,
461 }
462 
463 enum {
464     KP_IV               = 0x00000001,
465     KP_SALT             = 0x00000002,
466     KP_PADDING          = 0x00000003,
467     KP_MODE             = 0x00000004,
468     KP_MODE_BITS        = 0x00000005,
469     KP_PERMISSIONS      = 0x00000006,
470     KP_ALGID            = 0x00000007,
471     KP_BLOCKLEN         = 0x00000008,
472     KP_KEYLEN           = 0x00000009,
473     KP_SALT_EX          = 0x0000000a,
474     KP_P                = 0x0000000b,
475     KP_G                = 0x0000000c,
476     KP_Q                = 0x0000000d,
477     KP_X                = 0x0000000e,
478     KP_Y                = 0x0000000f,
479     KP_RA               = 0x00000010,
480     KP_RB               = 0x00000011,
481     KP_INFO             = 0x00000012,
482     KP_EFFECTIVE_KEYLEN = 0x00000013,
483     KP_SCHANNEL_ALG     = 0x00000014,
484     KP_PUB_PARAMS       = 0x00000027,
485 }
486 
487 enum {
488     CRYPT_FLAG_PCT1    = 0x0001,
489     CRYPT_FLAG_SSL2    = 0x0002,
490     CRYPT_FLAG_SSL3    = 0x0004,
491     CRYPT_FLAG_TLS1    = 0x0008,
492     CRYPT_FLAG_IPSEC   = 0x0010,
493     CRYPT_FLAG_SIGNING = 0x0020,
494 }
495 
496 enum {
497     SCHANNEL_MAC_KEY    = 0x00000000,
498     SCHANNEL_ENC_KEY    = 0x00000001,
499 }
500 
501 enum {
502     INTERNATIONAL_USAGE = 0x00000001,
503 }
504 
505 
506 alias UINT ALG_ID;
507 alias ULONG_PTR HCRYPTPROV, HCRYPTKEY, HCRYPTHASH;
508 alias PVOID HCERTSTORE, HCRYPTMSG, HCERTCHAINENGINE;
509 
510 struct VTableProvStruc {
511     FARPROC FuncVerifyImage;
512 }
513 alias VTableProvStruc* PVTableProvStruc;
514 
515 struct _CRYPTOAPI_BLOB {
516     DWORD cbData;
517     BYTE* pbData;
518 }
519 alias _CRYPTOAPI_BLOB CRYPT_INTEGER_BLOB, CRYPT_UINT_BLOB,
520   CRYPT_OBJID_BLOB, CERT_NAME_BLOB, CERT_RDN_VALUE_BLOB, CERT_BLOB,
521   CRL_BLOB, DATA_BLOB, CRYPT_DATA_BLOB, CRYPT_HASH_BLOB,
522   CRYPT_DIGEST_BLOB, CRYPT_DER_BLOB, CRYPT_ATTR_BLOB;
523 alias _CRYPTOAPI_BLOB* PCRYPT_INTEGER_BLOB, PCRYPT_UINT_BLOB,
524   PCRYPT_OBJID_BLOB, PCERT_NAME_BLOB, PCERT_RDN_VALUE_BLOB, PCERT_BLOB,
525   PCRL_BLOB, PDATA_BLOB, PCRYPT_DATA_BLOB, PCRYPT_HASH_BLOB,
526   PCRYPT_DIGEST_BLOB, PCRYPT_DER_BLOB, PCRYPT_ATTR_BLOB;
527 
528 // not described in SDK; has the same layout as HTTPSPolicyCallbackData
529 struct SSL_EXTRA_CERT_CHAIN_POLICY_PARA {
530     DWORD  cbStruct;
531     DWORD  dwAuthType;
532     DWORD  fdwChecks;
533     LPWSTR pwszServerName;
534 }
535 alias SSL_EXTRA_CERT_CHAIN_POLICY_PARA HTTPSPolicyCallbackData;
536 alias SSL_EXTRA_CERT_CHAIN_POLICY_PARA* PSSL_EXTRA_CERT_CHAIN_POLICY_PARA,
537   PHTTPSPolicyCallbackData;
538 
539 /* #if (_WIN32_WINNT>=0x500) */
540 struct CERT_CHAIN_POLICY_PARA {
541     DWORD cbSize = CERT_CHAIN_POLICY_PARA.sizeof;
542     DWORD dwFlags;
543     void* pvExtraPolicyPara;
544 }
545 alias CERT_CHAIN_POLICY_PARA* PCERT_CHAIN_POLICY_PARA;
546 
547 struct CERT_CHAIN_POLICY_STATUS {
548     DWORD cbSize = CERT_CHAIN_POLICY_STATUS.sizeof;
549     DWORD dwError;
550     LONG  lChainIndex;
551     LONG  lElementIndex;
552     void* pvExtraPolicyStatus;
553 }
554 alias CERT_CHAIN_POLICY_STATUS* PCERT_CHAIN_POLICY_STATUS;
555 /* #endif */
556 
557 struct CRYPT_ALGORITHM_IDENTIFIER {
558     LPSTR pszObjId;
559     CRYPT_OBJID_BLOB Parameters;
560 }
561 alias CRYPT_ALGORITHM_IDENTIFIER* PCRYPT_ALGORITHM_IDENTIFIER;
562 
563 struct CRYPT_BIT_BLOB {
564     DWORD cbData;
565     BYTE* pbData;
566     DWORD cUnusedBits;
567 }
568 alias CRYPT_BIT_BLOB* PCRYPT_BIT_BLOB;
569 
570 struct CERT_PUBLIC_KEY_INFO {
571     CRYPT_ALGORITHM_IDENTIFIER Algorithm;
572     CRYPT_BIT_BLOB             PublicKey;
573 }
574 alias CERT_PUBLIC_KEY_INFO* PCERT_PUBLIC_KEY_INFO;
575 
576 struct CERT_EXTENSION {
577     LPSTR            pszObjId;
578     BOOL             fCritical;
579     CRYPT_OBJID_BLOB Value;
580 }
581 alias CERT_EXTENSION* PCERT_EXTENSION;
582 
583 struct CERT_INFO {
584     DWORD dwVersion;
585     CRYPT_INTEGER_BLOB SerialNumber;
586     CRYPT_ALGORITHM_IDENTIFIER SignatureAlgorithm;
587     CERT_NAME_BLOB Issuer;
588     FILETIME NotBefore;
589     FILETIME NotAfter;
590     CERT_NAME_BLOB Subject;
591     CERT_PUBLIC_KEY_INFO SubjectPublicKeyInfo;
592     CRYPT_BIT_BLOB IssuerUniqueId;
593     CRYPT_BIT_BLOB SubjectUniqueId;
594     DWORD cExtension;
595     PCERT_EXTENSION rgExtension;
596 }
597 alias CERT_INFO* PCERT_INFO;
598 
599 struct CERT_CONTEXT {
600     DWORD      dwCertEncodingType;
601     BYTE*      pbCertEncoded;
602     DWORD      cbCertEncoded;
603     PCERT_INFO pCertInfo;
604     HCERTSTORE hCertStore;
605 }
606 alias CERT_CONTEXT*        PCERT_CONTEXT;
607 alias const(CERT_CONTEXT)* PCCERT_CONTEXT;
608 
609 struct CTL_USAGE {
610     DWORD  cUsageIdentifier;
611     LPSTR* rgpszUsageIdentifier;
612 }
613 alias CTL_USAGE CERT_ENHKEY_USAGE;
614 alias CTL_USAGE* PCTRL_USAGE, PCERT_ENHKEY_USAGE;
615 
616 struct CERT_USAGE_MATCH {
617     DWORD             dwType;
618     CERT_ENHKEY_USAGE Usage;
619 }
620 alias CERT_USAGE_MATCH* PCERT_USAGE_MATCH;
621 /* #if (_WIN32_WINNT>=0x500) */
622 
623 struct CERT_CHAIN_PARA {
624     DWORD            cbSize = CERT_CHAIN_PARA.sizeof;
625     CERT_USAGE_MATCH RequestedUsage;
626 //#if CERT_CHAIN_PARA_HAS_EXTRA_FIELDS
627     CERT_USAGE_MATCH RequestedIssuancePolicy;
628     DWORD            dwUrlRetrievalTimeout;
629     BOOL             fCheckRevocationFreshnessTime;
630     DWORD            dwRevocationFreshnessTime;
631 //#endif
632 }
633 alias CERT_CHAIN_PARA* PCERT_CHAIN_PARA;
634 
635 extern (Windows) alias BOOL function(PCCERT_CONTEXT, void*)
636   PFN_CERT_CHAIN_FIND_BY_ISSUER_CALLBACK;
637 
638 struct CERT_CHAIN_FIND_BY_ISSUER_PARA {
639     DWORD  cbSize = CERT_CHAIN_FIND_BY_ISSUER_PARA.sizeof;
640     LPCSTR pszUsageIdentifier;
641     DWORD  dwKeySpec;
642     DWORD  dwAcquirePrivateKeyFlags;
643     DWORD  cIssuer;
644     CERT_NAME_BLOB* rgIssuer;
645     PFN_CERT_CHAIN_FIND_BY_ISSUER_CALLBACK pfnFIndCallback;
646     void*  pvFindArg;
647     DWORD* pdwIssuerChainIndex;
648     DWORD* pdwIssuerElementIndex;
649 }
650 alias CERT_CHAIN_FIND_BY_ISSUER_PARA* PCERT_CHAIN_FIND_BY_ISSUER_PARA;
651 /* #endif */
652 
653 struct CERT_TRUST_STATUS {
654     DWORD dwErrorStatus;
655     DWORD dwInfoStatus;
656 }
657 alias CERT_TRUST_STATUS* PCERT_TRUST_STATUS;
658 
659 struct CRL_ENTRY {
660     CRYPT_INTEGER_BLOB SerialNumber;
661     FILETIME           RevocationDate;
662     DWORD              cExtension;
663     PCERT_EXTENSION    rgExtension;
664 }
665 alias CRL_ENTRY* PCRL_ENTRY;
666 
667 struct CRL_INFO {
668     DWORD           dwVersion;
669     CRYPT_ALGORITHM_IDENTIFIER SignatureAlgorithm;
670     CERT_NAME_BLOB  Issuer;
671     FILETIME        ThisUpdate;
672     FILETIME        NextUpdate;
673     DWORD           cCRLEntry;
674     PCRL_ENTRY      rgCRLEntry;
675     DWORD           cExtension;
676     PCERT_EXTENSION rgExtension;
677 }
678 alias CRL_INFO* PCRL_INFO;
679 
680 struct CRL_CONTEXT {
681     DWORD      dwCertEncodingType;
682     BYTE*      pbCrlEncoded;
683     DWORD      cbCrlEncoded;
684     PCRL_INFO  pCrlInfo;
685     HCERTSTORE hCertStore;
686 }
687 alias CRL_CONTEXT*        PCRL_CONTEXT;
688 alias const(CRL_CONTEXT)* PCCRL_CONTEXT;
689 
690 struct CERT_REVOCATION_CRL_INFO {
691     DWORD         cbSize = CERT_REVOCATION_CRL_INFO.sizeof;
692     PCCRL_CONTEXT pBaseCRLContext;
693     PCCRL_CONTEXT pDeltaCRLContext;
694     PCRL_ENTRY    pCrlEntry;
695     BOOL          fDeltaCrlEntry;
696 }
697 alias CERT_REVOCATION_CRL_INFO* PCERT_REVOCATION_CRL_INFO;
698 
699 struct CERT_REVOCATION_INFO {
700     DWORD  cbSize = CERT_REVOCATION_INFO.sizeof;
701     DWORD  dwRevocationResult;
702     LPCSTR pszRevocationOid;
703     LPVOID pvOidSpecificInfo;
704     BOOL   fHasFreshnessTime;
705     DWORD  dwFreshnessTime;
706     PCERT_REVOCATION_CRL_INFO pCrlInfo;
707 }
708 alias CERT_REVOCATION_INFO* PCERT_REVOCATION_INFO;
709 
710 /* #if (_WIN32_WINNT>=0x500) */
711 struct CERT_CHAIN_ELEMENT {
712     DWORD                 cbSize = CERT_CHAIN_ELEMENT.sizeof;
713     PCCERT_CONTEXT        pCertContext;
714     CERT_TRUST_STATUS     TrustStatus;
715     PCERT_REVOCATION_INFO pRevocationInfo;
716     PCERT_ENHKEY_USAGE    pIssuanceUsage;
717     PCERT_ENHKEY_USAGE    pApplicationUsage;
718 }
719 alias CERT_CHAIN_ELEMENT* PCERT_CHAIN_ELEMENT;
720 /* #endif */
721 
722 struct CRYPT_ATTRIBUTE {
723     LPSTR            pszObjId;
724     DWORD            cValue;
725     PCRYPT_ATTR_BLOB rgValue;
726 }
727 alias CRYPT_ATTRIBUTE* PCRYPT_ATTRIBUTE;
728 
729 struct CTL_ENTRY {
730     CRYPT_DATA_BLOB  SubjectIdentifier;
731     DWORD            cAttribute;
732     PCRYPT_ATTRIBUTE rgAttribute;
733 }
734 alias CTL_ENTRY* PCTL_ENTRY;
735 
736 struct CTL_INFO {
737     DWORD              dwVersion;
738     CTL_USAGE          SubjectUsage;
739     CRYPT_DATA_BLOB    ListIdentifier;
740     CRYPT_INTEGER_BLOB SequenceNumber;
741     FILETIME           ThisUpdate;
742     FILETIME           NextUpdate;
743     CRYPT_ALGORITHM_IDENTIFIER SubjectAlgorithm;
744     DWORD              cCTLEntry;
745     PCTL_ENTRY         rgCTLEntry;
746     DWORD              cExtension;
747     PCERT_EXTENSION    rgExtension;
748 }
749 alias CTL_INFO* PCTL_INFO;
750 
751 struct CTL_CONTEXT {
752     DWORD      dwMsgAndCertEncodingType;
753     BYTE*      pbCtlEncoded;
754     DWORD      cbCtlEncoded;
755     PCTL_INFO  pCtlInfo;
756     HCERTSTORE hCertStore;
757     HCRYPTMSG  hCryptMsg;
758     BYTE*      pbCtlContent;
759     DWORD      cbCtlContent;
760 }
761 alias CTL_CONTEXT*        PCTL_CONTEXT;
762 alias const(CTL_CONTEXT)* PCCTL_CONTEXT;
763 
764 struct CERT_TRUST_LIST_INFO {
765     DWORD         cbSize = CERT_TRUST_LIST_INFO.sizeof;
766     PCTL_ENTRY    pCtlEntry;
767     PCCTL_CONTEXT pCtlContext;
768 }
769 alias CERT_TRUST_LIST_INFO* PCERT_TRUST_LIST_INFO;
770 
771 struct CERT_SIMPLE_CHAIN {
772     DWORD                 cbSize = CERT_SIMPLE_CHAIN.sizeof;
773     CERT_TRUST_STATUS     TrustStatus;
774     DWORD                 cElement;
775     PCERT_CHAIN_ELEMENT*  rgpElement;
776     PCERT_TRUST_LIST_INFO pTrustListInfo;
777     BOOL                  fHasRevocationFreshnessTime;
778     DWORD                 dwRevocationFreshnessTime;
779 }
780 alias CERT_SIMPLE_CHAIN* PCERT_SIMPLE_CHAIN;
781 
782 /* #if (_WIN32_WINNT>=0x500) */
783 alias const(CERT_CHAIN_CONTEXT)* PCCERT_CHAIN_CONTEXT;
784 struct CERT_CHAIN_CONTEXT {
785     DWORD                 cbSize = CERT_CHAIN_CONTEXT.sizeof;
786     CERT_TRUST_STATUS     TrustStatus;
787     DWORD                 cChain;
788     PCERT_SIMPLE_CHAIN*   rgpChain;
789     DWORD                 cLowerQualityChainContext;
790     PCCERT_CHAIN_CONTEXT* rgpLowerQualityChainContext;
791     BOOL                  fHasRevocationFreshnessTime;
792     DWORD                 dwRevocationFreshnessTime;
793 }
794 alias CERT_CHAIN_CONTEXT* PCERT_CHAIN_CONTEXT;
795 /* #endif */
796 
797 struct PROV_ENUMALGS {
798     ALG_ID   aiAlgid;
799     DWORD    dwBitLen;
800     DWORD    dwNameLen;
801     CHAR[20] szName = 0;
802 }
803 
804 struct PUBLICKEYSTRUC {
805     BYTE   bType;
806     BYTE   bVersion;
807     WORD   reserved;
808     ALG_ID aiKeyAlg;
809 }
810 alias PUBLICKEYSTRUC BLOBHEADER;
811 
812 struct RSAPUBKEY {
813     DWORD magic;
814     DWORD bitlen;
815     DWORD pubexp;
816 }
817 
818 struct HMAC_INFO {
819     ALG_ID HashAlgid;
820     BYTE*  pbInnerString;
821     DWORD  cbInnerString;
822     BYTE*  pbOuterString;
823     DWORD  cbOuterString;
824 }
825 alias HMAC_INFO* PHMAC_INFO;
826 
827 extern (Windows) @nogc nothrow {
828     BOOL CertCloseStore(HCERTSTORE, DWORD);
829     BOOL CertGetCertificateChain(HCERTCHAINENGINE, PCCERT_CONTEXT, LPFILETIME,
830       HCERTSTORE, PCERT_CHAIN_PARA, DWORD, LPVOID, PCCERT_CHAIN_CONTEXT*);
831     BOOL CertVerifyCertificateChainPolicy(LPCSTR, PCCERT_CHAIN_CONTEXT,
832       PCERT_CHAIN_POLICY_PARA, PCERT_CHAIN_POLICY_STATUS);
833     void CertFreeCertificateChain(PCCERT_CHAIN_CONTEXT);
834     DWORD CertNameToStrA(DWORD, PCERT_NAME_BLOB, DWORD, LPSTR, DWORD);
835     DWORD CertNameToStrW(DWORD, PCERT_NAME_BLOB, DWORD, LPWSTR, DWORD);
836     HCERTSTORE CertOpenSystemStoreA(HCRYPTPROV, LPCSTR);
837     HCERTSTORE CertOpenSystemStoreW(HCRYPTPROV, LPCWSTR);
838     HCERTSTORE CertOpenStore(LPCSTR, DWORD, HCRYPTPROV, DWORD, const(void)*);
839     PCCERT_CONTEXT CertFindCertificateInStore(HCERTSTORE, DWORD, DWORD, DWORD,
840 const(void)*, PCCERT_CONTEXT);
841     BOOL CertFreeCertificateContext(PCCERT_CONTEXT);
842     PCCERT_CONTEXT CertGetIssuerCertificateFromStore(HCERTSTORE,
843       PCCERT_CONTEXT, PCCERT_CONTEXT, DWORD*);
844     PCCERT_CHAIN_CONTEXT CertFindChainInStore(HCERTSTORE, DWORD, DWORD, DWORD,
845 const(void)*, PCCERT_CHAIN_CONTEXT);
846 
847     BOOL CryptAcquireContextA(HCRYPTPROV*, LPCSTR, LPCSTR, DWORD, DWORD);
848     BOOL CryptAcquireContextW(HCRYPTPROV*, LPCWSTR, LPCWSTR, DWORD, DWORD);
849      BOOL CryptContextAddRef(HCRYPTPROV, DWORD*, DWORD);
850     BOOL CryptReleaseContext(HCRYPTPROV, ULONG_PTR);
851     BOOL CryptGenKey(HCRYPTPROV, ALG_ID, DWORD, HCRYPTKEY*);
852     BOOL CryptDeriveKey(HCRYPTPROV, ALG_ID, HCRYPTHASH, DWORD, HCRYPTKEY*);
853     BOOL CryptDestroyKey(HCRYPTKEY);
854     static if (_WIN32_WINNT >= 0x500) {
855         BOOL CryptDuplicateHash(HCRYPTHASH, DWORD*, DWORD, HCRYPTHASH*);
856         BOOL CryptDuplicateKey(HCRYPTKEY, DWORD*, DWORD, HCRYPTKEY*);
857     }
858     BOOL CryptSetKeyParam(HCRYPTKEY, DWORD, PBYTE, DWORD);
859     BOOL CryptGetKeyParam(HCRYPTKEY, DWORD, PBYTE, PDWORD, DWORD);
860     BOOL CryptSetHashParam(HCRYPTHASH, DWORD, PBYTE, DWORD);
861     BOOL CryptGetHashParam(HCRYPTHASH, DWORD, PBYTE, PDWORD, DWORD);
862     BOOL CryptSetProvParam(HCRYPTPROV, DWORD, PBYTE, DWORD);
863     BOOL CryptGetProvParam(HCRYPTPROV, DWORD, PBYTE, PDWORD, DWORD);
864     BOOL CryptGenRandom(HCRYPTPROV, DWORD, PBYTE);
865     BOOL CryptGetUserKey(HCRYPTPROV, DWORD, HCRYPTKEY*);
866     BOOL CryptExportKey(HCRYPTKEY, HCRYPTKEY, DWORD, DWORD, PBYTE, PDWORD);
867     BOOL CryptImportKey(HCRYPTPROV, PBYTE, DWORD, HCRYPTKEY, DWORD,
868       HCRYPTKEY*);
869     BOOL CryptEncrypt(HCRYPTKEY, HCRYPTHASH, BOOL, DWORD, PBYTE, PDWORD,
870       DWORD);
871     BOOL CryptDecrypt(HCRYPTKEY, HCRYPTHASH, BOOL, DWORD, PBYTE, PDWORD);
872     BOOL CryptCreateHash(HCRYPTPROV, ALG_ID, HCRYPTKEY, DWORD, HCRYPTHASH*);
873     BOOL CryptHashData(HCRYPTHASH, PBYTE, DWORD, DWORD);
874     BOOL CryptHashSessionKey(HCRYPTHASH, HCRYPTKEY, DWORD);
875     BOOL CryptGetHashValue(HCRYPTHASH, DWORD, PBYTE, PDWORD);
876     BOOL CryptDestroyHash(HCRYPTHASH);
877     BOOL CryptSignHashA(HCRYPTHASH, DWORD, LPCSTR, DWORD, PBYTE, PDWORD);
878     BOOL CryptSignHashW(HCRYPTHASH, DWORD, LPCWSTR, DWORD, PBYTE, PDWORD);
879     BOOL CryptVerifySignatureA(HCRYPTHASH, PBYTE, DWORD, HCRYPTKEY, LPCSTR,
880       DWORD);
881     BOOL CryptVerifySignatureW(HCRYPTHASH, PBYTE, DWORD, HCRYPTKEY, LPCWSTR,
882       DWORD);
883     BOOL CryptSetProviderA(LPCSTR, DWORD);
884     BOOL CryptSetProviderW(LPCWSTR, DWORD);
885 }
886 
887 version (Unicode) {
888     alias CertNameToStrW CertNameToStr;
889     alias CryptAcquireContextW CryptAcquireContext;
890     alias CryptSignHashW CryptSignHash;
891     alias CryptVerifySignatureW CryptVerifySignature;
892     alias CryptSetProviderW CryptSetProvider;
893     alias CertOpenSystemStoreW CertOpenSystemStore;
894     /+alias CERT_FIND_SUBJECT_STR_W CERT_FIND_SUBJECT_STR;
895     alias CERT_FIND_ISSUER_STR_W CERT_FIND_ISSUER_STR;+/
896 } else {
897     alias CertNameToStrA CertNameToStr;
898     alias CryptAcquireContextA CryptAcquireContext;
899     alias CryptSignHashA CryptSignHash;
900     alias CryptVerifySignatureA CryptVerifySignature;
901     alias CryptSetProviderA CryptSetProvider;
902     alias CertOpenSystemStoreA CertOpenSystemStore;
903     /+alias CERT_FIND_SUBJECT_STR_A CERT_FIND_SUBJECT_STR;
904     alias CERT_FIND_ISSUER_STR_A CERT_FIND_ISSUER_STR;+/
905 }