libraries/WM_Libraries/Platform/Common/crypto/wm_crypto_hard.c
int tls_crypto_3des_encrypt_decrypt(psCipherContext_t * ctx, unsigned char *in, unsigned char *out, u32 len, CRYPTO_WAY dec)
{
	unsigned int sec_cfg, val;
	u32 keylen = DES3_KEY_LEN;
	unsigned char *key = (unsigned char *)(unsigned char *)ctx->des3.key.ek[0];
	unsigned char *IV = ctx->des3.IV;
	CRYPTO_MODE cbc = (CRYPTO_MODE)(ctx->des3.key.ek[1][0] & 0xFF);
	//memset((void *)HR_CRYPTO_KEY0, 0, DES3_KEY_LEN);
	tls_crypto_clear_32reg(HR_CRYPTO_KEY0, DES3_KEY_LEN);
	//memcpy((void *)HR_CRYPTO_KEY0, key, keylen);
	tls_crypto_write_32reg(HR_CRYPTO_KEY0, key, keylen);
	//memset((void *)HR_CRYPTO_IV0, 0, DES3_IV_LEN);
	tls_crypto_clear_32reg(HR_CRYPTO_IV0, DES3_IV_LEN);
	//memcpy((void *)HR_CRYPTO_IV0, IV, DES3_IV_LEN);
	tls_crypto_write_32reg(HR_CRYPTO_IV0, IV, DES3_IV_LEN);
	tls_reg_write32(HR_CRYPTO_SRC_ADDR, (unsigned int)in);
	tls_reg_write32(HR_CRYPTO_DEST_ADDR, (unsigned int)out);
	val = tls_reg_read32(HR_CRYPTO_SEC_CFG);
	sec_cfg = (val & 0xF0000000) |(CRYPTO_METHOD_3DES << 16) | (1 << SOFT_RESET_DES) | (dec << 20) | (cbc << 21) | (len & 0xFFFF); 
	tls_reg_write32(HR_CRYPTO_SEC_CFG, sec_cfg);
	tls_reg_write32(HR_CRYPTO_SEC_CTRL, 0x1);//start crypto
	while (!crypto_complete)
	{

	}
	crypto_complete = 0;
	return ERR_CRY_OK;
}
/**
 * @brief			This function encrypts or decrypts a variable length data stream according to 3DES.
 *
 * @param[in]		ctx 		Pointer to the Cipher Context.
 * @param[in]		in 		Pointer to the input plaintext data stream(or the encrypted text data stream) of variable length.
 * @param[in]		out 		Pointer to the resulting ciphertext data stream.
 * @param[in]		len 		Length of the plaintext data stream in octets.
 * @param[in]		dec 		The cryption way which indicates encryption or decryption.
 *
 * @retval		0  		success 
 * @retval		other	failed	
 *
 * @note			None
 */
@brief                       This function encrypts or decrypts a variable length data stream according to 3DES.
@param[in]           ctx             Pointer to the Cipher Context.
@param[in]           in              Pointer to the input plaintext data stream(or the encrypted text data stream) of variable length.
@param[in]           out             Pointer to the resulting ciphertext data stream.
@param[in]           len             Length of the plaintext data stream in octets.
@param[in]           dec             The cryption way which indicates encryption or decryption.

@retval              0               success
@retval              other   failed

