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.

274 lines
6.1 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. encrypt.c
  5. Abstract:
  6. Helper functions to work with string representations of OWF hashed passwords.
  7. Author:
  8. Ovidiu Temereanca (ovidiut) 27-Mar-2000
  9. Revision History:
  10. <alias> <date> <comments>
  11. --*/
  12. //
  13. // Includes
  14. //
  15. #pragma once
  16. typedef struct {
  17. USHORT Length;
  18. USHORT MaximumLength;
  19. PWSTR Buffer;
  20. } ENCRYPT_UNICODE_STRING, *PENCRYPT_UNICODE_STRING;
  21. #define UNICODE_STRING ENCRYPT_UNICODE_STRING
  22. #define PUNICODE_STRING PENCRYPT_UNICODE_STRING
  23. #define NTSTATUS LONG
  24. #include <crypt.h>
  25. #undef NTSTATUS
  26. #undef UNICODE_STRING
  27. #undef PUNICODE_STRING
  28. #include <lmcons.h>
  29. //
  30. // Strings
  31. //
  32. // None
  33. //
  34. // Constants
  35. //
  36. //
  37. // maximum length in Tchars of a LM password
  38. //
  39. #define LM_PASSWORD_SIZE_MAX (LM20_PWLEN + 1)
  40. //
  41. // length in Tchars of the string-encoded format of *_OWF_PASSWORD
  42. //
  43. #define STRING_ENCODED_LM_OWF_PWD_LENGTH (sizeof(LM_OWF_PASSWORD) * 2)
  44. #define STRING_ENCODED_NT_OWF_PWD_LENGTH (sizeof(NT_OWF_PASSWORD) * 2)
  45. #define STRING_ENCODED_PASSWORD_LENGTH (STRING_ENCODED_LM_OWF_PWD_LENGTH + STRING_ENCODED_NT_OWF_PWD_LENGTH)
  46. //
  47. // size in Tchars of the string-encoded format of *_OWF_PASSWORD
  48. // may be used for static allocations
  49. //
  50. #define STRING_ENCODED_LM_OWF_PWD_SIZE (STRING_ENCODED_LM_OWF_PWD_LENGTH + 1)
  51. #define STRING_ENCODED_NT_OWF_PWD_SIZE (STRING_ENCODED_NT_OWF_PWD_LENGTH + 1)
  52. //
  53. // size in Tchars of the string-encoded format of
  54. // LM_OWF_PASSWORD joined with NT_OWF_PASSWORD
  55. // may be used for static allocations
  56. //
  57. #define STRING_ENCODED_PASSWORD_SIZE (STRING_ENCODED_PASSWORD_LENGTH + 1)
  58. //
  59. // Macros
  60. //
  61. // None
  62. //
  63. // Types
  64. //
  65. // None
  66. //
  67. // Globals
  68. //
  69. // None
  70. //
  71. // Macro expansion list
  72. //
  73. // None
  74. //
  75. // Public function prototypes
  76. //
  77. DWORD
  78. SetLocalUserEncryptedPassword (
  79. IN PCWSTR User,
  80. IN PCWSTR OldPassword,
  81. IN BOOL OldIsEncrypted,
  82. IN PCWSTR NewPassword,
  83. IN BOOL NewIsEncrypted
  84. );
  85. BOOL
  86. CalculateLmOwfPassword (
  87. IN PLM_PASSWORD LmPassword,
  88. OUT PLM_OWF_PASSWORD LmOwfPassword
  89. );
  90. BOOL
  91. CalculateNtOwfPassword (
  92. IN PNT_PASSWORD NtPassword,
  93. OUT PNT_OWF_PASSWORD NtOwfPassword
  94. );
  95. INT
  96. CompareNtPasswords (
  97. IN PNT_OWF_PASSWORD NtOwfPassword1,
  98. IN PNT_OWF_PASSWORD NtOwfPassword2
  99. );
  100. INT
  101. CompareLmPasswords (
  102. IN PLM_OWF_PASSWORD LmOwfPassword1,
  103. IN PLM_OWF_PASSWORD LmOwfPassword2
  104. );
  105. BOOL
  106. EncodeLmOwfPasswordA (
  107. IN PCSTR AnsiPassword,
  108. OUT PLM_OWF_PASSWORD OwfPassword,
  109. OUT PBOOL ComplexNtPassword OPTIONAL
  110. );
  111. BOOL
  112. EncodeLmOwfPasswordW (
  113. IN PCWSTR Password,
  114. OUT PLM_OWF_PASSWORD OwfPassword,
  115. OUT PBOOL ComplexNtPassword OPTIONAL
  116. );
  117. BOOL
  118. EncodeNtOwfPasswordA (
  119. IN PCSTR Password,
  120. OUT PNT_OWF_PASSWORD OwfPassword
  121. );
  122. BOOL
  123. EncodeNtOwfPasswordW (
  124. IN PCWSTR Password,
  125. OUT PNT_OWF_PASSWORD OwfPassword
  126. );
  127. BOOL
  128. StringEncodeOwfPasswordA (
  129. IN PCSTR Password,
  130. OUT PSTR EncodedPassword,
  131. OUT PBOOL ComplexNtPassword OPTIONAL
  132. );
  133. BOOL
  134. StringEncodeOwfPasswordW (
  135. IN PCWSTR Password,
  136. OUT PWSTR EncodedPassword,
  137. OUT PBOOL ComplexNtPassword OPTIONAL
  138. );
  139. BOOL
  140. StringEncodeLmOwfPasswordA (
  141. IN PCSTR Password,
  142. OUT PSTR EncodedPassword,
  143. OUT PBOOL ComplexNtPassword OPTIONAL
  144. );
  145. BOOL
  146. StringEncodeLmOwfPasswordW (
  147. IN PCWSTR Password,
  148. OUT PWSTR EncodedPassword,
  149. OUT PBOOL ComplexNtPassword OPTIONAL
  150. );
  151. BOOL
  152. StringEncodeNtOwfPasswordA (
  153. IN PCSTR Password,
  154. OUT PSTR EncodedPassword
  155. );
  156. BOOL
  157. StringEncodeNtOwfPasswordW (
  158. IN PCWSTR Password,
  159. OUT PWSTR EncodedPassword
  160. );
  161. BOOL
  162. StringDecodeOwfPasswordA (
  163. IN PCSTR EncodedOwfPassword,
  164. OUT PLM_OWF_PASSWORD LmOwfPassword,
  165. OUT PNT_OWF_PASSWORD NtOwfPassword,
  166. OUT PBOOL ComplexNtPassword OPTIONAL
  167. );
  168. BOOL
  169. StringDecodeOwfPasswordW (
  170. IN PCWSTR EncodedOwfPassword,
  171. OUT PLM_OWF_PASSWORD LmOwfPassword,
  172. OUT PNT_OWF_PASSWORD NtOwfPassword,
  173. OUT PBOOL ComplexNtPassword OPTIONAL
  174. );
  175. BOOL
  176. StringDecodeLmOwfPasswordA (
  177. IN PCSTR EncodedOwfPassword,
  178. OUT PLM_OWF_PASSWORD OwfPassword
  179. );
  180. BOOL
  181. StringDecodeLmOwfPasswordW (
  182. IN PCWSTR EncodedOwfPassword,
  183. OUT PLM_OWF_PASSWORD OwfPassword
  184. );
  185. BOOL
  186. StringDecodeNtOwfPasswordA (
  187. IN PCSTR EncodedOwfPassword,
  188. OUT PNT_OWF_PASSWORD OwfPassword
  189. );
  190. BOOL
  191. StringDecodeNtOwfPasswordW (
  192. IN PCWSTR EncodedOwfPassword,
  193. OUT PNT_OWF_PASSWORD OwfPassword
  194. );
  195. //
  196. // Function name macros
  197. //
  198. #ifndef UNICODE
  199. #define EncodeLmOwfPassword EncodeLmOwfPasswordA
  200. #define EncodeNtOwfPassword EncodeNtOwfPasswordA
  201. #define StringEncodeOwfPassword StringEncodeOwfPasswordA
  202. #define StringEncodeLmOwfPassword StringEncodeLmOwfPasswordA
  203. #define StringEncodeNtOwfPassword StringEncodeNtOwfPasswordA
  204. #define StringDecodeOwfPassword StringDecodeOwfPasswordA
  205. #define StringDecodeLmOwfPassword StringDecodeLmOwfPasswordA
  206. #define StringDecodeNtOwfPassword StringDecodeNtOwfPasswordA
  207. #else
  208. #define EncodeLmOwfPassword EncodeLmOwfPasswordW
  209. #define EncodeNtOwfPassword EncodeNtOwfPasswordW
  210. #define StringEncodeOwfPassword StringEncodeOwfPasswordW
  211. #define StringEncodeLmOwfPassword StringEncodeLmOwfPasswordW
  212. #define StringEncodeNtOwfPassword StringEncodeNtOwfPasswordW
  213. #define StringDecodeOwfPassword StringDecodeOwfPasswordW
  214. #define StringDecodeLmOwfPassword StringDecodeLmOwfPasswordW
  215. #define StringDecodeNtOwfPassword StringDecodeNtOwfPasswordW
  216. #endif