Home | History | Annotate | Download | only in include
      1 /**
      2  * This file has no copyright assigned and is placed in the Public Domain.
      3  * This file is part of the mingw-w64 runtime package.
      4  * No warranty is given; refer to the file DISCLAIMER.PD within this package.
      5  */
      6 
      7 #ifndef _INC_CARDMOD
      8 #define _INC_CARDMOD
      9 #include <wincrypt.h>
     10 
     11 #define CARD_BUFFER_SIZE_ONLY 0x20000000
     12 #define CARD_PADDING_INFO_PRESENT 0x40000000
     13 
     14 #define CARD_PADDING_NONE  0
     15 #define CARD_PADDING_PKCS1 1
     16 #define CARD_PADDING_PSS   4
     17 
     18 #define CARD_CREATE_CONTAINER_KEY_GEN 1
     19 #define CARD_CREATE_CONTAINER_KEY_IMPORT 2
     20 
     21 #define AT_KEYEXCHANGE 1
     22 #define AT_SIGNATURE   2
     23 #define AT_ECDSA_P256  3
     24 #define AT_ECDSA_P384  4
     25 #define AT_ECDSA_P521  5
     26 #define AT_ECDHE_P256  6
     27 #define AT_ECDHE_P384  7
     28 #define AT_ECDHE_P521  8
     29 
     30 #ifdef __cplusplus
     31 extern "C" {
     32 #endif
     33 
     34 #define InvalidAc 0
     35 
     36 typedef enum _CARD_DIRECTORY_ACCESS_CONDITION {
     37   UserCreateDeleteDirAc    = 1,
     38   AdminCreateDeleteDirAc   = 2
     39 } CARD_DIRECTORY_ACCESS_CONDITION;
     40 
     41 typedef enum _CARD_FILE_ACCESS_CONDITION {
     42   EveryoneReadUserWriteAc    = 1,
     43   UserWriteExecuteAc         = 2,
     44   EveryoneReadAdminWriteAc   = 3,
     45   UnknownAc                  = 4
     46 } CARD_FILE_ACCESS_CONDITION;
     47 
     48 typedef struct _CARD_SIGNING_INFO {
     49   DWORD  dwVersion;
     50   BYTE   bContainerIndex;
     51   DWORD  dwKeySpec;
     52   DWORD  dwSigningFlags;
     53   ALG_ID aiHashAlg;
     54   PBYTE  pbData;
     55   DWORD  cbData;
     56   PBYTE  pbSignedData;
     57   DWORD  cbSignedData;
     58   LPVOID pPaddingInfo;
     59   DWORD  dwPaddingType;
     60 } CARD_SIGNING_INFO, *PCARD_SIGNING_INFO;
     61 
     62 typedef struct _CARD_CAPABILITIES {
     63   DWORD   dwVersion;
     64   WINBOOL fCertificateCompression;
     65   WINBOOL fKeyGen;
     66 } CARD_CAPABILITIES, *PCARD_CAPABILITIES;
     67 
     68 typedef struct _CONTAINER_INFO {
     69   DWORD dwVersion;
     70   DWORD dwReserved;
     71   DWORD cbSigPublicKey;
     72   PBYTE pbSigPublicKey;
     73   DWORD cbKeyExPublicKey;
     74   PBYTE pbKeyExPublicKey;
     75 } CONTAINER_INFO, *PCONTAINER_INFO;
     76 
     77 typedef LPVOID ( WINAPI *PFN_CSP_ALLOC )(SIZE_T Size);
     78 typedef LPVOID ( WINAPI *PFN_CSP_REALLOC )(LPVOID Address,SIZE_T Size);
     79 typedef VOID ( WINAPI *PFN_CSP_FREE )(LPVOID Address);
     80 typedef DWORD ( WINAPI *PFN_CSP_CACHE_ADD_FILE )(
     81   PVOID pvCacheContext,
     82   LPWSTR wszTag,
     83   DWORD dwFlags,
     84   PBYTE pbData,
     85   DWORD cbData
     86 );
     87 
     88 typedef DWORD ( WINAPI *PFN_CSP_CACHE_LOOKUP_FILE )(
     89   PVOID pvCacheContext,
     90   LPWSTR wszTag,
     91   DWORD dwFlags,
     92   PBYTE *ppbData,
     93   PDWORD pcbData
     94 );
     95 
     96 typedef DWORD ( WINAPI *PFN_CSP_CACHE_DELETE_FILE )(
     97   PVOID pvCacheContext,
     98   LPWSTR wszTag,
     99   DWORD dwFlags
    100 );
    101 
    102 typedef DWORD ( WINAPI *PFN_CSP_PAD_DATA )(
    103   PCARD_SIGNING_INFO pSigningInfo,
    104   DWORD cbMaxWidth,
    105   DWORD *pcbPaddedBuffer,
    106   PBYTE *ppbPaddedBuffer
    107 );
    108 
    109 typedef struct _CARD_DERIVE_KEY {
    110   DWORD   dwVersion;
    111   DWORD   dwFlags;
    112   LPCWSTR pwszKDF;
    113   BYTE    bSecretAgreementIndex;
    114   PVOID   pParameterList;
    115   PUCHAR  pbDerivedKey;
    116   DWORD   cbDerivedKey;
    117 } CARD_DERIVE_KEY, *PCARD_DERIVE_KEY;
    118 
    119 typedef struct _CARD_FILE_INFO {
    120   DWORD                      dwVersion;
    121   DWORD                      cbFileSize;
    122   CARD_FILE_ACCESS_CONDITION AccessCondition;
    123 } CARD_FILE_INFO, *PCARD_FILE_INFO;
    124 
    125 typedef struct _CARD_FREE_SPACE_INFO {
    126   DWORD dwVersion;
    127   DWORD dwBytesAvailable;
    128   DWORD dwKeyContainersAvailable;
    129   DWORD dwMaxKeyContainers;
    130 } CARD_FREE_SPACE_INFO, *PCARD_FREE_SPACE_INFO;
    131 
    132 typedef struct _CARD_RSA_DECRYPT_INFO {
    133   DWORD dwVersion;
    134   BYTE  bContainerIndex;
    135   DWORD dwKeySpec;
    136   PBYTE pbData;
    137   DWORD cbData;
    138 } CARD_RSA_DECRYPT_INFO, *PCARD_RSA_DECRYPT_INFO;
    139 
    140 typedef struct _CARD_DH_AGREEMENT_INFO {
    141   DWORD dwVersion;
    142   BYTE  bContainerIndex;
    143   DWORD dwFlags;
    144   DWORD dwPublicKey;
    145   PBYTE pbPublicKey;
    146   PBYTE pbReserved;
    147   DWORD cbReserved;
    148   BYTE  bSecretAgreementIndex;
    149 } CARD_DH_AGREEMENT_INFO, *PCARD_DH_AGREEMENT_INFO;
    150 
    151 typedef struct _CARD_KEY_SIZES {
    152   DWORD dwVersion;
    153   DWORD dwMinimumBitlen;
    154   DWORD dwMaximumBitlen;
    155   DWORD dwIncrementalBitlen;
    156 } CARD_KEY_SIZES, *PCARD_KEY_SIZES;
    157 
    158 typedef struct _CARD_DATA *PCARD_DATA;
    159 
    160 typedef DWORD (WINAPI *PFN_CARD_DELETE_CONTEXT)(
    161   PCARD_DATA pCardData
    162 );
    163 
    164 typedef DWORD (WINAPI *PFN_CARD_QUERY_CAPABILITIES)(
    165   PCARD_DATA pCardData,
    166   PCARD_CAPABILITIES pCardCapabilities
    167 );
    168 
    169 typedef DWORD (WINAPI *PFN_CARD_DELETE_CONTAINER)(
    170   PCARD_DATA pCardData,
    171   BYTE bContainerIndex,
    172   DWORD dwReserved
    173 );
    174 
    175 typedef DWORD (WINAPI *PFN_CARD_CREATE_CONTAINER)(
    176   PCARD_DATA pCardData,
    177   BYTE bContainerIndex,
    178   DWORD dwFlags,
    179   DWORD dwKeySpec,
    180   DWORD dwKeySize,
    181   PBYTE pbKeyData
    182 );
    183 
    184 typedef DWORD (WINAPI *PFN_CARD_GET_CONTAINER_INFO)(
    185   PCARD_DATA pCardData,
    186   BYTE bContainerIndex,
    187   DWORD dwFlags,
    188   PCONTAINER_INFO pContainerInfo
    189 );
    190 
    191 typedef DWORD (WINAPI *PFN_CARD_AUTHENTICATE_PIN)(
    192   PCARD_DATA pCardData,
    193   LPWSTR pwszUserId,
    194   PBYTE pbPin,
    195   DWORD cbPin,
    196   PDWORD pcAttemptsRemaining
    197 );
    198 
    199 typedef DWORD (WINAPI *PFN_CARD_GET_CHALLENGE)(
    200   PCARD_DATA pCardData,
    201   PBYTE *ppbChallengeData,
    202   PDWORD pcbChallengeData
    203 );
    204 
    205 typedef DWORD (WINAPI *PFN_CARD_AUTHENTICATE_CHALLENGE)(
    206   PCARD_DATA pCardData,
    207   PBYTE pbResponseData,
    208   DWORD cbResponseData,
    209   PDWORD pcAttemptsRemaining
    210 );
    211 
    212 typedef DWORD (WINAPI *PFN_CARD_UNBLOCK_PIN)(
    213   PCARD_DATA pCardData,
    214   LPWSTR pwszUserId,
    215   PBYTE pbAuthenticationData,
    216   DWORD cbAuthenticationData,
    217   PBYTE pbNewPinData,
    218   DWORD cbNewPinData,
    219   DWORD cRetryCount,
    220   DWORD dwFlags
    221 );
    222 
    223 typedef DWORD (WINAPI *PFN_CARD_CHANGE_AUTHENTICATOR)(
    224   PCARD_DATA pCardData,
    225   LPWSTR pwszUserId,
    226   PBYTE pbCurrentAuthenticator,
    227   DWORD cbCurrentAuthenticator,
    228   PBYTE pbNewAuthenticator,
    229   DWORD cbNewAuthenticator,
    230   DWORD cRetryCount,
    231   DWORD dwFlags,
    232   PDWORD pcAttemptsRemaining
    233 );
    234 
    235 typedef DWORD (WINAPI *PFN_CARD_DEAUTHENTICATE)(
    236   PCARD_DATA pCardData,
    237   LPWSTR pwszUserId,
    238   DWORD dwFlags
    239 );
    240 
    241 typedef DWORD (WINAPI *PFN_CARD_CREATE_DIRECTORY)(
    242   PCARD_DATA pCardData,
    243   LPSTR pszDirectory,
    244   CARD_DIRECTORY_ACCESS_CONDITION AccessCondition
    245 );
    246 
    247 typedef DWORD (WINAPI *PFN_CARD_DELETE_DIRECTORY)(
    248   PCARD_DATA pCardData,
    249   LPSTR pszDirectoryName
    250 );
    251 
    252 typedef DWORD (WINAPI *PFN_CARD_CREATE_FILE)(
    253   PCARD_DATA pCardData,
    254   LPSTR pszDirectoryName,
    255   LPSTR pszFileName,
    256   DWORD cbInitialCreationSize,
    257   CARD_FILE_ACCESS_CONDITION AccessCondition
    258 );
    259 
    260 typedef DWORD (WINAPI *PFN_CARD_READ_FILE)(
    261   PCARD_DATA pCardData,
    262   LPSTR pszDirectoryName,
    263   LPSTR pszFileName,
    264   DWORD dwFlags,
    265   PBYTE *ppbData,
    266   PDWORD pcbData
    267 );
    268 
    269 typedef DWORD (WINAPI *PFN_CARD_WRITE_FILE)(
    270   PCARD_DATA pCardData,
    271   LPSTR pszDirectoryName,
    272   LPSTR pszFileName,
    273   DWORD dwFlags,
    274   PBYTE pbData,
    275   DWORD cbData
    276 );
    277 
    278 typedef DWORD (WINAPI *PFN_CARD_DELETE_FILE)(
    279   PCARD_DATA pCardData,
    280   LPSTR pszDirectoryName,
    281   LPSTR pszFileName,
    282   DWORD dwFlags
    283 );
    284 
    285 typedef DWORD (WINAPI *PFN_CARD_ENUM_FILES)(
    286   PCARD_DATA pCardData,
    287   LPSTR pszDirectoryName,
    288   LPSTR *pmszFileNames,
    289   LPDWORD pdwcbFileName,
    290   DWORD dwFlags
    291 );
    292 
    293 typedef DWORD (WINAPI *PFN_CARD_GET_FILE_INFO)(
    294   PCARD_DATA pCardData,
    295   LPSTR pszDirectoryName,
    296   LPSTR pszFileName,
    297   PCARD_FILE_INFO pCardFileInfo
    298 );
    299 
    300 typedef DWORD (WINAPI *PFN_CARD_QUERY_FREE_SPACE)(
    301   PCARD_DATA pCardData,
    302   DWORD dwFlags,
    303   PCARD_FREE_SPACE_INFO pCardFreeSpaceInfo
    304 );
    305 
    306 typedef DWORD (WINAPI *PFN_CARD_QUERY_KEY_SIZES)(
    307   PCARD_DATA pCardData,
    308   DWORD dwKeySpec,
    309   DWORD dwFlags,
    310   PCARD_KEY_SIZES pKeySizes
    311 );
    312 
    313 typedef DWORD (WINAPI *PFN_CARD_SIGN_DATA)(
    314   PCARD_DATA pCardData,
    315   PCARD_SIGNING_INFO pInfo
    316 );
    317 
    318 typedef DWORD (WINAPI *PFN_CARD_RSA_DECRYPT)(
    319   PCARD_DATA pCardData,
    320   PCARD_RSA_DECRYPT_INFO pInfo
    321 );
    322 
    323 typedef DWORD (WINAPI *PFN_CARD_CONSTRUCT_DH_AGREEMENT)(
    324   PCARD_DATA pCardData,
    325   PCARD_DH_AGREEMENT_INFO pAgreementInfo
    326 );
    327 
    328 #if (_WIN32_WINNT >= 0x0600)
    329 typedef DWORD (WINAPI *PFN_CARD_DERIVE_KEY)(
    330   PCARD_DATA pCardData,
    331   PCARD_DERIVE_KEY pAgreementInfo
    332 );
    333 
    334 typedef DWORD (WINAPI *PFN_CARD_DESTROY_DH_AGREEMENT)(
    335   PCARD_DATA pCardData,
    336   BYTE bSecretAgreementIndex,
    337   DWORD dwFlags
    338 );
    339 
    340 typedef DWORD (WINAPI *PFN_CSP_GET_DH_AGREEMENT)(
    341   PCARD_DATA pCardData,
    342   PVOID hSecretAgreement,
    343   BYTE *pbSecretAgreementIndex,
    344   DWORD dwFlags
    345 );
    346 
    347 #else
    348 typedef LPVOID PFN_CARD_DERIVE_KEY;
    349 typedef LPVOID PFN_CARD_DESTROY_DH_AGREEMENT;
    350 typedef LPVOID PFN_CSP_GET_DH_AGREEMENT;
    351 #endif /*(_WIN32_WINNT >= 0x0600)*/
    352 
    353 typedef struct _CARD_DATA {
    354   DWORD                           dwVersion;
    355   PBYTE                           pbAtr;
    356   DWORD                           cbAtr;
    357   LPWSTR                          pwszCardName;
    358   PFN_CSP_ALLOC                   pfnCspAlloc;
    359   PFN_CSP_REALLOC                 pfnCspReAlloc;
    360   PFN_CSP_FREE                    pfnCspFree;
    361   PFN_CSP_CACHE_ADD_FILE          pfnCspCacheAddFile;
    362   PFN_CSP_CACHE_LOOKUP_FILE       pfnCspCacheLookupFile;
    363   PFN_CSP_CACHE_DELETE_FILE       pfnCspCacheDeleteFile;
    364   PVOID                           pvCacheContext;
    365   PFN_CSP_PAD_DATA                pfnCspPadData;
    366   SCARDCONTEXT                    hSCardCtx;
    367   SCARDHANDLE                     hScard;
    368   PVOID                           pvVendorSpecific;
    369   PFN_CARD_DELETE_CONTEXT         pfnCardDeleteContext;
    370   PFN_CARD_QUERY_CAPABILITIES     pfnCardQueryCapabilities;
    371   PFN_CARD_DELETE_CONTAINER       pfnCardDeleteContainer;
    372   PFN_CARD_CREATE_CONTAINER       pfnCardCreateContainer;
    373   PFN_CARD_GET_CONTAINER_INFO     pfnCardGetContainerInfo;
    374   PFN_CARD_AUTHENTICATE_PIN       pfnCardAuthenticatePin;
    375   PFN_CARD_GET_CHALLENGE          pfnCardGetChallenge;
    376   PFN_CARD_AUTHENTICATE_CHALLENGE pfnCardAuthenticateChallenge;
    377   PFN_CARD_UNBLOCK_PIN            pfnCardUnblockPin;
    378   PFN_CARD_CHANGE_AUTHENTICATOR   pfnCardChangeAuthenticator;
    379   PFN_CARD_DEAUTHENTICATE         pfnCardDeauthenticate;
    380   PFN_CARD_CREATE_DIRECTORY       pfnCardCreateDirectory;
    381   PFN_CARD_DELETE_DIRECTORY       pfnCardDeleteDirectory;
    382   LPVOID                          pvUnused3;
    383   LPVOID                          pvUnused4;
    384   PFN_CARD_CREATE_FILE            pfnCardCreateFile;
    385   PFN_CARD_READ_FILE              pfnCardReadFile;
    386   PFN_CARD_WRITE_FILE             pfnCardWriteFile;
    387   PFN_CARD_DELETE_FILE            pfnCardDeleteFile;
    388   PFN_CARD_ENUM_FILES             pfnCardEnumFiles;
    389   PFN_CARD_GET_FILE_INFO          pfnCardGetFileInfo;
    390   PFN_CARD_QUERY_FREE_SPACE       pfnCardQueryFreeSpace;
    391   PFN_CARD_QUERY_KEY_SIZES        pfnCardQueryKeySizes;
    392   PFN_CARD_SIGN_DATA              pfnCardSignData;
    393   PFN_CARD_RSA_DECRYPT            pfnCardRSADecrypt;
    394   PFN_CARD_CONSTRUCT_DH_AGREEMENT pfnCardConstructDHAgreement;
    395   PFN_CARD_DERIVE_KEY             pfnCardDeriveKey;
    396   PFN_CARD_DESTROY_DH_AGREEMENT   pfnCardDestroyDHAgreement;
    397   PFN_CSP_GET_DH_AGREEMENT        pfnCspGetDHAgreement;
    398 } CARD_DATA, *PCARD_DATA;
    399 
    400 DWORD WINAPI CardAcquireContext(
    401   PCARD_DATA pCardData,
    402   DWORD dwFlags
    403 );
    404 
    405 DWORD WINAPI CardDeleteContainer(
    406   PCARD_DATA pCardData,
    407   BYTE bContainerIndex,
    408   DWORD dwReserved
    409 );
    410 
    411 #ifdef __cplusplus
    412 }
    413 #endif
    414 #endif /*_INC_CARDMOD*/
    415