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.

804 lines
20 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 2000
  3. Module Name:
  4. cspdk
  5. Abstract:
  6. This header file contains the definitions and references that every CSP
  7. needs to know.
  8. Author:
  9. Doug Barlow (dbarlow) 1/27/2000
  10. --*/
  11. #ifndef _CSPDK_H_
  12. #define _CSPDK_H_
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. #define CRYPT_PROVSTRUC_VERSION_V3 3
  17. #define CRYPT_MAX_PROVIDER_ID 999
  18. #define CRYPT_SIG_RESOURCE_VERSION 0x00000100
  19. #define CRYPT_EXTERNAL_SIGNATURE_LENGTH 136
  20. #define CRYPT_SIG_RESOURCE_NUMBER 0x29A
  21. #define CRYPT_SIG_RESOURCE TEXT("#666")
  22. #define CRYPT_MAC_RESOURCE_NUMBER 0x29B
  23. #define CRYPT_MAC_RESOURCE TEXT("#667")
  24. // Exponentiation Offload Reg Location
  25. #define EXPO_OFFLOAD_REG_VALUE "ExpoOffload"
  26. #define EXPO_OFFLOAD_FUNC_NAME "OffloadModExpo"
  27. //
  28. // Exponentiation Offload Entry Point Prototype
  29. //
  30. typedef struct _OFFLOAD_PRIVATE_KEY
  31. {
  32. DWORD dwVersion;
  33. DWORD cbPrime1;
  34. DWORD cbPrime2;
  35. PBYTE pbPrime1; // "p"
  36. PBYTE pbPrime2; // "q"
  37. } OFFLOAD_PRIVATE_KEY, *POFFLOAD_PRIVATE_KEY;
  38. #define CUR_OFFLOAD_VERSION 1
  39. typedef BOOL (WINAPI *PFN_OFFLOAD_MOD_EXPO)(
  40. IN PBYTE pbBase,
  41. IN PBYTE pbExponent,
  42. IN DWORD cbExponent,
  43. IN PBYTE pbModulus,
  44. IN DWORD cbModulus,
  45. OUT PBYTE pbResult,
  46. IN OPTIONAL PVOID pvOffloadPrivateKey,
  47. IN DWORD dwFlags);
  48. //
  49. // Callback prototypes
  50. //
  51. typedef BOOL (WINAPI *CRYPT_VERIFY_IMAGE_A)(LPCSTR szImage, CONST BYTE *pbSigData);
  52. typedef BOOL (WINAPI *CRYPT_VERIFY_IMAGE_W)(LPCWSTR szImage, CONST BYTE *pbSigData);
  53. typedef void (*CRYPT_RETURN_HWND)(HWND *phWnd);
  54. //
  55. // Structures for CSPs
  56. //
  57. typedef struct _VTableProvStruc {
  58. DWORD Version;
  59. CRYPT_VERIFY_IMAGE_A FuncVerifyImage;
  60. CRYPT_RETURN_HWND FuncReturnhWnd;
  61. DWORD dwProvType;
  62. BYTE *pbContextInfo;
  63. DWORD cbContextInfo;
  64. LPSTR pszProvName;
  65. } VTableProvStruc, *PVTableProvStruc;
  66. typedef struct _VTableProvStrucW {
  67. DWORD Version;
  68. CRYPT_VERIFY_IMAGE_W FuncVerifyImage;
  69. CRYPT_RETURN_HWND FuncReturnhWnd;
  70. DWORD dwProvType;
  71. BYTE *pbContextInfo;
  72. DWORD cbContextInfo;
  73. LPWSTR pszProvName;
  74. } VTableProvStrucW, *PVTableProvStrucW;
  75. typedef struct {
  76. DWORD dwVersion;
  77. DWORD dwCrcOffset;
  78. BYTE rgbSignature[88]; // 1024-bit key, plus 2 DWORDs of padding.
  79. } InFileSignatureResource;
  80. //
  81. // ===========================================================================
  82. // CSP Entry points.
  83. // ===========================================================================
  84. //
  85. /*
  86. - CPAcquireContext
  87. -
  88. * Purpose:
  89. * The CPAcquireContext function is used to acquire a context
  90. * handle to a cryptographic service provider (CSP).
  91. *
  92. *
  93. * Parameters:
  94. * OUT phProv - Handle to a CSP
  95. * IN szContainer - Pointer to a string which is the
  96. * identity of the logged on user
  97. * IN dwFlags - Flags values
  98. * IN pVTable - Pointer to table of function pointers
  99. *
  100. * Returns:
  101. */
  102. extern BOOL WINAPI
  103. CPAcquireContext(
  104. OUT HCRYPTPROV *phProv,
  105. IN LPCSTR szContainer,
  106. IN DWORD dwFlags,
  107. IN PVTableProvStruc pVTable);
  108. /*
  109. - CPAcquireContextW
  110. -
  111. * Purpose:
  112. * The CPAcquireContextW function is used to acquire a context
  113. * handle to a cryptographic service provider (CSP). using
  114. * UNICODE strings. This is an optional entry point for a CSP.
  115. * It is not used prior to Whistler. There it is used if
  116. * exported by the CSP image, otherwise any string conversions
  117. * are done, and CPAcquireContext is called.
  118. *
  119. *
  120. * Parameters:
  121. * OUT phProv - Handle to a CSP
  122. * IN szContainer - Pointer to a string which is the
  123. * identity of the logged on user
  124. * IN dwFlags - Flags values
  125. * IN pVTable - Pointer to table of function pointers
  126. *
  127. * Returns:
  128. */
  129. extern BOOL WINAPI
  130. CPAcquireContextW(
  131. OUT HCRYPTPROV *phProv,
  132. IN LPCWSTR szContainer,
  133. IN DWORD dwFlags,
  134. IN PVTableProvStrucW pVTable);
  135. /*
  136. - CPReleaseContext
  137. -
  138. * Purpose:
  139. * The CPReleaseContext function is used to release a
  140. * context created by CryptAcquireContext.
  141. *
  142. * Parameters:
  143. * IN phProv - Handle to a CSP
  144. * IN dwFlags - Flags values
  145. *
  146. * Returns:
  147. */
  148. extern BOOL WINAPI
  149. CPReleaseContext(
  150. IN HCRYPTPROV hProv,
  151. IN DWORD dwFlags);
  152. /*
  153. - CPGenKey
  154. -
  155. * Purpose:
  156. * Generate cryptographic keys
  157. *
  158. *
  159. * Parameters:
  160. * IN hProv - Handle to a CSP
  161. * IN Algid - Algorithm identifier
  162. * IN dwFlags - Flags values
  163. * OUT phKey - Handle to a generated key
  164. *
  165. * Returns:
  166. */
  167. extern BOOL WINAPI
  168. CPGenKey(
  169. IN HCRYPTPROV hProv,
  170. IN ALG_ID Algid,
  171. IN DWORD dwFlags,
  172. OUT HCRYPTKEY *phKey);
  173. /*
  174. - CPDeriveKey
  175. -
  176. * Purpose:
  177. * Derive cryptographic keys from base data
  178. *
  179. *
  180. * Parameters:
  181. * IN hProv - Handle to a CSP
  182. * IN Algid - Algorithm identifier
  183. * IN hBaseData - Handle to base data
  184. * IN dwFlags - Flags values
  185. * OUT phKey - Handle to a generated key
  186. *
  187. * Returns:
  188. */
  189. extern BOOL WINAPI
  190. CPDeriveKey(
  191. IN HCRYPTPROV hProv,
  192. IN ALG_ID Algid,
  193. IN HCRYPTHASH hHash,
  194. IN DWORD dwFlags,
  195. OUT HCRYPTKEY *phKey);
  196. /*
  197. - CPDestroyKey
  198. -
  199. * Purpose:
  200. * Destroys the cryptographic key that is being referenced
  201. * with the hKey parameter
  202. *
  203. *
  204. * Parameters:
  205. * IN hProv - Handle to a CSP
  206. * IN hKey - Handle to a key
  207. *
  208. * Returns:
  209. */
  210. extern BOOL WINAPI
  211. CPDestroyKey(
  212. IN HCRYPTPROV hProv,
  213. IN HCRYPTKEY hKey);
  214. /*
  215. - CPSetKeyParam
  216. -
  217. * Purpose:
  218. * Allows applications to customize various aspects of the
  219. * operations of a key
  220. *
  221. * Parameters:
  222. * IN hProv - Handle to a CSP
  223. * IN hKey - Handle to a key
  224. * IN dwParam - Parameter number
  225. * IN pbData - Pointer to data
  226. * IN dwFlags - Flags values
  227. *
  228. * Returns:
  229. */
  230. extern BOOL WINAPI
  231. CPSetKeyParam(
  232. IN HCRYPTPROV hProv,
  233. IN HCRYPTKEY hKey,
  234. IN DWORD dwParam,
  235. IN CONST BYTE *pbData,
  236. IN DWORD dwFlags);
  237. /*
  238. - CPGetKeyParam
  239. -
  240. * Purpose:
  241. * Allows applications to get various aspects of the
  242. * operations of a key
  243. *
  244. * Parameters:
  245. * IN hProv - Handle to a CSP
  246. * IN hKey - Handle to a key
  247. * IN dwParam - Parameter number
  248. * OUT pbData - Pointer to data
  249. * IN pdwDataLen - Length of parameter data
  250. * IN dwFlags - Flags values
  251. *
  252. * Returns:
  253. */
  254. extern BOOL WINAPI
  255. CPGetKeyParam(
  256. IN HCRYPTPROV hProv,
  257. IN HCRYPTKEY hKey,
  258. IN DWORD dwParam,
  259. OUT LPBYTE pbData,
  260. IN OUT LPDWORD pcbDataLen,
  261. IN DWORD dwFlags);
  262. /*
  263. - CPSetProvParam
  264. -
  265. * Purpose:
  266. * Allows applications to customize various aspects of the
  267. * operations of a provider
  268. *
  269. * Parameters:
  270. * IN hProv - Handle to a CSP
  271. * IN dwParam - Parameter number
  272. * IN pbData - Pointer to data
  273. * IN dwFlags - Flags values
  274. *
  275. * Returns:
  276. */
  277. extern BOOL WINAPI
  278. CPSetProvParam(
  279. IN HCRYPTPROV hProv,
  280. IN DWORD dwParam,
  281. IN CONST BYTE *pbData,
  282. IN DWORD dwFlags);
  283. /*
  284. - CPGetProvParam
  285. -
  286. * Purpose:
  287. * Allows applications to get various aspects of the
  288. * operations of a provider
  289. *
  290. * Parameters:
  291. * IN hProv - Handle to a CSP
  292. * IN dwParam - Parameter number
  293. * OUT pbData - Pointer to data
  294. * IN OUT pdwDataLen - Length of parameter data
  295. * IN dwFlags - Flags values
  296. *
  297. * Returns:
  298. */
  299. extern BOOL WINAPI
  300. CPGetProvParam(
  301. IN HCRYPTPROV hProv,
  302. IN DWORD dwParam,
  303. OUT LPBYTE pbData,
  304. IN OUT LPDWORD pcbDataLen,
  305. IN DWORD dwFlags);
  306. /*
  307. - CPSetHashParam
  308. -
  309. * Purpose:
  310. * Allows applications to customize various aspects of the
  311. * operations of a hash
  312. *
  313. * Parameters:
  314. * IN hProv - Handle to a CSP
  315. * IN hHash - Handle to a hash
  316. * IN dwParam - Parameter number
  317. * IN pbData - Pointer to data
  318. * IN dwFlags - Flags values
  319. *
  320. * Returns:
  321. */
  322. extern BOOL WINAPI
  323. CPSetHashParam(
  324. IN HCRYPTPROV hProv,
  325. IN HCRYPTHASH hHash,
  326. IN DWORD dwParam,
  327. IN CONST BYTE *pbData,
  328. IN DWORD dwFlags);
  329. /*
  330. - CPGetHashParam
  331. -
  332. * Purpose:
  333. * Allows applications to get various aspects of the
  334. * operations of a hash
  335. *
  336. * Parameters:
  337. * IN hProv - Handle to a CSP
  338. * IN hHash - Handle to a hash
  339. * IN dwParam - Parameter number
  340. * OUT pbData - Pointer to data
  341. * IN pdwDataLen - Length of parameter data
  342. * IN dwFlags - Flags values
  343. *
  344. * Returns:
  345. */
  346. extern BOOL WINAPI
  347. CPGetHashParam(
  348. IN HCRYPTPROV hProv,
  349. IN HCRYPTHASH hHash,
  350. IN DWORD dwParam,
  351. OUT LPBYTE pbData,
  352. IN OUT LPDWORD pcbDataLen,
  353. IN DWORD dwFlags);
  354. /*
  355. - CPExportKey
  356. -
  357. * Purpose:
  358. * Export cryptographic keys out of a CSP in a secure manner
  359. *
  360. *
  361. * Parameters:
  362. * IN hProv - Handle to the CSP user
  363. * IN hKey - Handle to the key to export
  364. * IN hPubKey - Handle to exchange public key value of
  365. * the destination user
  366. * IN dwBlobType - Type of key blob to be exported
  367. * IN dwFlags - Flags values
  368. * OUT pbData - Key blob data
  369. * IN OUT pdwDataLen - Length of key blob in bytes
  370. *
  371. * Returns:
  372. */
  373. extern BOOL WINAPI
  374. CPExportKey(
  375. IN HCRYPTPROV hProv,
  376. IN HCRYPTKEY hKey,
  377. IN HCRYPTKEY hPubKey,
  378. IN DWORD dwBlobType,
  379. IN DWORD dwFlags,
  380. OUT LPBYTE pbData,
  381. IN OUT LPDWORD pcbDataLen);
  382. /*
  383. - CPImportKey
  384. -
  385. * Purpose:
  386. * Import cryptographic keys
  387. *
  388. *
  389. * Parameters:
  390. * IN hProv - Handle to the CSP user
  391. * IN pbData - Key blob data
  392. * IN dwDataLen - Length of the key blob data
  393. * IN hPubKey - Handle to the exchange public key value of
  394. * the destination user
  395. * IN dwFlags - Flags values
  396. * OUT phKey - Pointer to the handle to the key which was
  397. * Imported
  398. *
  399. * Returns:
  400. */
  401. extern BOOL WINAPI
  402. CPImportKey(
  403. IN HCRYPTPROV hProv,
  404. IN CONST BYTE *pbData,
  405. IN DWORD cbDataLen,
  406. IN HCRYPTKEY hPubKey,
  407. IN DWORD dwFlags,
  408. OUT HCRYPTKEY *phKey);
  409. /*
  410. - CPEncrypt
  411. -
  412. * Purpose:
  413. * Encrypt data
  414. *
  415. *
  416. * Parameters:
  417. * IN hProv - Handle to the CSP user
  418. * IN hKey - Handle to the key
  419. * IN hHash - Optional handle to a hash
  420. * IN Final - Boolean indicating if this is the final
  421. * block of plaintext
  422. * IN dwFlags - Flags values
  423. * IN OUT pbData - Data to be encrypted
  424. * IN OUT pdwDataLen - Pointer to the length of the data to be
  425. * encrypted
  426. * IN dwBufLen - Size of Data buffer
  427. *
  428. * Returns:
  429. */
  430. extern BOOL WINAPI
  431. CPEncrypt(
  432. IN HCRYPTPROV hProv,
  433. IN HCRYPTKEY hKey,
  434. IN HCRYPTHASH hHash,
  435. IN BOOL fFinal,
  436. IN DWORD dwFlags,
  437. IN OUT LPBYTE pbData,
  438. IN OUT LPDWORD pcbDataLen,
  439. IN DWORD cbBufLen);
  440. /*
  441. - CPDecrypt
  442. -
  443. * Purpose:
  444. * Decrypt data
  445. *
  446. *
  447. * Parameters:
  448. * IN hProv - Handle to the CSP user
  449. * IN hKey - Handle to the key
  450. * IN hHash - Optional handle to a hash
  451. * IN Final - Boolean indicating if this is the final
  452. * block of ciphertext
  453. * IN dwFlags - Flags values
  454. * IN OUT pbData - Data to be decrypted
  455. * IN OUT pdwDataLen - Pointer to the length of the data to be
  456. * decrypted
  457. *
  458. * Returns:
  459. */
  460. extern BOOL WINAPI
  461. CPDecrypt(
  462. IN HCRYPTPROV hProv,
  463. IN HCRYPTKEY hKey,
  464. IN HCRYPTHASH hHash,
  465. IN BOOL fFinal,
  466. IN DWORD dwFlags,
  467. IN OUT LPBYTE pbData,
  468. IN OUT LPDWORD pcbDataLen);
  469. /*
  470. - CPCreateHash
  471. -
  472. * Purpose:
  473. * initate the hashing of a stream of data
  474. *
  475. *
  476. * Parameters:
  477. * IN hUID - Handle to the user identifcation
  478. * IN Algid - Algorithm identifier of the hash algorithm
  479. * to be used
  480. * IN hKey - Optional handle to a key
  481. * IN dwFlags - Flags values
  482. * OUT pHash - Handle to hash object
  483. *
  484. * Returns:
  485. */
  486. extern BOOL WINAPI
  487. CPCreateHash(
  488. IN HCRYPTPROV hProv,
  489. IN ALG_ID Algid,
  490. IN HCRYPTKEY hKey,
  491. IN DWORD dwFlags,
  492. OUT HCRYPTHASH *phHash);
  493. /*
  494. - CPHashData
  495. -
  496. * Purpose:
  497. * Compute the cryptograghic hash on a stream of data
  498. *
  499. *
  500. * Parameters:
  501. * IN hProv - Handle to the user identifcation
  502. * IN hHash - Handle to hash object
  503. * IN pbData - Pointer to data to be hashed
  504. * IN dwDataLen - Length of the data to be hashed
  505. * IN dwFlags - Flags values
  506. *
  507. * Returns:
  508. */
  509. extern BOOL WINAPI
  510. CPHashData(
  511. IN HCRYPTPROV hProv,
  512. IN HCRYPTHASH hHash,
  513. IN CONST BYTE *pbData,
  514. IN DWORD cbDataLen,
  515. IN DWORD dwFlags);
  516. /*
  517. - CPHashSessionKey
  518. -
  519. * Purpose:
  520. * Compute the cryptograghic hash on a key object.
  521. *
  522. *
  523. * Parameters:
  524. * IN hProv - Handle to the user identifcation
  525. * IN hHash - Handle to hash object
  526. * IN hKey - Handle to a key object
  527. * IN dwFlags - Flags values
  528. *
  529. * Returns:
  530. * CRYPT_FAILED
  531. * CRYPT_SUCCEED
  532. */
  533. extern BOOL WINAPI
  534. CPHashSessionKey(
  535. IN HCRYPTPROV hProv,
  536. IN HCRYPTHASH hHash,
  537. IN HCRYPTKEY hKey,
  538. IN DWORD dwFlags);
  539. /*
  540. - CPSignHash
  541. -
  542. * Purpose:
  543. * Create a digital signature from a hash
  544. *
  545. *
  546. * Parameters:
  547. * IN hProv - Handle to the user identifcation
  548. * IN hHash - Handle to hash object
  549. * IN dwKeySpec - Key pair to that is used to sign with
  550. * IN sDescription - Description of data to be signed
  551. * IN dwFlags - Flags values
  552. * OUT pbSignature - Pointer to signature data
  553. * IN OUT dwHashLen - Pointer to the len of the signature data
  554. *
  555. * Returns:
  556. */
  557. extern BOOL WINAPI
  558. CPSignHash(
  559. IN HCRYPTPROV hProv,
  560. IN HCRYPTHASH hHash,
  561. IN DWORD dwKeySpec,
  562. IN LPCWSTR szDescription,
  563. IN DWORD dwFlags,
  564. OUT LPBYTE pbSignature,
  565. IN OUT LPDWORD pcbSigLen);
  566. /*
  567. - CPDestroyHash
  568. -
  569. * Purpose:
  570. * Destroy the hash object
  571. *
  572. *
  573. * Parameters:
  574. * IN hProv - Handle to the user identifcation
  575. * IN hHash - Handle to hash object
  576. *
  577. * Returns:
  578. */
  579. extern BOOL WINAPI
  580. CPDestroyHash(
  581. IN HCRYPTPROV hProv,
  582. IN HCRYPTHASH hHash);
  583. /*
  584. - CPVerifySignature
  585. -
  586. * Purpose:
  587. * Used to verify a signature against a hash object
  588. *
  589. *
  590. * Parameters:
  591. * IN hProv - Handle to the user identifcation
  592. * IN hHash - Handle to hash object
  593. * IN pbSignture - Pointer to signature data
  594. * IN dwSigLen - Length of the signature data
  595. * IN hPubKey - Handle to the public key for verifying
  596. * the signature
  597. * IN sDescription - String describing the signed data
  598. * IN dwFlags - Flags values
  599. *
  600. * Returns:
  601. */
  602. extern BOOL WINAPI
  603. CPVerifySignature(
  604. IN HCRYPTPROV hProv,
  605. IN HCRYPTHASH hHash,
  606. IN CONST BYTE *pbSignature,
  607. IN DWORD cbSigLen,
  608. IN HCRYPTKEY hPubKey,
  609. IN LPCWSTR szDescription,
  610. IN DWORD dwFlags);
  611. /*
  612. - CPGenRandom
  613. -
  614. * Purpose:
  615. * Used to fill a buffer with random bytes
  616. *
  617. *
  618. * Parameters:
  619. * IN hProv - Handle to the user identifcation
  620. * IN dwLen - Number of bytes of random data requested
  621. * IN OUT pbBuffer - Pointer to the buffer where the random
  622. * bytes are to be placed
  623. *
  624. * Returns:
  625. */
  626. extern BOOL WINAPI
  627. CPGenRandom(
  628. IN HCRYPTPROV hProv,
  629. IN DWORD cbLen,
  630. OUT LPBYTE pbBuffer);
  631. /*
  632. - CPGetUserKey
  633. -
  634. * Purpose:
  635. * Gets a handle to a permanent user key
  636. *
  637. *
  638. * Parameters:
  639. * IN hProv - Handle to the user identifcation
  640. * IN dwKeySpec - Specification of the key to retrieve
  641. * OUT phUserKey - Pointer to key handle of retrieved key
  642. *
  643. * Returns:
  644. */
  645. extern BOOL WINAPI
  646. CPGetUserKey(
  647. IN HCRYPTPROV hProv,
  648. IN DWORD dwKeySpec,
  649. OUT HCRYPTKEY *phUserKey);
  650. /*
  651. - CPDuplicateHash
  652. -
  653. * Purpose:
  654. * Duplicates the state of a hash and returns a handle to it.
  655. * This is an optional entry. Typically it only occurs in
  656. * SChannel related CSPs.
  657. *
  658. * Parameters:
  659. * IN hUID - Handle to a CSP
  660. * IN hHash - Handle to a hash
  661. * IN pdwReserved - Reserved
  662. * IN dwFlags - Flags
  663. * IN phHash - Handle to the new hash
  664. *
  665. * Returns:
  666. */
  667. extern BOOL WINAPI
  668. CPDuplicateHash(
  669. IN HCRYPTPROV hProv,
  670. IN HCRYPTHASH hHash,
  671. IN LPDWORD pdwReserved,
  672. IN DWORD dwFlags,
  673. OUT HCRYPTHASH *phHash);
  674. /*
  675. - CPDuplicateKey
  676. -
  677. * Purpose:
  678. * Duplicates the state of a key and returns a handle to it.
  679. * This is an optional entry. Typically it only occurs in
  680. * SChannel related CSPs.
  681. *
  682. * Parameters:
  683. * IN hUID - Handle to a CSP
  684. * IN hKey - Handle to a key
  685. * IN pdwReserved - Reserved
  686. * IN dwFlags - Flags
  687. * IN phKey - Handle to the new key
  688. *
  689. * Returns:
  690. */
  691. extern BOOL WINAPI
  692. CPDuplicateKey(
  693. IN HCRYPTPROV hProv,
  694. IN HCRYPTKEY hKey,
  695. IN LPDWORD pdwReserved,
  696. IN DWORD dwFlags,
  697. OUT HCRYPTKEY *phKey);
  698. #ifdef __cplusplus
  699. }
  700. #endif
  701. #endif // _CSPDK_H_