libraries/WM_Libraries/Platform/Common/crypto/wm_crypto_hard.c
int tls_crypto_rc4(psCipherContext_t * ctx, unsigned char *in, unsigned char *out, u32 len)
{
	unsigned int sec_cfg, val;
	unsigned char *key = ctx->arc4.state;
	u32 keylen = ctx->arc4.byteCount;
	//memset((void *)HR_CRYPTO_KEY0, 0, 16);
	tls_crypto_clear_32reg(HR_CRYPTO_KEY0, 16);
	//memcpy((void *)HR_CRYPTO_KEY0, key, keylen);
	tls_crypto_write_32reg(HR_CRYPTO_KEY0, key, keylen);
	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_RC4 << 16) | (1 << SOFT_RESET_RC4) | (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 a variable length data stream according to RC4.
 *				The RC4 algorithm it generates a "keystream" which is simply XORed with the plaintext to produce the ciphertext stream. 
 *				Decryption is exactly the same as encryption. This function also decrypts a variable length data stream according to RC4.
 *
 * @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.
 *
 * @retval  		0  		success 
 * @retval  		other   	failed  
 *
 * @note             	None
 */
@brief               This function encrypts a variable length data stream according to RC4.
The RC4 algorithm it generates a "keystream" which is simply XORed with the plaintext to produce the ciphertext stream.
Decryption is exactly the same as encryption. This function also decrypts a variable length data stream according to RC4.

@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.

@retval              0               success
@retval              other           failed

@note                None
@brief This function encrypts a variable length data stream according to RC4 . The RC4 algorithm it generates a " keystream " which is simply XORed with the plaintext to produce the ciphertext stream . Decryption is exactly the same as encryption . This function also decrypts a variable length data stream according to RC4 . @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 . @retval 0 success @retval other failed @note None
int tls_crypto_rc4(psCipherContext_t * ctx, unsigned char *in, unsigned char *out, u32 len)
{
	unsigned int sec_cfg, val;
	unsigned char *key = ctx->arc4.state;
	u32 keylen = ctx->arc4.byteCount;
	tls_crypto_clear_32reg(HR_CRYPTO_KEY0, 16);
	tls_crypto_write_32reg(HR_CRYPTO_KEY0, key, keylen);
	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_RC4 << 16) | (1 << SOFT_RESET_RC4) | (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_rc4 ( psCipherContext_t * ctx , unsigned char * in , unsigned char * out , u32 len ) { unsigned int sec_cfg , val ; unsigned char * key = ctx -> arc4 . state ; u32 keylen = ctx -> arc4 . byteCount ; tls_crypto_clear_32reg ( HR_CRYPTO_KEY0 , 16 ) ; tls_crypto_write_32reg ( HR_CRYPTO_KEY0 , key , keylen ) ; 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_RC4 << 16 ) | ( 1 << SOFT_RESET_RC4 ) | ( 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 a variable length data stream according to RC4.
@brief This function encrypts a variable length data stream according to RC4 .
//memset((void *)HR_CRYPTO_KEY0, 0, 16); //memcpy((void *)HR_CRYPTO_KEY0, key, keylen); //start crypto