cscg24-guacamole

CSCG 2024 Challenge 'Guacamole Mashup'
git clone https://git.sinitax.com/sinitax/cscg24-guacamole
Log | Files | Refs | sfeed.txt

wincrypt.h (24807B)


      1/**
      2 * WinPR: Windows Portable Runtime
      3 * Cryptography API (CryptoAPI)
      4 *
      5 * Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
      6 *
      7 * Licensed under the Apache License, Version 2.0 (the "License");
      8 * you may not use this file except in compliance with the License.
      9 * You may obtain a copy of the License at
     10 *
     11 *     http://www.apache.org/licenses/LICENSE-2.0
     12 *
     13 * Unless required by applicable law or agreed to in writing, software
     14 * distributed under the License is distributed on an "AS IS" BASIS,
     15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     16 * See the License for the specific language governing permissions and
     17 * limitations under the License.
     18 */
     19
     20#ifndef WINPR_WINCRYPT_H
     21#define WINPR_WINCRYPT_H
     22
     23#include <winpr/winpr.h>
     24#include <winpr/wtypes.h>
     25
     26#include <winpr/error.h>
     27
     28#ifdef _WIN32
     29
     30#include <wincrypt.h>
     31
     32#endif
     33
     34#ifndef ALG_TYPE_RESERVED7
     35#define ALG_TYPE_RESERVED7 (7 << 9)
     36#endif
     37
     38#if !defined(NTDDI_VERSION) || (NTDDI_VERSION <= 0x05010200)
     39#define ALG_SID_SHA_256 12
     40#define ALG_SID_SHA_384 13
     41#define ALG_SID_SHA_512 14
     42#define CALG_SHA_256 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA_256)
     43#define CALG_SHA_384 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA_384)
     44#define CALG_SHA_512 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA_512)
     45#endif
     46
     47#ifndef _WIN32
     48
     49/* ncrypt.h */
     50
     51typedef ULONG_PTR NCRYPT_HANDLE;
     52typedef ULONG_PTR NCRYPT_PROV_HANDLE;
     53typedef ULONG_PTR NCRYPT_KEY_HANDLE;
     54typedef ULONG_PTR NCRYPT_HASH_HANDLE;
     55typedef ULONG_PTR NCRYPT_SECRET_HANDLE;
     56
     57/* wincrypt.h */
     58
     59#define GET_ALG_CLASS(x) (x & (7 << 13))
     60#define GET_ALG_TYPE(x) (x & (15 << 9))
     61#define GET_ALG_SID(x) (x & (511))
     62
     63#define ALG_CLASS_ANY (0)
     64#define ALG_CLASS_SIGNATURE (1 << 13)
     65#define ALG_CLASS_MSG_ENCRYPT (2 << 13)
     66#define ALG_CLASS_DATA_ENCRYPT (3 << 13)
     67#define ALG_CLASS_HASH (4 << 13)
     68#define ALG_CLASS_KEY_EXCHANGE (5 << 13)
     69#define ALG_CLASS_ALL (7 << 13)
     70
     71#define ALG_TYPE_ANY (0)
     72#define ALG_TYPE_DSS (1 << 9)
     73#define ALG_TYPE_RSA (2 << 9)
     74#define ALG_TYPE_BLOCK (3 << 9)
     75#define ALG_TYPE_STREAM (4 << 9)
     76#define ALG_TYPE_DH (5 << 9)
     77#define ALG_TYPE_SECURECHANNEL (6 << 9)
     78
     79#define ALG_SID_ANY (0)
     80
     81#define ALG_SID_RSA_ANY 0
     82#define ALG_SID_RSA_PKCS 1
     83#define ALG_SID_RSA_MSATWORK 2
     84#define ALG_SID_RSA_ENTRUST 3
     85#define ALG_SID_RSA_PGP 4
     86
     87#define ALG_SID_DSS_ANY 0
     88#define ALG_SID_DSS_PKCS 1
     89#define ALG_SID_DSS_DMS 2
     90
     91#define ALG_SID_DES 1
     92#define ALG_SID_3DES 3
     93#define ALG_SID_DESX 4
     94#define ALG_SID_IDEA 5
     95#define ALG_SID_CAST 6
     96#define ALG_SID_SAFERSK64 7
     97#define ALG_SID_SAFERSK128 8
     98#define ALG_SID_3DES_112 9
     99#define ALG_SID_CYLINK_MEK 12
    100#define ALG_SID_RC5 13
    101
    102#define ALG_SID_AES_128 14
    103#define ALG_SID_AES_192 15
    104#define ALG_SID_AES_256 16
    105#define ALG_SID_AES 17
    106
    107#define ALG_SID_SKIPJACK 10
    108#define ALG_SID_TEK 11
    109
    110#define CRYPT_MODE_CBCI 6
    111#define CRYPT_MODE_CFBP 7
    112#define CRYPT_MODE_OFBP 8
    113#define CRYPT_MODE_CBCOFM 9
    114#define CRYPT_MODE_CBCOFMI 10
    115
    116#define ALG_SID_RC2 2
    117
    118#define ALG_SID_RC4 1
    119#define ALG_SID_SEAL 2
    120
    121#define ALG_SID_DH_SANDF 1
    122#define ALG_SID_DH_EPHEM 2
    123#define ALG_SID_AGREED_KEY_ANY 3
    124#define ALG_SID_KEA 4
    125
    126#define ALG_SID_ECDH 5
    127
    128#define ALG_SID_MD2 1
    129#define ALG_SID_MD4 2
    130#define ALG_SID_MD5 3
    131#define ALG_SID_SHA 4
    132#define ALG_SID_SHA1 4
    133#define ALG_SID_MAC 5
    134#define ALG_SID_RIPEMD 6
    135#define ALG_SID_RIPEMD160 7
    136#define ALG_SID_SSL3SHAMD5 8
    137#define ALG_SID_HMAC 9
    138#define ALG_SID_TLS1PRF 10
    139
    140#define ALG_SID_HASH_REPLACE_OWF 11
    141
    142#define ALG_SID_SHA_256 12
    143#define ALG_SID_SHA_384 13
    144#define ALG_SID_SHA_512 14
    145
    146#define ALG_SID_SSL3_MASTER 1
    147#define ALG_SID_SCHANNEL_MASTER_HASH 2
    148#define ALG_SID_SCHANNEL_MAC_KEY 3
    149#define ALG_SID_PCT1_MASTER 4
    150#define ALG_SID_SSL2_MASTER 5
    151#define ALG_SID_TLS1_MASTER 6
    152#define ALG_SID_SCHANNEL_ENC_KEY 7
    153
    154#define ALG_SID_ECMQV 1
    155
    156#define CALG_MD2 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MD2)
    157#define CALG_MD4 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MD4)
    158#define CALG_MD5 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MD5)
    159#define CALG_SHA (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA)
    160#define CALG_SHA1 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA1)
    161#define CALG_MAC (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MAC)
    162#define CALG_RSA_SIGN (ALG_CLASS_SIGNATURE | ALG_TYPE_RSA | ALG_SID_RSA_ANY)
    163#define CALG_DSS_SIGN (ALG_CLASS_SIGNATURE | ALG_TYPE_DSS | ALG_SID_DSS_ANY)
    164
    165#define CALG_NO_SIGN (ALG_CLASS_SIGNATURE | ALG_TYPE_ANY | ALG_SID_ANY)
    166
    167#define CALG_RSA_KEYX (ALG_CLASS_KEY_EXCHANGE | ALG_TYPE_RSA | ALG_SID_RSA_ANY)
    168#define CALG_DES (ALG_CLASS_DATA_ENCRYPT | ALG_TYPE_BLOCK | ALG_SID_DES)
    169#define CALG_3DES_112 (ALG_CLASS_DATA_ENCRYPT | ALG_TYPE_BLOCK | ALG_SID_3DES_112)
    170#define CALG_3DES (ALG_CLASS_DATA_ENCRYPT | ALG_TYPE_BLOCK | ALG_SID_3DES)
    171#define CALG_DESX (ALG_CLASS_DATA_ENCRYPT | ALG_TYPE_BLOCK | ALG_SID_DESX)
    172#define CALG_RC2 (ALG_CLASS_DATA_ENCRYPT | ALG_TYPE_BLOCK | ALG_SID_RC2)
    173#define CALG_RC4 (ALG_CLASS_DATA_ENCRYPT | ALG_TYPE_STREAM | ALG_SID_RC4)
    174#define CALG_SEAL (ALG_CLASS_DATA_ENCRYPT | ALG_TYPE_STREAM | ALG_SID_SEAL)
    175#define CALG_DH_SF (ALG_CLASS_KEY_EXCHANGE | ALG_TYPE_DH | ALG_SID_DH_SANDF)
    176#define CALG_DH_EPHEM (ALG_CLASS_KEY_EXCHANGE | ALG_TYPE_DH | ALG_SID_DH_EPHEM)
    177#define CALG_AGREEDKEY_ANY (ALG_CLASS_KEY_EXCHANGE | ALG_TYPE_DH | ALG_SID_AGREED_KEY_ANY)
    178#define CALG_KEA_KEYX (ALG_CLASS_KEY_EXCHANGE | ALG_TYPE_DH | ALG_SID_KEA)
    179#define CALG_HUGHES_MD5 (ALG_CLASS_KEY_EXCHANGE | ALG_TYPE_ANY | ALG_SID_MD5)
    180#define CALG_SKIPJACK (ALG_CLASS_DATA_ENCRYPT | ALG_TYPE_BLOCK | ALG_SID_SKIPJACK)
    181#define CALG_TEK (ALG_CLASS_DATA_ENCRYPT | ALG_TYPE_BLOCK | ALG_SID_TEK)
    182#define CALG_CYLINK_MEK (ALG_CLASS_DATA_ENCRYPT | ALG_TYPE_BLOCK | ALG_SID_CYLINK_MEK)
    183#define CALG_SSL3_SHAMD5 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SSL3SHAMD5)
    184#define CALG_SSL3_MASTER (ALG_CLASS_MSG_ENCRYPT | ALG_TYPE_SECURECHANNEL | ALG_SID_SSL3_MASTER)
    185#define CALG_SCHANNEL_MASTER_HASH \
    186	(ALG_CLASS_MSG_ENCRYPT | ALG_TYPE_SECURECHANNEL | ALG_SID_SCHANNEL_MASTER_HASH)
    187#define CALG_SCHANNEL_MAC_KEY \
    188	(ALG_CLASS_MSG_ENCRYPT | ALG_TYPE_SECURECHANNEL | ALG_SID_SCHANNEL_MAC_KEY)
    189#define CALG_SCHANNEL_ENC_KEY \
    190	(ALG_CLASS_MSG_ENCRYPT | ALG_TYPE_SECURECHANNEL | ALG_SID_SCHANNEL_ENC_KEY)
    191#define CALG_PCT1_MASTER (ALG_CLASS_MSG_ENCRYPT | ALG_TYPE_SECURECHANNEL | ALG_SID_PCT1_MASTER)
    192#define CALG_SSL2_MASTER (ALG_CLASS_MSG_ENCRYPT | ALG_TYPE_SECURECHANNEL | ALG_SID_SSL2_MASTER)
    193#define CALG_TLS1_MASTER (ALG_CLASS_MSG_ENCRYPT | ALG_TYPE_SECURECHANNEL | ALG_SID_TLS1_MASTER)
    194#define CALG_RC5 (ALG_CLASS_DATA_ENCRYPT | ALG_TYPE_BLOCK | ALG_SID_RC5)
    195#define CALG_HMAC (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_HMAC)
    196#define CALG_TLS1PRF (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_TLS1PRF)
    197
    198#define CALG_HASH_REPLACE_OWF (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_HASH_REPLACE_OWF)
    199#define CALG_AES_128 (ALG_CLASS_DATA_ENCRYPT | ALG_TYPE_BLOCK | ALG_SID_AES_128)
    200#define CALG_AES_192 (ALG_CLASS_DATA_ENCRYPT | ALG_TYPE_BLOCK | ALG_SID_AES_192)
    201#define CALG_AES_256 (ALG_CLASS_DATA_ENCRYPT | ALG_TYPE_BLOCK | ALG_SID_AES_256)
    202#define CALG_AES (ALG_CLASS_DATA_ENCRYPT | ALG_TYPE_BLOCK | ALG_SID_AES)
    203
    204#define CALG_SHA_256 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA_256)
    205#define CALG_SHA_384 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA_384)
    206#define CALG_SHA_512 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA_512)
    207
    208#define CALG_ECDH (ALG_CLASS_KEY_EXCHANGE | ALG_TYPE_DH | ALG_SID_ECDH)
    209#define CALG_ECMQV (ALG_CLASS_KEY_EXCHANGE | ALG_TYPE_ANY | ALG_SID_ECMQV)
    210
    211typedef struct
    212{
    213	DWORD cbData;
    214	BYTE* pbData;
    215} CRYPT_INTEGER_BLOB, *PCRYPT_INTEGER_BLOB, CRYPT_UINT_BLOB, *PCRYPT_UINT_BLOB, CRYPT_OBJID_BLOB,
    216    *PCRYPT_OBJID_BLOB, CERT_NAME_BLOB, *PCERT_NAME_BLOB, CERT_RDN_VALUE_BLOB,
    217    *PCERT_RDN_VALUE_BLOB, CERT_BLOB, *PCERT_BLOB, CRL_BLOB, *PCRL_BLOB, DATA_BLOB, *PDATA_BLOB,
    218    CRYPT_DATA_BLOB, *PCRYPT_DATA_BLOB, CRYPT_HASH_BLOB, *PCRYPT_HASH_BLOB, CRYPT_DIGEST_BLOB,
    219    *PCRYPT_DIGEST_BLOB, CRYPT_DER_BLOB, *PCRYPT_DER_BLOB, CRYPT_ATTR_BLOB, *PCRYPT_ATTR_BLOB;
    220
    221typedef struct
    222{
    223	LPSTR pszObjId;
    224	CRYPT_OBJID_BLOB Parameters;
    225} CRYPT_ALGORITHM_IDENTIFIER, *PCRYPT_ALGORITHM_IDENTIFIER;
    226
    227typedef struct
    228{
    229	DWORD cbData;
    230	BYTE* pbData;
    231	DWORD cUnusedBits;
    232} CRYPT_BIT_BLOB, *PCRYPT_BIT_BLOB;
    233
    234typedef struct
    235{
    236	CRYPT_ALGORITHM_IDENTIFIER Algorithm;
    237	CRYPT_BIT_BLOB PublicKey;
    238} CERT_PUBLIC_KEY_INFO, *PCERT_PUBLIC_KEY_INFO;
    239
    240typedef struct
    241{
    242	LPSTR pszObjId;
    243	BOOL fCritical;
    244	CRYPT_OBJID_BLOB Value;
    245} CERT_EXTENSION, *PCERT_EXTENSION;
    246typedef const CERT_EXTENSION* PCCERT_EXTENSION;
    247
    248typedef struct
    249{
    250	DWORD dwVersion;
    251	CRYPT_INTEGER_BLOB SerialNumber;
    252	CRYPT_ALGORITHM_IDENTIFIER SignatureAlgorithm;
    253	CERT_NAME_BLOB Issuer;
    254	FILETIME NotBefore;
    255	FILETIME NotAfter;
    256	CERT_NAME_BLOB Subject;
    257	CERT_PUBLIC_KEY_INFO SubjectPublicKeyInfo;
    258	CRYPT_BIT_BLOB IssuerUniqueId;
    259	CRYPT_BIT_BLOB SubjectUniqueId;
    260	DWORD cExtension;
    261	PCERT_EXTENSION rgExtension;
    262} CERT_INFO, *PCERT_INFO;
    263
    264typedef void* HCERTSTORE;
    265typedef ULONG_PTR HCRYPTPROV;
    266typedef ULONG_PTR HCRYPTPROV_LEGACY;
    267
    268typedef struct
    269{
    270	DWORD dwCertEncodingType;
    271	BYTE* pbCertEncoded;
    272	DWORD cbCertEncoded;
    273	PCERT_INFO pCertInfo;
    274	HCERTSTORE hCertStore;
    275} CERT_CONTEXT, *PCERT_CONTEXT;
    276typedef const CERT_CONTEXT* PCCERT_CONTEXT;
    277
    278#if !defined(AT_KEYEXCHANGE)
    279#define AT_KEYEXCHANGE (1)
    280#endif
    281#if !defined(AT_SIGNATURE)
    282#define AT_SIGNATURE (2)
    283#endif
    284#if !defined(AT_AUTHENTICATE)
    285#define AT_AUTHENTICATE (3)
    286#endif
    287
    288#define CERT_ENCODING_TYPE_MASK 0x0000FFFF
    289#define CMSG_ENCODING_TYPE_MASK 0xFFFF0000
    290#define GET_CERT_ENCODING_TYPE(x) (x & CERT_ENCODING_TYPE_MASK)
    291#define GET_CMSG_ENCODING_TYPE(x) (x & CMSG_ENCODING_TYPE_MASK)
    292
    293#define CRYPT_ASN_ENCODING 0x00000001
    294#define CRYPT_NDR_ENCODING 0x00000002
    295#define X509_ASN_ENCODING 0x00000001
    296#define X509_NDR_ENCODING 0x00000002
    297#define PKCS_7_ASN_ENCODING 0x00010000
    298#define PKCS_7_NDR_ENCODING 0x00020000
    299
    300#define CERT_COMPARE_MASK 0xFFFF
    301#define CERT_COMPARE_SHIFT 16
    302#define CERT_COMPARE_ANY 0
    303#define CERT_COMPARE_SHA1_HASH 1
    304#define CERT_COMPARE_NAME 2
    305#define CERT_COMPARE_ATTR 3
    306#define CERT_COMPARE_MD5_HASH 4
    307#define CERT_COMPARE_PROPERTY 5
    308#define CERT_COMPARE_PUBLIC_KEY 6
    309#define CERT_COMPARE_HASH CERT_COMPARE_SHA1_HASH
    310#define CERT_COMPARE_NAME_STR_A 7
    311#define CERT_COMPARE_NAME_STR_W 8
    312#define CERT_COMPARE_KEY_SPEC 9
    313#define CERT_COMPARE_ENHKEY_USAGE 10
    314#define CERT_COMPARE_CTL_USAGE CERT_COMPARE_ENHKEY_USAGE
    315#define CERT_COMPARE_SUBJECT_CERT 11
    316#define CERT_COMPARE_ISSUER_OF 12
    317#define CERT_COMPARE_EXISTING 13
    318#define CERT_COMPARE_SIGNATURE_HASH 14
    319#define CERT_COMPARE_KEY_IDENTIFIER 15
    320#define CERT_COMPARE_CERT_ID 16
    321#define CERT_COMPARE_CROSS_CERT_DIST_POINTS 17
    322#define CERT_COMPARE_PUBKEY_MD5_HASH 18
    323#define CERT_COMPARE_SUBJECT_INFO_ACCESS 19
    324#define CERT_COMPARE_HASH_STR 20
    325#define CERT_COMPARE_HAS_PRIVATE_KEY 21
    326
    327#define CERT_FIND_ANY (CERT_COMPARE_ANY << CERT_COMPARE_SHIFT)
    328#define CERT_FIND_SHA1_HASH (CERT_COMPARE_SHA1_HASH << CERT_COMPARE_SHIFT)
    329#define CERT_FIND_MD5_HASH (CERT_COMPARE_MD5_HASH << CERT_COMPARE_SHIFT)
    330#define CERT_FIND_SIGNATURE_HASH (CERT_COMPARE_SIGNATURE_HASH << CERT_COMPARE_SHIFT)
    331#define CERT_FIND_KEY_IDENTIFIER (CERT_COMPARE_KEY_IDENTIFIER << CERT_COMPARE_SHIFT)
    332#define CERT_FIND_HASH CERT_FIND_SHA1_HASH
    333#define CERT_FIND_PROPERTY (CERT_COMPARE_PROPERTY << CERT_COMPARE_SHIFT)
    334#define CERT_FIND_PUBLIC_KEY (CERT_COMPARE_PUBLIC_KEY << CERT_COMPARE_SHIFT)
    335#define CERT_FIND_SUBJECT_NAME (CERT_COMPARE_NAME << CERT_COMPARE_SHIFT | CERT_INFO_SUBJECT_FLAG)
    336#define CERT_FIND_SUBJECT_ATTR (CERT_COMPARE_ATTR << CERT_COMPARE_SHIFT | CERT_INFO_SUBJECT_FLAG)
    337#define CERT_FIND_ISSUER_NAME (CERT_COMPARE_NAME << CERT_COMPARE_SHIFT | CERT_INFO_ISSUER_FLAG)
    338#define CERT_FIND_ISSUER_ATTR (CERT_COMPARE_ATTR << CERT_COMPARE_SHIFT | CERT_INFO_ISSUER_FLAG)
    339#define CERT_FIND_SUBJECT_STR_A \
    340	(CERT_COMPARE_NAME_STR_A << CERT_COMPARE_SHIFT | CERT_INFO_SUBJECT_FLAG)
    341#define CERT_FIND_SUBJECT_STR_W \
    342	(CERT_COMPARE_NAME_STR_W << CERT_COMPARE_SHIFT | CERT_INFO_SUBJECT_FLAG)
    343#define CERT_FIND_SUBJECT_STR CERT_FIND_SUBJECT_STR_W
    344#define CERT_FIND_ISSUER_STR_A \
    345	(CERT_COMPARE_NAME_STR_A << CERT_COMPARE_SHIFT | CERT_INFO_ISSUER_FLAG)
    346#define CERT_FIND_ISSUER_STR_W \
    347	(CERT_COMPARE_NAME_STR_W << CERT_COMPARE_SHIFT | CERT_INFO_ISSUER_FLAG)
    348#define CERT_FIND_ISSUER_STR CERT_FIND_ISSUER_STR_W
    349#define CERT_FIND_KEY_SPEC (CERT_COMPARE_KEY_SPEC << CERT_COMPARE_SHIFT)
    350#define CERT_FIND_ENHKEY_USAGE (CERT_COMPARE_ENHKEY_USAGE << CERT_COMPARE_SHIFT)
    351#define CERT_FIND_CTL_USAGE CERT_FIND_ENHKEY_USAGE
    352#define CERT_FIND_SUBJECT_CERT (CERT_COMPARE_SUBJECT_CERT << CERT_COMPARE_SHIFT)
    353#define CERT_FIND_ISSUER_OF (CERT_COMPARE_ISSUER_OF << CERT_COMPARE_SHIFT)
    354#define CERT_FIND_EXISTING (CERT_COMPARE_EXISTING << CERT_COMPARE_SHIFT)
    355#define CERT_FIND_CERT_ID (CERT_COMPARE_CERT_ID << CERT_COMPARE_SHIFT)
    356#define CERT_FIND_CROSS_CERT_DIST_POINTS (CERT_COMPARE_CROSS_CERT_DIST_POINTS << CERT_COMPARE_SHIFT)
    357#define CERT_FIND_PUBKEY_MD5_HASH (CERT_COMPARE_PUBKEY_MD5_HASH << CERT_COMPARE_SHIFT)
    358#define CERT_FIND_SUBJECT_INFO_ACCESS (CERT_COMPARE_SUBJECT_INFO_ACCESS << CERT_COMPARE_SHIFT)
    359#define CERT_FIND_HASH_STR (CERT_COMPARE_HASH_STR << CERT_COMPARE_SHIFT)
    360#define CERT_FIND_HAS_PRIVATE_KEY (CERT_COMPARE_HAS_PRIVATE_KEY << CERT_COMPARE_SHIFT)
    361
    362#define CERT_FIND_OPTIONAL_ENHKEY_USAGE_FLAG 0x1
    363#define CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG 0x2
    364#define CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG 0x4
    365#define CERT_FIND_NO_ENHKEY_USAGE_FLAG 0x8
    366#define CERT_FIND_OR_ENHKEY_USAGE_FLAG 0x10
    367#define CERT_FIND_VALID_ENHKEY_USAGE_FLAG 0x20
    368#define CERT_FIND_OPTIONAL_CTL_USAGE_FLAG CERT_FIND_OPTIONAL_ENHKEY_USAGE_FLAG
    369#define CERT_FIND_EXT_ONLY_CTL_USAGE_FLAG CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG
    370#define CERT_FIND_PROP_ONLY_CTL_USAGE_FLAG CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG
    371#define CERT_FIND_NO_CTL_USAGE_FLAG CERT_FIND_NO_ENHKEY_USAGE_FLAG
    372#define CERT_FIND_OR_CTL_USAGE_FLAG CERT_FIND_OR_ENHKEY_USAGE_FLAG
    373#define CERT_FIND_VALID_CTL_USAGE_FLAG CERT_FIND_VALID_ENHKEY_USAGE_FLAG
    374
    375#define CERT_NAME_EMAIL_TYPE 1
    376#define CERT_NAME_RDN_TYPE 2
    377#define CERT_NAME_ATTR_TYPE 3
    378#define CERT_NAME_SIMPLE_DISPLAY_TYPE 4
    379#define CERT_NAME_FRIENDLY_DISPLAY_TYPE 5
    380#define CERT_NAME_DNS_TYPE 6
    381#define CERT_NAME_URL_TYPE 7
    382#define CERT_NAME_UPN_TYPE 8
    383
    384#define CERT_NAME_ISSUER_FLAG 0x1
    385#define CERT_NAME_DISABLE_IE4_UTF8_FLAG 0x00010000
    386
    387#define CERT_NAME_SEARCH_ALL_NAMES_FLAG 0x2
    388
    389#define CERT_STORE_PROV_MSG ((LPCSTR)1)
    390#define CERT_STORE_PROV_MEMORY ((LPCSTR)2)
    391#define CERT_STORE_PROV_FILE ((LPCSTR)3)
    392#define CERT_STORE_PROV_REG ((LPCSTR)4)
    393#define CERT_STORE_PROV_PKCS7 ((LPCSTR)5)
    394#define CERT_STORE_PROV_SERIALIZED ((LPCSTR)6)
    395#define CERT_STORE_PROV_FILENAME_A ((LPCSTR)7)
    396#define CERT_STORE_PROV_FILENAME_W ((LPCSTR)8)
    397#define CERT_STORE_PROV_FILENAME CERT_STORE_PROV_FILENAME_W
    398#define CERT_STORE_PROV_SYSTEM_A ((LPCSTR)9)
    399#define CERT_STORE_PROV_SYSTEM_W ((LPCSTR)10)
    400#define CERT_STORE_PROV_SYSTEM CERT_STORE_PROV_SYSTEM_W
    401#define CERT_STORE_PROV_COLLECTION ((LPCSTR)11)
    402#define CERT_STORE_PROV_SYSTEM_REGISTRY_A ((LPCSTR)12)
    403#define CERT_STORE_PROV_SYSTEM_REGISTRY_W ((LPCSTR)13)
    404#define CERT_STORE_PROV_SYSTEM_REGISTRY CERT_STORE_PROV_SYSTEM_REGISTRY_W
    405#define CERT_STORE_PROV_PHYSICAL_W ((LPCSTR)14)
    406#define CERT_STORE_PROV_PHYSICAL CERT_STORE_PROV_PHYSICAL_W
    407#define CERT_STORE_PROV_SMART_CARD_W ((LPCSTR)15)
    408#define CERT_STORE_PROV_SMART_CARD CERT_STORE_PROV_SMART_CARD_W
    409#define CERT_STORE_PROV_LDAP_W ((LPCSTR)16)
    410#define CERT_STORE_PROV_LDAP CERT_STORE_PROV_LDAP_W
    411#define CERT_STORE_PROV_PKCS12 ((LPCSTR)17)
    412#define sz_CERT_STORE_PROV_MEMORY "Memory"
    413#define sz_CERT_STORE_PROV_FILENAME_W "File"
    414#define sz_CERT_STORE_PROV_FILENAME sz_CERT_STORE_PROV_FILENAME_W
    415#define sz_CERT_STORE_PROV_SYSTEM_W "System"
    416#define sz_CERT_STORE_PROV_SYSTEM sz_CERT_STORE_PROV_SYSTEM_W
    417#define sz_CERT_STORE_PROV_PKCS7 "PKCS7"
    418#define sz_CERT_STORE_PROV_PKCS12 "PKCS12"
    419#define sz_CERT_STORE_PROV_SERIALIZED "Serialized"
    420#define sz_CERT_STORE_PROV_COLLECTION "Collection"
    421#define sz_CERT_STORE_PROV_SYSTEM_REGISTRY_W "SystemRegistry"
    422#define sz_CERT_STORE_PROV_SYSTEM_REGISTRY sz_CERT_STORE_PROV_SYSTEM_REGISTRY_W
    423#define sz_CERT_STORE_PROV_PHYSICAL_W "Physical"
    424#define sz_CERT_STORE_PROV_PHYSICAL sz_CERT_STORE_PROV_PHYSICAL_W
    425#define sz_CERT_STORE_PROV_SMART_CARD_W "SmartCard"
    426#define sz_CERT_STORE_PROV_SMART_CARD sz_CERT_STORE_PROV_SMART_CARD_W
    427#define sz_CERT_STORE_PROV_LDAP_W "Ldap"
    428#define sz_CERT_STORE_PROV_LDAP sz_CERT_STORE_PROV_LDAP_W
    429
    430#define CERT_STORE_SIGNATURE_FLAG 0x00000001
    431#define CERT_STORE_TIME_VALIDITY_FLAG 0x00000002
    432#define CERT_STORE_REVOCATION_FLAG 0x00000004
    433#define CERT_STORE_NO_CRL_FLAG 0x00010000
    434#define CERT_STORE_NO_ISSUER_FLAG 0x00020000
    435#define CERT_STORE_BASE_CRL_FLAG 0x00000100
    436#define CERT_STORE_DELTA_CRL_FLAG 0x00000200
    437
    438#define CERT_STORE_NO_CRYPT_RELEASE_FLAG 0x00000001
    439#define CERT_STORE_SET_LOCALIZED_NAME_FLAG 0x00000002
    440#define CERT_STORE_DEFER_CLOSE_UNTIL_LAST_FREE_FLAG 0x00000004
    441#define CERT_STORE_DELETE_FLAG 0x00000010
    442#define CERT_STORE_UNSAFE_PHYSICAL_FLAG 0x00000020
    443#define CERT_STORE_SHARE_STORE_FLAG 0x00000040
    444#define CERT_STORE_SHARE_CONTEXT_FLAG 0x00000080
    445#define CERT_STORE_MANIFOLD_FLAG 0x00000100
    446#define CERT_STORE_ENUM_ARCHIVED_FLAG 0x00000200
    447#define CERT_STORE_UPDATE_KEYID_FLAG 0x00000400
    448#define CERT_STORE_BACKUP_RESTORE_FLAG 0x00000800
    449#define CERT_STORE_READONLY_FLAG 0x00008000
    450#define CERT_STORE_OPEN_EXISTING_FLAG 0x00004000
    451#define CERT_STORE_CREATE_NEW_FLAG 0x00002000
    452#define CERT_STORE_MAXIMUM_ALLOWED_FLAG 0x00001000
    453
    454#define CERT_SYSTEM_STORE_MASK 0xFFFF0000
    455#define CERT_SYSTEM_STORE_RELOCATE_FLAG 0x80000000
    456#define CERT_SYSTEM_STORE_UNPROTECTED_FLAG 0x40000000
    457#define CERT_SYSTEM_STORE_DEFER_READ_FLAG 0x20000000
    458#define CERT_SYSTEM_STORE_LOCATION_MASK 0x00FF0000
    459#define CERT_SYSTEM_STORE_LOCATION_SHIFT 16
    460#define CERT_SYSTEM_STORE_CURRENT_USER_ID 1
    461#define CERT_SYSTEM_STORE_LOCAL_MACHINE_ID 2
    462#define CERT_SYSTEM_STORE_CURRENT_SERVICE_ID 4
    463#define CERT_SYSTEM_STORE_SERVICES_ID 5
    464#define CERT_SYSTEM_STORE_USERS_ID 6
    465#define CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY_ID 7
    466#define CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY_ID 8
    467#define CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE_ID 9
    468
    469#define CERT_SYSTEM_STORE_CURRENT_USER \
    470	(CERT_SYSTEM_STORE_CURRENT_USER_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT)
    471#define CERT_SYSTEM_STORE_LOCAL_MACHINE \
    472	(CERT_SYSTEM_STORE_LOCAL_MACHINE_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT)
    473#define CERT_SYSTEM_STORE_CURRENT_SERVICE \
    474	(CERT_SYSTEM_STORE_CURRENT_SERVICE_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT)
    475#define CERT_SYSTEM_STORE_SERVICES \
    476	(CERT_SYSTEM_STORE_SERVICES_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT)
    477#define CERT_SYSTEM_STORE_USERS (CERT_SYSTEM_STORE_USERS_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT)
    478#define CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY \
    479	(CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT)
    480#define CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY \
    481	(CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT)
    482#define CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE \
    483	(CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT)
    484
    485WINPR_API HCERTSTORE CertOpenStore(LPCSTR lpszStoreProvider, DWORD dwMsgAndCertEncodingType,
    486                                   HCRYPTPROV_LEGACY hCryptProv, DWORD dwFlags, const void* pvPara);
    487
    488WINPR_API HCERTSTORE CertOpenSystemStoreW(HCRYPTPROV_LEGACY hProv, LPCWSTR szSubsystemProtocol);
    489WINPR_API HCERTSTORE CertOpenSystemStoreA(HCRYPTPROV_LEGACY hProv, LPCSTR szSubsystemProtocol);
    490
    491WINPR_API BOOL CertCloseStore(HCERTSTORE hCertStore, DWORD dwFlags);
    492
    493#ifdef UNICODE
    494#define CertOpenSystemStore CertOpenSystemStoreW
    495#else
    496#define CertOpenSystemStore CertOpenSystemStoreA
    497#endif
    498
    499#ifdef __cplusplus
    500extern "C"
    501{
    502#endif
    503
    504	WINPR_API PCCERT_CONTEXT CertFindCertificateInStore(HCERTSTORE hCertStore,
    505	                                                    DWORD dwCertEncodingType, DWORD dwFindFlags,
    506	                                                    DWORD dwFindType, const void* pvFindPara,
    507	                                                    PCCERT_CONTEXT pPrevCertContext);
    508
    509	WINPR_API PCCERT_CONTEXT CertEnumCertificatesInStore(HCERTSTORE hCertStore,
    510	                                                     PCCERT_CONTEXT pPrevCertContext);
    511
    512	WINPR_API DWORD CertGetNameStringW(PCCERT_CONTEXT pCertContext, DWORD dwType, DWORD dwFlags,
    513	                                   void* pvTypePara, LPWSTR pszNameString, DWORD cchNameString);
    514	WINPR_API DWORD CertGetNameStringA(PCCERT_CONTEXT pCertContext, DWORD dwType, DWORD dwFlags,
    515	                                   void* pvTypePara, LPSTR pszNameString, DWORD cchNameString);
    516
    517#ifdef __cplusplus
    518}
    519#endif
    520
    521#ifdef UNICODE
    522#define CertGetNameString CertGetNameStringW
    523#else
    524#define CertGetNameString CertGetNameStringA
    525#endif
    526
    527/**
    528 * Data Protection API (DPAPI)
    529 */
    530
    531#define CRYPTPROTECTMEMORY_BLOCK_SIZE 16
    532
    533#define CRYPTPROTECTMEMORY_SAME_PROCESS 0x00000000
    534#define CRYPTPROTECTMEMORY_CROSS_PROCESS 0x00000001
    535#define CRYPTPROTECTMEMORY_SAME_LOGON 0x00000002
    536
    537#define CRYPTPROTECT_PROMPT_ON_UNPROTECT 0x00000001
    538#define CRYPTPROTECT_PROMPT_ON_PROTECT 0x00000002
    539#define CRYPTPROTECT_PROMPT_RESERVED 0x00000004
    540#define CRYPTPROTECT_PROMPT_STRONG 0x00000008
    541#define CRYPTPROTECT_PROMPT_REQUIRE_STRONG 0x00000010
    542
    543#define CRYPTPROTECT_UI_FORBIDDEN 0x1
    544#define CRYPTPROTECT_LOCAL_MACHINE 0x4
    545#define CRYPTPROTECT_CRED_SYNC 0x8
    546#define CRYPTPROTECT_AUDIT 0x10
    547#define CRYPTPROTECT_NO_RECOVERY 0x20
    548#define CRYPTPROTECT_VERIFY_PROTECTION 0x40
    549#define CRYPTPROTECT_CRED_REGENERATE 0x80
    550
    551#define CRYPTPROTECT_FIRST_RESERVED_FLAGVAL 0x0FFFFFFF
    552#define CRYPTPROTECT_LAST_RESERVED_FLAGVAL 0xFFFFFFFF
    553
    554typedef struct
    555{
    556	DWORD cbSize;
    557	DWORD dwPromptFlags;
    558	HWND hwndApp;
    559	LPCWSTR szPrompt;
    560} CRYPTPROTECT_PROMPTSTRUCT, *PCRYPTPROTECT_PROMPTSTRUCT;
    561
    562#define CRYPTPROTECT_DEFAULT_PROVIDER                      \
    563	{                                                      \
    564		0xdf9d8cd0, 0x1501, 0x11d1,                        \
    565		{                                                  \
    566			0x8c, 0x7a, 0x00, 0xc0, 0x4f, 0xc2, 0x97, 0xeb \
    567		}                                                  \
    568	}
    569
    570#ifdef __cplusplus
    571extern "C"
    572{
    573#endif
    574
    575	WINPR_API BOOL CryptProtectMemory(LPVOID pData, DWORD cbData, DWORD dwFlags);
    576	WINPR_API BOOL CryptUnprotectMemory(LPVOID pData, DWORD cbData, DWORD dwFlags);
    577
    578	WINPR_API BOOL CryptProtectData(DATA_BLOB* pDataIn, LPCWSTR szDataDescr,
    579	                                DATA_BLOB* pOptionalEntropy, PVOID pvReserved,
    580	                                CRYPTPROTECT_PROMPTSTRUCT* pPromptStruct, DWORD dwFlags,
    581	                                DATA_BLOB* pDataOut);
    582	WINPR_API BOOL CryptUnprotectData(DATA_BLOB* pDataIn, LPWSTR* ppszDataDescr,
    583	                                  DATA_BLOB* pOptionalEntropy, PVOID pvReserved,
    584	                                  CRYPTPROTECT_PROMPTSTRUCT* pPromptStruct, DWORD dwFlags,
    585	                                  DATA_BLOB* pDataOut);
    586
    587#ifdef __cplusplus
    588}
    589#endif
    590
    591#define CRYPT_STRING_BASE64HEADER 0x00000000
    592#define CRYPT_STRING_BASE64 0x00000001
    593#define CRYPT_STRING_BINARY 0x00000002
    594#define CRYPT_STRING_BASE64REQUESTHEADER 0x00000003
    595#define CRYPT_STRING_HEX 0x00000004
    596#define CRYPT_STRING_HEXASCII 0x00000005
    597#define CRYPT_STRING_BASE64_ANY 0x00000006
    598#define CRYPT_STRING_ANY 0x00000007
    599#define CRYPT_STRING_HEX_ANY 0x00000008
    600#define CRYPT_STRING_BASE64X509CRLHEADER 0x00000009
    601#define CRYPT_STRING_HEXADDR 0x0000000A
    602#define CRYPT_STRING_HEXASCIIADDR 0x0000000B
    603#define CRYPT_STRING_HEXRAW 0x0000000C
    604
    605#define CRYPT_STRING_HASHDATA 0x10000000
    606#define CRYPT_STRING_STRICT 0x20000000
    607#define CRYPT_STRING_NOCRLF 0x40000000
    608#define CRYPT_STRING_NOCR 0x80000000
    609
    610WINPR_API BOOL CryptStringToBinaryW(LPCWSTR pszString, DWORD cchString, DWORD dwFlags,
    611                                    BYTE* pbBinary, DWORD* pcbBinary, DWORD* pdwSkip,
    612                                    DWORD* pdwFlags);
    613WINPR_API BOOL CryptStringToBinaryA(LPCSTR pszString, DWORD cchString, DWORD dwFlags,
    614                                    BYTE* pbBinary, DWORD* pcbBinary, DWORD* pdwSkip,
    615                                    DWORD* pdwFlags);
    616
    617WINPR_API BOOL CryptBinaryToStringW(CONST BYTE* pbBinary, DWORD cbBinary, DWORD dwFlags,
    618                                    LPWSTR pszString, DWORD* pcchString);
    619WINPR_API BOOL CryptBinaryToStringA(CONST BYTE* pbBinary, DWORD cbBinary, DWORD dwFlags,
    620                                    LPSTR pszString, DWORD* pcchString);
    621
    622#ifdef UNICODE
    623#define CryptStringToBinary CryptStringToBinaryW
    624#define CryptBinaryToString CryptBinaryToStringW
    625#else
    626#define CryptStringToBinary CryptStringToBinaryA
    627#define CryptBinaryToString CryptBinaryToStringA
    628#endif
    629
    630#endif
    631
    632#ifndef ALG_SID_ECSDA
    633#define ALG_SID_ECDSA 3
    634#define CALG_ECDSA (ALG_CLASS_SIGNATURE | ALG_TYPE_DSS | ALG_SID_ECDSA)
    635#endif
    636
    637#endif /* WINPR_WINCRYPT_H */