187 lines
		
	
	
		
			6.1 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			187 lines
		
	
	
		
			6.1 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
| /****************************************************************************
 | |
| 
 | |
| 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_ASYNC_H_
 | |
| #define _IOT_CRYPTO_ASYNC_H_
 | |
| 
 | |
| #ifdef __cplusplus
 | |
| extern "C" {
 | |
| #endif
 | |
| 
 | |
| #include "iot_config.h"
 | |
| #include "iot_crypto_dsa_async_api.h"
 | |
| 
 | |
| /* ecdsa */
 | |
| #define IOT_CRYPTO_ASYNC_ECDSA_PUB_LEN     64
 | |
| #define IOT_CRYPTO_ASYNC_ECDSA_PRI_LEN     32
 | |
| #define IOT_CRYPTO_ASYNC_ECDSA_R_S_LEN     32
 | |
| 
 | |
| /* sm2 */
 | |
| #define IOT_CRYPTO_ASYNC_SM2_PUB_LEN       64
 | |
| #define IOT_CRYPTO_ASYNC_SM2_PRI_LEN       32
 | |
| #define IOT_CRYPTO_ASYNC_R_S_LEN           32
 | |
| #define IOT_CRYPTO_ASYNC_SM2_USER_ID_LEN   16
 | |
| 
 | |
| /* sg */
 | |
| #define IOT_CRYPTO_ASYNC_ECP_LEN           1
 | |
| #define IOT_CRYPTO_ASYNC_CHIP_ID_LEN       24
 | |
| 
 | |
| /* save the pack status and set 1 byte align */
 | |
| #pragma pack(push)
 | |
| #pragma pack(1)
 | |
| 
 | |
| typedef struct _iot_crypto_async_src_info {
 | |
|     /* crypto done callback function */
 | |
|     iot_crypto_async_done_func_t cb;
 | |
|     /* TODO: add others information */
 | |
| } iot_crypto_async_src_info_t;
 | |
| 
 | |
| typedef struct _iot_crypto_async_msg_info {
 | |
|     /* buffer length */
 | |
|     uint32_t len;
 | |
|     /* data buffer */
 | |
|     uint8_t data[0];
 | |
| } iot_crypto_async_msg_info_t;
 | |
| 
 | |
| typedef struct _iot_crypto_async_sm2_sign_info_t {
 | |
|     /* crypto done callback function */
 | |
|     iot_crypto_async_done_func_t cb;
 | |
|     iot_crypto_async_hdr_t hdr;
 | |
|     uint8_t id[IOT_CRYPTO_ASYNC_SM2_USER_ID_LEN];
 | |
|     uint8_t pub_key[IOT_CRYPTO_ASYNC_SM2_PUB_LEN];
 | |
|     uint8_t pri_key[IOT_CRYPTO_ASYNC_SM2_PRI_LEN];
 | |
|     iot_crypto_async_msg_info_t msg;
 | |
| } iot_crypto_async_sm2_sign_info_t;
 | |
| 
 | |
| typedef struct _iot_crypto_async_sm2_verify_info_t {
 | |
|     /* crypto done callback function */
 | |
|     iot_crypto_async_done_func_t cb;
 | |
|     iot_crypto_async_hdr_t hdr;
 | |
|     uint8_t id[IOT_CRYPTO_ASYNC_SM2_USER_ID_LEN];
 | |
|     uint8_t pub_key[IOT_CRYPTO_ASYNC_SM2_PUB_LEN];
 | |
|     uint8_t r[IOT_CRYPTO_ASYNC_R_S_LEN];
 | |
|     uint8_t s[IOT_CRYPTO_ASYNC_R_S_LEN];
 | |
|     iot_crypto_async_msg_info_t msg;
 | |
| } iot_crypto_async_sm2_verify_info_t;
 | |
| 
 | |
| typedef struct _iot_crypto_async_ecdsa_sign_info_t {
 | |
|     /* crypto done callback function */
 | |
|     iot_crypto_async_done_func_t cb;
 | |
|     iot_crypto_async_hdr_t hdr;
 | |
|     uint32_t ecp;
 | |
|     uint8_t pri_key[IOT_CRYPTO_ASYNC_ECDSA_PRI_LEN];
 | |
|     iot_crypto_async_msg_info_t msg;
 | |
| } iot_crypto_async_ecdsa_sign_info_t;
 | |
| 
 | |
| typedef struct _iot_crypto_async_ecdsa_verify_info_t {
 | |
|     /* crypto done callback function */
 | |
|     iot_crypto_async_done_func_t cb;
 | |
|     iot_crypto_async_hdr_t hdr;
 | |
|     uint32_t ecp;
 | |
|     uint8_t pub_key[IOT_CRYPTO_ASYNC_SM2_PUB_LEN];
 | |
|     uint8_t r[IOT_CRYPTO_ASYNC_ECDSA_R_S_LEN];
 | |
|     uint8_t s[IOT_CRYPTO_ASYNC_ECDSA_R_S_LEN];
 | |
|     iot_crypto_async_msg_info_t msg;
 | |
| } iot_crypto_async_ecdsa_verify_info_t;
 | |
| 
 | |
