136 lines
		
	
	
		
			5.2 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			136 lines
		
	
	
		
			5.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_INTERNAL_H
 | |
| #define IOT_CRYPTO_INTERNAL_H
 | |
| 
 | |
| #include "iot_crypto_dsa_api.h"
 | |
| #include "iot_utils_api.h"
 | |
| #include "iot_crypto.h"
 | |
| 
 | |
| #ifdef __cplusplus
 | |
| extern "C" {
 | |
| #endif
 | |
| 
 | |
| uint32_t iot_crypto_ecdsa_with_sha256_sign_verify_internal(
 | |
|     ecdsa_ecp_t ecp,
 | |
|     const uint8_t *msg, uint32_t len,
 | |
|     const uint8_t *public_key, uint32_t public_key_len,
 | |
|     const uint8_t *r_buf, uint32_t r_buf_len,
 | |
|     const uint8_t *s_buf, uint32_t s_buf_len);
 | |
| 
 | |
| uint32_t iot_crypto_ecdsa_with_sha256_sign_internal(
 | |
|     ecdsa_ecp_t ecp, const uint8_t *msg, uint32_t len,
 | |
|     const uint8_t *pri_key, uint32_t pri_key_len,
 | |
|     uint8_t *r_buf, uint32_t *r_buf_len,
 | |
|     uint8_t *s_buf, uint32_t *s_buf_len);
 | |
| 
 | |
| uint32_t iot_crypto_sm2_sign_internal(uint8_t *message, uint32_t message_size,
 | |
|     uint8_t *ID, uint32_t ID_len, uint8_t *public_key, uint32_t public_key_len,
 | |
|     uint8_t *r, uint32_t *rlen, uint8_t *s, uint32_t *slen, uint8_t *private_key,
 | |
|     uint32_t private_key_len);
 | |
| 
 | |
| uint32_t iot_crypto_sm2_verify_internal(uint8_t *message,
 | |
|     uint32_t message_size, uint8_t *ID, uint32_t ID_len, uint8_t *public_key,
 | |
|     uint32_t public_key_len, uint8_t *r, uint32_t rlen, uint8_t *s,
 | |
|     uint32_t slen);
 | |
| 
 | |
| uint32_t iot_crypto_sm2_gen_share_key_internal(uint8_t *pub_key,
 | |
|     uint8_t *pri_key, uint8_t *gen_key, uint32_t gen_key_len);
 | |
| 
 | |
| uint32_t iot_crypto_ecdsa_gen_keypair_internal(
 | |
|     ecdsa_ecp_t ecp, uint8_t *public_key, uint32_t *public_key_len,
 | |
|     uint8_t *pri_key, uint32_t *pri_key_len);
 | |
| 
 | |
| uint32_t iot_crypto_sm2_gen_keypair_internal(uint8_t *public_key,
 | |
|     uint32_t *public_key_len, uint8_t *private_key, uint32_t *private_key_len);
 | |
| 
 | |
| uint32_t iot_crypto_sm2_encrypt_internal(uint8_t* message_plain,
 | |
|     uint32_t message_size, uint8_t* cipher_text, uint32_t *ciphertext_len,
 | |
|     uint8_t *pubkey);
 | |
| 
 | |
| uint32_t iot_crypto_sm2_decrypt_internal(uint8_t* cipher_text,
 | |
|     uint32_t ciphertext_len, uint8_t* message_plain, uint32_t *message_size,
 | |
|     uint8_t *prikey);
 | |
| 
 | |
| uint32_t iot_crypto_sm2_exchange_info_init_internal(uint8_t *pub_key_a,
 | |
|     uint32_t pub_key_a_len,uint8_t *pub_key_b, uint32_t pub_key_b_len,
 | |
|     uint8_t *pri_key, uint32_t pri_key_len, uint32_t key_len_in_bits,
 | |
|     sm2_exchange_info_t *sm2_info);
 | |
| 
 | |
| void iot_crypto_sm2_exchange_info_deinit_internal
 | |
|     (sm2_exchange_info_t *sm2_info);
 | |
| 
 | |
| uint32_t iot_crypto_sm2_exchange_req_step1_internal(uint8_t *ida,
 | |
|     uint32_t ida_len, uint8_t *idb, uint32_t idb_len, ecp_point_t *ra,
 | |
|     sm2_exchange_info_t *sm2_info);
 | |
| 
 | |
| uint32_t iot_crypto_sm2_exchange_req_step2_internal(ecp_point_t *rb,
 | |
|     sm2_exchange_info_t *sm2_info);
 | |
| 
 | |
| uint32_t iot_crypto_sm2_exchange_response_step1_internal(uint8_t *ida,
 | |
|     uint32_t ida_len, uint8_t *idb, uint32_t idb_len, ecp_point_t *ra,
 | |
|     ecp_point_t *rb, sm2_exchange_info_t *sm2_info);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_crypto_bignum_mul() -  X = A * B
 | |
|  * @param X:           result
 | |
|  * @param A:           operand A
 | |
|  * @param B:           operand B
 | |
|  *
 | |
|  * @retval:            error code. see CRYPTO_RET_XXX
 | |
|  */
 | |
| int iot_crypto_bignum_mul(uint32_t *X, uint32_t X_len, uint32_t *A,
 | |
|     uint32_t A_len, uint32_t *B, uint32_t B_len);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_crypto_bignum_mod() -  X = A mod B
 | |
|  * @param X:           result
 | |
|  * @param A:           operand A
 | |
|  * @param B:           operand B
 | |
|  *
 | |
|  * @retval:            error code. see CRYPTO_RET_XXX
 | |
|  */
 | |
| int iot_crypto_bignum_mod(uint32_t *X, uint32_t X_len, uint32_t *A,
 | |
|     uint32_t A_len, uint32_t *B, uint32_t B_len);
 | |
| 
 | |
| void iot_crypto_aes_ind_internal(SEC_SYS_AES_OPT_MODE opt_mode,
 | |
|     SEC_SYS_AES_CALC_MODE mode, uint8_t *indata, uint32_t indata_len,
 | |
|     uint8_t *outdata, uint32_t *outdata_len, uint8_t *aes_key,
 | |
|     uint32_t key_len, uint8_t aes_iv[16]);
 | |
| 
 | |
| uint32_t iot_crypto_sm3_internal(uint8_t *indata, uint32_t indata_len,
 | |
|     uint8_t *outdata, uint32_t outdata_len);
 | |
| 
 | |
| uint32_t iot_crypto_aes_ecb_with_key_internal(const uint8_t *key,
 | |
|     uint32_t keybits, uint8_t mode, uint32_t len, const uint8_t *input,
 | |
|     uint8_t *output);
 | |
| 
 | |
| uint32_t iot_crypto_aes_ctr_with_key_internal(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);
 | |
| 
 | |
| uint32_t iot_crypto_aes_cbc_with_key_internal(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);
 | |
| 
 | |
| void iot_crypto_dsa_init(void);
 | |
| 
 | |
| #ifdef __cplusplus
 | |
| }
 | |
| #endif
 | |
| 
 | |
| #endif //IOT_CRYPTO_INTERNAL_H
 |