@note                        None
@brief This function encrypts or decrypts a variable length data stream according to 3DES . @param [ in ] ctx Pointer to the Cipher Context . @param [ in ] in Pointer to the input plaintext data stream ( or the encrypted text data stream ) of variable length . @param [ in ] out Pointer to the resulting ciphertext data stream . @param [ in ] len Length of the plaintext data stream in octets . @param [ in ] dec The cryption way which indicates encryption or decryption . @retval 0 success @retval other failed @note None
int tls_crypto_3des_encrypt_decrypt(psCipherContext_t * ctx, unsigned char *in, unsigned char *out, u32 len, CRYPTO_WAY dec)
{
	unsigned int sec_cfg, val;
	u32 keylen = DES3_KEY_LEN;
	unsigned char *key = (unsigned char *)(unsigned char *)ctx->des3.key.ek[0];
	unsigned char *IV = ctx->des3.IV;
	CRYPTO_MODE cbc = (CRYPTO_MODE)(ctx->des3.key.ek[1][0] & 0xFF);
	tls_crypto_clear_32reg(HR_CRYPTO_KEY0, DES3_KEY_LEN);
	tls_crypto_write_32reg(HR_CRYPTO_KEY0, key, keylen);
	tls_crypto_clear_32reg(HR_CRYPTO_IV0, DES3_IV_LEN);
	tls_crypto_write_32reg(HR_CRYPTO_IV0, IV, DES3_IV_LEN);
	tls_reg_write32(HR_CRYPTO_SRC_ADDR, (unsigned int)in);
	tls_reg_write32(HR_CRYPTO_DEST_ADDR, (unsigned int)out);
	val = tls_reg_read32(HR_CRYPTO_SEC_CFG);
	sec_cfg = (val & 0xF0000000) |(CRYPTO_METHOD_3DES << 16) | (1 << SOFT_RESET_DES) | (dec << 20) | (cbc << 21) | (len & 0xFFFF); 
	tls_reg_write32(HR_CRYPTO_SEC_CFG, sec_cfg);
	tls_reg_write32(HR_CRYPTO_SEC_CTRL, 0x1);
	while (!crypto_complete)
	{
	}
	crypto_complete = 0;
	return ERR_CRY_OK;
}
int tls_crypto_3des_encrypt_decrypt ( psCipherContext_t * ctx , unsigned char * in , unsigned char * out , u32 len , CRYPTO_WAY dec ) { unsigned int sec_cfg , val ; u32 keylen = DES3_KEY_LEN ; unsigned char * key = ( unsigned char * ) ( unsigned char * ) ctx -> des3 . key . ek [ 0 ] ; unsigned char * IV = ctx -> des3 . IV ; CRYPTO_MODE cbc = ( CRYPTO_MODE ) ( ctx -> des3 . key . ek [ 1 ] [ 0 ] & 0xFF ) ; tls_crypto_clear_32reg ( HR_CRYPTO_KEY0 , DES3_KEY_LEN ) ; tls_crypto_write_32reg ( HR_CRYPTO_KEY0 , key , keylen ) ; tls_crypto_clear_32reg ( HR_CRYPTO_IV0 , DES3_IV_LEN ) ; tls_crypto_write_32reg ( HR_CRYPTO_IV0 , IV , DES3_IV_LEN ) ; tls_reg_write32 ( HR_CRYPTO_SRC_ADDR , ( unsigned int ) in ) ; tls_reg_write32 ( HR_CRYPTO_DEST_ADDR , ( unsigned int ) out ) ; val = tls_reg_read32 ( HR_CRYPTO_SEC_CFG ) ; sec_cfg = ( val & 0xF0000000 ) | ( CRYPTO_METHOD_3DES << 16 ) | ( 1 << SOFT_RESET_DES ) | ( dec << 20 ) | ( cbc << 21 ) | ( len & 0xFFFF ) ; tls_reg_write32 ( HR_CRYPTO_SEC_CFG , sec_cfg ) ; tls_reg_write32 ( HR_CRYPTO_SEC_CTRL , 0x1 ) ; while ( ! crypto_complete ) { } crypto_complete = 0 ; return ERR_CRY_OK ; }
@brief                       This function encrypts or decrypts a variable length data stream according to 3DES.
@brief This function encrypts or decrypts a variable length data stream according to 3DES .
//memset((void *)HR_CRYPTO_KEY0, 0, DES3_KEY_LEN); //memcpy((void *)HR_CRYPTO_KEY0, key, keylen); //memset((void *)HR_CRYPTO_IV0, 0, DES3_IV_LEN); //memcpy((void *)HR_CRYPTO_IV0, IV, DES3_IV_LEN); //start crypto