| typedef struct _iot_crypto_async_sm2_gen_key_info_t {
 | |
|     /* crypto done callback function */
 | |
|     iot_crypto_async_done_func_t cb;
 | |
|     iot_crypto_async_hdr_t hdr;
 | |
|     uint8_t pub_key[IOT_CRYPTO_ASYNC_SM2_PUB_LEN];
 | |
|     uint8_t pri_key[IOT_CRYPTO_ASYNC_SM2_PRI_LEN];
 | |
|     iot_crypto_ret_sm2_kdf_gen_t gen_key;
 | |
| } iot_crypto_async_sm2_gen_key_info_t;
 | |
| 
 | |
| typedef struct _iot_crypto_async_sm2_gen_keypair_info_t {
 | |
|     /* crypto done callback function */
 | |
|     iot_crypto_async_done_func_t cb;
 | |
|     iot_crypto_async_hdr_t hdr;
 | |
|     iot_crypto_ret_sm2_gen_keypair_info_t ret_info;
 | |
| } iot_crypto_async_sm2_gen_keypair_info_t;
 | |
| 
 | |
| typedef struct _iot_crypto_async_ecdsa_gen_keypair_info_t {
 | |
|     /* crypto done callback function */
 | |
|     iot_crypto_async_done_func_t cb;
 | |
|     iot_crypto_async_hdr_t hdr;
 | |
|     iot_crypto_ret_ecdsa_gen_keypair_info_t ret_info;
 | |
| } iot_crypto_async_ecdsa_gen_keypair_info_t;
 | |
| 
 | |
| typedef struct _iot_crypto_async_sg_auth_sign_info {
 | |
|     /* crypto done callback function */
 | |
|     iot_crypto_async_done_func_t cb;
 | |
|     iot_crypto_async_hdr_t hdr;
 | |
|     uint32_t random_type;
 | |
|     uint32_t random_len;
 | |
|     uint32_t gen_key_len;
 | |
|     uint32_t chip_id_len;
 | |
|     uint8_t root_pub[IOT_CRYPTO_ASYNC_SM2_PUB_LEN];
 | |
|     uint8_t local_pub[IOT_CRYPTO_ASYNC_SM2_PUB_LEN];
 | |
|     uint8_t local_pri[IOT_CRYPTO_ASYNC_SM2_PRI_LEN];
 | |
|     uint8_t sign_r[IOT_CRYPTO_ASYNC_R_S_LEN];
 | |
|     uint8_t sign_s[IOT_CRYPTO_ASYNC_R_S_LEN];
 | |
|     uint8_t user_id[IOT_CRYPTO_ASYNC_SM2_USER_ID_LEN];
 | |
|     uint8_t chip_id[IOT_CRYPTO_ASYNC_CHIP_ID_LEN];
 | |
|     uint8_t auth_ecp;
 | |
|     uint8_t auth_pub[IOT_CRYPTO_ASYNC_SM2_PUB_LEN];
 | |
|     uint8_t random[0];
 | |
| } iot_crypto_async_sg_auth_sign_info_t;
 | |
| 
 | |
| typedef struct _iot_crypto_async_sg_auth_verify_info {
 | |
|     /* crypto done callback function */
 | |
|     iot_crypto_async_done_func_t cb;
 | |
|     iot_crypto_async_hdr_t hdr;
 | |
|     uint32_t random_type;
 | |
|     uint32_t random_len;
 | |
|     uint32_t gen_key_len;
 | |
|     uint32_t local_ecp;
 | |
|     uint32_t chip_id_len;
 | |
|     uint8_t root_pub[IOT_CRYPTO_ASYNC_SM2_PUB_LEN];
 | |
|     uint8_t local_pri[IOT_CRYPTO_ASYNC_SM2_PRI_LEN];
 | |
|     uint8_t sign_r[IOT_CRYPTO_ASYNC_R_S_LEN];
 | |
|     uint8_t sign_s[IOT_CRYPTO_ASYNC_R_S_LEN];
 | |
|     uint8_t random_r[IOT_CRYPTO_ASYNC_R_S_LEN];
 | |
|     uint8_t random_s[IOT_CRYPTO_ASYNC_R_S_LEN];
 | |
|     uint8_t user_id[IOT_CRYPTO_ASYNC_SM2_USER_ID_LEN];
 | |
|     uint8_t chip_id[IOT_CRYPTO_ASYNC_CHIP_ID_LEN];
 | |
|     uint8_t auth_ecp;
 | |
|     uint8_t auth_pub[IOT_CRYPTO_ASYNC_SM2_PUB_LEN];
 | |
|     uint8_t random[0];
 | |
| } iot_crypto_async_sg_auth_verify_info_t;
 | |
| 
 | |
| /* restore the pack status */
 | |
| #pragma pack(pop)
 | |
| 
 | |
| #if IOT_CRYPTO_ASYNC_SUPPORT
 | |
| 
 | |
| /**
 | |
|  * @brief iot_crypto_async_init         crypto async context init
 | |
|  *
 | |
|  * @retval: none
 | |
|  */
 | |
| void iot_crypto_async_init(void);
 | |
| 
 | |
| #else /* IOT_CRYPTO_ASYNC_SUPPORT */
 | |
| 
 | |
| #define iot_crypto_async_init()
 | |
| 
 | |
| #endif /* IOT_CRYPTO_ASYNC_SUPPORT */
 | |
| 
 | |
| #ifdef __cplusplus
 | |
| }
 | |
| #endif
 | |
| 
 | |
| #endif /* _IOT_CRYPTO_ASYNC_H_ */
 |