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.

404 lines
11 KiB

  1. #ifndef __INTEROP__H__
  2. #define __INTEROP__H__
  3. #include <windows.h>
  4. #include <wincrypt.h>
  5. #include "csptestsuite.h"
  6. //
  7. // Function: ExportAndImportKey
  8. // Purpose: Export the source key into the provided
  9. // data blob.
  10. //
  11. BOOL ExportPublicKey(
  12. IN HCRYPTKEY hSourceKey,
  13. OUT PDATA_BLOB pdbKey,
  14. IN PTESTCASE ptc);
  15. //
  16. // Struct: HASH_INFO
  17. // Purpose: Provide information on the data and algorithm used in
  18. // a hash context.
  19. //
  20. typedef struct _HASH_INFO
  21. {
  22. ALG_ID aiHash;
  23. DATA_BLOB dbBaseData;
  24. DATA_BLOB dbHashValue;
  25. } HASH_INFO, *PHASH_INFO;
  26. //
  27. // Function: CreateHashAndAddData
  28. // Purpose: Using the provided cryptographic context, create
  29. // a new hash object of the provided hash algorithm. Add the
  30. // specified data to the hash.
  31. //
  32. BOOL CreateHashAndAddData(
  33. IN HCRYPTPROV hProv,
  34. OUT HCRYPTHASH *phHash,
  35. IN PHASH_INFO pHashInfo,
  36. IN PTESTCASE ptc,
  37. IN HCRYPTKEY hKey,
  38. IN PHMAC_INFO pHmacInfo);
  39. //
  40. // Function: ExportPlaintextSessionKey
  41. // Purpose: Use RSA private key with exponent of one to export the provided
  42. // session key. This will cause the key to actually be unencrypted.
  43. //
  44. // Method described in MSDN KB article Q228786 (exporting a plain-text
  45. // session key).
  46. //
  47. BOOL ExportPlaintextSessionKey(
  48. IN HCRYPTKEY hKey,
  49. IN HCRYPTPROV hProv,
  50. OUT PDATA_BLOB pdbKey,
  51. IN PTESTCASE ptc);
  52. //
  53. // Function: ImportPlaintextSessionKey
  54. // Purpose: Use an RSA private key with exponent of one to import
  55. // the session key in the provided data blob. Return the resulting
  56. // key context.
  57. //
  58. BOOL ImportPlaintextSessionKey(
  59. IN PDATA_BLOB pdbKey,
  60. OUT HCRYPTKEY *phKey,
  61. IN HCRYPTPROV hProv,
  62. IN PTESTCASE ptc);
  63. //
  64. // Struct: MAC_INFO
  65. // Purpose: Provide information on the data used to produce a keyed
  66. // hash value (a MAC).
  67. //
  68. typedef struct TEST_MAC_INFO
  69. {
  70. //
  71. // Defined in wincrypt.h
  72. //
  73. HMAC_INFO HmacInfo;
  74. DATA_BLOB dbKey;
  75. } TEST_MAC_INFO, *PTEST_MAC_INFO;
  76. //
  77. // Function: CheckHashedData
  78. // Purpose: Use the provided cryptographic context parameter, hProv,
  79. // to reproduce a hash-value based on provided information.
  80. //
  81. BOOL CheckHashedData(
  82. IN PHASH_INFO pHashInfo,
  83. IN HCRYPTPROV hProv,
  84. IN PTESTCASE ptc,
  85. IN PTEST_MAC_INFO pTestMacInfo);
  86. //
  87. // Struct: DERIVED_KEY_INFO
  88. // Purpose: Provide information on the procedure used to produce a
  89. // derived session key.
  90. //
  91. typedef struct _DERIVED_KEY_INFO
  92. {
  93. HASH_INFO HashInfo;
  94. ALG_ID aiKey;
  95. DWORD dwKeySize;
  96. DATA_BLOB dbKey;
  97. //
  98. // Debugging
  99. //
  100. BYTE rgbHashValA[1024];
  101. DWORD cbHA;
  102. BYTE rgbHashValB[1024];
  103. DWORD cbHB;
  104. BYTE rgbCipherA[1024];
  105. DWORD cbCA;
  106. BYTE rgbCipherB[1024];
  107. DWORD cbCB;
  108. } DERIVED_KEY_INFO, *PDERIVED_KEY_INFO;
  109. //
  110. // Function: CheckDerivedKey
  111. // Purpose: Use the provided cryptographic context parameter, hProv, to
  112. // attempt to reproduce a derived session key using information provided
  113. // in the pDerivedKeyInfo struct. Report any failures using data
  114. // in the ptc parameter.
  115. //
  116. BOOL CheckDerivedKey(
  117. IN PDERIVED_KEY_INFO pDerivedKeyInfo,
  118. IN HCRYPTPROV hProv,
  119. IN PTESTCASE ptc);
  120. //
  121. // Struct: SIGNED_DATA_INFO
  122. // Purpose: Provide information on the procedure used to produce
  123. // hash-based RSA signature.
  124. //
  125. typedef struct _SIGNED_DATA_INFO
  126. {
  127. HASH_INFO HashInfo;
  128. DATA_BLOB dbSignature;
  129. DATA_BLOB dbPublicKey;
  130. } SIGNED_DATA_INFO, *PSIGNED_DATA_INFO;
  131. //
  132. // Function: CheckSignedData
  133. // Purpose: Use the provided cryptographic context, hProv,
  134. // to reproduce an RSA signature based on information
  135. // provided in the pSignedDataInfo struct.
  136. //
  137. BOOL CheckSignedData(
  138. IN PSIGNED_DATA_INFO pSignedDataInfo,
  139. IN HCRYPTPROV hProv,
  140. IN PTESTCASE ptc);
  141. //
  142. // -------------------------------------------------------
  143. // Defines for testing symmetric Encryption and Decryption
  144. // -------------------------------------------------------
  145. //
  146. #define MAXIMUM_SESSION_KEY_LEN 128
  147. #define DEFAULT_SALT_LEN 64
  148. #define CIPHER_BLOCKS_PER_ROUND 2
  149. #define BLOCKS_IN_BASE_DATA 5
  150. #define STREAM_CIPHER_BASE_DATA_LEN 999
  151. typedef enum _CIPHER_OP
  152. {
  153. OP_Encrypt,
  154. OP_Decrypt
  155. } CIPHER_OP;
  156. //
  157. // Struct: TEST_ENCRYPT_INFO
  158. // Purpose: Provide information about the data being used to
  159. // test data encryption/decryption with a session key.
  160. //
  161. typedef struct _TEST_ENCRYPT_INFO
  162. {
  163. //
  164. // These parameters must be set by the caller
  165. //
  166. ALG_ID aiKeyAlg;
  167. DWORD dwKeySize;
  168. BOOL fUseSalt;
  169. BOOL fSetIV;
  170. BOOL fSetMode;
  171. DWORD dwMode;
  172. //
  173. // These parameters are set by the ProcessCipherData
  174. // function.
  175. //
  176. DWORD cbBlockLen;
  177. DATA_BLOB dbSalt;
  178. PBYTE pbIV;
  179. DATA_BLOB dbBaseData;
  180. DATA_BLOB dbProcessedData;
  181. DATA_BLOB dbKey;
  182. CIPHER_OP Operation;
  183. } TEST_ENCRYPT_INFO, *PTEST_ENCRYPT_INFO;
  184. //
  185. // Function: ProcessCipherData
  186. // Purpose: Based on the information provided in the
  187. // pTestEncryptInfo struct, perform the following steps:
  188. //
  189. // 1) generate a symmetric key of the requested size and alg
  190. // 2) set the appropriate key parameters
  191. // 3) generate some random base data to be processed
  192. // 4) perform the encryption or decryption
  193. // 5) export the key in plaintext
  194. //
  195. BOOL ProcessCipherData(
  196. IN HCRYPTPROV hProvA,
  197. IN OUT PTEST_ENCRYPT_INFO pTestEncryptInfo,
  198. IN PTESTCASE ptc);
  199. //
  200. // Function: VerifyCipherData
  201. // Purpose: Verify that the data produced by ProcessCipherData
  202. // can be correctly processed using the opposite cryptographic
  203. // operation with a different CSP. In other words, if the requested
  204. // operation was Encrypt, verify that the data can be correctly decrypted, etc.
  205. //
  206. BOOL VerifyCipherData(
  207. IN HCRYPTPROV hProvB,
  208. IN PTEST_ENCRYPT_INFO pTestEncryptInfo,
  209. IN PTESTCASE ptc);
  210. //
  211. // ---------------------------------------
  212. // Defines for testing hashed session keys
  213. // ---------------------------------------
  214. //
  215. //
  216. // Struct: HASH_SESSION_INFO
  217. // Purpose: Provide data for creating and hashing a session key of the
  218. // specified type, and verifying the resulting key using a second
  219. // CSP.
  220. //
  221. typedef struct _HASH_SESSION_INFO
  222. {
  223. ALG_ID aiKey;
  224. DWORD dwKeySize;
  225. ALG_ID aiHash;
  226. DATA_BLOB dbKey;
  227. DATA_BLOB dbHash;
  228. DWORD dwFlags;
  229. } HASH_SESSION_INFO, *PHASH_SESSION_INFO;
  230. //
  231. // Function: CreateHashedSessionKey
  232. // Purpose: Create a session key of the specified size and type.
  233. // Hash the session key with CryptHashSessionKey. Export the
  234. // key in plaintext. Export the hash value.
  235. //
  236. BOOL CreateHashedSessionKey(
  237. IN HCRYPTPROV hProv,
  238. IN OUT PHASH_SESSION_INFO pHashSessionInfo,
  239. IN PTESTCASE ptc);
  240. //
  241. // Function: VerifyHashedSessionKey
  242. // Purpose: Import the plaintext session key into a separate CSP.
  243. // Hash the session key with CryptHashSessionKey. Verify
  244. // the resulting hash value.
  245. //
  246. BOOL VerifyHashedSessionKey(
  247. IN HCRYPTPROV hInteropProv,
  248. IN PHASH_SESSION_INFO pHashSessionInfo,
  249. IN PTESTCASE ptc);
  250. //
  251. // ---------------------------------------------
  252. // Defines for testing RSA key exchange scenario
  253. // ---------------------------------------------
  254. //
  255. //
  256. // Struct: KEYEXCHANGE_INFO
  257. // Purpose: Provide static information used for initiating an RSA
  258. // public key-, session key-, and data-exchange scenario involving two
  259. // users.
  260. //
  261. typedef struct _KEYEXCHANGE_INFO
  262. {
  263. DATA_BLOB dbPlainText;
  264. DWORD dwPubKeySize;
  265. DWORD dwSessionKeySize;
  266. ALG_ID aiSessionKey;
  267. ALG_ID aiHash;
  268. } KEYEXCHANGE_INFO, *PKEYEXCHANGE_INFO;
  269. //
  270. // Struct: KEYEXCHANGE_STATE
  271. // Purpose: Provide state information used to track the progress of an
  272. // RSA key and encrypted data exchange scenario involving two users,
  273. // A and B.
  274. //
  275. typedef struct _KEYEXCHANGE_STATE
  276. {
  277. DATA_BLOB dbPubKeyA;
  278. DATA_BLOB dbPubKeyB;
  279. DATA_BLOB dbEncryptedSessionKeyB;
  280. DATA_BLOB dbSignatureB;
  281. DATA_BLOB dbCipherTextB;
  282. } KEYEXCHANGE_STATE, *PKEYEXCHANGE_STATE;
  283. //
  284. // Function: RSA1_CreateKeyPair
  285. // Purpose: The first step of the RSA key exchange scenario.
  286. // User A creates a key pair and exports the public key.
  287. //
  288. BOOL RSA1_CreateKeyPair(
  289. IN HCRYPTPROV hProvA,
  290. IN PKEYEXCHANGE_INFO pKeyExchangeInfo,
  291. OUT PKEYEXCHANGE_STATE pKeyExchangeState,
  292. IN PTESTCASE ptc);
  293. //
  294. // Function: RSA2_EncryptPlainText
  295. // Purpose: The second step of the RSA key exchange scenario.
  296. // User B first creates a signature key pair and signs
  297. // the plain text message. User B then
  298. // creates a session key and encrypts the plain text.
  299. // User A's public key is then used to encrypt the session key.
  300. //
  301. BOOL RSA2_EncryptPlainText(
  302. IN HCRYPTPROV hProvB,
  303. IN PKEYEXCHANGE_INFO pKeyExchangeInfo,
  304. IN OUT PKEYEXCHANGE_STATE pKeyExchangeState,
  305. IN PTESTCASE ptc);
  306. //
  307. // Function: RSA3_DecryptAndCheck
  308. // Purpose: The third and final step of the RSA key exchange scenario.
  309. // User A decrypts the session key from User B. User A uses the session
  310. // key to decrypt the cipher text and uses User B's public key to verify
  311. // the signature.
  312. //
  313. BOOL RSA3_DecryptAndCheck(
  314. IN HCRYPTPROV hProvA,
  315. IN PKEYEXCHANGE_INFO pKeyExchangeInfo,
  316. IN PKEYEXCHANGE_STATE pKeyExchangeState,
  317. IN PTESTCASE ptc);
  318. //
  319. // Private key with exponent of one.
  320. //
  321. static BYTE PrivateKeyWithExponentOfOne[] =
  322. {
  323. 0x07, 0x02, 0x00, 0x00, 0x00, 0xA4, 0x00, 0x00,
  324. 0x52, 0x53, 0x41, 0x32, 0x00, 0x02, 0x00, 0x00,
  325. 0x01, 0x00, 0x00, 0x00, 0xAB, 0xEF, 0xFA, 0xC6,
  326. 0x7D, 0xE8, 0xDE, 0xFB, 0x68, 0x38, 0x09, 0x92,
  327. 0xD9, 0x42, 0x7E, 0x6B, 0x89, 0x9E, 0x21, 0xD7,
  328. 0x52, 0x1C, 0x99, 0x3C, 0x17, 0x48, 0x4E, 0x3A,
  329. 0x44, 0x02, 0xF2, 0xFA, 0x74, 0x57, 0xDA, 0xE4,
  330. 0xD3, 0xC0, 0x35, 0x67, 0xFA, 0x6E, 0xDF, 0x78,
  331. 0x4C, 0x75, 0x35, 0x1C, 0xA0, 0x74, 0x49, 0xE3,
  332. 0x20, 0x13, 0x71, 0x35, 0x65, 0xDF, 0x12, 0x20,
  333. 0xF5, 0xF5, 0xF5, 0xC1, 0xED, 0x5C, 0x91, 0x36,
  334. 0x75, 0xB0, 0xA9, 0x9C, 0x04, 0xDB, 0x0C, 0x8C,
  335. 0xBF, 0x99, 0x75, 0x13, 0x7E, 0x87, 0x80, 0x4B,
  336. 0x71, 0x94, 0xB8, 0x00, 0xA0, 0x7D, 0xB7, 0x53,
  337. 0xDD, 0x20, 0x63, 0xEE, 0xF7, 0x83, 0x41, 0xFE,
  338. 0x16, 0xA7, 0x6E, 0xDF, 0x21, 0x7D, 0x76, 0xC0,
  339. 0x85, 0xD5, 0x65, 0x7F, 0x00, 0x23, 0x57, 0x45,
  340. 0x52, 0x02, 0x9D, 0xEA, 0x69, 0xAC, 0x1F, 0xFD,
  341. 0x3F, 0x8C, 0x4A, 0xD0,
  342. 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  343. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  344. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  345. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  346. 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  347. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  348. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  349. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  350. 0x64, 0xD5, 0xAA, 0xB1,
  351. 0xA6, 0x03, 0x18, 0x92, 0x03, 0xAA, 0x31, 0x2E,
  352. 0x48, 0x4B, 0x65, 0x20, 0x99, 0xCD, 0xC6, 0x0C,
  353. 0x15, 0x0C, 0xBF, 0x3E, 0xFF, 0x78, 0x95, 0x67,
  354. 0xB1, 0x74, 0x5B, 0x60,
  355. 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  356. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  357. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  358. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  359. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  360. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  361. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  362. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  363. };
  364. #endif