eapol/eapol_framework/eapol_common/include/eap_crypto_api.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_CRYPTO_API_H_ )
       
    22 #define _EAP_CRYPTO_API_H_
       
    23 
       
    24 #include "eap_am_types.h"
       
    25 #include "eap_variable_data.h"
       
    26 #include "eap_am_export.h"
       
    27 #include "abs_eap_am_crypto.h"
       
    28 #include "eap_array.h"
       
    29 
       
    30 #if defined(des_set_key)
       
    31 // OpenSSL defines this.
       
    32 #undef des_set_key
       
    33 #endif //#if defined(des_set_key)
       
    34 
       
    35 
       
    36 const u32_t HMAC_SHA1_SIZE = 20u; // bytes = 160 bits
       
    37 const u32_t HMAC_SHA1_128_SIZE = 16u; // bytes = 128 bits
       
    38 const u32_t HMAC_MD5_SIZE = 20u; // bytes = 160 bits
       
    39 const u32_t HMAC_MD5_128_SIZE = 16u; // bytes = 128 bits
       
    40 
       
    41 const u32_t WPA_PSK_LENGTH = 32;
       
    42 
       
    43 /// The abs_crypto_block_algorithm_c class describes interface of CBC block encryption algorithm.
       
    44 class EAP_EXPORT abs_crypto_cbc_block_algorithm_c
       
    45 {
       
    46 
       
    47 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
    48 private:
       
    49 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
    50 
       
    51 
       
    52 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
    53 public:
       
    54 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
    55 
       
    56 	EAP_FUNC_IMPORT virtual ~abs_crypto_cbc_block_algorithm_c();
       
    57 
       
    58 	/**
       
    59 	 * The set_is_valid() function sets the state of the
       
    60 	 * abs_crypto_block_algorithm_c object valid. The abs_crypto_block_algorithm_c object 
       
    61 	 * calls this function after it is initialized.
       
    62 	 */
       
    63 	virtual void set_is_valid() = 0;
       
    64 
       
    65 	/**
       
    66 	 * The get_is_valid() function returns the status of the abs_crypto_block_algorithm_c object.
       
    67 	 * True indicates the object is initialized.
       
    68 	 */
       
    69 	virtual bool get_is_valid() = 0;
       
    70 
       
    71 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
    72 
       
    73 	/**
       
    74 	 * The get_encrypts() function returns true when encryption is initialized.
       
    75 	 * It returns false when decryption is initialized.
       
    76 	 */
       
    77 	virtual bool get_encrypts() = 0;
       
    78 
       
    79 	/**
       
    80 	 * This function returns the length of AES key in bytes.
       
    81 	 */
       
    82 	virtual u32_t get_key_length() = 0;
       
    83 
       
    84 	/**
       
    85 	 * This function returns the length of AES block size in bytes.
       
    86 	 */
       
    87 	virtual u32_t get_block_size() = 0;
       
    88 
       
    89 	/**
       
    90 	 * Calculates the data length aligned to block size.
       
    91 	 */
       
    92 	virtual u32_t aligned_data_length(
       
    93 		u32_t data_length) = 0;
       
    94 
       
    95 	/**
       
    96 	 * This function returns the internally stored initialization vector.
       
    97 	 * The last encrypted and decrypted block is stored to this buffer 
       
    98 	 * between subsequent encryption and decryption calls. 
       
    99 	 * User of crypto_cbc_c object could get the last stored block calling this function.
       
   100 	 */
       
   101 	virtual const eap_variable_data_c * get_tmp_IV() = 0;
       
   102 
       
   103 	/**
       
   104 	 * This function adds count padding bytes to buffer. All padding bytes are zero (0x00).
       
   105 	 */
       
   106 	virtual eap_status_e add_padding_bytes(
       
   107 		void * const buffer,
       
   108 		const u32_t buffer_length,
       
   109 		const u8_t padding_byte) = 0;
       
   110 
       
   111 	/**
       
   112 	 * This function checks the count padding bytes of buffer are zero (0x00).
       
   113 	 */
       
   114 	virtual eap_status_e check_padding_bytes(
       
   115 		const void * const buffer,
       
   116 		const u32_t buffer_length,
       
   117 		const u8_t padding_byte) = 0;
       
   118 
       
   119 	/**
       
   120 	 * This function sets the mode to encryption, 
       
   121 	 * sets the initialization vector and the encryption key.
       
   122 	 */
       
   123 	virtual eap_status_e set_encryption_key(
       
   124 		const void * const encryption_IV,
       
   125 		const u32_t encryption_IV_length,
       
   126 		const void * const key,
       
   127 		const u32_t key_length) = 0;
       
   128 
       
   129 	/**
       
   130 	 * This function sets the mode to decryption, 
       
   131 	 * sets the initialization vector and the decryption key.
       
   132 	 */
       
   133 	virtual eap_status_e set_decryption_key(
       
   134 		const void * const encryption_IV,
       
   135 		const u32_t encryption_IV_length,
       
   136 		const void * const key,
       
   137 		const u32_t key_length) = 0;
       
   138 
       
   139 	/**
       
   140 	 * This function encrypts continuous data bytes from data_in to data_out buffer. 
       
   141 	 * Note the length of the data must be aligned to block size of the cipher.
       
   142 	 */
       
   143 	virtual eap_status_e encrypt_data(
       
   144 		const void * const data_in,
       
   145 		void * const data_out,
       
   146 		const u32_t data_length) = 0;
       
   147 
       
   148 	/**
       
   149 	 * This function encrypts continuous data bytes in data_in_out buffer. 
       
   150 	 * Note the length of the data must be aligned to block size of the cipher.
       
   151 	 */
       
   152 	virtual eap_status_e encrypt_data(
       
   153 		void * const data_in_out,
       
   154 		const u32_t data_length) = 0;
       
   155 
       
   156 	/**
       
   157 	 * This function decrypts continuous data bytes from data_in to data_out buffer. 
       
   158 	 * Note the length of the data must be aligned to block size of the cipher.
       
   159 	 */
       
   160 	virtual eap_status_e decrypt_data(
       
   161 		const void * const data_in,
       
   162 		void * const data_out,
       
   163 		const u32_t data_length) = 0;
       
   164 
       
   165 	/**
       
   166 	 * This function decrypts continuous data bytes in data_in_out buffer. 
       
   167 	 * Note the length of the data must be aligned to block size of the cipher.
       
   168 	 */
       
   169 	virtual eap_status_e decrypt_data(
       
   170 		void * const data_in_out,
       
   171 		const u32_t data_length) = 0;
       
   172 
       
   173 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   174 
       
   175 	/**
       
   176 	 * The update_non_aligned() function updates the context of 
       
   177 	 * AES-algorithm with data bytes. The direction (encryption/decryption) 
       
   178 	 * depends of the initialized context. NOTE the length of data feed in 
       
   179 	 * separate calls of update_non_aligned() does not need to be 
       
   180 	 * aligned to AES-block size. Only the sum of whole data must be aligned to AES-block size.
       
   181 	 * This version takes pointers to input and output buffers as a parameter. 
       
   182 	 * Those buffers must be fully separated. Some optimizations are used 
       
   183 	 * taking advance from separate buffers. 
       
   184 	 */
       
   185 	virtual eap_status_e update_non_aligned(
       
   186 		const void * const msg_in,
       
   187 		void * const msg_out,
       
   188 		const u32_t msg_size) = 0;
       
   189 
       
   190 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   191 
       
   192 	/**
       
   193 	 * The update_non_aligned() function updates the context of 
       
   194 	 * AES-algorithm with data bytes. The direction (encryption/decryption) 
       
   195 	 * depends of the initialized context. NOTE the length of data feed in 
       
   196 	 * separate calls of update_non_aligned() does not need to be 
       
   197 	 * aligned to AES-block size. Only the sum of whole data must be aligned to AES-block size.
       
   198 	 * This version takes one pointer to buffer. The buffer is used for input and output data. 
       
   199 	 */
       
   200 	virtual eap_status_e update_non_aligned(
       
   201 		void * const msg_in_out,
       
   202 		const u32_t msg_size) = 0;
       
   203 
       
   204 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   205 
       
   206 	/**
       
   207 	 * The finalize_non_aligned() finalizes the AES-context. 
       
   208 	 * The sum of length of feed data must be aligned to AES-block size 
       
   209 	 * before this function is called.
       
   210 	 */
       
   211 	virtual eap_status_e finalize_non_aligned() = 0;
       
   212 
       
   213 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   214 };
       
   215 
       
   216 
       
   217 
       
   218 /// The abs_crypto_block_algorithm_c class describes interface of block encryption algorithm.
       
   219 class EAP_EXPORT abs_crypto_block_algorithm_c
       
   220 {
       
   221 
       
   222 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   223 private:
       
   224 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   225 
       
   226 
       
   227 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   228 public:
       
   229 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   230 
       
   231 	EAP_FUNC_IMPORT virtual ~abs_crypto_block_algorithm_c();
       
   232 
       
   233 	/**
       
   234 	 * The set_is_valid() function sets the state of the
       
   235 	 * abs_crypto_block_algorithm_c object valid. The abs_crypto_block_algorithm_c object 
       
   236 	 * calls this function after it is initialized.
       
   237 	 */
       
   238 	virtual void set_is_valid() = 0;
       
   239 
       
   240 	/**
       
   241 	 * The get_is_valid() function returns the status of the abs_crypto_block_algorithm_c object.
       
   242 	 * True indicates the object is initialized.
       
   243 	 */
       
   244 	virtual bool get_is_valid() = 0;
       
   245 
       
   246 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   247 
       
   248 	/**
       
   249 	 * The get_encrypts() function returns true when encryption is initialized.
       
   250 	 * It returns false when decryption is initialized.
       
   251 	 */
       
   252 	virtual bool get_encrypts() = 0;
       
   253 
       
   254 	/**
       
   255 	 * This function returns the length of key in bytes.
       
   256 	 */
       
   257 	virtual u32_t get_key_length() = 0;
       
   258 
       
   259 	/**
       
   260 	 * This function returns the length of block size in bytes.
       
   261 	 */
       
   262 	virtual u32_t get_block_size() = 0;
       
   263 
       
   264 	/**
       
   265 	 * This function sets the mode to encryption, 
       
   266 	 * sets the initialization vector and the encryption key.
       
   267 	 */
       
   268 	virtual eap_status_e set_encryption_key(
       
   269 		const void * const key,
       
   270 		const u32_t key_length) = 0;
       
   271 
       
   272 	/**
       
   273 	 * This function sets the mode to decryption, 
       
   274 	 * sets the initialization vector and the decryption key.
       
   275 	 */
       
   276 	virtual eap_status_e set_decryption_key(
       
   277 		const void * const key,
       
   278 		const u32_t key_length) = 0;
       
   279 
       
   280 	/**
       
   281 	 * This function encrypts continuous data bytes from data_in to data_out buffer. 
       
   282 	 * Note the length of the data must be aligned to block size of the cipher.
       
   283 	 */
       
   284 	virtual eap_status_e encrypt_block(
       
   285 		const void * const data_in,
       
   286 		void * const data_out,
       
   287 		const u32_t data_length) = 0;
       
   288 
       
   289 	/**
       
   290 	 * This function decrypts continuous data bytes from data_in to data_out buffer. 
       
   291 	 * Note the length of the data must be aligned to block size of the cipher.
       
   292 	 */
       
   293 	virtual eap_status_e decrypt_block(
       
   294 		const void * const data_in,
       
   295 		void * const data_out,
       
   296 		const u32_t data_length) = 0;
       
   297 
       
   298 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   299 };
       
   300 
       
   301 
       
   302 
       
   303 /// The abs_crypto_stream_algorithm_c class describes interface of stream encryption algorithm.
       
   304 class EAP_EXPORT abs_crypto_stream_algorithm_c
       
   305 {
       
   306 
       
   307 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   308 private:
       
   309 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   310 
       
   311 
       
   312 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   313 public:
       
   314 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   315 
       
   316 	EAP_FUNC_IMPORT virtual ~abs_crypto_stream_algorithm_c();
       
   317 
       
   318 	/**
       
   319 	 * The set_is_valid() function sets the state of the
       
   320 	 * abs_crypto_block_algorithm_c object valid. The abs_crypto_block_algorithm_c object 
       
   321 	 * calls this function after it is initialized.
       
   322 	 */
       
   323 	virtual void set_is_valid() = 0;
       
   324 
       
   325 	/**
       
   326 	 * The get_is_valid() function returns the status of the abs_crypto_block_algorithm_c object.
       
   327 	 * True indicates the object is initialized.
       
   328 	 */
       
   329 	virtual bool get_is_valid() = 0;
       
   330 
       
   331 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   332 
       
   333 	/**
       
   334 	 * This function sets the key.
       
   335 	 */
       
   336 	virtual eap_status_e set_key(
       
   337 		const eap_variable_data_c * const key) = 0;
       
   338 
       
   339 	/**
       
   340 	 * This function discards desired count of stream.
       
   341 	 */
       
   342 	virtual eap_status_e discard_stream(const u32_t count_of_discarded_octets) = 0;
       
   343 
       
   344 	/**
       
   345 	 * This function encrypts continuous data bytes in data_in_out buffer. 
       
   346 	 */
       
   347 	virtual eap_status_e encrypt_data(
       
   348 		void * const data_in_out,
       
   349 		const u32_t data_length) = 0;
       
   350 
       
   351 	/**
       
   352 	 * This function encrypts continuous data bytes from data_in to data_out buffer. 
       
   353 	 */
       
   354 	virtual eap_status_e encrypt_data(
       
   355 		const void * const data_in,
       
   356 		void * const data_out,
       
   357 		const u32_t data_length) = 0;
       
   358 
       
   359 	/**
       
   360 	 * This function encrypts continuous data bytes in data_in_out buffer. 
       
   361 	 */
       
   362 	virtual eap_status_e decrypt_data(
       
   363 		void * const data_in_out,
       
   364 		const u32_t data_length) = 0;
       
   365 
       
   366 	/**
       
   367 	 * This function decrypts continuous data bytes from data_in to data_out buffer. 
       
   368 	 */
       
   369 	virtual eap_status_e decrypt_data(
       
   370 		const void * const data_in,
       
   371 		void * const data_out,
       
   372 		const u32_t data_length) = 0;
       
   373 
       
   374 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   375 };
       
   376 
       
   377 
       
   378 
       
   379 /// The abs_crypto_hash_algorithm_c class describes interface the MAC algorithm.
       
   380 class EAP_EXPORT abs_crypto_hash_algorithm_c
       
   381 {
       
   382 
       
   383 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   384 private:
       
   385 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   386 
       
   387 
       
   388 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   389 public:
       
   390 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   391 
       
   392 	EAP_FUNC_IMPORT virtual ~abs_crypto_hash_algorithm_c();
       
   393 
       
   394 	/**
       
   395 	 * The set_is_valid() function sets the state of the
       
   396 	 * abs_crypto_hash_algorithm_c object valid. The abs_crypto_hash_algorithm_c object 
       
   397 	 * calls this function after it is initialized.
       
   398 	 */
       
   399 	virtual void set_is_valid() = 0;
       
   400 
       
   401 	/**
       
   402 	 * The get_is_valid() function returns the status of the abs_crypto_hash_algorithm_c object.
       
   403 	 * True indicates the object is initialized.
       
   404 	 */
       
   405 	virtual bool get_is_valid() = 0;
       
   406 
       
   407 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   408 
       
   409 	/**
       
   410 	 * This function returns the size of message digest of HASH-algorithm.
       
   411 	 */
       
   412 	virtual u32_t get_digest_length() = 0;
       
   413 
       
   414 	/**
       
   415 	 * This function returns the block size of HASH-algorithm.
       
   416 	 */
       
   417 	virtual u32_t get_block_size() = 0;
       
   418 
       
   419 	/**
       
   420 	 * This function sets the mode to encryption, 
       
   421 	 * sets the initialization vector and the encryption key.
       
   422 	 */
       
   423 	virtual eap_status_e hash_init() = 0;
       
   424 
       
   425 	/**
       
   426 	 * This function updates the context of HASH-algorithm with data.
       
   427 	 */
       
   428 	virtual eap_status_e hash_update(
       
   429 		const void * const data,
       
   430 		const u32_t data_length) = 0;
       
   431 
       
   432 	/**
       
   433 	 * This function writes the message digest to buffer. 
       
   434 	 * Length is set if md_length_or_null is non-NULL.
       
   435 	 */
       
   436 	virtual eap_status_e hash_final(
       
   437 		void * const message_digest,
       
   438 		u32_t *md_length_or_null) = 0;
       
   439 
       
   440 	/**
       
   441 	 * This function cleans up the HMAC-SHA1 context.
       
   442 	 */
       
   443 	virtual eap_status_e hash_cleanup() = 0;
       
   444 
       
   445 	/**
       
   446 	 * This function returns a copy of the context of HASH-algorithm.
       
   447 	 * Caller must free the copy.
       
   448 	 */
       
   449 	virtual abs_crypto_hash_algorithm_c * copy() = 0;
       
   450 
       
   451 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   452 };
       
   453 
       
   454 
       
   455 //------------------------------------------------------------
       
   456 
       
   457 
       
   458 /// The abs_crypto_mac_algorithm_c class describes interface the HMAC algorithm.
       
   459 class EAP_EXPORT abs_crypto_hmac_algorithm_c
       
   460 {
       
   461 
       
   462 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   463 private:
       
   464 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   465 
       
   466 
       
   467 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   468 public:
       
   469 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   470 
       
   471 	EAP_FUNC_IMPORT virtual ~abs_crypto_hmac_algorithm_c();
       
   472 
       
   473 	/**
       
   474 	 * The set_is_valid() function sets the state of the
       
   475 	 * abs_crypto_mac_algorithm_c object valid. The abs_crypto_mac_algorithm_c object 
       
   476 	 * calls this function after it is initialized.
       
   477 	 */
       
   478 	virtual void set_is_valid() = 0;
       
   479 
       
   480 	/**
       
   481 	 * The get_is_valid() function returns the status of the abs_crypto_mac_algorithm_c object.
       
   482 	 * True indicates the object is initialized.
       
   483 	 */
       
   484 	virtual bool get_is_valid() = 0;
       
   485 
       
   486 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   487 
       
   488 	/**
       
   489 	 * This function returns the size of message digest of HMAC-algorithm.
       
   490 	 */
       
   491 	virtual u32_t get_digest_length() = 0;
       
   492 
       
   493 	/**
       
   494 	 * This function sets the mode to encryption, 
       
   495 	 * sets the initialization vector and the encryption key.
       
   496 	 */
       
   497 	virtual eap_status_e hmac_set_key(
       
   498 		const eap_variable_data_c * const mac_key) = 0;
       
   499 
       
   500 	/**
       
   501 	 * This function updates the context of HMAC-algorithm with data.
       
   502 	 */
       
   503 	virtual eap_status_e hmac_update(
       
   504 		const void * const data,
       
   505 		const u32_t data_length) = 0;
       
   506 
       
   507 	/**
       
   508 	 * This function writes the message digest to buffer. 
       
   509 	 * Length is set if md_length_or_null is non-NULL.
       
   510 	 */
       
   511 	virtual eap_status_e hmac_final(
       
   512 		void * const message_digest,
       
   513 		u32_t *md_length_or_null) = 0;
       
   514 
       
   515 	/**
       
   516 	 * This function cleans up the HMAC context.
       
   517 	 */
       
   518 	virtual eap_status_e hmac_cleanup() = 0;
       
   519 
       
   520 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   521 };
       
   522 
       
   523 
       
   524 //------------------------------------------------------------
       
   525 
       
   526 
       
   527 /// The crypto_hmac_c class describes HMAC algorithm.
       
   528 class EAP_EXPORT crypto_hmac_c
       
   529 : public abs_crypto_hmac_algorithm_c
       
   530 {
       
   531 
       
   532 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   533 private:
       
   534 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   535 
       
   536 	/// This is pointer to the tools class.
       
   537 	abs_eap_am_tools_c * const m_am_tools;
       
   538 
       
   539 	/// This is pointer to the block encryption algorithm.
       
   540 	abs_crypto_hash_algorithm_c * m_crypto_hash_algorithm;
       
   541 
       
   542 	/// This is the initialized key.
       
   543 	eap_variable_data_c * m_key;
       
   544 
       
   545 	/// This is the initialized inner pad.
       
   546 	eap_variable_data_c * m_ipad;
       
   547 
       
   548 	/// This is the initialized outer pad.
       
   549 	eap_variable_data_c * m_opad;
       
   550 
       
   551 	/// This indicates whether this object was generated successfully.
       
   552 	bool m_is_valid;
       
   553 
       
   554 	/// This object must free m_crypto_hash_algorithm when this value is true.
       
   555 	bool m_free_crypto_hash_algorithm;
       
   556 
       
   557 
       
   558 	EAP_FUNC_IMPORT eap_status_e initialize_pad(
       
   559 		eap_variable_data_c * const p_pad,
       
   560 		const u8_t pad_value);
       
   561 
       
   562 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   563 public:
       
   564 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   565 
       
   566 	/**
       
   567 	 * Destructor resets the used internal buffers.
       
   568 	 */
       
   569 	EAP_FUNC_IMPORT virtual ~crypto_hmac_c();
       
   570 
       
   571 	/**
       
   572 	 * Constructor initializes the used internal buffers.
       
   573 	 */
       
   574 	EAP_FUNC_IMPORT crypto_hmac_c(
       
   575 		abs_eap_am_tools_c * const tools,
       
   576 		abs_crypto_hash_algorithm_c * const crypto_hash_algorithm,
       
   577 		const bool free_crypto_hash_algorithm);
       
   578 
       
   579 	/**
       
   580 	 * The set_is_valid() function sets the state of the
       
   581 	 * abs_crypto_mac_algorithm_c object valid. The abs_crypto_mac_algorithm_c object 
       
   582 	 * calls this function after it is initialized.
       
   583 	 */
       
   584 	EAP_FUNC_IMPORT void set_is_valid();
       
   585 
       
   586 	/**
       
   587 	 * The get_is_valid() function returns the status of the abs_crypto_mac_algorithm_c object.
       
   588 	 * True indicates the object is initialized.
       
   589 	 */
       
   590 	EAP_FUNC_IMPORT bool get_is_valid();
       
   591 
       
   592 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   593 
       
   594 	/**
       
   595 	 * This function returns the size of message digest of HMAC-algorithm.
       
   596 	 */
       
   597 	EAP_FUNC_IMPORT u32_t get_digest_length();
       
   598 
       
   599 	/**
       
   600 	 * This function sets the mode to encryption, 
       
   601 	 * sets the initialization vector and the encryption key.
       
   602 	 */
       
   603 	EAP_FUNC_IMPORT eap_status_e hmac_set_key(
       
   604 		const eap_variable_data_c * const hmac_key);
       
   605 
       
   606 	/**
       
   607 	 * This function updates the context of HMAC-algorithm with data.
       
   608 	 */
       
   609 	EAP_FUNC_IMPORT eap_status_e hmac_update(
       
   610 		const void * const data,
       
   611 		const u32_t data_length);
       
   612 
       
   613 	/**
       
   614 	 * This function writes the message digest to buffer. 
       
   615 	 * Length is set if md_length_or_null is non-NULL.
       
   616 	 */
       
   617 	EAP_FUNC_IMPORT eap_status_e hmac_final(
       
   618 		void * const message_digest,
       
   619 		u32_t *md_length_or_null);
       
   620 
       
   621 	/**
       
   622 	 * This function writes the message digest of HMAC of 128 bits in length to buffer. 
       
   623 	 * Length is set if md_length_or_null is non-NULL.
       
   624 	 */
       
   625 	EAP_FUNC_IMPORT eap_status_e hmac_128_final(
       
   626 		void * const message_digest,
       
   627 		u32_t *md_length_or_null);
       
   628 
       
   629 	/**
       
   630 	 * This function cleans up the HMAC context.
       
   631 	 */
       
   632 	EAP_FUNC_IMPORT eap_status_e hmac_cleanup();
       
   633 
       
   634 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   635 };
       
   636 
       
   637 
       
   638 //------------------------------------------------------------
       
   639 
       
   640 /// The crypto_cbc_c class includes the state of 
       
   641 /// one instance of CBC block encryption algorithm.
       
   642 class EAP_EXPORT crypto_cbc_c
       
   643 : public abs_crypto_cbc_block_algorithm_c
       
   644 {
       
   645 
       
   646 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   647 private:
       
   648 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   649 
       
   650 	/// This is pointer to the tools class.
       
   651 	abs_eap_am_tools_c * const m_am_tools;
       
   652 
       
   653 	/// This is pointer to the block encryption algorithm.
       
   654 	abs_crypto_block_algorithm_c * m_crypto_block_algorithm;
       
   655 
       
   656 	/// This indicates whether this object was generated successfully.
       
   657 	bool m_is_valid;
       
   658 
       
   659 	/// This stores the initialization vector between subsequent
       
   660 	/// calls of encryption or decryption.
       
   661 	eap_variable_data_c * m_tmp_IV;
       
   662 
       
   663 	/// This stores the offset of non-aligned data between 
       
   664 	/// subsequent calls of encryption or decryption.
       
   665 	i32_t m_encr_offset;
       
   666 
       
   667 	/// This stores pointers to non-aligned data targets between 
       
   668 	/// subsequent calls of encryption or decryption.
       
   669 	u8_t **m_encr_dispatch;
       
   670 
       
   671 	/// This stores the non-aligned data between subsequent 
       
   672 	/// calls of encryption or decryption.
       
   673 	u8_t *m_encr_hold;
       
   674 
       
   675 	u8_t *m_saved_in_buffer;
       
   676 	u8_t *m_saved_out_buffer;
       
   677 
       
   678 	u8_t *m_iv_buffer_1;
       
   679 	u8_t *m_iv_buffer_2;
       
   680 
       
   681 	bool m_free_crypto_block_algorithm;
       
   682 
       
   683 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   684 
       
   685 	EAP_FUNC_IMPORT void reset();
       
   686 
       
   687 	/**
       
   688 	 * Run xor to data and IV block.
       
   689 	 */
       
   690 	EAP_FUNC_IMPORT void cbc_xor_block(
       
   691 		const void * const encryption_IV,
       
   692 		void * const data_block,
       
   693 		const u32_t block_size,
       
   694 		const u32_t key_length);
       
   695 
       
   696 	/**
       
   697 	 * Copies source to target.
       
   698 	 */
       
   699 	EAP_FUNC_IMPORT void cbc_copy_block(
       
   700 		void * const target,
       
   701 		const void * const source,
       
   702 		const u32_t block_size,
       
   703 		const u32_t key_length);
       
   704 
       
   705 	/**
       
   706 	 * This function encrypts continuous data bytes from data_in to data_out buffer. 
       
   707 	 * Note the length of the data must be aligned to block size of the cipher.
       
   708 	 */
       
   709 	EAP_FUNC_IMPORT eap_status_e internal_encrypt_data(
       
   710 		const void * const data_in,
       
   711 		void * const data_out,
       
   712 		const u32_t data_length);
       
   713 
       
   714 	/**
       
   715 	 * This function decrypts continuous data bytes from data_in to data_out buffer. 
       
   716 	 * Note the length of the data must be aligned to block size of the cipher.
       
   717 	 */
       
   718 	EAP_FUNC_IMPORT eap_status_e internal_decrypt_data(
       
   719 		const void * const data_in,
       
   720 		void * const data_out,
       
   721 		const u32_t data_length);
       
   722 
       
   723 
       
   724 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   725 public:
       
   726 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   727 
       
   728 	/**
       
   729 	 * Destructor resets the used internal buffers.
       
   730 	 */
       
   731 	EAP_FUNC_IMPORT virtual ~crypto_cbc_c();
       
   732 
       
   733 	/**
       
   734 	 * Constructor initializes the used internal buffers.
       
   735 	 */
       
   736 	EAP_FUNC_IMPORT crypto_cbc_c(
       
   737 		abs_eap_am_tools_c * const tools,
       
   738 		abs_crypto_block_algorithm_c * const crypto_block_algorithm,
       
   739 		const bool free_crypto_block_algorithm);
       
   740 
       
   741 	/**
       
   742 	 * The get_encrypts() function returns true when encryption is initialized.
       
   743 	 * It returns false when decryption is initialized.
       
   744 	 */
       
   745 	EAP_FUNC_IMPORT virtual bool get_encrypts();
       
   746 
       
   747 	/**
       
   748 	 * This function returns the length of CBC key in bytes.
       
   749 	 */
       
   750 	EAP_FUNC_IMPORT virtual u32_t get_key_length();
       
   751 
       
   752 	/**
       
   753 	 * This function returns the length of CBC block size in bytes.
       
   754 	 */
       
   755 	EAP_FUNC_IMPORT virtual u32_t get_block_size();
       
   756 
       
   757 	/**
       
   758 	 * The set_is_valid() function sets the state of the
       
   759 	 * crypto_cbc_c object valid. The crypto_cbc_c object 
       
   760 	 * calls this function after it is initialized.
       
   761 	 */
       
   762 	EAP_FUNC_IMPORT void set_is_valid();
       
   763 
       
   764 	/**
       
   765 	 * The get_is_valid() function returns the status of the crypto_cbc_c object.
       
   766 	 * True indicates the object is initialized.
       
   767 	 */
       
   768 	EAP_FUNC_IMPORT bool get_is_valid();
       
   769 
       
   770 	/**
       
   771 	 * This function returns the internally stored initialization vector.
       
   772 	 * The last encrypted and decrypted block is stored to this buffer 
       
   773 	 * between subsequent encryption and decryption calls. 
       
   774 	 * User of crypto_cbc_c object could get the last stored block calling this function.
       
   775 	 */
       
   776 	EAP_FUNC_IMPORT const eap_variable_data_c * get_tmp_IV();
       
   777 
       
   778 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   779 
       
   780 	/**
       
   781 	 * Calculates the data length aligned to block size.
       
   782 	 */
       
   783 	EAP_FUNC_IMPORT u32_t aligned_data_length(
       
   784 		u32_t data_length);
       
   785 
       
   786 	/**
       
   787 	 * This function adds count padding bytes to buffer. All padding bytes are zero (0x00).
       
   788 	 */
       
   789 	EAP_FUNC_IMPORT eap_status_e add_padding_bytes(
       
   790 		void * const buffer,
       
   791 		const u32_t buffer_length,
       
   792 		const u8_t padding_byte);
       
   793 
       
   794 	/**
       
   795 	 * This function checks the count padding bytes of buffer are zero (0x00).
       
   796 	 */
       
   797 	EAP_FUNC_IMPORT eap_status_e check_padding_bytes(
       
   798 		const void * const buffer,
       
   799 		const u32_t buffer_length,
       
   800 		const u8_t padding_byte);
       
   801 
       
   802 	/**
       
   803 	 * This function sets the mode to encryption, 
       
   804 	 * sets the initialization vector and the encryption key.
       
   805 	 */
       
   806 	EAP_FUNC_IMPORT eap_status_e set_encryption_key(
       
   807 		const void * const encryption_IV,
       
   808 		const u32_t encryption_IV_length,
       
   809 		const void * const key,
       
   810 		const u32_t key_length);
       
   811 
       
   812 	/**
       
   813 	 * This function sets the mode to decryption, 
       
   814 	 * sets the initialization vector and the decryption key.
       
   815 	 */
       
   816 	EAP_FUNC_IMPORT eap_status_e set_decryption_key(
       
   817 		const void * const encryption_IV,
       
   818 		const u32_t encryption_IV_length,
       
   819 		const void * const key,
       
   820 		const u32_t key_length);
       
   821 
       
   822 	/**
       
   823 	 * This function encrypts continuous data bytes from data_in to data_out buffer. 
       
   824 	 * Note the length of the data must be aligned to block size of the cipher.
       
   825 	 */
       
   826 	EAP_FUNC_IMPORT eap_status_e encrypt_data(
       
   827 		const void * const data_in,
       
   828 		void * const data_out,
       
   829 		const u32_t data_length);
       
   830 
       
   831 	/**
       
   832 	 * This function encrypts continuous data bytes in data_in_out buffer. 
       
   833 	 * Note the length of the data must be aligned to block size of the cipher.
       
   834 	 */
       
   835 	EAP_FUNC_IMPORT eap_status_e encrypt_data(
       
   836 		void * const data_in_out,
       
   837 		const u32_t data_length);
       
   838 
       
   839 	/**
       
   840 	 * This function decrypts continuous data bytes from data_in to data_out buffer. 
       
   841 	 * Note the length of the data must be aligned to block size of the cipher.
       
   842 	 */
       
   843 	EAP_FUNC_IMPORT eap_status_e decrypt_data(
       
   844 		const void * const data_in,
       
   845 		void * const data_out,
       
   846 		const u32_t data_length);
       
   847 
       
   848 	/**
       
   849 	 * This function decrypts continuous data bytes in data_in_out buffer. 
       
   850 	 * Note the length of the data must be aligned to block size of the cipher.
       
   851 	 */
       
   852 	EAP_FUNC_IMPORT eap_status_e decrypt_data(
       
   853 		void * const data_in_out,
       
   854 		const u32_t data_length);
       
   855 
       
   856 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   857 
       
   858 	/**
       
   859 	 * The update_non_aligned() function updates the context of 
       
   860 	 * CBC-algorithm with data bytes. The direction (encryption/decryption) 
       
   861 	 * depends of the initialized context. NOTE the length of data feed in 
       
   862 	 * separate calls of update_non_aligned() does not need to be 
       
   863 	 * aligned to CBC-block size. Only the sum of whole data must be aligned to CBC-block size.
       
   864 	 * This version takes pointers to input and output buffers as a parameter. 
       
   865 	 * Those buffers must be fully separated. Some optimizations are used 
       
   866 	 * taking advance from separate buffers. 
       
   867 	 */
       
   868 	EAP_FUNC_IMPORT eap_status_e update_non_aligned(
       
   869 		const void * const msg_in,
       
   870 		void * const msg_out,
       
   871 		const u32_t msg_size);
       
   872 
       
   873 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   874 
       
   875 	/**
       
   876 	 * The update_non_aligned() function updates the context of 
       
   877 	 * CBC-algorithm with data bytes. The direction (encryption/decryption) 
       
   878 	 * depends of the initialized context. NOTE the length of data feed in 
       
   879 	 * separate calls of update_non_aligned() does not need to be 
       
   880 	 * aligned to CBC-block size. Only the sum of whole data must be aligned to CBC-block size.
       
   881 	 * This version takes one pointer to buffer. The buffer is used for input and output data. 
       
   882 	 */
       
   883 	EAP_FUNC_IMPORT eap_status_e update_non_aligned(
       
   884 		void * const msg_in_out,
       
   885 		const u32_t msg_size);
       
   886 
       
   887 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   888 
       
   889 	/**
       
   890 	 * The finalize_non_aligned() finalizes the CBC-context. 
       
   891 	 * The sum of length of feed data must be aligned to CBC-block size 
       
   892 	 * before this function is called.
       
   893 	 */
       
   894 	EAP_FUNC_IMPORT eap_status_e finalize_non_aligned();
       
   895 
       
   896 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   897 };
       
   898 
       
   899 
       
   900 //------------------------------------------------------------
       
   901 
       
   902 /// The crypto_aes_c class includes the state of 
       
   903 /// one instance of AES block encryption algorithm.
       
   904 class EAP_EXPORT crypto_aes_c
       
   905 : public abs_crypto_block_algorithm_c
       
   906 {
       
   907 
       
   908 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   909 private:
       
   910 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   911 
       
   912 	/// This is pointer to the tools class.
       
   913 	abs_eap_am_tools_c * const m_am_tools;
       
   914 
       
   915 	/// This indicates whether this object was generated successfully.
       
   916 	bool m_is_valid;
       
   917 
       
   918 	/// Context is stored to this variable.
       
   919 	/// This hides the whole implementation.
       
   920 	/// This includes the context of AES-block cipher.
       
   921 	/// This depends on the crypto library.
       
   922 	eap_variable_data_c m_aes_context;
       
   923 
       
   924 	/// This is the used block size.
       
   925 	u32_t m_block_size;
       
   926 
       
   927 	/// This is set true when encryption is the current mode.
       
   928 	/// Decryption initializes this false.
       
   929 	bool m_encrypt;
       
   930 
       
   931 
       
   932 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   933 public:
       
   934 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   935 
       
   936 	/**
       
   937 	 * Destructor resets the used internal buffers.
       
   938 	 */
       
   939 	EAP_FUNC_IMPORT virtual ~crypto_aes_c();
       
   940 
       
   941 	/**
       
   942 	 * Constructor initializes the used internal buffers.
       
   943 	 */
       
   944 	EAP_FUNC_IMPORT crypto_aes_c(abs_eap_am_tools_c * const tools);
       
   945 
       
   946 	EAP_FUNC_IMPORT bool get_encrypts();
       
   947 
       
   948 	/**
       
   949 	 * The set_is_valid() function sets the state of the
       
   950 	 * crypto_aes_c object valid. The crypto_aes_c object 
       
   951 	 * calls this function after it is initialized.
       
   952 	 */
       
   953 	EAP_FUNC_IMPORT void set_is_valid();
       
   954 
       
   955 	/**
       
   956 	 * The get_is_valid() function returns the status of the crypto_aes_c object.
       
   957 	 * True indicates the object is initialized.
       
   958 	 */
       
   959 	EAP_FUNC_IMPORT bool get_is_valid();
       
   960 
       
   961 	/**
       
   962 	 * This function returns the length of AES key in bytes.
       
   963 	 */
       
   964 	EAP_FUNC_IMPORT u32_t get_key_length();
       
   965 
       
   966 	/**
       
   967 	 * This function returns the length of AES block size in bytes.
       
   968 	 */
       
   969 	EAP_FUNC_IMPORT u32_t get_block_size();
       
   970 
       
   971 
       
   972 	/**
       
   973 	 * This function sets the mode to encryption, 
       
   974 	 * sets the initialization vector and the encryption key.
       
   975 	 */
       
   976 	EAP_FUNC_IMPORT eap_status_e set_encryption_key(
       
   977 		const void * const key,
       
   978 		const u32_t key_length);
       
   979 
       
   980 	/**
       
   981 	 * This function sets the mode to decryption, 
       
   982 	 * sets the initialization vector and the decryption key.
       
   983 	 */
       
   984 	EAP_FUNC_IMPORT eap_status_e set_decryption_key(
       
   985 		const void * const key,
       
   986 		const u32_t key_length);
       
   987 
       
   988 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
   989 
       
   990 	/**
       
   991 	 * This function encrypts continuous data bytes from data_in to data_out buffer. 
       
   992 	 * Note the length of the data must be aligned to block size of the cipher.
       
   993 	 */
       
   994 	EAP_FUNC_IMPORT eap_status_e encrypt_block(
       
   995 		const void * const data_in,
       
   996 		void * const data_out,
       
   997 		const u32_t data_length);
       
   998 
       
   999 	/**
       
  1000 	 * This function decrypts continuous data bytes from data_in to data_out buffer. 
       
  1001 	 * Note the length of the data must be aligned to block size of the cipher.
       
  1002 	 */
       
  1003 	EAP_FUNC_IMPORT eap_status_e decrypt_block(
       
  1004 		const void * const data_in,
       
  1005 		void * const data_out,
       
  1006 		const u32_t data_length);
       
  1007 
       
  1008 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  1009 };
       
  1010 
       
  1011 
       
  1012 //------------------------------------------------------------
       
  1013 
       
  1014 /// The crypto_3des_ede_c class includes the state of 
       
  1015 /// one instance of 3DES-EDE block encryption algorithm.
       
  1016 class EAP_EXPORT crypto_3des_ede_c
       
  1017 : public abs_crypto_block_algorithm_c
       
  1018 {
       
  1019 
       
  1020 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  1021 private:
       
  1022 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  1023 
       
  1024 	/// This is pointer to the tools class.
       
  1025 	abs_eap_am_tools_c * const m_am_tools;
       
  1026 
       
  1027 	/// This indicates whether this object was generated successfully.
       
  1028 	bool m_is_valid;
       
  1029 
       
  1030 	/// Context is stored to this variable.
       
  1031 	/// This hides the whole implementation.
       
  1032 	/// This includes the context of 3DES-EDE-block cipher.
       
  1033 	/// This depends on the crypto library.
       
  1034 	eap_variable_data_c m_context;
       
  1035 
       
  1036 	/// This is the used block size.
       
  1037 	u32_t m_block_size;
       
  1038 
       
  1039 	/// This is set true when encryption is the current mode.
       
  1040 	/// Decryption initializes this false.
       
  1041 	bool m_encrypt;
       
  1042 
       
  1043 
       
  1044 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  1045 public:
       
  1046 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  1047 
       
  1048 	/**
       
  1049 	 * Destructor resets the used internal buffers.
       
  1050 	 */
       
  1051 	EAP_FUNC_IMPORT virtual ~crypto_3des_ede_c();
       
  1052 
       
  1053 	/**
       
  1054 	 * Constructor initializes the used internal buffers.
       
  1055 	 */
       
  1056 	EAP_FUNC_IMPORT crypto_3des_ede_c(abs_eap_am_tools_c * const tools);
       
  1057 
       
  1058 	EAP_FUNC_IMPORT bool get_encrypts();
       
  1059 
       
  1060 	/**
       
  1061 	 * The set_is_valid() function sets the state of the
       
  1062 	 * crypto_3des_ede_c object valid. The crypto_3des_ede_c object 
       
  1063 	 * calls this function after it is initialized.
       
  1064 	 */
       
  1065 	EAP_FUNC_IMPORT void set_is_valid();
       
  1066 
       
  1067 	/**
       
  1068 	 * The get_is_valid() function returns the status of the crypto_3des_ede_c object.
       
  1069 	 * True indicates the object is initialized.
       
  1070 	 */
       
  1071 	EAP_FUNC_IMPORT bool get_is_valid();
       
  1072 
       
  1073 	/**
       
  1074 	 * This function returns the length of 3DES-EDE key in bytes.
       
  1075 	 */
       
  1076 	EAP_FUNC_IMPORT u32_t get_key_length();
       
  1077 
       
  1078 	/**
       
  1079 	 * This function returns the length of 3DES-EDE block size in bytes.
       
  1080 	 */
       
  1081 	EAP_FUNC_IMPORT u32_t get_block_size();
       
  1082 
       
  1083 
       
  1084 	/**
       
  1085 	 * This function sets the mode to encryption, 
       
  1086 	 * sets the initialization vector and the encryption key.
       
  1087 	 */
       
  1088 	EAP_FUNC_IMPORT eap_status_e set_encryption_key(
       
  1089 		const void * const key,
       
  1090 		const u32_t key_length);
       
  1091 
       
  1092 	/**
       
  1093 	 * This function sets the mode to decryption, 
       
  1094 	 * sets the initialization vector and the decryption key.
       
  1095 	 */
       
  1096 	EAP_FUNC_IMPORT eap_status_e set_decryption_key(
       
  1097 		const void * const key,
       
  1098 		const u32_t key_length);
       
  1099 
       
  1100 	/**
       
  1101 	 * This function encrypts continuous data bytes from data_in to data_out buffer. 
       
  1102 	 * Note the length of the data must be aligned to block size of the cipher.
       
  1103 	 */
       
  1104 	EAP_FUNC_IMPORT eap_status_e encrypt_block(
       
  1105 		const void * const data_in,
       
  1106 		void * const data_out,
       
  1107 		const u32_t data_length);
       
  1108 
       
  1109 	/**
       
  1110 	 * This function decrypts continuous data bytes from data_in to data_out buffer. 
       
  1111 	 * Note the length of the data must be aligned to block size of the cipher.
       
  1112 	 */
       
  1113 	EAP_FUNC_IMPORT eap_status_e decrypt_block(
       
  1114 		const void * const data_in,
       
  1115 		void * const data_out,
       
  1116 		const u32_t data_length);
       
  1117 
       
  1118 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  1119 };
       
  1120 
       
  1121 
       
  1122 //------------------------------------------------------------
       
  1123 
       
  1124 
       
  1125 const u8_t EAP_CRYPTO_AES_WRAP_DEFAULT_INITIAL_IV[] = {
       
  1126 	0xA6, 0xA6, 0xA6, 0xA6, 0xA6, 0xA6, 0xA6, 0xA6,
       
  1127 	};
       
  1128 
       
  1129 const u64_t EAP_CRYPTO_AES_WRAP_BLOCK_SIZE = sizeof(u64_t);
       
  1130 
       
  1131 
       
  1132 /// The crypto_aes_wrap_c class describes interface of block encryption algorithm.
       
  1133 class EAP_EXPORT crypto_aes_wrap_c
       
  1134 {
       
  1135 
       
  1136 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  1137 private:
       
  1138 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  1139 
       
  1140 	/// This is pointer to the tools class.
       
  1141 	abs_eap_am_tools_c * const m_am_tools;
       
  1142 
       
  1143 	/// This is the AES the block encryption algorithm.
       
  1144 	crypto_aes_c m_aes;
       
  1145 
       
  1146 	eap_variable_data_c m_key;
       
  1147 
       
  1148 	/// This is set true when encryption is the current mode.
       
  1149 	/// Decryption initializes this false.
       
  1150 	bool m_encrypt;
       
  1151 
       
  1152 	/// This indicates whether this object was generated successfully.
       
  1153 	bool m_is_valid;
       
  1154 
       
  1155 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  1156 public:
       
  1157 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  1158 
       
  1159 	EAP_FUNC_IMPORT virtual ~crypto_aes_wrap_c();
       
  1160 
       
  1161 	/**
       
  1162 	 * Constructor initializes the used internal buffers.
       
  1163 	 */
       
  1164 	EAP_FUNC_IMPORT crypto_aes_wrap_c(abs_eap_am_tools_c * const tools);
       
  1165 
       
  1166 	/**
       
  1167 	 * The set_is_valid() function sets the state of the
       
  1168 	 * crypto_aes_wrap_c object valid. The crypto_aes_wrap_c object 
       
  1169 	 * calls this function after it is initialized.
       
  1170 	 */
       
  1171 	EAP_FUNC_IMPORT void set_is_valid();
       
  1172 
       
  1173 	/**
       
  1174 	 * The get_is_valid() function returns the status of the crypto_aes_wrap_c object.
       
  1175 	 * True indicates the object is initialized.
       
  1176 	 */
       
  1177 	EAP_FUNC_IMPORT bool get_is_valid();
       
  1178 
       
  1179 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  1180 
       
  1181 	/**
       
  1182 	 * The get_encrypts() function returns true when encryption is initialized.
       
  1183 	 * It returns false when decryption is initialized.
       
  1184 	 */
       
  1185 	EAP_FUNC_IMPORT bool get_encrypts();
       
  1186 
       
  1187 	/**
       
  1188 	 * This function returns the length of key in bytes.
       
  1189 	 */
       
  1190 	EAP_FUNC_IMPORT u32_t get_key_length();
       
  1191 
       
  1192 	/**
       
  1193 	 * This function returns the length of block size in bytes.
       
  1194 	 */
       
  1195 	EAP_FUNC_IMPORT u32_t get_block_size();
       
  1196 
       
  1197 	/**
       
  1198 	 * This function sets the mode to encryption, 
       
  1199 	 * sets the initialization vector and the encryption key.
       
  1200 	 */
       
  1201 	EAP_FUNC_IMPORT eap_status_e set_encryption_key(
       
  1202 		const void * const key,
       
  1203 		const u32_t key_length);
       
  1204 
       
  1205 	/**
       
  1206 	 * This function sets the mode to decryption, 
       
  1207 	 * sets the initialization vector and the decryption key.
       
  1208 	 */
       
  1209 	EAP_FUNC_IMPORT eap_status_e set_decryption_key(
       
  1210 		const void * const key,
       
  1211 		const u32_t key_length);
       
  1212 
       
  1213 	/**
       
  1214 	 * This function adds buffer_length padding bytes to buffer.
       
  1215 	 */
       
  1216 	EAP_FUNC_IMPORT eap_status_e add_padding_bytes(
       
  1217 		void * const buffer,
       
  1218 		const u32_t buffer_length);
       
  1219 
       
  1220 	/**
       
  1221 	 * This function encrypts continuous data bytes from data_in to data_out buffer. 
       
  1222 	 * Note the length of the data must be aligned to block size of the cipher.
       
  1223 	 */
       
  1224 	EAP_FUNC_IMPORT eap_status_e encrypt_block(
       
  1225 		const void * const data_in,
       
  1226 		const u32_t data_in_length,
       
  1227 		void * const data_out,
       
  1228 		const u32_t data_out_length);
       
  1229 
       
  1230 	/**
       
  1231 	 * This function decrypts continuous data bytes from data_in to data_out buffer. 
       
  1232 	 * Note the length of the data must be aligned to block size of the cipher.
       
  1233 	 */
       
  1234 	EAP_FUNC_IMPORT eap_status_e decrypt_block(
       
  1235 		const void * const data_in,
       
  1236 		const u32_t data_in_length,
       
  1237 		void * const data_out,
       
  1238 		const u32_t data_out_length);
       
  1239 
       
  1240 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  1241 };
       
  1242 
       
  1243 
       
  1244 
       
  1245 //------------------------------------------------------------
       
  1246 
       
  1247 /// The crypto_random_c class includes the state of 
       
  1248 /// one instance of random generator.
       
  1249 class EAP_EXPORT crypto_random_c
       
  1250 {
       
  1251 
       
  1252 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  1253 private:
       
  1254 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  1255 
       
  1256 	/// This is pointer to the tools class.
       
  1257 	abs_eap_am_tools_c * const m_am_tools;
       
  1258 
       
  1259 	/// This indicates whether this object was generated successfully.
       
  1260 	bool m_is_valid;
       
  1261 
       
  1262 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  1263 public:
       
  1264 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  1265 
       
  1266 	/**
       
  1267 	 * Destructor does nothing special.
       
  1268 	 */
       
  1269 	EAP_FUNC_IMPORT virtual ~crypto_random_c();
       
  1270 
       
  1271 	/**
       
  1272 	 * Constructor initializes the object.
       
  1273 	 */
       
  1274 	EAP_FUNC_IMPORT crypto_random_c(abs_eap_am_tools_c * const tools);
       
  1275 
       
  1276 	/**
       
  1277 	 * The set_is_valid() function sets the state of the crypto_random_c object valid. 
       
  1278 	 * The crypto_random_c object calls this function after it is initialized.
       
  1279 	 */
       
  1280 	EAP_FUNC_IMPORT void set_is_valid();
       
  1281 
       
  1282 	/**
       
  1283 	 * The get_is_valid() function returns the status of the crypto_random_c object. 
       
  1284 	 * True indicates the object is initialized.
       
  1285 	 */
       
  1286 	EAP_FUNC_IMPORT bool get_is_valid();
       
  1287 
       
  1288 	/**
       
  1289 	 * This function copies count random bytes to buffer.
       
  1290 	 */
       
  1291 	EAP_FUNC_IMPORT eap_status_e get_rand_bytes(
       
  1292 		void * const buffer,
       
  1293 		const u32_t count);
       
  1294 
       
  1295 	/**
       
  1296 	 * This function copies count random bytes to buffer.
       
  1297 	 */
       
  1298 	EAP_FUNC_IMPORT eap_status_e get_rand_bytes(
       
  1299 		eap_variable_data_c * const buffer,
       
  1300 		const u32_t count);
       
  1301 
       
  1302 	/**
       
  1303 	 * This function creates random integer value between minimum and maximum inclusively.
       
  1304 	 */
       
  1305 	EAP_FUNC_IMPORT u32_t get_rand_integer(
       
  1306 		const u32_t minimum,
       
  1307 		const u32_t maximum);
       
  1308 
       
  1309 	/**
       
  1310 	 * This function seeds the random generator with count bytes from buffer. 
       
  1311 	 * User could call this function as many times as is needed and at any time.
       
  1312 	 */
       
  1313 	EAP_FUNC_IMPORT eap_status_e add_rand_seed(
       
  1314 		const void * const buffer,
       
  1315 		const u32_t count);
       
  1316 
       
  1317 	/**
       
  1318 	 * This function seeds random generator with the hardware ticks. 
       
  1319 	 * User could call this function as many times as is needed and at any time.
       
  1320 	 */
       
  1321 	EAP_FUNC_IMPORT eap_status_e add_rand_seed_hw_ticks();
       
  1322 
       
  1323 };
       
  1324 
       
  1325 
       
  1326 //------------------------------------------------------------
       
  1327 
       
  1328 /// The crypto_sha_256_c class includes the state of 
       
  1329 /// one instance of SHA-256 algorithm.
       
  1330 class EAP_EXPORT crypto_sha_256_c
       
  1331 : public abs_crypto_hash_algorithm_c
       
  1332 {
       
  1333 
       
  1334 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  1335 private:
       
  1336 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  1337 
       
  1338 	/// This is pointer to the tools class.
       
  1339 	abs_eap_am_tools_c * const m_am_tools;
       
  1340 
       
  1341 	/// Context is stored to this variable.
       
  1342 	/// This hides the whole implementation.
       
  1343 	/// includes the context of the SHA-256 algorithm. 
       
  1344 	/// This depends on the crypto library.
       
  1345 	eap_variable_data_c m_sha_256_context;
       
  1346 
       
  1347 	/// This indicates whether this object was generated successfully.
       
  1348 	bool m_is_valid;
       
  1349 
       
  1350 	/**
       
  1351 	 * The set_is_invalid() function sets the state of the crypto_sha_256_c object invalid. 
       
  1352 	 * The crypto_sha_256_c object calls this function after it is initialized.
       
  1353 	 */
       
  1354 	EAP_FUNC_IMPORT void set_is_invalid();
       
  1355 
       
  1356 	/**
       
  1357 	 * The set_is_valid() function sets the state of the crypto_sha_256_c object valid. 
       
  1358 	 * The crypto_sha_256_c object calls this function after it is initialized.
       
  1359 	 */
       
  1360 	EAP_FUNC_IMPORT void set_is_valid();
       
  1361 
       
  1362 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  1363 public:
       
  1364 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  1365 
       
  1366 	/**
       
  1367 	 * Destructor resets the used internal buffers.
       
  1368 	 */
       
  1369 	EAP_FUNC_IMPORT virtual ~crypto_sha_256_c();
       
  1370 
       
  1371 	/**
       
  1372 	 * Constructor initializes the used internal buffers.
       
  1373 	 */
       
  1374 	EAP_FUNC_IMPORT crypto_sha_256_c(abs_eap_am_tools_c * const tools);
       
  1375 
       
  1376 	/**
       
  1377 	 * This function copies the context from parameter sha_256_context to this object.
       
  1378 	 */
       
  1379 	EAP_FUNC_IMPORT eap_status_e copy_context(const eap_variable_data_c * const sha_256_context);
       
  1380 
       
  1381 	/**
       
  1382 	 * The get_is_valid() function returns the status of the crypto_sha_256_c object. 
       
  1383 	 * True indicates the object is initialized.
       
  1384 	 */
       
  1385 	EAP_FUNC_IMPORT bool get_is_valid();
       
  1386 
       
  1387 	/**
       
  1388 	 * This function returns the size of message digest of SHA-256-algorithm.
       
  1389 	 */
       
  1390 	EAP_FUNC_IMPORT u32_t get_digest_length();
       
  1391 
       
  1392 	/**
       
  1393 	 * This function returns the block size of SHA-256-algorithm.
       
  1394 	 */
       
  1395 	EAP_FUNC_IMPORT u32_t get_block_size();
       
  1396 
       
  1397 	/**
       
  1398 	 * This function initializes the context of SHA-256-algorithm.
       
  1399 	 */
       
  1400 	EAP_FUNC_IMPORT eap_status_e hash_init();
       
  1401 
       
  1402 	/**
       
  1403 	 * This function updates the context of SHA-256-algorithm with data.
       
  1404 	 */
       
  1405 	EAP_FUNC_IMPORT eap_status_e hash_update(
       
  1406 		const void * const data,
       
  1407 		const u32_t data_length);
       
  1408 
       
  1409 	/**
       
  1410 	 * This function writes the message digest to buffer.
       
  1411 	 * @param Length is set if md_length_or_null is non-NULL.
       
  1412 	 */
       
  1413 	EAP_FUNC_IMPORT eap_status_e hash_final(
       
  1414 		void * const message_digest,
       
  1415 		u32_t *md_length_or_null);
       
  1416 
       
  1417 	/**
       
  1418 	 * This function cleans up the SHA-256 context.
       
  1419 	 */
       
  1420 	EAP_FUNC_IMPORT eap_status_e hash_cleanup();
       
  1421 
       
  1422 	/**
       
  1423 	 * This function returns a copy of the context of SHA-256-algorithm.
       
  1424 	 * Caller must free the copy.
       
  1425 	 */
       
  1426 	EAP_FUNC_IMPORT abs_crypto_hash_algorithm_c * copy();
       
  1427 };
       
  1428 
       
  1429 
       
  1430 //------------------------------------------------------------
       
  1431 
       
  1432 /// The crypto_sha1_c class includes the state of 
       
  1433 /// one instance of SHA1 algorithm.
       
  1434 class EAP_EXPORT crypto_sha1_c
       
  1435 : public abs_crypto_hash_algorithm_c
       
  1436 {
       
  1437 
       
  1438 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  1439 private:
       
  1440 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  1441 
       
  1442 	/// This is pointer to the tools class.
       
  1443 	abs_eap_am_tools_c * const m_am_tools;
       
  1444 
       
  1445 	/// Context is stored to this variable.
       
  1446 	/// This hides the whole implementation.
       
  1447 	/// includes the context of the SHA1 algorithm. 
       
  1448 	/// This depends on the crypto library.
       
  1449 	eap_variable_data_c m_sha1_context;
       
  1450 
       
  1451 	/// This indicates whether this object was generated successfully.
       
  1452 	bool m_is_valid;
       
  1453 
       
  1454 	/**
       
  1455 	 * The set_is_invalid() function sets the state of the crypto_sha1_c object invalid. 
       
  1456 	 * The crypto_sha1_c object calls this function after it is initialized.
       
  1457 	 */
       
  1458 	EAP_FUNC_IMPORT void set_is_invalid();
       
  1459 
       
  1460 	/**
       
  1461 	 * The set_is_valid() function sets the state of the crypto_sha1_c object valid. 
       
  1462 	 * The crypto_sha1_c object calls this function after it is initialized.
       
  1463 	 */
       
  1464 	EAP_FUNC_IMPORT void set_is_valid();
       
  1465 
       
  1466 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  1467 public:
       
  1468 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  1469 
       
  1470 	/**
       
  1471 	 * Destructor resets the used internal buffers.
       
  1472 	 */
       
  1473 	EAP_FUNC_IMPORT virtual ~crypto_sha1_c();
       
  1474 
       
  1475 	/**
       
  1476 	 * Constructor initializes the used internal buffers.
       
  1477 	 */
       
  1478 	EAP_FUNC_IMPORT crypto_sha1_c(abs_eap_am_tools_c * const tools);
       
  1479 
       
  1480 	/**
       
  1481 	 * This function copies the context from parameter sha1_context to this object.
       
  1482 	 */
       
  1483 	EAP_FUNC_IMPORT eap_status_e copy_context(const eap_variable_data_c * const sha1_context);
       
  1484 
       
  1485 	/**
       
  1486 	 * The get_is_valid() function returns the status of the crypto_sha1_c object. 
       
  1487 	 * True indicates the object is initialized.
       
  1488 	 */
       
  1489 	EAP_FUNC_IMPORT bool get_is_valid();
       
  1490 
       
  1491 	/**
       
  1492 	 * This function returns the size of message digest of SHA1-algorithm.
       
  1493 	 */
       
  1494 	EAP_FUNC_IMPORT u32_t get_digest_length();
       
  1495 
       
  1496 	/**
       
  1497 	 * This function returns the block size of SHA1-algorithm.
       
  1498 	 */
       
  1499 	EAP_FUNC_IMPORT u32_t get_block_size();
       
  1500 
       
  1501 	/**
       
  1502 	 * This function initializes the context of SHA1-algorithm.
       
  1503 	 */
       
  1504 	EAP_FUNC_IMPORT eap_status_e hash_init();
       
  1505 
       
  1506 	/**
       
  1507 	 * This function updates the context of SHA1-algorithm with data.
       
  1508 	 */
       
  1509 	EAP_FUNC_IMPORT eap_status_e hash_update(
       
  1510 		const void * const data,
       
  1511 		const u32_t data_length);
       
  1512 
       
  1513 	/**
       
  1514 	 * This function writes the message digest to buffer.
       
  1515 	 * @param Length is set if md_length_or_null is non-NULL.
       
  1516 	 */
       
  1517 	EAP_FUNC_IMPORT eap_status_e hash_final(
       
  1518 		void * const message_digest,
       
  1519 		u32_t *md_length_or_null);
       
  1520 
       
  1521 	/**
       
  1522 	 * This function cleans up the SHA1 context.
       
  1523 	 */
       
  1524 	EAP_FUNC_IMPORT eap_status_e hash_cleanup();
       
  1525 
       
  1526 	/**
       
  1527 	 * This function returns a copy of the context of SHA1-algorithm.
       
  1528 	 * Caller must free the copy.
       
  1529 	 */
       
  1530 	EAP_FUNC_IMPORT abs_crypto_hash_algorithm_c * copy();
       
  1531 };
       
  1532 
       
  1533 
       
  1534 //------------------------------------------------------------
       
  1535 
       
  1536 /// The crypto_ephemeral_diffie_hellman_c class includes
       
  1537 /// the state of one instance of ephemeral Diffie-Hellman key exchange algorithm.
       
  1538 class EAP_EXPORT crypto_ephemeral_diffie_hellman_c
       
  1539 {
       
  1540 
       
  1541 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  1542 private:
       
  1543 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  1544 
       
  1545 	/// This is pointer to the tools class.
       
  1546 	abs_eap_am_tools_c * const m_am_tools;
       
  1547 
       
  1548 	/// This indicates whether this object was generated successfully.
       
  1549 	bool m_is_valid;
       
  1550 
       
  1551 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  1552 public:
       
  1553 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  1554 
       
  1555 	/**
       
  1556 	 * Destructor resets the used internal buffers.
       
  1557 	 */
       
  1558 	EAP_FUNC_IMPORT virtual ~crypto_ephemeral_diffie_hellman_c();
       
  1559 
       
  1560 	/**
       
  1561 	 * Constructor initializes the used internal buffers.
       
  1562 	 */
       
  1563 	EAP_FUNC_IMPORT crypto_ephemeral_diffie_hellman_c(abs_eap_am_tools_c * const tools);
       
  1564 
       
  1565 	/**
       
  1566 	 * The set_is_valid() function sets the state of the crypto_ephemeral_diffie_hellman_c
       
  1567 	 * object valid. The crypto_ephemeral_diffie_hellman_c object calls this function
       
  1568 	 * after it is initialized.
       
  1569 	 */
       
  1570 	EAP_FUNC_IMPORT void set_is_valid();
       
  1571 
       
  1572 	/**
       
  1573 	 * The get_is_valid() function returns the status of the crypto_ephemeral_diffie_hellman_c object.
       
  1574 	 * True indicates the object is initialized.
       
  1575 	 */
       
  1576 	EAP_FUNC_IMPORT bool get_is_valid();
       
  1577 
       
  1578 	/**
       
  1579 	 * This function creates the private and public keys using the prime and generator.
       
  1580 	 * Returns context in dh_context. It must be given to generate_g_power_to_xy and
       
  1581 	 * dh_cleanup.
       
  1582 	 */
       
  1583 	EAP_FUNC_IMPORT eap_status_e generate_diffie_hellman_keys(
       
  1584 		eap_variable_data_c * const dh_context,
       
  1585 		eap_variable_data_c * const own_public_dh_key,
       
  1586 		const void * const prime,
       
  1587 		const u32_t prime_length,
       
  1588 		const void * const group_generator,
       
  1589 		const u32_t group_generator_length);
       
  1590 
       
  1591 	/**
       
  1592 	 * This function creates the shared Diffie-Hellman key using own private key,
       
  1593 	 * peer public key, prime and group generator.
       
  1594 	 */
       
  1595 	EAP_FUNC_IMPORT eap_status_e generate_g_power_to_xy(
       
  1596 		const eap_variable_data_c * const dh_context,
       
  1597 		const eap_variable_data_c * const peer_public_dh_key,
       
  1598 		eap_variable_data_c * const shared_dh_key,
       
  1599 		const void * const prime,
       
  1600 		const u32_t prime_length,
       
  1601 		const void * const group_generator,
       
  1602 		const u32_t group_generator_length);
       
  1603 
       
  1604 	EAP_FUNC_IMPORT eap_status_e dh_cleanup(
       
  1605 		const eap_variable_data_c * const dh_context);
       
  1606 
       
  1607 };
       
  1608 
       
  1609 //------------------------------------------------------------
       
  1610 
       
  1611 /// The crypto_sha1_c class includes the state of 
       
  1612 /// one instance of MD5 algorithm.
       
  1613 class EAP_EXPORT crypto_md5_c
       
  1614 : public abs_crypto_hash_algorithm_c
       
  1615 {
       
  1616 
       
  1617 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  1618 private:
       
  1619 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  1620 
       
  1621 	/// This is pointer to the tools class.
       
  1622 	abs_eap_am_tools_c * const m_am_tools;
       
  1623 
       
  1624 	/// Context is stored to this variable.
       
  1625 	/// This hides the whole implementation.
       
  1626 	/// includes the context of the MD5 algorithm. 
       
  1627 	/// This depends on the crypto library.
       
  1628 	eap_variable_data_c m_md5_context;
       
  1629 
       
  1630 	/// This indicates whether this object was generated successfully.
       
  1631 	bool m_is_valid;
       
  1632 
       
  1633 	/**
       
  1634 	 * The set_is_invalid() function sets the state of the crypto_md5_c object invalid. 
       
  1635 	 * The crypto_md5_c object calls this function after it is initialized.
       
  1636 	 */
       
  1637 	EAP_FUNC_IMPORT void set_is_invalid();
       
  1638 
       
  1639 	/**
       
  1640 	 * The set_is_valid() function sets the state of the crypto_md5_c object valid. 
       
  1641 	 * The crypto_md5_c object calls this function after it is initialized.
       
  1642 	 */
       
  1643 	EAP_FUNC_IMPORT void set_is_valid();
       
  1644 
       
  1645 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  1646 public:
       
  1647 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  1648 
       
  1649 	/**
       
  1650 	 * Destructor resets the used internal buffers.
       
  1651 	 */
       
  1652 	EAP_FUNC_IMPORT virtual ~crypto_md5_c();
       
  1653 
       
  1654 	/**
       
  1655 	 * Constructor initializes the used internal buffers.
       
  1656 	 */
       
  1657 	EAP_FUNC_IMPORT crypto_md5_c(abs_eap_am_tools_c * const tools);
       
  1658 
       
  1659 	/**
       
  1660 	 * This function copies the context from parameter sha1_context to this object.
       
  1661 	 */
       
  1662 	EAP_FUNC_IMPORT eap_status_e copy_context(const eap_variable_data_c * const sha1_context);
       
  1663 
       
  1664 	/**
       
  1665 	 * The get_is_valid() function returns the status of the crypto_md5_c object. 
       
  1666 	 * True indicates the object is initialized.
       
  1667 	 */
       
  1668 	EAP_FUNC_IMPORT bool get_is_valid();
       
  1669 
       
  1670 	/**
       
  1671 	 * This function returns the size of message digest of MD5-algorithm.
       
  1672 	 */
       
  1673 	EAP_FUNC_IMPORT u32_t get_digest_length();
       
  1674 
       
  1675 	/**
       
  1676 	 * This function returns the block size of MD5-algorithm.
       
  1677 	 */
       
  1678 	EAP_FUNC_IMPORT u32_t get_block_size();
       
  1679 
       
  1680 	/**
       
  1681 	 * This function initializes the context of MD5-algorithm.
       
  1682 	 */
       
  1683 	EAP_FUNC_IMPORT eap_status_e hash_init();
       
  1684 
       
  1685 	/**
       
  1686 	 * This function updates the context of MD5-algorithm with data.
       
  1687 	 */
       
  1688 	EAP_FUNC_IMPORT eap_status_e hash_update(
       
  1689 		const void * const data,
       
  1690 		const u32_t data_length);
       
  1691 
       
  1692 	/**
       
  1693 	 * This function writes the message digest to buffer.
       
  1694 	 * @param Length is set if md_length_or_null is non-NULL.
       
  1695 	 */
       
  1696 	EAP_FUNC_IMPORT eap_status_e hash_final(
       
  1697 		void * const message_digest,
       
  1698 		u32_t *md_length_or_null);
       
  1699 
       
  1700 	/**
       
  1701 	 * This function cleans up the MD5 context.
       
  1702 	 */
       
  1703 	EAP_FUNC_IMPORT eap_status_e hash_cleanup();
       
  1704 
       
  1705 	/**
       
  1706 	 * This function returns a copy of the context of MD5-algorithm.
       
  1707 	 * Caller must free the copy.
       
  1708 	 */
       
  1709 	EAP_FUNC_IMPORT abs_crypto_hash_algorithm_c * copy();
       
  1710 };
       
  1711 
       
  1712 
       
  1713 //------------------------------------------------------------
       
  1714 
       
  1715 /// The crypto_sha1_c class includes the state of 
       
  1716 /// one instance of MD4 algorithm.
       
  1717 class EAP_EXPORT crypto_md4_c
       
  1718 : public abs_crypto_hash_algorithm_c
       
  1719 {
       
  1720 
       
  1721 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  1722 private:
       
  1723 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  1724 
       
  1725 	/// This is pointer to the tools class.
       
  1726 	abs_eap_am_tools_c * const m_am_tools;
       
  1727 
       
  1728 	/// Context is stored to this variable.
       
  1729 	/// This hides the whole implementation.
       
  1730 	/// includes the context of the MD4 algorithm. 
       
  1731 	/// This depends on the crypto library.
       
  1732 	eap_variable_data_c m_md4_context;
       
  1733 
       
  1734 	/// This indicates whether this object was generated successfully.
       
  1735 	bool m_is_valid;
       
  1736 
       
  1737 	/**
       
  1738 	 * The set_is_invalid() function sets the state of the crypto_md4_c object invalid. 
       
  1739 	 * The crypto_md4_c object calls this function after it is initialized.
       
  1740 	 */
       
  1741 	EAP_FUNC_IMPORT void set_is_invalid();
       
  1742 
       
  1743 	/**
       
  1744 	 * The set_is_valid() function sets the state of the crypto_md4_c object valid. 
       
  1745 	 * The crypto_md4_c object calls this function after it is initialized.
       
  1746 	 */
       
  1747 	EAP_FUNC_IMPORT void set_is_valid();
       
  1748 
       
  1749 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  1750 public:
       
  1751 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  1752 
       
  1753 	/**
       
  1754 	 * Destructor resets the used internal buffers.
       
  1755 	 */
       
  1756 	EAP_FUNC_IMPORT virtual ~crypto_md4_c();
       
  1757 
       
  1758 	/**
       
  1759 	 * Constructor initializes the used internal buffers.
       
  1760 	 */
       
  1761 	EAP_FUNC_IMPORT crypto_md4_c(abs_eap_am_tools_c * const tools);
       
  1762 
       
  1763 	/**
       
  1764 	 * This function copies the context from parameter sha1_context to this object.
       
  1765 	 */
       
  1766 	EAP_FUNC_IMPORT eap_status_e copy_context(const eap_variable_data_c * const sha1_context);
       
  1767 
       
  1768 	/**
       
  1769 	 * The get_is_valid() function returns the status of the crypto_md4_c object. 
       
  1770 	 * True indicates the object is initialized.
       
  1771 	 */
       
  1772 	EAP_FUNC_IMPORT bool get_is_valid();
       
  1773 
       
  1774 	/**
       
  1775 	 * This function returns the size of message digest of MD4-algorithm.
       
  1776 	 */
       
  1777 	EAP_FUNC_IMPORT u32_t get_digest_length();
       
  1778 
       
  1779 	/**
       
  1780 	 * This function returns the block size of MD4-algorithm.
       
  1781 	 */
       
  1782 	EAP_FUNC_IMPORT u32_t get_block_size();
       
  1783 
       
  1784 	/**
       
  1785 	 * This function initializes the context of MD4-algorithm.
       
  1786 	 */
       
  1787 	EAP_FUNC_IMPORT eap_status_e hash_init();
       
  1788 
       
  1789 	/**
       
  1790 	 * This function updates the context of MD4-algorithm with data.
       
  1791 	 */
       
  1792 	EAP_FUNC_IMPORT eap_status_e hash_update(
       
  1793 		const void * const data,
       
  1794 		const u32_t data_length);
       
  1795 
       
  1796 	/**
       
  1797 	 * This function writes the message digest to buffer.
       
  1798 	 * @param Length is set if md_length_or_null is non-NULL.
       
  1799 	 */
       
  1800 	EAP_FUNC_IMPORT eap_status_e hash_final(
       
  1801 		void * const message_digest,
       
  1802 		u32_t *md_length_or_null);
       
  1803 
       
  1804 	/**
       
  1805 	 * This function cleans up the MD4 context.
       
  1806 	 */
       
  1807 	EAP_FUNC_IMPORT eap_status_e hash_cleanup();
       
  1808 
       
  1809 	/**
       
  1810 	 * This function returns a copy of the context of MD4-algorithm.
       
  1811 	 * Caller must free the copy.
       
  1812 	 */
       
  1813 	EAP_FUNC_IMPORT abs_crypto_hash_algorithm_c * copy();
       
  1814 };
       
  1815 
       
  1816 
       
  1817 //------------------------------------------------------------
       
  1818 /// The crypto_rc4_c class includes the state of 
       
  1819 /// one instance of RC4 algorithm.
       
  1820 class EAP_EXPORT crypto_rc4_c
       
  1821 : public abs_crypto_stream_algorithm_c
       
  1822 {
       
  1823 
       
  1824 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  1825 private:
       
  1826 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  1827 
       
  1828 	/// This is pointer to the tools class.
       
  1829 	abs_eap_am_tools_c * const m_am_tools;
       
  1830 
       
  1831 	/// Context is stored to this variable.
       
  1832 	/// This hides the whole implementation.
       
  1833 	/// includes the context of the RC4 algorithm. 
       
  1834 	/// This depends on the crypto library.
       
  1835 	eap_variable_data_c m_rc4_context;
       
  1836 
       
  1837 	/// This indicates whether this object was generated successfully.
       
  1838 	bool m_is_valid;
       
  1839 
       
  1840 	/**
       
  1841 	 * The set_is_invalid() function sets the state of the crypto_rc4_c object invalid. 
       
  1842 	 * The crypto_rc4_c object calls this function after it is initialized.
       
  1843 	 */
       
  1844 	EAP_FUNC_IMPORT void set_is_invalid();
       
  1845 
       
  1846 	/**
       
  1847 	 * The set_is_valid() function sets the state of the crypto_rc4_c object valid. 
       
  1848 	 * The crypto_rc4_c object calls this function after it is initialized.
       
  1849 	 */
       
  1850 	EAP_FUNC_IMPORT void set_is_valid();
       
  1851 
       
  1852 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  1853 public:
       
  1854 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  1855 
       
  1856 	/**
       
  1857 	 * Destructor resets the used internal buffers.
       
  1858 	 */
       
  1859 	EAP_FUNC_IMPORT virtual ~crypto_rc4_c();
       
  1860 
       
  1861 	/**
       
  1862 	 * Constructor initializes the used internal buffers.
       
  1863 	 */
       
  1864 	EAP_FUNC_IMPORT crypto_rc4_c(abs_eap_am_tools_c * const tools);
       
  1865 
       
  1866 	/**
       
  1867 	 * The get_is_valid() function returns the status of the crypto_rc4_c object. 
       
  1868 	 * True indicates the object is initialized.
       
  1869 	 */
       
  1870 	EAP_FUNC_IMPORT bool get_is_valid();
       
  1871 
       
  1872 	/**
       
  1873 	 * This function sets the RC4 key.
       
  1874 	 */
       
  1875 	EAP_FUNC_IMPORT eap_status_e set_key(const eap_variable_data_c * const key);
       
  1876 
       
  1877 	/**
       
  1878 	 * This function discards desired count of RC4 stream.
       
  1879 	 */
       
  1880 	EAP_FUNC_IMPORT eap_status_e discard_stream(const u32_t count_of_discarded_octets);
       
  1881 
       
  1882 	/**
       
  1883 	 * This function encrypts continuous data bytes in data_in_out buffer. 
       
  1884 	 */
       
  1885 	EAP_FUNC_IMPORT eap_status_e encrypt_data(
       
  1886 		void * const data_in_out,
       
  1887 		const u32_t data_length);
       
  1888 
       
  1889 	/**
       
  1890 	 * This function does RC4 encryption.
       
  1891 	 */
       
  1892 	EAP_FUNC_IMPORT eap_status_e encrypt_data(
       
  1893 		const void * const data_in, 
       
  1894 		void * const data_out,
       
  1895 		const u32_t data_length);
       
  1896 
       
  1897 	/**
       
  1898 	 * This function decrypts continuous data bytes in data_in_out buffer. 
       
  1899 	 */
       
  1900 	EAP_FUNC_IMPORT eap_status_e decrypt_data(
       
  1901 		void * const data_in_out,
       
  1902 		const u32_t data_length);
       
  1903 
       
  1904 	/**
       
  1905 	 * This function does RC4 decryption.
       
  1906 	 */
       
  1907 	EAP_FUNC_IMPORT eap_status_e decrypt_data(
       
  1908 		const void * const data_in, 
       
  1909 		void * const data_out,
       
  1910 		const u32_t data_length);
       
  1911 
       
  1912 };
       
  1913 
       
  1914 //------------------------------------------------------------
       
  1915 
       
  1916 /// The crypto_tls_base_prf_c class includes the state of 
       
  1917 /// one instance of TLS-PRF base algorithms.
       
  1918 class EAP_EXPORT crypto_tls_base_prf_c
       
  1919 {
       
  1920 
       
  1921 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  1922 private:
       
  1923 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  1924 
       
  1925 	/// This is pointer to the tools class.
       
  1926 	abs_eap_am_tools_c * const m_am_tools;
       
  1927 
       
  1928 	/// This indicates whether this object was generated successfully.
       
  1929 	bool m_is_valid;
       
  1930 
       
  1931 	/**
       
  1932 	 * The set_is_invalid() function sets the state of the crypto_tls_base_prf_c object invalid. 
       
  1933 	 * The crypto_tls_base_prf_c object calls this function after it is initialized.
       
  1934 	 */
       
  1935 	EAP_FUNC_IMPORT void set_is_invalid();
       
  1936 
       
  1937 	/**
       
  1938 	 * The set_is_valid() function sets the state of the crypto_tls_base_prf_c object valid. 
       
  1939 	 * The crypto_tls_base_prf_c object calls this function after it is initialized.
       
  1940 	 */
       
  1941 	EAP_FUNC_IMPORT void set_is_valid();
       
  1942 
       
  1943 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  1944 public:
       
  1945 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  1946 
       
  1947 	/**
       
  1948 	 * Destructor resets the used internal buffers.
       
  1949 	 */
       
  1950 	EAP_FUNC_IMPORT virtual ~crypto_tls_base_prf_c();
       
  1951 
       
  1952 	/**
       
  1953 	 * Constructor initializes the used internal buffers.
       
  1954 	 */
       
  1955 	EAP_FUNC_IMPORT crypto_tls_base_prf_c(abs_eap_am_tools_c * const tools);
       
  1956 
       
  1957 	/**
       
  1958 	 * The get_is_valid() function returns the status of the crypto_tls_base_prf_c object. 
       
  1959 	 * True indicates the object is initialized.
       
  1960 	 */
       
  1961 	EAP_FUNC_IMPORT bool get_is_valid();
       
  1962 
       
  1963 	EAP_FUNC_IMPORT eap_status_e tls_prf_A_value(
       
  1964 		abs_crypto_hmac_algorithm_c * const hash,
       
  1965 		eap_variable_data_c * const key,
       
  1966 		eap_variable_data_c * const seed,
       
  1967 		eap_variable_data_c * const A_md5_output);
       
  1968 
       
  1969 	EAP_FUNC_IMPORT eap_status_e tls_prf_one_round(
       
  1970 		abs_crypto_hmac_algorithm_c * const hash,
       
  1971 		const eap_variable_data_c * const key,
       
  1972 		eap_variable_data_c * const A_input,
       
  1973 		eap_variable_data_c * const seed,
       
  1974 		void * const out_buffer,
       
  1975 		const u32_t out_buffer_length);
       
  1976 
       
  1977 	/**
       
  1978 	 * This function cleans up the TLS-PRF context.
       
  1979 	 */
       
  1980 	EAP_FUNC_IMPORT eap_status_e tls_prf_cleanup();
       
  1981 
       
  1982 };
       
  1983 
       
  1984 //------------------------------------------------------------
       
  1985 
       
  1986 /// The crypto_tls_sha1_prf_c class includes the state of 
       
  1987 /// one instance of TLS-PRF SHA1 algorithm.
       
  1988 /// This is needed because compound authentication
       
  1989 /// binding of PEAP does use only P_SHA-1 for generating
       
  1990 /// compound keyed MACs and the compound session keys.
       
  1991 class EAP_EXPORT crypto_tls_sha1_prf_c
       
  1992 : public crypto_tls_base_prf_c
       
  1993 {
       
  1994 
       
  1995 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  1996 private:
       
  1997 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  1998 
       
  1999 	/// This is pointer to the tools class.
       
  2000 	abs_eap_am_tools_c * const m_am_tools;
       
  2001 
       
  2002 	crypto_hmac_c * m_sha1_context;
       
  2003 	crypto_hmac_c * m_A_sha1_context;
       
  2004 
       
  2005 	eap_variable_data_c m_sha1_key;
       
  2006 
       
  2007 	eap_variable_data_c m_seed;
       
  2008 
       
  2009 	/// This indicates whether this object was generated successfully.
       
  2010 	bool m_is_valid;
       
  2011 
       
  2012 	/**
       
  2013 	 * The set_is_invalid() function sets the state of the crypto_tls_sha1_prf_c object invalid. 
       
  2014 	 * The crypto_tls_sha1_prf_c object calls this function after it is initialized.
       
  2015 	 */
       
  2016 	EAP_FUNC_IMPORT void set_is_invalid();
       
  2017 
       
  2018 	/**
       
  2019 	 * The set_is_valid() function sets the state of the crypto_tls_sha1_prf_c object valid. 
       
  2020 	 * The crypto_tls_sha1_prf_c object calls this function after it is initialized.
       
  2021 	 */
       
  2022 	EAP_FUNC_IMPORT void set_is_valid();
       
  2023 
       
  2024 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  2025 public:
       
  2026 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  2027 
       
  2028 	/**
       
  2029 	 * Destructor resets the used internal buffers.
       
  2030 	 */
       
  2031 	EAP_FUNC_IMPORT virtual ~crypto_tls_sha1_prf_c();
       
  2032 
       
  2033 	/**
       
  2034 	 * Constructor initializes the used internal buffers.
       
  2035 	 */
       
  2036 	EAP_FUNC_IMPORT crypto_tls_sha1_prf_c(abs_eap_am_tools_c * const tools);
       
  2037 
       
  2038 	/**
       
  2039 	 * The get_is_valid() function returns the status of the crypto_tls_sha1_prf_c object. 
       
  2040 	 * True indicates the object is initialized.
       
  2041 	 */
       
  2042 	EAP_FUNC_IMPORT bool get_is_valid();
       
  2043 
       
  2044 	/**
       
  2045 	 * This function initializes the context of TLS-PRF algorithm using the key.
       
  2046 	 */
       
  2047 	EAP_FUNC_IMPORT eap_status_e tls_prf_init(
       
  2048 		const eap_variable_data_c * const secret,
       
  2049 		const eap_variable_data_c * const label,
       
  2050 		const eap_variable_data_c * const seed);
       
  2051 
       
  2052 	/**
       
  2053 	 * This function writes the message digest to buffer. 
       
  2054 	 * Length is set if md_length_or_null is non-NULL.
       
  2055 	 */
       
  2056 	EAP_FUNC_IMPORT eap_status_e tls_prf_output(
       
  2057 		void * const pseudo_random_data,
       
  2058 		const u32_t pseudo_random_data_length);
       
  2059 
       
  2060 	/**
       
  2061 	 * This function cleans up the TLS-PRF context.
       
  2062 	 */
       
  2063 	EAP_FUNC_IMPORT eap_status_e tls_prf_cleanup();
       
  2064 
       
  2065 };
       
  2066 
       
  2067 //------------------------------------------------------------
       
  2068 
       
  2069 /// The crypto_tls_md5_prf_c class includes the state of 
       
  2070 /// one instance of TLS-PRF MD5 algorithm.
       
  2071 class EAP_EXPORT crypto_tls_md5_prf_c
       
  2072 : public crypto_tls_base_prf_c
       
  2073 {
       
  2074 
       
  2075 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  2076 private:
       
  2077 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  2078 
       
  2079 	/// This is pointer to the tools class.
       
  2080 	abs_eap_am_tools_c * const m_am_tools;
       
  2081 
       
  2082 	crypto_hmac_c * m_md5_context;
       
  2083 	crypto_hmac_c * m_A_md5_context;
       
  2084 
       
  2085 	eap_variable_data_c m_md5_key;
       
  2086 
       
  2087 	eap_variable_data_c m_seed;
       
  2088 
       
  2089 	/// This indicates whether this object was generated successfully.
       
  2090 	bool m_is_valid;
       
  2091 
       
  2092 	/**
       
  2093 	 * The set_is_invalid() function sets the state of the crypto_tls_md5_prf_c object invalid. 
       
  2094 	 * The crypto_tls_md5_prf_c object calls this function after it is initialized.
       
  2095 	 */
       
  2096 	EAP_FUNC_IMPORT void set_is_invalid();
       
  2097 
       
  2098 	/**
       
  2099 	 * The set_is_valid() function sets the state of the crypto_tls_md5_prf_c object valid. 
       
  2100 	 * The crypto_tls_md5_prf_c object calls this function after it is initialized.
       
  2101 	 */
       
  2102 	EAP_FUNC_IMPORT void set_is_valid();
       
  2103 
       
  2104 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  2105 public:
       
  2106 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  2107 
       
  2108 	/**
       
  2109 	 * Destructor resets the used internal buffers.
       
  2110 	 */
       
  2111 	EAP_FUNC_IMPORT virtual ~crypto_tls_md5_prf_c();
       
  2112 
       
  2113 	/**
       
  2114 	 * Constructor initializes the used internal buffers.
       
  2115 	 */
       
  2116 	EAP_FUNC_IMPORT crypto_tls_md5_prf_c(abs_eap_am_tools_c * const tools);
       
  2117 
       
  2118 	/**
       
  2119 	 * The get_is_valid() function returns the status of the crypto_tls_md5_prf_c object. 
       
  2120 	 * True indicates the object is initialized.
       
  2121 	 */
       
  2122 	EAP_FUNC_IMPORT bool get_is_valid();
       
  2123 
       
  2124 	/**
       
  2125 	 * This function initializes the context of TLS-PRF algorithm using the key.
       
  2126 	 */
       
  2127 	EAP_FUNC_IMPORT eap_status_e tls_prf_init(
       
  2128 		const eap_variable_data_c * const secret,
       
  2129 		const eap_variable_data_c * const label,
       
  2130 		const eap_variable_data_c * const seed);
       
  2131 
       
  2132 	/**
       
  2133 	 * This function writes the message digest to buffer. 
       
  2134 	 * Length is set if md_length_or_null is non-NULL.
       
  2135 	 */
       
  2136 	EAP_FUNC_IMPORT eap_status_e tls_prf_output(
       
  2137 		void * const pseudo_random_data,
       
  2138 		const u32_t pseudo_random_data_length);
       
  2139 
       
  2140 	/**
       
  2141 	 * This function cleans up the TLS-PRF context.
       
  2142 	 */
       
  2143 	EAP_FUNC_IMPORT eap_status_e tls_prf_cleanup();
       
  2144 
       
  2145 };
       
  2146 
       
  2147 //------------------------------------------------------------
       
  2148 
       
  2149 /// The crypto_tls_prf_c class includes the state of 
       
  2150 /// one instance of TLS-PRF algorithm.
       
  2151 class EAP_EXPORT crypto_tls_prf_c
       
  2152 {
       
  2153 
       
  2154 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  2155 private:
       
  2156 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  2157 
       
  2158 	/// This is pointer to the tools class.
       
  2159 	abs_eap_am_tools_c * const m_am_tools;
       
  2160 
       
  2161 	crypto_tls_md5_prf_c * m_tls_md5_prf;
       
  2162 	crypto_tls_sha1_prf_c * m_tls_sha1_prf;
       
  2163 
       
  2164 	/// This indicates whether this object was generated successfully.
       
  2165 	bool m_is_valid;
       
  2166 
       
  2167 	/**
       
  2168 	 * The set_is_invalid() function sets the state of the crypto_tls_prf_c object invalid. 
       
  2169 	 * The crypto_tls_prf_c object calls this function after it is initialized.
       
  2170 	 */
       
  2171 	EAP_FUNC_IMPORT void set_is_invalid();
       
  2172 
       
  2173 	/**
       
  2174 	 * The set_is_valid() function sets the state of the crypto_tls_prf_c object valid. 
       
  2175 	 * The crypto_tls_prf_c object calls this function after it is initialized.
       
  2176 	 */
       
  2177 	EAP_FUNC_IMPORT void set_is_valid();
       
  2178 
       
  2179 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  2180 public:
       
  2181 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  2182 
       
  2183 	/**
       
  2184 	 * Destructor resets the used internal buffers.
       
  2185 	 */
       
  2186 	EAP_FUNC_IMPORT virtual ~crypto_tls_prf_c();
       
  2187 
       
  2188 	/**
       
  2189 	 * Constructor initializes the used internal buffers.
       
  2190 	 */
       
  2191 	EAP_FUNC_IMPORT crypto_tls_prf_c(abs_eap_am_tools_c * const tools);
       
  2192 
       
  2193 	/**
       
  2194 	 * The get_is_valid() function returns the status of the crypto_tls_prf_c object. 
       
  2195 	 * True indicates the object is initialized.
       
  2196 	 */
       
  2197 	EAP_FUNC_IMPORT bool get_is_valid();
       
  2198 
       
  2199 	/**
       
  2200 	 * This function initializes the context of TLS-PRF algorithm using the key.
       
  2201 	 */
       
  2202 	EAP_FUNC_IMPORT eap_status_e tls_prf_init(
       
  2203 		const eap_variable_data_c * const secret,
       
  2204 		const eap_variable_data_c * const label,
       
  2205 		const eap_variable_data_c * const seed);
       
  2206 
       
  2207 	/**
       
  2208 	 * This function writes the message digest to buffer. 
       
  2209 	 * Length is set if md_length_or_null is non-NULL.
       
  2210 	 */
       
  2211 	EAP_FUNC_IMPORT eap_status_e tls_prf_output(
       
  2212 		void * const pseudo_random_data,
       
  2213 		const u32_t pseudo_random_data_length);
       
  2214 
       
  2215 	/**
       
  2216 	 * This function cleans up the TLS-PRF context.
       
  2217 	 */
       
  2218 	EAP_FUNC_IMPORT eap_status_e tls_prf_cleanup();
       
  2219 
       
  2220 };
       
  2221 
       
  2222 //------------------------------------------------------------
       
  2223 
       
  2224 
       
  2225 /// The crypto_eap_fast_hmac_sha1_prf_c class includes the state of 
       
  2226 /// one instance of T-PRF algorithm used in EAP-FAST.
       
  2227 class EAP_EXPORT crypto_eap_fast_hmac_sha1_prf_c
       
  2228 {
       
  2229 
       
  2230 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  2231 private:
       
  2232 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  2233 
       
  2234 	/// This is pointer to the tools class.
       
  2235 	abs_eap_am_tools_c * const m_am_tools;
       
  2236 
       
  2237 	crypto_hmac_c * m_context;
       
  2238 
       
  2239 	eap_variable_data_c m_key;
       
  2240 
       
  2241 	eap_variable_data_c m_S_value;
       
  2242 
       
  2243 	/// This indicates whether this object was generated successfully.
       
  2244 	bool m_is_valid;
       
  2245 
       
  2246 	/**
       
  2247 	 * The set_is_invalid() function sets the state of the crypto_eap_fast_hmac_sha1_prf_c object invalid. 
       
  2248 	 * The crypto_eap_fast_hmac_sha1_prf_c object calls this function after it is initialized.
       
  2249 	 */
       
  2250 	EAP_FUNC_IMPORT void set_is_invalid();
       
  2251 
       
  2252 	/**
       
  2253 	 * The set_is_valid() function sets the state of the crypto_eap_fast_hmac_sha1_prf_c object valid. 
       
  2254 	 * The crypto_eap_fast_hmac_sha1_prf_c object calls this function after it is initialized.
       
  2255 	 */
       
  2256 	EAP_FUNC_IMPORT void set_is_valid();
       
  2257 
       
  2258 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  2259 public:
       
  2260 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  2261 
       
  2262 	/**
       
  2263 	 * Destructor resets the used internal buffers.
       
  2264 	 */
       
  2265 	EAP_FUNC_IMPORT virtual ~crypto_eap_fast_hmac_sha1_prf_c();
       
  2266 
       
  2267 	/**
       
  2268 	 * Constructor initializes the used internal buffers.
       
  2269 	 */
       
  2270 	EAP_FUNC_IMPORT crypto_eap_fast_hmac_sha1_prf_c(abs_eap_am_tools_c * const tools);
       
  2271 
       
  2272 	/**
       
  2273 	 * The get_is_valid() function returns the status of the crypto_eap_fast_hmac_sha1_prf_c object. 
       
  2274 	 * True indicates the object is initialized.
       
  2275 	 */
       
  2276 	EAP_FUNC_IMPORT bool get_is_valid();
       
  2277 
       
  2278 	/**
       
  2279 	 * This function initializes the context of T-PRF algorithm using the key.
       
  2280 	 */
       
  2281 	EAP_FUNC_IMPORT eap_status_e t_prf_init(
       
  2282 		const eap_variable_data_c * const key,
       
  2283 		const eap_variable_data_c * const label,
       
  2284 		const eap_variable_data_c * const seed);
       
  2285 
       
  2286 	/**
       
  2287 	 * This function writes the message digest to buffer. 
       
  2288 	 */
       
  2289 	EAP_FUNC_IMPORT eap_status_e t_prf_output(
       
  2290 		void * const pseudo_random_data,
       
  2291 		const u16_t pseudo_random_data_length);
       
  2292 
       
  2293 	/**
       
  2294 	 * This function cleans up the T-PRF context.
       
  2295 	 */
       
  2296 	EAP_FUNC_IMPORT eap_status_e t_prf_cleanup();
       
  2297 
       
  2298 };
       
  2299 
       
  2300 
       
  2301 //------------------------------------------------------------
       
  2302 
       
  2303 /// The crypto_tls_prf_c class includes the state of 
       
  2304 /// one instance of RSA algorithm.
       
  2305 class EAP_EXPORT crypto_rsa_c
       
  2306 {
       
  2307 
       
  2308 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  2309 private:
       
  2310 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  2311 
       
  2312 	/// This is pointer to the tools class.
       
  2313 	abs_eap_am_tools_c * const m_am_tools;
       
  2314 
       
  2315 	/// Context is stored to this variable.
       
  2316 	/// This hides the whole implementation.
       
  2317 	/// Includes the context of the RSA algorithm. 
       
  2318 	/// This depends on the crypto library.
       
  2319 	eap_variable_data_c m_context;
       
  2320 
       
  2321 	/// This indicates whether this object was generated successfully.
       
  2322 	bool m_is_valid;
       
  2323 
       
  2324 	/**
       
  2325 	 * The set_is_invalid() function sets the state of the crypto_rsa_c object invalid. 
       
  2326 	 * The crypto_rsa_c object calls this function after it is initialized.
       
  2327 	 */
       
  2328 	EAP_FUNC_IMPORT void set_is_invalid();
       
  2329 
       
  2330 	/**
       
  2331 	 * The set_is_valid() function sets the state of the crypto_rsa_c object valid. 
       
  2332 	 * The crypto_rsa_c object calls this function after it is initialized.
       
  2333 	 */
       
  2334 	EAP_FUNC_IMPORT void set_is_valid();
       
  2335 
       
  2336 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  2337 public:
       
  2338 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  2339 
       
  2340 	/**
       
  2341 	 * Destructor resets the used internal buffers.
       
  2342 	 */
       
  2343 	EAP_FUNC_IMPORT virtual ~crypto_rsa_c();
       
  2344 
       
  2345 	/**
       
  2346 	 * Constructor initializes the used internal buffers.
       
  2347 	 */
       
  2348 	EAP_FUNC_IMPORT crypto_rsa_c(abs_eap_am_tools_c * const tools);
       
  2349 
       
  2350 	/**
       
  2351 	 * The get_is_valid() function returns the status of the crypto_rsa_c object. 
       
  2352 	 * True indicates the object is initialized.
       
  2353 	 */
       
  2354 	EAP_FUNC_IMPORT bool get_is_valid();
       
  2355 
       
  2356 	/**
       
  2357 	 * This function initializes the context of RSA algorithm using the key.
       
  2358 	 */
       
  2359 	EAP_FUNC_IMPORT eap_status_e init();
       
  2360 
       
  2361 	EAP_FUNC_IMPORT eap_status_e encrypt_with_public_key(
       
  2362 		const eap_variable_data_c * const public_rsa_key,
       
  2363 		const eap_variable_data_c * const input_data,
       
  2364 		eap_variable_data_c * const output_data);
       
  2365 
       
  2366 	EAP_FUNC_IMPORT eap_status_e decrypt_with_public_key(
       
  2367 		const eap_variable_data_c * const public_rsa_key,
       
  2368 		const eap_variable_data_c * const input_data,
       
  2369 		eap_variable_data_c * const output_data);
       
  2370 
       
  2371 	EAP_FUNC_IMPORT eap_status_e encrypt_with_private_key(
       
  2372 		const eap_variable_data_c * const private_rsa_key,
       
  2373 		const eap_variable_data_c * const input_data,
       
  2374 		eap_variable_data_c * const output_data);
       
  2375 
       
  2376 	EAP_FUNC_IMPORT eap_status_e decrypt_with_private_key(
       
  2377 		const eap_variable_data_c * const private_rsa_key,
       
  2378 		const eap_variable_data_c * const input_data,
       
  2379 		eap_variable_data_c * const output_data);
       
  2380 
       
  2381 	EAP_FUNC_IMPORT eap_status_e sign(
       
  2382 		const eap_variable_data_c * const private_dsa_key,
       
  2383 		const eap_variable_data_c * const hash,
       
  2384 		eap_variable_data_c * const signed_hash);
       
  2385 
       
  2386 	EAP_FUNC_IMPORT eap_status_e verify(
       
  2387 		const eap_variable_data_c * const public_rsa_key,
       
  2388 		const eap_variable_data_c * const hash,
       
  2389 		const eap_variable_data_c * const signed_hash);
       
  2390 
       
  2391 	/**
       
  2392 	 * This function cleans up the RSA context.
       
  2393 	 */
       
  2394 	EAP_FUNC_IMPORT eap_status_e cleanup();
       
  2395 
       
  2396 };
       
  2397 
       
  2398 //------------------------------------------------------------
       
  2399 
       
  2400 /// The crypto_tls_prf_c class includes the state of 
       
  2401 /// one instance of DSA algorithm.
       
  2402 class EAP_EXPORT crypto_dsa_c
       
  2403 {
       
  2404 
       
  2405 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  2406 private:
       
  2407 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  2408 
       
  2409 	/// This is pointer to the tools class.
       
  2410 	abs_eap_am_tools_c * const m_am_tools;
       
  2411 
       
  2412 	/// Context is stored to this variable.
       
  2413 	/// This hides the whole implementation.
       
  2414 	/// Includes the context of the DSA algorithm. 
       
  2415 	/// This depends on the crypto library.
       
  2416 	eap_variable_data_c m_context;
       
  2417 
       
  2418 	/// This indicates whether this object was generated successfully.
       
  2419 	bool m_is_valid;
       
  2420 
       
  2421 	/**
       
  2422 	 * The set_is_invalid() function sets the state of the crypto_dsa_c object invalid. 
       
  2423 	 * The crypto_dsa_c object calls this function after it is initialized.
       
  2424 	 */
       
  2425 	EAP_FUNC_IMPORT void set_is_invalid();
       
  2426 
       
  2427 	/**
       
  2428 	 * The set_is_valid() function sets the state of the crypto_dsa_c object valid. 
       
  2429 	 * The crypto_dsa_c object calls this function after it is initialized.
       
  2430 	 */
       
  2431 	EAP_FUNC_IMPORT void set_is_valid();
       
  2432 
       
  2433 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  2434 public:
       
  2435 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  2436 
       
  2437 	/**
       
  2438 	 * Destructor resets the used internal buffers.
       
  2439 	 */
       
  2440 	EAP_FUNC_IMPORT virtual ~crypto_dsa_c();
       
  2441 
       
  2442 	/**
       
  2443 	 * Constructor initializes the used internal buffers.
       
  2444 	 */
       
  2445 	EAP_FUNC_IMPORT crypto_dsa_c(abs_eap_am_tools_c * const tools);
       
  2446 
       
  2447 	/**
       
  2448 	 * The get_is_valid() function returns the status of the crypto_dsa_c object. 
       
  2449 	 * True indicates the object is initialized.
       
  2450 	 */
       
  2451 	EAP_FUNC_IMPORT bool get_is_valid();
       
  2452 
       
  2453 	/**
       
  2454 	 * This function initializes the context of DSA algorithm using the key.
       
  2455 	 */
       
  2456 	EAP_FUNC_IMPORT eap_status_e init();
       
  2457 
       
  2458 	EAP_FUNC_IMPORT eap_status_e sign(
       
  2459 		const eap_variable_data_c * const private_dsa_key,
       
  2460 		const eap_variable_data_c * const hash,
       
  2461 		eap_variable_data_c * const signed_hash);
       
  2462 
       
  2463 	EAP_FUNC_IMPORT eap_status_e verify(
       
  2464 		const eap_variable_data_c * const public_dsa_key,
       
  2465 		const eap_variable_data_c * const dsa_param_p,
       
  2466 		const eap_variable_data_c * const dsa_param_q,
       
  2467 		const eap_variable_data_c * const dsa_param_g,
       
  2468 		const eap_variable_data_c * const hash,
       
  2469 		const eap_variable_data_c * const signed_hash);
       
  2470 
       
  2471 	/**
       
  2472 	 * This function cleans up the DSA context.
       
  2473 	 */
       
  2474 	EAP_FUNC_IMPORT eap_status_e cleanup();
       
  2475 
       
  2476 };
       
  2477 
       
  2478 //------------------------------------------------------------
       
  2479 
       
  2480 /// The crypto_wpa_psk_password_hash_c class includes the functions for
       
  2481 /// generating WPA PSK from an ASCII password
       
  2482 class EAP_EXPORT crypto_wpa_psk_password_hash_c
       
  2483 {
       
  2484 
       
  2485 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  2486 private:
       
  2487 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  2488 
       
  2489 	/// This is pointer to the tools class.
       
  2490 	abs_eap_am_tools_c * const m_am_tools;
       
  2491 
       
  2492 	/// This indicates whether this object was generated successfully.
       
  2493 	bool m_is_valid;
       
  2494 
       
  2495 	/**
       
  2496 	 * The set_is_invalid() function sets the state of the crypto_rc4_c object invalid. 
       
  2497 	 * The crypto_rc4_c object calls this function after it is initialized.
       
  2498 	 */
       
  2499 	void set_is_invalid();
       
  2500 
       
  2501 	/**
       
  2502 	 * The set_is_valid() function sets the state of the crypto_rc4_c object valid. 
       
  2503 	 * The crypto_rc4_c object calls this function after it is initialized.
       
  2504 	 */
       
  2505 	void set_is_valid();
       
  2506 
       
  2507 	/**
       
  2508 	* Calculates the PSK hash from an ASCII password
       
  2509 	*/
       
  2510 	eap_status_e password_hash_F(
       
  2511 		const eap_variable_data_c * const password,
       
  2512 		const eap_variable_data_c * const ssid,	
       
  2513 		u32_t iterations,
       
  2514 		u32_t count,
       
  2515 		eap_variable_data_c * const output,
       
  2516 		void * object,
       
  2517 		eap_status_e (*progress_callback)(void*, u32_t));
       
  2518 
       
  2519 
       
  2520 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  2521 public:
       
  2522 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  2523 
       
  2524 	/**
       
  2525 	 * Destructor resets the used internal buffers.
       
  2526 	 */
       
  2527 	EAP_FUNC_IMPORT virtual ~crypto_wpa_psk_password_hash_c();
       
  2528 
       
  2529 	/**
       
  2530 	 * Constructor initializes the used internal buffers.
       
  2531 	 */
       
  2532 	EAP_FUNC_IMPORT crypto_wpa_psk_password_hash_c(abs_eap_am_tools_c * const tools);
       
  2533 
       
  2534 	/**
       
  2535 	 * The get_is_valid() function returns the status of the crypto_wpa_psk_password_hash object. 
       
  2536 	 * True indicates the object is initialized.
       
  2537 	 */
       
  2538 	EAP_FUNC_IMPORT bool get_is_valid();
       
  2539 	
       
  2540 	/**
       
  2541 	* Calculates the PSK hash from an ASCII password
       
  2542 	*/
       
  2543 	EAP_FUNC_IMPORT eap_status_e password_hash(
       
  2544 		const eap_variable_data_c * const password,
       
  2545 		const eap_variable_data_c * const ssid,	
       
  2546 		eap_variable_data_c * const output,
       
  2547 		void * object = 0,
       
  2548 		eap_status_e (*progress_callback)(void*, u32_t) = 0);
       
  2549 
       
  2550 };
       
  2551 
       
  2552 //------------------------------------------------------------
       
  2553 
       
  2554 /// The crypto_wpa_psk_password_hash_c class includes the functions for
       
  2555 /// generating WPA PSK from an ASCII password
       
  2556 class EAP_EXPORT crypto_nt_hash_c
       
  2557 {
       
  2558 
       
  2559 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  2560 private:
       
  2561 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  2562 
       
  2563 	/// This is pointer to the tools class.
       
  2564 	abs_eap_am_tools_c * const m_am_tools;
       
  2565 
       
  2566 	/// This indicates whether this object was generated successfully.
       
  2567 	bool m_is_valid;
       
  2568 
       
  2569 	/**
       
  2570 	 * The set_is_invalid() function sets the state of the crypto_rc4_c object invalid. 
       
  2571 	 * The crypto_rc4_c object calls this function after it is initialized.
       
  2572 	 */
       
  2573 	void set_is_invalid();
       
  2574 
       
  2575 	/**
       
  2576 	 * The set_is_valid() function sets the state of the crypto_rc4_c object valid. 
       
  2577 	 * The crypto_rc4_c object calls this function after it is initialized.
       
  2578 	 */
       
  2579 	void set_is_valid();
       
  2580 
       
  2581 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  2582 public:
       
  2583 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  2584 
       
  2585 	/**
       
  2586 	 * Destructor resets the used internal buffers.
       
  2587 	 */
       
  2588 	EAP_FUNC_IMPORT virtual ~crypto_nt_hash_c();
       
  2589 
       
  2590 	/**
       
  2591 	 * Constructor initializes the used internal buffers.
       
  2592 	 */
       
  2593 	EAP_FUNC_IMPORT crypto_nt_hash_c(abs_eap_am_tools_c * const tools);
       
  2594 
       
  2595 	/**
       
  2596 	 * The get_is_valid() function returns the status of the crypto_wpa_psk_password_hash object. 
       
  2597 	 * True indicates the object is initialized.
       
  2598 	 */
       
  2599 	EAP_FUNC_IMPORT bool get_is_valid();
       
  2600 	
       
  2601 	EAP_FUNC_IMPORT eap_status_e nt_password_hash(
       
  2602 		const eap_variable_data_c * const password_utf8,
       
  2603 		eap_variable_data_c * const password_hash,
       
  2604 		const u32_t digest_size);
       
  2605 
       
  2606 	EAP_FUNC_IMPORT eap_status_e hash_nt_password_hash(
       
  2607 		const eap_variable_data_c * const password_hash,
       
  2608 		eap_variable_data_c * const password_hash_hash,
       
  2609 		const u32_t digest_size);
       
  2610 
       
  2611 	/* RFC 3079 */
       
  2612 
       
  2613 	EAP_FUNC_IMPORT eap_status_e get_master_key(
       
  2614 		const eap_variable_data_c * const password_hash_hash,
       
  2615 		const eap_variable_data_c * const nt_response,
       
  2616 		eap_variable_data_c * const master_key,
       
  2617 		const u32_t in_master_key_length);
       
  2618 
       
  2619 	EAP_FUNC_IMPORT eap_status_e get_asymmetric_start_key(
       
  2620 		const eap_variable_data_c * const in_master_key,
       
  2621 		eap_variable_data_c * const out_session_key,
       
  2622 		const u32_t in_session_key_length,
       
  2623 		const bool in_is_send,
       
  2624 		const bool in_is_server);
       
  2625 
       
  2626 	EAP_FUNC_IMPORT eap_status_e get_new_key_from_sha(
       
  2627 		const eap_variable_data_c * const in_start_key,
       
  2628 		const eap_variable_data_c * const in_session_key,
       
  2629 		eap_variable_data_c * const out_interim_key,
       
  2630 		const u32_t in_interim_key_length);
       
  2631 	
       
  2632 };
       
  2633 
       
  2634 //------------------------------------------------------------
       
  2635 
       
  2636 /// The crypto_kd_hmac_sha256_c class includes the functions for
       
  2637 /// KD-HMAC-SHA256.
       
  2638 class EAP_EXPORT crypto_kd_hmac_sha256_c
       
  2639 {
       
  2640 
       
  2641 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  2642 private:
       
  2643 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  2644 
       
  2645 	/// This is pointer to the tools class.
       
  2646 	abs_eap_am_tools_c * const m_am_tools;
       
  2647 
       
  2648 	/// This indicates whether this object was generated successfully.
       
  2649 	bool m_is_valid;
       
  2650 
       
  2651 	/**
       
  2652 	 * The set_is_invalid() function sets the state of the crypto_kd_hmac_sha256_c object invalid. 
       
  2653 	 * The crypto_kd_hmac_sha256_c object calls this function after it is initialized.
       
  2654 	 */
       
  2655 	void set_is_invalid();
       
  2656 
       
  2657 	/**
       
  2658 	 * The set_is_valid() function sets the state of the crypto_kd_hmac_sha256_c object valid. 
       
  2659 	 * The crypto_kd_hmac_sha256_c object calls this function after it is initialized.
       
  2660 	 */
       
  2661 	void set_is_valid();
       
  2662 
       
  2663 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  2664 public:
       
  2665 	// - - - - - - - - - - - - - - - - - - - - - - - -
       
  2666 
       
  2667 	/**
       
  2668 	 * Destructor resets the used internal buffers.
       
  2669 	 */
       
  2670 	EAP_FUNC_IMPORT virtual ~crypto_kd_hmac_sha256_c();
       
  2671 
       
  2672 	/**
       
  2673 	 * Constructor initializes the used internal buffers.
       
  2674 	 */
       
  2675 	EAP_FUNC_IMPORT crypto_kd_hmac_sha256_c(abs_eap_am_tools_c * const tools);
       
  2676 
       
  2677 	/**
       
  2678 	 * The get_is_valid() function returns the status of the crypto_kd_hmac_sha256_c object. 
       
  2679 	 * True indicates the object is initialized.
       
  2680 	 */
       
  2681 	EAP_FUNC_IMPORT bool get_is_valid();
       
  2682 	
       
  2683 	EAP_FUNC_IMPORT eap_status_e expand_key(
       
  2684 		eap_variable_data_c * const output,
       
  2685 		const u32_t required_output_size,
       
  2686 		const eap_variable_data_c * const key,
       
  2687 		const eap_variable_data_c * const label
       
  2688 		);
       
  2689 };
       
  2690 
       
  2691 //------------------------------------------------------------
       
  2692 
       
  2693 #endif //#if !defined( _EAP_CRYPTO_API_H_ )
       
  2694 
       
  2695 
       
  2696 
       
  2697 // End.