eapol/eapol_framework/eapol_common/am/include/ms_mppe_send_recv_key.h
changeset 0 c8830336c852
child 2 1c7bc153c08e
equal deleted inserted replaced
-1:000000000000 0:c8830336c852
       
     1 /*
       
     2 * Copyright (c) 2001-2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  EAP and WLAN authentication protocols.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #if !defined(_MS_MPPE_SEND_RECV_KEY_H_)
       
    22 #define _MS_MPPE_SEND_RECV_KEY_H_
       
    23 
       
    24 //----------------------------------------------------------------------------
       
    25 
       
    26 //
       
    27 // Bytes needed:
       
    28 //      4: Vendor-Id
       
    29 //      1: Vendor-Type
       
    30 //      1: Vendor-Length
       
    31 //      2: Salt
       
    32 //      1: Key-Length
       
    33 //     32: Key
       
    34 //     15: Padding
       
    35 //     -----------------
       
    36 //     56: Total
       
    37 //
       
    38 // Copy MS-MPPE-Send-Key
       
    39 //
       
    40 // 0                   1                   2                   3
       
    41 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
       
    42 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    43 // |                  Vendor-ID                                  |
       
    44 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    45 // | Vendor-Type   | Vendor-Length |           Salt              |
       
    46 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    47 // | Key Length    |         Key total 32 bytes                  |
       
    48 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    49 // |                       Key (cont)                            |
       
    50 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    51 // |                       Key (cont)                            |
       
    52 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    53 // |                       Key (cont)                            |
       
    54 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    55 // |                       Key (cont)                            |
       
    56 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    57 // |                       Key (cont)                            |
       
    58 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    59 // |                       Key (cont)                            |
       
    60 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    61 // |                       Key (cont)                            |
       
    62 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    63 // |               |       Padding total 15 bytes                |
       
    64 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    65 // |                       Padding                               |
       
    66 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    67 // |                       Padding                               |
       
    68 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    69 // |                       Padding                               |
       
    70 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    71 
       
    72 const u32_t MS_MPPE_KEY_LENGTH     = 32u;
       
    73 const u32_t MS_MPPE_PADDING_LENGTH = 15u;
       
    74 
       
    75 const u8_t MS_MPPE_Send_Key = 16u;
       
    76 const u8_t MS_MPPE_Recv_Key = 17u;
       
    77 
       
    78 #pragma pack(1)
       
    79 
       
    80 // 
       
    81 class ms_mppe_send_recv_key_c
       
    82 {
       
    83 private:
       
    84 	//--------------------------------------------------
       
    85 
       
    86 
       
    87 	u32_t m_vendor_id;
       
    88 	u8_t m_vendor_type;
       
    89 	u8_t m_vendor_length;
       
    90 	u16_t m_salt;
       
    91 	u8_t m_key_length;
       
    92 	u8_t m_key[MS_MPPE_KEY_LENGTH];
       
    93 	u8_t m_padding[MS_MPPE_PADDING_LENGTH];
       
    94 
       
    95 	//--------------------------------------------------
       
    96 protected:
       
    97 	//--------------------------------------------------
       
    98 
       
    99 	//--------------------------------------------------
       
   100 public:
       
   101 	//--------------------------------------------------
       
   102 
       
   103 	// 
       
   104 	~ms_mppe_send_recv_key_c()
       
   105 	{
       
   106 	}
       
   107 
       
   108 	// 
       
   109 	ms_mppe_send_recv_key_c(abs_eap_am_tools_c * const m_am_tools)
       
   110 	{
       
   111 		reset_header(m_am_tools);
       
   112 	}
       
   113 
       
   114 	void reset_header(abs_eap_am_tools_c * const m_am_tools)
       
   115 	{
       
   116 		m_vendor_id = eap_htonl(311); // microsoft
       
   117 		m_vendor_type = 0u;
       
   118 		m_vendor_length = sizeof(*this) - sizeof(m_vendor_id);
       
   119 		m_salt = 0u;
       
   120 		m_key_length = 0u;
       
   121 		m_am_tools->memset(m_key, 0, sizeof(m_key));
       
   122 		m_am_tools->memset(m_padding, 0, sizeof(m_padding));
       
   123 	}
       
   124 
       
   125 	eap_status_e set_key(
       
   126 		abs_eap_am_tools_c * const m_am_tools,
       
   127 		const u8_t * const key,
       
   128 		const u32_t key_length,
       
   129 		const u8_t key_type)
       
   130 	{
       
   131 		if (key_length >= sizeof(m_key))
       
   132 		{
       
   133 			m_vendor_type = key_type; // MS-MPPE-Send-Key or MS-MPPE-Recv-Key
       
   134 			m_key_length = sizeof(m_key);
       
   135 			m_am_tools->memmove(m_key, key, sizeof(m_key));
       
   136 			return eap_status_ok;
       
   137 		}
       
   138 		else
       
   139 		{
       
   140 			return eap_status_key_error;
       
   141 		}
       
   142 	}
       
   143 
       
   144 	// 
       
   145 	//--------------------------------------------------
       
   146 }; // class ms_mppe_send_recv_key_c
       
   147 
       
   148 #pragma pack()
       
   149 
       
   150 #endif //#if !defined(_MS_MPPE_SEND_RECV_KEY_H_)
       
   151 
       
   152 //--------------------------------------------------
       
   153 
       
   154 
       
   155 
       
   156 // End.