ms_funcs.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. /*
  2. * WPA Supplicant / shared MSCHAPV2 helper functions / RFC 2433 / RFC 2759
  3. * Copyright (c) 2004-2012, Jouni Malinen <j@w1.fi>
  4. *
  5. * This software may be distributed under the terms of the BSD license.
  6. * See README for more details.
  7. */
  8. #include "includes.h"
  9. #include "common.h"
  10. #include "sha1.h"
  11. #include "ms_funcs.h"
  12. #include "crypto.h"
  13. /**
  14. * utf8_to_ucs2 - Convert UTF-8 string to UCS-2 encoding
  15. * @utf8_string: UTF-8 string (IN)
  16. * @utf8_string_len: Length of utf8_string (IN)
  17. * @ucs2_buffer: UCS-2 buffer (OUT)
  18. * @ucs2_buffer_size: Length of UCS-2 buffer (IN)
  19. * @ucs2_string_size: Number of 2-byte words in the resulting UCS-2 string
  20. * Returns: 0 on success, -1 on failure
  21. */
  22. static int utf8_to_ucs2(const u8 *utf8_string, size_t utf8_string_len,
  23. u8 *ucs2_buffer, size_t ucs2_buffer_size,
  24. size_t *ucs2_string_size)
  25. {
  26. size_t i, j;
  27. for (i = 0, j = 0; i < utf8_string_len; i++) {
  28. u8 c = utf8_string[i];
  29. if (j >= ucs2_buffer_size) {
  30. /* input too long */
  31. return -1;
  32. }
  33. if (c <= 0x7F) {
  34. WPA_PUT_LE16(ucs2_buffer + j, c);
  35. j += 2;
  36. } else if (i == utf8_string_len - 1 ||
  37. j >= ucs2_buffer_size - 1) {
  38. /* incomplete surrogate */
  39. return -1;
  40. } else {
  41. u8 c2 = utf8_string[++i];
  42. if ((c & 0xE0) == 0xC0) {
  43. /* two-byte encoding */
  44. WPA_PUT_LE16(ucs2_buffer + j,
  45. ((c & 0x1F) << 6) | (c2 & 0x3F));
  46. j += 2;
  47. } else if (i == utf8_string_len ||
  48. j >= ucs2_buffer_size - 1) {
  49. /* incomplete surrogate */
  50. return -1;
  51. } else {
  52. /* three-byte encoding */
  53. u8 c3 = utf8_string[++i];
  54. WPA_PUT_LE16(ucs2_buffer + j,
  55. ((c & 0xF) << 12) |
  56. ((c2 & 0x3F) << 6) | (c3 & 0x3F));
  57. j += 2;
  58. }
  59. }
  60. }
  61. if (ucs2_string_size)
  62. *ucs2_string_size = j / 2;
  63. return 0;
  64. }
  65. /**
  66. * challenge_hash - ChallengeHash() - RFC 2759, Sect. 8.2
  67. * @peer_challenge: 16-octet PeerChallenge (IN)
  68. * @auth_challenge: 16-octet AuthenticatorChallenge (IN)
  69. * @username: 0-to-256-char UserName (IN)
  70. * @username_len: Length of username
  71. * @challenge: 8-octet Challenge (OUT)
  72. * Returns: 0 on success, -1 on failure
  73. */
  74. int challenge_hash(const u8 *peer_challenge, const u8 *auth_challenge,
  75. const u8 *username, size_t username_len, u8 *challenge)
  76. {
  77. u8 hash[SHA1_MAC_LEN];
  78. const unsigned char *addr[3];
  79. size_t len[3];
  80. addr[0] = peer_challenge;
  81. len[0] = 16;
  82. addr[1] = auth_challenge;
  83. len[1] = 16;
  84. addr[2] = username;
  85. len[2] = username_len;
  86. if (sha1_vector(3, addr, len, hash))
  87. return -1;
  88. os_memcpy(challenge, hash, 8);
  89. return 0;
  90. }
  91. /**
  92. * nt_password_hash - NtPasswordHash() - RFC 2759, Sect. 8.3
  93. * @password: 0-to-256-unicode-char Password (IN; UTF-8)
  94. * @password_len: Length of password
  95. * @password_hash: 16-octet PasswordHash (OUT)
  96. * Returns: 0 on success, -1 on failure
  97. */
  98. int nt_password_hash(const u8 *password, size_t password_len,
  99. u8 *password_hash)
  100. {
  101. u8 buf[512], *pos;
  102. size_t len, max_len;
  103. max_len = sizeof(buf);
  104. if (utf8_to_ucs2(password, password_len, buf, max_len, &len) < 0)
  105. return -1;
  106. len *= 2;
  107. pos = buf;
  108. return md4_vector(1, (const u8 **) &pos, &len, password_hash);
  109. }
  110. /**
  111. * hash_nt_password_hash - HashNtPasswordHash() - RFC 2759, Sect. 8.4
  112. * @password_hash: 16-octet PasswordHash (IN)
  113. * @password_hash_hash: 16-octet PasswordHashHash (OUT)
  114. * Returns: 0 on success, -1 on failure
  115. */
  116. int hash_nt_password_hash(const u8 *password_hash, u8 *password_hash_hash)
  117. {
  118. size_t len = 16;
  119. return md4_vector(1, &password_hash, &len, password_hash_hash);
  120. }
  121. /**
  122. * challenge_response - ChallengeResponse() - RFC 2759, Sect. 8.5
  123. * @challenge: 8-octet Challenge (IN)
  124. * @password_hash: 16-octet PasswordHash (IN)
  125. * @response: 24-octet Response (OUT)
  126. */
  127. void challenge_response(const u8 *challenge, const u8 *password_hash,
  128. u8 *response)
  129. {
  130. u8 zpwd[7];
  131. des_encrypt(challenge, password_hash, response);
  132. des_encrypt(challenge, password_hash + 7, response + 8);
  133. zpwd[0] = password_hash[14];
  134. zpwd[1] = password_hash[15];
  135. os_memset(zpwd + 2, 0, 5);
  136. des_encrypt(challenge, zpwd, response + 16);
  137. }
  138. /**
  139. * generate_nt_response - GenerateNTResponse() - RFC 2759, Sect. 8.1
  140. * @auth_challenge: 16-octet AuthenticatorChallenge (IN)
  141. * @peer_challenge: 16-octet PeerChallenge (IN)
  142. * @username: 0-to-256-char UserName (IN)
  143. * @username_len: Length of username
  144. * @password: 0-to-256-unicode-char Password (IN; UTF-8)
  145. * @password_len: Length of password
  146. * @response: 24-octet Response (OUT)
  147. * Returns: 0 on success, -1 on failure
  148. */
  149. int generate_nt_response(const u8 *auth_challenge, const u8 *peer_challenge,
  150. const u8 *username, size_t username_len,
  151. const u8 *password, size_t password_len,
  152. u8 *response)
  153. {
  154. u8 challenge[8];
  155. u8 password_hash[16];
  156. if (challenge_hash(peer_challenge, auth_challenge, username,
  157. username_len, challenge) ||
  158. nt_password_hash(password, password_len, password_hash))
  159. return -1;
  160. challenge_response(challenge, password_hash, response);
  161. return 0;
  162. }
  163. /**
  164. * generate_nt_response_pwhash - GenerateNTResponse() - RFC 2759, Sect. 8.1
  165. * @auth_challenge: 16-octet AuthenticatorChallenge (IN)
  166. * @peer_challenge: 16-octet PeerChallenge (IN)
  167. * @username: 0-to-256-char UserName (IN)
  168. * @username_len: Length of username
  169. * @password_hash: 16-octet PasswordHash (IN)
  170. * @response: 24-octet Response (OUT)
  171. * Returns: 0 on success, -1 on failure
  172. */
  173. int generate_nt_response_pwhash(const u8 *auth_challenge,
  174. const u8 *peer_challenge,
  175. const u8 *username, size_t username_len,
  176. const u8 *password_hash,
  177. u8 *response)
  178. {
  179. u8 challenge[8];
  180. if (challenge_hash(peer_challenge, auth_challenge,
  181. username, username_len,
  182. challenge))
  183. return -1;
  184. challenge_response(challenge, password_hash, response);
  185. return 0;
  186. }
  187. /**
  188. * generate_authenticator_response_pwhash - GenerateAuthenticatorResponse() - RFC 2759, Sect. 8.7
  189. * @password_hash: 16-octet PasswordHash (IN)
  190. * @nt_response: 24-octet NT-Response (IN)
  191. * @peer_challenge: 16-octet PeerChallenge (IN)
  192. * @auth_challenge: 16-octet AuthenticatorChallenge (IN)
  193. * @username: 0-to-256-char UserName (IN)
  194. * @username_len: Length of username
  195. * @response: 20-octet AuthenticatorResponse (OUT) (note: this value is usually
  196. * encoded as a 42-octet ASCII string (S=hexdump_of_response)
  197. * Returns: 0 on success, -1 on failure
  198. */
  199. int generate_authenticator_response_pwhash(
  200. const u8 *password_hash,
  201. const u8 *peer_challenge, const u8 *auth_challenge,
  202. const u8 *username, size_t username_len,
  203. const u8 *nt_response, u8 *response)
  204. {
  205. static const u8 magic1[39] = {
  206. 0x4D, 0x61, 0x67, 0x69, 0x63, 0x20, 0x73, 0x65, 0x72, 0x76,
  207. 0x65, 0x72, 0x20, 0x74, 0x6F, 0x20, 0x63, 0x6C, 0x69, 0x65,
  208. 0x6E, 0x74, 0x20, 0x73, 0x69, 0x67, 0x6E, 0x69, 0x6E, 0x67,
  209. 0x20, 0x63, 0x6F, 0x6E, 0x73, 0x74, 0x61, 0x6E, 0x74
  210. };
  211. static const u8 magic2[41] = {
  212. 0x50, 0x61, 0x64, 0x20, 0x74, 0x6F, 0x20, 0x6D, 0x61, 0x6B,
  213. 0x65, 0x20, 0x69, 0x74, 0x20, 0x64, 0x6F, 0x20, 0x6D, 0x6F,
  214. 0x72, 0x65, 0x20, 0x74, 0x68, 0x61, 0x6E, 0x20, 0x6F, 0x6E,
  215. 0x65, 0x20, 0x69, 0x74, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6F,
  216. 0x6E
  217. };
  218. u8 password_hash_hash[16], challenge[8];
  219. const unsigned char *addr1[3];
  220. const size_t len1[3] = { 16, 24, sizeof(magic1) };
  221. const unsigned char *addr2[3];
  222. const size_t len2[3] = { SHA1_MAC_LEN, 8, sizeof(magic2) };
  223. addr1[0] = password_hash_hash;
  224. addr1[1] = nt_response;
  225. addr1[2] = magic1;
  226. addr2[0] = response;
  227. addr2[1] = challenge;
  228. addr2[2] = magic2;
  229. if (hash_nt_password_hash(password_hash, password_hash_hash) ||
  230. sha1_vector(3, addr1, len1, response) ||
  231. challenge_hash(peer_challenge, auth_challenge, username,
  232. username_len, challenge))
  233. return -1;
  234. return sha1_vector(3, addr2, len2, response);
  235. }
  236. /**
  237. * generate_authenticator_response - GenerateAuthenticatorResponse() - RFC 2759, Sect. 8.7
  238. * @password: 0-to-256-unicode-char Password (IN; UTF-8)
  239. * @password_len: Length of password
  240. * @nt_response: 24-octet NT-Response (IN)
  241. * @peer_challenge: 16-octet PeerChallenge (IN)
  242. * @auth_challenge: 16-octet AuthenticatorChallenge (IN)
  243. * @username: 0-to-256-char UserName (IN)
  244. * @username_len: Length of username
  245. * @response: 20-octet AuthenticatorResponse (OUT) (note: this value is usually
  246. * encoded as a 42-octet ASCII string (S=hexdump_of_response)
  247. * Returns: 0 on success, -1 on failure
  248. */
  249. int generate_authenticator_response(const u8 *password, size_t password_len,
  250. const u8 *peer_challenge,
  251. const u8 *auth_challenge,
  252. const u8 *username, size_t username_len,
  253. const u8 *nt_response, u8 *response)
  254. {
  255. u8 password_hash[16];
  256. if (nt_password_hash(password, password_len, password_hash))
  257. return -1;
  258. return generate_authenticator_response_pwhash(
  259. password_hash, peer_challenge, auth_challenge,
  260. username, username_len, nt_response, response);
  261. }
  262. /**
  263. * nt_challenge_response - NtChallengeResponse() - RFC 2433, Sect. A.5
  264. * @challenge: 8-octet Challenge (IN)
  265. * @password: 0-to-256-unicode-char Password (IN; UTF-8)
  266. * @password_len: Length of password
  267. * @response: 24-octet Response (OUT)
  268. * Returns: 0 on success, -1 on failure
  269. */
  270. int nt_challenge_response(const u8 *challenge, const u8 *password,
  271. size_t password_len, u8 *response)
  272. {
  273. u8 password_hash[16];
  274. if (nt_password_hash(password, password_len, password_hash))
  275. return -1;
  276. challenge_response(challenge, password_hash, response);
  277. return 0;
  278. }
  279. /**
  280. * get_master_key - GetMasterKey() - RFC 3079, Sect. 3.4
  281. * @password_hash_hash: 16-octet PasswordHashHash (IN)
  282. * @nt_response: 24-octet NTResponse (IN)
  283. * @master_key: 16-octet MasterKey (OUT)
  284. * Returns: 0 on success, -1 on failure
  285. */
  286. int get_master_key(const u8 *password_hash_hash, const u8 *nt_response,
  287. u8 *master_key)
  288. {
  289. static const u8 magic1[27] = {
  290. 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x74,
  291. 0x68, 0x65, 0x20, 0x4d, 0x50, 0x50, 0x45, 0x20, 0x4d,
  292. 0x61, 0x73, 0x74, 0x65, 0x72, 0x20, 0x4b, 0x65, 0x79
  293. };
  294. const unsigned char *addr[3];
  295. const size_t len[3] = { 16, 24, sizeof(magic1) };
  296. u8 hash[SHA1_MAC_LEN];
  297. addr[0] = password_hash_hash;
  298. addr[1] = nt_response;
  299. addr[2] = magic1;
  300. if (sha1_vector(3, addr, len, hash))
  301. return -1;
  302. os_memcpy(master_key, hash, 16);
  303. return 0;
  304. }
  305. /**
  306. * get_asymetric_start_key - GetAsymetricStartKey() - RFC 3079, Sect. 3.4
  307. * @master_key: 16-octet MasterKey (IN)
  308. * @session_key: 8-to-16 octet SessionKey (OUT)
  309. * @session_key_len: SessionKeyLength (Length of session_key) (IN)
  310. * @is_send: IsSend (IN, BOOLEAN)
  311. * @is_server: IsServer (IN, BOOLEAN)
  312. * Returns: 0 on success, -1 on failure
  313. */
  314. int get_asymetric_start_key(const u8 *master_key, u8 *session_key,
  315. size_t session_key_len, int is_send,
  316. int is_server)
  317. {
  318. static const u8 magic2[84] = {
  319. 0x4f, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6c, 0x69,
  320. 0x65, 0x6e, 0x74, 0x20, 0x73, 0x69, 0x64, 0x65, 0x2c, 0x20,
  321. 0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x74, 0x68,
  322. 0x65, 0x20, 0x73, 0x65, 0x6e, 0x64, 0x20, 0x6b, 0x65, 0x79,
  323. 0x3b, 0x20, 0x6f, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x73,
  324. 0x65, 0x72, 0x76, 0x65, 0x72, 0x20, 0x73, 0x69, 0x64, 0x65,
  325. 0x2c, 0x20, 0x69, 0x74, 0x20, 0x69, 0x73, 0x20, 0x74, 0x68,
  326. 0x65, 0x20, 0x72, 0x65, 0x63, 0x65, 0x69, 0x76, 0x65, 0x20,
  327. 0x6b, 0x65, 0x79, 0x2e
  328. };
  329. static const u8 magic3[84] = {
  330. 0x4f, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6c, 0x69,
  331. 0x65, 0x6e, 0x74, 0x20, 0x73, 0x69, 0x64, 0x65, 0x2c, 0x20,
  332. 0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x74, 0x68,
  333. 0x65, 0x20, 0x72, 0x65, 0x63, 0x65, 0x69, 0x76, 0x65, 0x20,
  334. 0x6b, 0x65, 0x79, 0x3b, 0x20, 0x6f, 0x6e, 0x20, 0x74, 0x68,
  335. 0x65, 0x20, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x20, 0x73,
  336. 0x69, 0x64, 0x65, 0x2c, 0x20, 0x69, 0x74, 0x20, 0x69, 0x73,
  337. 0x20, 0x74, 0x68, 0x65, 0x20, 0x73, 0x65, 0x6e, 0x64, 0x20,
  338. 0x6b, 0x65, 0x79, 0x2e
  339. };
  340. static const u8 shs_pad1[40] = {
  341. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  342. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  343. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  344. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  345. };
  346. static const u8 shs_pad2[40] = {
  347. 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2,
  348. 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2,
  349. 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2,
  350. 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2
  351. };
  352. u8 digest[SHA1_MAC_LEN];
  353. const unsigned char *addr[4];
  354. const size_t len[4] = { 16, 40, 84, 40 };
  355. addr[0] = master_key;
  356. addr[1] = shs_pad1;
  357. if (is_send) {
  358. addr[2] = is_server ? magic3 : magic2;
  359. } else {
  360. addr[2] = is_server ? magic2 : magic3;
  361. }
  362. addr[3] = shs_pad2;
  363. if (sha1_vector(4, addr, len, digest))
  364. return -1;
  365. if (session_key_len > SHA1_MAC_LEN)
  366. session_key_len = SHA1_MAC_LEN;
  367. os_memcpy(session_key, digest, session_key_len);
  368. return 0;
  369. }
  370. #ifndef CONFIG_NO_RC4
  371. #define PWBLOCK_LEN 516
  372. /**
  373. * encrypt_pw_block_with_password_hash - EncryptPwBlockWithPasswordHash() - RFC 2759, Sect. 8.10
  374. * @password: 0-to-256-unicode-char Password (IN; UTF-8)
  375. * @password_len: Length of password
  376. * @password_hash: 16-octet PasswordHash (IN)
  377. * @pw_block: 516-byte PwBlock (OUT)
  378. * Returns: 0 on success, -1 on failure
  379. */
  380. int encrypt_pw_block_with_password_hash(
  381. const u8 *password, size_t password_len,
  382. const u8 *password_hash, u8 *pw_block)
  383. {
  384. size_t ucs2_len, offset;
  385. u8 *pos;
  386. os_memset(pw_block, 0, PWBLOCK_LEN);
  387. if (utf8_to_ucs2(password, password_len, pw_block, 512, &ucs2_len) < 0
  388. || ucs2_len > 256)
  389. return -1;
  390. offset = (256 - ucs2_len) * 2;
  391. if (offset != 0) {
  392. os_memmove(pw_block + offset, pw_block, ucs2_len * 2);
  393. if (os_get_random(pw_block, offset) < 0)
  394. return -1;
  395. }
  396. /*
  397. * PasswordLength is 4 octets, but since the maximum password length is
  398. * 256, only first two (in little endian byte order) can be non-zero.
  399. */
  400. pos = &pw_block[2 * 256];
  401. WPA_PUT_LE16(pos, password_len * 2);
  402. rc4_skip(password_hash, 16, 0, pw_block, PWBLOCK_LEN);
  403. return 0;
  404. }
  405. /**
  406. * new_password_encrypted_with_old_nt_password_hash - NewPasswordEncryptedWithOldNtPasswordHash() - RFC 2759, Sect. 8.9
  407. * @new_password: 0-to-256-unicode-char NewPassword (IN; UTF-8)
  408. * @new_password_len: Length of new_password
  409. * @old_password: 0-to-256-unicode-char OldPassword (IN; UTF-8)
  410. * @old_password_len: Length of old_password
  411. * @encrypted_pw_block: 516-octet EncryptedPwBlock (OUT)
  412. * Returns: 0 on success, -1 on failure
  413. */
  414. int new_password_encrypted_with_old_nt_password_hash(
  415. const u8 *new_password, size_t new_password_len,
  416. const u8 *old_password, size_t old_password_len,
  417. u8 *encrypted_pw_block)
  418. {
  419. u8 password_hash[16];
  420. if (nt_password_hash(old_password, old_password_len, password_hash))
  421. return -1;
  422. if (encrypt_pw_block_with_password_hash(new_password, new_password_len,
  423. password_hash,
  424. encrypted_pw_block))
  425. return -1;
  426. return 0;
  427. }
  428. #endif /* CONFIG_NO_RC4 */
  429. /**
  430. * nt_password_hash_encrypted_with_block - NtPasswordHashEncryptedWithBlock() - RFC 2759, Sect 8.13
  431. * @password_hash: 16-octer PasswordHash (IN)
  432. * @block: 16-octet Block (IN)
  433. * @cypher: 16-octer Cypher (OUT)
  434. */
  435. void nt_password_hash_encrypted_with_block(const u8 *password_hash,
  436. const u8 *block, u8 *cypher)
  437. {
  438. des_encrypt(password_hash, block, cypher);
  439. des_encrypt(password_hash + 8, block + 7, cypher + 8);
  440. }
  441. /**
  442. * old_nt_password_hash_encrypted_with_new_nt_password_hash - OldNtPasswordHashEncryptedWithNewNtPasswordHash() - RFC 2759, Sect. 8.12
  443. * @new_password: 0-to-256-unicode-char NewPassword (IN; UTF-8)
  444. * @new_password_len: Length of new_password
  445. * @old_password: 0-to-256-unicode-char OldPassword (IN; UTF-8)
  446. * @old_password_len: Length of old_password
  447. * @encrypted_password_hash: 16-octet EncryptedPasswordHash (OUT)
  448. * Returns: 0 on success, -1 on failure
  449. */
  450. int old_nt_password_hash_encrypted_with_new_nt_password_hash(
  451. const u8 *new_password, size_t new_password_len,
  452. const u8 *old_password, size_t old_password_len,
  453. u8 *encrypted_password_hash)
  454. {
  455. u8 old_password_hash[16], new_password_hash[16];
  456. if (nt_password_hash(old_password, old_password_len,
  457. old_password_hash) ||
  458. nt_password_hash(new_password, new_password_len,
  459. new_password_hash))
  460. return -1;
  461. nt_password_hash_encrypted_with_block(old_password_hash,
  462. new_password_hash,
  463. encrypted_password_hash);
  464. return 0;
  465. }