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.

613 lines
10 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1996 - 1999
  3. Module Name:
  4. cspDirect
  5. Abstract:
  6. This file provides direct linkage to a CSP, so it does not have to be in a
  7. separate DLL. This facilitates code generation and debugging.
  8. Author:
  9. Doug Barlow (dbarlow) 5/8/1996
  10. Environment:
  11. Win32
  12. Notes:
  13. ?Notes?
  14. --*/
  15. #ifndef WIN32_LEAN_AND_MEAN
  16. #define WIN32_LEAN_AND_MEAN
  17. #endif
  18. #include <windows.h>
  19. #include "cspUtils.h"
  20. #ifdef _CSPDIRECT_H_
  21. #ifdef CSP_BREAK
  22. #define entrypoint breakpoint
  23. #else
  24. #define entrypoint
  25. #endif
  26. static int WINAPI
  27. SayYes(
  28. IN LPCTSTR szImage,
  29. IN LPBYTE pbSignature)
  30. {
  31. return TRUE;
  32. }
  33. static int WINAPI
  34. GetWnd(
  35. HWND *phWnd)
  36. {
  37. if (NULL != phWnd)
  38. *phWnd = NULL;
  39. return (int)NULL;
  40. }
  41. static HCRYPTPROV
  42. g_hProv
  43. = NULL;
  44. CSPBOOL
  45. CSPAcquireContextA(
  46. HCRYPTPROV *phProv,
  47. LPCSTR pszContainer,
  48. LPCSTR pszProvider,
  49. DWORD dwProvType,
  50. DWORD dwFlags)
  51. {
  52. #ifdef UNICODE
  53. return CRYPT_FAILED;
  54. #else
  55. BOOL fSts;
  56. VTableProvStruc VTable;
  57. VTable.Version = 3;
  58. VTable.FuncVerifyImage = (FARPROC)SayYes;
  59. VTable.FuncReturnhWnd = (FARPROC)GetWnd;
  60. VTable.dwProvType = dwProvType;
  61. VTable.pbContextInfo = NULL;
  62. VTable.cbContextInfo = 0;
  63. VTable.pszProvName = const_cast<LPTSTR>(pszProvider);
  64. entrypoint;
  65. fSts =
  66. CPAcquireContext(
  67. phProv,
  68. pszContainer,
  69. dwFlags,
  70. &VTable);
  71. g_hProv = *phProv;
  72. return fSts;
  73. #endif
  74. }
  75. CSPBOOL
  76. CSPAcquireContextW(
  77. HCRYPTPROV *phProv,
  78. LPCWSTR pszContainer,
  79. LPCWSTR pszProvider,
  80. DWORD dwProvType,
  81. DWORD dwFlags)
  82. {
  83. #ifdef UNICODE
  84. BOOL fSts;
  85. VTableProvStruc VTable;
  86. VTable.Version = 3;
  87. VTable.FuncVerifyImage = (FARPROC)SayYes;
  88. VTable.FuncReturnhWnd = (FARPROC)GetWnd;
  89. VTable.dwProvType = dwProvType;
  90. VTable.pbContextInfo = NULL;
  91. VTable.cbContextInfo = 0;
  92. VTable.pszProvName = pszProvider;
  93. entrypoint;
  94. fSts =
  95. CPAcquireContext(
  96. phProv,
  97. pszContainer,
  98. dwFlags,
  99. &VTable);
  100. g_hProv = *phProv;
  101. return fSts;
  102. #else
  103. return CRYPT_FAILED;
  104. #endif
  105. }
  106. CSPBOOL
  107. CSPReleaseContext(
  108. HCRYPTPROV hProv,
  109. DWORD dwFlags)
  110. {
  111. ASSERT(g_hProv == hProv);
  112. g_hProv = NULL;
  113. entrypoint;
  114. return
  115. CPReleaseContext(
  116. hProv,
  117. dwFlags);
  118. }
  119. CSPBOOL
  120. CSPGenKey(
  121. HCRYPTPROV hProv,
  122. ALG_ID Algid,
  123. DWORD dwFlags,
  124. HCRYPTKEY *phKey)
  125. {
  126. ASSERT(g_hProv == hProv);
  127. entrypoint;
  128. return
  129. CPGenKey(
  130. hProv,
  131. Algid,
  132. dwFlags,
  133. phKey);
  134. }
  135. CSPBOOL
  136. CSPDeriveKey(
  137. HCRYPTPROV hProv,
  138. ALG_ID Algid,
  139. HCRYPTHASH hBaseData,
  140. DWORD dwFlags,
  141. HCRYPTKEY *phKey)
  142. {
  143. ASSERT(g_hProv == hProv);
  144. entrypoint;
  145. return
  146. CPDeriveKey(
  147. hProv,
  148. Algid,
  149. hBaseData,
  150. dwFlags,
  151. phKey);
  152. }
  153. CSPBOOL
  154. CSPDestroyKey(
  155. HCRYPTKEY hKey)
  156. {
  157. entrypoint;
  158. return
  159. CPDestroyKey(
  160. g_hProv,
  161. hKey);
  162. }
  163. CSPBOOL
  164. CSPSetKeyParam(
  165. HCRYPTKEY hKey,
  166. DWORD dwParam,
  167. BYTE *pbData,
  168. DWORD dwFlags)
  169. {
  170. entrypoint;
  171. return
  172. CPSetKeyParam(
  173. g_hProv,
  174. hKey,
  175. dwParam,
  176. pbData,
  177. dwFlags);
  178. }
  179. CSPBOOL
  180. CSPGetKeyParam(
  181. HCRYPTKEY hKey,
  182. DWORD dwParam,
  183. BYTE *pbData,
  184. DWORD *pdwDataLen,
  185. DWORD dwFlags)
  186. {
  187. entrypoint;
  188. return
  189. CPGetKeyParam(
  190. g_hProv,
  191. hKey,
  192. dwParam,
  193. pbData,
  194. pdwDataLen,
  195. dwFlags);
  196. }
  197. CSPBOOL
  198. CSPSetHashParam(
  199. HCRYPTHASH hHash,
  200. DWORD dwParam,
  201. BYTE *pbData,
  202. DWORD dwFlags)
  203. {
  204. entrypoint;
  205. return
  206. CPSetHashParam(
  207. g_hProv,
  208. hHash,
  209. dwParam,
  210. pbData,
  211. dwFlags);
  212. }
  213. CSPBOOL
  214. CSPGetHashParam(
  215. HCRYPTHASH hHash,
  216. DWORD dwParam,
  217. BYTE *pbData,
  218. DWORD *pdwDataLen,
  219. DWORD dwFlags)
  220. {
  221. entrypoint;
  222. return
  223. CPGetHashParam(
  224. g_hProv,
  225. hHash,
  226. dwParam,
  227. pbData,
  228. pdwDataLen,
  229. dwFlags);
  230. }
  231. CSPBOOL
  232. CSPSetProvParam(
  233. HCRYPTPROV hProv,
  234. DWORD dwParam,
  235. BYTE *pbData,
  236. DWORD dwFlags)
  237. {
  238. ASSERT(g_hProv == hProv);
  239. entrypoint;
  240. return
  241. CPSetProvParam(
  242. hProv,
  243. dwParam,
  244. pbData,
  245. dwFlags);
  246. }
  247. CSPBOOL
  248. CSPGetProvParam(
  249. HCRYPTPROV hProv,
  250. DWORD dwParam,
  251. BYTE *pbData,
  252. DWORD *pdwDataLen,
  253. DWORD dwFlags)
  254. {
  255. ASSERT(g_hProv == hProv);
  256. entrypoint;
  257. return
  258. CPGetProvParam(
  259. hProv,
  260. dwParam,
  261. pbData,
  262. pdwDataLen,
  263. dwFlags);
  264. }
  265. CSPBOOL
  266. CSPGenRandom(
  267. HCRYPTPROV hProv,
  268. DWORD dwLen,
  269. BYTE *pbBuffer)
  270. {
  271. ASSERT(g_hProv == hProv);
  272. entrypoint;
  273. return
  274. CPGenRandom(
  275. hProv,
  276. dwLen,
  277. pbBuffer);
  278. }
  279. CSPBOOL
  280. CSPGetUserKey(
  281. HCRYPTPROV hProv,
  282. DWORD dwKeySpec,
  283. HCRYPTKEY *phUserKey)
  284. {
  285. ASSERT(g_hProv == hProv);
  286. entrypoint;
  287. return
  288. CPGetUserKey(
  289. hProv,
  290. dwKeySpec,
  291. phUserKey);
  292. }
  293. CSPBOOL
  294. CSPExportKey(
  295. HCRYPTKEY hKey,
  296. HCRYPTKEY hExpKey,
  297. DWORD dwBlobType,
  298. DWORD dwFlags,
  299. BYTE *pbData,
  300. DWORD *pdwDataLen)
  301. {
  302. entrypoint;
  303. return
  304. CPExportKey(
  305. g_hProv,
  306. hKey,
  307. hExpKey,
  308. dwBlobType,
  309. dwFlags,
  310. pbData,
  311. pdwDataLen);
  312. }
  313. CSPBOOL
  314. CSPImportKey(
  315. HCRYPTPROV hProv,
  316. CONST BYTE *pbData,
  317. DWORD dwDataLen,
  318. HCRYPTKEY hPubKey,
  319. DWORD dwFlags,
  320. HCRYPTKEY *phKey)
  321. {
  322. ASSERT(g_hProv == hProv);
  323. entrypoint;
  324. return
  325. CPImportKey(
  326. hProv,
  327. pbData,
  328. dwDataLen,
  329. hPubKey,
  330. dwFlags,
  331. phKey);
  332. }
  333. CSPBOOL
  334. CSPEncrypt(
  335. HCRYPTKEY hKey,
  336. HCRYPTHASH hHash,
  337. BOOL Final,
  338. DWORD dwFlags,
  339. BYTE *pbData,
  340. DWORD *pdwDataLen,
  341. DWORD dwBufLen)
  342. {
  343. entrypoint;
  344. return
  345. CPEncrypt(
  346. g_hProv,
  347. hKey,
  348. hHash,
  349. Final,
  350. dwFlags,
  351. pbData,
  352. pdwDataLen,
  353. dwBufLen);
  354. }
  355. CSPBOOL
  356. CSPDecrypt(
  357. HCRYPTKEY hKey,
  358. HCRYPTHASH hHash,
  359. BOOL Final,
  360. DWORD dwFlags,
  361. BYTE *pbData,
  362. DWORD *pdwDataLen)
  363. {
  364. entrypoint;
  365. return
  366. CPDecrypt(
  367. g_hProv,
  368. hKey,
  369. hHash,
  370. Final,
  371. dwFlags,
  372. pbData,
  373. pdwDataLen);
  374. }
  375. CSPBOOL
  376. CSPCreateHash(
  377. HCRYPTPROV hProv,
  378. ALG_ID Algid,
  379. HCRYPTKEY hKey,
  380. DWORD dwFlags,
  381. HCRYPTHASH *phHash)
  382. {
  383. ASSERT(g_hProv == hProv);
  384. entrypoint;
  385. return
  386. CPCreateHash(
  387. hProv,
  388. Algid,
  389. hKey,
  390. dwFlags,
  391. phHash);
  392. }
  393. CSPBOOL
  394. CSPHashData(
  395. HCRYPTHASH hHash,
  396. CONST BYTE *pbData,
  397. DWORD dwDataLen,
  398. DWORD dwFlags)
  399. {
  400. entrypoint;
  401. return
  402. CPHashData(
  403. g_hProv,
  404. hHash,
  405. pbData,
  406. dwDataLen,
  407. dwFlags);
  408. }
  409. CSPBOOL
  410. CSPHashSessionKey(
  411. HCRYPTHASH hHash,
  412. HCRYPTKEY hKey,
  413. DWORD dwFlags)
  414. {
  415. entrypoint;
  416. return
  417. CPHashSessionKey(
  418. g_hProv,
  419. hHash,
  420. hKey,
  421. dwFlags);
  422. }
  423. /*
  424. CSPBOOL
  425. CSPGetHashValue(
  426. HCRYPTHASH hHash,
  427. DWORD dwFlags,
  428. BYTE *pbHash,
  429. DWORD *pdwHashLen)
  430. {
  431. entrypoint;
  432. return
  433. CPGetHashValue(
  434. g_hProv,
  435. hHash,
  436. dwFlags,
  437. pbHash,
  438. pdwHashLen);
  439. }
  440. */
  441. CSPBOOL
  442. CSPDestroyHash(
  443. HCRYPTHASH hHash)
  444. {
  445. entrypoint;
  446. return
  447. CPDestroyHash(
  448. g_hProv,
  449. hHash);
  450. }
  451. CSPBOOL
  452. CSPSignHashA(
  453. HCRYPTHASH hHash,
  454. DWORD dwKeySpec,
  455. LPCSTR sDescription,
  456. DWORD dwFlags,
  457. BYTE *pbSignature,
  458. DWORD *pdwSigLen)
  459. {
  460. #ifdef UNICODE
  461. return CRYPT_FAILED;
  462. #else
  463. entrypoint;
  464. return
  465. CPSignHash(
  466. g_hProv,
  467. hHash,
  468. dwKeySpec,
  469. sDescription,
  470. dwFlags,
  471. pbSignature,
  472. pdwSigLen);
  473. #endif
  474. }
  475. CSPBOOL
  476. CSPSignHashW(
  477. HCRYPTHASH hHash,
  478. DWORD dwKeySpec,
  479. LPCWSTR sDescription,
  480. DWORD dwFlags,
  481. BYTE *pbSignature,
  482. DWORD *pdwSigLen)
  483. {
  484. #ifdef UNICODE
  485. entrypoint;
  486. return
  487. CPSignHash(
  488. g_hProv,
  489. hHash,
  490. dwKeySpec,
  491. sDescription,
  492. dwFlags,
  493. pbSignature,
  494. pdwSigLen);
  495. #else
  496. return CRYPT_FAILED;
  497. #endif
  498. }
  499. CSPBOOL
  500. CSPVerifySignatureA(
  501. HCRYPTHASH hHash,
  502. CONST BYTE *pbSignature,
  503. DWORD dwSigLen,
  504. HCRYPTKEY hPubKey,
  505. LPCSTR sDescription,
  506. DWORD dwFlags)
  507. {
  508. #ifdef UNICODE
  509. return CRYPT_FAILED;
  510. #else
  511. entrypoint;
  512. return
  513. CPVerifySignature(
  514. g_hProv,
  515. hHash,
  516. pbSignature,
  517. dwSigLen,
  518. hPubKey,
  519. sDescription,
  520. dwFlags);
  521. #endif
  522. }
  523. CSPBOOL
  524. CSPVerifySignatureW(
  525. HCRYPTHASH hHash,
  526. CONST BYTE *pbSignature,
  527. DWORD dwSigLen,
  528. HCRYPTKEY hPubKey,
  529. LPCWSTR sDescription,
  530. DWORD dwFlags)
  531. {
  532. #ifdef UNICODE
  533. entrypoint;
  534. return
  535. CPVerifySignature(
  536. g_hProv,
  537. hHash,
  538. pbSignature,
  539. dwSigLen,
  540. hPubKey,
  541. sDescription,
  542. dwFlags);
  543. #else
  544. return CRYPT_FAILED;
  545. #endif
  546. }
  547. CSPBOOL
  548. CSPSetProviderA(
  549. LPCSTR pszProvName,
  550. DWORD dwProvType)
  551. {
  552. entrypoint;
  553. return TRUE;
  554. }
  555. CSPBOOL
  556. CSPSetProviderW(
  557. LPCWSTR pszProvName,
  558. DWORD dwProvType)
  559. {
  560. entrypoint;
  561. return TRUE;
  562. }
  563. #endif // defined(_CSPDIRECT_H_)