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.

386 lines
11 KiB

  1. //+-------------------------------------------------------------------------
  2. // Microsoft Windows
  3. //
  4. // Copyright (C) Microsoft Corporation, 1996 - 1999
  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. // OssUtilSetBitStringWithoutTrailingZeroes
  24. // OssUtilGetBitString
  25. // OssUtilGetIA5String
  26. // OssUtilSetUnicodeConvertedToIA5String
  27. // OssUtilFreeUnicodeConvertedToIA5String
  28. // OssUtilGetIA5StringConvertedToUnicode
  29. // OssUtilGetBMPString
  30. // OssUtilSetAny
  31. // OssUtilGetAny
  32. // OssUtilEncodeInfo
  33. // OssUtilDecodeAndAllocInfo
  34. // OssUtilFreeInfo
  35. // OssUtilEncodeInfoEx
  36. // OssUtilDecodeAndAllocInfo
  37. // OssUtilAllocStructInfoEx
  38. // OssUtilDecodeAndAllocInfoEx
  39. //
  40. // History: 17-Nov-96 philh created
  41. //--------------------------------------------------------------------------
  42. #ifndef __OSSUTIL_H__
  43. #define __OSSUTIL_H__
  44. #include <wincrypt.h>
  45. #include <pkialloc.h>
  46. #include "asn1hdr.h"
  47. #include "ossglobl.h"
  48. #ifdef __cplusplus
  49. extern "C" {
  50. #endif
  51. //+-------------------------------------------------------------------------
  52. // OssUtil allocation and free functions
  53. //--------------------------------------------------------------------------
  54. #define OssUtilAlloc PkiNonzeroAlloc
  55. #define OssUtilFree PkiFree
  56. //+-------------------------------------------------------------------------
  57. // Reverses a buffer of bytes in place
  58. //--------------------------------------------------------------------------
  59. void
  60. WINAPI
  61. OssUtilReverseBytes(
  62. IN OUT PBYTE pbIn,
  63. IN DWORD cbIn
  64. );
  65. //+-------------------------------------------------------------------------
  66. // Reverses a buffer of bytes to a new buffer. OssUtilFree() must be
  67. // called to free allocated bytes.
  68. //--------------------------------------------------------------------------
  69. PBYTE
  70. WINAPI
  71. OssUtilAllocAndReverseBytes(
  72. IN PBYTE pbIn,
  73. IN DWORD cbIn
  74. );
  75. //+-------------------------------------------------------------------------
  76. // Get Octet String
  77. //--------------------------------------------------------------------------
  78. void
  79. WINAPI
  80. OssUtilGetOctetString(
  81. IN unsigned int OssLength,
  82. IN unsigned char *OssValue,
  83. IN DWORD dwFlags,
  84. OUT PCRYPT_DATA_BLOB pInfo,
  85. IN OUT BYTE **ppbExtra,
  86. IN OUT LONG *plRemainExtra
  87. );
  88. //+-------------------------------------------------------------------------
  89. // Set/Free/Get HugeInteger
  90. //
  91. // BYTE reversal::
  92. // - this only needs to be done for little endian processors
  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. // Set BitString Without Trailing Zeroes
  166. //--------------------------------------------------------------------------
  167. void
  168. WINAPI
  169. OssUtilSetBitStringWithoutTrailingZeroes(
  170. IN PCRYPT_BIT_BLOB pInfo,
  171. OUT unsigned int *pOssBitLength,
  172. OUT unsigned char **ppOssValue
  173. );
  174. //+-------------------------------------------------------------------------
  175. // Get IA5 String
  176. //--------------------------------------------------------------------------
  177. void
  178. WINAPI
  179. OssUtilGetIA5String(
  180. IN unsigned int OssLength,
  181. IN char *pOssValue,
  182. IN DWORD dwFlags,
  183. OUT LPSTR *ppsz,
  184. IN OUT BYTE **ppbExtra,
  185. IN OUT LONG *plRemainExtra
  186. );
  187. //+-------------------------------------------------------------------------
  188. // Set/Free/Get Unicode mapped to IA5 String
  189. //--------------------------------------------------------------------------
  190. BOOL
  191. WINAPI
  192. OssUtilSetUnicodeConvertedToIA5String(
  193. IN LPWSTR pwsz,
  194. OUT unsigned int *pOssLength,
  195. OUT char **ppOssValue
  196. );
  197. void
  198. WINAPI
  199. OssUtilFreeUnicodeConvertedToIA5String(
  200. IN char *pOssValue
  201. );
  202. void
  203. WINAPI
  204. OssUtilGetIA5StringConvertedToUnicode(
  205. IN unsigned int OssLength,
  206. IN char *pOssValue,
  207. IN DWORD dwFlags,
  208. OUT LPWSTR *ppwsz,
  209. IN OUT BYTE **ppbExtra,
  210. IN OUT LONG *plRemainExtra
  211. );
  212. //+-------------------------------------------------------------------------
  213. // Get BMP String
  214. //--------------------------------------------------------------------------
  215. void
  216. WINAPI
  217. OssUtilGetBMPString(
  218. IN unsigned int OssLength,
  219. IN unsigned short *pOssValue,
  220. IN DWORD dwFlags,
  221. OUT LPWSTR *ppwsz,
  222. IN OUT BYTE **ppbExtra,
  223. IN OUT LONG *plRemainExtra
  224. );
  225. //+-------------------------------------------------------------------------
  226. // Set/Get "Any" DER BLOB
  227. //--------------------------------------------------------------------------
  228. void
  229. WINAPI
  230. OssUtilSetAny(
  231. IN PCRYPT_OBJID_BLOB pInfo,
  232. OUT OpenType *pOss
  233. );
  234. void
  235. WINAPI
  236. OssUtilGetAny(
  237. IN OpenType *pOss,
  238. IN DWORD dwFlags,
  239. OUT PCRYPT_OBJID_BLOB pInfo,
  240. IN OUT BYTE **ppbExtra,
  241. IN OUT LONG *plRemainExtra
  242. );
  243. //+-------------------------------------------------------------------------
  244. // Encode an OSS formatted info structure
  245. //--------------------------------------------------------------------------
  246. BOOL
  247. WINAPI
  248. OssUtilEncodeInfo(
  249. IN OssGlobal *Pog,
  250. IN int pdunum,
  251. IN void *pvOssInfo,
  252. OUT OPTIONAL BYTE *pbEncoded,
  253. IN OUT DWORD *pcbEncoded
  254. );
  255. //+-------------------------------------------------------------------------
  256. // Decode into an allocated, OSS formatted info structure
  257. //--------------------------------------------------------------------------
  258. BOOL
  259. WINAPI
  260. OssUtilDecodeAndAllocInfo(
  261. IN OssGlobal *Pog,
  262. IN int pdunum,
  263. IN const BYTE *pbEncoded,
  264. IN DWORD cbEncoded,
  265. OUT void **ppvOssInfo
  266. );
  267. //+-------------------------------------------------------------------------
  268. // Free an allocated, OSS formatted info structure
  269. //--------------------------------------------------------------------------
  270. void
  271. WINAPI
  272. OssUtilFreeInfo(
  273. IN OssGlobal *Pog,
  274. IN int pdunum,
  275. IN void *pvOssInfo
  276. );
  277. //+-------------------------------------------------------------------------
  278. // Encode an OSS formatted info structure.
  279. //
  280. // If CRYPT_ENCODE_ALLOC_FLAG is set, allocate memory for pbEncoded and
  281. // return *((BYTE **) pvEncoded) = pbAllocEncoded. Otherwise,
  282. // pvEncoded points to byte array to be updated.
  283. //--------------------------------------------------------------------------
  284. BOOL
  285. WINAPI
  286. OssUtilEncodeInfoEx(
  287. IN OssGlobal *Pog,
  288. IN int pdunum,
  289. IN void *pvOssInfo,
  290. IN DWORD dwFlags,
  291. IN OPTIONAL PCRYPT_ENCODE_PARA pEncodePara,
  292. OUT OPTIONAL void *pvEncoded,
  293. IN OUT DWORD *pcbEncoded
  294. );
  295. typedef BOOL (WINAPI *PFN_OSS_UTIL_DECODE_EX_CALLBACK)(
  296. IN void *pvOssInfo,
  297. IN DWORD dwFlags,
  298. IN OPTIONAL PCRYPT_DECODE_PARA pDecodePara,
  299. OUT OPTIONAL void *pvStructInfo,
  300. IN OUT LONG *plRemainExtra
  301. );
  302. //+-------------------------------------------------------------------------
  303. // Call the callback to convert the OSS structure into the 'C' structure.
  304. // If CRYPT_DECODE_ALLOC_FLAG is set allocate memory for the 'C'
  305. // structure and call the callback initially to get the length and then
  306. // a second time to update the allocated 'C' structure.
  307. //
  308. // Allocated structure is returned:
  309. // *((void **) pvStructInfo) = pvAllocStructInfo
  310. //--------------------------------------------------------------------------
  311. BOOL
  312. WINAPI
  313. OssUtilAllocStructInfoEx(
  314. IN void *pvOssInfo,
  315. IN DWORD dwFlags,
  316. IN OPTIONAL PCRYPT_DECODE_PARA pDecodePara,
  317. IN PFN_OSS_UTIL_DECODE_EX_CALLBACK pfnDecodeExCallback,
  318. OUT OPTIONAL void *pvStructInfo,
  319. IN OUT DWORD *pcbStructInfo
  320. );
  321. //+-------------------------------------------------------------------------
  322. // Decode the OSS formatted info structure and call the callback
  323. // function to convert the OSS structure to the 'C' structure.
  324. //
  325. // If CRYPT_DECODE_ALLOC_FLAG is set allocate memory for the 'C'
  326. // structure and call the callback initially to get the length and then
  327. // a second time to update the allocated 'C' structure.
  328. //
  329. // Allocated structure is returned:
  330. // *((void **) pvStructInfo) = pvAllocStructInfo
  331. //--------------------------------------------------------------------------
  332. BOOL
  333. WINAPI
  334. OssUtilDecodeAndAllocInfoEx(
  335. IN OssGlobal *Pog,
  336. IN int pdunum,
  337. IN const BYTE *pbEncoded,
  338. IN DWORD cbEncoded,
  339. IN DWORD dwFlags,
  340. IN OPTIONAL PCRYPT_DECODE_PARA pDecodePara,
  341. IN PFN_OSS_UTIL_DECODE_EX_CALLBACK pfnDecodeExCallback,
  342. OUT OPTIONAL void *pvStructInfo,
  343. IN OUT DWORD *pcbStructInfo
  344. );
  345. #ifdef __cplusplus
  346. } // Balance extern "C" above
  347. #endif
  348. #endif