173 lines
		
	
	
		
			5.9 KiB
		
	
	
	
		
			C
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			173 lines
		
	
	
		
			5.9 KiB
		
	
	
	
		
			C
		
	
	
		
			Executable File
		
	
	
	
	
| /****************************************************************************
 | |
| 
 | |
| Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
 | |
| 
 | |
| This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
 | |
| be copied by any method or incorporated into another program without
 | |
| the express written consent of Aerospace C.Power. This Information or any portion
 | |
| thereof remains the property of Aerospace C.Power. The Information contained herein
 | |
| is believed to be accurate and Aerospace C.Power assumes no responsibility or
 | |
| liability for its use in any way and conveys no license or title under
 | |
| any patent or copyright and makes no representation or warranty that this
 | |
| Information is free from patent or copyright infringement.
 | |
| 
 | |
| ****************************************************************************/
 | |
| 
 | |
| #ifndef IOT_CRYPTO_AES_API_H
 | |
| #define IOT_CRYPTO_AES_API_H
 | |
| 
 | |
| #ifdef __cplusplus
 | |
| extern "C" {
 | |
| #endif
 | |
| 
 | |
| #include "iot_crypto_error_api.h"
 | |
| 
 | |
| /** \defgroup CRYPTO_APIs CRYPTO APIs
 | |
|   */
 | |
| 
 | |
| #define IOT_AES_ENCRYPT     1
 | |
| #define IOT_AES_DECRYPT     0
 | |
| 
 | |
| /** @addtogroup CRYPTO_APIs
 | |
|   * @{
 | |
|   */
 | |
| 
 | |
| /**
 | |
|  * @brief iot_crypto_aes_setkey_enc() - set AES enc key
 | |
|  * @param tm:           time zone param
 | |
|  *
 | |
|  * @retval:             error code. see CRYPTO_RET_XXX
 | |
|  */
 | |
| uint32_t iot_crypto_aes_setkey_enc(const uint8_t *key, uint32_t keybits);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_crypto_aes_setkey_dec() - set AES dec key
 | |
|  * @param key:           key buffer
 | |
|  * @param keybits:       key length
 | |
|  *
 | |
|  * @retval:              error code. see CRYPTO_RET_XXX
 | |
|  */
 | |
| uint32_t iot_crypto_aes_setkey_dec(const uint8_t *key, uint32_t keybits);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_crypto_aes_ecb() - AES ECB
 | |
|  * @param mode:          1->enc mode, 0->dec mode
 | |
|  * @param len:           buffer len
 | |
|  * @param input:         input buffer
 | |
|  * @param output:        output buffer
 | |
|  *
 | |
|  * @retval:              error code. see CRYPTO_RET_XXX
 | |
|  */
 | |
| uint32_t iot_crypto_aes_ecb(uint8_t mode, uint32_t len,
 | |
|     const uint8_t *input, uint8_t *output);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_crypto_aes_cbc() - AES CBC
 | |
|  * @param mode:          1->enc mode, 0->dec mode
 | |
|  * @param len:           buffer len
 | |
|  * @param len:           iv buffer
 | |
|  * @param input:         input buffer
 | |
|  * @param output:        output buffer
 | |
|  *
 | |
|  * @retval:              error code. see CRYPTO_RET_XXX
 | |
|  */
 | |
| uint32_t iot_crypto_aes_cbc(uint8_t mode, uint32_t len, uint8_t *iv,
 | |
|     const uint8_t *input, uint8_t *output);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_crypto_aes_ctr() - AES CTR
 | |
|  * @param len:           buffer len
 | |
|  * @param nc_off         offset in the current stream_block
 | |
|  * @param nonce_counter  128-bit nonce and counter.
 | |
|  * @param stream_block   saved stream-block for resuming.
 | |
|  * @param input:         input buffer
 | |
|  * @param output:        output buffer
 | |
|  *
 | |
|  * @retval:              error code. see CRYPTO_RET_XXX
 | |
|  */
 | |
| uint32_t iot_crypto_aes_ctr( int len, size_t *nc_off, uint8_t *nonce_counter,
 | |
|     uint8_t *stream_block, const uint8_t *input, uint8_t *output);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_crypto_aes_ecb_with_key() - set aes key and AES ECB calculation
 | |
|  * @param key:           key buffer
 | |
|  * @param keybits:       key length
 | |
|  * @param mode:          1->enc mode, 0->dec mode
 | |
|  * @param len:           buffer len
 | |
|  * @param input:         input buffer
 | |
|  * @param output:        output buffer
 | |
|  *
 | |
|  * @retval:              error code. see CRYPTO_RET_XXX
 | |
|  */
 | |
| uint32_t iot_crypto_aes_ecb_with_key(const uint8_t *key, uint32_t keybits,
 | |
|     uint8_t mode, uint32_t len, const uint8_t *input, uint8_t *output);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_crypto_aes_cbc_with_key() - set aes key and AES CBC calculation
 | |
|  * @param key:           key buffer
 | |
|  * @param keybits:       key bit length
 | |
|  * @param mode:          1->enc mode, 0->dec mode
 | |
|  * @param len:           buffer len
 | |
|  * @param in_iv:         input iv buffer
 | |
|  * @param input:         input buffer
 | |
|  * @param output:        output buffer
 | |
|  * @param out_iv:        output iv buffer
 | |
|  * @param round:         round count
 | |
|  *
 | |
|  * @retval:              error code. see CRYPTO_RET_XXX
 | |
|  */
 | |
| uint32_t iot_crypto_aes_cbc_with_key(const uint8_t *key, uint32_t keybits,
 | |
|     uint8_t mode, uint32_t len, uint8_t *in_iv, const uint8_t *input,
 | |
|     uint8_t *output, uint8_t *out_iv, uint32_t round);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_crypto_aes_ctr_with_key() - set aes key and AES CTR calculation
 | |
|  * @param key:           key buffer
 | |
|  * @param keybits:       key length
 | |
|  * @param len:           buffer len
 | |
|  * @param nc_off         offset in the current stream_block
 | |
|  * @param nonce_counter  128-bit nonce and counter.
 | |
|  * @param stream_block   saved stream-block for resuming.
 | |
|  * @param input:         input buffer
 | |
|  * @param output:        output buffer
 | |
|  *
 | |
|  * @retval:              error code. see CRYPTO_RET_XXX
 | |
|  */
 | |
| uint32_t iot_crypto_aes_ctr_with_key(const uint8_t *key, uint32_t keybits,
 | |
|     int len, size_t *nc_off, uint8_t *nonce_counter, uint8_t *stream_block,
 | |
|     const uint8_t *input, uint8_t *output);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_crypto_aes_gcm
 | |
|  *
 | |
|  * @param is_enc:               1 - encrypt, 0 - decrypt
 | |
|  * @param key:                  key buffer
 | |
|  * @param keybits:              key bit number
 | |
|  * @param input:                for encrypt, this is plaintext
 | |
|  *                              for decrypt, this is chipertext
 | |
|  * @param input_len:            input text byte length
 | |
|  * @param iv:                   input iv buffer
 | |
|  * @param iv_len:               iv byte length
 | |
|  * @param add:                  add buffer
 | |
|  * @param add_len:              add byte length
 | |
|  * @param output:               for encrypt, this is chipertext
 | |
|  *                              for decrypt, this is plaintext
 | |
|  * @param tag:                  output tag buffer
 | |
|  *
 | |
|  * @retval:                     error code. see CRYPTO_RET_XXX
 | |
|  */
 | |
| uint32_t iot_crypto_aes_gcm(uint8_t is_enc, uint8_t *key,
 | |
|     uint32_t keybits, uint8_t *input, uint32_t input_len, uint8_t *iv,
 | |
|     uint32_t iv_len, uint8_t *add, uint32_t add_len, uint8_t *output,
 | |
|     uint8_t *tag);
 | |
| 
 | |
| /**
 | |
|   * @}
 | |
|   */
 | |
| 
 | |
| #ifdef __cplusplus
 | |
| }
 | |
| #endif
 | |
| 
 | |
| #endif //IOT_CRYPTO_AES_API_H
 |