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.

273 lines
8.2 KiB

  1. //+-------------------------------------------------------------------------
  2. // Microsoft Windows
  3. //
  4. // Copyright (C) Microsoft Corporation, 1996 - 1996
  5. //
  6. // File: crypttls.h
  7. //
  8. // Contents: Crypt Thread Local Storage (TLS) and OssGlobal "world"
  9. // installation and allocation functions
  10. //
  11. // APIs:
  12. // I_CryptAllocTls
  13. // I_CryptFreeTls
  14. // I_CryptGetTls
  15. // I_CryptSetTls
  16. // I_CryptDetachTls
  17. // I_CryptInstallOssGlobal
  18. // I_CryptUninstallOssGlobal
  19. // I_CryptGetOssGlobal
  20. //
  21. // I_CryptInstallAsn1Module
  22. // I_CryptUninstallAsn1Module
  23. // I_CryptGetAsn1Encoder
  24. // I_CryptGetAsn1Decoder
  25. //
  26. //
  27. // History: 17-Nov-96 philh created
  28. //--------------------------------------------------------------------------
  29. #ifndef __CRYPTTLS_H__
  30. #define __CRYPTTLS_H__
  31. #include "msasn1.h"
  32. #include "ossglobl.h"
  33. #include <wincrypt.h>
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37. // Handle to an allocated Crypt TLS entry
  38. typedef DWORD HCRYPTTLS;
  39. // Handle to an installed OssGlobal table
  40. typedef DWORD HCRYPTOSSGLOBAL;
  41. // Pointer to OssGlobal. Returned by I_CryptGetOssGlobal()
  42. typedef OssGlobal *POssGlobal;
  43. // Handle to an installed Asn1 module
  44. typedef DWORD HCRYPTASN1MODULE;
  45. //+-------------------------------------------------------------------------
  46. // Install a thread local storage entry and return a handle for future access.
  47. //--------------------------------------------------------------------------
  48. HCRYPTTLS
  49. WINAPI
  50. I_CryptAllocTls();
  51. //+-------------------------------------------------------------------------
  52. // Called at DLL_PROCESS_DETACH to free a thread local storage entry.
  53. // Optionally, calls the callback for each thread having a non-NULL pvTls.
  54. //--------------------------------------------------------------------------
  55. BOOL
  56. WINAPI
  57. I_CryptFreeTls(
  58. IN HCRYPTTLS hCryptTls,
  59. IN OPTIONAL PFN_CRYPT_FREE pfnFree
  60. );
  61. //+-------------------------------------------------------------------------
  62. // Get the thread specific pointer specified by the
  63. // hCryptTls returned by I_CryptAllocTls().
  64. //
  65. // Returns NULL for an error or uninitialized pointer.
  66. //--------------------------------------------------------------------------
  67. void *
  68. WINAPI
  69. I_CryptGetTls(
  70. IN HCRYPTTLS hCryptTls
  71. );
  72. //+-------------------------------------------------------------------------
  73. // Set the thread specific pointer specified by the
  74. // hCryptTls returned by I_CryptAllocTls().
  75. //
  76. // Returns FALSE for an invalid handle or unable to allocate memory.
  77. //--------------------------------------------------------------------------
  78. BOOL
  79. WINAPI
  80. I_CryptSetTls(
  81. IN HCRYPTTLS hCryptTls,
  82. IN void *pvTls
  83. );
  84. //+-------------------------------------------------------------------------
  85. // Called at DLL_THREAD_DETACH to free the thread's
  86. // TLS entry specified by the hCryptTls. Returns the thread specific pointer
  87. // to be freed by the caller.
  88. //
  89. // Note, at DLL_PROCESS_DETACH, I_CryptFreeTls should be called instead.
  90. //--------------------------------------------------------------------------
  91. void *
  92. WINAPI
  93. I_CryptDetachTls(
  94. IN HCRYPTTLS hCryptTls
  95. );
  96. //+-------------------------------------------------------------------------
  97. // Install an OssGlobal entry and return a handle for future access.
  98. //
  99. // Each thread has its own copy of OssGlobal. Allocation and
  100. // initialization are deferred until first referenced by the thread.
  101. //
  102. // The parameter, pvCtlTbl is passed to ossinit() to initialize the OssGlobal.
  103. //
  104. // I_CryptGetOssGlobal must be called with the handled returned by
  105. // I_CryptInstallOssGlobal to get the thread specific OssGlobal.
  106. //
  107. // Currently, dwFlags and pvReserved aren't used and must be set to 0.
  108. //--------------------------------------------------------------------------
  109. HCRYPTOSSGLOBAL
  110. WINAPI
  111. I_CryptInstallOssGlobal(
  112. IN void *pvCtlTbl,
  113. IN DWORD dwFlags,
  114. IN void *pvReserved
  115. );
  116. //+-------------------------------------------------------------------------
  117. // Called at DLL_PROCESS_DETACH to uninstall an OssGlobal entry. Iterate
  118. // through the threads and frees their allocated copy of OssGlobal.
  119. //--------------------------------------------------------------------------
  120. BOOL
  121. WINAPI
  122. I_CryptUninstallOssGlobal(
  123. IN HCRYPTOSSGLOBAL hOssGlobal
  124. );
  125. //+-------------------------------------------------------------------------
  126. // Get the thread specific pointer to the OssGlobal specified by the
  127. // hOssGlobal returned by CryptInstallOssGlobal. If the
  128. // OssGlobal doesn't exist, then, its allocated and initialized using
  129. // the pvCtlTbl associated with hOssGlobal.
  130. //--------------------------------------------------------------------------
  131. POssGlobal
  132. WINAPI
  133. I_CryptGetOssGlobal(
  134. IN HCRYPTOSSGLOBAL hOssGlobal
  135. );
  136. //+-------------------------------------------------------------------------
  137. // Install an Asn1 module entry and return a handle for future access.
  138. //
  139. // Each thread has its own copy of the decoder and encoder associated
  140. // with the Asn1 module. Creation is deferred until first referenced by
  141. // the thread.
  142. //
  143. // I_CryptGetAsn1Encoder or I_CryptGetAsn1Decoder must be called with the
  144. // handle returned by I_CryptInstallAsn1Module to get the thread specific
  145. // Asn1 encoder or decoder.
  146. //
  147. // Currently, dwFlags and pvReserved aren't used and must be set to 0.
  148. //--------------------------------------------------------------------------
  149. #ifdef OSS_CRYPT_ASN1
  150. __inline
  151. HCRYPTASN1MODULE
  152. WINAPI
  153. I_CryptInstallAsn1Module(
  154. IN void *pvCtlTbl,
  155. IN DWORD dwFlags,
  156. IN void *pvReserved
  157. )
  158. {
  159. return (HCRYPTASN1MODULE) I_CryptInstallOssGlobal(
  160. pvCtlTbl, dwFlags, pvReserved);
  161. }
  162. #else
  163. HCRYPTASN1MODULE
  164. WINAPI
  165. I_CryptInstallAsn1Module(
  166. IN ASN1module_t pMod,
  167. IN DWORD dwFlags,
  168. IN void *pvReserved
  169. );
  170. #endif // OSS_CRYPT_ASN1
  171. //+-------------------------------------------------------------------------
  172. // Called at DLL_PROCESS_DETACH to uninstall an hAsn1Module entry. Iterates
  173. // through the threads and frees their created Asn1 encoders and decoders.
  174. //--------------------------------------------------------------------------
  175. #ifdef OSS_CRYPT_ASN1
  176. __inline
  177. BOOL
  178. WINAPI
  179. I_CryptUninstallAsn1Module(
  180. IN HCRYPTASN1MODULE hAsn1Module
  181. )
  182. {
  183. return I_CryptUninstallOssGlobal((HCRYPTOSSGLOBAL) hAsn1Module);
  184. }
  185. #else
  186. BOOL
  187. WINAPI
  188. I_CryptUninstallAsn1Module(
  189. IN HCRYPTASN1MODULE hAsn1Module
  190. );
  191. #endif // OSS_CRYPT_ASN1
  192. //+-------------------------------------------------------------------------
  193. // Get the thread specific pointer to the Asn1 encoder specified by the
  194. // hAsn1Module returned by CryptInstallAsn1Module. If the
  195. // encoder doesn't exist, then, its created using the Asn1 module
  196. // associated with hAsn1Module.
  197. //--------------------------------------------------------------------------
  198. #ifdef OSS_CRYPT_ASN1
  199. __inline
  200. ASN1encoding_t
  201. WINAPI
  202. I_CryptGetAsn1Encoder(
  203. IN HCRYPTASN1MODULE hAsn1Module
  204. )
  205. {
  206. return (ASN1encoding_t) I_CryptGetOssGlobal((HCRYPTOSSGLOBAL) hAsn1Module);
  207. }
  208. #else
  209. ASN1encoding_t
  210. WINAPI
  211. I_CryptGetAsn1Encoder(
  212. IN HCRYPTASN1MODULE hAsn1Module
  213. );
  214. #endif // OSS_CRYPT_ASN1
  215. //+-------------------------------------------------------------------------
  216. // Get the thread specific pointer to the Asn1 decoder specified by the
  217. // hAsn1Module returned by CryptInstallAsn1Module. If the
  218. // decoder doesn't exist, then, its created using the Asn1 module
  219. // associated with hAsn1Module.
  220. //--------------------------------------------------------------------------
  221. #ifdef OSS_CRYPT_ASN1
  222. __inline
  223. ASN1decoding_t
  224. WINAPI
  225. I_CryptGetAsn1Decoder(
  226. IN HCRYPTASN1MODULE hAsn1Module
  227. )
  228. {
  229. return (ASN1decoding_t) I_CryptGetOssGlobal((HCRYPTOSSGLOBAL) hAsn1Module);
  230. }
  231. #else
  232. ASN1decoding_t
  233. WINAPI
  234. I_CryptGetAsn1Decoder(
  235. IN HCRYPTASN1MODULE hAsn1Module
  236. );
  237. #endif // OSS_CRYPT_ASN1
  238. #ifdef __cplusplus
  239. } // Balance extern "C" above
  240. #endif
  241. #endif