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.

398 lines
12 KiB

  1. //+-------------------------------------------------------------------------
  2. // Microsoft Windows
  3. //
  4. // Copyright (C) Microsoft Corporation, 1996 - 1996
  5. //
  6. // File: ossutil.h
  7. //
  8. // Contents: OSS ASN.1 compiler utility functions.
  9. //
  10. // APIs:
  11. // OssUtilAlloc
  12. // OssUtilFree
  13. // OssUtilReverseBytes
  14. // OssUtilAllocAndReverseBytes
  15. // OssUtilGetOctetString
  16. // OssUtilSetHugeInteger
  17. // OssUtilFreeHugeInteger
  18. // OssUtilGetHugeInteger
  19. // OssUtilSetHugeUINT
  20. // OssUtilFreeHugeUINT
  21. // OssUtilGetHugeUINT
  22. // OssUtilSetBitString
  23. // OssUtilGetBitString
  24. // OssUtilGetIA5String
  25. // OssUtilSetUnicodeConvertedToIA5String
  26. // OssUtilFreeUnicodeConvertedToIA5String
  27. // OssUtilGetIA5StringConvertedToUnicode
  28. // OssUtilGetBMPString
  29. // OssUtilSetAny
  30. // OssUtilGetAny
  31. // OssUtilEncodeInfo
  32. // OssUtilDecodeAndAllocInfo
  33. // OssUtilFreeInfo
  34. // OssUtilEncodeInfoEx
  35. // OssUtilDecodeAndAllocInfo
  36. // OssUtilAllocStructInfoEx
  37. // OssUtilDecodeAndAllocInfoEx
  38. //
  39. // History: 17-Nov-96 philh created
  40. //--------------------------------------------------------------------------
  41. #ifndef __OSSUTIL_H__
  42. #define __OSSUTIL_H__
  43. #include <wincrypt.h>
  44. #include <pkialloc.h>
  45. #include "asn1hdr.h"
  46. #include "ossglobl.h"
  47. #ifdef __cplusplus
  48. extern "C" {
  49. #endif
  50. //+-------------------------------------------------------------------------
  51. // OssUtil allocation and free functions
  52. //--------------------------------------------------------------------------
  53. #define OssUtilAlloc PkiNonzeroAlloc
  54. #define OssUtilFree PkiFree
  55. //+-------------------------------------------------------------------------
  56. // Reverses a buffer of bytes in place
  57. //--------------------------------------------------------------------------
  58. void
  59. WINAPI
  60. OssUtilReverseBytes(
  61. IN OUT PBYTE pbIn,
  62. IN DWORD cbIn
  63. );
  64. //+-------------------------------------------------------------------------
  65. // Reverses a buffer of bytes to a new buffer. OssUtilFree() must be
  66. // called to free allocated bytes.
  67. //--------------------------------------------------------------------------
  68. PBYTE
  69. WINAPI
  70. OssUtilAllocAndReverseBytes(
  71. IN PBYTE pbIn,
  72. IN DWORD cbIn
  73. );
  74. //+-------------------------------------------------------------------------
  75. // Get Octet String
  76. //--------------------------------------------------------------------------
  77. void
  78. WINAPI
  79. OssUtilGetOctetString(
  80. IN unsigned int OssLength,
  81. IN unsigned char *OssValue,
  82. IN DWORD dwFlags,
  83. OUT PCRYPT_DATA_BLOB pInfo,
  84. IN OUT BYTE **ppbExtra,
  85. IN OUT LONG *plRemainExtra
  86. );
  87. //+-------------------------------------------------------------------------
  88. // Set/Free/Get HugeInteger
  89. //
  90. // BUGBUG: BYTE reversal::
  91. // - this only needs to be done for little endian
  92. // - this needs to be fixed in the OSS compiler
  93. //
  94. // OssUtilFreeHugeInteger must be called to free the allocated OssValue.
  95. //--------------------------------------------------------------------------
  96. BOOL
  97. WINAPI
  98. OssUtilSetHugeInteger(
  99. IN PCRYPT_INTEGER_BLOB pInfo,
  100. OUT unsigned int *pOssLength,
  101. OUT unsigned char **ppOssValue
  102. );
  103. void
  104. WINAPI
  105. OssUtilFreeHugeInteger(
  106. IN unsigned char *pOssValue
  107. );
  108. void
  109. WINAPI
  110. OssUtilGetHugeInteger(
  111. IN unsigned int OssLength,
  112. IN unsigned char *pOssValue,
  113. IN DWORD dwFlags,
  114. OUT PCRYPT_INTEGER_BLOB pInfo,
  115. IN OUT BYTE **ppbExtra,
  116. IN OUT LONG *plRemainExtra
  117. );
  118. //+-------------------------------------------------------------------------
  119. // Set/Free/Get Huge Unsigned Integer
  120. //
  121. // Set inserts a leading 0x00 before reversing.
  122. // Get removes a leading 0x00 if present, after reversing.
  123. //
  124. // OssUtilFreeHugeUINT must be called to free the allocated OssValue.
  125. //--------------------------------------------------------------------------
  126. BOOL
  127. WINAPI
  128. OssUtilSetHugeUINT(
  129. IN PCRYPT_UINT_BLOB pInfo,
  130. OUT unsigned int *pOssLength,
  131. OUT unsigned char **ppOssValue
  132. );
  133. #define OssUtilFreeHugeUINT OssUtilFreeHugeInteger
  134. void
  135. WINAPI
  136. OssUtilGetHugeUINT(
  137. IN unsigned int OssLength,
  138. IN unsigned char *pOssValue,
  139. IN DWORD dwFlags,
  140. OUT PCRYPT_UINT_BLOB pInfo,
  141. IN OUT BYTE **ppbExtra,
  142. IN OUT LONG *plRemainExtra
  143. );
  144. //+-------------------------------------------------------------------------
  145. // Set/Get BitString
  146. //--------------------------------------------------------------------------
  147. void
  148. WINAPI
  149. OssUtilSetBitString(
  150. IN PCRYPT_BIT_BLOB pInfo,
  151. OUT unsigned int *pOssBitLength,
  152. OUT unsigned char **ppOssValue
  153. );
  154. void
  155. WINAPI
  156. OssUtilGetBitString(
  157. IN unsigned int OssBitLength,
  158. IN unsigned char *pOssValue,
  159. IN DWORD dwFlags,
  160. OUT PCRYPT_BIT_BLOB pInfo,
  161. IN OUT BYTE **ppbExtra,
  162. IN OUT LONG *plRemainExtra
  163. );
  164. //+-------------------------------------------------------------------------
  165. // Get IA5 String
  166. //--------------------------------------------------------------------------
  167. void
  168. WINAPI
  169. OssUtilGetIA5String(
  170. IN unsigned int OssLength,
  171. IN char *pOssValue,
  172. IN DWORD dwFlags,
  173. OUT LPSTR *ppsz,
  174. IN OUT BYTE **ppbExtra,
  175. IN OUT LONG *plRemainExtra
  176. );
  177. //+-------------------------------------------------------------------------
  178. // Set/Free/Get Unicode mapped to IA5 String
  179. //--------------------------------------------------------------------------
  180. BOOL
  181. WINAPI
  182. OssUtilSetUnicodeConvertedToIA5String(
  183. IN LPWSTR pwsz,
  184. OUT unsigned int *pOssLength,
  185. OUT char **ppOssValue
  186. );
  187. void
  188. WINAPI
  189. OssUtilFreeUnicodeConvertedToIA5String(
  190. IN char *pOssValue
  191. );
  192. void
  193. WINAPI
  194. OssUtilGetIA5StringConvertedToUnicode(
  195. IN unsigned int OssLength,
  196. IN char *pOssValue,
  197. IN DWORD dwFlags,
  198. OUT LPWSTR *ppwsz,
  199. IN OUT BYTE **ppbExtra,
  200. IN OUT LONG *plRemainExtra
  201. );
  202. //+-------------------------------------------------------------------------
  203. // Get BMP String
  204. //--------------------------------------------------------------------------
  205. void
  206. WINAPI
  207. OssUtilGetBMPString(
  208. IN unsigned int OssLength,
  209. IN unsigned short *pOssValue,
  210. IN DWORD dwFlags,
  211. OUT LPWSTR *ppwsz,
  212. IN OUT BYTE **ppbExtra,
  213. IN OUT LONG *plRemainExtra
  214. );
  215. //+-------------------------------------------------------------------------
  216. // Set/Get "Any" DER BLOB
  217. //--------------------------------------------------------------------------
  218. void
  219. WINAPI
  220. OssUtilSetAny(
  221. IN PCRYPT_OBJID_BLOB pInfo,
  222. OUT OpenType *pOss
  223. );
  224. void
  225. WINAPI
  226. OssUtilGetAny(
  227. IN OpenType *pOss,
  228. IN DWORD dwFlags,
  229. OUT PCRYPT_OBJID_BLOB pInfo,
  230. IN OUT BYTE **ppbExtra,
  231. IN OUT LONG *plRemainExtra
  232. );
  233. //+-------------------------------------------------------------------------
  234. // Encode an OSS formatted info structure
  235. //--------------------------------------------------------------------------
  236. BOOL
  237. WINAPI
  238. OssUtilEncodeInfo(
  239. IN OssGlobal *Pog,
  240. IN int pdunum,
  241. IN void *pvOssInfo,
  242. OUT OPTIONAL BYTE *pbEncoded,
  243. IN OUT DWORD *pcbEncoded
  244. );
  245. //+-------------------------------------------------------------------------
  246. // Decode into an allocated, OSS formatted info structure
  247. //--------------------------------------------------------------------------
  248. BOOL
  249. WINAPI
  250. OssUtilDecodeAndAllocInfo(
  251. IN OssGlobal *Pog,
  252. IN int pdunum,
  253. IN const BYTE *pbEncoded,
  254. IN DWORD cbEncoded,
  255. OUT void **ppvOssInfo
  256. );
  257. //+-------------------------------------------------------------------------
  258. // Free an allocated, OSS formatted info structure
  259. //--------------------------------------------------------------------------
  260. void
  261. WINAPI
  262. OssUtilFreeInfo(
  263. IN OssGlobal *Pog,
  264. IN int pdunum,
  265. IN void *pvOssInfo
  266. );
  267. //+-------------------------------------------------------------------------
  268. // Encode an OSS formatted info structure.
  269. //
  270. // If CRYPT_ENCODE_ALLOC_FLAG is set, allocate memory for pbEncoded and
  271. // return *((BYTE **) pvEncoded) = pbAllocEncoded. Otherwise,
  272. // pvEncoded points to byte array to be updated.
  273. //--------------------------------------------------------------------------
  274. BOOL
  275. WINAPI
  276. OssUtilEncodeInfoEx(
  277. IN OssGlobal *Pog,
  278. IN int pdunum,
  279. IN void *pvOssInfo,
  280. IN DWORD dwFlags,
  281. IN OPTIONAL PCRYPT_ENCODE_PARA pEncodePara,
  282. OUT OPTIONAL void *pvEncoded,
  283. IN OUT DWORD *pcbEncoded
  284. );
  285. typedef BOOL (WINAPI *PFN_OSS_UTIL_DECODE_EX_CALLBACK)(
  286. IN void *pvOssInfo,
  287. IN DWORD dwFlags,
  288. IN OPTIONAL PCRYPT_DECODE_PARA pDecodePara,
  289. OUT OPTIONAL void *pvStructInfo,
  290. IN OUT LONG *plRemainExtra
  291. );
  292. //+-------------------------------------------------------------------------
  293. // Call the callback to convert the OSS structure into the 'C' structure.
  294. // If CRYPT_DECODE_ALLOC_FLAG is set allocate memory for the 'C'
  295. // structure and call the callback initially to get the length and then
  296. // a second time to update the allocated 'C' structure.
  297. //
  298. // Allocated structure is returned:
  299. // *((void **) pvStructInfo) = pvAllocStructInfo
  300. //--------------------------------------------------------------------------
  301. BOOL
  302. WINAPI
  303. OssUtilAllocStructInfoEx(
  304. IN void *pvOssInfo,
  305. IN DWORD dwFlags,
  306. IN OPTIONAL PCRYPT_DECODE_PARA pDecodePara,
  307. IN PFN_OSS_UTIL_DECODE_EX_CALLBACK pfnDecodeExCallback,
  308. OUT OPTIONAL void *pvStructInfo,
  309. IN OUT DWORD *pcbStructInfo
  310. );
  311. //+-------------------------------------------------------------------------
  312. // Decode the OSS formatted info structure and call the callback
  313. // function to convert the OSS structure to the 'C' structure.
  314. //
  315. // If CRYPT_DECODE_ALLOC_FLAG is set allocate memory for the 'C'
  316. // structure and call the callback initially to get the length and then
  317. // a second time to update the allocated 'C' structure.
  318. //
  319. // Allocated structure is returned:
  320. // *((void **) pvStructInfo) = pvAllocStructInfo
  321. //--------------------------------------------------------------------------
  322. BOOL
  323. WINAPI
  324. OssUtilDecodeAndAllocInfoEx(
  325. IN OssGlobal *Pog,
  326. IN int pdunum,
  327. IN const BYTE *pbEncoded,
  328. IN DWORD cbEncoded,
  329. IN DWORD dwFlags,
  330. IN OPTIONAL PCRYPT_DECODE_PARA pDecodePara,
  331. IN PFN_OSS_UTIL_DECODE_EX_CALLBACK pfnDecodeExCallback,
  332. OUT OPTIONAL void *pvStructInfo,
  333. IN OUT DWORD *pcbStructInfo
  334. );
  335. ////////////////////////////////////////////////////////// 4.0 routines
  336. BOOL
  337. WINAPI
  338. OssConvToObjectIdentifier(
  339. IN LPCSTR pszObjId,
  340. IN OUT unsigned short *pCount,
  341. OUT unsigned long rgulValue[]
  342. )
  343. ;
  344. BOOL
  345. WINAPI
  346. OssConvFromObjectIdentifier(
  347. IN unsigned short Count,
  348. IN unsigned long rgulValue[],
  349. OUT LPSTR pszObjId,
  350. IN OUT DWORD *pcbObjId
  351. )
  352. ;
  353. #ifdef __cplusplus
  354. } // Balance extern "C" above
  355. #endif
  356. #endif