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.

501 lines
17 KiB

  1. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Microsoft Windows, Copyright (C) Microsoft Corporation, 2000
  3. File: Common.h
  4. Content: Declaration of Common.
  5. History: 11-15-99 dsie created
  6. ------------------------------------------------------------------------------*/
  7. #ifndef __COMMON_H_
  8. #define __COMMON_H_
  9. #include "Debug.h"
  10. ////////////////////
  11. //
  12. // typedefs
  13. //
  14. typedef enum osVersion
  15. {
  16. OS_WIN_UNKNOWN = 0,
  17. OS_WIN_32s = 1,
  18. OS_WIN_9X = 2,
  19. OS_WIN_ME = 3,
  20. OS_WIN_NT3_5 = 4,
  21. OS_WIN_NT4 = 5,
  22. OS_WIN_2K = 6,
  23. OS_WIN_XP = 7,
  24. OS_WIN_ABOVE_XP = 8,
  25. } OSVERSION, * POSVERSION;
  26. extern LPSTR g_rgpszOSNames[];
  27. ////////////////////
  28. //
  29. // macros
  30. //
  31. #define IsWinNTAndAbove() (GetOSVersion() >= OS_WIN_NT4)
  32. #define IsWin2KAndAbove() (GetOSVersion() >= OS_WIN_2K)
  33. #define IsWinXPAndAbove() (GetOSVersion() >= OS_WIN_XP)
  34. #define OSName() (g_rgpszOSNames[GetOSVersion()])
  35. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  36. Function : GetOSVersion
  37. Synopsis : Get the current OS platform/version.
  38. Parameter: None.
  39. Remark :
  40. ------------------------------------------------------------------------------*/
  41. OSVERSION GetOSVersion ();
  42. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  43. Function : EncodeObject
  44. Synopsis : Allocate memory and encode an ASN.1 object using CAPI
  45. CryptEncodeObject() API.
  46. Parameter: LPCSRT pszStructType - see MSDN document for possible
  47. types.
  48. LPVOID pbData - Pointer to data to be encoded
  49. (data type must match
  50. pszStrucType).
  51. CRYPT_DATA_BLOB * pEncodedBlob - Pointer to CRYPT_DATA_BLOB to
  52. receive the encoded length and
  53. data.
  54. Remark : No parameter check is done.
  55. ------------------------------------------------------------------------------*/
  56. HRESULT EncodeObject (LPCSTR pszStructType,
  57. LPVOID pbData,
  58. CRYPT_DATA_BLOB * pEncodedBlob);
  59. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  60. Function : DecodeObject
  61. Synopsis : Allocate memory and decode an ASN.1 object using CAPI
  62. CryptDecodeObject() API.
  63. Parameter: LPCSRT pszStructType - see MSDN document for possible
  64. types.
  65. BYTE * pbEncoded - Pointer to data to be decoded
  66. (data type must match
  67. pszStructType).
  68. DWORD cbEncoded - Size of encoded data.
  69. CRYPT_DATA_BLOB * pDecodedBlob - Pointer to CRYPT_DATA_BLOB to
  70. receive the decoded length and
  71. data.
  72. Remark : No parameter check is done.
  73. ------------------------------------------------------------------------------*/
  74. HRESULT DecodeObject (LPCSTR pszStructType,
  75. BYTE * pbEncoded,
  76. DWORD cbEncoded,
  77. CRYPT_DATA_BLOB * pDecodedBlob);
  78. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  79. Function : GetKeyParam
  80. Synopsis : Allocate memory and retrieve requested key parameter using
  81. CryptGetKeyParam() API.
  82. Parameter: HCRYPTKEY hKey - Key handler.
  83. DWORD dwParam - Key parameter query.
  84. BYTE ** ppbData - Pointer to receive buffer.
  85. DWORD * pcbData - Size of buffer.
  86. Remark :
  87. ------------------------------------------------------------------------------*/
  88. HRESULT GetKeyParam (HCRYPTKEY hKey,
  89. DWORD dwParam,
  90. BYTE ** ppbData,
  91. DWORD * pcbData);
  92. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  93. Function : IsAlgSupported
  94. Synopsis : Check to see if the algo is supported by the CSP.
  95. Parameter: HCRYPTPROV hCryptProv - CSP handle.
  96. ALG_ID AlgId - Algorithm ID.
  97. PROV_ENUMALGS_EX * pPeex - Pointer to PROV_ENUMALGS_EX to receive
  98. the found structure.
  99. Remark :
  100. ------------------------------------------------------------------------------*/
  101. HRESULT IsAlgSupported (HCRYPTPROV hCryptProv,
  102. ALG_ID AlgId,
  103. PROV_ENUMALGS_EX * pPeex);
  104. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  105. Function : IsAlgKeyLengthSupported
  106. Synopsis : Check to see if the algo and key length is supported by the CSP.
  107. Parameter: HCRYPTPROV hCryptProv - CSP handle.
  108. ALG_ID AlgID - Algorithm ID.
  109. DWORD dwKeyLength - Key length
  110. Remark :
  111. ------------------------------------------------------------------------------*/
  112. HRESULT IsAlgKeyLengthSupported (HCRYPTPROV hCryptProv,
  113. ALG_ID AlgID,
  114. DWORD dwKeyLength);
  115. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  116. Function : AcquireContext
  117. Synopsis : Acquire context for the specified CSP and keyset container.
  118. Parameter: LPSTR pszProvider - CSP provider name or NULL.
  119. LPSTR pszContainer - Keyset container name or NULL.
  120. DWORD dwProvType - Provider type.
  121. DWORD dwFlags - Same as dwFlags of CryptAcquireConext.
  122. BOOL bNewKeyset - TRUE to create new keyset container, else FALSE.
  123. HCRYPTPROV * phCryptProv - Pointer to HCRYPTPROV to recevice
  124. CSP context.
  125. Remark :
  126. ------------------------------------------------------------------------------*/
  127. HRESULT AcquireContext(LPSTR pszProvider,
  128. LPSTR pszContainer,
  129. DWORD dwProvType,
  130. DWORD dwFlags,
  131. BOOL bNewKeyset,
  132. HCRYPTPROV * phCryptProv);
  133. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  134. Function : AcquireContext
  135. Synopsis : Acquire context for the specified CSP and keyset container.
  136. Parameter: LPWSTR pwszProvider - CSP provider name or NULL.
  137. LPWSTR pwszContainer - Keyset container name or NULL.
  138. DWORD dwProvType - Provider type.
  139. DWORD dwFlags - Same as dwFlags of CryptAcquireConext.
  140. BOOL bNewKeyset - TRUE to create new keyset container, else FALSE.
  141. HCRYPTPROV * phCryptProv - Pointer to HCRYPTPROV to recevice
  142. CSP context.
  143. Remark :
  144. ------------------------------------------------------------------------------*/
  145. HRESULT AcquireContext(LPWSTR pwszProvider,
  146. LPWSTR pwszContainer,
  147. DWORD dwProvType,
  148. DWORD dwFlags,
  149. BOOL bNewKeyset,
  150. HCRYPTPROV * phCryptProv);
  151. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  152. Function : AcquireContext
  153. Synopsis : Acquire context of a CSP using the default container for a
  154. specified hash algorithm.
  155. Parameter: ALG_ID AlgOID - Algorithm ID.
  156. HCRYPTPROV * phCryptProv - Pointer to HCRYPTPROV to recevice
  157. CSP context.
  158. Remark : Note that KeyLength will be ignored for DES and 3DES.
  159. ------------------------------------------------------------------------------*/
  160. HRESULT AcquireContext(ALG_ID AlgID,
  161. HCRYPTPROV * phCryptProv);
  162. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  163. Function : AcquireContext
  164. Synopsis : Acquire context of a CSP using the default container for a
  165. specified algorithm and desired key length.
  166. Parameter: ALG_ID AlgOID - Algorithm ID.
  167. DWORD dwKeyLength - Key length.
  168. HCRYPTPROV * phCryptProv - Pointer to HCRYPTPROV to recevice
  169. CSP context.
  170. Remark : Note that KeyLength will be ignored for DES and 3DES.
  171. ------------------------------------------------------------------------------*/
  172. HRESULT AcquireContext (ALG_ID AlgID,
  173. DWORD dwKeyLength,
  174. HCRYPTPROV * phCryptProv);
  175. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  176. Function : AcquireContext
  177. Synopsis : Acquire context of a CSP using the default container for a
  178. specified algorithm and desired key length.
  179. Parameter: CAPICOM_ENCRYPTION_ALGORITHM AlgoName - Algorithm name.
  180. CAPICOM_ENCRYPTION_KEY_LENGTH KeyLength - Key length.
  181. HCRYPTPROV * phCryptProv - Pointer to HCRYPTPROV to recevice
  182. CSP context.
  183. Remark : Note that KeyLength will be ignored for DES and 3DES.
  184. Note also the the returned handle cannot be used to access private
  185. key, and should NOT be used to store assymetric key, as it refers
  186. to the default container, which can be easily destroy any existing
  187. assymetric key pair.
  188. ------------------------------------------------------------------------------*/
  189. HRESULT AcquireContext (CAPICOM_ENCRYPTION_ALGORITHM AlgoName,
  190. CAPICOM_ENCRYPTION_KEY_LENGTH KeyLength,
  191. HCRYPTPROV * phCryptProv);
  192. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  193. Function : AcquireContext
  194. Synopsis : Acquire the proper CSP and access to the private key for
  195. the specified cert.
  196. Parameter: PCCERT_CONTEXT pCertContext - Pointer to CERT_CONTEXT of cert.
  197. HCRYPTPROV * phCryptProv - Pointer to HCRYPTPROV to recevice
  198. CSP context.
  199. DWORD * pdwKeySpec - Pointer to DWORD to receive key
  200. spec, AT_KEYEXCHANGE or AT_SIGNATURE.
  201. BOOL * pbReleaseContext - Upon successful and if this is set
  202. to TRUE, then the caller must
  203. free the CSP context by calling
  204. CryptReleaseContext(), otherwise
  205. the caller must not free the CSP
  206. context.
  207. Remark :
  208. ------------------------------------------------------------------------------*/
  209. HRESULT AcquireContext (PCCERT_CONTEXT pCertContext,
  210. HCRYPTPROV * phCryptProv,
  211. DWORD * pdwKeySpec,
  212. BOOL * pbReleaseContext);
  213. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  214. Function : ReleaseContext
  215. Synopsis : Release CSP context.
  216. Parameter: HCRYPTPROV hProv - CSP handle.
  217. Remark :
  218. ------------------------------------------------------------------------------*/
  219. HRESULT ReleaseContext (HCRYPTPROV hProv);
  220. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  221. Function : OIDToAlgID
  222. Synopsis : Convert algorithm OID to the corresponding ALG_ID value.
  223. Parameter: LPSTR pszAlgoOID - Algorithm OID string.
  224. ALG_ID * pAlgID - Pointer to ALG_ID to receive the value.
  225. Remark :
  226. ------------------------------------------------------------------------------*/
  227. HRESULT OIDToAlgID (LPSTR pszAlgoOID,
  228. ALG_ID * pAlgID);
  229. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  230. Function : AlgIDToOID
  231. Synopsis : Convert ALG_ID value to the corresponding algorithm OID.
  232. Parameter: ALG_ID AlgID - ALG_ID to be converted.
  233. LPSTR * ppszAlgoOID - Pointer to LPSTR to receive the OID string.
  234. Remark :
  235. ------------------------------------------------------------------------------*/
  236. HRESULT AlgIDToOID (ALG_ID AlgID,
  237. LPSTR * ppszAlgoOID);
  238. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  239. Function : AlgIDToEnumName
  240. Synopsis : Convert ALG_ID value to the corresponding algorithm enum name.
  241. Parameter: ALG_ID AlgID - ALG_ID to be converted.
  242. CAPICOM_ENCRYPTION_ALGORITHM * pAlgoName - Receive algo enum name.
  243. Remark :
  244. ------------------------------------------------------------------------------*/
  245. HRESULT AlgIDToEnumName (ALG_ID AlgID,
  246. CAPICOM_ENCRYPTION_ALGORITHM * pAlgoName);
  247. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  248. Function : EnumNameToAlgID
  249. Synopsis : Convert algorithm enum name to the corresponding ALG_ID value.
  250. Parameter: CAPICOM_ENCRYPTION_ALGORITHM AlgoName - Algo enum name.
  251. CAPICOM_ENCRYPTION_KEY_LENGTH KeyLength - Key length.
  252. ALG_ID * pAlgID - Pointer to ALG_ID to receive the value.
  253. Remark :
  254. ------------------------------------------------------------------------------*/
  255. HRESULT EnumNameToAlgID (CAPICOM_ENCRYPTION_ALGORITHM AlgoName,
  256. CAPICOM_ENCRYPTION_KEY_LENGTH KeyLength,
  257. ALG_ID * pAlgID);
  258. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  259. Function : KeyLengthToEnumName
  260. Synopsis : Convert actual key length value to the corresponding key length
  261. enum name.
  262. Parameter: DWORD dwKeyLength - Key length.
  263. ALG_ID AlgId - Algo ID.
  264. CAPICOM_ENCRYPTION_KEY_LENGTH * pKeyLengthName - Receive key length
  265. enum name.
  266. Remark :
  267. ------------------------------------------------------------------------------*/
  268. HRESULT KeyLengthToEnumName (DWORD dwKeyLength,
  269. ALG_ID AlgId,
  270. CAPICOM_ENCRYPTION_KEY_LENGTH * pKeyLengthName);
  271. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  272. Function : EnumNameToKeyLength
  273. Synopsis : Convert key length enum name to the corresponding actual key length
  274. value .
  275. Parameter: CAPICOM_ENCRYPTION_KEY_LENGTH KeyLengthName - Key length enum name.
  276. ALG_ID AlgId - Algorithm ID.
  277. DWORD * pdwKeyLength - Pointer to DWORD to receive value.
  278. Remark :
  279. ------------------------------------------------------------------------------*/
  280. HRESULT EnumNameToKeyLength (CAPICOM_ENCRYPTION_KEY_LENGTH KeyLengthName,
  281. ALG_ID AlgId,
  282. DWORD * pdwKeyLength);
  283. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  284. Function : IsDiskFile
  285. Synopsis : Check if a the file name represents a disk file.
  286. Parameter: LPWSTR pwszFileName - File name.
  287. Remark :
  288. ------------------------------------------------------------------------------*/
  289. HRESULT IsDiskFile (LPWSTR pwszFileName);
  290. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  291. Function : ReadFileContent
  292. Synopsis : Read all bytes from the specified file.
  293. Parameter: LPWSTR pwszFileName
  294. DATA_BLOB * pDataBlob
  295. Remark :
  296. ------------------------------------------------------------------------------*/
  297. HRESULT ReadFileContent (LPWSTR pwszFileName,
  298. DATA_BLOB * pDataBlob);
  299. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  300. Function : WriteFileContent
  301. Synopsis : Write all bytes of blob to the specified file.
  302. Parameter: LPWSTR pwszFileName - File name.
  303. DATA_BLOB DataBlob - Blob to be written.
  304. Remark :
  305. ------------------------------------------------------------------------------*/
  306. HRESULT WriteFileContent(LPCWSTR pwszFileName,
  307. DATA_BLOB DataBlob);
  308. #endif //__COMMON_H_