101 lines
		
	
	
		
			3.2 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			101 lines
		
	
	
		
			3.2 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_LOCK_H_
 | |
| #define _IOT_CRYPTO_LOCK_H_
 | |
| 
 | |
| #ifdef __cplusplus
 | |
| extern "C" {
 | |
| #endif
 | |
| 
 | |
| #include "os_types.h"
 | |
| 
 | |
| /* crypto algorithm type */
 | |
| #define IOT_CRYPTO_ATYPE_ENC_DEC_AES                0
 | |
| #define IOT_CRYPTO_ATYPE_ENC_DEC_AES_GCM            1
 | |
| #define IOT_CRYPTO_ATYPE_ENC_DEC_AES_GCM_CERT       2
 | |
| #define IOT_CRYPTO_ATYPE_ENC_DEC_SM4                3
 | |
| #define IOT_CRYPTO_ATYPE_TRNG                       4
 | |
| #define IOT_CRYPTO_ATYPE_ENC_DEC_DES                5
 | |
| #define IOT_CRYPTO_ATYPE_ENC_DEC_SM2                6
 | |
| #define IOT_CRYPTO_ATYPE_SM2_SIGN                   7
 | |
| #define IOT_CRYPTO_ATYPE_SM2_VERIFY                 8
 | |
| #define IOT_CRYPTO_ATYPE_ECDSA_SIGN                 9
 | |
| #define IOT_CRYPTO_ATYPE_ECDSA_VERIFY               10
 | |
| #define IOT_CRYPTO_ATYPE_SHA_SM3                    11
 | |
| #define IOT_CRYPTO_ATYPE_KEYPAIR_ECDSA              12
 | |
| #define IOT_CRYPTO_ATYPE_KEYPAIR_SM2                13
 | |
| #define IOT_CRYPTO_ATYPE_SHAREKEY_SM2               14
 | |
| #define IOT_CRYPTO_ATYPE_CNT                        15
 | |
| 
 | |
| /* SM3_SHA hw plc_cpu/sec_cpu spinlock */
 | |
| #if IOT_SEC_CPU_SUPPORT
 | |
| 
 | |
| #include "cpu.h"
 | |
| #include "iot_spinlock.h"
 | |
| 
 | |
| /**
 | |
|  * @brief iot_crypto_sm3_sha_spin_lock      acquire crypto spinlock
 | |
|  *
 | |
|  * @retval:             none
 | |
|  */
 | |
| #define iot_crypto_sm3_sha_spin_lock()              \
 | |
|     iot_spinlock_lock(SPINLOCK_CRYPTO_SM3_SHA, (uint8_t)cpu_get_mhartid())
 | |
| 
 | |
| /**
 | |
|  * @brief iot_crypto_sm3_sha_spin_unlock    release crypto spinlock
 | |
|  *
 | |
|  * @retval:             none
 | |
|  */
 | |
| #define iot_crypto_sm3_sha_spin_unlock()            \
 | |
|     iot_spinlock_unlock(SPINLOCK_CRYPTO_SM3_SHA, (uint8_t)cpu_get_mhartid())
 | |
| 
 | |
| #else /* IOT_SEC_CPU_SUPPORT */
 | |
| 
 | |
| #define iot_crypto_sm3_sha_spin_lock()
 | |
| #define iot_crypto_sm3_sha_spin_unlock()
 | |
| 
 | |
| #endif /* IOT_SEC_CPU_SUPPORT */
 | |
| 
 | |
| /**
 | |
|  * @brief iot_crypto_acquire_mutex          acquire crypto lock
 | |
|  *
 | |
|  * @param type:         algorithm type, see IOT_CRYPTO_ATYPE_XXX
 | |
|  * @retval: none
 | |
|  */
 | |
| void iot_crypto_acquire_mutex(uint8_t type);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_crypto_release_mutex          release crypto lock
 | |
|  *
 | |
|  * @param type:         algorithm type, see IOT_CRYPTO_ATYPE_XXX
 | |
|  * @retval: none
 | |
|  */
 | |
| void iot_crypto_release_mutex(uint8_t type);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_crypto_lock_init              crypto lock context init
 | |
|  *
 | |
|  * @param type:         algorithm type, see IOT_CRYPTO_ATYPE_XXX
 | |
|  * @retval: none
 | |
|  */
 | |
| uint32_t iot_crypto_lock_init(void);
 | |
| 
 | |
| #ifdef __cplusplus
 | |
| }
 | |
| #endif
 | |
| 
 | |
| #endif /* _IOT_CRYPTO_LOCK_H_ */
 |