ms_funcs.c 16 KB

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