Updated through tag hostap_2_5 from git://w1.fi/hostap.git
[mech_eap.git] / libeap / src / eap_peer / mschapv2.c
index b8fb075..9bc7370 100644 (file)
@@ -2,14 +2,8 @@
  * MSCHAPV2 (RFC 2759)
  * Copyright (c) 2004-2008, Jouni Malinen <j@w1.fi>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * Alternatively, this software may be distributed under the terms of BSD
- * license.
- *
- * See README and COPYING for more details.
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
  */
 
 #include "includes.h"
@@ -69,22 +63,28 @@ int mschapv2_derive_response(const u8 *identity, size_t identity_len,
        if (pwhash) {
                wpa_hexdump_key(MSG_DEBUG, "MSCHAPV2: password hash",
                                password, password_len);
-               generate_nt_response_pwhash(auth_challenge, peer_challenge,
-                                           username, username_len,
-                                           password, nt_response);
-               generate_authenticator_response_pwhash(
-                       password, peer_challenge, auth_challenge,
-                       username, username_len, nt_response, auth_response);
+               if (generate_nt_response_pwhash(auth_challenge, peer_challenge,
+                                               username, username_len,
+                                               password, nt_response) ||
+                   generate_authenticator_response_pwhash(
+                           password, peer_challenge, auth_challenge,
+                           username, username_len, nt_response,
+                           auth_response))
+                       return -1;
        } else {
                wpa_hexdump_ascii_key(MSG_DEBUG, "MSCHAPV2: password",
                                      password, password_len);
-               generate_nt_response(auth_challenge, peer_challenge,
-                                    username, username_len,
-                                    password, password_len, nt_response);
-               generate_authenticator_response(password, password_len,
-                                               peer_challenge, auth_challenge,
-                                               username, username_len,
-                                               nt_response, auth_response);
+               if (generate_nt_response(auth_challenge, peer_challenge,
+                                        username, username_len,
+                                        password, password_len,
+                                        nt_response) ||
+                   generate_authenticator_response(password, password_len,
+                                                   peer_challenge,
+                                                   auth_challenge,
+                                                   username, username_len,
+                                                   nt_response,
+                                                   auth_response))
+                       return -1;
        }
        wpa_hexdump(MSG_DEBUG, "MSCHAPV2: NT Response",
                    nt_response, MSCHAPV2_NT_RESPONSE_LEN);
@@ -100,7 +100,8 @@ int mschapv2_derive_response(const u8 *identity, size_t identity_len,
                    hash_nt_password_hash(password_hash, password_hash_hash))
                        return -1;
        }
-       get_master_key(password_hash_hash, nt_response, master_key);
+       if (get_master_key(password_hash_hash, nt_response, master_key))
+               return -1;
        wpa_hexdump_key(MSG_DEBUG, "MSCHAPV2: Master Key",
                        master_key, MSCHAPV2_MASTER_KEY_LEN);
 
@@ -116,8 +117,8 @@ int mschapv2_verify_auth_response(const u8 *auth_response,
            buf[0] != 'S' || buf[1] != '=' ||
            hexstr2bin((char *) (buf + 2), recv_response,
                       MSCHAPV2_AUTH_RESPONSE_LEN) ||
-           os_memcmp(auth_response, recv_response,
-                     MSCHAPV2_AUTH_RESPONSE_LEN) != 0)
+           os_memcmp_const(auth_response, recv_response,
+                           MSCHAPV2_AUTH_RESPONSE_LEN) != 0)
                return -1;
        return 0;
 }