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.

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