eapol/eapol_framework/eapol_common/am/include/eap_am_crypto_openssl.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( _EAP_AM_CRYPTO_OPENSSL_H_ )
       
    22 #define _EAP_AM_CRYPTO_OPENSSL_H_
       
    23 
       
    24 #include "eap_am_types.h"
       
    25 #include "eap_variable_data.h"
       
    26 #include "eap_am_export.h"
       
    27 #include "eap_am_tools.h"
       
    28 #include "eap_array.h"
       
    29 #include "abs_eap_am_crypto.h"
       
    30 #if defined(USE_EAP_RANDOM_TEST)
       
    31 #include "eap_am_random_test.h"
       
    32 #endif //#if defined(USE_EAP_RANDOM_TEST)
       
    33 
       
    34 #if defined(des_set_key)
       
    35 // OpenSSL defines this.
       
    36 #undef des_set_key
       
    37 #endif //#if defined(des_set_key)
       
    38 
       
    39 class abs_eap_am_tools_c;
       
    40 class eap_variable_data_c;
       
    41 
       
    42 const u32_t EAP_HW_TICKS_SEED_BUFFER_SIZE = 8u;
       
    43 
       
    44 /// Class eap_am_crypto_openssl_c offers services to authenticate data,
       
    45 /// encrypt data, decrypt data, generate keys and generate cryptographically
       
    46 /// strong random data.
       
    47 class EAP_EXPORT eap_am_crypto_openssl_c 
       
    48 : public abs_eap_am_crypto_c
       
    49 {
       
    50 private:
       
    51 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
    52 	/// This is pointer to the tools class.
       
    53 	abs_eap_am_tools_c * const m_am_tools;
       
    54 
       
    55 #if defined(USE_EAP_RANDOM_TEST)
       
    56 	/// This is used because of the random generator of OpenSSL does some
       
    57 	/// memory violations that valgrind founds.
       
    58 	eap_am_random_test_c m_test_random;
       
    59 #endif //#if defined(USE_EAP_RANDOM_TEST)
       
    60 
       
    61 	bool m_use_test_random;
       
    62 
       
    63 	/// This indicates whether this object was generated successfully.
       
    64 	bool m_is_valid;
       
    65 
       
    66 	u8_t m_hw_ticks_seed_buffer[EAP_HW_TICKS_SEED_BUFFER_SIZE];
       
    67 	u32_t m_hw_ticks_seed_index;
       
    68 
       
    69 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
    70 public:
       
    71 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
    72 
       
    73 	static abs_eap_am_tools_c * g_tools;
       
    74 
       
    75 	/**
       
    76 	 * Destructor does nothing special.
       
    77 	 */
       
    78 	EAP_FUNC_IMPORT virtual ~eap_am_crypto_openssl_c();
       
    79 
       
    80 	/**
       
    81 	 * Constructor initializes the member attributes.
       
    82 	 */
       
    83 	EAP_FUNC_IMPORT eap_am_crypto_openssl_c(abs_eap_am_tools_c * const tools);
       
    84 
       
    85 	/**
       
    86 	 * The configure() function is called after the constructor of the 
       
    87 	 * object is successfully executed. During the function call the object 
       
    88 	 * could query the configuration. Each derived class must define this
       
    89 	 * function. Needed configuration depends on the implementation.
       
    90 	 */
       
    91 	EAP_FUNC_IMPORT eap_status_e configure();
       
    92 
       
    93 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
    94 
       
    95 	EAP_FUNC_IMPORT bool get_is_valid() const
       
    96 	{
       
    97 		return m_is_valid;
       
    98 	}
       
    99 	EAP_FUNC_IMPORT void set_is_valid()
       
   100 	{
       
   101 		m_is_valid = true;
       
   102 	}
       
   103 
       
   104 	/**
       
   105 	 * This function activates random generator for test use.
       
   106 	 * It does generate predictive pseudorandom data.
       
   107 	 */
       
   108 	EAP_FUNC_IMPORT void use_test_random(
       
   109 		const u8_t * const seed,
       
   110 		const u32_t seed_length,
       
   111 		const bool does_continuous_seeding_when_true);
       
   112 
       
   113 	/**
       
   114 	 * The get_rand_bytes() function fills count random bytes to buffer.
       
   115 	 */
       
   116 	EAP_FUNC_IMPORT eap_status_e get_rand_bytes(
       
   117 		u8_t * const buffer,
       
   118 		const u32_t count);
       
   119 
       
   120 	/**
       
   121 	 * The add_rand_seed() function seeds count bytes from buffer to the
       
   122 	 * random data pool. The seed bytes could be any data that increases
       
   123 	 * entropy of the random data pool. For example time stamps of send
       
   124 	 * and received messages, likewise addresses, cookies and nonces
       
   125 	 * included in messages.
       
   126 	 */
       
   127 	EAP_FUNC_IMPORT eap_status_e add_rand_seed(
       
   128 		const u8_t * const buffer,
       
   129 		const u32_t count);
       
   130 
       
   131 	/**
       
   132 	 * The add_rand_seed_hw_ticks() function adds hardware ticks read with 
       
   133 	 * the abs_eap_am_tools::get_hardware_ticks()  function. This could be
       
   134 	 * used to seed the random data pool with time stamps.
       
   135 	 */
       
   136 	EAP_FUNC_IMPORT eap_status_e add_rand_seed_hw_ticks();
       
   137 
       
   138 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   139 
       
   140 	/**
       
   141 	 * The generate_diffie_hellman_keys() function generates private and
       
   142 	 * public Diffie-Hellman keys. 
       
   143 	 * @param dh_context Saves context here. It is private key in OpenSSL
       
   144 	 * and CDHKey in Symbian.
       
   145 	 */
       
   146 	EAP_FUNC_IMPORT eap_status_e generate_diffie_hellman_keys(
       
   147 		eap_variable_data_c * const dh_context,
       
   148 		eap_variable_data_c * const own_public_dh_key,
       
   149 		const u8_t * const prime,
       
   150 		const u32_t prime_length,
       
   151 		const u8_t * const group_generator,
       
   152 		const u32_t group_generator_length);
       
   153 
       
   154 	/**
       
   155 	 * The generate_g_power_to_xy() function generates shared secret 
       
   156 	 * Diffie-Hellman key from own_private_dh_key and peer_public_dh_key.
       
   157 	 * @param dh_context Gets context. Is private key in OpenSSL and
       
   158 	 * CDHKey in Symbian.
       
   159 	 */
       
   160 	EAP_FUNC_IMPORT eap_status_e generate_g_power_to_xy(
       
   161 		const eap_variable_data_c * const dh_context,
       
   162 		const eap_variable_data_c * const peer_public_dh_key,
       
   163 		eap_variable_data_c * const shared_dh_key,
       
   164 		const u8_t * const prime,
       
   165 		const u32_t prime_length,
       
   166 		const u8_t * const group_generator,
       
   167 		const u32_t group_generator_length);
       
   168 
       
   169 	/**
       
   170 	 * This functions cleans up the diffie-hellman context.
       
   171 	 */
       
   172 	
       
   173 	EAP_FUNC_IMPORT eap_status_e dh_cleanup(
       
   174 		const eap_variable_data_c * const dh_context);
       
   175 
       
   176 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   177 
       
   178 	/**
       
   179 	 * This function returns the size of message digest of SHA1-algorithm.
       
   180 	 */
       
   181 	 EAP_FUNC_IMPORT u32_t get_sha_256_digest_length(
       
   182 		eap_variable_data_c * const sha_256_context);
       
   183 
       
   184 	/**
       
   185 	 * This function returns the block size of SHA1-algorithm.
       
   186 	 */
       
   187 	 EAP_FUNC_IMPORT u32_t get_sha_256_block_size(
       
   188 		eap_variable_data_c * const sha_256_context);
       
   189 
       
   190 	/**
       
   191 	 * The sha_256_init() function initializes SHA1.
       
   192 	 * Internal context of SHA1 is stored to sha_256_context.
       
   193 	 */
       
   194 	 EAP_FUNC_IMPORT eap_status_e sha_256_init(
       
   195 		eap_variable_data_c * const sha_256_context);
       
   196 
       
   197 	/**
       
   198 	 * The sha_256_update() function updates the context of 
       
   199 	 * sha_256_context with data_length bytes of data.
       
   200 	 */
       
   201 	 EAP_FUNC_IMPORT eap_status_e sha_256_update(
       
   202 		eap_variable_data_c * const sha_256_context,
       
   203 		const u8_t * const data,
       
   204 		const u32_t data_length);
       
   205 
       
   206 	/**
       
   207 	 * The sha_256_final() function writes the message authentication code 
       
   208 	 * (MAC) to buffer pointed by message_digest. The length of MAC is stored 
       
   209 	 * to buffer pointed by md_length_or_null, If md_length_or_null is non NULL.
       
   210 	 */
       
   211 	 EAP_FUNC_IMPORT eap_status_e sha_256_final(
       
   212 		eap_variable_data_c * const sha_256_context,
       
   213 		u8_t * const message_digest,
       
   214 		u32_t *md_length_or_null);
       
   215 
       
   216 	/**
       
   217 	 * The hmac_sha_256_cleanup() cleanups the SHA1 context.
       
   218 	 */
       
   219 	 EAP_FUNC_IMPORT eap_status_e sha_256_cleanup(
       
   220 		eap_variable_data_c * const sha_256_context);
       
   221 
       
   222 	/**
       
   223 	 * The sha_256_copy_context() copies the SHA1 context.
       
   224 	 */
       
   225 	 EAP_FUNC_IMPORT eap_status_e sha_256_copy_context(
       
   226 		eap_variable_data_c * const copied_sha_256_context,
       
   227 		const eap_variable_data_c * const original_sha_256_context);
       
   228 
       
   229 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   230 
       
   231 	/**
       
   232 	 * This function returns the size of message digest of SHA1-algorithm.
       
   233 	 */
       
   234 	EAP_FUNC_IMPORT u32_t get_sha1_digest_length(
       
   235 		eap_variable_data_c * const sha1_context);
       
   236 
       
   237 	/**
       
   238 	 * This function returns the block size of SHA1-algorithm.
       
   239 	 */
       
   240 	EAP_FUNC_IMPORT u32_t get_sha1_block_size(
       
   241 		eap_variable_data_c * const sha1_context);
       
   242 
       
   243 	/**
       
   244 	 * The sha1_init() function initializes SHA1.
       
   245 	 * Internal context of SHA1 is stored to sha1_context.
       
   246 	 */
       
   247 	EAP_FUNC_IMPORT eap_status_e sha1_init(
       
   248 		eap_variable_data_c * const sha1_context);
       
   249 
       
   250 	/**
       
   251 	 * The sha1_update() function updates the context of 
       
   252 	 * sha1_context with data_length bytes of data.
       
   253 	 */
       
   254 	EAP_FUNC_IMPORT eap_status_e sha1_update(
       
   255 		eap_variable_data_c * const sha1_context,
       
   256 		const u8_t * const data,
       
   257 		const u32_t data_length);
       
   258 
       
   259 	/**
       
   260 	 * The sha1_final() function writes the message authentication code 
       
   261 	 * (MAC) to buffer pointed by message_digest. The length of MAC is stored 
       
   262 	 * to buffer pointed by md_length_or_null, If md_length_or_null is non
       
   263 	 * NULL.
       
   264 	 */
       
   265 	EAP_FUNC_IMPORT eap_status_e sha1_final(
       
   266 		eap_variable_data_c * const sha1_context,
       
   267 		u8_t * const message_digest,
       
   268 		u32_t *md_length_or_null);
       
   269 
       
   270 	/**
       
   271 	 * The hmac_sha1_cleanup() cleanups the SHA1 context.
       
   272 	 */
       
   273 	EAP_FUNC_IMPORT eap_status_e sha1_cleanup(
       
   274 		eap_variable_data_c * const sha1_context);
       
   275 
       
   276 	/**
       
   277 	 * The sha1_copy_context() copies the SHA1 context.
       
   278 	 */
       
   279 	EAP_FUNC_IMPORT eap_status_e sha1_copy_context(
       
   280 		eap_variable_data_c * const copied_sha1_context,
       
   281 		const eap_variable_data_c * const original_sha1_context);
       
   282 
       
   283 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   284 
       
   285 	/**
       
   286 	 * The aes_key_length() function returns the length of key AES-algorithm. 
       
   287 	 * This will be constant 16 bytes (128 bits). Still it is better use
       
   288 	 * function to help changes if the length of key is changed in future. 
       
   289 	 */
       
   290 	EAP_FUNC_IMPORT u32_t aes_key_length();
       
   291 
       
   292 	/**
       
   293 	 * The aes_block_size() function returns the block size of AES-algorithm. 
       
   294 	 * This will be constant 16 bytes (128 bits). Still it is better use
       
   295 	 * function to help changes if the size is changed in future.
       
   296 	 */
       
   297 	EAP_FUNC_IMPORT u32_t aes_block_size();
       
   298 
       
   299 
       
   300 	/**
       
   301 	 * The aes_set_encryption_key() function initializes the encryption 
       
   302 	 * context of AES-algorithm to the aes_context using key_length bytes
       
   303 	 * from buffer key. 
       
   304 	 */
       
   305 	EAP_FUNC_IMPORT eap_status_e aes_set_encryption_key(
       
   306 		eap_variable_data_c * const aes_context,
       
   307 		const u8_t * const key,
       
   308 		const u32_t key_length);
       
   309 
       
   310 	/**
       
   311 	 * The aes_set_decryption_key() function initializes the decryption
       
   312 	 * context of 
       
   313 	 * AES-algorithm to the aes_context using key_length bytes from buffer key.
       
   314 	 */
       
   315 	EAP_FUNC_IMPORT eap_status_e aes_set_decryption_key(
       
   316 		eap_variable_data_c * const aes_context,
       
   317 		const u8_t * const key,
       
   318 		const u32_t key_length);
       
   319 
       
   320 	EAP_FUNC_IMPORT eap_status_e aes_cleanup(
       
   321 		eap_variable_data_c * const aes_context);
       
   322 
       
   323 	/**
       
   324 	 * The aes_encrypt_block() function encrypts data of data_length bytes 
       
   325 	 * using encryption_IV initialization vector. NOTE the length of data must 
       
   326 	 * be aligned to block size of AES-algorithm.
       
   327 	 * This version takes pointers to input and output buffers as a parameter.
       
   328 	 * Those buffers must be fully separated. Some optimizations are used
       
   329 	 * taking advance from separate buffers. 
       
   330 	 */
       
   331 	EAP_FUNC_IMPORT eap_status_e aes_encrypt_block(
       
   332 		eap_variable_data_c * const aes_context,
       
   333 		const u8_t * const data_in,
       
   334 		u8_t * const data_out,
       
   335 		const u32_t data_length);
       
   336 
       
   337 	/**
       
   338 	 * The aes_decrypt_block() function decrypts data of data_length bytes 
       
   339 	 * using decryption_IV initialization vector. NOTE the length of data must 
       
   340 	 * be aligned to block size of AES-algorithm.
       
   341 	 * This version takes pointers to input and output buffers as a parameter.
       
   342 	 * Those buffers must be fully separated. Some optimizations are used 
       
   343 	 * taking advance from separate buffers.
       
   344 	 */
       
   345 	EAP_FUNC_IMPORT eap_status_e aes_decrypt_block(
       
   346 		eap_variable_data_c * const aes_context,
       
   347 		const u8_t * const data_in,
       
   348 		u8_t * const data_out,
       
   349 		const u32_t data_length);
       
   350 
       
   351 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   352 
       
   353 	/**
       
   354 	 * The key_length() function returns the length of key 3DES-EDE-algorithm. 
       
   355 	 * This will be constant 16 bytes (128 bits). Still it is better use
       
   356 	 * function to help changes if the length of key is changed in future. 
       
   357 	 */
       
   358 	EAP_FUNC_IMPORT u32_t key_length_3des_ede();
       
   359 
       
   360 	/**
       
   361 	 * The block_size() function returns the block size of 3DES-EDE-algorithm. 
       
   362 	 * This will be constant 16 bytes (128 bits). Still it is better use
       
   363 	 * function to help changes if the size is changed in future.
       
   364 	 */
       
   365 	EAP_FUNC_IMPORT u32_t block_size_3des_ede();
       
   366 
       
   367 
       
   368 	/**
       
   369 	 * The cbc_set_encryption_key() function initializes the encryption 
       
   370 	 * context of 3DES-EDE-algorithm to the context using key_length bytes
       
   371 	 * from buffer key. 
       
   372 	 */
       
   373 	EAP_FUNC_IMPORT eap_status_e set_encryption_key_3des_ede(
       
   374 		eap_variable_data_c * const context,
       
   375 		const u8_t * const key,
       
   376 		const u32_t key_length);
       
   377 
       
   378 	/**
       
   379 	 * The cbc_set_decryption_key() function initializes the decryption
       
   380 	 * context of 3DES-EDE-algorithm to the context using key_length bytes
       
   381 	 * from buffer key.
       
   382 	 */
       
   383 	EAP_FUNC_IMPORT eap_status_e set_decryption_key_3des_ede(
       
   384 		eap_variable_data_c * const context,
       
   385 		const u8_t * const key,
       
   386 		const u32_t key_length);
       
   387 
       
   388 	EAP_FUNC_IMPORT eap_status_e cleanup_3des_ede(
       
   389 		eap_variable_data_c * const context);
       
   390 
       
   391 	/**
       
   392 	 * The cbc_encrypt_data() function encrypts data of data_length bytes 
       
   393 	 * using encryption_IV initialization vector. NOTE the length of data must 
       
   394 	 * be aligned to block size of 3DES-EDE-algorithm.
       
   395 	 * This version takes pointers to input and output buffers as a parameter.
       
   396 	 * Those buffers must be fully separated. Some optimizations are used
       
   397 	 * taking advance from separate buffers. 
       
   398 	 */
       
   399 	EAP_FUNC_IMPORT eap_status_e encrypt_block_3des_ede(
       
   400 		eap_variable_data_c * const context,
       
   401 		const u8_t * const data_in,
       
   402 		u8_t * const data_out,
       
   403 		const u32_t data_length);
       
   404 
       
   405 	/**
       
   406 	 * The cbc_decrypt_data() function decrypts data of data_length bytes 
       
   407 	 * using decryption_IV initialization vector. NOTE the length of data must 
       
   408 	 * be aligned to block size of 3DES-EDE-algorithm.
       
   409 	 * This version takes pointers to input and output buffers as a parameter.
       
   410 	 * Those buffers must be fully separated. Some optimizations are used 
       
   411 	 * taking advance from separate buffers.
       
   412 	 */
       
   413 	EAP_FUNC_IMPORT eap_status_e decrypt_block_3des_ede(
       
   414 		eap_variable_data_c * const context,
       
   415 		const u8_t * const data_in,
       
   416 		u8_t * const data_out,
       
   417 		const u32_t data_length);
       
   418 
       
   419 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   420 
       
   421 	/**
       
   422 	 * Key derivation is based on the random number generation specified in
       
   423 	 * NIST Federal Information Processing Standards (FIPS) Publication
       
   424 	 * 186-2 [9]. The random number generator is specified in the change
       
   425 	 * notice 1 (2001 October 5) of [9] (Algorithm 1). As specified in the
       
   426 	 * change notice (page 74), when Algorithm 1 is used as a general-
       
   427 	 * purpose random number generator, the "mod q" term in step 3.3 is
       
   428 	 * omitted. The function G used in the algorithm is constructed via
       
   429 	 * Secure Hash Standard as specified in Appendix 3.3 of the standard.
       
   430 	 
       
   431 	 * 160-bit XKEY and XVAL values are used, so b = 160. The initial
       
   432 	 * secret seed value XKEY is computed from the n GSM Kc keys and the
       
   433 	 * NONCE_MT with the following formula:
       
   434 	 * @code
       
   435 	 * XKEY = SHA1(n*Kc| NONCE_MT)
       
   436 	 * 
       
   437 	 * Random generator becomes as follows:
       
   438 	 * Step 1. Choose a new, secret value for the seed-key, XKEY.
       
   439 	 * Step 2. In hexadecimal notation let
       
   440 	 *         t = 67452301 EFCDAB89 98BADCFE 10325476 C3D2E1F0.
       
   441 	 *         This is the initial value for H0 || H1 || H2 || H3 || H4
       
   442 	 *         in the SHS.
       
   443 	 * Step 3. For j = 0 to m - 1 do
       
   444 	 *             c. xj = G(t,XKEY).
       
   445 	 *             d. XKEY = (1 + XKEY + xj) mod 2^b.
       
   446 	 * @endcode
       
   447 	 */
       
   448 	EAP_FUNC_IMPORT eap_status_e dss_pseudo_random(
       
   449 		u8_t *out,
       
   450 		u32_t out_length,
       
   451 		u8_t *xkey,
       
   452 		u32_t xkey_length);
       
   453 
       
   454 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   455 
       
   456 	/**
       
   457 	 * This function returns the size of message digest of MD5-algorithm.
       
   458 	 */
       
   459 	EAP_FUNC_IMPORT u32_t get_md5_digest_length(
       
   460 		eap_variable_data_c * const md5_context);
       
   461 
       
   462 	/**
       
   463 	 * This function returns the block size of MD5-algorithm.
       
   464 	 */
       
   465 	EAP_FUNC_IMPORT u32_t get_md5_block_size(
       
   466 		eap_variable_data_c * const md5_context);
       
   467 
       
   468 	/**
       
   469 	 * The sha1_init() function initializes MD5.
       
   470 	 * Internal context of MD5 is stored to sha1_context.
       
   471 	 */
       
   472 	EAP_FUNC_IMPORT eap_status_e md5_init(
       
   473 		eap_variable_data_c * const md5_context);
       
   474 
       
   475 	/**
       
   476 	 * The md5_update() function updates the context of 
       
   477 	 * md5_context with data_length bytes of data.
       
   478 	 */
       
   479 	EAP_FUNC_IMPORT eap_status_e md5_update(
       
   480 		eap_variable_data_c * const md5_context,
       
   481 		const u8_t * const data,
       
   482 		const u32_t data_length);
       
   483 
       
   484 	/**
       
   485 	 * The md5_final() function writes the message authentication code 
       
   486 	 * (MAC) to buffer pointed by message_digest. The length of MAC is stored 
       
   487 	 * to buffer pointed by md_length_or_null, If md_length_or_null is non
       
   488 	 * NULL.
       
   489 	 */
       
   490 	EAP_FUNC_IMPORT eap_status_e md5_final(
       
   491 		eap_variable_data_c * const md5_context,
       
   492 		u8_t * const message_digest,
       
   493 		u32_t *md_length_or_null);
       
   494 
       
   495 	/**
       
   496 	 * The hmac_md5_cleanup() cleanups the MD5 context.
       
   497 	 */
       
   498 	EAP_FUNC_IMPORT eap_status_e md5_cleanup(
       
   499 		eap_variable_data_c * const md5_context);
       
   500 
       
   501 	/**
       
   502 	 * The md5_copy_context() copies the MD5 context.
       
   503 	 */
       
   504 	 EAP_FUNC_IMPORT eap_status_e md5_copy_context(
       
   505 		eap_variable_data_c * const copied_md5_context,
       
   506 		const eap_variable_data_c * const original_md5_context);
       
   507 
       
   508 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   509 
       
   510 	/**
       
   511 	 * This function returns the size of message digest of MD4-algorithm.
       
   512 	 */
       
   513 	EAP_FUNC_IMPORT u32_t get_md4_digest_length(
       
   514 		eap_variable_data_c * const md4_context);
       
   515 
       
   516 	/**
       
   517 	 * This function returns the block size of MD4-algorithm.
       
   518 	 */
       
   519 	EAP_FUNC_IMPORT u32_t get_md4_block_size(
       
   520 		eap_variable_data_c * const md4_context);
       
   521 
       
   522 	/**
       
   523 	 * The sha1_init() function initializes MD4.
       
   524 	 * Internal context of MD4 is stored to sha1_context.
       
   525 	 */
       
   526 	EAP_FUNC_IMPORT eap_status_e md4_init(
       
   527 		eap_variable_data_c * const md4_context);
       
   528 
       
   529 	/**
       
   530 	 * The md4_update() function updates the context of 
       
   531 	 * md5_context with data_length bytes of data.
       
   532 	 */
       
   533 	EAP_FUNC_IMPORT eap_status_e md4_update(
       
   534 		eap_variable_data_c * const md4_context,
       
   535 		const u8_t * const data,
       
   536 		const u32_t data_length);
       
   537 
       
   538 	/**
       
   539 	 * The md4_final() function writes the message authentication code 
       
   540 	 * (MAC) to buffer pointed by message_digest. The length of MAC is stored 
       
   541 	 * to buffer pointed by md_length_or_null, If md_length_or_null is non
       
   542 	 * NULL.
       
   543 	 */
       
   544 	EAP_FUNC_IMPORT eap_status_e md4_final(
       
   545 		eap_variable_data_c * const md4_context,
       
   546 		u8_t * const message_digest,
       
   547 		u32_t *md_length_or_null);
       
   548 
       
   549 	/**
       
   550 	 * The hmac_md5_cleanup() cleanups the MD4 context.
       
   551 	 */
       
   552 	EAP_FUNC_IMPORT eap_status_e md4_cleanup(
       
   553 		eap_variable_data_c * const md4_context);
       
   554 
       
   555 	/**
       
   556 	 * The md4_copy_context() copies the MD4 context.
       
   557 	 */
       
   558 	 EAP_FUNC_IMPORT eap_status_e md4_copy_context(
       
   559 		eap_variable_data_c * const copied_md4_context,
       
   560 		const eap_variable_data_c * const original_md4_context);
       
   561 
       
   562 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   563 
       
   564 	/**
       
   565 	* Used to set the RC4 key.
       
   566 	*/
       
   567 	EAP_FUNC_IMPORT eap_status_e rc4_set_key(
       
   568 		eap_variable_data_c * const rc4_context, 
       
   569 		const eap_variable_data_c * const key);
       
   570 
       
   571 	/**
       
   572 	* Used to clean up the RC4 context.
       
   573 	*/
       
   574 	EAP_FUNC_IMPORT eap_status_e rc4_cleanup(
       
   575 		eap_variable_data_c * const rc4_context);
       
   576 
       
   577 	/**
       
   578 	* Encrypts RC4 data.
       
   579 	*/
       
   580 	EAP_FUNC_IMPORT eap_status_e rc4_encrypt(
       
   581 		const eap_variable_data_c * const rc4_context, 
       
   582 		void * const data_in_out,
       
   583 		const u32_t data_length);
       
   584 
       
   585 	/**
       
   586 	* Encrypts RC4 data.
       
   587 	*/
       
   588 	EAP_FUNC_IMPORT eap_status_e rc4_encrypt(
       
   589 		const eap_variable_data_c * const rc4_context, 
       
   590 		const void * const data_in, 
       
   591 		void * const data_out,
       
   592 		const u32_t data_length);
       
   593 
       
   594 	/**
       
   595 	* Decrypts RC4 data.
       
   596 	*/
       
   597 	EAP_FUNC_IMPORT eap_status_e rc4_decrypt(
       
   598 		const eap_variable_data_c * const rc4_context, 
       
   599 		void * const data_in_out,
       
   600 		const u32_t data_length);
       
   601 
       
   602 	/**
       
   603 	* Decrypts RC4 data.
       
   604 	*/
       
   605 	EAP_FUNC_IMPORT eap_status_e rc4_decrypt(
       
   606 		const eap_variable_data_c * const rc4_context, 
       
   607 		const void * const data_in, 
       
   608 		void * const data_out,
       
   609 		const u32_t data_length);
       
   610 	
       
   611 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   612 
       
   613 	/**
       
   614 	 * The rsa_init() function initializes context of RSA.
       
   615 	 * Internal context of RSA is stored to rsa_context.
       
   616 	 */
       
   617 	EAP_FUNC_IMPORT eap_status_e rsa_init(
       
   618 		eap_variable_data_c * const rsa_context);
       
   619 
       
   620 	EAP_FUNC_IMPORT eap_status_e rsa_encrypt_with_public_key(
       
   621 		eap_variable_data_c * const rsa_context,
       
   622 		const eap_variable_data_c * const public_rsa_key,
       
   623 		const eap_variable_data_c * const input_data,
       
   624 		eap_variable_data_c * const output_data);
       
   625 
       
   626 	EAP_FUNC_IMPORT eap_status_e rsa_decrypt_with_public_key(
       
   627 		eap_variable_data_c * const rsa_context,
       
   628 		const eap_variable_data_c * const public_rsa_key,
       
   629 		const eap_variable_data_c * const input_data,
       
   630 		eap_variable_data_c * const output_data);
       
   631 
       
   632 	EAP_FUNC_IMPORT eap_status_e rsa_encrypt_with_private_key(
       
   633 		eap_variable_data_c * const rsa_context,
       
   634 		const eap_variable_data_c * const private_rsa_key,
       
   635 		const eap_variable_data_c * const input_data,
       
   636 		eap_variable_data_c * const output_data);
       
   637 
       
   638 	EAP_FUNC_IMPORT eap_status_e rsa_decrypt_with_private_key(
       
   639 		eap_variable_data_c * const rsa_context,
       
   640 		const eap_variable_data_c * const private_rsa_key,
       
   641 		const eap_variable_data_c * const input_data,
       
   642 		eap_variable_data_c * const output_data);
       
   643 
       
   644 	EAP_FUNC_IMPORT eap_status_e rsa_sign(
       
   645 		eap_variable_data_c * const rsa_context,
       
   646 		const eap_variable_data_c * const private_rsa_key,
       
   647 		const eap_variable_data_c * const hash,
       
   648 		eap_variable_data_c * const signed_hash);
       
   649 
       
   650 	EAP_FUNC_IMPORT eap_status_e rsa_verify(
       
   651 		eap_variable_data_c * const rsa_context,
       
   652 		const eap_variable_data_c * const public_rsa_key,
       
   653 		const eap_variable_data_c * const hash,
       
   654 		const eap_variable_data_c * const signed_hash);
       
   655 
       
   656 	/**
       
   657 	 * The rsa_cleanup() function cleans up context of RSA.
       
   658 	 * Internal context of RSA is stored to rsa_context.
       
   659 	 */
       
   660 	EAP_FUNC_IMPORT eap_status_e rsa_cleanup(
       
   661 		eap_variable_data_c * const rsa_context);
       
   662 
       
   663 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   664 
       
   665 	/**
       
   666 	 * The dsa_init() function initializes context of DSA.
       
   667 	 * Internal context of DSA is stored to dsa_context.
       
   668 	 */
       
   669 	EAP_FUNC_IMPORT eap_status_e dsa_init(
       
   670 		eap_variable_data_c * const dsa_context);
       
   671 
       
   672 	EAP_FUNC_IMPORT eap_status_e dsa_sign(
       
   673 		eap_variable_data_c * const dsa_context,
       
   674 		const eap_variable_data_c * const private_dsa_key,
       
   675 		const eap_variable_data_c * const hash,
       
   676 		eap_variable_data_c * const signed_hash);
       
   677 
       
   678 	EAP_FUNC_IMPORT eap_status_e dsa_verify(
       
   679 		eap_variable_data_c * const dsa_context,		
       
   680 		const eap_variable_data_c * const public_dsa_key,
       
   681 		const eap_variable_data_c * const dsa_param_p,
       
   682 		const eap_variable_data_c * const dsa_param_q,
       
   683 		const eap_variable_data_c * const dsa_param_g,
       
   684 		const eap_variable_data_c * const hash,
       
   685 		const eap_variable_data_c * const signed_hash);
       
   686 
       
   687 	/**
       
   688 	 * The dsa_cleanup() function cleans up context of DSA.
       
   689 	 * Internal context of DSA is stored to dsa_context.
       
   690 	 */
       
   691 	EAP_FUNC_IMPORT eap_status_e dsa_cleanup(
       
   692 		eap_variable_data_c * const dsa_context);
       
   693 
       
   694 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   695 
       
   696 	EAP_FUNC_IMPORT void open_crypto_memory_leaks();
       
   697 	EAP_FUNC_IMPORT void close_crypto_memory_leaks();
       
   698 };
       
   699 
       
   700 #endif //#if !defined( _EAP_AM_CRYPTO_OPENSSL_H_ )
       
   701 
       
   702 
       
   703 
       
   704 // End.