libraries/WM_Libraries/Platform/Common/crypto/wm_crypto_hard.c
int tls_crypto_crc_update(psCrcContext_t * ctx, unsigned char *in, u32 len)
{
	unsigned int sec_cfg, val;
	val = tls_reg_read32(HR_CRYPTO_SEC_CFG);
	sec_cfg =  (val & 0xF0000000) | (CRYPTO_METHOD_CRC << 16) | (ctx->type << 21) | (ctx->mode << 23) | (len & 0xFFFF); 
	tls_reg_write32(HR_CRYPTO_SEC_CFG, sec_cfg);
	if(ctx->mode & OUTPUT_REFLECT)
	{
		u8 ch_crc = 16;
		u32 state = 0;
		switch(ctx->type)
		{
			case CRYPTO_CRC_TYPE_8:
				ch_crc = 8;
				break;
			case CRYPTO_CRC_TYPE_16_MODBUS:
				ch_crc = 16;
				break;
			case CRYPTO_CRC_TYPE_16_CCITT:
				ch_crc = 16;
				break;
			case CRYPTO_CRC_TYPE_32:
				ch_crc = 32;
				break;
			default:
				break;
		}
		state = Reflect(ctx->state, ch_crc);
		tls_reg_write32(HR_CRYPTO_CRC_KEY, state);
	}
	else
		tls_reg_write32(HR_CRYPTO_CRC_KEY, ctx->state);
	
	tls_reg_write32(HR_CRYPTO_SRC_ADDR, (unsigned int)in);
	tls_reg_write32(HR_CRYPTO_SEC_CTRL, 0x1);//start crypto
	while (!crypto_complete)
	{

	}
	crypto_complete = 0;
	ctx->state = tls_reg_read32(HR_CRYPTO_CRC_RESULT); 
	return ERR_CRY_OK;
}
/**
 * @brief			This function updates the CRC value with a variable length bytes.
 *				This function may be called as many times as necessary, so the message may be processed in blocks.
 *
 * @param[in]		ctx 		Pointer to the CRC Context. 
 * @param[in]		in 		Pointer to a variable length bytes
 * @param[in]		len 		The bytes 's length 
 *
 * @retval		0		success 
 * @retval		other	failed	
 *
 * @note			None
 */
@brief                       This function updates the CRC value with a variable length bytes.
This function may be called as many times as necessary, so the message may be processed in blocks.

@param[in]           ctx             Pointer to the CRC Context.
@param[in]           in              Pointer to a variable length bytes
@param[in]           len             The bytes 's length

@retval              0               success
@retval              other   failed

@note                        None
@brief This function updates the CRC value with a variable length bytes . This function may be called as many times as necessary so the message may be processed in blocks . @param [ in ] ctx Pointer to the CRC Context . @param [ in ] in Pointer to a variable length bytes @param [ in ] len The bytes ' s length @retval 0 success @retval other failed @note None
int tls_crypto_crc_update(psCrcContext_t * ctx, unsigned char *in, u32 len)
{
	unsigned int sec_cfg, val;
	val = tls_reg_read32(HR_CRYPTO_SEC_CFG);
	sec_cfg =  (val & 0xF0000000) | (CRYPTO_METHOD_CRC << 16) | (ctx->type << 21) | (ctx->mode << 23) | (len & 0xFFFF); 
	tls_reg_write32(HR_CRYPTO_SEC_CFG, sec_cfg);
	if(ctx->mode & OUTPUT_REFLECT)
	{
		u8 ch_crc = 16;
		u32 state = 0;
		switch(ctx->type)
		{
			case CRYPTO_CRC_TYPE_8:
				ch_crc = 8;
				break;
			case CRYPTO_CRC_TYPE_16_MODBUS:
				ch_crc = 16;
				break;
			case CRYPTO_CRC_TYPE_16_CCITT:
				ch_crc = 16;
				break;
			case CRYPTO_CRC_TYPE_32:
				ch_crc = 32;
				break;
			default:
				break;
		}
		state = Reflect(ctx->state, ch_crc);
		tls_reg_write32(HR_CRYPTO_CRC_KEY, state);
	}
	else
		tls_reg_write32(HR_CRYPTO_CRC_KEY, ctx->state);
	tls_reg_write32(HR_CRYPTO_SRC_ADDR, (unsigned int)in);
	tls_reg_write32(HR_CRYPTO_SEC_CTRL, 0x1);
	while (!crypto_complete)
	{
	}
	crypto_complete = 0;
	ctx->state = tls_reg_read32(HR_CRYPTO_CRC_RESULT); 
	return ERR_CRY_OK;
}
int tls_crypto_crc_update ( psCrcContext_t * ctx , unsigned char * in , u32 len ) { unsigned int sec_cfg , val ; val = tls_reg_read32 ( HR_CRYPTO_SEC_CFG ) ; sec_cfg = ( val & 0xF0000000 ) | ( CRYPTO_METHOD_CRC << 16 ) | ( ctx -> type << 21 ) | ( ctx -> mode << 23 ) | ( len & 0xFFFF ) ; tls_reg_write32 ( HR_CRYPTO_SEC_CFG , sec_cfg ) ; if ( ctx -> mode & OUTPUT_REFLECT ) { u8 ch_crc = 16 ; u32 state = 0 ; switch ( ctx -> type ) { case CRYPTO_CRC_TYPE_8 : ch_crc = 8 ; break ; case CRYPTO_CRC_TYPE_16_MODBUS : ch_crc = 16 ; break ; case CRYPTO_CRC_TYPE_16_CCITT : ch_crc = 16 ; break ; case CRYPTO_CRC_TYPE_32 : ch_crc = 32 ; break ; default : break ; } state = Reflect ( ctx -> state , ch_crc ) ; tls_reg_write32 ( HR_CRYPTO_CRC_KEY , state ) ; } else tls_reg_write32 ( HR_CRYPTO_CRC_KEY , ctx -> state ) ; tls_reg_write32 ( HR_CRYPTO_SRC_ADDR , ( unsigned int ) in ) ; tls_reg_write32 ( HR_CRYPTO_SEC_CTRL , 0x1 ) ; while ( ! crypto_complete ) { } crypto_complete = 0 ; ctx -> state = tls_reg_read32 ( HR_CRYPTO_CRC_RESULT ) ; return ERR_CRY_OK ; }
@brief                       This function updates the CRC value with a variable length bytes.
@brief This function updates the CRC value with a variable length bytes .
//start crypto