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.

313 lines
12 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. CDigestAuth.h
  5. Abstract:
  6. This class performs digest authentication MD5 calculations.
  7. Author:
  8. Darren L. Anderson (darrenan) 5-Aug-1998
  9. Revision History:
  10. 5-Aug-1998 darrenan
  11. Created.
  12. --*/
  13. #ifndef __DIGESTAUTH_H
  14. #define __DIGESTAUTH_H
  15. #include <windows.h>
  16. #define DIGESTBUF_LEN 33
  17. enum DIGEST_AUTH_NAMES
  18. {
  19. DIGEST_AUTH_USERNAME=0,
  20. DIGEST_AUTH_REALM,
  21. DIGEST_AUTH_NONCE,
  22. DIGEST_AUTH_URI,
  23. DIGEST_AUTH_RESPONSE,
  24. DIGEST_AUTH_DIGEST,
  25. DIGEST_AUTH_ALGORITHM,
  26. DIGEST_AUTH_OPAQUE,
  27. DIGEST_AUTH_CNONCE,
  28. DIGEST_AUTH_QOP,
  29. DIGEST_AUTH_NC,
  30. DIGEST_AUTH_LAST
  31. };
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif
  35. VOID WINAPI
  36. ToHex(
  37. LPBYTE pSrc,
  38. UINT cSrc,
  39. LPSTR pDst
  40. );
  41. HRESULT WINAPI
  42. DigestFromCreds(
  43. IN LPCSTR pszAlgorithm,
  44. IN LPCSTR pszUsername,
  45. IN LPCSTR pszRealm,
  46. IN LPCSTR pszPassword,
  47. IN LPCSTR pszNonce,
  48. IN LPCSTR pszNonceCount,
  49. IN LPCSTR pszCNonce,
  50. IN LPCSTR pszQOP,
  51. IN LPCSTR pszMethod,
  52. IN LPCSTR pszURI,
  53. IN LPCSTR pszEntityDigest,
  54. OUT LPSTR pszSessionKey,
  55. OUT LPSTR pszResult
  56. );
  57. HRESULT WINAPI
  58. DigestFromKey(
  59. IN LPCSTR pszAlgorithm,
  60. IN LPCSTR pszSessionKey,
  61. IN LPCSTR pszNonce,
  62. IN LPCSTR pszNonceCount,
  63. IN LPCSTR pszCNonce,
  64. IN LPCSTR pszQOP,
  65. IN LPCSTR pszMethod,
  66. IN LPCSTR pszURI,
  67. IN LPCSTR pszEntityDigest,
  68. OUT LPSTR pszResult
  69. );
  70. // Base64EncodeA and Base64EncodeW is provided for backward
  71. // compatibility with the existing code only.
  72. HRESULT WINAPI
  73. Base64EncodeA(
  74. const LPBYTE pSrc,
  75. ULONG ulSrcSize,
  76. LPSTR pszDst
  77. );
  78. HRESULT WINAPI
  79. Base64EncodeW(
  80. const LPBYTE pSrc,
  81. ULONG ulSrcSize,
  82. LPWSTR pszDst
  83. );
  84. /*
  85. HRESULT WINAPI
  86. Base64DecodeA(
  87. LPCSTR pszSrc,
  88. ULONG ulSrcSize,
  89. LPBYTE pDst
  90. );
  91. HRESULT WINAPI
  92. Base64DecodeW(
  93. LPCWSTR pszSrc,
  94. ULONG ulSrcSize,
  95. LPBYTE pDst
  96. );
  97. */
  98. /////////////////////////////////////////////////////////////////////////////////////
  99. typedef unsigned char Byte;
  100. typedef long SInt32;
  101. typedef unsigned long UInt32;
  102. typedef unsigned char Boolean;
  103. void WINAPI
  104. Base64_DecodeBytes( // base-64 encode a series of blocks
  105. const char *pSource, // the source (can be the same as the destination)
  106. char *pTerminate, // the source termination characters
  107. Byte *rDest, // the destination (can be the same as the source)
  108. SInt32 *rDestSize); // the number of dest bytes
  109. void WINAPI
  110. UU_DecodeBytes( // uu decode a series of blocks
  111. const char *pSource, // the source (can be the same as the destination)
  112. char *pTerminate, // the source termination characters
  113. Byte *rDest, // the destination (can be the same as the source)
  114. SInt32 *rSize); // the number of source bytes
  115. void WINAPI
  116. MSUU_DecodeBytes( // ms uu decode a series of blocks
  117. const char *pSource, // the source (can be the same as the destination)
  118. char *pTerminate, // the source termination characters
  119. Byte *rDest, // the destination (can be the same as the source)
  120. SInt32 *rSize); // the number of source bytes
  121. void WINAPI
  122. SixBit_DecodeBytes( // six bit decode a series of blocks
  123. const char *pSource, // the source (can be the same as the destination)
  124. char *pTerminate, // the source termination characters
  125. const Byte *pFromTable, // conversion table
  126. Byte *rDest, // the destination (can be the same as the source)
  127. SInt32 *rSize); // the number of source bytes
  128. void WINAPI
  129. Base64_DecodeStream( // base-64 decode a stream of bytes
  130. Byte *pRemainder, // the remainder from a previous encode (returns any new remainder)
  131. SInt32 *pRemainderSize, // the size of the remainder (returns new new remainder size)
  132. const char *pSource, // the source
  133. SInt32 pSourceSize, // the source size
  134. Boolean pTerminate, // meaningless (for Base64_EncodeStream() compatibility)
  135. Byte *rDest, // the destination
  136. SInt32 *rDestSize); // returns the destination size
  137. void WINAPI
  138. UU_DecodeStream( // uu decode a stream of bytes
  139. Byte *pRemainder, // the remainder from a previous encode (returns any new remainder)
  140. SInt32 *pRemainderSize, // the size of the remainder (returns new new remainder size)
  141. const char *pSource, // the source
  142. SInt32 pSourceSize, // the source size
  143. Boolean pTerminate, // meaningless (for Base64_EncodeStream() compatibility)
  144. Byte *rDest, // the destination
  145. SInt32 *rDestSize); // returns the destination size
  146. void WINAPI
  147. MSUU_DecodeStream( // ms uu decode a stream of bytes
  148. Byte *pRemainder, // the remainder from a previous encode (returns any new remainder)
  149. SInt32 *pRemainderSize, // the size of the remainder (returns new new remainder size)
  150. const char *pSource, // the source
  151. SInt32 pSourceSize, // the source size
  152. Boolean pTerminate, // meaningless (for Base64_EncodeStream() compatibility)
  153. Byte *rDest, // the destination
  154. SInt32 *rDestSize); // returns the destination size
  155. void WINAPI
  156. SixBit_DecodeStream( // six bit decode a stream of bytes
  157. Byte *pRemainder, // the remainder from a previous encode (returns any new remainder)
  158. SInt32 *pRemainderSize, // the size of the remainder (returns new new remainder size)
  159. const char *pSource, // the source
  160. SInt32 pSourceSize, // the source size
  161. Boolean pTerminate, // meaningless (for Base64_EncodeStream() compatibility)
  162. const Byte *pFromTable, // conversion table
  163. Byte *rDest, // the destination
  164. SInt32 *rDestSize); // returns the destination size
  165. void WINAPI
  166. Base64_EncodeStream( // base-64 encode a stream of bytes
  167. Byte *pRemainder, // the remainder from a previous encode (returns any new remainder)
  168. SInt32 *pRemainderSize, // the size of the remainder (returns new new remainder size)
  169. const Byte *pSource, // the source
  170. SInt32 pSourceSize, // the source size
  171. Boolean pTerminate, // terminate the stream
  172. char *rDest, // the destination
  173. SInt32 *rDestSize); // the destination size
  174. void WINAPI
  175. UU_EncodeStream( // uu encode a stream of bytes
  176. Byte *pRemainder, // the remainder from a previous encode (returns any new remainder)
  177. SInt32 *pRemainderSize, // the size of the remainder (returns new new remainder size)
  178. const Byte *pSource, // the source
  179. SInt32 pSourceSize, // the source size
  180. Boolean pTerminate, // terminate the stream
  181. char *rDest, // the destination
  182. SInt32 *rDestSize); // the destination size
  183. void WINAPI
  184. MSUU_EncodeStream( // ms uu encode a stream of bytes
  185. Byte *pRemainder, // the remainder from a previous encode (returns any new remainder)
  186. SInt32 *pRemainderSize, // the size of the remainder (returns new new remainder size)
  187. const Byte *pSource, // the source
  188. SInt32 pSourceSize, // the source size
  189. Boolean pTerminate, // terminate the stream
  190. char *rDest, // the destination
  191. SInt32 *rDestSize); // the destination size
  192. void WINAPI
  193. SixBit_EncodeStream( // six bit encode a stream of bytes
  194. Byte *pRemainder, // the remainder from a previous encode (returns any new remainder)
  195. SInt32 *pRemainderSize, // the size of the remainder (returns new new remainder size)
  196. const Byte *pSource, // the source
  197. SInt32 pSourceSize, // the source size
  198. Boolean pTerminate, // terminate the stream
  199. const char *pToTable, // conversion table
  200. char *rDest, // the destination
  201. SInt32 *rDestSize); // the destination size
  202. void WINAPI
  203. Base64_EncodeBytes( // base-64 encode a series of whole blocks
  204. const Byte *pSource, // the source (can be the same as the destination)
  205. SInt32 pSourceSize, // the number of source bytes
  206. char *rDest, // the destination (can be the same as the source)
  207. SInt32 *rDesteSize); // returns the dest size
  208. void WINAPI
  209. UU_EncodeBytes( // uu encode a series of whole blocks
  210. const Byte *pSource, // the source (can be the same as the destination)
  211. SInt32 pSourceSize, // the number of source bytes
  212. char *rDest, // the destination (can be the same as the source)
  213. SInt32 *rDesteSize); // returns the dest size
  214. void WINAPI
  215. MSUU_EncodeBytes( // ms uu encode a series of whole blocks
  216. const Byte *pSource, // the source (can be the same as the destination)
  217. SInt32 pSourceSize, // the number of source bytes
  218. char *rDest, // the destination (can be the same as the source)
  219. SInt32 *rDesteSize); // returns the dest size
  220. void WINAPI
  221. SixBit_EncodeBytes( // six bit encode a series of whole blocks
  222. const Byte *pSource, // the source (can be the same as the destination)
  223. SInt32 pSourceSize, // the number of source bytes
  224. const char *pToTable, // conversion table
  225. char *rDest, // the destination (can be the same as the source)
  226. SInt32 *rDesteSize); // returns the dest size
  227. extern const char cToBase64[66];
  228. extern const Byte cFromBase64[257];
  229. extern const char cToUU[66];
  230. extern const Byte cFromUU[257];
  231. extern const char cToMSUU[66];
  232. extern const Byte cFromMSUU[257];
  233. /////////////////////////////////////////////////////////////////////////////////////
  234. HRESULT WINAPI
  235. GenerateNonce(BYTE *pSrcStr,
  236. long lSrcSize,
  237. BYTE *pDestStr,
  238. long *plDestSize);
  239. HRESULT WINAPI
  240. CheckNonce(BYTE* pNonce,
  241. long lSrcSize,
  242. long lTimeoutWindow = 300, // default to 5 minutes
  243. long lCurTime = 0);
  244. #if defined(UNICODE) || defined(_UNICODE)
  245. #define Base64Encode Base64EncodeW
  246. //#define Base64Decode Base64DecodeW
  247. #else
  248. #define Base64Encode Base64EncodeA
  249. //#define Base64Decode Base64DecodeA
  250. #endif
  251. BOOL
  252. ParseAuthorizationHeader(
  253. LPSTR pszHeader,
  254. LPSTR pValueTable[DIGEST_AUTH_LAST]
  255. );
  256. #ifdef __cplusplus
  257. }
  258. #endif
  259. #endif // __DIGESTAUTH_H