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.

305 lines
7.9 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1996 - 1999
  6. //
  7. // File: redir.h
  8. //
  9. //--------------------------------------------------------------------------
  10. #ifndef _REDIR_H_
  11. #define _REDIR_H_
  12. /*
  13. Dev Notes:
  14. To define a redirected provider, call FDefineProvTypeFuncPointers(...).
  15. Any hProv, hKey, or hHash created using that dwProvType after will
  16. be redirected. Any provider not in the list of redirected providers
  17. will fall through to CAPI. ReDir's handles are fully compatible with
  18. direct calls to CAPI.
  19. You are not required to undefine a provider you define -- ReDir will
  20. clean up the table during PROCESS_DETACH. However, if you
  21. wish to clean up a dwProvType you previously defined, call
  22. FUndefineProvTypeFuncPointers(...).
  23. WARNING:
  24. Reference counting is not applied to the defined providers. That
  25. is, if you remove a provider definition and then attempt to use
  26. an {hKey, hProv, hHash} that was used with that provider, ReDir will
  27. not have a valid function table.
  28. MultiThreading:
  29. Critical sections are applied to all functions where necessary, and
  30. this library should be fully multithread-safe.
  31. CryptSetProvider availability:
  32. CryptSetProvider{A,W} is not available to non-CAPI providers. The
  33. functions return FALSE if not pointing to AdvAPI's CAPI.
  34. Wide char APIs:
  35. Win95 doesn't support Wide APIs, and real ADVAPI doesn't export them.
  36. Thus, the easiest thing to do was to not try an load them, in any case.
  37. This means ReDir doesn't support the Wide APIs, even on NT. Could change
  38. to use an OS check before loading...?
  39. */
  40. // to allow us to see both W and A versions of APIs, don't
  41. // force us away from either just yet...
  42. #ifndef _ADVAPI32_
  43. #define WINADVAPI DECLSPEC_IMPORT
  44. #endif
  45. // wincrypt func prototypes; other func prototypes at EOF
  46. #include "wincrypt.h"
  47. // Some CryptoAPI typedefs
  48. typedef WINADVAPI BOOL WINAPI CRYPTACQUIRECONTEXTW(
  49. HCRYPTPROV *phProv,
  50. LPCWSTR pszContainer,
  51. LPCWSTR pszProvider,
  52. DWORD dwProvType,
  53. DWORD dwFlags);
  54. typedef WINADVAPI BOOL WINAPI CRYPTACQUIRECONTEXTA(
  55. HCRYPTPROV *phProv,
  56. LPCSTR pszContainer,
  57. LPCSTR pszProvider,
  58. DWORD dwProvType,
  59. DWORD dwFlags);
  60. #ifdef UNICODE
  61. #define CRYPTACQUIRECONTEXT CRYPTACQUIRECONTEXTW
  62. #else
  63. #define CRYPTACQUIRECONTEXT CRYPTACQUIRECONTEXTA
  64. #endif // !UNICODE
  65. typedef WINADVAPI BOOL WINAPI CRYPTRELEASECONTEXT(
  66. HCRYPTPROV hProv,
  67. DWORD dwFlags);
  68. typedef WINADVAPI BOOL WINAPI CRYPTGENKEY(
  69. HCRYPTPROV hProv,
  70. ALG_ID Algid,
  71. DWORD dwFlags,
  72. HCRYPTKEY *phKey);
  73. typedef WINADVAPI BOOL WINAPI CRYPTDERIVEKEY(
  74. HCRYPTPROV hProv,
  75. ALG_ID Algid,
  76. HCRYPTHASH hBaseData,
  77. DWORD dwFlags,
  78. HCRYPTKEY *phKey);
  79. typedef WINADVAPI BOOL WINAPI CRYPTDESTROYKEY(
  80. HCRYPTKEY hKey);
  81. typedef WINADVAPI BOOL WINAPI CRYPTSETKEYPARAM(
  82. HCRYPTKEY hKey,
  83. DWORD dwParam,
  84. BYTE *pbData,
  85. DWORD dwFlags);
  86. typedef WINADVAPI BOOL WINAPI CRYPTGETKEYPARAM(
  87. HCRYPTKEY hKey,
  88. DWORD dwParam,
  89. BYTE *pbData,
  90. DWORD *pdwDataLen,
  91. DWORD dwFlags);
  92. typedef WINADVAPI BOOL WINAPI CRYPTSETHASHPARAM(
  93. HCRYPTHASH hHash,
  94. DWORD dwParam,
  95. BYTE *pbData,
  96. DWORD dwFlags);
  97. typedef WINADVAPI BOOL WINAPI CRYPTGETHASHPARAM(
  98. HCRYPTHASH hHash,
  99. DWORD dwParam,
  100. BYTE *pbData,
  101. DWORD *pdwDataLen,
  102. DWORD dwFlags);
  103. typedef WINADVAPI BOOL WINAPI CRYPTSETPROVPARAM(
  104. HCRYPTPROV hProv,
  105. DWORD dwParam,
  106. BYTE *pbData,
  107. DWORD dwFlags);
  108. typedef WINADVAPI BOOL WINAPI CRYPTGETPROVPARAM(
  109. HCRYPTPROV hProv,
  110. DWORD dwParam,
  111. BYTE *pbData,
  112. DWORD *pdwDataLen,
  113. DWORD dwFlags);
  114. typedef WINADVAPI BOOL WINAPI CRYPTGENRANDOM(
  115. HCRYPTPROV hProv,
  116. DWORD dwLen,
  117. BYTE *pbBuffer);
  118. typedef WINADVAPI BOOL WINAPI CRYPTGETUSERKEY(
  119. HCRYPTPROV hProv,
  120. DWORD dwKeySpec,
  121. HCRYPTKEY *phUserKey);
  122. typedef WINADVAPI BOOL WINAPI CRYPTEXPORTKEY(
  123. HCRYPTKEY hKey,
  124. HCRYPTKEY hExpKey,
  125. DWORD dwBlobType,
  126. DWORD dwFlags,
  127. BYTE *pbData,
  128. DWORD *pdwDataLen);
  129. typedef WINADVAPI BOOL WINAPI CRYPTIMPORTKEY(
  130. HCRYPTPROV hProv,
  131. CONST BYTE *pbData,
  132. DWORD dwDataLen,
  133. HCRYPTKEY hPubKey,
  134. DWORD dwFlags,
  135. HCRYPTKEY *phKey);
  136. typedef WINADVAPI BOOL WINAPI CRYPTENCRYPT(
  137. HCRYPTKEY hKey,
  138. HCRYPTHASH hHash,
  139. BOOL Final,
  140. DWORD dwFlags,
  141. BYTE *pbData,
  142. DWORD *pdwDataLen,
  143. DWORD dwBufLen);
  144. typedef WINADVAPI BOOL WINAPI CRYPTDECRYPT(
  145. HCRYPTKEY hKey,
  146. HCRYPTHASH hHash,
  147. BOOL Final,
  148. DWORD dwFlags,
  149. BYTE *pbData,
  150. DWORD *pdwDataLen);
  151. typedef WINADVAPI BOOL WINAPI CRYPTCREATEHASH(
  152. HCRYPTPROV hProv,
  153. ALG_ID Algid,
  154. HCRYPTKEY hKey,
  155. DWORD dwFlags,
  156. HCRYPTHASH *phHash);
  157. typedef WINADVAPI BOOL WINAPI CRYPTHASHDATA(
  158. HCRYPTHASH hHash,
  159. CONST BYTE *pbData,
  160. DWORD dwDataLen,
  161. DWORD dwFlags);
  162. typedef WINADVAPI BOOL WINAPI CRYPTHASHSESSIONKEY(
  163. HCRYPTHASH hHash,
  164. HCRYPTKEY hKey,
  165. DWORD dwFlags);
  166. typedef WINADVAPI BOOL WINAPI CRYPTDESTROYHASH(
  167. HCRYPTHASH hHash);
  168. typedef WINADVAPI BOOL WINAPI CRYPTSIGNHASHA(
  169. HCRYPTHASH hHash,
  170. DWORD dwKeySpec,
  171. LPCSTR sDescription,
  172. DWORD dwFlags,
  173. BYTE *pbSignature,
  174. DWORD *pdwSigLen);
  175. typedef WINADVAPI BOOL WINAPI CRYPTSIGNHASHW(
  176. HCRYPTHASH hHash,
  177. DWORD dwKeySpec,
  178. LPCWSTR sDescription,
  179. DWORD dwFlags,
  180. BYTE *pbSignature,
  181. DWORD *pdwSigLen);
  182. #ifdef UNICODE
  183. #define CRYPTSIGNHASH CRYPTSIGNHASHW
  184. #else
  185. #define CRYPTSIGNHASH CRYPTSIGNHASHA
  186. #endif // !UNICODE
  187. typedef WINADVAPI BOOL WINAPI CRYPTVERIFYSIGNATUREA(
  188. HCRYPTHASH hHash,
  189. CONST BYTE *pbSignature,
  190. DWORD dwSigLen,
  191. HCRYPTKEY hPubKey,
  192. LPCSTR sDescription,
  193. DWORD dwFlags);
  194. typedef WINADVAPI BOOL WINAPI CRYPTVERIFYSIGNATUREW(
  195. HCRYPTHASH hHash,
  196. CONST BYTE *pbSignature,
  197. DWORD dwSigLen,
  198. HCRYPTKEY hPubKey,
  199. LPCWSTR sDescription,
  200. DWORD dwFlags);
  201. #ifdef UNICODE
  202. #define CRYPTVERIFYSIGNATURE CRYPTVERIFYSIGNATUREW
  203. #else
  204. #define CRYPTVERIFYSIGNATURE CRYPTVERIFYSIGNATUREA
  205. #endif // !UNICODE
  206. typedef WINADVAPI BOOL WINAPI CRYPTSETPROVIDERA(
  207. LPCSTR pszProvName,
  208. DWORD dwProvType);
  209. typedef WINADVAPI BOOL WINAPI CRYPTSETPROVIDERW(
  210. LPCWSTR pszProvName,
  211. DWORD dwProvType);
  212. #ifdef UNICODE
  213. #define CRYPTSETPROVIDER CRYPTSETPROVIDERW
  214. #else
  215. #define CRYPTSETPROVIDER CRYPTSETPROVIDERA
  216. #endif // !UNICODE
  217. // a structure with a bunch of
  218. typedef struct FuncList
  219. {
  220. CRYPTACQUIRECONTEXTA *pfnAcquireContextA;
  221. CRYPTACQUIRECONTEXTW *pfnAcquireContextW;
  222. CRYPTRELEASECONTEXT *pfnReleaseContext;
  223. CRYPTGENKEY *pfnGenKey;
  224. CRYPTDERIVEKEY *pfnDeriveKey;
  225. CRYPTDESTROYKEY *pfnDestroyKey;
  226. CRYPTSETKEYPARAM *pfnSetKeyParam;
  227. CRYPTGETKEYPARAM *pfnGetKeyParam;
  228. CRYPTSETHASHPARAM *pfnSetHashParam;
  229. CRYPTGETHASHPARAM *pfnGetHashParam;
  230. CRYPTSETPROVPARAM *pfnSetProvParam;
  231. CRYPTGETPROVPARAM *pfnGetProvParam;
  232. CRYPTGENRANDOM *pfnGenRandom;
  233. CRYPTGETUSERKEY *pfnGetUserKey;
  234. CRYPTEXPORTKEY *pfnExportKey;
  235. CRYPTIMPORTKEY *pfnImportKey;
  236. CRYPTENCRYPT *pfnEncrypt;
  237. CRYPTDECRYPT *pfnDecrypt;
  238. CRYPTCREATEHASH *pfnCreateHash;
  239. CRYPTHASHDATA *pfnHashData;
  240. CRYPTHASHSESSIONKEY *pfnHashSessionKey;
  241. CRYPTDESTROYHASH *pfnDestroyHash;
  242. CRYPTSIGNHASHA *pfnSignHashA;
  243. CRYPTSIGNHASHW *pfnSignHashW;
  244. CRYPTVERIFYSIGNATUREA *pfnVerifySignatureA;
  245. CRYPTVERIFYSIGNATUREW *pfnVerifySignatureW;
  246. CRYPTSETPROVIDERA *pfnSetProviderA;
  247. CRYPTSETPROVIDERW *pfnSetProviderW;
  248. } FUNCLIST, *PFUNCLIST;
  249. // other func prototypes
  250. BOOL WINAPI FDefineProvTypeFuncPointers(DWORD dwProvType, PFUNCLIST psFuncList);
  251. BOOL WINAPI FUndefineProvTypeFuncPointers(DWORD dwProvType);
  252. #endif // _REDIR_H_