eapol/eapol_framework/eapol_common/am/include/eap_am_crypto_rc4.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 
       
    22 #if !defined(_EAP_AM_CRYPTO_RC4_H_)
       
    23 #define _EAP_AM_CRYPTO_RC4_H_
       
    24 
       
    25 #include "eap_am_types.h"
       
    26 #include "eap_variable_data.h"
       
    27 #include "eap_am_export.h"
       
    28 #include "eap_am_tools.h"
       
    29 
       
    30 #undef set_key
       
    31 
       
    32 //------------------------------------------------------------
       
    33 
       
    34 /// The eap_am_crypto_rc4_c class includes the state of 
       
    35 /// one instance of RC4 algorithm.
       
    36 class EAP_EXPORT eap_am_crypto_rc4_c
       
    37 {
       
    38 
       
    39 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
    40 private:
       
    41 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
    42 
       
    43 	enum eap_am_crypto_rc4_constant
       
    44 	{
       
    45 		eap_am_crypto_rc4_constant_state_size = 256,
       
    46 	};
       
    47 
       
    48 	/// This is pointer to the tools class.
       
    49 	abs_eap_am_tools_c * const m_am_tools;
       
    50 
       
    51 	/// State is stored to this variable.
       
    52 	u8_t m_state[eap_am_crypto_rc4_constant_state_size];
       
    53 
       
    54 	/// This is the index i.
       
    55 	u8_t m_ind_i;
       
    56 
       
    57 	/// This is the index j.
       
    58 	u8_t m_ind_j;
       
    59 
       
    60 	/// This indicates whether this object was generated successfully.
       
    61 	bool m_is_valid;
       
    62 
       
    63 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
    64 
       
    65 	/**
       
    66 	 * Function cleanups the state and variables.
       
    67 	 */
       
    68 	EAP_FUNC_IMPORT eap_status_e cleanup();
       
    69 
       
    70 	/**
       
    71 	 * The set_is_invalid() function sets the state of the eap_am_crypto_rc4_c
       
    72 	 * object invalid. 
       
    73 	 * The eap_am_crypto_rc4_c object calls this function after it is
       
    74 	 * initialized.
       
    75 	 */
       
    76 	EAP_FUNC_IMPORT void set_is_invalid();
       
    77 
       
    78 	/**
       
    79 	 * The set_is_valid() function sets the state of the eap_am_crypto_rc4_c
       
    80 	 * object valid. 
       
    81 	 * The eap_am_crypto_rc4_c object calls this function after it is
       
    82 	 * initialized.
       
    83 	 */
       
    84 	EAP_FUNC_IMPORT void set_is_valid();
       
    85 
       
    86 	/**
       
    87 	 * Function swaps the values.
       
    88 	 */
       
    89 	EAP_FUNC_IMPORT inline void swap(
       
    90 		u8_t * const s_i,
       
    91 		u8_t * const s_j);
       
    92 
       
    93 	/**
       
    94 	 * Function returns the next random byte.
       
    95 	 */
       
    96 	inline u8_t get_random_byte();
       
    97 
       
    98 	/**
       
    99 	 * Function XORs input data buffer with generated pseudo random data
       
   100 	 * and stores result to output data buffer.
       
   101 	 */
       
   102 	inline eap_status_e process_data(
       
   103 		const void * const p_data_in,
       
   104 		void * const p_data_out,
       
   105 		const u32_t data_length);
       
   106 
       
   107 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   108 public:
       
   109 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   110 
       
   111 	/**
       
   112 	 * Destructor resets the used internal buffers.
       
   113 	 */
       
   114 	EAP_FUNC_IMPORT virtual ~eap_am_crypto_rc4_c();
       
   115 
       
   116 	/**
       
   117 	 * Constructor initializes the used internal buffers.
       
   118 	 */
       
   119 	EAP_FUNC_IMPORT eap_am_crypto_rc4_c(abs_eap_am_tools_c * const tools);
       
   120 
       
   121 	/**
       
   122 	 * The get_is_valid() function returns the status of the
       
   123 	 * eap_am_crypto_rc4_c object. 
       
   124 	 * True indicates the object is allocated successfully.
       
   125 	 */
       
   126 	EAP_FUNC_IMPORT bool get_is_valid();
       
   127 
       
   128 	/**
       
   129 	 * This function sets the RC4 key.
       
   130 	 */
       
   131 	EAP_FUNC_IMPORT eap_status_e set_key(
       
   132 		const eap_variable_data_c * const key);
       
   133 
       
   134 	/**
       
   135 	 * This function does RC4 encryption.
       
   136 	 */
       
   137 	EAP_FUNC_IMPORT eap_status_e encrypt_data(
       
   138 		const void * const data_in, 
       
   139 		void * const data_out,
       
   140 		const u32_t data_length);
       
   141 
       
   142 	/**
       
   143 	 * This function does RC4 decryption.
       
   144 	 */
       
   145 	EAP_FUNC_IMPORT eap_status_e decrypt_data(
       
   146 		const void * const data_in, 
       
   147 		void * const data_out,
       
   148 		const u32_t data_length);
       
   149 };
       
   150 
       
   151 #endif //#if !defined(_EAP_AM_CRYPTO_RC4_H_)
       
   152 
       
   153 //------------------------------------------------------------
       
   154 
       
   155 
       
   156 
       
   157 // End.