ms_funcs.c 16 KB

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