eapol/eapol_framework/eapol_common/am/include/eap_am_crypto_md4.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 #if !defined( _EAP_AM_CRYPTO_MD4_H_ )
       
    21 #define _EAP_AM_CRYPTO_MD4_H_
       
    22 
       
    23 #include "eap_am_types.h"
       
    24 #include "eap_variable_data.h"
       
    25 #include "eap_am_export.h"
       
    26 #include "eap_am_tools.h"
       
    27 
       
    28 
       
    29 //--------------------------------------------------
       
    30 
       
    31 /// The eap_am_crypto_md4_c class includes the state of 
       
    32 /// one instance of MD4 algorithm.
       
    33 class EAP_EXPORT eap_am_crypto_md4_c
       
    34 {
       
    35 
       
    36 private:
       
    37 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
    38 
       
    39 	enum eap_md4_init
       
    40 	{
       
    41 		EAP_MD4_INIT_H0 = 0x67452301ul,
       
    42 		EAP_MD4_INIT_H1 = 0xefcdab89ul,
       
    43 		EAP_MD4_INIT_H2 = 0x98badcfeul,
       
    44 		EAP_MD4_INIT_H3 = 0x10325476ul,
       
    45 	};
       
    46 
       
    47 	enum eap_md4_const
       
    48 	{
       
    49 		eap_md4_const_S11 =  3,
       
    50 		eap_md4_const_S12 =  7,
       
    51 		eap_md4_const_S13 = 11,
       
    52 		eap_md4_const_S14 = 19,
       
    53 		eap_md4_const_S21 =  3,
       
    54 		eap_md4_const_S22 =  5,
       
    55 		eap_md4_const_S23 =  9,
       
    56 		eap_md4_const_S24 = 13,
       
    57 		eap_md4_const_S31 =  3,
       
    58 		eap_md4_const_S32 =  9,
       
    59 		eap_md4_const_S33 = 11,
       
    60 		eap_md4_const_S34 = 15,
       
    61 	};
       
    62 
       
    63 	enum eap_md4_sizes
       
    64 	{
       
    65 		EAP_AM_CRYPTO_MD4_BLOCK_u32_COUNT = 16ul, ///< 16 u32_t integers.
       
    66 		EAP_AM_CRYPTO_MD4_BLOCK_BYTE_SIZE
       
    67 			= EAP_AM_CRYPTO_MD4_BLOCK_u32_COUNT * sizeof(u32_t), ///< in bytes.
       
    68 		EAP_AM_CRYPTO_MD4_DIGEST_BUFFER_u32_COUNT = 4ul, ///< 4 u32_t integers.
       
    69 		EAP_AM_CRYPTO_MD4_DIGEST_BUFFER_BYTE_SIZE
       
    70 			= EAP_AM_CRYPTO_MD4_DIGEST_BUFFER_u32_COUNT
       
    71 			* sizeof(u32_t), ///< in bytes.
       
    72 	};
       
    73 
       
    74 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
    75 
       
    76 	/// This is pointer to the tools class.
       
    77 	abs_eap_am_tools_c * const m_am_tools;
       
    78 
       
    79 	/// This buffer saves remaining data between subsequent calls 
       
    80 	/// of hash_update().
       
    81 	eap_variable_data_c m_saved_data;
       
    82 
       
    83 	/// This attribute saves the length of hashed data.
       
    84 	u64_t m_full_hashed_data_length;
       
    85 
       
    86 	u32_t m_W_in_host_order[EAP_AM_CRYPTO_MD4_BLOCK_u32_COUNT];
       
    87 
       
    88 	/// This buffer saves the digest value between subsequent calls 
       
    89 	/// of hash_update().
       
    90 	u32_t m_H[EAP_AM_CRYPTO_MD4_DIGEST_BUFFER_u32_COUNT];
       
    91 
       
    92 	/// This indicates whether this object was generated successfully.
       
    93 	bool m_is_valid;
       
    94 
       
    95 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
    96 
       
    97 	inline u32_t eap_md4_F(
       
    98 		const u32_t X,
       
    99 		const u32_t Y,
       
   100 		const u32_t Z
       
   101 		);
       
   102 
       
   103 	inline u32_t eap_md4_G(
       
   104 		const u32_t X,
       
   105 		const u32_t Y,
       
   106 		const u32_t Z
       
   107 		);
       
   108 
       
   109 	inline u32_t eap_md4_H(
       
   110 		const u32_t X,
       
   111 		const u32_t Y,
       
   112 		const u32_t Z
       
   113 		);
       
   114 
       
   115 	inline u32_t eap_md4_rotate_left(
       
   116 		const u32_t value,
       
   117 		const u32_t shift
       
   118 		);
       
   119 
       
   120 	inline void eap_md4_FF(
       
   121 		const u32_t index,
       
   122 		u32_t * const A,
       
   123 		const u32_t B,
       
   124 		const u32_t C,
       
   125 		const u32_t D,
       
   126 		const u32_t X,
       
   127 		const u32_t S
       
   128 		);
       
   129 
       
   130 	inline void eap_md4_GG(
       
   131 		const u32_t index,
       
   132 		u32_t * const A,
       
   133 		const u32_t B,
       
   134 		const u32_t C,
       
   135 		const u32_t D,
       
   136 		const u32_t X,
       
   137 		const u32_t S
       
   138 		);
       
   139 
       
   140 	inline void eap_md4_HH(
       
   141 		const u32_t index,
       
   142 		u32_t * const A,
       
   143 		const u32_t B,
       
   144 		const u32_t C,
       
   145 		const u32_t D,
       
   146 		const u32_t X,
       
   147 		const u32_t S
       
   148 		);
       
   149 
       
   150 	/// @param W is an array of 16 input 32-bit unsigned integers
       
   151 	/// in host order.
       
   152 	/// @param W_count is count of integers in W array.
       
   153 	EAP_FUNC_IMPORT eap_status_e eap_md4_transform_host_order(
       
   154 		const u32_t * const W,
       
   155 		const u32_t W_count
       
   156 		);
       
   157 
       
   158 	/// @param W is an array of 16 input 32-bit unsigned integers
       
   159 	/// in network order.
       
   160 	/// @param W_count is count of integers in W array.
       
   161 	EAP_FUNC_IMPORT eap_status_e eap_md4_process_data(
       
   162 		const u32_t * const W,
       
   163 		const u32_t W_count
       
   164 		);
       
   165 
       
   166 	/**
       
   167 	 * This function cleans up the MD4 context.
       
   168 	 */
       
   169 	EAP_FUNC_IMPORT eap_status_e hash_cleanup();
       
   170 
       
   171 	/**
       
   172 	 * This function copies the message digest to output buffer.
       
   173 	 */
       
   174 	EAP_FUNC_IMPORT eap_status_e copy_message_digest(
       
   175 		void * const output,
       
   176 		u32_t * const max_output_size);
       
   177 
       
   178 
       
   179 	/**
       
   180 	 * The set_is_invalid() function sets the state of the eap_am_crypto_md4_c
       
   181 	 * object invalid. 
       
   182 	 * The eap_am_crypto_md4_c object calls this function after it is
       
   183 	 * initialized.
       
   184 	 */
       
   185 	EAP_FUNC_IMPORT void set_is_invalid();
       
   186 
       
   187 	/**
       
   188 	 * The set_is_valid() function sets the state of the eap_am_crypto_md4_c
       
   189 	 * object valid. 
       
   190 	 * The eap_am_crypto_md4_c object calls this function after it is
       
   191 	 * initialized.
       
   192 	 */
       
   193 	EAP_FUNC_IMPORT void set_is_valid();
       
   194 
       
   195 	/**
       
   196 	 * This function copies the context of MD4.
       
   197 	 */
       
   198 	EAP_FUNC_IMPORT eap_status_e copy_context(
       
   199 		const eap_variable_data_c * const saved_data,
       
   200 		const u64_t full_hashed_data_length,
       
   201 		const u32_t * const H,
       
   202 		const u32_t * const W_in_host_order);
       
   203 
       
   204 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
   205 public:
       
   206 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
   207 
       
   208 	/**
       
   209 	 * Destructor does nothing special.
       
   210 	 */
       
   211 	EAP_FUNC_IMPORT virtual ~eap_am_crypto_md4_c();
       
   212 
       
   213 	/**
       
   214 	 * Constructor initializes the member attributes.
       
   215 	 */
       
   216 	EAP_FUNC_IMPORT eap_am_crypto_md4_c(abs_eap_am_tools_c * const tools);
       
   217 
       
   218 	/**
       
   219 	 * The get_is_valid() function returns the status of the
       
   220 	 * eap_am_crypto_md4_c object. 
       
   221 	 * True indicates the object is allocated successfully.
       
   222 	 */
       
   223 	EAP_FUNC_IMPORT bool get_is_valid();
       
   224 
       
   225 	/**
       
   226 	 * This function returns the size of message digest of HASH-algorithm.
       
   227 	 */
       
   228 	EAP_FUNC_IMPORT u32_t get_digest_length();
       
   229 
       
   230 	/**
       
   231 	 * This function returns the size of block of HASH-algorithm.
       
   232 	 */
       
   233 	EAP_FUNC_IMPORT u32_t get_block_size();
       
   234 
       
   235 	/**
       
   236 	 * This function initializes the context of MD4-algorithm.
       
   237 	 */
       
   238 	EAP_FUNC_IMPORT eap_status_e hash_init();
       
   239 
       
   240 	/**
       
   241 	 * This function updates the context of MD4-algorithm with data.
       
   242 	 */
       
   243 	EAP_FUNC_IMPORT eap_status_e hash_update(
       
   244 		const void * const data,
       
   245 		const u32_t data_length);
       
   246 
       
   247 	/**
       
   248 	 * This function writes the message digest to buffer.
       
   249 	 * @param Length is set if md_length_or_null is non-NULL.
       
   250 	 */
       
   251 	EAP_FUNC_IMPORT eap_status_e hash_final(
       
   252 		void * const message_digest,
       
   253 		u32_t *md_length_or_null);
       
   254 
       
   255 	/**
       
   256 	 * This function copies the context of MD4.
       
   257 	 */
       
   258 	EAP_FUNC_IMPORT eap_am_crypto_md4_c * copy();
       
   259 };
       
   260 
       
   261 //--------------------------------------------------
       
   262 
       
   263 #endif //#if !defined( _EAP_AM_CRYPTO_OPENSSL_H_ )
       
   264 
       
   265 
       
   266 
       
   267 // End.