Source code of Windows XP (NT5)
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.

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