WinCrypt.h
上传用户:dzyhzl
上传日期:2019-04-29
资源大小:56270k
文件大小:634k
源码类别:

模拟服务器

开发平台:

C/C++

  1. //+---------------------------------------------------------------------------
  2. //
  3. //  Microsoft Windows
  4. //  Copyright (C) Microsoft Corporation, 1992-1999.
  5. //
  6. //  File:       wincrypt.h
  7. //
  8. //  Contents:   Cryptographic API Prototypes and Definitions
  9. //
  10. //----------------------------------------------------------------------------
  11. #ifndef __WINCRYPT_H__
  12. #define __WINCRYPT_H__
  13. #if defined (_MSC_VER)
  14. #if ( _MSC_VER >= 800 )
  15. #if _MSC_VER >= 1200
  16. #pragma warning(push)
  17. #endif
  18. #pragma warning(disable:4201)    /* Nameless struct/union */
  19. #endif
  20. #if (_MSC_VER > 1020)
  21. #pragma once
  22. #endif
  23. #endif
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. #ifndef _HRESULT_DEFINED
  28. #define _HRESULT_DEFINED
  29. typedef LONG HRESULT;
  30. #endif // !_HRESULT_DEFINED
  31. #ifndef WINADVAPI
  32. #define WINADVAPI
  33. #endif
  34. #ifndef WINAPI
  35. #define WINAPI __stdcall
  36. #endif
  37. #ifndef CALLBACK
  38. #define CALLBACK __stdcall
  39. #endif
  40. #ifndef DECLSPEC_IMPORT
  41. #define DECLSPEC_IMPORT
  42. #endif
  43. #ifndef CONST
  44. #define CONST const
  45. #endif
  46. #ifndef IN
  47. #define IN
  48. #endif
  49. #ifndef OUT
  50. #define OUT
  51. #endif
  52. #ifndef OPTIONAL
  53. #define OPTIONAL
  54. #endif
  55. #if !defined(_CRYPT32_)
  56. #define WINCRYPT32API DECLSPEC_IMPORT
  57. #else
  58. #define WINCRYPT32API
  59. #endif
  60. #if !defined(_CRYPT32STRING_)
  61. # define WINCRYPT32STRINGAPI WINCRYPT32API
  62. #else
  63. # define WINCRYPT32STRINGAPI
  64. #endif
  65. //
  66. // Algorithm IDs and Flags
  67. //
  68. // ALG_ID crackers
  69. #define GET_ALG_CLASS(x)                (x & (7 << 13))
  70. #define GET_ALG_TYPE(x)                 (x & (15 << 9))
  71. #define GET_ALG_SID(x)                  (x & (511))
  72. // Algorithm classes
  73. #define ALG_CLASS_ANY                   (0)
  74. #define ALG_CLASS_SIGNATURE             (1 << 13)
  75. #define ALG_CLASS_MSG_ENCRYPT           (2 << 13)
  76. #define ALG_CLASS_DATA_ENCRYPT          (3 << 13)
  77. #define ALG_CLASS_HASH                  (4 << 13)
  78. #define ALG_CLASS_KEY_EXCHANGE          (5 << 13)
  79. #define ALG_CLASS_ALL                   (7 << 13)
  80. // Algorithm types
  81. #define ALG_TYPE_ANY                    (0)
  82. #define ALG_TYPE_DSS                    (1 << 9)
  83. #define ALG_TYPE_RSA                    (2 << 9)
  84. #define ALG_TYPE_BLOCK                  (3 << 9)
  85. #define ALG_TYPE_STREAM                 (4 << 9)
  86. #define ALG_TYPE_DH                     (5 << 9)
  87. #define ALG_TYPE_SECURECHANNEL          (6 << 9)
  88. // Generic sub-ids
  89. #define ALG_SID_ANY                     (0)
  90. // Some RSA sub-ids
  91. #define ALG_SID_RSA_ANY                 0
  92. #define ALG_SID_RSA_PKCS                1
  93. #define ALG_SID_RSA_MSATWORK            2
  94. #define ALG_SID_RSA_ENTRUST             3
  95. #define ALG_SID_RSA_PGP                 4
  96. // Some DSS sub-ids
  97. //
  98. #define ALG_SID_DSS_ANY                 0
  99. #define ALG_SID_DSS_PKCS                1
  100. #define ALG_SID_DSS_DMS                 2
  101. // Block cipher sub ids
  102. // DES sub_ids
  103. #define ALG_SID_DES                     1
  104. #define ALG_SID_3DES                    3
  105. #define ALG_SID_DESX                    4
  106. #define ALG_SID_IDEA                    5
  107. #define ALG_SID_CAST                    6
  108. #define ALG_SID_SAFERSK64               7
  109. #define ALG_SID_SAFERSK128              8
  110. #define ALG_SID_3DES_112                9
  111. #define ALG_SID_CYLINK_MEK              12
  112. #define ALG_SID_RC5                     13
  113. #define ALG_SID_AES_128                 14
  114. #define ALG_SID_AES_192                 15
  115. #define ALG_SID_AES_256                 16
  116. #define ALG_SID_AES                     17
  117. // Fortezza sub-ids
  118. #define ALG_SID_SKIPJACK                10
  119. #define ALG_SID_TEK                     11
  120. // KP_MODE
  121. #define CRYPT_MODE_CBCI                 6       // ANSI CBC Interleaved
  122. #define CRYPT_MODE_CFBP                 7       // ANSI CFB Pipelined
  123. #define CRYPT_MODE_OFBP                 8       // ANSI OFB Pipelined
  124. #define CRYPT_MODE_CBCOFM               9       // ANSI CBC + OF Masking
  125. #define CRYPT_MODE_CBCOFMI              10      // ANSI CBC + OFM Interleaved
  126. // RC2 sub-ids
  127. #define ALG_SID_RC2                     2
  128. // Stream cipher sub-ids
  129. #define ALG_SID_RC4                     1
  130. #define ALG_SID_SEAL                    2
  131. // Diffie-Hellman sub-ids
  132. #define ALG_SID_DH_SANDF                1
  133. #define ALG_SID_DH_EPHEM                2
  134. #define ALG_SID_AGREED_KEY_ANY          3
  135. #define ALG_SID_KEA                     4
  136. // Hash sub ids
  137. #define ALG_SID_MD2                     1
  138. #define ALG_SID_MD4                     2
  139. #define ALG_SID_MD5                     3
  140. #define ALG_SID_SHA                     4
  141. #define ALG_SID_SHA1                    4
  142. #define ALG_SID_MAC                     5
  143. #define ALG_SID_RIPEMD                  6
  144. #define ALG_SID_RIPEMD160               7
  145. #define ALG_SID_SSL3SHAMD5              8
  146. #define ALG_SID_HMAC                    9
  147. #define ALG_SID_TLS1PRF                 10
  148. #define ALG_SID_HASH_REPLACE_OWF        11
  149. // secure channel sub ids
  150. #define ALG_SID_SSL3_MASTER             1
  151. #define ALG_SID_SCHANNEL_MASTER_HASH    2
  152. #define ALG_SID_SCHANNEL_MAC_KEY        3
  153. #define ALG_SID_PCT1_MASTER             4
  154. #define ALG_SID_SSL2_MASTER             5
  155. #define ALG_SID_TLS1_MASTER             6
  156. #define ALG_SID_SCHANNEL_ENC_KEY        7
  157. // Our silly example sub-id
  158. #define ALG_SID_EXAMPLE                 80
  159. #ifndef ALGIDDEF
  160. #define ALGIDDEF
  161. typedef unsigned int ALG_ID;
  162. #endif
  163. // algorithm identifier definitions
  164. #define CALG_MD2                (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MD2)
  165. #define CALG_MD4                (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MD4)
  166. #define CALG_MD5                (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MD5)
  167. #define CALG_SHA                (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA)
  168. #define CALG_SHA1               (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA1)
  169. #define CALG_MAC                (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MAC)
  170. #define CALG_RSA_SIGN           (ALG_CLASS_SIGNATURE | ALG_TYPE_RSA | ALG_SID_RSA_ANY)
  171. #define CALG_DSS_SIGN           (ALG_CLASS_SIGNATURE | ALG_TYPE_DSS | ALG_SID_DSS_ANY)
  172. #define CALG_NO_SIGN            (ALG_CLASS_SIGNATURE | ALG_TYPE_ANY | ALG_SID_ANY)
  173. #define CALG_RSA_KEYX           (ALG_CLASS_KEY_EXCHANGE|ALG_TYPE_RSA|ALG_SID_RSA_ANY)
  174. #define CALG_DES                (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_DES)
  175. #define CALG_3DES_112           (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_3DES_112)
  176. #define CALG_3DES               (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_3DES)
  177. #define CALG_DESX               (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_DESX)
  178. #define CALG_RC2                (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_RC2)
  179. #define CALG_RC4                (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_STREAM|ALG_SID_RC4)
  180. #define CALG_SEAL               (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_STREAM|ALG_SID_SEAL)
  181. #define CALG_DH_SF              (ALG_CLASS_KEY_EXCHANGE|ALG_TYPE_DH|ALG_SID_DH_SANDF)
  182. #define CALG_DH_EPHEM           (ALG_CLASS_KEY_EXCHANGE|ALG_TYPE_DH|ALG_SID_DH_EPHEM)
  183. #define CALG_AGREEDKEY_ANY      (ALG_CLASS_KEY_EXCHANGE|ALG_TYPE_DH|ALG_SID_AGREED_KEY_ANY)
  184. #define CALG_KEA_KEYX           (ALG_CLASS_KEY_EXCHANGE|ALG_TYPE_DH|ALG_SID_KEA)
  185. #define CALG_HUGHES_MD5         (ALG_CLASS_KEY_EXCHANGE|ALG_TYPE_ANY|ALG_SID_MD5)
  186. #define CALG_SKIPJACK           (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_SKIPJACK)
  187. #define CALG_TEK                (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_TEK)
  188. #define CALG_CYLINK_MEK         (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_CYLINK_MEK)
  189. #define CALG_SSL3_SHAMD5        (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SSL3SHAMD5)
  190. #define CALG_SSL3_MASTER        (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_SSL3_MASTER)
  191. #define CALG_SCHANNEL_MASTER_HASH   (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_SCHANNEL_MASTER_HASH)
  192. #define CALG_SCHANNEL_MAC_KEY   (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_SCHANNEL_MAC_KEY)
  193. #define CALG_SCHANNEL_ENC_KEY   (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_SCHANNEL_ENC_KEY)
  194. #define CALG_PCT1_MASTER        (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_PCT1_MASTER)
  195. #define CALG_SSL2_MASTER        (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_SSL2_MASTER)
  196. #define CALG_TLS1_MASTER        (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_TLS1_MASTER)
  197. #define CALG_RC5                (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_RC5)
  198. #define CALG_HMAC               (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_HMAC)
  199. #define CALG_TLS1PRF            (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_TLS1PRF)
  200. #define CALG_HASH_REPLACE_OWF   (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_HASH_REPLACE_OWF)
  201. #define CALG_AES_128            (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_AES_128)
  202. #define CALG_AES_192            (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_AES_192)
  203. #define CALG_AES_256            (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_AES_256)
  204. #define CALG_AES                (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_AES)
  205. typedef ULONG_PTR HCRYPTPROV;
  206. typedef ULONG_PTR HCRYPTKEY;
  207. typedef ULONG_PTR HCRYPTHASH;
  208. // dwFlags definitions for CryptAcquireContext
  209. #define CRYPT_VERIFYCONTEXT     0xF0000000
  210. #define CRYPT_NEWKEYSET         0x00000008
  211. #define CRYPT_DELETEKEYSET      0x00000010
  212. #define CRYPT_MACHINE_KEYSET    0x00000020
  213. #define CRYPT_SILENT            0x00000040
  214. // dwFlag definitions for CryptGenKey
  215. #define CRYPT_EXPORTABLE        0x00000001
  216. #define CRYPT_USER_PROTECTED    0x00000002
  217. #define CRYPT_CREATE_SALT       0x00000004
  218. #define CRYPT_UPDATE_KEY        0x00000008
  219. #define CRYPT_NO_SALT           0x00000010
  220. #define CRYPT_PREGEN            0x00000040
  221. #define CRYPT_RECIPIENT         0x00000010
  222. #define CRYPT_INITIATOR         0x00000040
  223. #define CRYPT_ONLINE            0x00000080
  224. #define CRYPT_SF                0x00000100
  225. #define CRYPT_CREATE_IV         0x00000200
  226. #define CRYPT_KEK               0x00000400
  227. #define CRYPT_DATA_KEY          0x00000800
  228. #define CRYPT_VOLATILE          0x00001000
  229. #define CRYPT_SGCKEY            0x00002000
  230. #define CRYPT_ARCHIVABLE        0x00004000
  231. #define RSA1024BIT_KEY          0x04000000
  232. // dwFlags definitions for CryptDeriveKey
  233. #define CRYPT_SERVER            0x00000400
  234. #define KEY_LENGTH_MASK         0xFFFF0000
  235. // dwFlag definitions for CryptExportKey
  236. #define CRYPT_Y_ONLY            0x00000001
  237. #define CRYPT_SSL2_FALLBACK     0x00000002
  238. #define CRYPT_DESTROYKEY        0x00000004
  239. #define CRYPT_OAEP              0x00000040  // used with RSA encryptions/decryptions
  240.                                             // CryptExportKey, CryptImportKey,
  241.                                             // CryptEncrypt and CryptDecrypt
  242. #define CRYPT_BLOB_VER3         0x00000080  // export version 3 of a blob type
  243. #define CRYPT_IPSEC_HMAC_KEY    0x00000100  // CryptImportKey only
  244. // dwFlags definitions for CryptCreateHash
  245. #define CRYPT_SECRETDIGEST      0x00000001
  246. // dwFlags definitions for CryptHashData
  247. #define CRYPT_OWF_REPL_LM_HASH  0x00000001  // this is only for the OWF replacement CSP
  248. // dwFlags definitions for CryptHashSessionKey
  249. #define CRYPT_LITTLE_ENDIAN     0x00000001
  250. // dwFlags definitions for CryptSignHash and CryptVerifySignature
  251. #define CRYPT_NOHASHOID         0x00000001
  252. #define CRYPT_TYPE2_FORMAT      0x00000002
  253. #define CRYPT_X931_FORMAT       0x00000004
  254. // dwFlag definitions for CryptSetProviderEx and CryptGetDefaultProvider
  255. #define CRYPT_MACHINE_DEFAULT   0x00000001
  256. #define CRYPT_USER_DEFAULT      0x00000002
  257. #define CRYPT_DELETE_DEFAULT    0x00000004
  258. // exported key blob definitions
  259. #define SIMPLEBLOB              0x1
  260. #define PUBLICKEYBLOB           0x6
  261. #define PRIVATEKEYBLOB          0x7
  262. #define PLAINTEXTKEYBLOB        0x8
  263. #define OPAQUEKEYBLOB           0x9
  264. #define PUBLICKEYBLOBEX         0xA
  265. #define SYMMETRICWRAPKEYBLOB    0xB
  266. #define AT_KEYEXCHANGE          1
  267. #define AT_SIGNATURE            2
  268. #define CRYPT_USERDATA          1
  269. // dwParam
  270. #define KP_IV                   1       // Initialization vector
  271. #define KP_SALT                 2       // Salt value
  272. #define KP_PADDING              3       // Padding values
  273. #define KP_MODE                 4       // Mode of the cipher
  274. #define KP_MODE_BITS            5       // Number of bits to feedback
  275. #define KP_PERMISSIONS          6       // Key permissions DWORD
  276. #define KP_ALGID                7       // Key algorithm
  277. #define KP_BLOCKLEN             8       // Block size of the cipher
  278. #define KP_KEYLEN               9       // Length of key in bits
  279. #define KP_SALT_EX              10      // Length of salt in bytes
  280. #define KP_P                    11      // DSS/Diffie-Hellman P value
  281. #define KP_G                    12      // DSS/Diffie-Hellman G value
  282. #define KP_Q                    13      // DSS Q value
  283. #define KP_X                    14      // Diffie-Hellman X value
  284. #define KP_Y                    15      // Y value
  285. #define KP_RA                   16      // Fortezza RA value
  286. #define KP_RB                   17      // Fortezza RB value
  287. #define KP_INFO                 18      // for putting information into an RSA envelope
  288. #define KP_EFFECTIVE_KEYLEN     19      // setting and getting RC2 effective key length
  289. #define KP_SCHANNEL_ALG         20      // for setting the Secure Channel algorithms
  290. #define KP_CLIENT_RANDOM        21      // for setting the Secure Channel client random data
  291. #define KP_SERVER_RANDOM        22      // for setting the Secure Channel server random data
  292. #define KP_RP                   23
  293. #define KP_PRECOMP_MD5          24
  294. #define KP_PRECOMP_SHA          25
  295. #define KP_CERTIFICATE          26      // for setting Secure Channel certificate data (PCT1)
  296. #define KP_CLEAR_KEY            27      // for setting Secure Channel clear key data (PCT1)
  297. #define KP_PUB_EX_LEN           28
  298. #define KP_PUB_EX_VAL           29
  299. #define KP_KEYVAL               30
  300. #define KP_ADMIN_PIN            31
  301. #define KP_KEYEXCHANGE_PIN      32
  302. #define KP_SIGNATURE_PIN        33
  303. #define KP_PREHASH              34
  304. #define KP_OAEP_PARAMS          36      // for setting OAEP params on RSA keys
  305. #define KP_CMS_KEY_INFO         37
  306. #define KP_CMS_DH_KEY_INFO      38
  307. #define KP_PUB_PARAMS           39      // for setting public parameters
  308. #define KP_VERIFY_PARAMS        40      // for verifying DSA and DH parameters
  309. #define KP_HIGHEST_VERSION      41      // for TLS protocol version setting
  310. // KP_PADDING
  311. #define PKCS5_PADDING           1       // PKCS 5 (sec 6.2) padding method
  312. #define RANDOM_PADDING          2
  313. #define ZERO_PADDING            3
  314. // KP_MODE
  315. #define CRYPT_MODE_CBC          1       // Cipher block chaining
  316. #define CRYPT_MODE_ECB          2       // Electronic code book
  317. #define CRYPT_MODE_OFB          3       // Output feedback mode
  318. #define CRYPT_MODE_CFB          4       // Cipher feedback mode
  319. #define CRYPT_MODE_CTS          5       // Ciphertext stealing mode
  320. // KP_PERMISSIONS
  321. #define CRYPT_ENCRYPT           0x0001  // Allow encryption
  322. #define CRYPT_DECRYPT           0x0002  // Allow decryption
  323. #define CRYPT_EXPORT            0x0004  // Allow key to be exported
  324. #define CRYPT_READ              0x0008  // Allow parameters to be read
  325. #define CRYPT_WRITE             0x0010  // Allow parameters to be set
  326. #define CRYPT_MAC               0x0020  // Allow MACs to be used with key
  327. #define CRYPT_EXPORT_KEY        0x0040  // Allow key to be used for exporting keys
  328. #define CRYPT_IMPORT_KEY        0x0080  // Allow key to be used for importing keys
  329. #define CRYPT_ARCHIVE           0x0100  // Allow key to be exported at creation only
  330. #define HP_ALGID                0x0001  // Hash algorithm
  331. #define HP_HASHVAL              0x0002  // Hash value
  332. #define HP_HASHSIZE             0x0004  // Hash value size
  333. #define HP_HMAC_INFO            0x0005  // information for creating an HMAC
  334. #define HP_TLS1PRF_LABEL        0x0006  // label for TLS1 PRF
  335. #define HP_TLS1PRF_SEED         0x0007  // seed for TLS1 PRF
  336. #define CRYPT_FAILED            FALSE
  337. #define CRYPT_SUCCEED           TRUE
  338. #define RCRYPT_SUCCEEDED(rt)     ((rt) == CRYPT_SUCCEED)
  339. #define RCRYPT_FAILED(rt)        ((rt) == CRYPT_FAILED)
  340. //
  341. // CryptGetProvParam
  342. //
  343. #define PP_ENUMALGS             1
  344. #define PP_ENUMCONTAINERS       2
  345. #define PP_IMPTYPE              3
  346. #define PP_NAME                 4
  347. #define PP_VERSION              5
  348. #define PP_CONTAINER            6
  349. #define PP_CHANGE_PASSWORD      7
  350. #define PP_KEYSET_SEC_DESCR     8       // get/set security descriptor of keyset
  351. #define PP_CERTCHAIN            9       // for retrieving certificates from tokens
  352. #define PP_KEY_TYPE_SUBTYPE     10
  353. #define PP_PROVTYPE             16
  354. #define PP_KEYSTORAGE           17
  355. #define PP_APPLI_CERT           18
  356. #define PP_SYM_KEYSIZE          19
  357. #define PP_SESSION_KEYSIZE      20
  358. #define PP_UI_PROMPT            21
  359. #define PP_ENUMALGS_EX          22
  360. #define PP_ENUMMANDROOTS        25
  361. #define PP_ENUMELECTROOTS       26
  362. #define PP_KEYSET_TYPE          27
  363. #define PP_ADMIN_PIN            31
  364. #define PP_KEYEXCHANGE_PIN      32
  365. #define PP_SIGNATURE_PIN        33
  366. #define PP_SIG_KEYSIZE_INC      34
  367. #define PP_KEYX_KEYSIZE_INC     35
  368. #define PP_UNIQUE_CONTAINER     36
  369. #define PP_SGC_INFO             37
  370. #define PP_USE_HARDWARE_RNG     38
  371. #define PP_KEYSPEC              39
  372. #define PP_ENUMEX_SIGNING_PROT  40
  373. #define CRYPT_FIRST             1
  374. #define CRYPT_NEXT              2
  375. #define CRYPT_SGC_ENUM          4
  376. #define CRYPT_IMPL_HARDWARE     1
  377. #define CRYPT_IMPL_SOFTWARE     2
  378. #define CRYPT_IMPL_MIXED        3
  379. #define CRYPT_IMPL_UNKNOWN      4
  380. #define CRYPT_IMPL_REMOVABLE    8
  381. // key storage flags
  382. #define CRYPT_SEC_DESCR         0x00000001
  383. #define CRYPT_PSTORE            0x00000002
  384. #define CRYPT_UI_PROMPT         0x00000004
  385. // protocol flags
  386. #define CRYPT_FLAG_PCT1         0x0001
  387. #define CRYPT_FLAG_SSL2         0x0002
  388. #define CRYPT_FLAG_SSL3         0x0004
  389. #define CRYPT_FLAG_TLS1         0x0008
  390. #define CRYPT_FLAG_IPSEC        0x0010
  391. #define CRYPT_FLAG_SIGNING      0x0020
  392. // SGC flags
  393. #define CRYPT_SGC               0x0001
  394. #define CRYPT_FASTSGC           0x0002
  395. //
  396. // CryptSetProvParam
  397. //
  398. #define PP_CLIENT_HWND          1
  399. #define PP_CONTEXT_INFO         11
  400. #define PP_KEYEXCHANGE_KEYSIZE  12
  401. #define PP_SIGNATURE_KEYSIZE    13
  402. #define PP_KEYEXCHANGE_ALG      14
  403. #define PP_SIGNATURE_ALG        15
  404. #define PP_DELETEKEY            24
  405. #define PROV_RSA_FULL           1
  406. #define PROV_RSA_SIG            2
  407. #define PROV_DSS                3
  408. #define PROV_FORTEZZA           4
  409. #define PROV_MS_EXCHANGE        5
  410. #define PROV_SSL                6
  411. #define PROV_RSA_SCHANNEL       12
  412. #define PROV_DSS_DH             13
  413. #define PROV_EC_ECDSA_SIG       14
  414. #define PROV_EC_ECNRA_SIG       15
  415. #define PROV_EC_ECDSA_FULL      16
  416. #define PROV_EC_ECNRA_FULL      17
  417. #define PROV_DH_SCHANNEL        18
  418. #define PROV_SPYRUS_LYNKS       20
  419. #define PROV_RNG                21
  420. #define PROV_INTEL_SEC          22
  421. #define PROV_REPLACE_OWF        23
  422. #define PROV_RSA_AES            24
  423. //
  424. // STT defined Providers
  425. //
  426. #define PROV_STT_MER            7
  427. #define PROV_STT_ACQ            8
  428. #define PROV_STT_BRND           9
  429. #define PROV_STT_ROOT           10
  430. #define PROV_STT_ISS            11
  431. //
  432. // Provider friendly names
  433. //
  434. #define MS_DEF_PROV_A           "Microsoft Base Cryptographic Provider v1.0"
  435. #define MS_DEF_PROV_W           L"Microsoft Base Cryptographic Provider v1.0"
  436. #ifdef UNICODE
  437. #define MS_DEF_PROV             MS_DEF_PROV_W
  438. #else
  439. #define MS_DEF_PROV             MS_DEF_PROV_A
  440. #endif
  441. #define MS_ENHANCED_PROV_A      "Microsoft Enhanced Cryptographic Provider v1.0"
  442. #define MS_ENHANCED_PROV_W      L"Microsoft Enhanced Cryptographic Provider v1.0"
  443. #ifdef UNICODE
  444. #define MS_ENHANCED_PROV        MS_ENHANCED_PROV_W
  445. #else
  446. #define MS_ENHANCED_PROV        MS_ENHANCED_PROV_A
  447. #endif
  448. #define MS_STRONG_PROV_A        "Microsoft Strong Cryptographic Provider"
  449. #define MS_STRONG_PROV_W        L"Microsoft Strong Cryptographic Provider"
  450. #ifdef UNICODE
  451. #define MS_STRONG_PROV          MS_STRONG_PROV_W
  452. #else
  453. #define MS_STRONG_PROV          MS_STRONG_PROV_A
  454. #endif
  455. #define MS_DEF_RSA_SIG_PROV_A   "Microsoft RSA Signature Cryptographic Provider"
  456. #define MS_DEF_RSA_SIG_PROV_W   L"Microsoft RSA Signature Cryptographic Provider"
  457. #ifdef UNICODE
  458. #define MS_DEF_RSA_SIG_PROV     MS_DEF_RSA_SIG_PROV_W
  459. #else
  460. #define MS_DEF_RSA_SIG_PROV     MS_DEF_RSA_SIG_PROV_A
  461. #endif
  462. #define MS_DEF_RSA_SCHANNEL_PROV_A  "Microsoft RSA SChannel Cryptographic Provider"
  463. #define MS_DEF_RSA_SCHANNEL_PROV_W  L"Microsoft RSA SChannel Cryptographic Provider"
  464. #ifdef UNICODE
  465. #define MS_DEF_RSA_SCHANNEL_PROV    MS_DEF_RSA_SCHANNEL_PROV_W
  466. #else
  467. #define MS_DEF_RSA_SCHANNEL_PROV    MS_DEF_RSA_SCHANNEL_PROV_A
  468. #endif
  469. #define MS_DEF_DSS_PROV_A       "Microsoft Base DSS Cryptographic Provider"
  470. #define MS_DEF_DSS_PROV_W       L"Microsoft Base DSS Cryptographic Provider"
  471. #ifdef UNICODE
  472. #define MS_DEF_DSS_PROV         MS_DEF_DSS_PROV_W
  473. #else
  474. #define MS_DEF_DSS_PROV         MS_DEF_DSS_PROV_A
  475. #endif
  476. #define MS_DEF_DSS_DH_PROV_A    "Microsoft Base DSS and Diffie-Hellman Cryptographic Provider"
  477. #define MS_DEF_DSS_DH_PROV_W    L"Microsoft Base DSS and Diffie-Hellman Cryptographic Provider"
  478. #ifdef UNICODE
  479. #define MS_DEF_DSS_DH_PROV      MS_DEF_DSS_DH_PROV_W
  480. #else
  481. #define MS_DEF_DSS_DH_PROV      MS_DEF_DSS_DH_PROV_A
  482. #endif
  483. #define MS_ENH_DSS_DH_PROV_A    "Microsoft Enhanced DSS and Diffie-Hellman Cryptographic Provider"
  484. #define MS_ENH_DSS_DH_PROV_W    L"Microsoft Enhanced DSS and Diffie-Hellman Cryptographic Provider"
  485. #ifdef UNICODE
  486. #define MS_ENH_DSS_DH_PROV      MS_ENH_DSS_DH_PROV_W
  487. #else
  488. #define MS_ENH_DSS_DH_PROV      MS_ENH_DSS_DH_PROV_A
  489. #endif
  490. #define MS_DEF_DH_SCHANNEL_PROV_A  "Microsoft DH SChannel Cryptographic Provider"
  491. #define MS_DEF_DH_SCHANNEL_PROV_W  L"Microsoft DH SChannel Cryptographic Provider"
  492. #ifdef UNICODE
  493. #define MS_DEF_DH_SCHANNEL_PROV MS_DEF_DH_SCHANNEL_PROV_W
  494. #else
  495. #define MS_DEF_DH_SCHANNEL_PROV MS_DEF_DH_SCHANNEL_PROV_A
  496. #endif
  497. #define MS_SCARD_PROV_A         "Microsoft Base Smart Card Crypto Provider"
  498. #define MS_SCARD_PROV_W         L"Microsoft Base Smart Card Crypto Provider"
  499. #ifdef UNICODE
  500. #define MS_SCARD_PROV           MS_SCARD_PROV_W
  501. #else
  502. #define MS_SCARD_PROV           MS_SCARD_PROV_A
  503. #endif
  504. #define MS_ENH_RSA_AES_PROV_A   "Microsoft Enhanced RSA and AES Cryptographic Provider (Prototype)"
  505. #define MS_ENH_RSA_AES_PROV_W   L"Microsoft Enhanced RSA and AES Cryptographic Provider (Prototype)"
  506. #ifdef UNICODE
  507. #define MS_ENH_RSA_AES_PROV     MS_ENH_RSA_AES_PROV_W
  508. #else
  509. #define MS_ENH_RSA_AES_PROV     MS_ENH_RSA_AES_PROV_A
  510. #endif
  511. #define MAXUIDLEN               64
  512. // Exponentiation Offload Reg Location
  513. #define EXPO_OFFLOAD_REG_VALUE "ExpoOffload"
  514. #define EXPO_OFFLOAD_FUNC_NAME "OffloadModExpo"
  515. #define CUR_BLOB_VERSION        2
  516. // structure for use with CryptSetKeyParam for CMS keys
  517. // DO NOT USE THIS STRUCTURE!!!!!
  518. typedef struct _CMS_KEY_INFO {
  519.     DWORD       dwVersion;                      // sizeof(CMS_KEY_INFO)
  520.     ALG_ID  Algid;                              // algorithmm id for the key to be converted
  521.     BYTE    *pbOID;                             // pointer to OID to hash in with Z
  522.     DWORD   cbOID;                              // length of OID to hash in with Z
  523. } CMS_KEY_INFO, *PCMS_KEY_INFO;
  524. // structure for use with CryptSetHashParam with CALG_HMAC
  525. typedef struct _HMAC_Info {
  526.     ALG_ID  HashAlgid;
  527.     BYTE    *pbInnerString;
  528.     DWORD   cbInnerString;
  529.     BYTE    *pbOuterString;
  530.     DWORD   cbOuterString;
  531. } HMAC_INFO, *PHMAC_INFO;
  532. // structure for use with CryptSetKeyParam with KP_SCHANNEL_ALG
  533. typedef struct _SCHANNEL_ALG {
  534.     DWORD   dwUse;
  535.     ALG_ID  Algid;
  536.     DWORD   cBits;
  537.     DWORD   dwFlags;
  538.     DWORD   dwReserved;
  539. } SCHANNEL_ALG, *PSCHANNEL_ALG;
  540. // uses of algortihms for SCHANNEL_ALG structure
  541. #define     SCHANNEL_MAC_KEY    0x00000000
  542. #define     SCHANNEL_ENC_KEY    0x00000001
  543. // uses of dwFlags SCHANNEL_ALG structure
  544. #define     INTERNATIONAL_USAGE 0x00000001
  545. typedef struct _PROV_ENUMALGS {
  546.     ALG_ID    aiAlgid;
  547.     DWORD     dwBitLen;
  548.     DWORD     dwNameLen;
  549.     CHAR      szName[20];
  550. } PROV_ENUMALGS;
  551. typedef struct _PROV_ENUMALGS_EX {
  552.     ALG_ID    aiAlgid;
  553.     DWORD     dwDefaultLen;
  554.     DWORD     dwMinLen;
  555.     DWORD     dwMaxLen;
  556.     DWORD     dwProtocols;
  557.     DWORD     dwNameLen;
  558.     CHAR      szName[20];
  559.     DWORD     dwLongNameLen;
  560.     CHAR      szLongName[40];
  561. } PROV_ENUMALGS_EX;
  562. typedef struct _PUBLICKEYSTRUC {
  563.         BYTE    bType;
  564.         BYTE    bVersion;
  565.         WORD    reserved;
  566.         ALG_ID  aiKeyAlg;
  567. } BLOBHEADER, PUBLICKEYSTRUC;
  568. typedef struct _RSAPUBKEY {
  569.         DWORD   magic;                  // Has to be RSA1
  570.         DWORD   bitlen;                 // # of bits in modulus
  571.         DWORD   pubexp;                 // public exponent
  572.                                         // Modulus data follows
  573. } RSAPUBKEY;
  574. typedef struct _PUBKEY {
  575.         DWORD   magic;
  576.         DWORD   bitlen;                 // # of bits in modulus
  577. } DHPUBKEY, DSSPUBKEY, KEAPUBKEY, TEKPUBKEY;
  578. typedef struct _DSSSEED {
  579.         DWORD   counter;
  580.         BYTE    seed[20];
  581. } DSSSEED;
  582. typedef struct _PUBKEYVER3 {
  583.         DWORD   magic;
  584.         DWORD   bitlenP;                // # of bits in prime modulus
  585.         DWORD   bitlenQ;                // # of bits in prime q, 0 if not available
  586.         DWORD   bitlenJ;                // # of bits in (p-1)/q, 0 if not available
  587.         DSSSEED DSSSeed;
  588. } DHPUBKEY_VER3, DSSPUBKEY_VER3;
  589. typedef struct _PRIVKEYVER3 {
  590.         DWORD   magic;
  591.         DWORD   bitlenP;                // # of bits in prime modulus
  592.         DWORD   bitlenQ;                // # of bits in prime q, 0 if not available
  593.         DWORD   bitlenJ;                // # of bits in (p-1)/q, 0 if not available
  594.         DWORD   bitlenX;                // # of bits in X
  595.         DSSSEED DSSSeed;
  596. } DHPRIVKEY_VER3, DSSPRIVKEY_VER3;
  597. typedef struct _KEY_TYPE_SUBTYPE {
  598.         DWORD   dwKeySpec;
  599.         GUID    Type;
  600.         GUID    Subtype;
  601. } KEY_TYPE_SUBTYPE, *PKEY_TYPE_SUBTYPE;
  602. typedef struct _CERT_FORTEZZA_DATA_PROP {
  603.     unsigned char   SerialNumber[8];
  604.     int             CertIndex;
  605.     unsigned char   CertLabel[36];
  606. } CERT_FORTEZZA_DATA_PROP;
  607. //+-------------------------------------------------------------------------
  608. //  CRYPTOAPI BLOB definitions
  609. //--------------------------------------------------------------------------
  610. typedef struct _CRYPTOAPI_BLOB {
  611.     DWORD   cbData;
  612.     BYTE    *pbData;
  613. } CRYPT_INTEGER_BLOB, *PCRYPT_INTEGER_BLOB,
  614. CRYPT_UINT_BLOB, *PCRYPT_UINT_BLOB,
  615. CRYPT_OBJID_BLOB, *PCRYPT_OBJID_BLOB,
  616. CERT_NAME_BLOB, *PCERT_NAME_BLOB,
  617. CERT_RDN_VALUE_BLOB, *PCERT_RDN_VALUE_BLOB,
  618. CERT_BLOB, *PCERT_BLOB,
  619. CRL_BLOB, *PCRL_BLOB,
  620. DATA_BLOB, *PDATA_BLOB,
  621. CRYPT_DATA_BLOB, *PCRYPT_DATA_BLOB,
  622. CRYPT_HASH_BLOB, *PCRYPT_HASH_BLOB,
  623. CRYPT_DIGEST_BLOB, *PCRYPT_DIGEST_BLOB,
  624. CRYPT_DER_BLOB, *PCRYPT_DER_BLOB,
  625. CRYPT_ATTR_BLOB, *PCRYPT_ATTR_BLOB;
  626. // structure for use with CryptSetKeyParam for CMS keys
  627. typedef struct _CMS_DH_KEY_INFO {
  628.     DWORD               dwVersion;                      // sizeof(CMS_DH_KEY_INFO)
  629.     ALG_ID          Algid;                              // algorithmm id for the key to be converted
  630.     LPSTR           pszContentEncObjId; // pointer to OID to hash in with Z
  631.     CRYPT_DATA_BLOB PubInfo;            // OPTIONAL - public information
  632.     void            *pReserved;         // reserved - should be NULL
  633. } CMS_DH_KEY_INFO, *PCMS_DH_KEY_INFO;
  634. WINADVAPI
  635. BOOL
  636. WINAPI
  637. CryptAcquireContextA(
  638.     HCRYPTPROV *phProv,
  639.     LPCSTR szContainer,
  640.     LPCSTR szProvider,
  641.     DWORD dwProvType,
  642.     DWORD dwFlags
  643.     );
  644. WINADVAPI
  645. BOOL
  646. WINAPI
  647. CryptAcquireContextW(
  648.     HCRYPTPROV *phProv,
  649.     LPCWSTR szContainer,
  650.     LPCWSTR szProvider,
  651.     DWORD dwProvType,
  652.     DWORD dwFlags
  653.     );
  654. #ifdef UNICODE
  655. #define CryptAcquireContext  CryptAcquireContextW
  656. #else
  657. #define CryptAcquireContext  CryptAcquireContextA
  658. #endif // !UNICODE
  659. WINADVAPI
  660. BOOL
  661. WINAPI
  662. CryptReleaseContext(
  663.     HCRYPTPROV hProv,
  664.     DWORD dwFlags
  665.     );
  666. WINADVAPI
  667. BOOL
  668. WINAPI
  669. CryptGenKey(
  670.     HCRYPTPROV hProv,
  671.     ALG_ID Algid,
  672.     DWORD dwFlags,
  673.     HCRYPTKEY *phKey
  674.     );
  675. WINADVAPI
  676. BOOL
  677. WINAPI
  678. CryptDeriveKey(
  679.     HCRYPTPROV hProv,
  680.     ALG_ID Algid,
  681.     HCRYPTHASH hBaseData,
  682.     DWORD dwFlags,
  683.     HCRYPTKEY *phKey
  684.     );
  685. WINADVAPI
  686. BOOL
  687. WINAPI
  688. CryptDestroyKey(
  689.     HCRYPTKEY hKey
  690.     );
  691. WINADVAPI
  692. BOOL
  693. WINAPI
  694. CryptSetKeyParam(
  695.     HCRYPTKEY hKey,
  696.     DWORD dwParam,
  697.     CONST BYTE *pbData,
  698.     DWORD dwFlags
  699.     );
  700. WINADVAPI
  701. BOOL
  702. WINAPI
  703. CryptGetKeyParam(
  704.     HCRYPTKEY hKey,
  705.     DWORD dwParam,
  706.     BYTE *pbData,
  707.     DWORD *pdwDataLen,
  708.     DWORD dwFlags
  709.     );
  710. WINADVAPI
  711. BOOL
  712. WINAPI
  713. CryptSetHashParam(
  714.     HCRYPTHASH hHash,
  715.     DWORD dwParam,
  716.     CONST BYTE *pbData,
  717.     DWORD dwFlags
  718.     );
  719. WINADVAPI
  720. BOOL
  721. WINAPI
  722. CryptGetHashParam(
  723.     HCRYPTHASH hHash,
  724.     DWORD dwParam,
  725.     BYTE *pbData,
  726.     DWORD *pdwDataLen,
  727.     DWORD dwFlags
  728.     );
  729. WINADVAPI
  730. BOOL
  731. WINAPI
  732. CryptSetProvParam(
  733.     HCRYPTPROV hProv,
  734.     DWORD dwParam,
  735.     CONST BYTE *pbData,
  736.     DWORD dwFlags
  737.     );
  738. WINADVAPI
  739. BOOL
  740. WINAPI
  741. CryptGetProvParam(
  742.     HCRYPTPROV hProv,
  743.     DWORD dwParam,
  744.     BYTE *pbData,
  745.     DWORD *pdwDataLen,
  746.     DWORD dwFlags
  747.     );
  748. WINADVAPI
  749. BOOL
  750. WINAPI
  751. CryptGenRandom(
  752.     HCRYPTPROV hProv,
  753.     DWORD dwLen,
  754.     BYTE *pbBuffer
  755.     );
  756. WINADVAPI
  757. BOOL
  758. WINAPI
  759. CryptGetUserKey(
  760.     HCRYPTPROV hProv,
  761.     DWORD dwKeySpec,
  762.     HCRYPTKEY *phUserKey
  763.     );
  764. WINADVAPI
  765. BOOL
  766. WINAPI
  767. CryptExportKey(
  768.     HCRYPTKEY hKey,
  769.     HCRYPTKEY hExpKey,
  770.     DWORD dwBlobType,
  771.     DWORD dwFlags,
  772.     BYTE *pbData,
  773.     DWORD *pdwDataLen
  774.     );
  775. WINADVAPI
  776. BOOL
  777. WINAPI
  778. CryptImportKey(
  779.     HCRYPTPROV hProv,
  780.     CONST BYTE *pbData,
  781.     DWORD dwDataLen,
  782.     HCRYPTKEY hPubKey,
  783.     DWORD dwFlags,
  784.     HCRYPTKEY *phKey
  785.     );
  786. WINADVAPI
  787. BOOL
  788. WINAPI
  789. CryptEncrypt(
  790.     HCRYPTKEY hKey,
  791.     HCRYPTHASH hHash,
  792.     BOOL Final,
  793.     DWORD dwFlags,
  794.     BYTE *pbData,
  795.     DWORD *pdwDataLen,
  796.     DWORD dwBufLen
  797.     );
  798. WINADVAPI
  799. BOOL
  800. WINAPI
  801. CryptDecrypt(
  802.     HCRYPTKEY hKey,
  803.     HCRYPTHASH hHash,
  804.     BOOL Final,
  805.     DWORD dwFlags,
  806.     BYTE *pbData,
  807.     DWORD *pdwDataLen
  808.     );
  809. WINADVAPI
  810. BOOL
  811. WINAPI
  812. CryptCreateHash(
  813.     HCRYPTPROV hProv,
  814.     ALG_ID Algid,
  815.     HCRYPTKEY hKey,
  816.     DWORD dwFlags,
  817.     HCRYPTHASH *phHash
  818.     );
  819. WINADVAPI
  820. BOOL
  821. WINAPI
  822. CryptHashData(
  823.     HCRYPTHASH hHash,
  824.     CONST BYTE *pbData,
  825.     DWORD dwDataLen,
  826.     DWORD dwFlags
  827.     );
  828. WINADVAPI
  829. BOOL
  830. WINAPI
  831. CryptHashSessionKey(
  832.     HCRYPTHASH hHash,
  833.     HCRYPTKEY hKey,
  834.     DWORD dwFlags
  835.     );
  836. WINADVAPI
  837. BOOL
  838. WINAPI
  839. CryptDestroyHash(
  840.     HCRYPTHASH hHash
  841.     );
  842. WINADVAPI
  843. BOOL
  844. WINAPI
  845. CryptSignHashA(
  846.     HCRYPTHASH hHash,
  847.     DWORD dwKeySpec,
  848.     LPCSTR szDescription,
  849.     DWORD dwFlags,
  850.     BYTE *pbSignature,
  851.     DWORD *pdwSigLen
  852.     );
  853. WINADVAPI
  854. BOOL
  855. WINAPI
  856. CryptSignHashW(
  857.     HCRYPTHASH hHash,
  858.     DWORD dwKeySpec,
  859.     LPCWSTR szDescription,
  860.     DWORD dwFlags,
  861.     BYTE *pbSignature,
  862.     DWORD *pdwSigLen
  863.     );
  864. #ifdef UNICODE
  865. #define CryptSignHash  CryptSignHashW
  866. #else
  867. #define CryptSignHash  CryptSignHashA
  868. #endif // !UNICODE
  869. WINADVAPI
  870. BOOL
  871. WINAPI
  872. CryptVerifySignatureA(
  873.     HCRYPTHASH hHash,
  874.     CONST BYTE *pbSignature,
  875.     DWORD dwSigLen,
  876.     HCRYPTKEY hPubKey,
  877.     LPCSTR szDescription,
  878.     DWORD dwFlags
  879.     );
  880. WINADVAPI
  881. BOOL
  882. WINAPI
  883. CryptVerifySignatureW(
  884.     HCRYPTHASH hHash,
  885.     CONST BYTE *pbSignature,
  886.     DWORD dwSigLen,
  887.     HCRYPTKEY hPubKey,
  888.     LPCWSTR szDescription,
  889.     DWORD dwFlags
  890.     );
  891. #ifdef UNICODE
  892. #define CryptVerifySignature  CryptVerifySignatureW
  893. #else
  894. #define CryptVerifySignature  CryptVerifySignatureA
  895. #endif // !UNICODE
  896. WINADVAPI
  897. BOOL
  898. WINAPI
  899. CryptSetProviderA(
  900.     LPCSTR pszProvName,
  901.     DWORD dwProvType
  902.     );
  903. WINADVAPI
  904. BOOL
  905. WINAPI
  906. CryptSetProviderW(
  907.     LPCWSTR pszProvName,
  908.     DWORD dwProvType
  909.     );
  910. #ifdef UNICODE
  911. #define CryptSetProvider  CryptSetProviderW
  912. #else
  913. #define CryptSetProvider  CryptSetProviderA
  914. #endif // !UNICODE
  915. WINADVAPI
  916. BOOL
  917. WINAPI
  918. CryptSetProviderExA(
  919.     LPCSTR pszProvName,
  920.     DWORD dwProvType,
  921.     DWORD *pdwReserved,
  922.     DWORD dwFlags
  923.     );
  924. WINADVAPI
  925. BOOL
  926. WINAPI
  927. CryptSetProviderExW(
  928.     LPCWSTR pszProvName,
  929.     DWORD dwProvType,
  930.     DWORD *pdwReserved,
  931.     DWORD dwFlags
  932.     );
  933. #ifdef UNICODE
  934. #define CryptSetProviderEx  CryptSetProviderExW
  935. #else
  936. #define CryptSetProviderEx  CryptSetProviderExA
  937. #endif // !UNICODE
  938. WINADVAPI
  939. BOOL
  940. WINAPI
  941. CryptGetDefaultProviderA(
  942.     DWORD dwProvType,
  943.     DWORD *pdwReserved,
  944.     DWORD dwFlags,
  945.     LPSTR pszProvName,
  946.     DWORD *pcbProvName
  947.     );
  948. WINADVAPI
  949. BOOL
  950. WINAPI
  951. CryptGetDefaultProviderW(
  952.     DWORD dwProvType,
  953.     DWORD *pdwReserved,
  954.     DWORD dwFlags,
  955.     LPWSTR pszProvName,
  956.     DWORD *pcbProvName
  957.     );
  958. #ifdef UNICODE
  959. #define CryptGetDefaultProvider  CryptGetDefaultProviderW
  960. #else
  961. #define CryptGetDefaultProvider  CryptGetDefaultProviderA
  962. #endif // !UNICODE
  963. WINADVAPI
  964. BOOL
  965. WINAPI
  966. CryptEnumProviderTypesA(
  967.     DWORD dwIndex,
  968.     DWORD *pdwReserved,
  969.     DWORD dwFlags,
  970.     DWORD *pdwProvType,
  971.     LPSTR szTypeName,
  972.     DWORD *pcbTypeName
  973.     );
  974. WINADVAPI
  975. BOOL
  976. WINAPI
  977. CryptEnumProviderTypesW(
  978.     DWORD dwIndex,
  979.     DWORD *pdwReserved,
  980.     DWORD dwFlags,
  981.     DWORD *pdwProvType,
  982.     LPWSTR szTypeName,
  983.     DWORD *pcbTypeName
  984.     );
  985. #ifdef UNICODE
  986. #define CryptEnumProviderTypes  CryptEnumProviderTypesW
  987. #else
  988. #define CryptEnumProviderTypes  CryptEnumProviderTypesA
  989. #endif // !UNICODE
  990. WINADVAPI
  991. BOOL
  992. WINAPI
  993. CryptEnumProvidersA(
  994.     DWORD dwIndex,
  995.     DWORD *pdwReserved,
  996.     DWORD dwFlags,
  997.     DWORD *pdwProvType,
  998.     LPSTR szProvName,
  999.     DWORD *pcbProvName
  1000.     );
  1001. WINADVAPI
  1002. BOOL
  1003. WINAPI
  1004. CryptEnumProvidersW(
  1005.     DWORD dwIndex,
  1006.     DWORD *pdwReserved,
  1007.     DWORD dwFlags,
  1008.     DWORD *pdwProvType,
  1009.     LPWSTR szProvName,
  1010.     DWORD *pcbProvName
  1011.     );
  1012. #ifdef UNICODE
  1013. #define CryptEnumProviders  CryptEnumProvidersW
  1014. #else
  1015. #define CryptEnumProviders  CryptEnumProvidersA
  1016. #endif // !UNICODE
  1017. WINADVAPI
  1018. BOOL
  1019. WINAPI
  1020. CryptContextAddRef(
  1021.     HCRYPTPROV hProv,
  1022.     DWORD *pdwReserved,
  1023.     DWORD dwFlags
  1024.     );
  1025. WINADVAPI
  1026. BOOL
  1027. WINAPI
  1028. CryptDuplicateKey(
  1029.     HCRYPTKEY hKey,
  1030.     DWORD *pdwReserved,
  1031.     DWORD dwFlags,
  1032.     HCRYPTKEY *phKey
  1033.     );
  1034. WINADVAPI
  1035. BOOL
  1036. WINAPI
  1037. CryptDuplicateHash(
  1038.     HCRYPTHASH hHash,
  1039.     DWORD *pdwReserved,
  1040.     DWORD dwFlags,
  1041.     HCRYPTHASH *phHash
  1042.     );
  1043. typedef struct {
  1044.     DWORD  dwVersion;
  1045.     ALG_ID algId;
  1046.     DWORD  dwMinKeyLength;
  1047.     DWORD  dwMaxKeyLength;
  1048.     DWORD  dwRequiredFlags;
  1049.     DWORD  dwDisallowedFlags;
  1050. } _CRYPT_KEY_LIMITS_V01;
  1051. typedef _CRYPT_KEY_LIMITS_V01 CRYPT_KEY_LIMITS, *PCRYPT_KEY_LIMITS;
  1052. // Request Flag definitions
  1053. #define CRYPTLIMIT_USING_PCT 0x0001
  1054. #define CRYPTLIMIT_USING_SGC 0x0002
  1055. WINADVAPI
  1056. BOOL
  1057. WINAPI
  1058. CryptGetLocalKeyLimits(
  1059.     IN  ALG_ID algId,
  1060.     IN  DWORD dwFlags,
  1061.     OUT PCRYPT_KEY_LIMITS pLimits,
  1062.     IN OUT LPDWORD cbLimitLength);
  1063. //+-------------------------------------------------------------------------
  1064. //  In a CRYPT_BIT_BLOB the last byte may contain 0-7 unused bits. Therefore, the
  1065. //  overall bit length is cbData * 8 - cUnusedBits.
  1066. //--------------------------------------------------------------------------
  1067. typedef struct _CRYPT_BIT_BLOB {
  1068.     DWORD   cbData;
  1069.     BYTE    *pbData;
  1070.     DWORD   cUnusedBits;
  1071. } CRYPT_BIT_BLOB, *PCRYPT_BIT_BLOB;
  1072. //+-------------------------------------------------------------------------
  1073. //  Type used for any algorithm
  1074. //
  1075. //  Where the Parameters CRYPT_OBJID_BLOB is in its encoded representation. For most
  1076. //  algorithm types, the Parameters CRYPT_OBJID_BLOB is NULL (Parameters.cbData = 0).
  1077. //--------------------------------------------------------------------------
  1078. typedef struct _CRYPT_ALGORITHM_IDENTIFIER {
  1079.     LPSTR               pszObjId;
  1080.     CRYPT_OBJID_BLOB    Parameters;
  1081. } CRYPT_ALGORITHM_IDENTIFIER, *PCRYPT_ALGORITHM_IDENTIFIER;
  1082. // Following are the definitions of various algorithm object identifiers
  1083. // RSA
  1084. #define szOID_RSA               "1.2.840.113549"
  1085. #define szOID_PKCS              "1.2.840.113549.1"
  1086. #define szOID_RSA_HASH          "1.2.840.113549.2"
  1087. #define szOID_RSA_ENCRYPT       "1.2.840.113549.3"
  1088. #define szOID_PKCS_1            "1.2.840.113549.1.1"
  1089. #define szOID_PKCS_2            "1.2.840.113549.1.2"
  1090. #define szOID_PKCS_3            "1.2.840.113549.1.3"
  1091. #define szOID_PKCS_4            "1.2.840.113549.1.4"
  1092. #define szOID_PKCS_5            "1.2.840.113549.1.5"
  1093. #define szOID_PKCS_6            "1.2.840.113549.1.6"
  1094. #define szOID_PKCS_7            "1.2.840.113549.1.7"
  1095. #define szOID_PKCS_8            "1.2.840.113549.1.8"
  1096. #define szOID_PKCS_9            "1.2.840.113549.1.9"
  1097. #define szOID_PKCS_10           "1.2.840.113549.1.10"
  1098. #define szOID_PKCS_12           "1.2.840.113549.1.12"
  1099. #define szOID_RSA_RSA           "1.2.840.113549.1.1.1"
  1100. #define szOID_RSA_MD2RSA        "1.2.840.113549.1.1.2"
  1101. #define szOID_RSA_MD4RSA        "1.2.840.113549.1.1.3"
  1102. #define szOID_RSA_MD5RSA        "1.2.840.113549.1.1.4"
  1103. #define szOID_RSA_SHA1RSA       "1.2.840.113549.1.1.5"
  1104. #define szOID_RSA_SETOAEP_RSA   "1.2.840.113549.1.1.6"
  1105. #define szOID_RSA_DH            "1.2.840.113549.1.3.1"
  1106. #define szOID_RSA_data          "1.2.840.113549.1.7.1"
  1107. #define szOID_RSA_signedData    "1.2.840.113549.1.7.2"
  1108. #define szOID_RSA_envelopedData "1.2.840.113549.1.7.3"
  1109. #define szOID_RSA_signEnvData   "1.2.840.113549.1.7.4"
  1110. #define szOID_RSA_digestedData  "1.2.840.113549.1.7.5"
  1111. #define szOID_RSA_hashedData    "1.2.840.113549.1.7.5"
  1112. #define szOID_RSA_encryptedData "1.2.840.113549.1.7.6"
  1113. #define szOID_RSA_emailAddr     "1.2.840.113549.1.9.1"
  1114. #define szOID_RSA_unstructName  "1.2.840.113549.1.9.2"
  1115. #define szOID_RSA_contentType   "1.2.840.113549.1.9.3"
  1116. #define szOID_RSA_messageDigest "1.2.840.113549.1.9.4"
  1117. #define szOID_RSA_signingTime   "1.2.840.113549.1.9.5"
  1118. #define szOID_RSA_counterSign   "1.2.840.113549.1.9.6"
  1119. #define szOID_RSA_challengePwd  "1.2.840.113549.1.9.7"
  1120. #define szOID_RSA_unstructAddr  "1.2.840.113549.1.9.8"
  1121. #define szOID_RSA_extCertAttrs  "1.2.840.113549.1.9.9"
  1122. #define szOID_RSA_certExtensions "1.2.840.113549.1.9.14"
  1123. #define szOID_RSA_SMIMECapabilities "1.2.840.113549.1.9.15"
  1124. #define szOID_RSA_preferSignedData "1.2.840.113549.1.9.15.1"
  1125. #define szOID_RSA_SMIMEalg              "1.2.840.113549.1.9.16.3"
  1126. #define szOID_RSA_SMIMEalgESDH          "1.2.840.113549.1.9.16.3.5"
  1127. #define szOID_RSA_SMIMEalgCMS3DESwrap   "1.2.840.113549.1.9.16.3.6"
  1128. #define szOID_RSA_SMIMEalgCMSRC2wrap    "1.2.840.113549.1.9.16.3.7"
  1129. #define szOID_RSA_MD2           "1.2.840.113549.2.2"
  1130. #define szOID_RSA_MD4           "1.2.840.113549.2.4"
  1131. #define szOID_RSA_MD5           "1.2.840.113549.2.5"
  1132. #define szOID_RSA_RC2CBC        "1.2.840.113549.3.2"
  1133. #define szOID_RSA_RC4           "1.2.840.113549.3.4"
  1134. #define szOID_RSA_DES_EDE3_CBC  "1.2.840.113549.3.7"
  1135. #define szOID_RSA_RC5_CBCPad    "1.2.840.113549.3.9"
  1136. #define szOID_ANSI_X942         "1.2.840.10046"
  1137. #define szOID_ANSI_X942_DH      "1.2.840.10046.2.1"
  1138. #define szOID_X957              "1.2.840.10040"
  1139. #define szOID_X957_DSA          "1.2.840.10040.4.1"
  1140. #define szOID_X957_SHA1DSA      "1.2.840.10040.4.3"
  1141. // ITU-T UsefulDefinitions
  1142. #define szOID_DS                "2.5"
  1143. #define szOID_DSALG             "2.5.8"
  1144. #define szOID_DSALG_CRPT        "2.5.8.1"
  1145. #define szOID_DSALG_HASH        "2.5.8.2"
  1146. #define szOID_DSALG_SIGN        "2.5.8.3"
  1147. #define szOID_DSALG_RSA         "2.5.8.1.1"
  1148. // NIST OSE Implementors' Workshop (OIW)
  1149. // http://nemo.ncsl.nist.gov/oiw/agreements/stable/OSI/12s_9506.w51
  1150. // http://nemo.ncsl.nist.gov/oiw/agreements/working/OSI/12w_9503.w51
  1151. #define szOID_OIW               "1.3.14"
  1152. // NIST OSE Implementors' Workshop (OIW) Security SIG algorithm identifiers
  1153. #define szOID_OIWSEC            "1.3.14.3.2"
  1154. #define szOID_OIWSEC_md4RSA     "1.3.14.3.2.2"
  1155. #define szOID_OIWSEC_md5RSA     "1.3.14.3.2.3"
  1156. #define szOID_OIWSEC_md4RSA2    "1.3.14.3.2.4"
  1157. #define szOID_OIWSEC_desECB     "1.3.14.3.2.6"
  1158. #define szOID_OIWSEC_desCBC     "1.3.14.3.2.7"
  1159. #define szOID_OIWSEC_desOFB     "1.3.14.3.2.8"
  1160. #define szOID_OIWSEC_desCFB     "1.3.14.3.2.9"
  1161. #define szOID_OIWSEC_desMAC     "1.3.14.3.2.10"
  1162. #define szOID_OIWSEC_rsaSign    "1.3.14.3.2.11"
  1163. #define szOID_OIWSEC_dsa        "1.3.14.3.2.12"
  1164. #define szOID_OIWSEC_shaDSA     "1.3.14.3.2.13"
  1165. #define szOID_OIWSEC_mdc2RSA    "1.3.14.3.2.14"
  1166. #define szOID_OIWSEC_shaRSA     "1.3.14.3.2.15"
  1167. #define szOID_OIWSEC_dhCommMod  "1.3.14.3.2.16"
  1168. #define szOID_OIWSEC_desEDE     "1.3.14.3.2.17"
  1169. #define szOID_OIWSEC_sha        "1.3.14.3.2.18"
  1170. #define szOID_OIWSEC_mdc2       "1.3.14.3.2.19"
  1171. #define szOID_OIWSEC_dsaComm    "1.3.14.3.2.20"
  1172. #define szOID_OIWSEC_dsaCommSHA "1.3.14.3.2.21"
  1173. #define szOID_OIWSEC_rsaXchg    "1.3.14.3.2.22"
  1174. #define szOID_OIWSEC_keyHashSeal "1.3.14.3.2.23"
  1175. #define szOID_OIWSEC_md2RSASign "1.3.14.3.2.24"
  1176. #define szOID_OIWSEC_md5RSASign "1.3.14.3.2.25"
  1177. #define szOID_OIWSEC_sha1       "1.3.14.3.2.26"
  1178. #define szOID_OIWSEC_dsaSHA1    "1.3.14.3.2.27"
  1179. #define szOID_OIWSEC_dsaCommSHA1 "1.3.14.3.2.28"
  1180. #define szOID_OIWSEC_sha1RSASign "1.3.14.3.2.29"
  1181. // NIST OSE Implementors' Workshop (OIW) Directory SIG algorithm identifiers
  1182. #define szOID_OIWDIR            "1.3.14.7.2"
  1183. #define szOID_OIWDIR_CRPT       "1.3.14.7.2.1"
  1184. #define szOID_OIWDIR_HASH       "1.3.14.7.2.2"
  1185. #define szOID_OIWDIR_SIGN       "1.3.14.7.2.3"
  1186. #define szOID_OIWDIR_md2        "1.3.14.7.2.2.1"
  1187. #define szOID_OIWDIR_md2RSA     "1.3.14.7.2.3.1"
  1188. // INFOSEC Algorithms
  1189. // joint-iso-ccitt(2) country(16) us(840) organization(1) us-government(101) dod(2) id-infosec(1)
  1190. #define szOID_INFOSEC                       "2.16.840.1.101.2.1"
  1191. #define szOID_INFOSEC_sdnsSignature         "2.16.840.1.101.2.1.1.1"
  1192. #define szOID_INFOSEC_mosaicSignature       "2.16.840.1.101.2.1.1.2"
  1193. #define szOID_INFOSEC_sdnsConfidentiality   "2.16.840.1.101.2.1.1.3"
  1194. #define szOID_INFOSEC_mosaicConfidentiality "2.16.840.1.101.2.1.1.4"
  1195. #define szOID_INFOSEC_sdnsIntegrity         "2.16.840.1.101.2.1.1.5"
  1196. #define szOID_INFOSEC_mosaicIntegrity       "2.16.840.1.101.2.1.1.6"
  1197. #define szOID_INFOSEC_sdnsTokenProtection   "2.16.840.1.101.2.1.1.7"
  1198. #define szOID_INFOSEC_mosaicTokenProtection "2.16.840.1.101.2.1.1.8"
  1199. #define szOID_INFOSEC_sdnsKeyManagement     "2.16.840.1.101.2.1.1.9"
  1200. #define szOID_INFOSEC_mosaicKeyManagement   "2.16.840.1.101.2.1.1.10"
  1201. #define szOID_INFOSEC_sdnsKMandSig          "2.16.840.1.101.2.1.1.11"
  1202. #define szOID_INFOSEC_mosaicKMandSig        "2.16.840.1.101.2.1.1.12"
  1203. #define szOID_INFOSEC_SuiteASignature       "2.16.840.1.101.2.1.1.13"
  1204. #define szOID_INFOSEC_SuiteAConfidentiality "2.16.840.1.101.2.1.1.14"
  1205. #define szOID_INFOSEC_SuiteAIntegrity       "2.16.840.1.101.2.1.1.15"
  1206. #define szOID_INFOSEC_SuiteATokenProtection "2.16.840.1.101.2.1.1.16"
  1207. #define szOID_INFOSEC_SuiteAKeyManagement   "2.16.840.1.101.2.1.1.17"
  1208. #define szOID_INFOSEC_SuiteAKMandSig        "2.16.840.1.101.2.1.1.18"
  1209. #define szOID_INFOSEC_mosaicUpdatedSig      "2.16.840.1.101.2.1.1.19"
  1210. #define szOID_INFOSEC_mosaicKMandUpdSig     "2.16.840.1.101.2.1.1.20"
  1211. #define szOID_INFOSEC_mosaicUpdatedInteg    "2.16.840.1.101.2.1.1.21"
  1212. typedef struct _CRYPT_OBJID_TABLE {
  1213.     DWORD   dwAlgId;
  1214.     LPCSTR  pszObjId;
  1215. } CRYPT_OBJID_TABLE, *PCRYPT_OBJID_TABLE;
  1216. //+-------------------------------------------------------------------------
  1217. //  PKCS #1 HashInfo (DigestInfo)
  1218. //--------------------------------------------------------------------------
  1219. typedef struct _CRYPT_HASH_INFO {
  1220.     CRYPT_ALGORITHM_IDENTIFIER  HashAlgorithm;
  1221.     CRYPT_HASH_BLOB             Hash;
  1222. } CRYPT_HASH_INFO, *PCRYPT_HASH_INFO;
  1223. //+-------------------------------------------------------------------------
  1224. //  Type used for an extension to an encoded content
  1225. //
  1226. //  Where the Value's CRYPT_OBJID_BLOB is in its encoded representation.
  1227. //--------------------------------------------------------------------------
  1228. typedef struct _CERT_EXTENSION {
  1229.     LPSTR               pszObjId;
  1230.     BOOL                fCritical;
  1231.     CRYPT_OBJID_BLOB    Value;
  1232. } CERT_EXTENSION, *PCERT_EXTENSION;
  1233. //+-------------------------------------------------------------------------
  1234. //  AttributeTypeValue
  1235. //
  1236. //  Where the Value's CRYPT_OBJID_BLOB is in its encoded representation.
  1237. //--------------------------------------------------------------------------
  1238. typedef struct _CRYPT_ATTRIBUTE_TYPE_VALUE {
  1239.     LPSTR               pszObjId;
  1240.     CRYPT_OBJID_BLOB    Value;
  1241. } CRYPT_ATTRIBUTE_TYPE_VALUE, *PCRYPT_ATTRIBUTE_TYPE_VALUE;
  1242. //+-------------------------------------------------------------------------
  1243. //  Attributes
  1244. //
  1245. //  Where the Value's PATTR_BLOBs are in their encoded representation.
  1246. //--------------------------------------------------------------------------
  1247. typedef struct _CRYPT_ATTRIBUTE {
  1248.     LPSTR               pszObjId;
  1249.     DWORD               cValue;
  1250.     PCRYPT_ATTR_BLOB    rgValue;
  1251. } CRYPT_ATTRIBUTE, *PCRYPT_ATTRIBUTE;
  1252. typedef struct _CRYPT_ATTRIBUTES {
  1253.     IN DWORD                cAttr;
  1254.     IN PCRYPT_ATTRIBUTE     rgAttr;
  1255. } CRYPT_ATTRIBUTES, *PCRYPT_ATTRIBUTES;
  1256. //+-------------------------------------------------------------------------
  1257. //  Attributes making up a Relative Distinguished Name (CERT_RDN)
  1258. //
  1259. //  The interpretation of the Value depends on the dwValueType.
  1260. //  See below for a list of the types.
  1261. //--------------------------------------------------------------------------
  1262. typedef struct _CERT_RDN_ATTR {
  1263.     LPSTR                   pszObjId;
  1264.     DWORD                   dwValueType;
  1265.     CERT_RDN_VALUE_BLOB     Value;
  1266. } CERT_RDN_ATTR, *PCERT_RDN_ATTR;
  1267. //+-------------------------------------------------------------------------
  1268. //  CERT_RDN attribute Object Identifiers
  1269. //--------------------------------------------------------------------------
  1270. // Labeling attribute types:
  1271. #define szOID_COMMON_NAME                   "2.5.4.3"  // case-ignore string
  1272. #define szOID_SUR_NAME                      "2.5.4.4"  // case-ignore string
  1273. #define szOID_DEVICE_SERIAL_NUMBER          "2.5.4.5"  // printable string
  1274. // Geographic attribute types:
  1275. #define szOID_COUNTRY_NAME                  "2.5.4.6"  // printable 2char string
  1276. #define szOID_LOCALITY_NAME                 "2.5.4.7"  // case-ignore string
  1277. #define szOID_STATE_OR_PROVINCE_NAME        "2.5.4.8"  // case-ignore string
  1278. #define szOID_STREET_ADDRESS                "2.5.4.9"  // case-ignore string
  1279. // Organizational attribute types:
  1280. #define szOID_ORGANIZATION_NAME             "2.5.4.10" // case-ignore string
  1281. #define szOID_ORGANIZATIONAL_UNIT_NAME      "2.5.4.11" // case-ignore string
  1282. #define szOID_TITLE                         "2.5.4.12" // case-ignore string
  1283. // Explanatory attribute types:
  1284. #define szOID_DESCRIPTION                   "2.5.4.13" // case-ignore string
  1285. #define szOID_SEARCH_GUIDE                  "2.5.4.14"
  1286. #define szOID_BUSINESS_CATEGORY             "2.5.4.15" // case-ignore string
  1287. // Postal addressing attribute types:
  1288. #define szOID_POSTAL_ADDRESS                "2.5.4.16"
  1289. #define szOID_POSTAL_CODE                   "2.5.4.17" // case-ignore string
  1290. #define szOID_POST_OFFICE_BOX               "2.5.4.18" // case-ignore string
  1291. #define szOID_PHYSICAL_DELIVERY_OFFICE_NAME "2.5.4.19" // case-ignore string
  1292. // Telecommunications addressing attribute types:
  1293. #define szOID_TELEPHONE_NUMBER              "2.5.4.20" // telephone number
  1294. #define szOID_TELEX_NUMBER                  "2.5.4.21"
  1295. #define szOID_TELETEXT_TERMINAL_IDENTIFIER  "2.5.4.22"
  1296. #define szOID_FACSIMILE_TELEPHONE_NUMBER    "2.5.4.23"
  1297. #define szOID_X21_ADDRESS                   "2.5.4.24" // numeric string
  1298. #define szOID_INTERNATIONAL_ISDN_NUMBER     "2.5.4.25" // numeric string
  1299. #define szOID_REGISTERED_ADDRESS            "2.5.4.26"
  1300. #define szOID_DESTINATION_INDICATOR         "2.5.4.27" // printable string
  1301. // Preference attribute types:
  1302. #define szOID_PREFERRED_DELIVERY_METHOD     "2.5.4.28"
  1303. // OSI application attribute types:
  1304. #define szOID_PRESENTATION_ADDRESS          "2.5.4.29"
  1305. #define szOID_SUPPORTED_APPLICATION_CONTEXT "2.5.4.30"
  1306. // Relational application attribute types:
  1307. #define szOID_MEMBER                        "2.5.4.31"
  1308. #define szOID_OWNER                         "2.5.4.32"
  1309. #define szOID_ROLE_OCCUPANT                 "2.5.4.33"
  1310. #define szOID_SEE_ALSO                      "2.5.4.34"
  1311. // Security attribute types:
  1312. #define szOID_USER_PASSWORD                 "2.5.4.35"
  1313. #define szOID_USER_CERTIFICATE              "2.5.4.36"
  1314. #define szOID_CA_CERTIFICATE                "2.5.4.37"
  1315. #define szOID_AUTHORITY_REVOCATION_LIST     "2.5.4.38"
  1316. #define szOID_CERTIFICATE_REVOCATION_LIST   "2.5.4.39"
  1317. #define szOID_CROSS_CERTIFICATE_PAIR        "2.5.4.40"
  1318. // Undocumented attribute types???
  1319. //#define szOID_???                         "2.5.4.41"
  1320. #define szOID_GIVEN_NAME                    "2.5.4.42" // case-ignore string
  1321. #define szOID_INITIALS                      "2.5.4.43" // case-ignore string
  1322. // The DN Qualifier attribute type specifies disambiguating information to add
  1323. // to the relative distinguished name of an entry. It is intended to be used
  1324. // for entries held in multiple DSAs which would otherwise have the same name,
  1325. // and that its value be the same in a given DSA for all entries to which
  1326. // the information has been added.
  1327. #define szOID_DN_QUALIFIER                  "2.5.4.46"
  1328. // Pilot user attribute types:
  1329. #define szOID_DOMAIN_COMPONENT  "0.9.2342.19200300.100.1.25" // IA5, UTF8 string
  1330. // used for PKCS 12 attributes
  1331. #define szOID_PKCS_12_FRIENDLY_NAME_ATTR     "1.2.840.113549.1.9.20"
  1332. #define szOID_PKCS_12_LOCAL_KEY_ID           "1.2.840.113549.1.9.21"
  1333. #define szOID_PKCS_12_KEY_PROVIDER_NAME_ATTR "1.3.6.1.4.1.311.17.1"
  1334. #define szOID_LOCAL_MACHINE_KEYSET                       "1.3.6.1.4.1.311.17.2"
  1335. //+-------------------------------------------------------------------------
  1336. //  Microsoft CERT_RDN attribute Object Identifiers
  1337. //--------------------------------------------------------------------------
  1338. // Special RDN containing the KEY_ID. Its value type is CERT_RDN_OCTET_STRING.
  1339. #define szOID_KEYID_RDN                     "1.3.6.1.4.1.311.10.7.1"
  1340. //+-------------------------------------------------------------------------
  1341. //  CERT_RDN Attribute Value Types
  1342. //
  1343. //  For RDN_ENCODED_BLOB, the Value's CERT_RDN_VALUE_BLOB is in its encoded
  1344. //  representation. Otherwise, its an array of bytes.
  1345. //
  1346. //  For all CERT_RDN types, Value.cbData is always the number of bytes, not
  1347. //  necessarily the number of elements in the string. For instance,
  1348. //  RDN_UNIVERSAL_STRING is an array of ints (cbData == intCnt * 4) and
  1349. //  RDN_BMP_STRING is an array of unsigned shorts (cbData == ushortCnt * 2).
  1350. //
  1351. //  A RDN_UTF8_STRING is an array of UNICODE characters (cbData == charCnt *2).
  1352. //  These UNICODE characters are encoded as UTF8 8 bit characters.
  1353. //
  1354. //  For CertDecodeName, two 0 bytes are always appended to the end of the
  1355. //  string (ensures a CHAR or WCHAR string is null terminated).
  1356. //  These added 0 bytes are't included in the BLOB.cbData.
  1357. //--------------------------------------------------------------------------
  1358. #define CERT_RDN_ANY_TYPE                0
  1359. #define CERT_RDN_ENCODED_BLOB            1
  1360. #define CERT_RDN_OCTET_STRING            2
  1361. #define CERT_RDN_NUMERIC_STRING          3
  1362. #define CERT_RDN_PRINTABLE_STRING        4
  1363. #define CERT_RDN_TELETEX_STRING          5
  1364. #define CERT_RDN_T61_STRING              5
  1365. #define CERT_RDN_VIDEOTEX_STRING         6
  1366. #define CERT_RDN_IA5_STRING              7
  1367. #define CERT_RDN_GRAPHIC_STRING          8
  1368. #define CERT_RDN_VISIBLE_STRING          9
  1369. #define CERT_RDN_ISO646_STRING           9
  1370. #define CERT_RDN_GENERAL_STRING          10
  1371. #define CERT_RDN_UNIVERSAL_STRING        11
  1372. #define CERT_RDN_INT4_STRING             11
  1373. #define CERT_RDN_BMP_STRING              12
  1374. #define CERT_RDN_UNICODE_STRING          12
  1375. #define CERT_RDN_UTF8_STRING             13
  1376. #define CERT_RDN_TYPE_MASK                  0x000000FF
  1377. #define CERT_RDN_FLAGS_MASK                 0xFF000000
  1378. //+-------------------------------------------------------------------------
  1379. //  Flags that can be or'ed with the above Value Type when encoding/decoding
  1380. //--------------------------------------------------------------------------
  1381. // For encoding: when set, CERT_RDN_T61_STRING is selected instead of
  1382. // CERT_RDN_UNICODE_STRING if all the unicode characters are <= 0xFF
  1383. #define CERT_RDN_ENABLE_T61_UNICODE_FLAG    0x80000000
  1384. // For encoding: when set, CERT_RDN_UTF8_STRING is selected instead of
  1385. // CERT_RDN_UNICODE_STRING.
  1386. #define CERT_RDN_ENABLE_UTF8_UNICODE_FLAG   0x20000000
  1387. // For encoding: when set, the characters aren't checked to see if they
  1388. // are valid for the Value Type.
  1389. #define CERT_RDN_DISABLE_CHECK_TYPE_FLAG    0x40000000
  1390. // For decoding: by default, CERT_RDN_T61_STRING values are initially decoded
  1391. // as UTF8. If the UTF8 decoding fails, then, decoded as 8 bit characters.
  1392. // Setting this flag skips the initial attempt to decode as UTF8.
  1393. #define CERT_RDN_DISABLE_IE4_UTF8_FLAG      0x01000000
  1394. // Macro to check that the dwValueType is a character string and not an
  1395. // encoded blob or octet string
  1396. #define IS_CERT_RDN_CHAR_STRING(X)      
  1397.                 (((X) & CERT_RDN_TYPE_MASK) >= CERT_RDN_NUMERIC_STRING)
  1398. //+-------------------------------------------------------------------------
  1399. //  A CERT_RDN consists of an array of the above attributes
  1400. //--------------------------------------------------------------------------
  1401. typedef struct _CERT_RDN {
  1402.     DWORD           cRDNAttr;
  1403.     PCERT_RDN_ATTR  rgRDNAttr;
  1404. } CERT_RDN, *PCERT_RDN;
  1405. //+-------------------------------------------------------------------------
  1406. //  Information stored in a subject's or issuer's name. The information
  1407. //  is represented as an array of the above RDNs.
  1408. //--------------------------------------------------------------------------
  1409. typedef struct _CERT_NAME_INFO {
  1410.     DWORD       cRDN;
  1411.     PCERT_RDN   rgRDN;
  1412. } CERT_NAME_INFO, *PCERT_NAME_INFO;
  1413. //+-------------------------------------------------------------------------
  1414. //  Name attribute value without the Object Identifier
  1415. //
  1416. //  The interpretation of the Value depends on the dwValueType.
  1417. //  See above for a list of the types.
  1418. //--------------------------------------------------------------------------
  1419. typedef struct _CERT_NAME_VALUE {
  1420.     DWORD               dwValueType;
  1421.     CERT_RDN_VALUE_BLOB Value;
  1422. } CERT_NAME_VALUE, *PCERT_NAME_VALUE;
  1423. //+-------------------------------------------------------------------------
  1424. //  Public Key Info
  1425. //
  1426. //  The PublicKey is the encoded representation of the information as it is
  1427. //  stored in the bit string
  1428. //--------------------------------------------------------------------------
  1429. typedef struct _CERT_PUBLIC_KEY_INFO {
  1430.     CRYPT_ALGORITHM_IDENTIFIER    Algorithm;
  1431.     CRYPT_BIT_BLOB                PublicKey;
  1432. } CERT_PUBLIC_KEY_INFO, *PCERT_PUBLIC_KEY_INFO;
  1433. #define CERT_RSA_PUBLIC_KEY_OBJID            szOID_RSA_RSA
  1434. #define CERT_DEFAULT_OID_PUBLIC_KEY_SIGN     szOID_RSA_RSA
  1435. #define CERT_DEFAULT_OID_PUBLIC_KEY_XCHG     szOID_RSA_RSA
  1436. //+-------------------------------------------------------------------------
  1437. //  structure that contains all the information in a PKCS#8 PrivateKeyInfo
  1438. //--------------------------------------------------------------------------
  1439. typedef struct _CRYPT_PRIVATE_KEY_INFO{
  1440.     DWORD                       Version;
  1441.     CRYPT_ALGORITHM_IDENTIFIER  Algorithm;
  1442.     CRYPT_DER_BLOB              PrivateKey;
  1443.     PCRYPT_ATTRIBUTES           pAttributes;
  1444. }  CRYPT_PRIVATE_KEY_INFO, *PCRYPT_PRIVATE_KEY_INFO;
  1445. //+-------------------------------------------------------------------------
  1446. //  structure that contains all the information in a PKCS#8
  1447. //  EncryptedPrivateKeyInfo
  1448. //--------------------------------------------------------------------------
  1449. typedef struct _CRYPT_ENCRYPTED_PRIVATE_KEY_INFO{
  1450.     CRYPT_ALGORITHM_IDENTIFIER  EncryptionAlgorithm;
  1451.     CRYPT_DATA_BLOB             EncryptedPrivateKey;
  1452. } CRYPT_ENCRYPTED_PRIVATE_KEY_INFO, *PCRYPT_ENCRYPTED_PRIVATE_KEY_INFO;
  1453. //+-------------------------------------------------------------------------
  1454. // this callback is given when an EncryptedProvateKeyInfo structure is
  1455. // encountered during ImportPKCS8.  the caller is then expected to decrypt
  1456. // the private key and hand back the decrypted contents.
  1457. //
  1458. // the parameters are:
  1459. // Algorithm - the algorithm used to encrypt the PrivateKeyInfo
  1460. // EncryptedPrivateKey - the encrypted private key blob
  1461. // pClearTextKey - a buffer to receive the clear text
  1462. // cbClearTextKey - the number of bytes of the pClearTextKey buffer
  1463. //                  note the if this is zero then this should be
  1464. //                  filled in with the size required to decrypt the
  1465. //                  key into, and pClearTextKey should be ignored
  1466. // pVoidDecryptFunc - this is the pVoid that was passed into the call
  1467. //                    and is preserved and passed back as context
  1468. //+-------------------------------------------------------------------------
  1469. typedef BOOL (CALLBACK *PCRYPT_DECRYPT_PRIVATE_KEY_FUNC)(
  1470.                                                         CRYPT_ALGORITHM_IDENTIFIER  Algorithm,
  1471.                                                         CRYPT_DATA_BLOB             EncryptedPrivateKey,
  1472.                                                         BYTE                        *pbClearTextKey,
  1473.                                                         DWORD                       *pcbClearTextKey,
  1474.                                                         LPVOID                      pVoidDecryptFunc);
  1475. //+-------------------------------------------------------------------------
  1476. // this callback is given when creating a PKCS8 EncryptedPrivateKeyInfo.
  1477. // The caller is then expected to encrypt the private key and hand back
  1478. // the encrypted contents.
  1479. //
  1480. // the parameters are:
  1481. // Algorithm - the algorithm used to encrypt the PrivateKeyInfo
  1482. // pClearTextPrivateKey - the cleartext private key to be encrypted
  1483. // pbEncryptedKey - the output encrypted private key blob
  1484. // cbEncryptedKey - the number of bytes of the pbEncryptedKey buffer
  1485. //                  note the if this is zero then this should be
  1486. //                  filled in with the size required to encrypt the
  1487. //                  key into, and pbEncryptedKey should be ignored
  1488. // pVoidEncryptFunc - this is the pVoid that was passed into the call
  1489. //                    and is preserved and passed back as context
  1490. //+-------------------------------------------------------------------------
  1491. typedef BOOL (CALLBACK *PCRYPT_ENCRYPT_PRIVATE_KEY_FUNC)(
  1492.                                                         CRYPT_ALGORITHM_IDENTIFIER* pAlgorithm,
  1493.                                                         CRYPT_DATA_BLOB*            pClearTextPrivateKey,
  1494.                                                         BYTE                        *pbEncryptedKey,
  1495.                                                         DWORD                       *pcbEncryptedKey,
  1496.                                                         LPVOID                      pVoidEncryptFunc);
  1497. //+-------------------------------------------------------------------------
  1498. // this callback is given from the context of a ImportPKCS8 calls.  the caller
  1499. // is then expected to hand back an HCRYPTPROV to receive the key being imported
  1500. //
  1501. // the parameters are:
  1502. // pPrivateKeyInfo - pointer to a CRYPT_PRIVATE_KEY_INFO structure which
  1503. //                   describes the key being imported
  1504. // EncryptedPrivateKey - the encrypted private key blob
  1505. // phCryptProv - a pointer to a HCRRYPTPROV to be filled in
  1506. // pVoidResolveFunc - this is the pVoidResolveFunc passed in by the caller in the
  1507. //                    CRYPT_PRIVATE_KEY_BLOB_AND_PARAMS struct
  1508. //+-------------------------------------------------------------------------
  1509. typedef BOOL (CALLBACK *PCRYPT_RESOLVE_HCRYPTPROV_FUNC)(
  1510.                                                        CRYPT_PRIVATE_KEY_INFO      *pPrivateKeyInfo,
  1511.                                                        HCRYPTPROV                  *phCryptProv,
  1512.                                                        LPVOID                      pVoidResolveFunc);
  1513. //+-------------------------------------------------------------------------
  1514. // this struct contains a PKCS8 private key and two pointers to callback
  1515. // functions, with a corresponding pVoids.  the first callback is used to give
  1516. // the caller the opportunity to specify where the key is imported to.  the callback
  1517. // passes the caller the algoroithm OID and key size to use in making the decision.
  1518. // the other callback is used to decrypt the private key if the PKCS8 contains an
  1519. // EncryptedPrivateKeyInfo.  both pVoids are preserved and passed back to the caller
  1520. // in the respective callback
  1521. //+-------------------------------------------------------------------------
  1522. typedef struct _CRYPT_PKCS8_IMPORT_PARAMS{
  1523.     CRYPT_DIGEST_BLOB               PrivateKey;             // PKCS8 blob
  1524.     PCRYPT_RESOLVE_HCRYPTPROV_FUNC  pResolvehCryptProvFunc; // optional
  1525.     LPVOID                          pVoidResolveFunc;       // optional
  1526.     PCRYPT_DECRYPT_PRIVATE_KEY_FUNC pDecryptPrivateKeyFunc;
  1527.     LPVOID                          pVoidDecryptFunc;
  1528. } CRYPT_PKCS8_IMPORT_PARAMS, *PCRYPT_PKCS8_IMPORT_PARAMS, CRYPT_PRIVATE_KEY_BLOB_AND_PARAMS, *PCRYPT_PRIVATE_KEY_BLOB_AND_PARAMS;
  1529. //+-------------------------------------------------------------------------
  1530. // this struct contains information identifying a private key and a pointer
  1531. // to a callback function, with a corresponding pVoid. The callback is used
  1532. // to encrypt the private key. If the pEncryptPrivateKeyFunc is NULL, the
  1533. // key will not be encrypted and an EncryptedPrivateKeyInfo will not be generated.
  1534. // The pVoid is preserved and passed back to the caller in the respective callback
  1535. //+-------------------------------------------------------------------------
  1536. typedef struct _CRYPT_PKCS8_EXPORT_PARAMS{
  1537.     HCRYPTPROV                      hCryptProv;
  1538.     DWORD                           dwKeySpec;
  1539.     LPSTR                           pszPrivateKeyObjId;
  1540.     PCRYPT_ENCRYPT_PRIVATE_KEY_FUNC pEncryptPrivateKeyFunc;
  1541.     LPVOID                          pVoidEncryptFunc;
  1542. } CRYPT_PKCS8_EXPORT_PARAMS, *PCRYPT_PKCS8_EXPORT_PARAMS;
  1543. //+-------------------------------------------------------------------------
  1544. //  Information stored in a certificate
  1545. //
  1546. //  The Issuer, Subject, Algorithm, PublicKey and Extension BLOBs are the
  1547. //  encoded representation of the information.
  1548. //--------------------------------------------------------------------------
  1549. typedef struct _CERT_INFO {
  1550.     DWORD                       dwVersion;
  1551.     CRYPT_INTEGER_BLOB          SerialNumber;
  1552.     CRYPT_ALGORITHM_IDENTIFIER  SignatureAlgorithm;
  1553.     CERT_NAME_BLOB              Issuer;
  1554.     FILETIME                    NotBefore;
  1555.     FILETIME                    NotAfter;
  1556.     CERT_NAME_BLOB              Subject;
  1557.     CERT_PUBLIC_KEY_INFO        SubjectPublicKeyInfo;
  1558.     CRYPT_BIT_BLOB              IssuerUniqueId;
  1559.     CRYPT_BIT_BLOB              SubjectUniqueId;
  1560.     DWORD                       cExtension;
  1561.     PCERT_EXTENSION             rgExtension;
  1562. } CERT_INFO, *PCERT_INFO;
  1563. //+-------------------------------------------------------------------------
  1564. //  Certificate versions
  1565. //--------------------------------------------------------------------------
  1566. #define CERT_V1     0
  1567. #define CERT_V2     1
  1568. #define CERT_V3     2
  1569. //+-------------------------------------------------------------------------
  1570. //  Certificate Information Flags
  1571. //--------------------------------------------------------------------------
  1572. #define CERT_INFO_VERSION_FLAG                      1
  1573. #define CERT_INFO_SERIAL_NUMBER_FLAG                2
  1574. #define CERT_INFO_SIGNATURE_ALGORITHM_FLAG          3
  1575. #define CERT_INFO_ISSUER_FLAG                       4
  1576. #define CERT_INFO_NOT_BEFORE_FLAG                   5
  1577. #define CERT_INFO_NOT_AFTER_FLAG                    6
  1578. #define CERT_INFO_SUBJECT_FLAG                      7
  1579. #define CERT_INFO_SUBJECT_PUBLIC_KEY_INFO_FLAG      8
  1580. #define CERT_INFO_ISSUER_UNIQUE_ID_FLAG             9
  1581. #define CERT_INFO_SUBJECT_UNIQUE_ID_FLAG            10
  1582. #define CERT_INFO_EXTENSION_FLAG                    11
  1583. //+-------------------------------------------------------------------------
  1584. //  An entry in a CRL
  1585. //
  1586. //  The Extension BLOBs are the encoded representation of the information.
  1587. //--------------------------------------------------------------------------
  1588. typedef struct _CRL_ENTRY {
  1589.     CRYPT_INTEGER_BLOB  SerialNumber;
  1590.     FILETIME            RevocationDate;
  1591.     DWORD               cExtension;
  1592.     PCERT_EXTENSION     rgExtension;
  1593. } CRL_ENTRY, *PCRL_ENTRY;
  1594. //+-------------------------------------------------------------------------
  1595. //  Information stored in a CRL
  1596. //
  1597. //  The Issuer, Algorithm and Extension BLOBs are the encoded
  1598. //  representation of the information.
  1599. //--------------------------------------------------------------------------
  1600. typedef struct _CRL_INFO {
  1601.     DWORD                       dwVersion;
  1602.     CRYPT_ALGORITHM_IDENTIFIER  SignatureAlgorithm;
  1603.     CERT_NAME_BLOB              Issuer;
  1604.     FILETIME                    ThisUpdate;
  1605.     FILETIME                    NextUpdate;
  1606.     DWORD                       cCRLEntry;
  1607.     PCRL_ENTRY                  rgCRLEntry;
  1608.     DWORD                       cExtension;
  1609.     PCERT_EXTENSION             rgExtension;
  1610. } CRL_INFO, *PCRL_INFO;
  1611. //+-------------------------------------------------------------------------
  1612. //  CRL versions
  1613. //--------------------------------------------------------------------------
  1614. #define CRL_V1     0
  1615. #define CRL_V2     1
  1616. //+-------------------------------------------------------------------------
  1617. //  Information stored in a certificate request
  1618. //
  1619. //  The Subject, Algorithm, PublicKey and Attribute BLOBs are the encoded
  1620. //  representation of the information.
  1621. //--------------------------------------------------------------------------
  1622. typedef struct _CERT_REQUEST_INFO {
  1623.     DWORD                   dwVersion;
  1624.     CERT_NAME_BLOB          Subject;
  1625.     CERT_PUBLIC_KEY_INFO    SubjectPublicKeyInfo;
  1626.     DWORD                   cAttribute;
  1627.     PCRYPT_ATTRIBUTE        rgAttribute;
  1628. } CERT_REQUEST_INFO, *PCERT_REQUEST_INFO;
  1629. //+-------------------------------------------------------------------------
  1630. //  Certificate Request versions
  1631. //--------------------------------------------------------------------------
  1632. #define CERT_REQUEST_V1     0
  1633. //+-------------------------------------------------------------------------
  1634. //  Information stored in Netscape's Keygen request
  1635. //--------------------------------------------------------------------------
  1636. typedef struct _CERT_KEYGEN_REQUEST_INFO {
  1637.     DWORD                   dwVersion;
  1638.     CERT_PUBLIC_KEY_INFO    SubjectPublicKeyInfo;
  1639.     LPWSTR                  pwszChallengeString;        // encoded as IA5
  1640. } CERT_KEYGEN_REQUEST_INFO, *PCERT_KEYGEN_REQUEST_INFO;
  1641. #define CERT_KEYGEN_REQUEST_V1     0
  1642. //+-------------------------------------------------------------------------
  1643. //  Certificate, CRL, Certificate Request or Keygen Request Signed Content
  1644. //
  1645. //  The "to be signed" encoded content plus its signature. The ToBeSigned
  1646. //  is the encoded CERT_INFO, CRL_INFO, CERT_REQUEST_INFO or
  1647. //  CERT_KEYGEN_REQUEST_INFO.
  1648. //--------------------------------------------------------------------------
  1649. typedef struct _CERT_SIGNED_CONTENT_INFO {
  1650.     CRYPT_DER_BLOB              ToBeSigned;
  1651.     CRYPT_ALGORITHM_IDENTIFIER  SignatureAlgorithm;
  1652.     CRYPT_BIT_BLOB              Signature;
  1653. } CERT_SIGNED_CONTENT_INFO, *PCERT_SIGNED_CONTENT_INFO;
  1654. //+-------------------------------------------------------------------------
  1655. //  Certificate Trust List (CTL)
  1656. //--------------------------------------------------------------------------
  1657. //+-------------------------------------------------------------------------
  1658. //  CTL Usage. Also used for EnhancedKeyUsage extension.
  1659. //--------------------------------------------------------------------------
  1660. typedef struct _CTL_USAGE {
  1661.     DWORD               cUsageIdentifier;
  1662.     LPSTR               *rgpszUsageIdentifier;      // array of pszObjId
  1663. } CTL_USAGE, *PCTL_USAGE,
  1664. CERT_ENHKEY_USAGE, *PCERT_ENHKEY_USAGE;
  1665. //+-------------------------------------------------------------------------
  1666. //  An entry in a CTL
  1667. //--------------------------------------------------------------------------
  1668. typedef struct _CTL_ENTRY {
  1669.     CRYPT_DATA_BLOB     SubjectIdentifier;          // For example, its hash
  1670.     DWORD               cAttribute;
  1671.     PCRYPT_ATTRIBUTE    rgAttribute;                // OPTIONAL
  1672. } CTL_ENTRY, *PCTL_ENTRY;
  1673. //+-------------------------------------------------------------------------
  1674. //  Information stored in a CTL
  1675. //--------------------------------------------------------------------------
  1676. typedef struct _CTL_INFO {
  1677.     DWORD                       dwVersion;
  1678.     CTL_USAGE                   SubjectUsage;
  1679.     CRYPT_DATA_BLOB             ListIdentifier;     // OPTIONAL
  1680.     CRYPT_INTEGER_BLOB          SequenceNumber;     // OPTIONAL
  1681.     FILETIME                    ThisUpdate;
  1682.     FILETIME                    NextUpdate;         // OPTIONAL
  1683.     CRYPT_ALGORITHM_IDENTIFIER  SubjectAlgorithm;
  1684.     DWORD                       cCTLEntry;
  1685.     PCTL_ENTRY                  rgCTLEntry;         // OPTIONAL
  1686.     DWORD                       cExtension;
  1687.     PCERT_EXTENSION             rgExtension;        // OPTIONAL
  1688. } CTL_INFO, *PCTL_INFO;
  1689. //+-------------------------------------------------------------------------
  1690. //  CTL versions
  1691. //--------------------------------------------------------------------------
  1692. #define CTL_V1     0
  1693. //+-------------------------------------------------------------------------
  1694. //  TimeStamp Request
  1695. //
  1696. //  The pszTimeStamp is the OID for the Time type requested
  1697. //  The pszContentType is the Content Type OID for the content, usually DATA
  1698. //  The Content is a un-decoded blob
  1699. //--------------------------------------------------------------------------
  1700. typedef struct _CRYPT_TIME_STAMP_REQUEST_INFO {
  1701.     LPSTR                   pszTimeStampAlgorithm;   // pszObjId
  1702.     LPSTR                   pszContentType;          // pszObjId
  1703.     CRYPT_OBJID_BLOB        Content;
  1704.     DWORD                   cAttribute;
  1705.     PCRYPT_ATTRIBUTE        rgAttribute;
  1706. } CRYPT_TIME_STAMP_REQUEST_INFO, *PCRYPT_TIME_STAMP_REQUEST_INFO;
  1707. //+-------------------------------------------------------------------------
  1708. //  Name Value Attribute
  1709. //--------------------------------------------------------------------------
  1710. typedef struct _CRYPT_ENROLLMENT_NAME_VALUE_PAIR {
  1711.     LPWSTR      pwszName;
  1712.     LPWSTR      pwszValue;
  1713. } CRYPT_ENROLLMENT_NAME_VALUE_PAIR, * PCRYPT_ENROLLMENT_NAME_VALUE_PAIR;
  1714. //+-------------------------------------------------------------------------
  1715. //  CSP Provider
  1716. //--------------------------------------------------------------------------
  1717. typedef struct _CRYPT_CSP_PROVIDER {
  1718.     DWORD           dwKeySpec;
  1719.     LPWSTR          pwszProviderName;
  1720.     CRYPT_BIT_BLOB  Signature;
  1721. } CRYPT_CSP_PROVIDER, * PCRYPT_CSP_PROVIDER;
  1722. //+-------------------------------------------------------------------------
  1723. //  Certificate and Message encoding types
  1724. //
  1725. //  The encoding type is a DWORD containing both the certificate and message
  1726. //  encoding types. The certificate encoding type is stored in the LOWORD.
  1727. //  The message encoding type is stored in the HIWORD. Some functions or
  1728. //  structure fields require only one of the encoding types. The following
  1729. //  naming convention is used to indicate which encoding type(s) are
  1730. //  required:
  1731. //      dwEncodingType              (both encoding types are required)
  1732. //      dwMsgAndCertEncodingType    (both encoding types are required)
  1733. //      dwMsgEncodingType           (only msg encoding type is required)
  1734. //      dwCertEncodingType          (only cert encoding type is required)
  1735. //
  1736. //  Its always acceptable to specify both.
  1737. //--------------------------------------------------------------------------
  1738. #define CERT_ENCODING_TYPE_MASK     0x0000FFFF
  1739. #define CMSG_ENCODING_TYPE_MASK     0xFFFF0000
  1740. #define GET_CERT_ENCODING_TYPE(X)   (X & CERT_ENCODING_TYPE_MASK)
  1741. #define GET_CMSG_ENCODING_TYPE(X)   (X & CMSG_ENCODING_TYPE_MASK)
  1742. #define CRYPT_ASN_ENCODING          0x00000001
  1743. #define CRYPT_NDR_ENCODING          0x00000002
  1744. #define X509_ASN_ENCODING           0x00000001
  1745. #define X509_NDR_ENCODING           0x00000002
  1746. #define PKCS_7_ASN_ENCODING         0x00010000
  1747. #define PKCS_7_NDR_ENCODING         0x00020000
  1748. //+-------------------------------------------------------------------------
  1749. //  format the specified data structure according to the certificate
  1750. //  encoding type.
  1751. //
  1752. //  The default behavior of CryptFormatObject is to return single line
  1753. //  display of the encoded data, that is, each subfield will be concatenated with
  1754. //  a ", " on one line.  If user prefers to display the data in multiple line,
  1755. //  set the flag CRYPT_FORMAT_STR_MULTI_LINE, that is, each subfield will be displayed
  1756. //  on a seperate line.
  1757. //
  1758. //  If there is no formatting routine installed or registered
  1759. //  for the lpszStructType, the hex dump of the encoded BLOB will be returned.
  1760. //  User can set the flag CRYPT_FORMAT_STR_NO_HEX to disable the hex dump.
  1761. //--------------------------------------------------------------------------
  1762. WINCRYPT32API
  1763. BOOL
  1764. WINAPI
  1765. CryptFormatObject(
  1766.     IN DWORD dwCertEncodingType,
  1767.     IN DWORD dwFormatType,
  1768.     IN DWORD dwFormatStrType,
  1769.     IN void  *pFormatStruct,
  1770.     IN LPCSTR lpszStructType,
  1771.     IN const BYTE *pbEncoded,
  1772.     IN DWORD cbEncoded,
  1773.     OUT void *pbFormat,
  1774.     IN OUT DWORD *pcbFormat
  1775.     );
  1776. //-------------------------------------------------------------------------
  1777. // constants for dwFormatStrType of function CryptFormatObject
  1778. //-------------------------------------------------------------------------
  1779. #define         CRYPT_FORMAT_STR_MULTI_LINE         0x0001
  1780. #define         CRYPT_FORMAT_STR_NO_HEX             0x0010
  1781. //-------------------------------------------------------------------------
  1782. // constants for dwFormatType of function CryptFormatObject
  1783. // when format X509_NAME or X509_UNICODE_NAME
  1784. //-------------------------------------------------------------------------
  1785. // Just get the simple string
  1786. #define         CRYPT_FORMAT_SIMPLE                 0x0001
  1787. //Put an attribute name infront of the attribute
  1788. //such as "O=Microsoft,DN=xiaohs"
  1789. #define         CRYPT_FORMAT_X509                   0x0002
  1790. //Put an OID infront of the simple string, such as
  1791. //"2.5.4.22=Microsoft,2.5.4.3=xiaohs"
  1792. #define         CRYPT_FORMAT_OID                    0x0004
  1793. //Put a ";" between each RDN.  The default is ","
  1794. #define         CRYPT_FORMAT_RDN_SEMICOLON          0x0100
  1795. //Put a "n" between each RDN.
  1796. #define         CRYPT_FORMAT_RDN_CRLF               0x0200
  1797. //Unquote the DN value, which is quoated by default va the following
  1798. //rules: if the DN contains leading or trailing
  1799. //white space or one of the following characters: ",", "+", "=",
  1800. //""", "n",  "<", ">", "#" or ";". The quoting character is ".
  1801. //If the DN Value contains a " it is double quoted ("").
  1802. #define         CRYPT_FORMAT_RDN_UNQUOTE            0x0400
  1803. //reverse the order of the RDNs before converting to the string
  1804. #define         CRYPT_FORMAT_RDN_REVERSE            0x0800
  1805. //-------------------------------------------------------------------------
  1806. //  contants dwFormatType of function CryptFormatObject when format a DN.:
  1807. //
  1808. //  The following three values are defined in the section above:
  1809. //  CRYPT_FORMAT_SIMPLE:    Just a simple string
  1810. //                          such as  "Microsoft+xiaohs+NT"
  1811. //  CRYPT_FORMAT_X509       Put an attribute name infront of the attribute
  1812. //                          such as "O=Microsoft+xiaohs+NT"
  1813. //
  1814. //  CRYPT_FORMAT_OID        Put an OID infront of the simple string,
  1815. //                          such as "2.5.4.22=Microsoft+xiaohs+NT"
  1816. //
  1817. //  Additional values are defined as following:
  1818. //----------------------------------------------------------------------------
  1819. //Put a "," between each value.  Default is "+"
  1820. #define         CRYPT_FORMAT_COMMA                  0x1000
  1821. //Put a ";" between each value
  1822. #define         CRYPT_FORMAT_SEMICOLON              CRYPT_FORMAT_RDN_SEMICOLON
  1823. //Put a "n" between each value
  1824. #define         CRYPT_FORMAT_CRLF                   CRYPT_FORMAT_RDN_CRLF
  1825. //+-------------------------------------------------------------------------
  1826. //  Encode / decode the specified data structure according to the certificate
  1827. //  encoding type.
  1828. //
  1829. //  See below for a list of the predefined data structures.
  1830. //--------------------------------------------------------------------------
  1831. typedef LPVOID (WINAPI *PFN_CRYPT_ALLOC)(
  1832.     IN size_t cbSize
  1833.     );
  1834. typedef VOID (WINAPI *PFN_CRYPT_FREE)(
  1835.     IN LPVOID pv
  1836.     );
  1837. typedef struct _CRYPT_ENCODE_PARA {
  1838.     DWORD                   cbSize;
  1839.     PFN_CRYPT_ALLOC         pfnAlloc;           // OPTIONAL
  1840.     PFN_CRYPT_FREE          pfnFree;            // OPTIONAL
  1841. } CRYPT_ENCODE_PARA, *PCRYPT_ENCODE_PARA;
  1842. WINCRYPT32API
  1843. BOOL
  1844. WINAPI
  1845. CryptEncodeObjectEx(
  1846.     IN DWORD dwCertEncodingType,
  1847.     IN LPCSTR lpszStructType,
  1848.     IN const void *pvStructInfo,
  1849.     IN DWORD dwFlags,
  1850.     IN OPTIONAL PCRYPT_ENCODE_PARA pEncodePara,
  1851.     OUT void *pvEncoded,
  1852.     IN OUT DWORD *pcbEncoded
  1853.     );
  1854. WINCRYPT32API
  1855. BOOL
  1856. WINAPI
  1857. CryptEncodeObject(
  1858.     IN DWORD        dwCertEncodingType,
  1859.     IN LPCSTR       lpszStructType,
  1860.     IN const void   *pvStructInfo,
  1861.     OUT BYTE        *pbEncoded,
  1862.     IN OUT DWORD    *pcbEncoded
  1863.     );
  1864. // By default the signature bytes are reversed. The following flag can
  1865. // be set to inhibit the byte reversal.
  1866. //
  1867. // This flag is applicable to
  1868. //      X509_CERT_TO_BE_SIGNED
  1869. #define CRYPT_ENCODE_NO_SIGNATURE_BYTE_REVERSAL_FLAG    0x8
  1870. //  When the following flag is set the called encode function allocates
  1871. //  memory for the encoded bytes. A pointer to the allocated bytes
  1872. //  is returned in pvEncoded. If pEncodePara or pEncodePara->pfnAlloc is
  1873. //  NULL, then, LocalAlloc is called for the allocation and LocalFree must
  1874. //  be called to do the free. Otherwise, pEncodePara->pfnAlloc is called
  1875. //  for the allocation.
  1876. //
  1877. //  *pcbEncoded is ignored on input and updated with the length of the
  1878. //  allocated, encoded bytes.
  1879. //
  1880. //  If pfnAlloc is set, then, pfnFree should also be set.
  1881. #define CRYPT_ENCODE_ALLOC_FLAG             0x8000
  1882. //  The following flag is applicable when encoding X509_UNICODE_NAME.
  1883. //  When set, CERT_RDN_T61_STRING is selected instead of
  1884. //  CERT_RDN_UNICODE_STRING if all the unicode characters are <= 0xFF
  1885. #define CRYPT_UNICODE_NAME_ENCODE_ENABLE_T61_UNICODE_FLAG   
  1886.             CERT_RDN_ENABLE_T61_UNICODE_FLAG
  1887. //  The following flag is applicable when encoding X509_UNICODE_NAME.
  1888. //  When set, CERT_RDN_UTF8_STRING is selected instead of
  1889. //  CERT_RDN_UNICODE_STRING.
  1890. #define CRYPT_UNICODE_NAME_ENCODE_ENABLE_UTF8_UNICODE_FLAG   
  1891.             CERT_RDN_ENABLE_UTF8_UNICODE_FLAG
  1892. //  The following flag is applicable when encoding X509_UNICODE_NAME,
  1893. //  X509_UNICODE_NAME_VALUE or X509_UNICODE_ANY_STRING.
  1894. //  When set, the characters aren't checked to see if they
  1895. //  are valid for the specified Value Type.
  1896. #define CRYPT_UNICODE_NAME_ENCODE_DISABLE_CHECK_TYPE_FLAG   
  1897.             CERT_RDN_DISABLE_CHECK_TYPE_FLAG
  1898. //  The following flag is applicable when encoding the PKCS_SORTED_CTL. This
  1899. //  flag should be set if the identifier for the TrustedSubjects is a hash,
  1900. //  such as, MD5 or SHA1.
  1901. #define CRYPT_SORTED_CTL_ENCODE_HASHED_SUBJECT_IDENTIFIER_FLAG     0x10000
  1902. typedef struct _CRYPT_DECODE_PARA {
  1903.     DWORD                   cbSize;
  1904.     PFN_CRYPT_ALLOC         pfnAlloc;           // OPTIONAL
  1905.     PFN_CRYPT_FREE          pfnFree;            // OPTIONAL
  1906. } CRYPT_DECODE_PARA, *PCRYPT_DECODE_PARA;
  1907. WINCRYPT32API
  1908. BOOL
  1909. WINAPI
  1910. CryptDecodeObjectEx(
  1911.     IN DWORD dwCertEncodingType,
  1912.     IN LPCSTR lpszStructType,
  1913.     IN const BYTE *pbEncoded,
  1914.     IN DWORD cbEncoded,
  1915.     IN DWORD dwFlags,
  1916.     IN OPTIONAL PCRYPT_DECODE_PARA pDecodePara,
  1917.     OUT OPTIONAL void *pvStructInfo,
  1918.     IN OUT DWORD *pcbStructInfo
  1919.     );
  1920. WINCRYPT32API
  1921. BOOL
  1922. WINAPI
  1923. CryptDecodeObject(
  1924.     IN DWORD        dwCertEncodingType,
  1925.     IN LPCSTR       lpszStructType,
  1926.     IN const BYTE   *pbEncoded,
  1927.     IN DWORD        cbEncoded,
  1928.     IN DWORD        dwFlags,
  1929.     OUT void        *pvStructInfo,
  1930.     IN OUT DWORD    *pcbStructInfo
  1931.     );
  1932. // When the following flag is set the nocopy optimization is enabled.
  1933. // This optimization where appropriate, updates the pvStructInfo fields
  1934. // to point to content residing within pbEncoded instead of making a copy
  1935. // of and appending to pvStructInfo.
  1936. //
  1937. // Note, when set, pbEncoded can't be freed until pvStructInfo is freed.
  1938. #define CRYPT_DECODE_NOCOPY_FLAG            0x1
  1939. // For CryptDecodeObject(), by default the pbEncoded is the "to be signed"
  1940. // plus its signature. Set the following flag, if pbEncoded points to only
  1941. // the "to be signed".
  1942. //
  1943. // This flag is applicable to
  1944. //      X509_CERT_TO_BE_SIGNED
  1945. //      X509_CERT_CRL_TO_BE_SIGNED
  1946. //      X509_CERT_REQUEST_TO_BE_SIGNED
  1947. //      X509_KEYGEN_REQUEST_TO_BE_SIGNED
  1948. #define CRYPT_DECODE_TO_BE_SIGNED_FLAG      0x2
  1949. // When the following flag is set, the OID strings are allocated in
  1950. // crypt32.dll and shared instead of being copied into the returned
  1951. // data structure. This flag may be set if crypt32.dll isn't unloaded
  1952. // before the caller is unloaded.
  1953. #define CRYPT_DECODE_SHARE_OID_STRING_FLAG  0x4
  1954. // By default the signature bytes are reversed. The following flag can
  1955. // be set to inhibit the byte reversal.
  1956. //
  1957. // This flag is applicable to
  1958. //      X509_CERT_TO_BE_SIGNED
  1959. #define CRYPT_DECODE_NO_SIGNATURE_BYTE_REVERSAL_FLAG    0x8
  1960. // When the following flag is set the called decode function allocates
  1961. // memory for the decoded structure. A pointer to the allocated structure
  1962. // is returned in pvStructInfo. If pDecodePara or pDecodePara->pfnAlloc is
  1963. // NULL, then, LocalAlloc is called for the allocation and LocalFree must
  1964. // be called to do the free. Otherwise, pDecodePara->pfnAlloc is called
  1965. // for the allocation.
  1966. //
  1967. // *pcbStructInfo is ignored on input and updated with the length of the
  1968. // allocated, decoded structure.
  1969. //
  1970. // This flag may also be set in the CryptDecodeObject API. Since
  1971. // CryptDecodeObject doesn't take a pDecodePara, LocalAlloc is always
  1972. // called for the allocation which must be freed by calling LocalFree.
  1973. #define CRYPT_DECODE_ALLOC_FLAG             0x8000
  1974. // The following flag is applicable when decoding X509_UNICODE_NAME,
  1975. // X509_UNICODE_NAME_VALUE or X509_UNICODE_ANY_STRING.
  1976. // By default, CERT_RDN_T61_STRING values are initially decoded
  1977. // as UTF8. If the UTF8 decoding fails, then, decoded as 8 bit characters.
  1978. // Setting this flag skips the initial attempt to decode as UTF8.
  1979. #define CRYPT_UNICODE_NAME_DECODE_DISABLE_IE4_UTF8_FLAG     
  1980.             CERT_RDN_DISABLE_IE4_UTF8_FLAG
  1981. //+-------------------------------------------------------------------------
  1982. //  Predefined X509 certificate data structures that can be encoded / decoded.
  1983. //--------------------------------------------------------------------------
  1984. #define CRYPT_ENCODE_DECODE_NONE            0
  1985. #define X509_CERT                           ((LPCSTR) 1)
  1986. #define X509_CERT_TO_BE_SIGNED              ((LPCSTR) 2)
  1987. #define X509_CERT_CRL_TO_BE_SIGNED          ((LPCSTR) 3)
  1988. #define X509_CERT_REQUEST_TO_BE_SIGNED      ((LPCSTR) 4)
  1989. #define X509_EXTENSIONS                     ((LPCSTR) 5)
  1990. #define X509_NAME_VALUE                     ((LPCSTR) 6)
  1991. #define X509_NAME                           ((LPCSTR) 7)
  1992. #define X509_PUBLIC_KEY_INFO                ((LPCSTR) 8)
  1993. //+-------------------------------------------------------------------------
  1994. //  Predefined X509 certificate extension data structures that can be
  1995. //  encoded / decoded.
  1996. //--------------------------------------------------------------------------
  1997. #define X509_AUTHORITY_KEY_ID               ((LPCSTR) 9)
  1998. #define X509_KEY_ATTRIBUTES                 ((LPCSTR) 10)
  1999. #define X509_KEY_USAGE_RESTRICTION          ((LPCSTR) 11)
  2000. #define X509_ALTERNATE_NAME                 ((LPCSTR) 12)
  2001. #define X509_BASIC_CONSTRAINTS              ((LPCSTR) 13)
  2002. #define X509_KEY_USAGE                      ((LPCSTR) 14)
  2003. #define X509_BASIC_CONSTRAINTS2             ((LPCSTR) 15)
  2004. #define X509_CERT_POLICIES                  ((LPCSTR) 16)
  2005. //+-------------------------------------------------------------------------
  2006. //  Additional predefined data structures that can be encoded / decoded.
  2007. //--------------------------------------------------------------------------
  2008. #define PKCS_UTC_TIME                       ((LPCSTR) 17)
  2009. #define PKCS_TIME_REQUEST                   ((LPCSTR) 18)
  2010. #define RSA_CSP_PUBLICKEYBLOB               ((LPCSTR) 19)
  2011. #define X509_UNICODE_NAME                   ((LPCSTR) 20)
  2012. #define X509_KEYGEN_REQUEST_TO_BE_SIGNED    ((LPCSTR) 21)
  2013. #define PKCS_ATTRIBUTE                      ((LPCSTR) 22)
  2014. #define PKCS_CONTENT_INFO_SEQUENCE_OF_ANY   ((LPCSTR) 23)
  2015. //+-------------------------------------------------------------------------
  2016. //  Predefined primitive data structures that can be encoded / decoded.
  2017. //--------------------------------------------------------------------------
  2018. #define X509_UNICODE_NAME_VALUE             ((LPCSTR) 24)
  2019. #define X509_ANY_STRING                     X509_NAME_VALUE
  2020. #define X509_UNICODE_ANY_STRING             X509_UNICODE_NAME_VALUE
  2021. #define X509_OCTET_STRING                   ((LPCSTR) 25)
  2022. #define X509_BITS                           ((LPCSTR) 26)
  2023. #define X509_INTEGER                        ((LPCSTR) 27)
  2024. #define X509_MULTI_BYTE_INTEGER             ((LPCSTR) 28)
  2025. #define X509_ENUMERATED                     ((LPCSTR) 29)
  2026. #define X509_CHOICE_OF_TIME                 ((LPCSTR) 30)
  2027. //+-------------------------------------------------------------------------
  2028. //  More predefined X509 certificate extension data structures that can be
  2029. //  encoded / decoded.
  2030. //--------------------------------------------------------------------------
  2031. #define X509_AUTHORITY_KEY_ID2              ((LPCSTR) 31)
  2032. #define X509_AUTHORITY_INFO_ACCESS          ((LPCSTR) 32)
  2033. #define X509_CRL_REASON_CODE                X509_ENUMERATED
  2034. #define PKCS_CONTENT_INFO                   ((LPCSTR) 33)
  2035. #define X509_SEQUENCE_OF_ANY                ((LPCSTR) 34)
  2036. #define X509_CRL_DIST_POINTS                ((LPCSTR) 35)
  2037. #define X509_ENHANCED_KEY_USAGE             ((LPCSTR) 36)
  2038. #define PKCS_CTL                            ((LPCSTR) 37)
  2039. #define X509_MULTI_BYTE_UINT                ((LPCSTR) 38)
  2040. #define X509_DSS_PUBLICKEY                  X509_MULTI_BYTE_UINT
  2041. #define X509_DSS_PARAMETERS                 ((LPCSTR) 39)
  2042. #define X509_DSS_SIGNATURE                  ((LPCSTR) 40)
  2043. #define PKCS_RC2_CBC_PARAMETERS             ((LPCSTR) 41)
  2044. #define PKCS_SMIME_CAPABILITIES             ((LPCSTR) 42)
  2045. //+-------------------------------------------------------------------------
  2046. //  data structures for private keys
  2047. //--------------------------------------------------------------------------
  2048. #define PKCS_RSA_PRIVATE_KEY                ((LPCSTR) 43)
  2049. #define PKCS_PRIVATE_KEY_INFO               ((LPCSTR) 44)
  2050. #define PKCS_ENCRYPTED_PRIVATE_KEY_INFO     ((LPCSTR) 45)
  2051. //+-------------------------------------------------------------------------
  2052. //  certificate policy qualifier
  2053. //--------------------------------------------------------------------------
  2054. #define X509_PKIX_POLICY_QUALIFIER_USERNOTICE ((LPCSTR) 46)
  2055. //+-------------------------------------------------------------------------
  2056. //  Diffie-Hellman Key Exchange
  2057. //--------------------------------------------------------------------------
  2058. #define X509_DH_PUBLICKEY                   X509_MULTI_BYTE_UINT
  2059. #define X509_DH_PARAMETERS                  ((LPCSTR) 47)
  2060. #define PKCS_ATTRIBUTES                     ((LPCSTR) 48)
  2061. #define PKCS_SORTED_CTL                     ((LPCSTR) 49)
  2062. //+-------------------------------------------------------------------------
  2063. //  X942 Diffie-Hellman
  2064. //--------------------------------------------------------------------------
  2065. #define X942_DH_PARAMETERS                  ((LPCSTR) 50)
  2066. //+-------------------------------------------------------------------------
  2067. //  The following is the same as X509_BITS, except before encoding,
  2068. //  the bit length is decremented to exclude trailing zero bits.
  2069. //--------------------------------------------------------------------------
  2070. #define X509_BITS_WITHOUT_TRAILING_ZEROES   ((LPCSTR) 51)
  2071. //+-------------------------------------------------------------------------
  2072. //  X942 Diffie-Hellman Other Info
  2073. //--------------------------------------------------------------------------
  2074. #define X942_OTHER_INFO                     ((LPCSTR) 52)
  2075. #define X509_CERT_PAIR                      ((LPCSTR) 53)
  2076. #define X509_ISSUING_DIST_POINT             ((LPCSTR) 54)
  2077. #define X509_NAME_CONSTRAINTS               ((LPCSTR) 55)
  2078. #define X509_POLICY_MAPPINGS                ((LPCSTR) 56)
  2079. #define X509_POLICY_CONSTRAINTS             ((LPCSTR) 57)
  2080. #define X509_CROSS_CERT_DIST_POINTS         ((LPCSTR) 58)
  2081. //+-------------------------------------------------------------------------
  2082. //  Certificate Management Messages over CMS (CMC) Data Structures
  2083. //--------------------------------------------------------------------------
  2084. #define CMC_DATA                            ((LPCSTR) 59)
  2085. #define CMC_RESPONSE                        ((LPCSTR) 60)
  2086. #define CMC_STATUS                          ((LPCSTR) 61)
  2087. #define CMC_ADD_EXTENSIONS                  ((LPCSTR) 62)
  2088. #define CMC_ADD_ATTRIBUTES                  ((LPCSTR) 63)
  2089. //+-------------------------------------------------------------------------
  2090. //  Certificate Template
  2091. //--------------------------------------------------------------------------
  2092. #define X509_CERTIFICATE_TEMPLATE           ((LPCSTR) 64)
  2093. //+-------------------------------------------------------------------------
  2094. //  Predefined PKCS #7 data structures that can be encoded / decoded.
  2095. //--------------------------------------------------------------------------
  2096. #define PKCS7_SIGNER_INFO                   ((LPCSTR) 500)
  2097. //+-------------------------------------------------------------------------
  2098. //  Predefined PKCS #7 data structures that can be encoded / decoded.
  2099. //--------------------------------------------------------------------------
  2100. #define CMS_SIGNER_INFO                     ((LPCSTR) 501)
  2101. //+-------------------------------------------------------------------------
  2102. //  Predefined Software Publishing Credential (SPC)  data structures that
  2103. //  can be encoded / decoded.
  2104. //
  2105. //  Predefined values: 2000 .. 2999
  2106. //
  2107. //  See spc.h for value and data structure definitions.
  2108. //--------------------------------------------------------------------------
  2109. //+-------------------------------------------------------------------------
  2110. //  Extension Object Identifiers
  2111. //--------------------------------------------------------------------------
  2112. #define szOID_AUTHORITY_KEY_IDENTIFIER  "2.5.29.1"
  2113. #define szOID_KEY_ATTRIBUTES            "2.5.29.2"
  2114. #define szOID_CERT_POLICIES_95          "2.5.29.3"
  2115. #define szOID_KEY_USAGE_RESTRICTION     "2.5.29.4"
  2116. #define szOID_SUBJECT_ALT_NAME          "2.5.29.7"
  2117. #define szOID_ISSUER_ALT_NAME           "2.5.29.8"
  2118. #define szOID_BASIC_CONSTRAINTS         "2.5.29.10"
  2119. #define szOID_KEY_USAGE                 "2.5.29.15"
  2120. #define szOID_PRIVATEKEY_USAGE_PERIOD   "2.5.29.16"
  2121. #define szOID_BASIC_CONSTRAINTS2        "2.5.29.19"
  2122. #define szOID_CERT_POLICIES             "2.5.29.32"
  2123. #define szOID_ANY_CERT_POLICY           "2.5.29.32.0"
  2124. #define szOID_AUTHORITY_KEY_IDENTIFIER2 "2.5.29.35"
  2125. #define szOID_SUBJECT_KEY_IDENTIFIER    "2.5.29.14"
  2126. #define szOID_SUBJECT_ALT_NAME2         "2.5.29.17"
  2127. #define szOID_ISSUER_ALT_NAME2          "2.5.29.18"
  2128. #define szOID_CRL_REASON_CODE           "2.5.29.21"
  2129. #define szOID_REASON_CODE_HOLD          "2.5.29.23"
  2130. #define szOID_CRL_DIST_POINTS           "2.5.29.31"
  2131. #define szOID_ENHANCED_KEY_USAGE        "2.5.29.37"
  2132. // szOID_CRL_NUMBER -- Base CRLs only.  Monotonically increasing sequence
  2133. // number for each CRL issued by a CA.
  2134. #define szOID_CRL_NUMBER                "2.5.29.20"
  2135. // szOID_DELTA_CRL_INDICATOR -- Delta CRLs only.  Marked critical.
  2136. // Contains the minimum base CRL Number that can be used with a delta CRL.
  2137. #define szOID_DELTA_CRL_INDICATOR       "2.5.29.27"
  2138. #define szOID_ISSUING_DIST_POINT        "2.5.29.28"
  2139. // szOID_FRESHEST_CRL -- Base CRLs only.  Formatted identically to a CDP
  2140. // extension that holds URLs to fetch the delta CRL.
  2141. #define szOID_FRESHEST_CRL              "2.5.29.46"
  2142. #define szOID_NAME_CONSTRAINTS          "2.5.29.30"
  2143. // Note on 1/1/2000 szOID_POLICY_MAPPINGS was changed from "2.5.29.5"
  2144. #define szOID_POLICY_MAPPINGS           "2.5.29.33"
  2145. #define szOID_LEGACY_POLICY_MAPPINGS    "2.5.29.5"
  2146. #define szOID_POLICY_CONSTRAINTS        "2.5.29.36"
  2147. // Microsoft PKCS10 Attributes
  2148. #define szOID_RENEWAL_CERTIFICATE           "1.3.6.1.4.1.311.13.1"
  2149. #define szOID_ENROLLMENT_NAME_VALUE_PAIR    "1.3.6.1.4.1.311.13.2.1"
  2150. #define szOID_ENROLLMENT_CSP_PROVIDER       "1.3.6.1.4.1.311.13.2.2"
  2151. #define szOID_OS_VERSION                    "1.3.6.1.4.1.311.13.2.3"
  2152. //
  2153. // Extension contain certificate type
  2154. #define szOID_ENROLLMENT_AGENT              "1.3.6.1.4.1.311.20.2.1"
  2155. // Internet Public Key Infrastructure (PKIX)
  2156. #define szOID_PKIX                      "1.3.6.1.5.5.7"
  2157. #define szOID_PKIX_PE                   "1.3.6.1.5.5.7.1"
  2158. #define szOID_AUTHORITY_INFO_ACCESS     "1.3.6.1.5.5.7.1.1"
  2159. // Microsoft extensions or attributes
  2160. #define szOID_CERT_EXTENSIONS           "1.3.6.1.4.1.311.2.1.14"
  2161. #define szOID_NEXT_UPDATE_LOCATION      "1.3.6.1.4.1.311.10.2"
  2162. #define szOID_REMOVE_CERTIFICATE            "1.3.6.1.4.1.311.10.8.1"
  2163. #define szOID_CROSS_CERT_DIST_POINTS    "1.3.6.1.4.1.311.10.9.1"
  2164. //  Microsoft PKCS #7 ContentType Object Identifiers
  2165. #define szOID_CTL                       "1.3.6.1.4.1.311.10.1"
  2166. //  Microsoft Sorted CTL Extension Object Identifier
  2167. #define szOID_SORTED_CTL                "1.3.6.1.4.1.311.10.1.1"
  2168. // serialized serial numbers for PRS
  2169. #ifndef szOID_SERIALIZED
  2170. #define szOID_SERIALIZED                "1.3.6.1.4.1.311.10.3.3.1"
  2171. #endif
  2172. // UPN principal name in SubjectAltName
  2173. #ifndef szOID_NT_PRINCIPAL_NAME
  2174. #define szOID_NT_PRINCIPAL_NAME         "1.3.6.1.4.1.311.20.2.3"
  2175. #endif
  2176. // Windows product update unauthenticated attribute
  2177. #ifndef szOID_PRODUCT_UPDATE
  2178. #define szOID_PRODUCT_UPDATE            "1.3.6.1.4.1.311.31.1"
  2179. #endif
  2180. // CryptUI
  2181. #define szOID_ANY_APPLICATION_POLICY    "1.3.6.1.4.1.311.10.12.1"
  2182. //+-------------------------------------------------------------------------
  2183. //  Object Identifiers for use with Auto Enrollment
  2184. //--------------------------------------------------------------------------
  2185. #define szOID_AUTO_ENROLL_CTL_USAGE     "1.3.6.1.4.1.311.20.1"
  2186. // Extension contain certificate type
  2187. #define szOID_ENROLL_CERTTYPE_EXTENSION "1.3.6.1.4.1.311.20.2"
  2188. #define szOID_CERT_MANIFOLD             "1.3.6.1.4.1.311.20.3"
  2189. //+-------------------------------------------------------------------------
  2190. //  Object Identifiers for use with the MS Certificate Server
  2191. //--------------------------------------------------------------------------
  2192. #ifndef szOID_CERTSRV_CA_VERSION
  2193. #define szOID_CERTSRV_CA_VERSION        "1.3.6.1.4.1.311.21.1"
  2194. #endif
  2195. // szOID_CERTSRV_PREVIOUS_CERT_HASH -- Contains the sha1 hash of the previous
  2196. // version of the CA certificate.
  2197. #define szOID_CERTSRV_PREVIOUS_CERT_HASH    "1.3.6.1.4.1.311.21.2"
  2198. // szOID_CRL_VIRTUAL_BASE -- Delta CRLs only.  Contains the base CRL Number
  2199. // of the corresponding base CRL.
  2200. #define szOID_CRL_VIRTUAL_BASE          "1.3.6.1.4.1.311.21.3"
  2201. // szOID_CRL_NEXT_PUBLISH -- Contains the time when the next CRL is expected
  2202. // to be published.  This may be sooner than the CRL's NextUpdate field.
  2203. #define szOID_CRL_NEXT_PUBLISH          "1.3.6.1.4.1.311.21.4"
  2204. // Enhanced Key Usage for CA encryption certificate
  2205. #define szOID_KP_CA_EXCHANGE            "1.3.6.1.4.1.311.21.5"
  2206. // Enhanced Key Usage for key recovery agent certificate
  2207. #define szOID_KP_KEY_RECOVERY_AGENT     "1.3.6.1.4.1.311.21.6"
  2208. // Certificate template extension (v2)
  2209. #define szOID_CERTIFICATE_TEMPLATE      "1.3.6.1.4.1.311.21.7"
  2210. // The root oid for all enterprise specific oids
  2211. #define szOID_ENTERPRISE_OID_ROOT       "1.3.6.1.4.1.311.21.8"
  2212. // Dummy signing Subject RDN
  2213. #define szOID_RDN_DUMMY_SIGNER          "1.3.6.1.4.1.311.21.9"
  2214. // Application Policies extension -- same encoding as szOID_CERT_POLICIES
  2215. #define szOID_APPLICATION_CERT_POLICIES     "1.3.6.1.4.1.311.21.10"
  2216. // Application Policy Mappings -- same encoding as szOID_POLICY_MAPPINGS
  2217. #define szOID_APPLICATION_POLICY_MAPPINGS   "1.3.6.1.4.1.311.21.11"
  2218. // Application Policy Constraints -- same encoding as szOID_POLICY_CONSTRAINTS
  2219. #define szOID_APPLICATION_POLICY_CONSTRAINTS    "1.3.6.1.4.1.311.21.12"
  2220. #define szOID_ARCHIVED_KEY_ATTR                "1.3.6.1.4.1.311.21.13"
  2221. #define szOID_CRL_SELF_CDP                     "1.3.6.1.4.1.311.21.14"
  2222. // Requires all certificates below the root to have a non-empty intersecting
  2223. // issuance certificate policy usage.
  2224. #define szOID_REQUIRE_CERT_CHAIN_POLICY        "1.3.6.1.4.1.311.21.15"
  2225. #define szOID_ARCHIVED_KEY_CERT_HASH           "1.3.6.1.4.1.311.21.16"
  2226. #define szOID_ISSUED_CERT_HASH                 "1.3.6.1.4.1.311.21.17"
  2227. // Enhanced key usage for DS email replication
  2228. #define szOID_DS_EMAIL_REPLICATION             "1.3.6.1.4.1.311.21.19"
  2229. #define szOID_REQUEST_CLIENT_INFO              "1.3.6.1.4.1.311.21.20"
  2230. #define szOID_ENCRYPTED_KEY_HASH               "1.3.6.1.4.1.311.21.21"
  2231. //+-------------------------------------------------------------------------
  2232. //  Object Identifiers for use with the MS Directory Service
  2233. //--------------------------------------------------------------------------
  2234. #define szOID_NTDS_REPLICATION      "1.3.6.1.4.1.311.25.1"
  2235. //+-------------------------------------------------------------------------
  2236. //  Extension Object Identifiers (currently not implemented)
  2237. //--------------------------------------------------------------------------
  2238. #define szOID_SUBJECT_DIR_ATTRS         "2.5.29.9"
  2239. //+-------------------------------------------------------------------------
  2240. //  Enhanced Key Usage (Purpose) Object Identifiers
  2241. //--------------------------------------------------------------------------
  2242. #define szOID_PKIX_KP                   "1.3.6.1.5.5.7.3"
  2243. // Consistent key usage bits: DIGITAL_SIGNATURE, KEY_ENCIPHERMENT
  2244. // or KEY_AGREEMENT
  2245. #define szOID_PKIX_KP_SERVER_AUTH       "1.3.6.1.5.5.7.3.1"
  2246. // Consistent key usage bits: DIGITAL_SIGNATURE
  2247. #define szOID_PKIX_KP_CLIENT_AUTH       "1.3.6.1.5.5.7.3.2"
  2248. // Consistent key usage bits: DIGITAL_SIGNATURE
  2249. #define szOID_PKIX_KP_CODE_SIGNING      "1.3.6.1.5.5.7.3.3"
  2250. // Consistent key usage bits: DIGITAL_SIGNATURE, NON_REPUDIATION and/or
  2251. // (KEY_ENCIPHERMENT or KEY_AGREEMENT)
  2252. #define szOID_PKIX_KP_EMAIL_PROTECTION  "1.3.6.1.5.5.7.3.4"
  2253. // Consistent key usage bits: DIGITAL_SIGNATURE and/or
  2254. // (KEY_ENCIPHERMENT or KEY_AGREEMENT)
  2255. #define szOID_PKIX_KP_IPSEC_END_SYSTEM  "1.3.6.1.5.5.7.3.5"
  2256. // Consistent key usage bits: DIGITAL_SIGNATURE and/or
  2257. // (KEY_ENCIPHERMENT or KEY_AGREEMENT)
  2258. #define szOID_PKIX_KP_IPSEC_TUNNEL      "1.3.6.1.5.5.7.3.6"
  2259. // Consistent key usage bits: DIGITAL_SIGNATURE and/or
  2260. // (KEY_ENCIPHERMENT or KEY_AGREEMENT)
  2261. #define szOID_PKIX_KP_IPSEC_USER        "1.3.6.1.5.5.7.3.7"
  2262. // Consistent key usage bits: DIGITAL_SIGNATURE or NON_REPUDIATION
  2263. #define szOID_PKIX_KP_TIMESTAMP_SIGNING "1.3.6.1.5.5.7.3.8"
  2264. // IKE (Internet Key Exchange) Intermediate KP for an IPsec end entity.
  2265. // Defined in draft-ietf-ipsec-pki-req-04.txt, December 14, 1999.
  2266. #define szOID_IPSEC_KP_IKE_INTERMEDIATE "1.3.6.1.5.5.8.2.2"
  2267. //+-------------------------------------------------------------------------
  2268. //  Microsoft Enhanced Key Usage (Purpose) Object Identifiers
  2269. //+-------------------------------------------------------------------------
  2270. //  Signer of CTLs
  2271. #define szOID_KP_CTL_USAGE_SIGNING      "1.3.6.1.4.1.311.10.3.1"
  2272. //  Signer of TimeStamps
  2273. #define szOID_KP_TIME_STAMP_SIGNING     "1.3.6.1.4.1.311.10.3.2"
  2274. #ifndef szOID_SERVER_GATED_CRYPTO
  2275. #define szOID_SERVER_GATED_CRYPTO       "1.3.6.1.4.1.311.10.3.3"
  2276. #endif
  2277. #ifndef szOID_SGC_NETSCAPE
  2278. #define szOID_SGC_NETSCAPE              "2.16.840.1.113730.4.1"
  2279. #endif
  2280. #define szOID_KP_EFS                    "1.3.6.1.4.1.311.10.3.4"
  2281. #define szOID_EFS_RECOVERY              "1.3.6.1.4.1.311.10.3.4.1"
  2282. // Can use Windows Hardware Compatible (WHQL)
  2283. #define szOID_WHQL_CRYPTO               "1.3.6.1.4.1.311.10.3.5"
  2284. // Signed by the NT5 build lab
  2285. #define szOID_NT5_CRYPTO                "1.3.6.1.4.1.311.10.3.6"
  2286. // Signed by and OEM of WHQL
  2287. #define szOID_OEM_WHQL_CRYPTO           "1.3.6.1.4.1.311.10.3.7"
  2288. // Signed by the Embedded NT
  2289. #define szOID_EMBEDDED_NT_CRYPTO        "1.3.6.1.4.1.311.10.3.8"
  2290. // Signer of a CTL containing trusted roots
  2291. #define szOID_ROOT_LIST_SIGNER      "1.3.6.1.4.1.311.10.3.9"
  2292. // Can sign cross-cert and subordinate CA requests with qualified
  2293. // subordination (name constraints, policy mapping, etc.)
  2294. #define szOID_KP_QUALIFIED_SUBORDINATION    "1.3.6.1.4.1.311.10.3.10"
  2295. // Can be used to encrypt/recover escrowed keys
  2296. #define szOID_KP_KEY_RECOVERY               "1.3.6.1.4.1.311.10.3.11"
  2297. // Signer of documents
  2298. #define szOID_KP_DOCUMENT_SIGNING           "1.3.6.1.4.1.311.10.3.12"
  2299. // The default WinVerifyTrust Authenticode policy is to treat all time stamped
  2300. // signatures as being valid forever. This OID limits the valid lifetime of the
  2301. // signature to the lifetime of the certificate. This allows timestamped
  2302. // signatures to expire. Normally this OID will be used in conjunction with
  2303. // szOID_PKIX_KP_CODE_SIGNING to indicate new time stamp semantics should be
  2304. // used. Support for this OID was added in WXP.
  2305. #define szOID_KP_LIFETIME_SIGNING           "1.3.6.1.4.1.311.10.3.13"
  2306. #ifndef szOID_DRM
  2307. #define szOID_DRM                       "1.3.6.1.4.1.311.10.5.1"
  2308. #endif
  2309. // Microsoft DRM EKU
  2310. #ifndef szOID_DRM_INDIVIDUALIZATION
  2311. #define szOID_DRM_INDIVIDUALIZATION "1.3.6.1.4.1.311.10.5.2"
  2312. #endif
  2313. #ifndef szOID_LICENSES
  2314. #define szOID_LICENSES                  "1.3.6.1.4.1.311.10.6.1"
  2315. #endif
  2316. #ifndef szOID_LICENSE_SERVER
  2317. #define szOID_LICENSE_SERVER            "1.3.6.1.4.1.311.10.6.2"
  2318. #endif
  2319. #ifndef szOID_KP_SMARTCARD_LOGON
  2320. #define szOID_KP_SMARTCARD_LOGON        "1.3.6.1.4.1.311.20.2.2"
  2321. #endif
  2322. //+-------------------------------------------------------------------------
  2323. //  Microsoft Attribute Object Identifiers
  2324. //+-------------------------------------------------------------------------
  2325. #define szOID_YESNO_TRUST_ATTR          "1.3.6.1.4.1.311.10.4.1"
  2326. //+-------------------------------------------------------------------------
  2327. //  Qualifiers that may be part of the szOID_CERT_POLICIES and
  2328. //  szOID_CERT_POLICIES95 extensions
  2329. //+-------------------------------------------------------------------------
  2330. #define szOID_PKIX_POLICY_QUALIFIER_CPS               "1.3.6.1.5.5.7.2.1"
  2331. #define szOID_PKIX_POLICY_QUALIFIER_USERNOTICE        "1.3.6.1.5.5.7.2.2"
  2332. // OID for old qualifer
  2333. #define szOID_CERT_POLICIES_95_QUALIFIER1             "2.16.840.1.113733.1.7.1.1"
  2334. //+-------------------------------------------------------------------------
  2335. //  X509_CERT
  2336. //
  2337. //  The "to be signed" encoded content plus its signature. The ToBeSigned
  2338. //  content is the CryptEncodeObject() output for one of the following:
  2339. //  X509_CERT_TO_BE_SIGNED, X509_CERT_CRL_TO_BE_SIGNED or
  2340. //  X509_CERT_REQUEST_TO_BE_SIGNED.
  2341. //
  2342. //  pvStructInfo points to CERT_SIGNED_CONTENT_INFO.
  2343. //--------------------------------------------------------------------------
  2344. //+-------------------------------------------------------------------------
  2345. //  X509_CERT_TO_BE_SIGNED
  2346. //
  2347. //  pvStructInfo points to CERT_INFO.
  2348. //
  2349. //  For CryptDecodeObject(), the pbEncoded is the "to be signed" plus its
  2350. //  signature (output of a X509_CERT CryptEncodeObject()).
  2351. //
  2352. //  For CryptEncodeObject(), the pbEncoded is just the "to be signed".
  2353. //--------------------------------------------------------------------------
  2354. //+-------------------------------------------------------------------------
  2355. //  X509_CERT_CRL_TO_BE_SIGNED
  2356. //
  2357. //  pvStructInfo points to CRL_INFO.
  2358. //
  2359. //  For CryptDecodeObject(), the pbEncoded is the "to be signed" plus its
  2360. //  signature (output of a X509_CERT CryptEncodeObject()).
  2361. //
  2362. //  For CryptEncodeObject(), the pbEncoded is just the "to be signed".
  2363. //--------------------------------------------------------------------------
  2364. //+-------------------------------------------------------------------------
  2365. //  X509_CERT_REQUEST_TO_BE_SIGNED
  2366. //
  2367. //  pvStructInfo points to CERT_REQUEST_INFO.
  2368. //
  2369. //  For CryptDecodeObject(), the pbEncoded is the "to be signed" plus its
  2370. //  signature (output of a X509_CERT CryptEncodeObject()).
  2371. //
  2372. //  For CryptEncodeObject(), the pbEncoded is just the "to be signed".
  2373. //--------------------------------------------------------------------------
  2374. //+-------------------------------------------------------------------------
  2375. //  X509_EXTENSIONS
  2376. //  szOID_CERT_EXTENSIONS
  2377. //
  2378. //  pvStructInfo points to following CERT_EXTENSIONS.
  2379. //--------------------------------------------------------------------------
  2380. typedef struct _CERT_EXTENSIONS {
  2381.     DWORD           cExtension;
  2382.     PCERT_EXTENSION rgExtension;
  2383. } CERT_EXTENSIONS, *PCERT_EXTENSIONS;
  2384. //+-------------------------------------------------------------------------
  2385. //  X509_NAME_VALUE
  2386. //  X509_ANY_STRING
  2387. //
  2388. //  pvStructInfo points to CERT_NAME_VALUE.
  2389. //--------------------------------------------------------------------------
  2390. //+-------------------------------------------------------------------------
  2391. //  X509_UNICODE_NAME_VALUE
  2392. //  X509_UNICODE_ANY_STRING
  2393. //
  2394. //  pvStructInfo points to CERT_NAME_VALUE.
  2395. //
  2396. //  The name values are unicode strings.
  2397. //
  2398. //  For CryptEncodeObject:
  2399. //    Value.pbData points to the unicode string.
  2400. //    If Value.cbData = 0, then, the unicode string is NULL terminated.
  2401. //    Otherwise, Value.cbData is the unicode string byte count. The byte count
  2402. //    is twice the character count.
  2403. //
  2404. //    If the unicode string contains an invalid character for the specified
  2405. //    dwValueType, then, *pcbEncoded is updated with the unicode character
  2406. //    index of the first invalid character. LastError is set to:
  2407. //    CRYPT_E_INVALID_NUMERIC_STRING, CRYPT_E_INVALID_PRINTABLE_STRING or
  2408. //    CRYPT_E_INVALID_IA5_STRING.
  2409. //
  2410. //    To disable the above check, either set CERT_RDN_DISABLE_CHECK_TYPE_FLAG
  2411. //    in dwValueType or set CRYPT_UNICODE_NAME_ENCODE_DISABLE_CHECK_TYPE_FLAG
  2412. //    in dwFlags passed to CryptEncodeObjectEx.
  2413. //
  2414. //    The unicode string is converted before being encoded according to
  2415. //    the specified dwValueType. If dwValueType is set to 0, LastError
  2416. //    is set to E_INVALIDARG.
  2417. //
  2418. //    If the dwValueType isn't one of the character strings (its a
  2419. //    CERT_RDN_ENCODED_BLOB or CERT_RDN_OCTET_STRING), then, CryptEncodeObject
  2420. //    will return FALSE with LastError set to CRYPT_E_NOT_CHAR_STRING.
  2421. //
  2422. //  For CryptDecodeObject:
  2423. //    Value.pbData points to a NULL terminated unicode string. Value.cbData
  2424. //    contains the byte count of the unicode string excluding the NULL
  2425. //    terminator. dwValueType contains the type used in the encoded object.
  2426. //    Its not forced to CERT_RDN_UNICODE_STRING. The encoded value is
  2427. //    converted to the unicode string according to the dwValueType.
  2428. //
  2429. //    If the encoded object isn't one of the character string types, then,
  2430. //    CryptDecodeObject will return FALSE with LastError set to
  2431. //    CRYPT_E_NOT_CHAR_STRING. For a non character string, decode using
  2432. //    X509_NAME_VALUE or X509_ANY_STRING.
  2433. //
  2434. //    By default, CERT_RDN_T61_STRING values are initially decoded
  2435. //    as UTF8. If the UTF8 decoding fails, then, decoded as 8 bit characters.
  2436. //    Set CRYPT_UNICODE_NAME_DECODE_DISABLE_IE4_UTF8_FLAG in dwFlags
  2437. //    passed to either CryptDecodeObject or CryptDecodeObjectEx to
  2438. //    skip the initial attempt to decode as UTF8.
  2439. //--------------------------------------------------------------------------
  2440. //+-------------------------------------------------------------------------
  2441. //  X509_NAME
  2442. //
  2443. //  pvStructInfo points to CERT_NAME_INFO.
  2444. //--------------------------------------------------------------------------
  2445. //+-------------------------------------------------------------------------
  2446. //  X509_UNICODE_NAME
  2447. //
  2448. //  pvStructInfo points to CERT_NAME_INFO.
  2449. //
  2450. //  The RDN attribute values are unicode strings except for the dwValueTypes of
  2451. //  CERT_RDN_ENCODED_BLOB or CERT_RDN_OCTET_STRING. These dwValueTypes are
  2452. //  the same as for a X509_NAME. Their values aren't converted to/from unicode.
  2453. //
  2454. //  For CryptEncodeObject:
  2455. //    Value.pbData points to the unicode string.
  2456. //    If Value.cbData = 0, then, the unicode string is NULL terminated.
  2457. //    Otherwise, Value.cbData is the unicode string byte count. The byte count
  2458. //    is twice the character count.
  2459. //
  2460. //    If dwValueType = 0 (CERT_RDN_ANY_TYPE), the pszObjId is used to find
  2461. //    an acceptable dwValueType. If the unicode string contains an
  2462. //    invalid character for the found or specified dwValueType, then,
  2463. //    *pcbEncoded is updated with the error location of the invalid character.
  2464. //    See below for details. LastError is set to:
  2465. //    CRYPT_E_INVALID_NUMERIC_STRING, CRYPT_E_INVALID_PRINTABLE_STRING or
  2466. //    CRYPT_E_INVALID_IA5_STRING.
  2467. //
  2468. //    To disable the above check, either set CERT_RDN_DISABLE_CHECK_TYPE_FLAG
  2469. //    in dwValueType or set CRYPT_UNICODE_NAME_ENCODE_DISABLE_CHECK_TYPE_FLAG
  2470. //    in dwFlags passed to CryptEncodeObjectEx.
  2471. //
  2472. //    Set CERT_RDN_UNICODE_STRING in dwValueType or set
  2473. //    CRYPT_UNICODE_NAME_ENCODE_ENABLE_T61_UNICODE_FLAG in dwFlags passed
  2474. //    to CryptEncodeObjectEx to select CERT_RDN_T61_STRING instead of
  2475. //    CERT_RDN_UNICODE_STRING if all the unicode characters are <= 0xFF.
  2476. //
  2477. //    Set CERT_RDN_ENABLE_UTF8_UNICODE_STRING in dwValueType or set
  2478. //    CRYPT_UNICODE_NAME_ENCODE_ENABLE_UTF8_UNICODE_FLAG in dwFlags passed
  2479. //    to CryptEncodeObjectEx to select CERT_RDN_UTF8_STRING instead of
  2480. //    CERT_RDN_UNICODE_STRING.
  2481. //
  2482. //    The unicode string is converted before being encoded according to
  2483. //    the specified or ObjId matching dwValueType.
  2484. //
  2485. //  For CryptDecodeObject:
  2486. //    Value.pbData points to a NULL terminated unicode string. Value.cbData
  2487. //    contains the byte count of the unicode string excluding the NULL
  2488. //    terminator. dwValueType contains the type used in the encoded object.
  2489. //    Its not forced to CERT_RDN_UNICODE_STRING. The encoded value is
  2490. //    converted to the unicode string according to the dwValueType.
  2491. //
  2492. //    If the dwValueType of the encoded value isn't a character string
  2493. //    type, then, it isn't converted to UNICODE. Use the
  2494. //    IS_CERT_RDN_CHAR_STRING() macro on the dwValueType to check
  2495. //    that Value.pbData points to a converted unicode string.
  2496. //
  2497. //    By default, CERT_RDN_T61_STRING values are initially decoded
  2498. //    as UTF8. If the UTF8 decoding fails, then, decoded as 8 bit characters.
  2499. //    Set CRYPT_UNICODE_NAME_DECODE_DISABLE_IE4_UTF8_FLAG in dwFlags
  2500. //    passed to either CryptDecodeObject or CryptDecodeObjectEx to
  2501. //    skip the initial attempt to decode as UTF8.
  2502. //--------------------------------------------------------------------------
  2503. //+-------------------------------------------------------------------------
  2504. //  Unicode Name Value Error Location Definitions
  2505. //
  2506. //  Error location is returned in *pcbEncoded by
  2507. //  CryptEncodeObject(X509_UNICODE_NAME)
  2508. //
  2509. //  Error location consists of:
  2510. //    RDN_INDEX     - 10 bits << 22
  2511. //    ATTR_INDEX    - 6 bits << 16
  2512. //    VALUE_INDEX   - 16 bits (unicode character index)
  2513. //--------------------------------------------------------------------------
  2514. #define CERT_UNICODE_RDN_ERR_INDEX_MASK     0x3FF
  2515. #define CERT_UNICODE_RDN_ERR_INDEX_SHIFT    22
  2516. #define CERT_UNICODE_ATTR_ERR_INDEX_MASK    0x003F
  2517. #define CERT_UNICODE_ATTR_ERR_INDEX_SHIFT   16
  2518. #define CERT_UNICODE_VALUE_ERR_INDEX_MASK   0x0000FFFF
  2519. #define CERT_UNICODE_VALUE_ERR_INDEX_SHIFT  0
  2520. #define GET_CERT_UNICODE_RDN_ERR_INDEX(X)   
  2521.     ((X >> CERT_UNICODE_RDN_ERR_INDEX_SHIFT) & CERT_UNICODE_RDN_ERR_INDEX_MASK)
  2522. #define GET_CERT_UNICODE_ATTR_ERR_INDEX(X)  
  2523.     ((X >> CERT_UNICODE_ATTR_ERR_INDEX_SHIFT) & CERT_UNICODE_ATTR_ERR_INDEX_MASK)
  2524. #define GET_CERT_UNICODE_VALUE_ERR_INDEX(X) 
  2525.     (X & CERT_UNICODE_VALUE_ERR_INDEX_MASK)
  2526. //+-------------------------------------------------------------------------
  2527. //  X509_PUBLIC_KEY_INFO
  2528. //
  2529. //  pvStructInfo points to CERT_PUBLIC_KEY_INFO.
  2530. //--------------------------------------------------------------------------
  2531. //+-------------------------------------------------------------------------
  2532. //  X509_AUTHORITY_KEY_ID
  2533. //  szOID_AUTHORITY_KEY_IDENTIFIER
  2534. //
  2535. //  pvStructInfo points to following CERT_AUTHORITY_KEY_ID_INFO.
  2536. //--------------------------------------------------------------------------
  2537. typedef struct _CERT_AUTHORITY_KEY_ID_INFO {
  2538.     CRYPT_DATA_BLOB     KeyId;
  2539.     CERT_NAME_BLOB      CertIssuer;
  2540.     CRYPT_INTEGER_BLOB  CertSerialNumber;
  2541. } CERT_AUTHORITY_KEY_ID_INFO, *PCERT_AUTHORITY_KEY_ID_INFO;
  2542. //+-------------------------------------------------------------------------
  2543. //  X509_KEY_ATTRIBUTES
  2544. //  szOID_KEY_ATTRIBUTES
  2545. //
  2546. //  pvStructInfo points to following CERT_KEY_ATTRIBUTES_INFO.
  2547. //--------------------------------------------------------------------------
  2548. typedef struct _CERT_PRIVATE_KEY_VALIDITY {
  2549.     FILETIME            NotBefore;
  2550.     FILETIME            NotAfter;
  2551. } CERT_PRIVATE_KEY_VALIDITY, *PCERT_PRIVATE_KEY_VALIDITY;
  2552. typedef struct _CERT_KEY_ATTRIBUTES_INFO {
  2553.     CRYPT_DATA_BLOB             KeyId;
  2554.     CRYPT_BIT_BLOB              IntendedKeyUsage;
  2555.     PCERT_PRIVATE_KEY_VALIDITY  pPrivateKeyUsagePeriod;     // OPTIONAL
  2556. } CERT_KEY_ATTRIBUTES_INFO, *PCERT_KEY_ATTRIBUTES_INFO;
  2557. // Byte[0]
  2558. #define CERT_DIGITAL_SIGNATURE_KEY_USAGE     0x80
  2559. #define CERT_NON_REPUDIATION_KEY_USAGE       0x40
  2560. #define CERT_KEY_ENCIPHERMENT_KEY_USAGE      0x20
  2561. #define CERT_DATA_ENCIPHERMENT_KEY_USAGE     0x10
  2562. #define CERT_KEY_AGREEMENT_KEY_USAGE         0x08
  2563. #define CERT_KEY_CERT_SIGN_KEY_USAGE         0x04
  2564. #define CERT_OFFLINE_CRL_SIGN_KEY_USAGE      0x02
  2565. #define CERT_CRL_SIGN_KEY_USAGE              0x02
  2566. #define CERT_ENCIPHER_ONLY_KEY_USAGE         0x01
  2567. // Byte[1]
  2568. #define CERT_DECIPHER_ONLY_KEY_USAGE         0x80
  2569. //+-------------------------------------------------------------------------
  2570. //  X509_KEY_USAGE_RESTRICTION
  2571. //  szOID_KEY_USAGE_RESTRICTION
  2572. //
  2573. //  pvStructInfo points to following CERT_KEY_USAGE_RESTRICTION_INFO.
  2574. //--------------------------------------------------------------------------
  2575. typedef struct _CERT_POLICY_ID {
  2576.     DWORD                   cCertPolicyElementId;
  2577.     LPSTR                   *rgpszCertPolicyElementId;  // pszObjId
  2578. } CERT_POLICY_ID, *PCERT_POLICY_ID;
  2579. typedef struct _CERT_KEY_USAGE_RESTRICTION_INFO {
  2580.     DWORD                   cCertPolicyId;
  2581.     PCERT_POLICY_ID         rgCertPolicyId;
  2582.     CRYPT_BIT_BLOB          RestrictedKeyUsage;
  2583. } CERT_KEY_USAGE_RESTRICTION_INFO, *PCERT_KEY_USAGE_RESTRICTION_INFO;
  2584. // See CERT_KEY_ATTRIBUTES_INFO for definition of the RestrictedKeyUsage bits
  2585. //+-------------------------------------------------------------------------
  2586. //  X509_ALTERNATE_NAME
  2587. //  szOID_SUBJECT_ALT_NAME
  2588. //  szOID_ISSUER_ALT_NAME
  2589. //  szOID_SUBJECT_ALT_NAME2
  2590. //  szOID_ISSUER_ALT_NAME2
  2591. //
  2592. //  pvStructInfo points to following CERT_ALT_NAME_INFO.
  2593. //--------------------------------------------------------------------------
  2594. typedef struct _CERT_OTHER_NAME {
  2595.     LPSTR               pszObjId;
  2596.     CRYPT_OBJID_BLOB    Value;
  2597. } CERT_OTHER_NAME, *PCERT_OTHER_NAME;
  2598. typedef struct _CERT_ALT_NAME_ENTRY {
  2599.     DWORD   dwAltNameChoice;
  2600.     union {
  2601.         PCERT_OTHER_NAME            pOtherName;         // 1
  2602.         LPWSTR                      pwszRfc822Name;     // 2  (encoded IA5)
  2603.         LPWSTR                      pwszDNSName;        // 3  (encoded IA5)
  2604.         // Not implemented          x400Address;        // 4
  2605.         CERT_NAME_BLOB              DirectoryName;      // 5
  2606.         // Not implemented          pEdiPartyName;      // 6
  2607.         LPWSTR                      pwszURL;            // 7  (encoded IA5)
  2608.         CRYPT_DATA_BLOB             IPAddress;          // 8  (Octet String)
  2609.         LPSTR                       pszRegisteredID;    // 9  (Object Identifer)
  2610.     };
  2611. } CERT_ALT_NAME_ENTRY, *PCERT_ALT_NAME_ENTRY;
  2612. #define CERT_ALT_NAME_OTHER_NAME         1
  2613. #define CERT_ALT_NAME_RFC822_NAME        2
  2614. #define CERT_ALT_NAME_DNS_NAME           3
  2615. #define CERT_ALT_NAME_X400_ADDRESS       4
  2616. #define CERT_ALT_NAME_DIRECTORY_NAME     5
  2617. #define CERT_ALT_NAME_EDI_PARTY_NAME     6
  2618. #define CERT_ALT_NAME_URL                7
  2619. #define CERT_ALT_NAME_IP_ADDRESS         8
  2620. #define CERT_ALT_NAME_REGISTERED_ID      9
  2621. typedef struct _CERT_ALT_NAME_INFO {
  2622.     DWORD                   cAltEntry;
  2623.     PCERT_ALT_NAME_ENTRY    rgAltEntry;
  2624. } CERT_ALT_NAME_INFO, *PCERT_ALT_NAME_INFO;
  2625. //+-------------------------------------------------------------------------
  2626. //  Alternate name IA5 Error Location Definitions for
  2627. //  CRYPT_E_INVALID_IA5_STRING.
  2628. //
  2629. //  Error location is returned in *pcbEncoded by
  2630. //  CryptEncodeObject(X509_ALTERNATE_NAME)
  2631. //
  2632. //  Error location consists of:
  2633. //    ENTRY_INDEX   - 8 bits << 16
  2634. //    VALUE_INDEX   - 16 bits (unicode character index)
  2635. //--------------------------------------------------------------------------
  2636. #define CERT_ALT_NAME_ENTRY_ERR_INDEX_MASK  0xFF
  2637. #define CERT_ALT_NAME_ENTRY_ERR_INDEX_SHIFT 16
  2638. #define CERT_ALT_NAME_VALUE_ERR_INDEX_MASK  0x0000FFFF
  2639. #define CERT_ALT_NAME_VALUE_ERR_INDEX_SHIFT 0
  2640. #define GET_CERT_ALT_NAME_ENTRY_ERR_INDEX(X)   
  2641.     ((X >> CERT_ALT_NAME_ENTRY_ERR_INDEX_SHIFT) & 
  2642.     CERT_ALT_NAME_ENTRY_ERR_INDEX_MASK)
  2643. #define GET_CERT_ALT_NAME_VALUE_ERR_INDEX(X) 
  2644.     (X & CERT_ALT_NAME_VALUE_ERR_INDEX_MASK)
  2645. //+-------------------------------------------------------------------------
  2646. //  X509_BASIC_CONSTRAINTS
  2647. //  szOID_BASIC_CONSTRAINTS
  2648. //
  2649. //  pvStructInfo points to following CERT_BASIC_CONSTRAINTS_INFO.
  2650. //--------------------------------------------------------------------------
  2651. typedef struct _CERT_BASIC_CONSTRAINTS_INFO {
  2652.     CRYPT_BIT_BLOB          SubjectType;
  2653.     BOOL                    fPathLenConstraint;
  2654.     DWORD                   dwPathLenConstraint;
  2655.     DWORD                   cSubtreesConstraint;
  2656.     CERT_NAME_BLOB          *rgSubtreesConstraint;
  2657. } CERT_BASIC_CONSTRAINTS_INFO, *PCERT_BASIC_CONSTRAINTS_INFO;
  2658. #define CERT_CA_SUBJECT_FLAG         0x80
  2659. #define CERT_END_ENTITY_SUBJECT_FLAG 0x40
  2660. //+-------------------------------------------------------------------------
  2661. //  X509_BASIC_CONSTRAINTS2
  2662. //  szOID_BASIC_CONSTRAINTS2
  2663. //
  2664. //  pvStructInfo points to following CERT_BASIC_CONSTRAINTS2_INFO.
  2665. //--------------------------------------------------------------------------
  2666. typedef struct _CERT_BASIC_CONSTRAINTS2_INFO {
  2667.     BOOL                    fCA;
  2668.     BOOL                    fPathLenConstraint;
  2669.     DWORD                   dwPathLenConstraint;
  2670. } CERT_BASIC_CONSTRAINTS2_INFO, *PCERT_BASIC_CONSTRAINTS2_INFO;
  2671. //+-------------------------------------------------------------------------
  2672. //  X509_KEY_USAGE
  2673. //  szOID_KEY_USAGE
  2674. //
  2675. //  pvStructInfo points to a CRYPT_BIT_BLOB. Has same bit definitions as
  2676. //  CERT_KEY_ATTRIBUTES_INFO's IntendedKeyUsage.
  2677. //--------------------------------------------------------------------------
  2678. //+-------------------------------------------------------------------------
  2679. //  X509_CERT_POLICIES
  2680. //  szOID_CERT_POLICIES
  2681. //  szOID_CERT_POLICIES_95   NOTE--Only allowed for decoding!!!
  2682. //
  2683. //  pvStructInfo points to following CERT_POLICIES_INFO.
  2684. //
  2685. //  NOTE: when decoding using szOID_CERT_POLICIES_95 the pszPolicyIdentifier
  2686. //        may contain an empty string
  2687. //--------------------------------------------------------------------------
  2688. typedef struct _CERT_POLICY_QUALIFIER_INFO {
  2689.     LPSTR                       pszPolicyQualifierId;   // pszObjId
  2690.     CRYPT_OBJID_BLOB            Qualifier;              // optional
  2691. } CERT_POLICY_QUALIFIER_INFO, *PCERT_POLICY_QUALIFIER_INFO;
  2692. typedef struct _CERT_POLICY_INFO {
  2693.     LPSTR                       pszPolicyIdentifier;    // pszObjId
  2694.     DWORD                       cPolicyQualifier;       // optional
  2695.     CERT_POLICY_QUALIFIER_INFO  *rgPolicyQualifier;
  2696. } CERT_POLICY_INFO, *PCERT_POLICY_INFO;
  2697. typedef struct _CERT_POLICIES_INFO {
  2698.     DWORD                       cPolicyInfo;
  2699.     CERT_POLICY_INFO            *rgPolicyInfo;
  2700. } CERT_POLICIES_INFO, *PCERT_POLICIES_INFO;
  2701. //+-------------------------------------------------------------------------
  2702. //  X509_PKIX_POLICY_QUALIFIER_USERNOTICE
  2703. //  szOID_PKIX_POLICY_QUALIFIER_USERNOTICE
  2704. //
  2705. //  pvStructInfo points to following CERT_POLICY_QUALIFIER_USER_NOTICE.
  2706. //
  2707. //--------------------------------------------------------------------------
  2708. typedef struct _CERT_POLICY_QUALIFIER_NOTICE_REFERENCE {
  2709.     LPSTR   pszOrganization;
  2710.     DWORD   cNoticeNumbers;
  2711.     int     *rgNoticeNumbers;
  2712. } CERT_POLICY_QUALIFIER_NOTICE_REFERENCE, *PCERT_POLICY_QUALIFIER_NOTICE_REFERENCE;
  2713. typedef struct _CERT_POLICY_QUALIFIER_USER_NOTICE {
  2714.     CERT_POLICY_QUALIFIER_NOTICE_REFERENCE  *pNoticeReference;  // optional
  2715.     LPWSTR                                  pszDisplayText;     // optional
  2716. } CERT_POLICY_QUALIFIER_USER_NOTICE, *PCERT_POLICY_QUALIFIER_USER_NOTICE;
  2717. //+-------------------------------------------------------------------------
  2718. //  szOID_CERT_POLICIES_95_QUALIFIER1 - Decode Only!!!!
  2719. //
  2720. //  pvStructInfo points to following CERT_POLICY95_QUALIFIER1.
  2721. //
  2722. //--------------------------------------------------------------------------
  2723. typedef struct _CPS_URLS {
  2724.     LPWSTR                      pszURL;
  2725.     CRYPT_ALGORITHM_IDENTIFIER  *pAlgorithm; // optional
  2726.     CRYPT_DATA_BLOB             *pDigest;    // optional
  2727. } CPS_URLS, *PCPS_URLS;
  2728. typedef struct _CERT_POLICY95_QUALIFIER1 {
  2729.     LPWSTR      pszPracticesReference;      // optional
  2730.     LPSTR       pszNoticeIdentifier;        // optional
  2731.     LPSTR       pszNSINoticeIdentifier;     // optional
  2732.     DWORD       cCPSURLs;
  2733.     CPS_URLS    *rgCPSURLs;                 // optional
  2734. } CERT_POLICY95_QUALIFIER1, *PCERT_POLICY95_QUALIFIER1;
  2735. //+-------------------------------------------------------------------------
  2736. //  X509_POLICY_MAPPINGS
  2737. //  szOID_POLICY_MAPPINGS
  2738. //  szOID_LEGACY_POLICY_MAPPINGS
  2739. //
  2740. //  pvStructInfo points to following CERT_POLICY_MAPPINGS_INFO.
  2741. //--------------------------------------------------------------------------
  2742. typedef struct _CERT_POLICY_MAPPING {
  2743.     LPSTR                       pszIssuerDomainPolicy;      // pszObjId
  2744.     LPSTR                       pszSubjectDomainPolicy;     // pszObjId
  2745. } CERT_POLICY_MAPPING, *PCERT_POLICY_MAPPING;
  2746. typedef struct _CERT_POLICY_MAPPINGS_INFO {
  2747.     DWORD                       cPolicyMapping;
  2748.     PCERT_POLICY_MAPPING        rgPolicyMapping;
  2749. } CERT_POLICY_MAPPINGS_INFO, *PCERT_POLICY_MAPPINGS_INFO;
  2750. //+-------------------------------------------------------------------------
  2751. //  X509_POLICY_CONSTRAINTS
  2752. //  szOID_POLICY_CONSTRAINTS
  2753. //
  2754. //  pvStructInfo points to following CERT_POLICY_CONSTRAINTS_INFO.
  2755. //--------------------------------------------------------------------------
  2756. typedef struct _CERT_POLICY_CONSTRAINTS_INFO {
  2757.     BOOL                        fRequireExplicitPolicy;
  2758.     DWORD                       dwRequireExplicitPolicySkipCerts;