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.

1051 lines
20 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1999
  3. Module Name:
  4. FrontCrypt
  5. Abstract:
  6. This file provides the implementation for the Crypto API V1.0 Front End.
  7. Author:
  8. Doug Barlow (dbarlow) 8/22/1999
  9. Notes:
  10. ?Notes?
  11. --*/
  12. #ifndef WIN32_LEAN_AND_MEAN
  13. #define WIN32_LEAN_AND_MEAN
  14. #endif
  15. #include <windows.h> // All the Windows definitions.
  16. #include "cspUtils.h"
  17. LONG
  18. FCryptAcquireContext(
  19. HCRYPTPROV *phProv,
  20. LPCSTR pszContainer,
  21. LPCSTR pszProvider,
  22. DWORD dwProvType,
  23. DWORD dwFlags)
  24. {
  25. BOOL fSts;
  26. LONG lSts = ERROR_SUCCESS;
  27. fSts = CryptAcquireContextA(
  28. phProv,
  29. pszContainer,
  30. pszProvider,
  31. dwProvType,
  32. dwFlags);
  33. if (!fSts)
  34. lSts = GetLastError();
  35. return lSts;
  36. }
  37. LONG
  38. FCryptAcquireContext(
  39. HCRYPTPROV *phProv,
  40. LPCWSTR pszContainer,
  41. LPCWSTR pszProvider,
  42. DWORD dwProvType,
  43. DWORD dwFlags)
  44. {
  45. BOOL fSts;
  46. LONG lSts = ERROR_SUCCESS;
  47. fSts = CryptAcquireContextW(
  48. phProv,
  49. pszContainer,
  50. pszProvider,
  51. dwProvType,
  52. dwFlags);
  53. if (!fSts)
  54. lSts = GetLastError();
  55. return lSts;
  56. }
  57. LONG
  58. FCryptReleaseContext(
  59. HCRYPTPROV hProv,
  60. DWORD dwFlags)
  61. {
  62. BOOL fSts;
  63. LONG lSts = ERROR_SUCCESS;
  64. fSts = CryptReleaseContext(
  65. hProv,
  66. dwFlags);
  67. if (!fSts)
  68. lSts = GetLastError();
  69. return lSts;
  70. }
  71. LONG
  72. FCryptGenKey(
  73. HCRYPTPROV hProv,
  74. ALG_ID Algid,
  75. DWORD dwFlags,
  76. HCRYPTKEY *phKey)
  77. {
  78. BOOL fSts;
  79. LONG lSts = ERROR_SUCCESS;
  80. fSts = CryptGenKey(
  81. hProv,
  82. Algid,
  83. dwFlags,
  84. phKey);
  85. if (!fSts)
  86. lSts = GetLastError();
  87. return lSts;
  88. }
  89. LONG
  90. FCryptDeriveKey(
  91. HCRYPTPROV hProv,
  92. ALG_ID Algid,
  93. HCRYPTHASH hBaseData,
  94. DWORD dwFlags,
  95. HCRYPTKEY *phKey)
  96. {
  97. BOOL fSts;
  98. LONG lSts = ERROR_SUCCESS;
  99. fSts = CryptDeriveKey(
  100. hProv,
  101. Algid,
  102. hBaseData,
  103. dwFlags,
  104. phKey);
  105. if (!fSts)
  106. lSts = GetLastError();
  107. return lSts;
  108. }
  109. LONG
  110. FCryptDestroyKey(
  111. HCRYPTKEY hKey)
  112. {
  113. BOOL fSts;
  114. LONG lSts = ERROR_SUCCESS;
  115. fSts = CryptDestroyKey(
  116. hKey);
  117. if (!fSts)
  118. lSts = GetLastError();
  119. return lSts;
  120. }
  121. LONG
  122. FCryptSetKeyParam(
  123. HCRYPTKEY hKey,
  124. DWORD dwParam,
  125. LPCBYTE pbData,
  126. DWORD dwFlags)
  127. {
  128. BOOL fSts;
  129. LONG lSts = ERROR_SUCCESS;
  130. fSts = CryptSetKeyParam(
  131. hKey,
  132. dwParam,
  133. const_cast<LPBYTE>(pbData),
  134. dwFlags);
  135. if (!fSts)
  136. lSts = GetLastError();
  137. return lSts;
  138. }
  139. LONG
  140. FCryptGetKeyParam(
  141. HCRYPTKEY hKey,
  142. DWORD dwParam,
  143. CBuffer &bfData,
  144. DWORD dwFlags)
  145. {
  146. BOOL fSts;
  147. LONG lSts = ERROR_SUCCESS;
  148. DWORD dwLen;
  149. LPBYTE pbVal;
  150. for (;;)
  151. {
  152. dwLen = bfData.Space();
  153. pbVal = bfData.Access();
  154. fSts = CryptGetKeyParam(
  155. hKey,
  156. dwParam,
  157. pbVal,
  158. &dwLen,
  159. dwFlags);
  160. if (!fSts)
  161. {
  162. lSts = GetLastError();
  163. if (ERROR_MORE_DATA == lSts)
  164. bfData.Space(dwLen);
  165. else
  166. break;
  167. }
  168. else if (NULL == pbVal)
  169. {
  170. bfData.Space(dwLen);
  171. }
  172. else
  173. {
  174. lSts = ERROR_SUCCESS;
  175. bfData.Length(dwLen);
  176. break;
  177. }
  178. }
  179. return lSts;
  180. }
  181. LONG
  182. FCryptSetHashParam(
  183. HCRYPTHASH hHash,
  184. DWORD dwParam,
  185. LPCBYTE pbData,
  186. DWORD dwFlags)
  187. {
  188. BOOL fSts;
  189. LONG lSts = ERROR_SUCCESS;
  190. fSts = CryptSetHashParam(
  191. hHash,
  192. dwParam,
  193. const_cast<LPBYTE>(pbData),
  194. dwFlags);
  195. if (!fSts)
  196. lSts = GetLastError();
  197. return lSts;
  198. }
  199. LONG
  200. FCryptGetHashParam(
  201. HCRYPTHASH hHash,
  202. DWORD dwParam,
  203. CBuffer &bfData,
  204. DWORD dwFlags)
  205. {
  206. BOOL fSts;
  207. LONG lSts = ERROR_SUCCESS;
  208. DWORD dwLen;
  209. LPBYTE pbVal;
  210. for (;;)
  211. {
  212. dwLen = bfData.Space();
  213. pbVal = bfData.Access();
  214. fSts = CryptGetHashParam(
  215. hHash,
  216. dwParam,
  217. pbVal,
  218. &dwLen,
  219. dwFlags);
  220. if (!fSts)
  221. {
  222. lSts = GetLastError();
  223. if (ERROR_MORE_DATA == lSts)
  224. bfData.Space(dwLen);
  225. else
  226. break;
  227. }
  228. else if (NULL == pbVal)
  229. {
  230. bfData.Space(dwLen);
  231. }
  232. else
  233. {
  234. lSts = ERROR_SUCCESS;
  235. bfData.Length(dwLen);
  236. break;
  237. }
  238. }
  239. return lSts;
  240. }
  241. LONG
  242. FCryptSetProvParam(
  243. HCRYPTPROV hProv,
  244. DWORD dwParam,
  245. LPCBYTE pbData,
  246. DWORD dwFlags)
  247. {
  248. BOOL fSts;
  249. LONG lSts = ERROR_SUCCESS;
  250. fSts = CryptSetProvParam(
  251. hProv,
  252. dwParam,
  253. const_cast<LPBYTE>(pbData),
  254. dwFlags);
  255. if (!fSts)
  256. lSts = GetLastError();
  257. return lSts;
  258. }
  259. LONG
  260. FCryptGetProvParam(
  261. HCRYPTPROV hProv,
  262. DWORD dwParam,
  263. CBuffer &bfData,
  264. DWORD dwFlags)
  265. {
  266. BOOL fSts;
  267. LONG lSts = ERROR_SUCCESS;
  268. DWORD dwLen;
  269. LPBYTE pbVal;
  270. for (;;)
  271. {
  272. dwLen = bfData.Space();
  273. pbVal = bfData.Access();
  274. fSts = CryptGetProvParam(
  275. hProv,
  276. dwParam,
  277. pbVal,
  278. &dwLen,
  279. dwFlags);
  280. if (!fSts)
  281. {
  282. lSts = GetLastError();
  283. if (ERROR_MORE_DATA == lSts)
  284. bfData.Space(dwLen);
  285. else
  286. break;
  287. }
  288. else if (NULL == pbVal)
  289. {
  290. bfData.Space(dwLen);
  291. }
  292. else
  293. {
  294. lSts = ERROR_SUCCESS;
  295. bfData.Length(dwLen);
  296. break;
  297. }
  298. }
  299. return lSts;
  300. }
  301. LONG
  302. FCryptGenRandom(
  303. HCRYPTPROV hProv,
  304. DWORD dwLen,
  305. CBuffer &bfBuffer)
  306. {
  307. BOOL fSts;
  308. LONG lSts = ERROR_SUCCESS;
  309. bfBuffer.Space(dwLen);
  310. fSts = CryptGenRandom(
  311. hProv,
  312. dwLen,
  313. bfBuffer);
  314. if (!fSts)
  315. lSts = GetLastError();
  316. bfBuffer.Length(dwLen);
  317. return lSts;
  318. }
  319. LONG
  320. FCryptGetUserKey(
  321. HCRYPTPROV hProv,
  322. DWORD dwKeySpec,
  323. HCRYPTKEY *phUserKey)
  324. {
  325. BOOL fSts;
  326. LONG lSts = ERROR_SUCCESS;
  327. fSts = CryptGetUserKey(
  328. hProv,
  329. dwKeySpec,
  330. phUserKey);
  331. if (!fSts)
  332. lSts = GetLastError();
  333. return lSts;
  334. }
  335. LONG
  336. FCryptExportKey(
  337. HCRYPTKEY hKey,
  338. HCRYPTKEY hExpKey,
  339. DWORD dwBlobType,
  340. DWORD dwFlags,
  341. CBuffer &bfData)
  342. {
  343. BOOL fSts;
  344. LONG lSts = ERROR_SUCCESS;
  345. DWORD dwLen;
  346. LPBYTE pbVal;
  347. for (;;)
  348. {
  349. dwLen = bfData.Space();
  350. pbVal = bfData.Access();
  351. fSts = CryptExportKey(
  352. hKey,
  353. hExpKey,
  354. dwBlobType,
  355. dwFlags,
  356. pbVal,
  357. &dwLen);
  358. if (!fSts)
  359. {
  360. lSts = GetLastError();
  361. if (ERROR_MORE_DATA == lSts)
  362. bfData.Space(dwLen);
  363. else
  364. break;
  365. }
  366. else if (NULL == pbVal)
  367. {
  368. bfData.Space(dwLen);
  369. }
  370. else
  371. {
  372. lSts = ERROR_SUCCESS;
  373. bfData.Length(dwLen);
  374. break;
  375. }
  376. }
  377. return lSts;
  378. }
  379. LONG
  380. FCryptImportKey(
  381. HCRYPTPROV hProv,
  382. LPCBYTE pbData,
  383. DWORD dwDataLen,
  384. HCRYPTKEY hPubKey,
  385. DWORD dwFlags,
  386. HCRYPTKEY *phKey)
  387. {
  388. BOOL fSts;
  389. LONG lSts = ERROR_SUCCESS;
  390. fSts = CryptImportKey(
  391. hProv,
  392. pbData,
  393. dwDataLen,
  394. hPubKey,
  395. dwFlags,
  396. phKey);
  397. if (!fSts)
  398. lSts = GetLastError();
  399. return lSts;
  400. }
  401. LONG
  402. FCryptEncrypt(
  403. HCRYPTKEY hKey,
  404. HCRYPTHASH hHash,
  405. BOOL Final,
  406. DWORD dwFlags,
  407. CBuffer &bfData)
  408. {
  409. BOOL fSts;
  410. LONG lSts = ERROR_SUCCESS;
  411. DWORD dwLen;
  412. for (;;)
  413. {
  414. dwLen = bfData.Length();
  415. fSts = CryptEncrypt(
  416. hKey,
  417. hHash,
  418. Final,
  419. dwFlags,
  420. bfData,
  421. &dwLen,
  422. bfData.Space());
  423. if (!fSts)
  424. {
  425. lSts = GetLastError();
  426. if (ERROR_MORE_DATA == lSts)
  427. bfData.Extend(dwLen);
  428. else
  429. break;
  430. }
  431. else
  432. {
  433. lSts = ERROR_SUCCESS;
  434. bfData.Length(dwLen);
  435. break;
  436. }
  437. }
  438. return lSts;
  439. }
  440. LONG
  441. FCryptDecrypt(
  442. HCRYPTKEY hKey,
  443. HCRYPTHASH hHash,
  444. BOOL Final,
  445. DWORD dwFlags,
  446. CBuffer &bfData)
  447. {
  448. BOOL fSts;
  449. LONG lSts = ERROR_SUCCESS;
  450. DWORD dwLen;
  451. for (;;)
  452. {
  453. dwLen = bfData.Space();
  454. fSts = CryptDecrypt(
  455. hKey,
  456. hHash,
  457. Final,
  458. dwFlags,
  459. bfData,
  460. &dwLen);
  461. if (!fSts)
  462. {
  463. lSts = GetLastError();
  464. if (ERROR_MORE_DATA == lSts)
  465. bfData.Extend(dwLen);
  466. else
  467. break;
  468. }
  469. else
  470. {
  471. lSts = ERROR_SUCCESS;
  472. bfData.Length(dwLen);
  473. break;
  474. }
  475. }
  476. return lSts;
  477. }
  478. LONG
  479. FCryptCreateHash(
  480. HCRYPTPROV hProv,
  481. ALG_ID Algid,
  482. HCRYPTKEY hKey,
  483. DWORD dwFlags,
  484. HCRYPTHASH *phHash)
  485. {
  486. BOOL fSts;
  487. LONG lSts = ERROR_SUCCESS;
  488. fSts = CryptCreateHash(
  489. hProv,
  490. Algid,
  491. hKey,
  492. dwFlags,
  493. phHash);
  494. if (!fSts)
  495. lSts = GetLastError();
  496. return lSts;
  497. }
  498. LONG
  499. FCryptHashData(
  500. HCRYPTHASH hHash,
  501. LPCBYTE pbData,
  502. DWORD dwDataLen,
  503. DWORD dwFlags)
  504. {
  505. BOOL fSts;
  506. LONG lSts = ERROR_SUCCESS;
  507. fSts = CryptHashData(
  508. hHash,
  509. pbData,
  510. dwDataLen,
  511. dwFlags);
  512. if (!fSts)
  513. lSts = GetLastError();
  514. return lSts;
  515. }
  516. LONG
  517. FCryptHashSessionKey(
  518. HCRYPTHASH hHash,
  519. HCRYPTKEY hKey,
  520. DWORD dwFlags)
  521. {
  522. BOOL fSts;
  523. LONG lSts = ERROR_SUCCESS;
  524. fSts = CryptHashSessionKey(
  525. hHash,
  526. hKey,
  527. dwFlags);
  528. if (!fSts)
  529. lSts = GetLastError();
  530. return lSts;
  531. }
  532. LONG
  533. FCryptDestroyHash(
  534. HCRYPTHASH hHash)
  535. {
  536. BOOL fSts;
  537. LONG lSts = ERROR_SUCCESS;
  538. fSts = CryptDestroyHash(
  539. hHash);
  540. if (!fSts)
  541. lSts = GetLastError();
  542. return lSts;
  543. }
  544. LONG
  545. FCryptSignHash(
  546. HCRYPTHASH hHash,
  547. DWORD dwKeySpec,
  548. LPCSTR sDescription,
  549. DWORD dwFlags,
  550. CBuffer &bfSignature)
  551. {
  552. BOOL fSts;
  553. LONG lSts = ERROR_SUCCESS;
  554. DWORD dwLen;
  555. LPBYTE pbVal;
  556. for (;;)
  557. {
  558. dwLen = bfSignature.Space();
  559. pbVal = bfSignature.Access();
  560. fSts = CryptSignHashA(
  561. hHash,
  562. dwKeySpec,
  563. sDescription,
  564. dwFlags,
  565. pbVal,
  566. &dwLen);
  567. if (!fSts)
  568. {
  569. lSts = GetLastError();
  570. if (ERROR_MORE_DATA == lSts)
  571. bfSignature.Space(dwLen);
  572. else
  573. break;
  574. }
  575. else if (NULL == pbVal)
  576. {
  577. bfSignature.Space(dwLen);
  578. }
  579. else
  580. {
  581. lSts = ERROR_SUCCESS;
  582. bfSignature.Length(dwLen);
  583. break;
  584. }
  585. }
  586. return lSts;
  587. }
  588. LONG
  589. FCryptSignHash(
  590. HCRYPTHASH hHash,
  591. DWORD dwKeySpec,
  592. LPCWSTR sDescription,
  593. DWORD dwFlags,
  594. CBuffer &bfSignature)
  595. {
  596. BOOL fSts;
  597. LONG lSts = ERROR_SUCCESS;
  598. DWORD dwLen;
  599. LPBYTE pbVal;
  600. for (;;)
  601. {
  602. dwLen = bfSignature.Space();
  603. pbVal = bfSignature.Access();
  604. fSts = CryptSignHashW(
  605. hHash,
  606. dwKeySpec,
  607. sDescription,
  608. dwFlags,
  609. pbVal,
  610. &dwLen);
  611. if (!fSts)
  612. {
  613. lSts = GetLastError();
  614. if (ERROR_MORE_DATA == lSts)
  615. bfSignature.Space(dwLen);
  616. else
  617. break;
  618. }
  619. else if (NULL == pbVal)
  620. {
  621. bfSignature.Space(dwLen);
  622. }
  623. else
  624. {
  625. lSts = ERROR_SUCCESS;
  626. bfSignature.Length(dwLen);
  627. break;
  628. }
  629. }
  630. return lSts;
  631. }
  632. LONG
  633. FCryptVerifySignature(
  634. HCRYPTHASH hHash,
  635. LPCBYTE pbSignature,
  636. DWORD dwSigLen,
  637. HCRYPTKEY hPubKey,
  638. LPCSTR sDescription,
  639. DWORD dwFlags)
  640. {
  641. BOOL fSts;
  642. LONG lSts = ERROR_SUCCESS;
  643. fSts = CryptVerifySignatureA(
  644. hHash,
  645. pbSignature,
  646. dwSigLen,
  647. hPubKey,
  648. sDescription,
  649. dwFlags);
  650. if (!fSts)
  651. lSts = GetLastError();
  652. return lSts;
  653. }
  654. LONG
  655. FCryptVerifySignature(
  656. HCRYPTHASH hHash,
  657. LPCBYTE pbSignature,
  658. DWORD dwSigLen,
  659. HCRYPTKEY hPubKey,
  660. LPCWSTR sDescription,
  661. DWORD dwFlags)
  662. {
  663. BOOL fSts;
  664. LONG lSts = ERROR_SUCCESS;
  665. fSts = CryptVerifySignatureW(
  666. hHash,
  667. pbSignature,
  668. dwSigLen,
  669. hPubKey,
  670. sDescription,
  671. dwFlags);
  672. if (!fSts)
  673. lSts = GetLastError();
  674. return lSts;
  675. }
  676. LONG
  677. FCryptSetProvider(
  678. LPCSTR pszProvName,
  679. DWORD dwProvType)
  680. {
  681. BOOL fSts;
  682. LONG lSts = ERROR_SUCCESS;
  683. fSts = CryptSetProviderA(
  684. pszProvName,
  685. dwProvType);
  686. if (!fSts)
  687. lSts = GetLastError();
  688. return lSts;
  689. }
  690. LONG
  691. FCryptSetProvider(
  692. LPCWSTR pszProvName,
  693. DWORD dwProvType)
  694. {
  695. BOOL fSts;
  696. LONG lSts = ERROR_SUCCESS;
  697. fSts = CryptSetProviderW(
  698. pszProvName,
  699. dwProvType);
  700. if (!fSts)
  701. lSts = GetLastError();
  702. return lSts;
  703. }
  704. LONG
  705. FCryptSetProviderEx(
  706. LPCSTR pszProvName,
  707. DWORD dwProvType,
  708. DWORD * pdwReserved,
  709. DWORD dwFlags)
  710. {
  711. BOOL fSts;
  712. LONG lSts = ERROR_SUCCESS;
  713. fSts = CryptSetProviderExA(
  714. pszProvName,
  715. dwProvType,
  716. pdwReserved,
  717. dwFlags);
  718. if (!fSts)
  719. lSts = GetLastError();
  720. return lSts;
  721. }
  722. LONG
  723. FCryptSetProviderEx(
  724. LPCWSTR pszProvName,
  725. DWORD dwProvType,
  726. DWORD * pdwReserved,
  727. DWORD dwFlags)
  728. {
  729. BOOL fSts;
  730. LONG lSts = ERROR_SUCCESS;
  731. fSts = CryptSetProviderExW(
  732. pszProvName,
  733. dwProvType,
  734. pdwReserved,
  735. dwFlags);
  736. if (!fSts)
  737. lSts = GetLastError();
  738. return lSts;
  739. }
  740. LONG
  741. FCryptGetDefaultProvider(
  742. DWORD dwProvType,
  743. DWORD *pdwReserved,
  744. DWORD dwFlags,
  745. CBuffer &bfProvName)
  746. {
  747. BOOL fSts;
  748. LONG lSts;
  749. DWORD dwLen;
  750. LPTSTR szVal;
  751. for (;;)
  752. {
  753. dwLen = bfProvName.Space();
  754. szVal = (LPTSTR)bfProvName.Access();
  755. fSts = CryptGetDefaultProvider(
  756. dwProvType,
  757. pdwReserved,
  758. dwFlags,
  759. szVal,
  760. &dwLen);
  761. if (!fSts)
  762. {
  763. lSts = GetLastError();
  764. if (ERROR_MORE_DATA == lSts)
  765. bfProvName.Space(dwLen);
  766. else if ((ERROR_INVALID_PARAMETER == lSts) && (0 == dwFlags))
  767. {
  768. //
  769. // This is a workaround for a bug in advapi.
  770. // If there's no user default provider defined,
  771. // it returns "invalid parameter". This fix
  772. // forces a retry against the machine default.
  773. //
  774. dwFlags = CRYPT_MACHINE_DEFAULT;
  775. }
  776. else
  777. break;
  778. }
  779. else if (NULL == szVal)
  780. {
  781. bfProvName.Space(dwLen);
  782. }
  783. else
  784. {
  785. lSts = ERROR_SUCCESS;
  786. bfProvName.Length(dwLen);
  787. break;
  788. }
  789. }
  790. return lSts;
  791. }
  792. LONG
  793. FCryptEnumProviderTypes(
  794. DWORD dwIndex,
  795. DWORD * pdwReserved,
  796. DWORD dwFlags,
  797. DWORD * pdwProvType,
  798. CBuffer &bfTypeName)
  799. {
  800. BOOL fSts;
  801. LONG lSts = ERROR_SUCCESS;
  802. DWORD dwLen;
  803. LPTSTR szVal;
  804. for (;;)
  805. {
  806. dwLen = bfTypeName.Space();
  807. szVal = (LPTSTR)bfTypeName.Access();
  808. fSts = CryptEnumProviderTypes(
  809. dwIndex,
  810. pdwReserved,
  811. dwFlags,
  812. pdwProvType,
  813. szVal,
  814. &dwLen);
  815. if (!fSts)
  816. {
  817. lSts = GetLastError();
  818. if (ERROR_MORE_DATA == lSts)
  819. bfTypeName.Space(dwLen);
  820. else
  821. break;
  822. }
  823. else if (NULL == szVal)
  824. {
  825. bfTypeName.Space(dwLen);
  826. }
  827. else
  828. {
  829. lSts = ERROR_SUCCESS;
  830. bfTypeName.Length(dwLen);
  831. break;
  832. }
  833. }
  834. return lSts;
  835. }
  836. LONG
  837. FCryptEnumProviders(
  838. DWORD dwIndex,
  839. DWORD * pdwReserved,
  840. DWORD dwFlags,
  841. DWORD * pdwProvType,
  842. CBuffer &bfProvName)
  843. {
  844. BOOL fSts;
  845. LONG lSts = ERROR_SUCCESS;
  846. DWORD dwLen;
  847. LPTSTR szVal;
  848. for (;;)
  849. {
  850. dwLen = bfProvName.Space();
  851. szVal = (LPTSTR)bfProvName.Access();
  852. fSts = CryptEnumProviders(
  853. dwIndex,
  854. pdwReserved,
  855. dwFlags,
  856. pdwProvType,
  857. szVal,
  858. &dwLen);
  859. if (!fSts)
  860. {
  861. lSts = GetLastError();
  862. if (ERROR_MORE_DATA == lSts)
  863. bfProvName.Space(dwLen);
  864. else
  865. break;
  866. }
  867. else if (NULL == szVal)
  868. {
  869. bfProvName.Space(dwLen);
  870. }
  871. else
  872. {
  873. lSts = ERROR_SUCCESS;
  874. bfProvName.Length(dwLen);
  875. break;
  876. }
  877. }
  878. return lSts;
  879. }
  880. LONG
  881. FCryptContextAddRef(
  882. HCRYPTPROV hProv,
  883. DWORD * pdwReserved,
  884. DWORD dwFlags)
  885. {
  886. BOOL fSts;
  887. LONG lSts = ERROR_SUCCESS;
  888. fSts = CryptContextAddRef(
  889. hProv,
  890. pdwReserved,
  891. dwFlags);
  892. if (!fSts)
  893. lSts = GetLastError();
  894. return lSts;
  895. }
  896. LONG
  897. FCryptDuplicateKey(
  898. HCRYPTKEY hKey,
  899. DWORD * pdwReserved,
  900. DWORD dwFlags,
  901. HCRYPTKEY * phKey)
  902. {
  903. BOOL fSts;
  904. LONG lSts = ERROR_SUCCESS;
  905. fSts = CryptDuplicateKey(
  906. hKey,
  907. pdwReserved,
  908. dwFlags,
  909. phKey);
  910. if (!fSts)
  911. lSts = GetLastError();
  912. return lSts;
  913. }
  914. LONG
  915. FCryptDuplicateHash(
  916. HCRYPTHASH hHash,
  917. DWORD * pdwReserved,
  918. DWORD dwFlags,
  919. HCRYPTHASH * phHash)
  920. {
  921. BOOL fSts;
  922. LONG lSts = ERROR_SUCCESS;
  923. fSts = CryptDuplicateHash(
  924. hHash,
  925. pdwReserved,
  926. dwFlags,
  927. phHash);
  928. if (!fSts)
  929. lSts = GetLastError();
  930. return lSts;
  931. }