Leaked source code of windows server 2003
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.

380 lines
8.9 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. // default container name when creating a key set without container name
  62. #define CSP_DEFAULTKEYSETNAME "Gemplus GemSAFE Card CSP Default Container"
  63. #ifdef _DEBUG
  64. extern void DBG_PRINT( const PTCHAR szFormat, ... );
  65. extern DWORD dw1, dw2;
  66. #define DBG_TIME1 dw1 = GetTickCount();
  67. #define DBG_TIME2 dw2 = GetTickCount();
  68. #define DBG_DELTA dw2 - dw1
  69. #else
  70. __inline void NeverCalled666KillKenny( const PTCHAR szFormat, ... ) {}
  71. #define DBG_PRINT if (1) {} else NeverCalled666KillKenny
  72. #define DBG_TIME1
  73. #define DBG_TIME2
  74. #define DBG_DELTA 0
  75. #endif
  76. #define RETURN(r,s) { EndWait(); SetLastError(s); return(r); }
  77. #ifdef __cplusplus
  78. const DWORD GPP_SERIAL_NUMBER = 0xFFFF0001;
  79. const DWORD GPP_SESSION_RANDOM = 0xFFFF0002;
  80. const DWORD GPP_IMPORT_MECHANISM = 0xFFFF0003;
  81. const DWORD GPP_CHANGE_PIN = 0xFFFF0004;
  82. const DWORD GCRYPT_IMPORT_SECURE = 0xFFFF8001;
  83. const DWORD GCRYPT_IMPORT_PLAIN = 0xFFFF8002;
  84. #endif
  85. typedef struct TAG_Prov_Context
  86. {
  87. HCRYPTPROV hProv;
  88. SCARDHANDLE hCard;
  89. DWORD Flags;
  90. DWORD Slot;
  91. BOOL isContNameNullBlank; // [mv - 15/05/98]
  92. BOOL bCardTransactionOpened; // [FP] control the begin/end transaction when loading a RSA private key into the GPK card
  93. char szContainer[128];
  94. BYTE keysetID; // If Legacy GPK4000, we use 0xFF as the keyset
  95. HCRYPTKEY hRSASign;
  96. HCRYPTKEY hRSAKEK;
  97. BOOL bGPK8000; // Card is a GPK8000 ?
  98. BOOL bGPK_ISO_DF; // Card has ISO 7816-5 compliant DF name
  99. BOOL bLegacyKeyset; // Use legacy keyset name in IADF
  100. int dataUnitSize;
  101. BOOL bDisconnected;
  102. } Prov_Context;
  103. ///////////////////////////////////////////////////////////////////////////////////////////
  104. //
  105. // Globals
  106. //
  107. ///////////////////////////////////////////////////////////////////////////////////////////
  108. extern BYTE KeyLenFile[MAX_REAL_KEY];
  109. extern BYTE KeyLenChoice;
  110. extern DWORD ContainerStatus;
  111. extern TCHAR szKeyType[20];
  112. extern TCHAR s1[MAX_STRING], s2[MAX_STRING], s3[MAX_STRING];
  113. extern DWORD CspFlags;
  114. ///////////////////////////////////////////////////////////////////////////////////////////
  115. //
  116. // Wrappers for the CSP API
  117. //
  118. ///////////////////////////////////////////////////////////////////////////////////////////
  119. extern BOOL WINAPI
  120. MyCPAcquireContext(
  121. OUT HCRYPTPROV *phProv,
  122. IN LPCSTR szContainer,
  123. IN DWORD dwFlags,
  124. IN PVTableProvStruc pVTable);
  125. extern BOOL WINAPI
  126. MyCPAcquireContextW(
  127. OUT HCRYPTPROV *phProv,
  128. IN LPCWSTR szContainer,
  129. IN DWORD dwFlags,
  130. IN PVTableProvStrucW pVTable);
  131. extern BOOL WINAPI
  132. MyCPReleaseContext(
  133. IN HCRYPTPROV hProv,
  134. IN DWORD dwFlags);
  135. extern BOOL WINAPI
  136. MyCPGenKey(
  137. IN HCRYPTPROV hProv,
  138. IN ALG_ID Algid,
  139. IN DWORD dwFlags,
  140. OUT HCRYPTKEY *phKey);
  141. extern BOOL WINAPI
  142. MyCPDeriveKey(
  143. IN HCRYPTPROV hProv,
  144. IN ALG_ID Algid,
  145. IN HCRYPTHASH hHash,
  146. IN DWORD dwFlags,
  147. OUT HCRYPTKEY *phKey);
  148. extern BOOL WINAPI
  149. MyCPDestroyKey(
  150. IN HCRYPTPROV hProv,
  151. IN HCRYPTKEY hKey);
  152. extern BOOL WINAPI
  153. MyCPSetKeyParam(
  154. IN HCRYPTPROV hProv,
  155. IN HCRYPTKEY hKey,
  156. IN DWORD dwParam,
  157. IN CONST BYTE *pbData,
  158. IN DWORD dwFlags);
  159. extern BOOL WINAPI
  160. MyCPGetKeyParam(
  161. IN HCRYPTPROV hProv,
  162. IN HCRYPTKEY hKey,
  163. IN DWORD dwParam,
  164. OUT LPBYTE pbData,
  165. IN OUT LPDWORD pcbDataLen,
  166. IN DWORD dwFlags);
  167. extern BOOL WINAPI
  168. MyCPSetProvParam(
  169. IN HCRYPTPROV hProv,
  170. IN DWORD dwParam,
  171. IN CONST BYTE *pbData,
  172. IN DWORD dwFlags);
  173. extern BOOL WINAPI
  174. MyCPGetProvParam(
  175. IN HCRYPTPROV hProv,
  176. IN DWORD dwParam,
  177. OUT LPBYTE pbData,
  178. IN OUT LPDWORD pcbDataLen,
  179. IN DWORD dwFlags);
  180. extern BOOL WINAPI
  181. MyCPSetHashParam(
  182. IN HCRYPTPROV hProv,
  183. IN HCRYPTHASH hHash,
  184. IN DWORD dwParam,
  185. IN CONST BYTE *pbData,
  186. IN DWORD dwFlags);
  187. extern BOOL WINAPI
  188. MyCPGetHashParam(
  189. IN HCRYPTPROV hProv,
  190. IN HCRYPTHASH hHash,
  191. IN DWORD dwParam,
  192. OUT LPBYTE pbData,
  193. IN OUT LPDWORD pcbDataLen,
  194. IN DWORD dwFlags);
  195. extern BOOL WINAPI
  196. MyCPExportKey(
  197. IN HCRYPTPROV hProv,
  198. IN HCRYPTKEY hKey,
  199. IN HCRYPTKEY hPubKey,
  200. IN DWORD dwBlobType,
  201. IN DWORD dwFlags,
  202. OUT LPBYTE pbData,
  203. IN OUT LPDWORD pcbDataLen);
  204. extern BOOL WINAPI
  205. MyCPImportKey(
  206. IN HCRYPTPROV hProv,
  207. IN CONST BYTE *pbData,
  208. IN DWORD cbDataLen,
  209. IN HCRYPTKEY hPubKey,
  210. IN DWORD dwFlags,
  211. OUT HCRYPTKEY *phKey);
  212. extern BOOL WINAPI
  213. MyCPEncrypt(
  214. IN HCRYPTPROV hProv,
  215. IN HCRYPTKEY hKey,
  216. IN HCRYPTHASH hHash,
  217. IN BOOL fFinal,
  218. IN DWORD dwFlags,
  219. IN OUT LPBYTE pbData,
  220. IN OUT LPDWORD pcbDataLen,
  221. IN DWORD cbBufLen);
  222. extern BOOL WINAPI
  223. MyCPDecrypt(
  224. IN HCRYPTPROV hProv,
  225. IN HCRYPTKEY hKey,
  226. IN HCRYPTHASH hHash,
  227. IN BOOL fFinal,
  228. IN DWORD dwFlags,
  229. IN OUT LPBYTE pbData,
  230. IN OUT LPDWORD pcbDataLen);
  231. extern BOOL WINAPI
  232. MyCPCreateHash(
  233. IN HCRYPTPROV hProv,
  234. IN ALG_ID Algid,
  235. IN HCRYPTKEY hKey,
  236. IN DWORD dwFlags,
  237. OUT HCRYPTHASH *phHash);
  238. extern BOOL WINAPI
  239. MyCPHashData(
  240. IN HCRYPTPROV hProv,
  241. IN HCRYPTHASH hHash,
  242. IN CONST BYTE *pbData,
  243. IN DWORD cbDataLen,
  244. IN DWORD dwFlags);
  245. extern BOOL WINAPI
  246. MyCPHashSessionKey(
  247. IN HCRYPTPROV hProv,
  248. IN HCRYPTHASH hHash,
  249. IN HCRYPTKEY hKey,
  250. IN DWORD dwFlags);
  251. extern BOOL WINAPI
  252. MyCPSignHash(
  253. IN HCRYPTPROV hProv,
  254. IN HCRYPTHASH hHash,
  255. IN DWORD dwKeySpec,
  256. IN LPCWSTR szDescription,
  257. IN DWORD dwFlags,
  258. OUT LPBYTE pbSignature,
  259. IN OUT LPDWORD pcbSigLen);
  260. extern BOOL WINAPI
  261. MyCPDestroyHash(
  262. IN HCRYPTPROV hProv,
  263. IN HCRYPTHASH hHash);
  264. extern BOOL WINAPI
  265. MyCPVerifySignature(
  266. IN HCRYPTPROV hProv,
  267. IN HCRYPTHASH hHash,
  268. IN CONST BYTE *pbSignature,
  269. IN DWORD cbSigLen,
  270. IN HCRYPTKEY hPubKey,
  271. IN LPCWSTR szDescription,
  272. IN DWORD dwFlags);
  273. extern BOOL WINAPI
  274. MyCPGenRandom(
  275. IN HCRYPTPROV hProv,
  276. IN DWORD cbLen,
  277. OUT LPBYTE pbBuffer);
  278. extern BOOL WINAPI
  279. MyCPGetUserKey(
  280. IN HCRYPTPROV hProv,
  281. IN DWORD dwKeySpec,
  282. OUT HCRYPTKEY *phUserKey);
  283. extern BOOL WINAPI
  284. MyCPDuplicateHash(
  285. IN HCRYPTPROV hProv,
  286. IN HCRYPTHASH hHash,
  287. IN LPDWORD pdwReserved,
  288. IN DWORD dwFlags,
  289. OUT HCRYPTHASH *phHash);
  290. extern BOOL WINAPI
  291. MyCPDuplicateKey(
  292. IN HCRYPTPROV hProv,
  293. IN HCRYPTKEY hKey,
  294. IN LPDWORD pdwReserved,
  295. IN DWORD dwFlags,
  296. OUT HCRYPTKEY *phKey);
  297. #ifdef __cplusplus
  298. }
  299. #endif
  300. #endif