eapol/eapol_framework/eapol_common/core/eapol_key_state_common.cpp
branchRCL_3
changeset 46 c74b3d9f6b9e
parent 45 bad0cc58d154
equal deleted inserted replaced
45:bad0cc58d154 46:c74b3d9f6b9e
    14 * Description:  EAP and WLAN authentication protocols.
    14 * Description:  EAP and WLAN authentication protocols.
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 /*
    18 /*
    19 * %version: 135 %
    19 * %version: 120.1.6.1.2 %
    20 */
    20 */
    21 
    21 
    22 // This is enumeration of EAPOL source code.
    22 // This is enumeration of EAPOL source code.
    23 #if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
    23 #if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
    24 	#undef EAP_FILE_NUMBER_ENUM
    24 	#undef EAP_FILE_NUMBER_ENUM
   275 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
   275 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
   276 			return EAP_STATUS_RETURN(m_am_tools, status);
   276 			return EAP_STATUS_RETURN(m_am_tools, status);
   277 		}
   277 		}
   278 	}
   278 	}
   279 
   279 
       
   280 #if defined(USE_EAPOL_KEY_STATE_OPTIMIZED_4_WAY_HANDSHAKE)
   280 	{
   281 	{
   281 		m_is_associated = true;
   282 		m_is_associated = true;
   282 
   283 
   283 		EAP_TRACE_DEBUG(
   284 		EAP_TRACE_DEBUG(
   284 			m_am_tools, 
   285 			m_am_tools, 
   285 			TRACE_FLAGS_DEFAULT, 
   286 			TRACE_FLAGS_DEFAULT, 
   286 			(EAPL("EAPOL_KEY: %s: eapol_key_state_c::initialize(): m_is_associated=%s.\n"),
   287 			(EAPL("EAPOL_KEY: %s: eapol_key_state_c::initialize(): m_is_associated=%s.\n"),
   287 			 (m_is_client == true) ? "client": "server",
   288 			 (m_is_client == true) ? "client": "server",
   288 			 (m_is_associated == true) ? "true": "false"));
   289 			 (m_is_associated == true) ? "true": "false"));
   289 	}
   290 	}
       
   291 #endif //#if defined(USE_EAPOL_KEY_STATE_OPTIMIZED_4_WAY_HANDSHAKE)
   290 
   292 
   291 	return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
   293 	return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
   292 }
   294 }
   293 
   295 
   294 //--------------------------------------------------
   296 //--------------------------------------------------
       
   297 
       
   298 #if defined(USE_EAPOL_KEY_STATE) && defined(USE_EAPOL_KEY_STATE_OPTIMIZED_4_WAY_HANDSHAKE)
   295 
   299 
   296 // 
   300 // 
   297 EAP_FUNC_EXPORT eap_status_e eapol_key_state_c::initialize(
   301 EAP_FUNC_EXPORT eap_status_e eapol_key_state_c::initialize(
   298 	const eap_am_network_id_c * const receive_network_id,
   302 	const eap_am_network_id_c * const receive_network_id,
   299 	const eapol_key_authentication_type_e authentication_type)
   303 	const eapol_key_authentication_type_e authentication_type)
   322 	set_eapol_key_state(eapol_key_state_none);
   326 	set_eapol_key_state(eapol_key_state_none);
   323 	m_eapol_key_handshake_type = eapol_key_handshake_type_none;
   327 	m_eapol_key_handshake_type = eapol_key_handshake_type_none;
   324 
   328 
   325 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   329 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   326 
   330 
       
   331 #if defined(USE_EAPOL_KEY_STATE_OPTIMIZED_4_WAY_HANDSHAKE)
   327 	// Creates SNonce. This is done here in early phase of authentication.
   332 	// Creates SNonce. This is done here in early phase of authentication.
   328 	// This will reduce the CPU load when time critical first message
   333 	// This will reduce the CPU load when time critical first message
   329 	// of 4-Way handshake is processed.
   334 	// of 4-Way handshake is processed.
   330 	status = create_nonce(&m_SNonce, EAPOL_RSNA_NONCE_LENGTH_BYTES);
   335 	status = create_nonce(&m_SNonce, EAPOL_RSNA_NONCE_LENGTH_BYTES);
   331 	if (status != eap_status_ok)
   336 	if (status != eap_status_ok)
   332 	{
   337 	{
   333 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
   338 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
   334 		return EAP_STATUS_RETURN(m_am_tools, status);
   339 		return EAP_STATUS_RETURN(m_am_tools, status);
   335 	}
   340 	}
       
   341 #endif //#if defined(USE_EAPOL_KEY_STATE_OPTIMIZED_4_WAY_HANDSHAKE)
   336 
   342 
   337 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   343 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   338 
   344 
   339 
   345 
   340 	return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
   346 	return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
   341 }
   347 }
       
   348 
       
   349 #endif //#if defined(USE_EAPOL_KEY_STATE) && defined(USE_EAPOL_KEY_STATE_OPTIMIZED_4_WAY_HANDSHAKE)
   342 
   350 
   343 //--------------------------------------------------
   351 //--------------------------------------------------
   344 
   352 
   345 // 
   353 // 
   346 eap_status_e eapol_key_state_c::set_mac_addresses(
   354 eap_status_e eapol_key_state_c::set_mac_addresses(
   511 	, m_skip_PMKID_key_data_in_message_1(false)
   519 	, m_skip_PMKID_key_data_in_message_1(false)
   512 	, m_allow_non_zero_mic_and_reserved_in_message_1(false)
   520 	, m_allow_non_zero_mic_and_reserved_in_message_1(false)
   513 	, m_indicate_pmkid_to_lower_layer(false)
   521 	, m_indicate_pmkid_to_lower_layer(false)
   514 	, m_handshake_timeout_set(false)
   522 	, m_handshake_timeout_set(false)
   515 	, m_server_TEST_group_key_update(false)
   523 	, m_server_TEST_group_key_update(false)
       
   524 #if defined(USE_EAPOL_KEY_STATE_OPTIMIZED_4_WAY_HANDSHAKE)
   516 	, m_is_associated(false)
   525 	, m_is_associated(false)
       
   526 #endif //#if defined(USE_EAPOL_KEY_STATE_OPTIMIZED_4_WAY_HANDSHAKE)
   517 {
   527 {
   518 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
   528 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
   519 
   529 
   520 	EAP_UNREFERENCED_PARAMETER(receive_network_id);
   530 	EAP_UNREFERENCED_PARAMETER(receive_network_id);
   521 	EAP_UNREFERENCED_PARAMETER(authenticator_RSNA_IE);
   531 	EAP_UNREFERENCED_PARAMETER(authenticator_RSNA_IE);
   604 	, m_skip_PMKID_key_data_in_message_1(false)
   614 	, m_skip_PMKID_key_data_in_message_1(false)
   605 	, m_allow_non_zero_mic_and_reserved_in_message_1(false)
   615 	, m_allow_non_zero_mic_and_reserved_in_message_1(false)
   606 	, m_indicate_pmkid_to_lower_layer(false)
   616 	, m_indicate_pmkid_to_lower_layer(false)
   607 	, m_handshake_timeout_set(false)
   617 	, m_handshake_timeout_set(false)
   608 	, m_server_TEST_group_key_update(false)
   618 	, m_server_TEST_group_key_update(false)
       
   619 #if defined(USE_EAPOL_KEY_STATE_OPTIMIZED_4_WAY_HANDSHAKE)
   609 	, m_is_associated(false)
   620 	, m_is_associated(false)
       
   621 #endif //#if defined(USE_EAPOL_KEY_STATE_OPTIMIZED_4_WAY_HANDSHAKE)
   610 {
   622 {
   611 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
   623 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
   612 
   624 
   613 	EAP_TRACE_DEBUG(
   625 	EAP_TRACE_DEBUG(
   614 		m_am_tools,
   626 		m_am_tools,
   939 	const u32_t WPXM_WPXC,
   951 	const u32_t WPXM_WPXC,
   940 	const eapol_key_handshake_type_e eapol_key_handshake_type,
   952 	const eapol_key_handshake_type_e eapol_key_handshake_type,
   941 	const eapol_key_authentication_type_e authentication_type
   953 	const eapol_key_authentication_type_e authentication_type
   942 	)
   954 	)
   943 {
   955 {
   944 	EAP_UNREFERENCED_PARAMETER(eapol_key_handshake_type);
       
   945 	EAP_UNREFERENCED_PARAMETER(authentication_type);
       
   946 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
   956 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
   947 
   957 
   948 	EAP_TRACE_DEBUG(
   958 	EAP_TRACE_DEBUG(
   949 		m_am_tools, 
   959 		m_am_tools, 
   950 		TRACE_FLAGS_DEFAULT, 
   960 		TRACE_FLAGS_DEFAULT, 
  1136 		(void) EAP_STATUS_RETURN(m_am_tools, status);
  1146 		(void) EAP_STATUS_RETURN(m_am_tools, status);
  1137 		return 0;
  1147 		return 0;
  1138 	}
  1148 	}
  1139 
  1149 
  1140 
  1150 
       
  1151 #if defined(USE_EAPOL_KEY_STATE) && defined(USE_EAPOL_KEY_STATE_OPTIMIZED_4_WAY_HANDSHAKE)
       
  1152 
  1141 	status = new_state->initialize(
  1153 	status = new_state->initialize(
  1142 		receive_network_id,
  1154 		receive_network_id,
  1143 		m_authentication_type);
  1155 		m_authentication_type);
  1144 	if (status != eap_status_ok)
  1156 	if (status != eap_status_ok)
  1145 	{
  1157 	{
  1146 		new_state->shutdown();
  1158 		new_state->shutdown();
  1147 		delete new_state;
  1159 		delete new_state;
  1148 		(void) EAP_STATUS_RETURN(m_am_tools, status);
  1160 		(void) EAP_STATUS_RETURN(m_am_tools, status);
  1149 		return 0;
  1161 		return 0;
  1150 	}
  1162 	}
       
  1163 
       
  1164 #endif //#if defined(USE_EAPOL_KEY_STATE) && defined(USE_EAPOL_KEY_STATE_OPTIMIZED_4_WAY_HANDSHAKE)
       
  1165 
  1151 
  1166 
  1152 	eapol_key_handshake_type_e eapol_key_handshake_type(m_eapol_key_handshake_type);
  1167 	eapol_key_handshake_type_e eapol_key_handshake_type(m_eapol_key_handshake_type);
  1153 
  1168 
  1154 	eapol_key_authentication_type_e authentication_type(m_authentication_type);
  1169 	eapol_key_authentication_type_e authentication_type(m_authentication_type);
  1155 
  1170 
  1404 	eap_status_e status = eap_status_ok;
  1419 	eap_status_e status = eap_status_ok;
  1405 
  1420 
  1406 	EAP_TRACE_DEBUG(
  1421 	EAP_TRACE_DEBUG(
  1407 		m_am_tools, 
  1422 		m_am_tools, 
  1408 		TRACE_FLAGS_DEFAULT, 
  1423 		TRACE_FLAGS_DEFAULT, 
  1409 		(EAPL("EAPOL_KEY: %s: eapol_key_state_c::check_pmksa_cache(): this = 0x%08x, state %d=%s,\n"),
  1424 		(EAPL("EAPOL_KEY: %s: eapol_key_state_c::check_pmksa_cache(): this = 0x%08x, state %d=%s, selected_eapol_key_authentication_type %d=%s, m_authentication_type %d=%s.\n"),
  1410 		 (m_is_client == true) ? "client": "server",
  1425 		 (m_is_client == true) ? "client": "server",
  1411 		 this,
  1426 		 this,
  1412 		 get_eapol_key_state(),
  1427 		 get_eapol_key_state(),
  1413 		 eapol_key_state_string_c::get_eapol_key_state_string(get_eapol_key_state())));
  1428 		 eapol_key_state_string_c::get_eapol_key_state_string(get_eapol_key_state()),
  1414 
       
  1415 	EAP_TRACE_DEBUG(
       
  1416 		m_am_tools, 
       
  1417 		TRACE_FLAGS_DEFAULT, 
       
  1418 		(EAPL("EAPOL_KEY: %s: eapol_key_state_c::check_pmksa_cache(): selected_eapol_key_authentication_type %d=%s, m_authentication_type %d=%s.\n"),
       
  1419 		 (m_is_client == true) ? "client": "server",
       
  1420 		 selected_eapol_key_authentication_type,
  1429 		 selected_eapol_key_authentication_type,
  1421 		 eapol_key_state_string_c::get_eapol_key_authentication_type_string(selected_eapol_key_authentication_type),
  1430 		 eapol_key_state_string_c::get_eapol_key_authentication_type_string(selected_eapol_key_authentication_type),
  1422 		 m_authentication_type,
  1431 		 m_authentication_type,
  1423 		 eapol_key_state_string_c::get_eapol_key_authentication_type_string(m_authentication_type)));
  1432 		 eapol_key_state_string_c::get_eapol_key_authentication_type_string(m_authentication_type)));
  1424 
  1433 
  1558 		}
  1567 		}
  1559 	}
  1568 	}
  1560 
  1569 
  1561 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1570 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1562 
  1571 
       
  1572 #if defined(USE_EAPOL_KEY_STATE_OPTIMIZED_4_WAY_HANDSHAKE)
  1563 	// Creates SNonce. This is done here in early phase of authentication.
  1573 	// Creates SNonce. This is done here in early phase of authentication.
  1564 	// This will reduce the CPU load when time critical first message
  1574 	// This will reduce the CPU load when time critical first message
  1565 	// of 4-Way handshake is processed.
  1575 	// of 4-Way handshake is processed.
  1566 	status = create_nonce(&m_SNonce, EAPOL_RSNA_NONCE_LENGTH_BYTES);
  1576 	status = create_nonce(&m_SNonce, EAPOL_RSNA_NONCE_LENGTH_BYTES);
  1567 	if (status != eap_status_ok)
  1577 	if (status != eap_status_ok)
  1568 	{
  1578 	{
  1569 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
  1579 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
  1570 		return EAP_STATUS_RETURN(m_am_tools, status);
  1580 		return EAP_STATUS_RETURN(m_am_tools, status);
  1571 	}
  1581 	}
       
  1582 #endif //#if defined(USE_EAPOL_KEY_STATE_OPTIMIZED_4_WAY_HANDSHAKE)
  1572 
  1583 
  1573 	status = init_handshake_timeout(m_handshake_timeout);
  1584 	status = init_handshake_timeout(m_handshake_timeout);
  1574 	if (status != eap_status_ok)
  1585 	if (status != eap_status_ok)
  1575 	{
  1586 	{
  1576 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
  1587 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
  1669 }
  1680 }
  1670 
  1681 
  1671 //--------------------------------------------------
  1682 //--------------------------------------------------
  1672 
  1683 
  1673 //
  1684 //
  1674 EAP_FUNC_EXPORT eap_status_e eapol_key_state_c::complete_reassociation(
  1685 eap_status_e eapol_key_state_c::complete_reassociation(
  1675 	const eapol_wlan_authentication_state_e reassociation_result,
  1686 	const eapol_wlan_authentication_state_e reassociation_result,
  1676 	const eap_am_network_id_c * const /* receive_network_id */,
  1687 	const eap_am_network_id_c * const /* receive_network_id */,
  1677 	const eapol_key_authentication_type_e authentication_type,
  1688 	const eapol_key_authentication_type_e authentication_type,
  1678 	const eap_variable_data_c * const received_WPA_IE,
  1689 	const eap_variable_data_c * const received_WPA_IE,
  1679 	const eap_variable_data_c * const sent_WPA_IE,
  1690 	const eap_variable_data_c * const sent_WPA_IE,
  1732 		{
  1743 		{
  1733 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
  1744 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
  1734 			return EAP_STATUS_RETURN(m_am_tools, eap_status_authentication_failure);
  1745 			return EAP_STATUS_RETURN(m_am_tools, eap_status_authentication_failure);
  1735 		}
  1746 		}
  1736 
  1747 
       
  1748 #if defined(USE_EAPOL_KEY_STATE_OPTIMIZED_4_WAY_HANDSHAKE)
  1737 		{
  1749 		{
  1738 			m_is_associated = true;
  1750 			m_is_associated = true;
  1739 
  1751 
  1740 			EAP_TRACE_DEBUG(
  1752 			EAP_TRACE_DEBUG(
  1741 				m_am_tools, 
  1753 				m_am_tools, 
  1742 				TRACE_FLAGS_DEFAULT, 
  1754 				TRACE_FLAGS_DEFAULT, 
  1743 				(EAPL("EAPOL_KEY: %s: eapol_key_state_c::complete_reassociation(): m_is_associated=%s.\n"),
  1755 				(EAPL("EAPOL_KEY: %s: eapol_key_state_c::complete_reassociation(): m_is_associated=%s.\n"),
  1744 				 (m_is_client == true) ? "client": "server",
  1756 				 (m_is_client == true) ? "client": "server",
  1745 				 (m_is_associated == true) ? "true": "false"));
  1757 				 (m_is_associated == true) ? "true": "false"));
  1746 		}
  1758 		}
       
  1759 #endif //#if defined(USE_EAPOL_KEY_STATE_OPTIMIZED_4_WAY_HANDSHAKE)
       
  1760 
  1747 	}
  1761 	}
  1748 	else
  1762 	else
  1749 	{
  1763 	{
  1750 		// Reassociation failed, clean-up state.
  1764 		// Reassociation failed, clean-up state.
  1751 		reset();
  1765 		reset();
  2677 }
  2691 }
  2678 
  2692 
  2679 //--------------------------------------------------
  2693 //--------------------------------------------------
  2680 
  2694 
  2681 // 
  2695 // 
  2682 EAP_FUNC_EXPORT eap_status_e eapol_key_state_c::check_is_aes_key_wrap_padding(
  2696 eap_status_e eapol_key_state_c::check_is_aes_key_wrap_padding(
  2683 	const eapol_RSNA_key_descriptor_type_e /* current_key_data_type */,
  2697 	const eapol_RSNA_key_descriptor_type_e /* current_key_data_type */,
  2684 	eapol_rsna_key_data_header_c * const key_data_payload,
  2698 	eapol_rsna_key_data_header_c * const key_data_payload,
  2685 	const u32_t key_data_max_length
  2699 	const u32_t key_data_max_length
  2686 	)
  2700 	)
  2687 {
  2701 {
  2709 }
  2723 }
  2710 
  2724 
  2711 //--------------------------------------------------
  2725 //--------------------------------------------------
  2712 
  2726 
  2713 // 
  2727 // 
  2714 EAP_FUNC_EXPORT eap_status_e eapol_key_state_c::parse_generic_key_data_payload(
  2728 eap_status_e eapol_key_state_c::parse_generic_key_data_payload(
  2715 	const eapol_key_descriptor_type_e eapol_key_descriptor_type,
  2729 	const eapol_key_descriptor_type_e eapol_key_descriptor_type,
  2716 	const eapol_RSNA_key_descriptor_type_e current_key_descriptor_type,
  2730 	const eapol_RSNA_key_descriptor_type_e current_key_descriptor_type,
  2717 	eapol_rsna_key_data_header_c * const key_data_payload,
  2731 	eapol_rsna_key_data_header_c * const key_data_payload,
  2718 	u32_t * const key_data_max_length,
  2732 	u32_t * const key_data_max_length,
  2719 	eapol_rsna_key_data_payloads_c * const p_rsna_key_data_payloads,
  2733 	eapol_rsna_key_data_payloads_c * const p_rsna_key_data_payloads,
  3471 }
  3485 }
  3472 
  3486 
  3473 //--------------------------------------------------
  3487 //--------------------------------------------------
  3474 
  3488 
  3475 //
  3489 //
  3476 EAP_FUNC_EXPORT eap_status_e eapol_key_state_c::parse_key_data(
  3490 eap_status_e eapol_key_state_c::parse_key_data(
  3477 	const eapol_key_descriptor_type_e eapol_key_descriptor_type,
  3491 	const eapol_key_descriptor_type_e eapol_key_descriptor_type,
  3478 	const eapol_rsna_key_data_header_c * const p_payload,
  3492 	const eapol_rsna_key_data_header_c * const p_payload,
  3479 	u32_t * const buffer_length,
  3493 	u32_t * const buffer_length,
  3480 	eapol_rsna_key_data_payloads_c * const p_rsna_key_data_payloads,
  3494 	eapol_rsna_key_data_payloads_c * const p_rsna_key_data_payloads,
  3481 	const eapol_key_state_e expected_key_message,
  3495 	const eapol_key_state_e expected_key_message,
  3643 }
  3657 }
  3644 
  3658 
  3645 //--------------------------------------------------
  3659 //--------------------------------------------------
  3646 
  3660 
  3647 //
  3661 //
  3648 EAP_FUNC_EXPORT eap_status_e eapol_key_state_c::rsna_prf(
  3662 eap_status_e eapol_key_state_c::rsna_prf(
  3649 	const eap_variable_data_c * const key_K,
  3663 	const eap_variable_data_c * const key_K,
  3650 	const eap_variable_data_c * const label_A,
  3664 	const eap_variable_data_c * const label_A,
  3651 	const eap_variable_data_c * const input_B,
  3665 	const eap_variable_data_c * const input_B,
  3652 	const u32_t output_length_bits,
  3666 	const u32_t output_length_bits,
  3653 	eap_variable_data_c * const output
  3667 	eap_variable_data_c * const output
  3783 }
  3797 }
  3784 
  3798 
  3785 //--------------------------------------------------
  3799 //--------------------------------------------------
  3786 
  3800 
  3787 //
  3801 //
  3788 EAP_FUNC_EXPORT eap_status_e eapol_key_state_c::select_minimum(
  3802 eap_status_e eapol_key_state_c::select_minimum(
  3789 	const eap_variable_data_c * const input_a,
  3803 	const eap_variable_data_c * const input_a,
  3790 	const eap_variable_data_c * const input_b,
  3804 	const eap_variable_data_c * const input_b,
  3791 	const eap_variable_data_c ** const minimum,
  3805 	const eap_variable_data_c ** const minimum,
  3792 	const eap_variable_data_c ** const maximum)
  3806 	const eap_variable_data_c ** const maximum)
  3793 {
  3807 {
  3832 }
  3846 }
  3833 
  3847 
  3834 //--------------------------------------------------
  3848 //--------------------------------------------------
  3835 
  3849 
  3836 //
  3850 //
  3837 EAP_FUNC_EXPORT eap_status_e eapol_key_state_c::derive_PTK()
  3851 eap_status_e eapol_key_state_c::derive_PTK()
  3838 {
  3852 {
  3839 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
  3853 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
  3840 
  3854 
  3841 	EAP_TRACE_DEBUG(
  3855 	EAP_TRACE_DEBUG(
  3842 		m_am_tools,
  3856 		m_am_tools,
  4114 }
  4128 }
  4115 
  4129 
  4116 //--------------------------------------------------
  4130 //--------------------------------------------------
  4117 
  4131 
  4118 //
  4132 //
  4119 EAP_FUNC_EXPORT eap_status_e eapol_key_state_c::create_nonce(
  4133 eap_status_e eapol_key_state_c::create_nonce(
  4120 	eap_variable_data_c * const nonce,	const u32_t nonce_length)
  4134 	eap_variable_data_c * const nonce,	const u32_t nonce_length)
  4121 {
  4135 {
  4122 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
  4136 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
  4123 
  4137 
  4124 	EAP_TRACE_DEBUG(
  4138 	EAP_TRACE_DEBUG(
  4166 }
  4180 }
  4167 
  4181 
  4168 //--------------------------------------------------
  4182 //--------------------------------------------------
  4169 
  4183 
  4170 //
  4184 //
  4171 EAP_FUNC_EXPORT eap_status_e eapol_key_state_c::create_PMKID()
  4185 eap_status_e eapol_key_state_c::create_PMKID()
  4172 {
  4186 {
  4173 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
  4187 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
  4174 	eap_status_e status = eap_status_process_general_error;
  4188 	eap_status_e status = eap_status_process_general_error;
  4175 
  4189 
  4176 	if (m_pairwise_PMK_WPXK3.get_is_valid_data() == false)
  4190 	if (m_pairwise_PMK_WPXK3.get_is_valid_data() == false)
  4303 }
  4317 }
  4304 
  4318 
  4305 //--------------------------------------------------
  4319 //--------------------------------------------------
  4306 
  4320 
  4307 //
  4321 //
  4308 EAP_FUNC_EXPORT eap_status_e eapol_key_state_c::encrypt_key_data(
  4322 eap_status_e eapol_key_state_c::encrypt_key_data(
  4309 	eapol_RSNA_key_header_c * const eapol_key_message)
  4323 	eapol_RSNA_key_header_c * const eapol_key_message)
  4310 {
  4324 {
  4311 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
  4325 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
  4312 	eap_status_e status = eap_status_process_general_error;
  4326 	eap_status_e status = eap_status_process_general_error;
  4313 
  4327 
  4536 }
  4550 }
  4537 
  4551 
  4538 //--------------------------------------------------
  4552 //--------------------------------------------------
  4539 
  4553 
  4540 //
  4554 //
  4541 EAP_FUNC_EXPORT eap_status_e eapol_key_state_c::decrypt_key_data(
  4555 eap_status_e eapol_key_state_c::decrypt_key_data(
  4542 	eapol_RSNA_key_header_c * const eapol_key_message)
  4556 	eapol_RSNA_key_header_c * const eapol_key_message)
  4543 {
  4557 {
  4544 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
  4558 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
  4545 	eap_status_e status = eap_status_process_general_error;
  4559 	eap_status_e status = eap_status_process_general_error;
  4546 
  4560 
  4685 
  4699 
  4686 //--------------------------------------------------
  4700 //--------------------------------------------------
  4687 
  4701 
  4688 
  4702 
  4689 //
  4703 //
  4690 EAP_FUNC_EXPORT eap_status_e eapol_key_state_c::create_key_mic(
  4704 eap_status_e eapol_key_state_c::create_key_mic(
  4691 	eapol_RSNA_key_header_c * const eapol_key_message,
  4705 	eapol_RSNA_key_header_c * const eapol_key_message,
  4692 	const eap_variable_data_c * const confirmation_key)
  4706 	const eap_variable_data_c * const confirmation_key)
  4693 {
  4707 {
  4694 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
  4708 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
  4695 	eap_status_e status = eap_status_process_general_error;
  4709 	eap_status_e status = eap_status_process_general_error;
  4857 }
  4871 }
  4858 
  4872 
  4859 //--------------------------------------------------
  4873 //--------------------------------------------------
  4860 
  4874 
  4861 //
  4875 //
  4862 EAP_FUNC_EXPORT eap_status_e eapol_key_state_c::verify_key_mic(
  4876 eap_status_e eapol_key_state_c::verify_key_mic(
  4863 	eapol_RSNA_key_header_c * const eapol_key_message,
  4877 	eapol_RSNA_key_header_c * const eapol_key_message,
  4864 	const eap_variable_data_c * const confirmation_key)
  4878 	const eap_variable_data_c * const confirmation_key)
  4865 {
  4879 {
  4866 	eap_variable_data_c original_MIC(m_am_tools);
  4880 	eap_variable_data_c original_MIC(m_am_tools);
  4867 
  4881 
  5287 	return false;
  5301 	return false;
  5288 }
  5302 }
  5289 
  5303 
  5290 //--------------------------------------------------
  5304 //--------------------------------------------------
  5291 
  5305 
       
  5306 #if defined(USE_EAPOL_KEY_STATE_OPTIMIZED_4_WAY_HANDSHAKE)
       
  5307 
  5292 EAP_FUNC_EXPORT bool eapol_key_state_c::get_is_associated()
  5308 EAP_FUNC_EXPORT bool eapol_key_state_c::get_is_associated()
  5293 {
  5309 {
  5294 	EAP_TRACE_DEBUG(
  5310 	EAP_TRACE_DEBUG(
  5295 		m_am_tools, 
  5311 		m_am_tools, 
  5296 		TRACE_FLAGS_DEFAULT, 
  5312 		TRACE_FLAGS_DEFAULT, 
  5298 		 (m_is_client == true) ? "client": "server",
  5314 		 (m_is_client == true) ? "client": "server",
  5299 		 (m_is_associated == true) ? "true": "false"));
  5315 		 (m_is_associated == true) ? "true": "false"));
  5300 
  5316 
  5301 	return m_is_associated;
  5317 	return m_is_associated;
  5302 }
  5318 }
       
  5319 
       
  5320 #endif //#if defined(USE_EAPOL_KEY_STATE_OPTIMIZED_4_WAY_HANDSHAKE)
  5303 
  5321 
  5304 //--------------------------------------------------
  5322 //--------------------------------------------------
  5305 
  5323 
  5306 EAP_FUNC_EXPORT void eapol_key_state_c::set_eapol_key_state(const eapol_key_state_e state)
  5324 EAP_FUNC_EXPORT void eapol_key_state_c::set_eapol_key_state(const eapol_key_state_e state)
  5307 {
  5325 {
  5692 		 m_authentication_type,
  5710 		 m_authentication_type,
  5693 		 eapol_key_state_string_c::get_eapol_key_authentication_type_string(m_authentication_type)));
  5711 		 eapol_key_state_string_c::get_eapol_key_authentication_type_string(m_authentication_type)));
  5694 
  5712 
  5695 	eap_status_e status(eap_status_process_general_error);
  5713 	eap_status_e status(eap_status_process_general_error);
  5696 
  5714 
       
  5715 #if defined(USE_EAPOL_KEY_STATE_OPTIMIZED_4_WAY_HANDSHAKE)
  5697 	{
  5716 	{
  5698 		m_is_associated = false;
  5717 		m_is_associated = false;
  5699 
  5718 
  5700 		EAP_TRACE_DEBUG(
  5719 		EAP_TRACE_DEBUG(
  5701 			m_am_tools, 
  5720 			m_am_tools, 
  5702 			TRACE_FLAGS_DEFAULT, 
  5721 			TRACE_FLAGS_DEFAULT, 
  5703 			(EAPL("EAPOL_KEY: %s: eapol_key_state_c::init_pmksa_caching_timeout(): m_is_associated=%s.\n"),
  5722 			(EAPL("EAPOL_KEY: %s: eapol_key_state_c::init_pmksa_caching_timeout(): m_is_associated=%s.\n"),
  5704 			 (m_is_client == true) ? "client": "server",
  5723 			 (m_is_client == true) ? "client": "server",
  5705 			 (m_is_associated == true) ? "true": "false"));
  5724 			 (m_is_associated == true) ? "true": "false"));
  5706 	}
  5725 	}
       
  5726 #endif //#if defined(USE_EAPOL_KEY_STATE_OPTIMIZED_4_WAY_HANDSHAKE)
  5707 
  5727 
  5708 	if ((m_authentication_type == eapol_key_authentication_type_RSNA_EAP
  5728 	if ((m_authentication_type == eapol_key_authentication_type_RSNA_EAP
  5709 #if defined(EAP_USE_WPXM)
  5729 #if defined(EAP_USE_WPXM)
  5710 			|| get_is_WPXM() == true
  5730 			|| get_is_WPXM() == true
  5711 #endif //#if defined(EAP_USE_WPXM)
  5731 #endif //#if defined(EAP_USE_WPXM)
  6136 }
  6156 }
  6137 
  6157 
  6138 //--------------------------------------------------
  6158 //--------------------------------------------------
  6139 
  6159 
  6140 //
  6160 //
  6141 EAP_FUNC_EXPORT eap_status_e eapol_key_state_c::create_tkip_mic_failure_message(
  6161 eap_status_e eapol_key_state_c::create_tkip_mic_failure_message(
  6142 	eap_buf_chain_wr_c * const sent_packet,
  6162 	eap_buf_chain_wr_c * const sent_packet,
  6143 	const u32_t eapol_header_offset,
  6163 	const u32_t eapol_header_offset,
  6144 	u32_t * const data_length,
  6164 	u32_t * const data_length,
  6145 	u32_t * const buffer_length,
  6165 	u32_t * const buffer_length,
  6146 	const eapol_RSNA_key_header_c::eapol_tkip_mic_failure_type_e tkip_mic_failure_type,
  6166 	const eapol_RSNA_key_header_c::eapol_tkip_mic_failure_type_e tkip_mic_failure_type,
  6472 }
  6492 }
  6473 
  6493 
  6474 //--------------------------------------------------
  6494 //--------------------------------------------------
  6475 
  6495 
  6476 //
  6496 //
  6477 EAP_FUNC_EXPORT eap_status_e eapol_key_state_c::allow_4_way_handshake()
  6497 eap_status_e eapol_key_state_c::allow_4_way_handshake()
  6478 {
  6498 {
  6479 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
  6499 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
  6480 	eap_status_e status = eap_status_process_general_error;
  6500 	eap_status_e status = eap_status_process_general_error;
  6481 
  6501 
  6482 	EAP_TRACE_DEBUG(
  6502 	EAP_TRACE_DEBUG(
  6587 
  6607 
  6588 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
  6608 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
  6589 		return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
  6609 		return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
  6590 	}
  6610 	}
  6591 	
  6611 	
       
  6612 #if !defined(USE_EAPOL_KEY_STATE_OPTIMIZED_4_WAY_HANDSHAKE)
       
  6613 	// Creates SNonce. This is done here in early phase of authentication.
       
  6614 	// This will reduce the CPU load when time critical first message
       
  6615 	// of 4-Way handshake is processed.
       
  6616 	status = create_nonce(&m_SNonce, EAPOL_RSNA_NONCE_LENGTH_BYTES);
       
  6617 	if (status != eap_status_ok)
       
  6618 	{
       
  6619 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  6620 		return EAP_STATUS_RETURN(m_am_tools, status);
       
  6621 	}
       
  6622 #endif //#if !defined(USE_EAPOL_KEY_STATE_OPTIMIZED_4_WAY_HANDSHAKE)
       
  6623 
  6592 	status = init_handshake_timeout(m_handshake_timeout);
  6624 	status = init_handshake_timeout(m_handshake_timeout);
  6593 	if (status != eap_status_ok)
  6625 	if (status != eap_status_ok)
  6594 	{
  6626 	{
  6595 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
  6627 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
  6596 		return EAP_STATUS_RETURN(m_am_tools, status);
  6628 		return EAP_STATUS_RETURN(m_am_tools, status);
  6608 }
  6640 }
  6609 
  6641 
  6610 //--------------------------------------------------
  6642 //--------------------------------------------------
  6611 
  6643 
  6612 //
  6644 //
  6613 EAP_FUNC_EXPORT eap_status_e eapol_key_state_c::start_group_key_handshake(
  6645 eap_status_e eapol_key_state_c::start_group_key_handshake(
  6614 	const eap_am_network_id_c * const receive_network_id,
  6646 	const eap_am_network_id_c * const receive_network_id,
  6615 	const eapol_protocol_version_e received_eapol_version,
  6647 	const eapol_protocol_version_e received_eapol_version,
  6616 	const eapol_key_descriptor_type_e received_key_descriptor_type)
  6648 	const eapol_key_descriptor_type_e received_key_descriptor_type)
  6617 {
  6649 {
  6618 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
  6650 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
  6739 }
  6771 }
  6740 
  6772 
  6741 //--------------------------------------------------
  6773 //--------------------------------------------------
  6742 
  6774 
  6743 //
  6775 //
  6744 EAP_FUNC_EXPORT eap_status_e eapol_key_state_c::get_key_length(
  6776 eap_status_e eapol_key_state_c::get_key_length(
  6745 	const eapol_RSNA_key_header_c::eapol_RSNA_cipher_e cipher,
  6777 	const eapol_RSNA_key_header_c::eapol_RSNA_cipher_e cipher,
  6746 	u16_t * const key_length)
  6778 	u16_t * const key_length)
  6747 {
  6779 {
  6748 	if (cipher
  6780 	if (cipher
  6749 		== eapol_RSNA_key_header_c::eapol_RSNA_cipher_CCMP)
  6781 		== eapol_RSNA_key_header_c::eapol_RSNA_cipher_CCMP)
  6777 }
  6809 }
  6778 
  6810 
  6779 //--------------------------------------------------
  6811 //--------------------------------------------------
  6780 
  6812 
  6781 //
  6813 //
  6782 EAP_FUNC_EXPORT eap_status_e eapol_key_state_c::process_4_way_handshake_message(
  6814 eap_status_e eapol_key_state_c::process_4_way_handshake_message(
  6783 	const eap_am_network_id_c * const receive_network_id,
  6815 	const eap_am_network_id_c * const receive_network_id,
  6784 	eapol_RSNA_key_header_c * const eapol_key_message,
  6816 	eapol_RSNA_key_header_c * const eapol_key_message,
  6785 	const u32_t packet_length)
  6817 	const u32_t packet_length)
  6786 {
  6818 {
  6787 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
  6819 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
  6882 }
  6914 }
  6883 
  6915 
  6884 //--------------------------------------------------
  6916 //--------------------------------------------------
  6885 
  6917 
  6886 //
  6918 //
  6887 EAP_FUNC_EXPORT eap_status_e eapol_key_state_c::process_group_key_handshake_message(
  6919 eap_status_e eapol_key_state_c::process_group_key_handshake_message(
  6888 	const eap_am_network_id_c * const receive_network_id,
  6920 	const eap_am_network_id_c * const receive_network_id,
  6889 	eapol_RSNA_key_header_c * const eapol_key_message,
  6921 	eapol_RSNA_key_header_c * const eapol_key_message,
  6890 	const u32_t packet_length)
  6922 	const u32_t packet_length)
  6891 {
  6923 {
  6892 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
  6924 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
  6951 }
  6983 }
  6952 
  6984 
  6953 //--------------------------------------------------
  6985 //--------------------------------------------------
  6954 
  6986 
  6955 //
  6987 //
  6956 EAP_FUNC_EXPORT eap_status_e eapol_key_state_c::process_RSNA_key_descriptor(
  6988 eap_status_e eapol_key_state_c::process_RSNA_key_descriptor(
  6957 	const eap_am_network_id_c * const receive_network_id,
  6989 	const eap_am_network_id_c * const receive_network_id,
  6958 	eap_general_header_base_c * const packet_data,
  6990 	eap_general_header_base_c * const packet_data,
  6959 	const u32_t packet_length)
  6991 	const u32_t packet_length)
  6960 {
  6992 {
  6961 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
  6993 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);