Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

376 lines
8.4 KiB

  1. ///////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2000 Gemplus Canada Inc.
  4. //
  5. // Project:
  6. // Kenny (GPK CSP)
  7. //
  8. // Authors:
  9. // Thierry Tremblay
  10. // Francois Paradis
  11. //
  12. // Compiler:
  13. // Microsoft Visual C++ 6.0 - SP3
  14. // Platform SDK - January 2000
  15. //
  16. ///////////////////////////////////////////////////////////////////////////////////////////
  17. #ifndef KENNY_GPKCSP_H
  18. #define KENNY_GPKCSP_H
  19. #if defined(MS_BUILD) || defined(SHELL_TS)
  20. // Microsoft: Target Win2000
  21. #ifndef _WIN32_WINNT
  22. #define _WIN32_WINNT 0x0500
  23. #endif
  24. #else
  25. // Gemplus: Target Win95 / WINNT 4.0
  26. #ifndef _WIN32_WINNT
  27. #define _WIN32_WINNT 0x0400
  28. #endif
  29. #ifndef WINVER
  30. #define WINVER 0x400
  31. #endif
  32. #endif
  33. #ifndef WIN32_LEAN_AND_MEAN
  34. #define WIN32_LEAN_AND_MEAN
  35. #endif
  36. #include <windows.h>
  37. #include <winscard.h>
  38. #include <wincrypt.h>
  39. #include <cspdk.h>
  40. #include "gpkgui.h"
  41. #if !defined(CRYPT_IMPL_REMOVABLE) || !defined(NTE_SILENT_CONTEXT)
  42. #pragma message ("**************************************************************")
  43. #pragma message ("* *")
  44. #pragma message ("* You need to use the latest available Windows Platform SDK *")
  45. #pragma message ("* in order to compile this CSP. *")
  46. #pragma message ("* *")
  47. #pragma message ("* Make sure the include and library paths of the SDK are *")
  48. #pragma message ("* searched first (before your MSDEV paths). *")
  49. #pragma message ("* *")
  50. #pragma message ("**************************************************************")
  51. #error
  52. #endif
  53. #ifdef __cplusplus
  54. extern "C" {
  55. #endif
  56. ///////////////////////////////////////////////////////////////////////////////////////////
  57. //
  58. // Definitions
  59. //
  60. ///////////////////////////////////////////////////////////////////////////////////////////
  61. #ifdef _DEBUG
  62. extern void DBG_PRINT( const PTCHAR szFormat, ... );
  63. extern DWORD dw1, dw2;
  64. #define DBG_TIME1 dw1 = GetTickCount();
  65. #define DBG_TIME2 dw2 = GetTickCount();
  66. #define DBG_DELTA dw2 - dw1
  67. #else
  68. __inline void NeverCalled666KillKenny( const PTCHAR szFormat, ... ) {}
  69. #define DBG_PRINT if (1) {} else NeverCalled666KillKenny
  70. #define DBG_TIME1
  71. #define DBG_TIME2
  72. #define DBG_DELTA 0
  73. #endif
  74. #define RETURN(r,s) { EndWait(); SetLastError(s); return(r); }
  75. #ifdef __cplusplus
  76. const DWORD GPP_SERIAL_NUMBER = 0xFFFF0001;
  77. const DWORD GPP_SESSION_RANDOM = 0xFFFF0002;
  78. const DWORD GPP_IMPORT_MECHANISM = 0xFFFF0003;
  79. const DWORD GPP_CHANGE_PIN = 0xFFFF0004;
  80. const DWORD GCRYPT_IMPORT_SECURE = 0xFFFF8001;
  81. const DWORD GCRYPT_IMPORT_PLAIN = 0xFFFF8002;
  82. #endif
  83. typedef struct TAG_Prov_Context
  84. {
  85. HCRYPTPROV hProv;
  86. SCARDHANDLE hCard;
  87. DWORD Flags;
  88. DWORD Slot;
  89. BOOL isContNameNullBlank; // [mv - 15/05/98]
  90. BOOL bCardTransactionOpened; // [FP] control the begin/end transaction when loading a RSA private key into the GPK card
  91. char szContainer[128];
  92. BYTE keysetID; // If Legacy GPK4000, we use 0xFF as the keyset
  93. HCRYPTKEY hRSASign;
  94. HCRYPTKEY hRSAKEK;
  95. BOOL bGPK8000; // Card is a GPK8000 ?
  96. BOOL bGPK_ISO_DF; // Card has ISO 7816-5 compliant DF name
  97. BOOL bLegacyKeyset; // Use legacy keyset name in IADF
  98. int dataUnitSize;
  99. BOOL bDisconnected;
  100. } Prov_Context;
  101. ///////////////////////////////////////////////////////////////////////////////////////////
  102. //
  103. // Globals
  104. //
  105. ///////////////////////////////////////////////////////////////////////////////////////////
  106. extern BYTE KeyLenFile[MAX_REAL_KEY];
  107. extern BYTE KeyLenChoice;
  108. extern DWORD ContainerStatus;
  109. extern TCHAR szKeyType[20];
  110. extern TCHAR s1[MAX_STRING], s2[MAX_STRING], s3[MAX_STRING];
  111. extern DWORD CspFlags;
  112. ///////////////////////////////////////////////////////////////////////////////////////////
  113. //
  114. // Wrappers for the CSP API
  115. //
  116. ///////////////////////////////////////////////////////////////////////////////////////////
  117. extern BOOL WINAPI
  118. MyCPAcquireContext(
  119. OUT HCRYPTPROV *phProv,
  120. IN LPCSTR szContainer,
  121. IN DWORD dwFlags,
  122. IN PVTableProvStruc pVTable);
  123. extern BOOL WINAPI
  124. MyCPAcquireContextW(
  125. OUT HCRYPTPROV *phProv,
  126. IN LPCWSTR szContainer,
  127. IN DWORD dwFlags,
  128. IN PVTableProvStrucW pVTable);
  129. extern BOOL WINAPI
  130. MyCPReleaseContext(
  131. IN HCRYPTPROV hProv,
  132. IN DWORD dwFlags);
  133. extern BOOL WINAPI
  134. MyCPGenKey(
  135. IN HCRYPTPROV hProv,
  136. IN ALG_ID Algid,
  137. IN DWORD dwFlags,
  138. OUT HCRYPTKEY *phKey);
  139. extern BOOL WINAPI
  140. MyCPDeriveKey(
  141. IN HCRYPTPROV hProv,
  142. IN ALG_ID Algid,
  143. IN HCRYPTHASH hHash,
  144. IN DWORD dwFlags,
  145. OUT HCRYPTKEY *phKey);
  146. extern BOOL WINAPI
  147. MyCPDestroyKey(
  148. IN HCRYPTPROV hProv,
  149. IN HCRYPTKEY hKey);
  150. extern BOOL WINAPI
  151. MyCPSetKeyParam(
  152. IN HCRYPTPROV hProv,
  153. IN HCRYPTKEY hKey,
  154. IN DWORD dwParam,
  155. IN CONST BYTE *pbData,
  156. IN DWORD dwFlags);
  157. extern BOOL WINAPI
  158. MyCPGetKeyParam(
  159. IN HCRYPTPROV hProv,
  160. IN HCRYPTKEY hKey,
  161. IN DWORD dwParam,
  162. OUT LPBYTE pbData,
  163. IN OUT LPDWORD pcbDataLen,
  164. IN DWORD dwFlags);
  165. extern BOOL WINAPI
  166. MyCPSetProvParam(
  167. IN HCRYPTPROV hProv,
  168. IN DWORD dwParam,
  169. IN CONST BYTE *pbData,
  170. IN DWORD dwFlags);
  171. extern BOOL WINAPI
  172. MyCPGetProvParam(
  173. IN HCRYPTPROV hProv,
  174. IN DWORD dwParam,
  175. OUT LPBYTE pbData,
  176. IN OUT LPDWORD pcbDataLen,
  177. IN DWORD dwFlags);
  178. extern BOOL WINAPI
  179. MyCPSetHashParam(
  180. IN HCRYPTPROV hProv,
  181. IN HCRYPTHASH hHash,
  182. IN DWORD dwParam,
  183. IN CONST BYTE *pbData,
  184. IN DWORD dwFlags);
  185. extern BOOL WINAPI
  186. MyCPGetHashParam(
  187. IN HCRYPTPROV hProv,
  188. IN HCRYPTHASH hHash,
  189. IN DWORD dwParam,
  190. OUT LPBYTE pbData,
  191. IN OUT LPDWORD pcbDataLen,
  192. IN DWORD dwFlags);
  193. extern BOOL WINAPI
  194. MyCPExportKey(
  195. IN HCRYPTPROV hProv,
  196. IN HCRYPTKEY hKey,
  197. IN HCRYPTKEY hPubKey,
  198. IN DWORD dwBlobType,
  199. IN DWORD dwFlags,
  200. OUT LPBYTE pbData,
  201. IN OUT LPDWORD pcbDataLen);
  202. extern BOOL WINAPI
  203. MyCPImportKey(
  204. IN HCRYPTPROV hProv,
  205. IN CONST BYTE *pbData,
  206. IN DWORD cbDataLen,
  207. IN HCRYPTKEY hPubKey,
  208. IN DWORD dwFlags,
  209. OUT HCRYPTKEY *phKey);
  210. extern BOOL WINAPI
  211. MyCPEncrypt(
  212. IN HCRYPTPROV hProv,
  213. IN HCRYPTKEY hKey,
  214. IN HCRYPTHASH hHash,
  215. IN BOOL fFinal,
  216. IN DWORD dwFlags,
  217. IN OUT LPBYTE pbData,
  218. IN OUT LPDWORD pcbDataLen,
  219. IN DWORD cbBufLen);
  220. extern BOOL WINAPI
  221. MyCPDecrypt(
  222. IN HCRYPTPROV hProv,
  223. IN HCRYPTKEY hKey,
  224. IN HCRYPTHASH hHash,
  225. IN BOOL fFinal,
  226. IN DWORD dwFlags,
  227. IN OUT LPBYTE pbData,
  228. IN OUT LPDWORD pcbDataLen);
  229. extern BOOL WINAPI
  230. MyCPCreateHash(
  231. IN HCRYPTPROV hProv,
  232. IN ALG_ID Algid,
  233. IN HCRYPTKEY hKey,
  234. IN DWORD dwFlags,
  235. OUT HCRYPTHASH *phHash);
  236. extern BOOL WINAPI
  237. MyCPHashData(
  238. IN HCRYPTPROV hProv,
  239. IN HCRYPTHASH hHash,
  240. IN CONST BYTE *pbData,
  241. IN DWORD cbDataLen,
  242. IN DWORD dwFlags);
  243. extern BOOL WINAPI
  244. MyCPHashSessionKey(
  245. IN HCRYPTPROV hProv,
  246. IN HCRYPTHASH hHash,
  247. IN HCRYPTKEY hKey,
  248. IN DWORD dwFlags);
  249. extern BOOL WINAPI
  250. MyCPSignHash(
  251. IN HCRYPTPROV hProv,
  252. IN HCRYPTHASH hHash,
  253. IN DWORD dwKeySpec,
  254. IN LPCWSTR szDescription,
  255. IN DWORD dwFlags,
  256. OUT LPBYTE pbSignature,
  257. IN OUT LPDWORD pcbSigLen);
  258. extern BOOL WINAPI
  259. MyCPDestroyHash(
  260. IN HCRYPTPROV hProv,
  261. IN HCRYPTHASH hHash);
  262. extern BOOL WINAPI
  263. MyCPVerifySignature(
  264. IN HCRYPTPROV hProv,
  265. IN HCRYPTHASH hHash,
  266. IN CONST BYTE *pbSignature,
  267. IN DWORD cbSigLen,
  268. IN HCRYPTKEY hPubKey,
  269. IN LPCWSTR szDescription,
  270. IN DWORD dwFlags);
  271. extern BOOL WINAPI
  272. MyCPGenRandom(
  273. IN HCRYPTPROV hProv,
  274. IN DWORD cbLen,
  275. OUT LPBYTE pbBuffer);
  276. extern BOOL WINAPI
  277. MyCPGetUserKey(
  278. IN HCRYPTPROV hProv,
  279. IN DWORD dwKeySpec,
  280. OUT HCRYPTKEY *phUserKey);
  281. extern BOOL WINAPI
  282. MyCPDuplicateHash(
  283. IN HCRYPTPROV hProv,
  284. IN HCRYPTHASH hHash,
  285. IN LPDWORD pdwReserved,
  286. IN DWORD dwFlags,
  287. OUT HCRYPTHASH *phHash);
  288. extern BOOL WINAPI
  289. MyCPDuplicateKey(
  290. IN HCRYPTPROV hProv,
  291. IN HCRYPTKEY hKey,
  292. IN LPDWORD pdwReserved,
  293. IN DWORD dwFlags,
  294. OUT HCRYPTKEY *phKey);
  295. #ifdef __cplusplus
  296. }
  297. #endif
  298. #endif