diff --git a/src/eap-mschapv2.c b/src/eap-mschapv2.c index 8db4487e..e9392372 100644 --- a/src/eap-mschapv2.c +++ b/src/eap-mschapv2.c @@ -331,18 +331,12 @@ static void eap_mschapv2_handle_success(struct eap_state *eap, uint8_t master_key[16]; uint8_t session_key[32]; char authenticator_resp[42]; - struct l_checksum *check; bool ret; uint8_t buffer[5 + 1]; - check = l_checksum_new(L_CHECKSUM_MD4); - if (!check) - goto err; - - l_checksum_update(check, state->password_hash, 16); - l_checksum_get_digest(check, password_hash_hash, 16); - l_checksum_free(check); + mschapv2_hash_nt_password_hash(state->password_hash, + password_hash_hash); ret = mschapv2_generate_nt_response(state->password_hash, state->peer_challenge, diff --git a/src/mschaputil.c b/src/mschaputil.c index 39edddf3..7857936f 100644 --- a/src/mschaputil.c +++ b/src/mschaputil.c @@ -201,6 +201,30 @@ bool mschapv2_generate_nt_response(const uint8_t password_hash[static 16], return true; } +/** + * Generate the hash of the password hash + * + * @password_hash: The hash of the password + * @password_hash_hash: The MD4 hash of the password hash + * + * Returns: true on success, false if hash/encrypt couldn't be done + **/ +bool mschapv2_hash_nt_password_hash(const uint8_t password_hash[static 16], + uint8_t password_hash_hash[static 16]) +{ + struct l_checksum *check; + + check = l_checksum_new(L_CHECKSUM_MD4); + if (!check) + return false; + + l_checksum_update(check, password_hash, 16); + l_checksum_get_digest(check, password_hash_hash, 16); + l_checksum_free(check); + + return true; +} + /** * Generate the mschapv2 authenticator response for verifying authenticator * This function is specified in: diff --git a/src/mschaputil.h b/src/mschaputil.h index ee9765fd..7c767aca 100644 --- a/src/mschaputil.h +++ b/src/mschaputil.h @@ -26,6 +26,8 @@ bool mschap_challenge_response(const uint8_t *challenge, const uint8_t *password_hash, uint8_t *response); bool mschap_nt_password_hash(const char *password, uint8_t *password_hash); +bool mschapv2_hash_nt_password_hash(const uint8_t password_hash[static 16], + uint8_t password_hash_hash[static 16]); bool mschapv2_generate_nt_response(const uint8_t password_hash[static 16], const uint8_t peer_challenge[static 16],