Index: Yc_aes.h
===================================================================
--- /YC3121_SDK/fw/crypt/Yc_aes.h	(revision 797)
+++ /YC3121_SDK/fw/crypt/Yc_aes.h	(working copy)
@@ -22,7 +22,7 @@
 	AES_192 = 192,
 	AES_256 = 256
 }AES_KeySizeTypeDef;
-	
+
 typedef uint8_t AES_IvKeyTypeDef[AES_IV_SIZE];
 
 /**
@@ -44,7 +44,7 @@
 uint32_t AES_Enc(PACK_ModeTypeDef pack_mode,
                  uint8_t *output, uint32_t obytes,
                  uint8_t *input, uint32_t ibytes,
-                 uint8_t *key, AES_KeySizeTypeDef ksize, 
+                 uint8_t *key, AES_KeySizeTypeDef ksize,
                  AES_IvKeyTypeDef iv,
                  rng_callback f_rng, void *p_rng);
 
@@ -66,8 +66,8 @@
 uint32_t AES_Dec(PACK_ModeTypeDef pack_mode,
                  uint8_t *output, uint32_t obytes,
                  uint8_t *input, uint32_t ibytes,
-                 uint8_t *key, AES_KeySizeTypeDef ksize, 
+                 uint8_t *key, AES_KeySizeTypeDef ksize,
                  AES_IvKeyTypeDef iv,
                  rng_callback f_rng, void *p_rng);
- 
+
 #endif
Index: Yc_aes.c
===================================================================
--- /YC3121_SDK/fw/crypt/Yc_aes.c	(revision 797)
+++ /YC3121_SDK/fw/crypt/Yc_aes.c	(working copy)
@@ -9,7 +9,7 @@
 	if(iv == NULL)
 		uint8touint32(dst,src);
 	else
-		*dst = (src[0]^iv[0])+((src[1]^iv[1])<<8)+((src[2]^iv[2])<<16)+((src[3]^iv[3])<<24);	
+		*dst = (src[0]^iv[0])+((src[1]^iv[1])<<8)+((src[2]^iv[2])<<16)+((src[3]^iv[3])<<24);
 }
 
 static void int2char_iv(uint8_t *dst,uint32_t *src,uint8_t *iv)
@@ -34,7 +34,7 @@
 	uint32_t StartPosition;
 	uint32_t *u1,*u2;
 	uint8_t *c1,*c2;
-	
+
 	if(wlen == 0)
 		return ;
 	cpu_open_uniform_branch_timing();
@@ -93,7 +93,7 @@
 
 
 static uint32_t aes_common(CRYPT_ModeTypeDef ctpye,PACK_ModeTypeDef pack_mode,uint8_t *output, uint32_t obytes,
-								uint8_t *input, uint32_t ibytes,uint8_t *key, AES_KeySizeTypeDef ksize, 
+								uint8_t *input, uint32_t ibytes,uint8_t *key, AES_KeySizeTypeDef ksize,
 								AES_IvKeyTypeDef iv,rng_callback f_rng, void *p_rng)
 {
 	uint32_t i,j;
@@ -101,7 +101,7 @@
 	uint32_t rand[2]={0};
 	uint32_t fkey[8]={0};
 	uint8_t temp[16]={0};
-	
+
 	if(ibytes%16 != 0)
 		return RET_AES_INPUT_SIZE_ERROR;
 	if(obytes < ibytes)
@@ -110,22 +110,22 @@
 		return RET_AES_PACK_MODE_ERROR;
 	if((ksize != AES_128) && (ksize != AES_192) && (ksize != AES_256) )
 		return RET_AES_KEY_SIZE_ERROR;
-		
+
 	(*f_rng)((uint8_t *)rand_key,8,NULL);
 	(*f_rng)((uint8_t *)rand_data,8,NULL);
 	if(aes_checkkey(key,ksize,rand_key[0]) != RET_AES_KEY_IS_OK)
 		return RET_AES_KEY_IS_NULL;
-		
+
 	(*f_rng)((uint8_t *)rand,8,NULL);
 	(*f_rng)((uint8_t *)fkey,32,NULL);
 	mem_rollcpy(AES_RAND_REG0,rand,2,rand[0]);
 	mem_rollcpy(AES_FKEY_REG0,fkey,8,fkey[0]);
 
 	enable_clock(CLKCLS_AES);
-	AES_CNTRL_REG = 0;	
-	
+	AES_CNTRL_REG = 0;
+
 	mem_rollcpy_char2int(CHAR2INT,(uint32_t *)AES_KEY_REG0, key, NULL,0,0,ksize>>5, rand_key[0]);
-	for(j=0;j<ibytes; j = j+ 16)	
+	for(j=0;j<ibytes; j = j+ 16)
 	{
 		if(pack_mode == CBC && ctpye == ENC)
 		{
@@ -145,29 +145,29 @@
 					AES_CNTRL_REG |= AES_CNTRL_KEY_SEL_128;
 				else
 					goto RETURN_AES_FAILUER;
-		
-	 	AES_CNTRL_REG |= AES_CNTRL_ENABLE_RAND |(ctpye == DEC?AES_CNTRL_DEC : AES_CNTRL_ENC);
+
+        AES_CNTRL_REG |= AES_CNTRL_ENABLE_RAND |(ctpye == DEC?AES_CNTRL_DEC : AES_CNTRL_ENC);
 		AES_CNTRL_REG |= AES_CNTRL_REG_START;
-	 	while(AES_CNTRL_REG & AES_CNTRL_REG_START);
+        while(AES_CNTRL_REG & AES_CNTRL_REG_START);
 
-	 	if(pack_mode == CBC && ctpye == DEC)
-	 	{
-	 		if(j == 0)
-				mem_rollcpy_char2int(INT2CHAR,output, (uint32_t *)AES_DATA_REG0,iv, j, 0,4, rand_data[0]>>3);				
+        if(pack_mode == CBC && ctpye == DEC)
+        {
+            if(j == 0)
+				mem_rollcpy_char2int(INT2CHAR,output, (uint32_t *)AES_DATA_REG0,iv, j, 0,4, rand_data[0]>>3);
 			else
-				mem_rollcpy_char2int(INT2CHAR,output, (uint32_t *)AES_DATA_REG0, input,j, j-16,4, rand_data[0]>>4);				
+				mem_rollcpy_char2int(INT2CHAR,output, (uint32_t *)AES_DATA_REG0, input,j, j-16,4, rand_data[0]>>4);
 		}
 		else
-			mem_rollcpy_char2int(INT2CHAR,output, (uint32_t *)AES_DATA_REG0,NULL, j, 0,4, rand_data[0]>>5);				
-	}	
+			mem_rollcpy_char2int(INT2CHAR,output, (uint32_t *)AES_DATA_REG0,NULL, j, 0,4, rand_data[0]>>5);
+	}
 
 	if(mem_rollcmp_char(key, (uint8_t *)AES_KEY_REG0, ksize>>3,rand_key[1]) !=CMPOK)
 		goto RETURN_AES_FAILUER;
 	if(mem_rollcmp_char(key, (uint8_t *)AES_KEY_REG0, ksize>>3,rand_key[1]>>1) !=CMPOK)
 		goto RETURN_AES_FAILUER;
-		
-	AES_CNTRL_REG = 0;	
-	for(j=0;j<ibytes; j = j+ 16)	
+
+	AES_CNTRL_REG = 0;
+	for(j=0;j<ibytes; j = j+ 16)
 	{
 		if(pack_mode == CBC && ctpye == DEC)
 		{
@@ -187,58 +187,58 @@
 					AES_CNTRL_REG |= AES_CNTRL_KEY_SEL_128;
 				else
 					goto RETURN_AES_FAILUER;
-		
-	 	AES_CNTRL_REG |= AES_CNTRL_ENABLE_RAND |(ctpye == ENC?AES_CNTRL_DEC : AES_CNTRL_ENC);
+
+        AES_CNTRL_REG |= AES_CNTRL_ENABLE_RAND |(ctpye == ENC?AES_CNTRL_DEC : AES_CNTRL_ENC);
 		AES_CNTRL_REG |= AES_CNTRL_REG_START;
-	 	while(AES_CNTRL_REG & AES_CNTRL_REG_START);
+        while(AES_CNTRL_REG & AES_CNTRL_REG_START);
 
 		if(pack_mode == CBC && ctpye == ENC)
-	 	{
-	 		if(j == 0)
-				mem_rollcpy_char2int(INT2CHAR,temp, (uint32_t *)AES_DATA_REG0,iv, 0, 0,4, rand_data[1]>>3);				
+        {
+            if(j == 0)
+				mem_rollcpy_char2int(INT2CHAR,temp, (uint32_t *)AES_DATA_REG0,iv, 0, 0,4, rand_data[1]>>3);
 			else
-				mem_rollcpy_char2int(INT2CHAR,temp, (uint32_t *)AES_DATA_REG0, output,0, j-16,4, rand_data[1]>>4);				
+				mem_rollcpy_char2int(INT2CHAR,temp, (uint32_t *)AES_DATA_REG0, output,0, j-16,4, rand_data[1]>>4);
 		}
 		else
-			mem_rollcpy_char2int(INT2CHAR,temp, (uint32_t *)AES_DATA_REG0,NULL, 0, 0,4, rand_data[1]>>5);				
+			mem_rollcpy_char2int(INT2CHAR,temp, (uint32_t *)AES_DATA_REG0,NULL, 0, 0,4, rand_data[1]>>5);
 
 		if (mem_rollcmp_char(input+j,temp,16,rand_data[1]>>6)!=CMPOK)
 			goto RETURN_AES_FAILUER;
 		if (mem_rollcmp_char(input+j,temp,16,rand_data[1]>>7)!=CMPOK)
 			goto RETURN_AES_FAILUER;
-	}	
-	
+	}
+
 	if(mem_rollcmp_char(key, (uint8_t *)AES_KEY_REG0, ksize>>3,rand_key[1]>>2) !=CMPOK)
 		goto RETURN_AES_FAILUER;
 	if(mem_rollcmp_char(key, (uint8_t *)AES_KEY_REG0, ksize>>3,rand_key[1]>>3) !=CMPOK)
 		goto RETURN_AES_FAILUER;
 
-	mem_set((uint32_t *)AES_DATA_REG0,0,4); 	
-	mem_set((uint32_t *)AES_KEY_REG0,0,8); 	
+	mem_set((uint32_t *)AES_DATA_REG0,0,4);
+	mem_set((uint32_t *)AES_KEY_REG0,0,8);
 	return RET_AES_SUCCESS;
 
 RETURN_AES_FAILUER:
-	mem_set((uint32_t *)AES_DATA_REG0,0,4); 	
-	mem_set((uint32_t *)AES_KEY_REG0,0,8); 
-	for(j=0;j<obytes; j++)	
+	mem_set((uint32_t *)AES_DATA_REG0,0,4);
+	mem_set((uint32_t *)AES_KEY_REG0,0,8);
+	for(j=0;j<obytes; j++)
 		output[j] = 0;
 	return RET_AES_FAILURE;
-	
+
 }
 
 uint32_t AES_Enc(PACK_ModeTypeDef pack_mode,uint8_t *output, uint32_t obytes,
-					uint8_t *input, uint32_t ibytes,uint8_t *key, AES_KeySizeTypeDef ksize, 
+					uint8_t *input, uint32_t ibytes,uint8_t *key, AES_KeySizeTypeDef ksize,
 					AES_IvKeyTypeDef iv,rng_callback f_rng, void *p_rng)
 {
 	return aes_common(ENC,pack_mode,output,obytes,input,ibytes,key,ksize,iv,f_rng, p_rng);
-}					
+}
 
 uint32_t AES_Dec(PACK_ModeTypeDef pack_mode,uint8_t *output, uint32_t obytes,
-					uint8_t *input, uint32_t ibytes,uint8_t *key, AES_KeySizeTypeDef ksize, 
+					uint8_t *input, uint32_t ibytes,uint8_t *key, AES_KeySizeTypeDef ksize,
 					AES_IvKeyTypeDef iv,rng_callback f_rng, void *p_rng)
 {
 	return aes_common(DEC,pack_mode,output,obytes,input,ibytes,key,ksize,iv,f_rng, p_rng);
 }
- 
+
 
 
Index: libyc_crypt.a
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: yc_calc.h
===================================================================
--- /YC3121_SDK/fw/crypt/yc_calc.h	(revision 797)
+++ /YC3121_SDK/fw/crypt/yc_calc.h	(working copy)
@@ -26,7 +26,7 @@
 #define CALC_POLL  0
 #define CALC_IDLE  1
 
-//the values of the parameter index in function  calc_run() 
+//the values of the parameter index in function  calc_run()
 #define FUNC_MUL           0   //multiplication
 #define FUNC_DIV           1   //division
 #define FUNC_MODEXP        2   //modular exponentiation
@@ -47,8 +47,8 @@
 #define RET_CALC_IMPLEMENT_SUCCESS       (('R'<<24)|('E'<<16)|('I'<<8)|('S'))  //0x52454953
 #define RET_CALC_GCD_NOT_ONE             (('R'<<24)|('G'<<16)|('N'<<8)|('O'))
 
-#define CMPOK        0xA55AA55A 
-#define CMPERROR     0x5AA55AA5 
+#define CMPOK        0xA55AA55A
+#define CMPERROR     0x5AA55AA5
 
 //function
 void calc_interrupt(void);
@@ -95,7 +95,7 @@
 int mem_rollcmp(volatile uint32_t *indata1,uint32_t *indata2,uint32_t wlen, uint32_t startflag);
 int mem_rollcmp_char(uint8_t *indata1,uint8_t *indata2,uint32_t wlen, uint32_t startflag);
 unsigned int calculatexor(unsigned int *data,unsigned int initdata,int len);
- void memcpy_r(uint8_t *a,uint8_t *b,uint32_t len);
+void memcpy_r(uint8_t *a,uint8_t *b,uint32_t len);
 uint32_t mem_rollcpy(volatile uint32_t *result,uint32_t *content,uint32_t wlen, uint32_t startflag);
 void mem_rollcpy_r_char( uint8_t *result,uint8_t *content,uint32_t wlen, uint32_t startflag);
 uint32_t mem_rollcpy_char( uint8_t *result,uint8_t *content,uint32_t wlen, uint32_t startflag);
Index: yc_calc.c
===================================================================
--- /YC3121_SDK/fw/crypt/yc_calc.c	(revision 797)
+++ /YC3121_SDK/fw/crypt/yc_calc.c	(working copy)
@@ -1,25 +1,25 @@
 #include "yc_calc.h"
 
 
-const  unsigned int  CONST_LONG_ONE[64]  = {1, 0, 0, 0,0, 0, 0, 0, 
-									        0, 0, 0, 0,0, 0, 0, 0, 
-									        0, 0, 0, 0, 0, 0, 0, 0, 
+const  unsigned int  CONST_LONG_ONE[64]  = {1, 0, 0, 0,0, 0, 0, 0,
+									        0, 0, 0, 0,0, 0, 0, 0,
+									        0, 0, 0, 0, 0, 0, 0, 0,
+									        0, 0, 0, 0, 0, 0, 0, 0,
+									        0, 0, 0, 0, 0, 0, 0, 0,
+									        0, 0, 0, 0, 0, 0, 0, 0,
 									        0, 0, 0, 0, 0, 0, 0, 0,
-									        0, 0, 0, 0, 0, 0, 0, 0, 
-									        0, 0, 0, 0, 0, 0, 0, 0, 
-									        0, 0, 0, 0, 0, 0, 0, 0, 
 									        0, 0, 0, 0, 0, 0, 0, 0	} ;
-const  unsigned int  CONST_LONG_FFFFFFFF[64]  = { 0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF,0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF, 
-									        	0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF,0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF, 
-									        	0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF,0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF, 
-									        	0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF,0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF, 
-									      		0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF,0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF, 
-									        	0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF,0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF, 
-									        	0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF,0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF, 
+const  unsigned int  CONST_LONG_FFFFFFFF[64]  = { 0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF,0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF,
+									        	0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF,0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF,
+									        	0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF,0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF,
+									        	0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF,0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF,
+									      		0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF,0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF,
+									        	0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF,0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF,
+									        	0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF,0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF,
 									        	0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF,0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF, 0XFFFFFFFF};
 
 
-//#define AMBA 
+//#define AMBA
 uint32_t calc_const_c_base(uint32_t *result, uint32_t *p, uint32_t len, uint32_t config);
 uint32_t calc_modmul_base(uint32_t *result, calc_operand *operand, uint32_t len, uint32_t config);
 uint32_t calc_modmul2_base(uint32_t *result, uint32_t *a,volatile uint32_t *b, uint32_t *c, uint32_t len, uint32_t config);
@@ -27,6 +27,7 @@
 
 void calc_init()
 {
+    SYSCTRL_RSACLK = 7;
 	enable_clock(CLKCLS_RSA);
 }
 
@@ -39,7 +40,7 @@
 * Return value: none
 ***************************************************************************
 */
-#ifdef AMBA 
+#ifdef AMBA
 void calc_interrupt(void)
 {
 	REINT |= REINT_rsa_int;
@@ -51,21 +52,21 @@
 * Name: calc_config
 * Description: Configure the parameters of RSA.
 * Input:
-		 config - CALC_IDLE indicates idlerun mode.
-                  CALC_POLL indicates poll mode.
+		config - CALC_IDLE indicates idlerun mode.
+				CALC_POLL indicates poll mode.
 * Output: none
 * Return value: none
 ***************************************************************************
 */
 void calc_config(uint32_t config)
 {
-	
+
 	//configure RECR register
 	if(config != CALC_IDLE)
 		RECR &= ~RECR_idle_run;
 	else
 		RECR |= RECR_idle_run;
-	
+
 	RECR |= RECR_bus_crypt_en;
 }
 
@@ -73,18 +74,18 @@
 ***************************************************************************
 * Name: calc_setsecurity
 * Description: Configure security measures for modular exponentiation operation
-* Input: config - 
-		bit0~1: 
+* Input: config -
+		bit0~1:
 			0 - disable the measure of random performance
     		1 - modular square operation is performed randomly
     		2 - modular multiplication operation is performed randomly
     		3 - both modular multiplication and modular square are performed randomly
     	bit2:
-       		0 - Duty Ratio 1/2
-       		1 - Duty Ratio 1/4
+			0 - Duty Ratio 1/2
+			1 - Duty Ratio 1/4
     	bit3:
-       		0 - disable the measure of using fixed time in modular exponentiation. 
-       		1 - modular exponentiation operation is performed in fixed time.
+			0 - disable the measure of using fixed time in modular exponentiation.
+			1 - modular exponentiation operation is performed in fixed time.
 * Output: none
 * Return value: none
 ***************************************************************************
@@ -110,7 +111,7 @@
 	//select hardware function and run
 	REFR = index;
 	RECR |= RECR_start;
-	
+
 	if(RECR & RECR_idle_run) //idlerun
 	{
 		do{
@@ -129,13 +130,13 @@
 		while(RECR & RECR_start);
 #ifdef AMBA
 	calc_interrupt();
-#endif	
+#endif
 	//return value
 	if (RESR & RESR_error_flag)
 		return RET_CALC_FUNCTION_ID_ERROR;
 	if (RESR & RESR_opdata_error)
 		return RET_CALC_OPERAND_LENGTH_ERROR;
-	return RET_CALC_IMPLEMENT_SUCCESS;	
+	return RET_CALC_IMPLEMENT_SUCCESS;
 }
 
 /*
@@ -143,10 +144,10 @@
 * Name: calc_add
 * Description: Perform addition operation of big number
 * Input: a - a pointer to the augend.
-		 b - a pointer to the addend.
-		 len - the word-length of the value pointed to by a or b.
-* Output: result - result is a pointer to a variable of len words. The 
-		  result of addition will be stored in this variable.
+		b - a pointer to the addend.
+		len - the word-length of the value pointed to by a or b.
+* Output: result - result is a pointer to a variable of len words. The
+		result of addition will be stored in this variable.
 * Return value: the value of carrying in addition operation.
 ***************************************************************************
 */
@@ -155,7 +156,7 @@
 	uint32_t  carry=0;
 	uint32_t i;
 	uint32_t j;
-	unsigned long long temp; 
+	unsigned long long temp;
 
 //	result[0]=a[0]+b[0];
 	for(i=0;i<len;i++)
@@ -182,7 +183,7 @@
 		mrs i,CPSR            //read the carrying from CPSR
 	}
 	carry=(i>>29) & 1;
-*/	
+*/
 
 	return carry;
 }
@@ -191,10 +192,10 @@
 * Name: calc_sub
 * Description: Perform subtraction operation of big number.
 * Input: a - a pointer to the minuend.
-		 b - a pointer to the subtrahend.
-		 len - the word-length of the value pointed to by a or b.
-* Output: result - result is a pointer to a variable of len words. The 
-		  result of subtraction will be stored in this variable.
+		b - a pointer to the subtrahend.
+		len - the word-length of the value pointed to by a or b.
+* Output: result - result is a pointer to a variable of len words. The
+		result of subtraction will be stored in this variable.
 * Return value: the value of borrowing in subtraction operation.
 ***************************************************************************
 */
@@ -204,11 +205,11 @@
 	uint32_t borrow=0;
 	uint32_t i;
 	uint32_t temp;
-//	long long temp; 
+//	long long temp;
 	for(i=0;i<len;i++)
 	{
 		if (a[i] >= borrow)
-		{	
+		{
 			flag = 0;
 		}
 		else
@@ -220,20 +221,20 @@
 		if(temp>=b[i])
 		{
 			result[i] = temp-b[i];
-			borrow = 0;			
+			borrow = 0;
 		}
 		else
 		{
 			result[i] = 0x100000000-b[i]+temp;
 			borrow = 1;
 		}
-		
+
 		if (flag == 1)
 		{
 			borrow = 1;
 		}
 	}
-	
+
 /*	__asm
 	(
 		"mov i,#1"
@@ -256,11 +257,11 @@
 * Name: calc_modadd_1
 * Description: Perform modular addition operation of big number and Perform modular subtraction operation of big number.
 * Input: a - a pointer to the augend.
-		 b - a pointer to the addend.
-		 p - a pointer to the modulus.
-		 len - the word-length of the value pointed to by a, b or p.
-* Output: result - result is a pointer to a variable of len words. The 
-		  result of modular addition will be stored in this variable.
+		b - a pointer to the addend.
+		p - a pointer to the modulus.
+		len - the word-length of the value pointed to by a, b or p.
+* Output: result - result is a pointer to a variable of len words. The
+		result of modular addition will be stored in this variable.
 * Return value: none
 ***************************************************************************
 */
@@ -283,7 +284,7 @@
 
 	carry=calc_add(res,a,b,len);                  //a+b
 	res[len] = carry;
-	
+
 	if ((carry != 0) || mem_cmp(res,p,len)!=SMALLER)
 	{
 		calc_div(div_q,div_r,res,p,len+1,len);
@@ -299,7 +300,7 @@
 	{
 		*(result+i) = *pdata++;
 	}
-	
+
 }
 
 
@@ -308,11 +309,11 @@
 * Name: calc_modadd
 * Description: Perform modular addition operation of big number.
 * Input: a - a pointer to the augend.
-		 b - a pointer to the addend.
-		 p - a pointer to the modulus.
-		 len - the word-length of the value pointed to by a, b or p.
-* Output: result - result is a pointer to a variable of len words. The 
-		  result of modular addition will be stored in this variable.
+		b - a pointer to the addend.
+		p - a pointer to the modulus.
+		len - the word-length of the value pointed to by a, b or p.
+* Output: result - result is a pointer to a variable of len words. The
+		result of modular addition will be stored in this variable.
 * Return value: none
 ***************************************************************************
 */
@@ -336,11 +337,11 @@
 * Name: calc_modsub
 * Description: Perform modular subtraction operation of big number.
 * Input: a - a pointer to the minuend
-		 b - a pointer to the subtrahend
-		 p - a pointer to the modulus
-		 len - the word-length of the value pointed to by a, b or p.
-* Output: result - result is a pointer to a variable of len words. The 
-		  result of modular subtraction will be stored in this variable.
+		b - a pointer to the subtrahend
+		p - a pointer to the modulus
+		len - the word-length of the value pointed to by a, b or p.
+* Output: result - result is a pointer to a variable of len words. The
+		result of modular subtraction will be stored in this variable.
 * Return value: none
 ***************************************************************************
 */
@@ -360,10 +361,10 @@
 * Name: calc_xor
 * Description: Perform exclusive-OR operation of big number.
 * Input: a - a pointer to an operand.
-		 b - a pointer to the other operand.
-		 len - the word-length of the value pointed to by a or b.
-* Output: result - result is a pointer to a variable of len words. The 
-		  result of exclusive-OR will be stored in this variable.
+		b - a pointer to the other operand.
+		len - the word-length of the value pointed to by a or b.
+* Output: result - result is a pointer to a variable of len words. The
+		result of exclusive-OR will be stored in this variable.
 * Return value: none
 ***************************************************************************
 */
@@ -385,7 +386,7 @@
 	{
 		result[i] = a[i] ^b[i];
 	}
-	
+
 }
 
 /*
@@ -393,10 +394,10 @@
 * Name: calc_mul
 * Description: Perform multiplication operation of big number.
 * Input: a - a pointer to the multiplicand.
-		 b - a pointer to the multiplier.
-		 len_a - the word-length of the value pointed to by a. 
-		 len_b - the word-length of the value pointed to by b.
-* Output: result - a pointer to a variable of (len_a+len_b) words. The 
+		b - a pointer to the multiplier.
+		len_a - the word-length of the value pointed to by a.
+		len_b - the word-length of the value pointed to by b.
+* Output: result - a pointer to a variable of (len_a+len_b) words. The
 		  result of multiplication will be stored in this variable.
 * Return value: RET_CALC_FUNCTION_ID_ERROR: the identity of function is wrong
 				RET_CALC_OPERAND_LENGTH_ERROR: the length of operand is wrong
@@ -407,40 +408,40 @@
 {
 	uint32_t value;
 	calc_init();
-	
+
 	//load all the operands to the registers.
 	if(a != NULL)
-		mem_cpy(REDAR, a, len_a); 
+		mem_cpy(REDAR, a, len_a);
 	if(b != NULL)
-		mem_cpy(REDBR, b, len_b); 
-		
+		mem_cpy(REDBR, b, len_b);
+
 	//configure the length of factor
-	RECFR = ((len_b-1)<<8) | (len_a-1); 
-	
+	RECFR = ((len_b-1)<<8) | (len_a-1);
+
 	value = calc_run(FUNC_MUL);
-	
+
 	if (value != RET_CALC_IMPLEMENT_SUCCESS)
 		return value;
-	
+
 	if(result != NULL)
 		mem_cpy(result, REDCR, len_a+len_b);
-	
+
 	return RET_CALC_IMPLEMENT_SUCCESS;
 }
 
 /*
 ***************************************************************************
 * Name: calc_div
-* Description: Perform division operation of big number. If only the quotient 
-			   need to be get, set the parameter result_r NULL.
+* Description: Perform division operation of big number. If only the quotient
+			need to be get, set the parameter result_r NULL.
 * Input: a - a pointer to the dividend.
-		 b - a pointer to the divisor.
-		 len_a - the word-length of the value pointed to by a. 
-		 len_b - the word-length of the value pointed to by b.
-* Output: result_q - a pointer to a variable of len_a words. The quotient will 
-		  be stored in this variable.
-		  result_r - a pointer to a variable of len_b words. The remainder will
-		  be stored in this variable.
+		b - a pointer to the divisor.
+		len_a - the word-length of the value pointed to by a.
+		len_b - the word-length of the value pointed to by b.
+* Output: result_q - a pointer to a variable of len_a words. The quotient will
+		be stored in this variable.
+		result_r - a pointer to a variable of len_b words. The remainder will
+		be stored in this variable.
 * Return value: RET_CALC_FUNCTION_ID_ERROR: the identity of function is wrong
 				RET_CALC_OPERAND_LENGTH_ERROR: the length of operand is wrong
 				RET_CALC_IMPLEMENT_SUCCESS:  perform successfully
@@ -450,16 +451,16 @@
 {
 	uint32_t value;
 	calc_init();
-	
+
 	//load all the operands to the registers.
 	if(a != NULL)
-		mem_cpy(REDAR,a,len_a);  
+		mem_cpy(REDAR,a,len_a);
 	if(b != NULL)
 		mem_cpy(REDBR,b,len_b);
 	//
 	RECFR=((len_b-1)<<8) | (len_a-1);
 	value=calc_run(FUNC_DIV);
-	
+
 	if (value!=RET_CALC_IMPLEMENT_SUCCESS)
 		return value;
 	if (result_q != NULL)
@@ -474,11 +475,11 @@
 * Name: calc_mod
 * Description: Perform modular operation of big number.
 * Input: a - a pointer to the operand.
-		 b - a pointer to the modulus.
-		 len_a - the word-length of the value pointed to by a. 
-		 len_b - the word-length of the value pointed to by b.
-* Output: result - a pointer to a variable of len_b words. The remainder be 
-		  stored in this variable.
+		b - a pointer to the modulus.
+		len_a - the word-length of the value pointed to by a.
+		len_b - the word-length of the value pointed to by b.
+* Output: result - a pointer to a variable of len_b words. The remainder be
+		stored in this variable.
 * Return value: RET_CALC_FUNCTION_ID_ERROR: the identity of function is wrong
 				RET_CALC_OPERAND_LENGTH_ERROR: the length of operand is wrong
 				RET_CALC_IMPLEMENT_SUCCESS:  perform successfully
@@ -494,11 +495,11 @@
 * Name: calc_modexp
 * Description: Perform modular exponentiation operation of big number.
 * Input: operand - a pointer to the calc_operand structure .
-		 len_a - the word-length of the value pointed to by operand->a or
-		         operand->p.
-		 len_b - the word-length of the value pointed to by operand->b.
-* Output: result - a pointer to a variable of len_a words. The 
-		  result of modular exponentiation will be stored in this variable.
+		len_a - the word-length of the value pointed to by operand->a or
+		operand->p.
+		len_b - the word-length of the value pointed to by operand->b.
+* Output: result - a pointer to a variable of len_a words. The
+		result of modular exponentiation will be stored in this variable.
 * Return value: RET_CALC_FUNCTION_ID_ERROR: the identity of function is wrong
 				RET_CALC_OPERAND_LENGTH_ERROR: the length of operand is wrong
 				RET_CALC_IMPLEMENT_SUCCESS:  perform successfully
@@ -508,7 +509,7 @@
 {
 	uint32_t value;
 	calc_init();
-	
+
 	if(operand->a != NULL)
 		mem_cpy(REDAR,operand->a,len_a);  //load base a to REDAR register
 	if(operand->b != NULL)
@@ -521,7 +522,7 @@
 	//
 	RECFR=((len_b-1)<<8) | (len_a-1);
 	value=calc_run(FUNC_MODEXP);
-	
+
 	if (value!=RET_CALC_IMPLEMENT_SUCCESS)
 		return value;
 	if(result != NULL)
@@ -535,12 +536,12 @@
 * Name: calc_modexp2
 * Description: Perform modular exponentiation operation of big number.
 * Input: a - a pointer to the base.
-         b - a pointer to the exponent.
-		 c - a pointer to the factor c.
-		 len_a��the word -length of the value pointed to by a. 
-		 len_b��the word-length of the value pointed to by b.
-* Output: result - a pointer to a variable of len_a words. The 
-		  result of modular exponentiation will be stored in this variable.
+        b - a pointer to the exponent.
+		c - a pointer to the factor c.
+		len_a��the word -length of the value pointed to by a.
+		len_b��the word-length of the value pointed to by b.
+* Output: result - a pointer to a variable of len_a words. The
+		result of modular exponentiation will be stored in this variable.
 * Return value: RET_CALC_FUNCTION_ID_ERROR: the identity of function is wrong
 				RET_CALC_OPERAND_LENGTH_ERROR: the length of operand is wrong
 				RET_CALC_IMPLEMENT_SUCCESS:  perform successfully
@@ -560,7 +561,7 @@
 	//
 	RECFR=((len_b-1)<<8) | (len_a-1);
 	value=calc_run(FUNC_MODEXP);
-	
+
 	if (value!=RET_CALC_IMPLEMENT_SUCCESS)
 		return value;
 	if(result != NULL)
@@ -574,15 +575,15 @@
 * Name: calc_const_c
 * Description: Prepare factor c for Montgomery arithmetic in prime field.
 * Input: p - a pointer to the modulus in modular exponentiation: 2^(2*32*(Cb+1)) % B
-		 len - the world-length of the value pointed to by p.
-* Output: result - a pointer to a variable of len words. The factor c will be 
+		len - the world-length of the value pointed to by p.
+* Output: result - a pointer to a variable of len words. The factor c will be
 				stored in this variable.
 * Return value: RET_CALC_FUNCTION_ID_ERROR: the identity of function is wrong
 				RET_CALC_OPERAND_LENGTH_ERROR: the length of operand is wrong
 				RET_CALC_IMPLEMENT_SUCCESS:  perform successfully
 ***************************************************************************
 */
-// 
+//
 uint32_t calc_const_c_base(uint32_t *result, uint32_t *p, uint32_t len, uint32_t config)
 {
 	uint32_t value;
@@ -591,12 +592,12 @@
 		mem_cpy(REDBR,p,len);  //load modulus p to REDBR register
 	//
 	RECFR=(len-1)<<8;
-	
+
 	if(config == 0)            //select the operation in fp or f2m
 		value=calc_run(FUNC_MODEXP2_PRIME);
 	else
 	    value=calc_run(FUNC_MODEXP2_BIN);
-	
+
 	if (value!=RET_CALC_IMPLEMENT_SUCCESS)
 		return value;
 	if(result != NULL)
@@ -615,9 +616,9 @@
 * Name: calc_const_c_f2m
 * Description: Prepare factor c for Montgomery arithmetic in binary field.
 * Input: p - a pointer to the modulus in modular exponentiation: 2^(2*32*(Cb+1)) % B
-		 len - the world-length of the value pointed to by p.
-* Output: result - a pointer to a variable of len words. The factor c will be 
-		  stored in this variable.
+		len - the world-length of the value pointed to by p.
+* Output: result - a pointer to a variable of len words. The factor c will be
+		stored in this variable.
 * Return value: RET_CALC_FUNCTION_ID_ERROR: the identity of function is wrong
 				RET_CALC_OPERAND_LENGTH_ERROR: the length of operand is wrong
 				RET_CALC_IMPLEMENT_SUCCESS:  perform successfully
@@ -633,9 +634,9 @@
 * Name: calc_modmul
 * Description: Perform modular multiplication in prime field.
 * Input: operand - a pointer to the calc_operand structure.
-		 len - the word-length of the value pointed to by operand->a.
-* Output: result - a pointer to a variable of len words. The result of 
-		  modular multiplication will be stored in this variable.
+		len - the word-length of the value pointed to by operand->a.
+* Output: result - a pointer to a variable of len words. The result of
+		modular multiplication will be stored in this variable.
 * Return value: RET_CALC_FUNCTION_ID_ERROR: the identity of function is wrong
 				RET_CALC_OPERAND_LENGTH_ERROR: the length of operand is wrong
 				RET_CALC_IMPLEMENT_SUCCESS:  perform successfully
@@ -645,7 +646,7 @@
 {
 	uint32_t value;
 	calc_init();
-	
+
 	if(operand->a != NULL)
 		mem_cpy(REDAR,operand->a,len);  //load multiplicand a to REDAR register
 	if(operand->b != NULL)
@@ -661,7 +662,7 @@
 		value=calc_run(FUNC_MODMUL_PRIME);
 	else
 		value=calc_run(FUNC_MODMUL_BIN);
-		
+
 	if(value!=RET_CALC_IMPLEMENT_SUCCESS)
 		return value;
 	if(result != NULL)
@@ -680,9 +681,9 @@
 * Name: calc_modmul_f2m
 * Description: Perform modular multiplication in binary field.
 * Input: operand - a pointer to the calc_operand structure.
-		 len - the word-length of the value pointed to by operand->a.
-* Output: result - a pointer to a variable of len words. The result of 
-		  modular multiplication will be stored in this variable.
+		len - the word-length of the value pointed to by operand->a.
+* Output: result - a pointer to a variable of len words. The result of
+		modular multiplication will be stored in this variable.
 * Return value: RET_CALC_FUNCTION_ID_ERROR: the identity of function is wrong
 				RET_CALC_OPERAND_LENGTH_ERROR: the length of operand is wrong
 				RET_CALC_IMPLEMENT_SUCCESS:  perform successfully
@@ -699,7 +700,7 @@
 {
 	uint32_t value;
 	calc_init();
-	
+
 	if(a != NULL)
 		mem_cpy(REDAR,a,len);  //load multiplicand a to REDAR register
 	if(b != NULL)
@@ -714,7 +715,7 @@
 		value=calc_run(FUNC_MODMUL_PRIME);
 	else
 		value=calc_run(FUNC_MODMUL_BIN);
-	
+
 	if(value!=RET_CALC_IMPLEMENT_SUCCESS)
 		return value;
 	if(result != NULL)
@@ -729,11 +730,11 @@
 * Name: calc_modmul2
 * Description: Perform modular multiplication in prime field.
 * Input: a - a pointer to the multiplicand.
-		 b - a pointer to the multiplier.
-		 c - a pointer to the factor c.
-		 len - the word-length of the value pointed to by a, b or c.
-* Output: result - a pointer to a variable of len words. The result of 
-		  modular multiplication will be stored in this variable.
+		b - a pointer to the multiplier.
+		c - a pointer to the factor c.
+		len - the word-length of the value pointed to by a, b or c.
+* Output: result - a pointer to a variable of len words. The result of
+		modular multiplication will be stored in this variable.
 * Return value: RET_CALC_FUNCTION_ID_ERROR: the identity of function is wrong
 				RET_CALC_OPERAND_LENGTH_ERROR: the length of operand is wrong
 				RET_CALC_IMPLEMENT_SUCCESS:  perform successfully
@@ -743,7 +744,7 @@
 {
 	uint32_t value;
 	calc_init();
-	
+
 	if(a != NULL)
 		mem_cpy(REDAR,a,len);  //load multiplicand a to REDAR register
 	if(b != NULL)
@@ -756,7 +757,7 @@
 		value=calc_run(FUNC_MODMUL_PRIME);
 	else
 		value=calc_run(FUNC_MODMUL_BIN);
-	
+
 	if(value!=RET_CALC_IMPLEMENT_SUCCESS)
 		return value;
 	if(result != NULL)
@@ -775,11 +776,11 @@
 * Name: calc_modmul2_f2m
 * Description: Perform modular multiplication in binary field.
 * Input: a - a pointer to the multiplicand.
-		 b - a pointer to the multiplier.
-		 c - a pointer to the factor c.
-		 len - the word-length of the value pointed to by a, b or c.
-* Output: result - a pointer to a variable of len words. The result of 
-		  modular multiplication will be stored in this variable.
+		b - a pointer to the multiplier.
+		c - a pointer to the factor c.
+		len - the word-length of the value pointed to by a, b or c.
+* Output: result - a pointer to a variable of len words. The result of
+		modular multiplication will be stored in this variable.
 * Return value: RET_CALC_FUNCTION_ID_ERROR: the identity of function is wrong
 				RET_CALC_OPERAND_LENGTH_ERROR: the length of operand is wrong
 				RET_CALC_IMPLEMENT_SUCCESS:  perform successfully
@@ -793,13 +794,13 @@
 /*
 ***************************************************************************
 * Name: calc_modinv
-* Description: Perform modular inversion in prime field, and check if the 
-			   greatest common divisor is equal to 1.
+* Description: Perform modular inversion in prime field, and check if the
+			greatest common divisor is equal to 1.
 * Input: a - a pointer to the base.
-		 p - a pointer to the modulus.
-		 len��the word-length of the value pointed to by a or p.
-* Output: result - a pointer to a variable of len words. The result of 
-		  modular inversion will be stored in this variable.
+		p - a pointer to the modulus.
+		len��the word-length of the value pointed to by a or p.
+* Output: result - a pointer to a variable of len words. The result of
+		modular inversion will be stored in this variable.
 * Return value: RET_CALC_FUNCTION_ID_ERROR: the identity of function is wrong
 				RET_CALC_OPERAND_LENGTH_ERROR: the length of operand is wrong
 				RET_CALC_IMPLEMENT_SUCCESS:  perform successfully
@@ -810,20 +811,20 @@
 {
 	uint32_t value;
 	calc_init();
-	
+
 	if(a != NULL)
 		mem_cpy(REDAR,a,len);  //load base a to REDAR register
 	if(p != NULL)
 		mem_cpy(REDPR,p,len);  //load modulus p to REDPR register
 	//
 	RECFR=len-1;
-	value=calc_run(FUNC_MODINV_PRIME); 
-	
+	value=calc_run(FUNC_MODINV_PRIME);
+
 	if (value!=RET_CALC_IMPLEMENT_SUCCESS)
 		return value;
 	if (mem_cmp2(REDBR,1,len) != EQUAL)
 		return RET_CALC_GCD_NOT_ONE;
-		
+
 	if (result != NULL)
 		mem_cpy(result, REDAR, len);
 	return RET_CALC_IMPLEMENT_SUCCESS;
@@ -834,8 +835,8 @@
 * Name: calc_gcd
 * Description: Check if the greatest common divisor is equal to 1.
 * Input: a - a pointer to the base in modular inversion.
-		 p - a pointer to the modulus in modulaar inversion.
-		 len��the word-length of the value pointed to by a or p.
+		p - a pointer to the modulus in modulaar inversion.
+		len��the word-length of the value pointed to by a or p.
 * Output: None
 * Return value: RET_CALC_FUNCTION_ID_ERROR: the identity of function is wrong
 				RET_CALC_OPERAND_LENGTH_ERROR: the length of operand is wrong
@@ -853,10 +854,10 @@
 * Name: calc_modinv_f2m
 * Description: Perform modular inversion in binary field.
 * Input: a - a pointer to the base.
-		 p - a pointer to the modulus.
-		 len��the word-length of the value pointed to by a or p.
-* Output: result - a pointer to a variable of len words. The result of 
-		  modular inversion will be stored in this variable.
+		p - a pointer to the modulus.
+		len��the word-length of the value pointed to by a or p.
+* Output: result - a pointer to a variable of len words. The result of
+		modular inversion will be stored in this variable.
 * Return value: RET_CALC_FUNCTION_ID_ERROR: the identity of function is wrong
 				RET_CALC_OPERAND_LENGTH_ERROR: the length of operand is wrong
 				RET_CALC_IMPLEMENT_SUCCESS:  perform successfully
@@ -872,8 +873,8 @@
 		mem_cpy(REDPR,p,len);  //load modulus p to REDPR register
 	//
 	RECFR=len-1;
-	value=calc_run(FUNC_MODINV_BIN);	
-		
+	value=calc_run(FUNC_MODINV_BIN);
+
 	if (value!=RET_CALC_IMPLEMENT_SUCCESS)
 		return value;
 	if (result != NULL)
@@ -888,8 +889,8 @@
 * Name: calc_const_q
 * Description: Prepare factor q for Montgomery arithmetic in prime field.
 * Input: a - a pointer to the base in modular inversion whose modulus is 2^32.
-* Output: result - a pointer to a variable of 1 words. The factor q will be 
-		  stored in this variable.
+* Output: result - a pointer to a variable of 1 words. The factor q will be
+		stored in this variable.
 * Return value: RET_CALC_FUNCTION_ID_ERROR: the identity of function is wrong
 				RET_CALC_OPERAND_LENGTH_ERROR: the length of operand is wrong
 				RET_CALC_IMPLEMENT_SUCCESS:  perform successfully
@@ -907,10 +908,10 @@
 	//
 	RECFR=1;
 	value=calc_run(FUNC_MODINV_PRIME);
-	
+
 	if (value!=RET_CALC_IMPLEMENT_SUCCESS)
 		return value;
-		
+
 	if(result != NULL)
 		*result=(~(*REDAR))+1;//two's complement
 
@@ -921,8 +922,8 @@
 * Name: calc_const_q_f2m
 * Description: Prepare factor q for Montgomery arithmetic in binary field.
 * Input: a - a pointer to the base in modular inversion whose modulus is 2^32.
-* Output: result - a pointer to a variable of 1 words. The factor q will be 
-		  stored in this variable.
+* Output: result - a pointer to a variable of 1 words. The factor q will be
+		stored in this variable.
 * Return value: RET_CALC_FUNCTION_ID_ERROR: the identity of function is wrong
 				RET_CALC_OPERAND_LENGTH_ERROR: the length of operand is wrong
 				RET_CALC_IMPLEMENT_SUCCESS:  perform successfully
@@ -940,7 +941,7 @@
 	//
 	RECFR=1;
 	value=calc_run(FUNC_MODINV_BIN);
-	
+
 	if (value!=RET_CALC_IMPLEMENT_SUCCESS)
 		return value;
 	if(result != NULL)
@@ -953,10 +954,10 @@
 * Name: calc_sr
 * Description: Perform shift right operation of big number.
 * Input: a - a pointer to the operand.
-		 len - the word-length of the value pointed to by a. 
-		 sr_len -the number of bits needs to be shifted
-* Output: result - a pointer to a variable of len words. The result of 
-		  shift right be stored in this variable.
+		len - the word-length of the value pointed to by a.
+		sr_len -the number of bits needs to be shifted
+* Output: result - a pointer to a variable of len words. The result of
+		shift right be stored in this variable.
 * Return value: none
 ***************************************************************************
 */
@@ -968,12 +969,12 @@
 
 	length_div32=sf_len>>5;
 	length_mod32=sf_len & 0x1f;
-	
+
 	for (i=length_div32,j=0;i<len-1;i++,j++)
 		result[j]=(a[i]>>length_mod32) | (a[i+1]<<(32-length_mod32));
-		
+
 	result[len-length_div32-1]=a[len-1]>>length_mod32;
-	
+
 	for (j=len-length_div32;j<len;j++)
 		result[j]=0;
 }
@@ -982,26 +983,26 @@
 * Name: calc_bitlen
 * Description: Get the effective number of bits.
 * Input: a - a pointer to the operand
-		 len - the word-length of the value pointed to by a. 
+		len - the word-length of the value pointed to by a.
 * Output: none
-* Return value: The effective number of bits. 
+* Return value: The effective number of bits.
 ***************************************************************************
 */
 uint32_t calc_bitlen(uint32_t *a, uint32_t len)
 {
 	int32_t i, j;
 	uint32_t bitlen;
-	
+
 	bitlen = len * 32; // the max number
-	
-	for(i=len-1; i>=0; i--) //word 
+
+	for(i=len-1; i>=0; i--) //word
 	{
 		if(a[i] == 0)
 			bitlen -= 32;
 		else
 			break;
 	}
-	
+
 	for(j=31; j>=0; j++)  //bit
 	{
 		if(a[i] & (1<<j))
@@ -1009,7 +1010,7 @@
 		else
 			bitlen--;
 	}
-	
+
 	return bitlen;
 }
 /*
@@ -1017,11 +1018,11 @@
 * Name: calc_modinv2048
 * Description: Perform 2048-bit modular inversion operation.
 * Input: a - a pointer to base of 32 bits or 64bits
-		 b - a pointer to modulus of len_b bits
-		 len_a - the word-length of the value pointed to by a.
-		 len_b - the word-length of the value pointed to by b.
-* Output: result - a pointer to a variable of len_b words. The result of 
-		  modular inversion be stored in this variable.
+		b - a pointer to modulus of len_b bits
+		len_a - the word-length of the value pointed to by a.
+		len_b - the word-length of the value pointed to by b.
+* Output: result - a pointer to a variable of len_b words. The result of
+		modular inversion be stored in this variable.
 * Return value: none
 ***************************************************************************
 */
@@ -1032,10 +1033,10 @@
 		uint32_t k;
 		uint32_t g0[2],g1[2],g2[2];
 		uint32_t v0[64+2],v1[64+2],v2[64+2];
-	
+
 	    for(i=0;i<len_a;i++)
-	      v1[len_b+i]=0;
-	    
+	    	v1[len_b+i]=0;
+
 		k=2;  //i=1
 		calc_div(v2,g2,b,a,len_b,len_a);//G(2)= w % e, V(2)= 0 + [ w / e]*1
 		if (mem_cmp2(g2,1,len_a)==EQUAL)//G(2) == 1
@@ -1075,8 +1076,8 @@
 * Name: calc_gcd2048
 * Description: Check if the greatest common divisor is 1.
 * Input: a - a operand of 32 bits.
-		 b - a pointer to anoter operand of 2048 bits.
-		 len - the word-length of the operand pointed to by b.
+		b - a pointer to anoter operand of 2048 bits.
+		len - the word-length of the operand pointed to by b.
 * Output: none
 * Return value: RET_CALC_GCD_NOT_ONE:  The greatest common divisor is not 1.
 				RET_CALC_IMPLEMENT_SUCCESS:   The greatest common divisor is 1.
@@ -1127,19 +1128,19 @@
 			calc_sub(result,x0,result,len);
 		mem_cpy(x0,x1, len);
 		mem_cpy(x1,result, len);
-		
+
 		mem_cpy(tempa,tempb, len);
 		mem_cpy(tempb,r, len);
-		
-		calc_div(q,r,tempa,tempb,len,len);  
+
+		calc_div(q,r,tempa,tempb,len,len);
 	}
-	if (mem_cmp2(tempb,1,len)!=EQUAL)   
+	if (mem_cmp2(tempb,1,len)!=EQUAL)
 		return RET_CALC_GCD_NOT_ONE;
 	else
 	{
 		calc_mod(result,result,b, len, len);
 		return RET_CALC_IMPLEMENT_SUCCESS;
-	}	
+	}
 }
 
 
@@ -1148,7 +1149,7 @@
 	dst[0] = *src;
 	dst[1] = *src>>8;
 	dst[2] = *src>>16;
-	dst[3] = *src>>24;	
+	dst[3] = *src>>24;
 }
 
 void uint8touint32(uint32_t *dst,uint8_t *src)
@@ -1156,69 +1157,69 @@
 	*dst = src[0]+(src[1]<<8)+(src[2]<<16)+(src[3]<<24);
 }
 
-void mem_cpy(volatile unsigned int *dst,volatile unsigned int *src,unsigned int s)  
-{  
-  
-    if(src==NULL||dst==NULL)  
-        return ;  
-  
-    if(dst>src&&dst<(src+s))  
-    {  
-        for(unsigned int i=s-1;i!=-1;i--)  
-            dst[i]=src[i];  
-    }  
-    else  
-    {  
-        for(unsigned int i=0;i<s;++i)  
-            dst[i]=src[i];  
-    }  
-}  
-
-int mem_cmp(volatile unsigned int *str1,volatile unsigned int *str2,int len)  
-{  
-//    assert(str1);  
-//    assert(str2);  
- //    if(str1==NULL||str2==NULL)  
-//        return NULL;  
-	volatile  unsigned int *su1, *su2;  
+void mem_cpy(volatile unsigned int *dst,volatile unsigned int *src,unsigned int s)
+{
+
+    if(src==NULL||dst==NULL)
+        return ;
+
+    if(dst>src&&dst<(src+s))
+    {
+        for(unsigned int i=s-1;i!=-1;i--)
+            dst[i]=src[i];
+    }
+    else
+    {
+        for(unsigned int i=0;i<s;++i)
+            dst[i]=src[i];
+    }
+}
+
+int mem_cmp(volatile unsigned int *str1,volatile unsigned int *str2,int len)
+{
+//    assert(str1);
+//    assert(str2);
+ //    if(str1==NULL||str2==NULL)
+//        return NULL;
+	volatile  unsigned int *su1, *su2;
 	int i=1;
-	 for( su1 = str1, su2 = str2; i <= len; i++)  
-	 {
+	for( su1 = str1, su2 = str2; i <= len; i++)
+	{
 	 //	res = su1[len-i] -su2[len -i];
-	        if (su1[len-i] != su2[len -i])
-	        {
-	        	if(su1[len-i] > su2[len -i])
-	        		return BIGGER;
-	        	else
-	        		if(su1[len-i] < su2[len -i])
-	        			return SMALLER;
-	        }
-	   }
-	    return EQUAL;   
-} 
+		if (su1[len-i] != su2[len -i])
+		{
+			if(su1[len-i] > su2[len -i])
+				return BIGGER;
+			else
+				if(su1[len-i] < su2[len -i])
+					return SMALLER;
+		}
+	}
+	    return EQUAL;
+}
 
-int mem_cmp2(volatile unsigned int *str1,unsigned int str2,int len)  
-{ 
+int mem_cmp2(volatile unsigned int *str1,unsigned int str2,int len)
+{
 	int i;
 	if(str1[0] == str2)
 	{
 		i  = len;
 		len--;
-		while(len)  
+		while(len)
 		{
 			if(str1[i-len] != 0)
 			    return  BIGGER;
-			len--;						
+			len--;
 		}
-	       return EQUAL;  
-	 }
+	    return EQUAL;
+	}
 	else
 		if(str1[0] > str2)
 			return BIGGER;
 		else
-	 		return  SMALLER;
+			return  SMALLER;
 
-} 
+}
 
 /*
 void revstr(char *str, size_t len)
@@ -1243,7 +1244,7 @@
 
 void mem_set(volatile unsigned int *s, unsigned int c, unsigned int n)
 {
-	while (n > 0) 
+	while (n > 0)
 	{
 		*s++ = c;
 		--n;
@@ -1253,97 +1254,97 @@
 
 int mem_rollcmp(volatile uint32_t *indata1,uint32_t *indata2,uint32_t wlen, uint32_t startflag)
 {
-  uint32_t icnt = 0;
-  uint32_t tmp = wlen;
-  uint32_t StartPosition;
-  
-  if(wlen == 0)
-    return CMPERROR;
-  cpu_open_uniform_branch_timing();
-  cpu_open_branch_self();
-
-  StartPosition = startflag%wlen;
-  
-  icnt = StartPosition;
-  tmp = 0;
+	uint32_t icnt = 0;
+	uint32_t tmp = wlen;
+	uint32_t StartPosition;
+
+	if(wlen == 0)
+	return CMPERROR;
+	cpu_open_uniform_branch_timing();
+	cpu_open_branch_self();
+
+	StartPosition = startflag%wlen;
+
+	icnt = StartPosition;
+	tmp = 0;
 s1:
-  if(icnt >= wlen)
-    goto s2;
+	if(icnt >= wlen)
+		goto s2;
 
-    if(indata1[icnt] != indata2[icnt])
-    {
-        return CMPERROR;
-    }
-  icnt += 1;
-  goto s1;
+	if(indata1[icnt] != indata2[icnt])
+	{
+		return CMPERROR;
+	}
+	icnt += 1;
+	goto s1;
 s2:
-  if(tmp >= StartPosition)
-    goto s4;
+	if(tmp >= StartPosition)
+		goto s4;
 
-  if(indata1[tmp] != indata2[tmp])
+	if(indata1[tmp] != indata2[tmp])
     {
         return CMPERROR;
     }
-  tmp+=1;
+	tmp+=1;
 s3:
-  if(tmp >= StartPosition)
-    goto s4;
+	if(tmp >= StartPosition)
+		goto s4;
 
-  if(indata1[tmp] != indata2[tmp])
-    {
-        return CMPERROR;
-    }
-  tmp+=1;
-  goto s3;
+	if(indata1[tmp] != indata2[tmp])
+	{
+		return CMPERROR;
+	}
+	tmp+=1;
+	goto s3;
 s4:
-  __asm("NOP");
+	__asm("NOP");
 
-  cpu_close_branch_self();
-  cpu_close_uniform_branch_timing();
-  return CMPOK;
+	cpu_close_branch_self();
+	cpu_close_uniform_branch_timing();
+	return CMPOK;
 }
 
 int mem_rollcmp_char(uint8_t *indata1,uint8_t *indata2,uint32_t wlen, uint32_t startflag)
 {
-  uint32_t icnt = 0;
-  uint32_t tmp = wlen;
-  uint32_t StartPosition;
-  
-  if(wlen == 0)
-    return CMPERROR;
-  cpu_open_uniform_branch_timing();
-  cpu_open_branch_self();
-
-  StartPosition = startflag%wlen;
-  icnt = StartPosition;
-  tmp = 0;
+    uint32_t icnt = 0;
+    uint32_t tmp = wlen;
+    uint32_t StartPosition;
+
+    if(wlen == 0)
+        return CMPERROR;
+    cpu_open_uniform_branch_timing();
+    cpu_open_branch_self();
+
+    StartPosition = startflag%wlen;
+    icnt = StartPosition;
+    tmp = 0;
 s1:
-  if(icnt >= wlen)
-    goto s2;
+    if(icnt >= wlen)
+        goto s2;
 
     if(indata1[icnt] != indata2[icnt])
         return CMPERROR;
-  icnt += 1;
-  goto s1;
+    icnt += 1;
+    goto s1;
 s2:
-  if(tmp >= StartPosition)
-    goto s4;
-  if(indata1[tmp] != indata2[tmp])
+    if(tmp >= StartPosition)
+        goto s4;
+    if(indata1[tmp] != indata2[tmp])
         return CMPERROR;
-  tmp+=1;
+    tmp+=1;
 s3:
-  if(tmp >= StartPosition)
-    goto s4;
+    if(tmp >= StartPosition)
+        goto s4;
 
-  if(indata1[tmp] != indata2[tmp])
+    if(indata1[tmp] != indata2[tmp])
         return CMPERROR;
-  tmp+=1;
-  goto s3;
+    tmp+=1;
+    goto s3;
 s4:
-  __asm("NOP");
-  cpu_close_branch_self();
-  cpu_close_uniform_branch_timing();
-  return CMPOK;
+    __asm("NOP");
+    cpu_close_branch_self();
+    cpu_close_uniform_branch_timing();
+    return CMPOK;
 }
 
 
@@ -1455,7 +1456,7 @@
 	uint32_t tmp = wlen;
 	uint32_t StartPosition;
 	uint32_t temp=0;
-	
+
 	if(wlen == 0)
 		return ;
 	if(content == result)
@@ -1464,7 +1465,7 @@
 	cpu_open_branch_self();
 
 	StartPosition = startflag%wlen;
-		
+
 	icnt = StartPosition;
 	tmp = 0;
 s1:
@@ -1485,7 +1486,7 @@
 	tmp+=1;
 	goto s3;
 s4:
-	__asm("NOP");	
+	__asm("NOP");
 	cpu_close_branch_self();
 	cpu_close_uniform_branch_timing();
 	temp = 0;
@@ -1497,7 +1498,7 @@
 	uint32_t tmp = wlen;
 	uint32_t StartPosition;
 	uint8_t temp=0;
-	
+
 	if(wlen == 0)
 		return ;
 	if(content == result)
@@ -1526,7 +1527,7 @@
 	tmp+=1;
 	goto s3;
 s4:
-	__asm("NOP");	
+	__asm("NOP");
 	cpu_close_branch_self();
 	cpu_close_uniform_branch_timing();
 	temp = 0;
@@ -1558,7 +1559,7 @@
 		__asm("NOP");
 }
 
-#define CRYPT_LIB_VERSION 0x00010003
+#define CRYPT_LIB_VERSION 0x00010004
 uint32_t CRYPT_GetVersion(void)
 {
 	return CRYPT_LIB_VERSION;
Index: yc_crc16.c
===================================================================
--- /YC3121_SDK/fw/crypt/yc_crc16.c	(revision 797)
+++ /YC3121_SDK/fw/crypt/yc_crc16.c	(working copy)
@@ -5,7 +5,7 @@
 	uint16_t num = 0;
 	uint32_t val1 = 0;
 	uint16_t val2 = 0;
-	
+
 	CRC_RESULT_REG = iv;
 	CRC_MASK_REG = mask;
 
@@ -16,7 +16,7 @@
 		for (num = 0; num < data_len; num++)
 		{
 			val1 = *(data + num) + (*(data + num + 1) << 8) + (*(data + num + 2) << 16) + (*(data + num + 3) << 24);
-			
+
 			CRC_DATA_REG =  val1;
 
 			num = num + 3;
@@ -27,7 +27,7 @@
 		for (num = 0; num < data_len; num++)
 		{
 			val1 = *(data + num) + (*(data + num + 1) << 8);
-			
+
 			CRC_DATAS_REG =  val1;
 
 			num = num + 1;
@@ -40,17 +40,17 @@
 			CRC_DATAB_REG = *data++;
 		}
 	}
-	
+
 	#else
 		for (num = 0; num < data_len; num++)
 		{
 			CRC_DATAB_REG = *data++;
 		}
-		
+
 	#endif
 
 	return CRC_RESULT_REG;
-	
+
 }
 
 
Index: yc_crypt.h
===================================================================
--- /YC3121_SDK/fw/crypt/yc_crypt.h	(revision 797)
+++ /YC3121_SDK/fw/crypt/yc_crypt.h	(working copy)
@@ -8,9 +8,9 @@
 #define BIGGER 			(('B'<<24)|('I'<<16)|('G'<<8)|('G'))
 #define SMALLER 		(('S'<<24)|('M'<<16)|('A'<<8)|('L'))
 
-typedef enum 
+typedef enum
 {
-	ECB = (('P'<<24)|('E'<<16)|('C'<<8)|('B')), 
+	ECB = (('P'<<24)|('E'<<16)|('C'<<8)|('B')),
 	CBC = (('P'<<24)|('C'<<16)|('B'<<8)|('C'))
 }PACK_ModeTypeDef;
 
@@ -27,4 +27,4 @@
 void crypt_data_rand(rng_callback f_rng, void *p_rng);
 
 
-#endif 
+#endif
Index: yc_crypt.lib
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: yc_des.h
===================================================================
--- /YC3121_SDK/fw/crypt/yc_des.h	(revision 797)
+++ /YC3121_SDK/fw/crypt/yc_des.h	(working copy)
@@ -17,26 +17,26 @@
 #define RET_DES_INPUT_SIZE_ERROR   (('R'<<24)|('D'<<16)|('I'<<8)|('S'))  //输入数据 len 错误
 #define RET_DES_RESULT_CHECK_ERROR (('R'<<24)|('D'<<16)|('R'<<8)|('C'))  //输出结果错误
 
-#define DES_KEY_SIZE 8  
+#define DES_KEY_SIZE 8
 #define DES_IV_SIZE  8
-                                               
+
 typedef uint8_t DES_KeyTypeDef[DES_KEY_SIZE];
-typedef uint8_t DES_IvTypeDef[DES_IV_SIZE]; 
+typedef uint8_t DES_IvTypeDef[DES_IV_SIZE];
 
-typedef uint8_t DES_RandTypeDef[4]; 
-typedef uint8_t DES_FakeTypeDef[8]; 
+typedef uint8_t DES_RandTypeDef[4];
+typedef uint8_t DES_FakeTypeDef[8];
 
 #define DES_TYPE_DES_ENC  (('D'<<24)|('T'<<16)|('D'<<8)|('E'))  //DES 加密模式
 #define DES_TYPE_DES_DEC  (('D'<<24)|('T'<<16)|('D'<<8)|('D'))  //DES 解密模式
 #define DES_TYPE_TDES_ENC (('D'<<24)|('T'<<16)|('T'<<8)|('E'))  //TDES 加密模式
 #define DES_TYPE_TDES_DEC (('D'<<24)|('T'<<16)|('T'<<8)|('D'))  //TDES 解密模式
 
-typedef struct         
-{                      
-	DES_KeyTypeDef k1;   
-	DES_KeyTypeDef k2;   
-	DES_KeyTypeDef k3;   
-}TDES_KeyTypeDef;      
+typedef struct
+{
+	DES_KeyTypeDef k1;
+	DES_KeyTypeDef k2;
+	DES_KeyTypeDef k3;
+}TDES_KeyTypeDef;
 
 /**
   * @method	mh_des_enc
@@ -59,7 +59,7 @@
 					uint8_t *input, uint32_t ibytes,
 					DES_KeyTypeDef key,	DES_IvTypeDef iv,
 					rng_callback f_rng, void *p_rng);
-					
+
 /**
   * @method	DES_Decrypt
   * @brief	DES decrypt function
Index: yc_des.c
===================================================================
--- /YC3121_SDK/fw/crypt/yc_des.c	(revision 797)
+++ /YC3121_SDK/fw/crypt/yc_des.c	(working copy)
@@ -13,7 +13,7 @@
 
 void des_setiv(uint8_t *content)
 {
-	
+
 	uint8_t i;
 	for (i=0;i<2;i++)
 //		DESIV_REG[i]=content[i*4]+(content[i*4+1]<<8)+(content[i*4+2]<<16)+(content[i*4+3]<<24);
@@ -69,12 +69,12 @@
 		if(rand & 4)
 		{
 			DESKEY3_REG[1] = (key3[0]<<24)+ (key3[1]<<16)+ (key3[2]<<8)+ (key3[3]);
-			DESKEY3_REG[0] = (key3[4]<<24)+ (key3[5]<<16)+ (key3[6]<<8)+ (key3[7]);	
+			DESKEY3_REG[0] = (key3[4]<<24)+ (key3[5]<<16)+ (key3[6]<<8)+ (key3[7]);
 		}
 		else
 		{
 			DESKEY3_REG[1] = (key3[0]<<24)+ (key3[1]<<16)+ (key3[2]<<8)+ (key3[3]);
-			DESKEY3_REG[0] = (key3[4]<<24)+ (key3[5]<<16)+ (key3[6]<<8)+ (key3[7]);	
+			DESKEY3_REG[0] = (key3[4]<<24)+ (key3[5]<<16)+ (key3[6]<<8)+ (key3[7]);
 		}
 //		for (i=0;i<2;i++)
 //			DESKEY3_REG[1-i]=(key3[i*4]<<24)+(key3[i*4+1]<<16)+(key3[i*4+2]<<8)+(key3[i*4+3]);
@@ -111,10 +111,10 @@
 //		result[7-i]=(uint8_t)(content[i>>2]>>(8*(i%4)));
 }
 
-	
+
 void des_getkey(uint8_t *key1,uint8_t *key2,uint8_t *key3,uint32_t rand )
 {
-	uint8_t i;	
+	uint8_t i;
 	uint32_t temp = 0;
 	if (key1 != NULL)
 		des_getdata_r( key1, DESKEY1_REG  , rand);
@@ -157,11 +157,11 @@
 	if(rand & 1)
 	{
 		DESDATA_REG[1] = (content[0]<<24)+ (content[1]<<16)+ (content[2]<<8)+ (content[3]);
-		DESDATA_REG[0] = (content[4]<<24)+ (content[5]<<16)+ (content[6]<<8)+ (content[7]);	
+		DESDATA_REG[0] = (content[4]<<24)+ (content[5]<<16)+ (content[6]<<8)+ (content[7]);
 	}
 	else
 	{
-		DESDATA_REG[0] = (content[4]<<24)+ (content[5]<<16)+ (content[6]<<8)+ (content[7]);	
+		DESDATA_REG[0] = (content[4]<<24)+ (content[5]<<16)+ (content[6]<<8)+ (content[7]);
 		DESDATA_REG[1] = (content[0]<<24)+ (content[1]<<16)+ (content[2]<<8)+ (content[3]);
 	}
 }
@@ -195,7 +195,7 @@
 /*
 uint32_t mem_cmp8(uint8_t *s1,uint8_t *s2,uint8_t len)
 {
-	uint8_t i;	
+	uint8_t i;
 	for (i=0;i<len;i++)
 	{
 		if(s1[i]!=s2[i])
@@ -246,7 +246,7 @@
 	cpu_open_branch_self();
 	(*f_rng)((uint8_t *)rand_key,8,NULL);
  	(*f_rng)((uint8_t *)rand_data,8,NULL);
- 	
+
 	if (config!=DES_FLOW_NONE)
 	{
 		cpu_close_branch_self();
@@ -277,7 +277,7 @@
 //				des_setiv(i?(value & 0x1 ? &para->result[(i-1)*8] : &para->content[(i-1)*8]):para->iv);
 				des_filldata(&para->result[i*8],rand_data[0]>>1);
 				des_run(value);
-				des_getdata(temp,rand_data[1]>>1);   //check data 
+				des_getdata(temp,rand_data[1]>>1);   //check data
 				//(uint32_t *)
 				if (mem_rollcmp_char((&para->content[i*8]),temp,8,rand_data[0])!=CMPOK)
 				{
@@ -308,7 +308,7 @@
 			else
 				value=para->config | DESCNTRL_REG_ENCRYPT;
 			for (i=0;i<para->length>>3;i++)
-			{	
+			{
 				des_filldata(&para->result[i*8],rand_data[0]>>3);
 				des_run(value);
 				des_getdata(temp,rand_data[1]>>4);
@@ -328,7 +328,7 @@
 		}
 		des_getkey(key1,key2,key3,rand_data[1]);  //check key
 		if(mem_rollcmp_char(para->key1,key1,8,rand_key[0]) !=CMPOK)
-//		if (  mem_cmp8((volatile uint32_t *)(para->key1),(volatile uint32_t *)key1,2) !=EQUAL) 
+//		if (  mem_cmp8((volatile uint32_t *)(para->key1),(volatile uint32_t *)key1,2) !=EQUAL)
 		{
 			goto RETURN_DES_FAILUER;
 		}
@@ -431,14 +431,14 @@
 			goto RETURN_DES_FAILUER;
 		}
 		des_getkey(key1,key2,key3,rand_data[1]>>3);
-		if ((para->key1 && mem_rollcmp_char(para->key1,key1,8,rand_key[0])!=CMPOK) || 
-			(para->key2 && mem_rollcmp_char(para->key2,key2,8,rand_key[0])!=CMPOK) || 
+		if ((para->key1 && mem_rollcmp_char(para->key1,key1,8,rand_key[0])!=CMPOK) ||
+			(para->key2 && mem_rollcmp_char(para->key2,key2,8,rand_key[0])!=CMPOK) ||
 				(para->key3 && mem_rollcmp_char(para->key3,key3,8,rand_key[0])!=CMPOK))
 		{
 			goto RETURN_DES_FAILUER;
 		}
 		cpu_close_branch_self();
-		mem_set((uint32_t *)key1,0,2); 
+		mem_set((uint32_t *)key1,0,2);
 		mem_set((uint32_t *)key2,0,2);
 		mem_set((uint32_t *)key3,0,2);
 		des_setkey(key1,key2,key3,rand_key[0]>>4);
@@ -558,19 +558,19 @@
 		des_closefake();
 	}
 #endif
-	mem_set((uint32_t *)key1,0,2); 
+	mem_set((uint32_t *)key1,0,2);
 	mem_set((uint32_t *)key2,0,2);
 	mem_set((uint32_t *)key3,0,2);
-	des_setkey(key1,key2,key3,rand_key[1]);	
+	des_setkey(key1,key2,key3,rand_key[1]);
 	des_filldata(key1,rand_data[0]>>2);
 	return RET_DES_SUCCESS;
-	
+
 RETURN_DES_FAILUER:
 	cpu_close_branch_self();
-	mem_set((uint32_t *)key1,0,2); 
+	mem_set((uint32_t *)key1,0,2);
 	mem_set((uint32_t *)key2,0,2);
 	mem_set((uint32_t *)key3,0,2);
-	des_setkey(key1,key2,key3,rand_key[1]);	
+	des_setkey(key1,key2,key3,rand_key[1]);
 	des_filldata(key1,rand_data[0]);
 	for (i=0;i<para->length;i++)
 		para->result[i] = 0;
@@ -580,7 +580,7 @@
 }
 
 
-uint32_t des_common(PACK_ModeTypeDef pack_mode,uint32_t type_mode, 
+uint32_t des_common(PACK_ModeTypeDef pack_mode,uint32_t type_mode,
 					uint8_t *output, uint32_t obytes,
 					uint8_t *input, uint32_t ibytes,
 					TDES_KeyTypeDef *key,	DES_IvTypeDef iv,
@@ -589,7 +589,7 @@
 	des_para des;
 	DES_KeyTypeDef key_null= {0,0,0,0,0,0,0,0};
 	DES_FakeTypeDef fake_null = {0,0,0,0,0,0,0,0};
-	DES_RandTypeDef rand_null = {0,0,0,0}; 
+	DES_RandTypeDef rand_null = {0,0,0,0};
 	uint32_t rand_key=0;
 	(*f_rng)((uint8_t *)(&rand_key),4,NULL);
 
@@ -597,7 +597,7 @@
 		return RET_DES_INPUT_SIZE_ERROR;
 	if(obytes < ibytes || obytes == 0)
 		return RET_DES_OUTBUF_TOO_SMALL;
-		
+
 	if(pack_mode == CBC)
 	{
 		des.iv = iv;
@@ -611,10 +611,10 @@
 			return RET_DES_PACK_MODE_ERROR;
 
 	if(des_checkkey(key->k2,rand_key) ==RET_DES_KEY_IS_NULL &&
-		des_checkkey(key->k3,rand_key) ==RET_DES_KEY_IS_NULL && 
+		des_checkkey(key->k3,rand_key) ==RET_DES_KEY_IS_NULL &&
 			des_checkkey(key->k1,rand_key) ==RET_DES_KEY_IS_NULL)
 	return RET_DES_KEY_IS_NULL;
-	
+
 	switch(type_mode)
 	{
 		case DES_TYPE_TDES_DEC:
@@ -643,13 +643,13 @@
 			break;
 		default:
 			return  RET_DES_FAILURE;
-			break;	
+			break;
 	}
 
 	des.content = input;
 	des.result = output;
 	des.key1 = key->k1;
-			
+
 	des.rand = rand_null;
 	des.fakekey = fake_null;
  	(*f_rng)(des.rand,4,NULL);
@@ -657,7 +657,7 @@
 	des.length = ibytes;
 	enable_clock(CLKCLS_DES);
 	return des_flow_sec(&des,DES_FLOW_SECURITY,f_rng, p_rng);
-	
+
 }
 
 uint32_t DES_Enc(PACK_ModeTypeDef pack_mode,
@@ -711,7 +711,7 @@
 					rng_callback f_rng, void *p_rng)
 {
 	return des_common( pack_mode,DES_TYPE_TDES_DEC, output,  obytes,
-					 input,  ibytes, key,  iv, f_rng, p_rng);
+					input,  ibytes, key,  iv, f_rng, p_rng);
 }
 
 
Index: yc_ecc.c
===================================================================
--- /YC3121_SDK/fw/crypt/yc_ecc.c	(revision 797)
+++ /YC3121_SDK/fw/crypt/yc_ecc.c	(working copy)
@@ -48,21 +48,21 @@
 	#ifdef SM2_DEBUG
 	MyPrintf("c1.x:\n");
 	for(i=0;i<9;i++)
-		MyPrintf("%08x ",c1.x[i]);	MyPrintf("\n");	
+		MyPrintf("%08x ",c1.x[i]);	MyPrintf("\n");
 
 	MyPrintf("c1.y:\n");
 	for(i=0;i<9;i++)
-		MyPrintf("%08x ",c1.y[i]);	MyPrintf("\n");	
+		MyPrintf("%08x ",c1.y[i]);	MyPrintf("\n");
 
 	MyPrintf("c2.x:\n");
 	for(i=0;i<9;i++)
-		MyPrintf("%08x ",c2.x[i]);	MyPrintf("\n");	
+		MyPrintf("%08x ",c2.x[i]);	MyPrintf("\n");
 
 	MyPrintf("c2.y:\n");
 	for(i=0;i<9;i++)
-		MyPrintf("%08x ",c2.y[i]);	MyPrintf("\n");	
-	#endif	
-	
+		MyPrintf("%08x ",c2.y[i]);	MyPrintf("\n");
+	#endif
+
 	calc_xor(r3, c1.x, c2.x, 9);
 	calc_xor(r6, c1.y, c2.y, 9);
 	memcpy(r7, (uint32_t *)CONST_LONG_ONE, 36);
@@ -82,7 +82,7 @@
 		MyPrintf("%08x ",*(para->p_c+i));	MyPrintf("\n");
 	MyPrintf("p_q:\n");
 	MyPrintf("%08x ",REDQR);
-	#endif	
+	#endif
 
 	REDQR=para->p_q;
 
@@ -100,12 +100,12 @@
 	MyPrintf("r10:\n");
 	for(i=0;i<9;i++)
 		MyPrintf("%08x ",r10[i]);	MyPrintf("\n");
-	#endif	
+	#endif
 
 	calc_xor(rtemp1, r3, r6, para->len_words);
 	calc_modmul_f2m_2(rtemp2,r6,rtemp1,para->p,para->p_c,para->len_words, 1);
 	calc_modmul_f2m_2(rtemp1,para->a,r9,para->p,para->p_c,para->len_words, 1);
-	calc_xor(rtemp2, rtemp2, r10, para->len_words); 
+	calc_xor(rtemp2, rtemp2, r10, para->len_words);
 	calc_xor(rtemp2, rtemp2, rtemp1, para->len_words);//11
 	calc_modmul_f2m_2(c3.x,r3,rtemp2,para->p,para->p_c,para->len_words, 1);
 
@@ -127,7 +127,7 @@
 
 	memcpy(result->x, c3.x,para->len_words*4);
 	memcpy(result->y, c3.y,para->len_words*4);
-	
+
 }
 
 void sm2_bin_padd_2(ecc_point_a *result, ecc_point_j *a, ecc_point_j *b, ecc_para *para)
@@ -139,7 +139,7 @@
 	uint32_t r3[9];
 	uint32_t r4[9];
 	uint32_t r5[9];
-	
+
 	uint32_t rtemp1[9];
 	uint32_t rtemp2[9];
 	uint8_t i=0;
@@ -160,7 +160,7 @@
 	memcpy(z2, (unsigned int *)(b->z), 33);
 
 	calc_modmul_f2m_2(r2, c1.x, c1.x, para->p, para->p_c, para->len_words, 1);
-	
+
 	calc_xor(r3, r2, c1.y, para->len_words);
 
 	calc_modmul_f2m_2(r4, c1.x, c1.x, para->p, para->p_c, para->len_words, 1);
@@ -244,14 +244,14 @@
 	if (config==ECC_P192 || config==ECC_P224 || config==ECC_P256)
 	{
 		para->field=ECC_PRIME;
-		
+
 //		calc_mod(para->p_c,para->p,para->len_words);
 //		rsa_modinv2(&para->p_q,para->p);
 //		calc_modinv2(&para->p_q,para->p);
 
 		calc_const_c(para->p_c, para->p,para->len_words);
 		calc_const_q(&para->p_q, para->p);
-		
+
 		calc_add(result,para->p,three,para->len_words);
 		if (mem_cmp(result,para->a,para->len_words) == EQUAL)
 		{
@@ -270,7 +270,7 @@
 		calc_const_q_f2m(&para->p_q, para->p);
 
 		//calc_const_c_f2m(para->n_c, para->n,para->len_words);
-		//calc_const_q_f2m(&(para->n_q), para->n); 
+		//calc_const_q_f2m(&(para->n_q), para->n);
 		RECR &= ~(1<<4);
 	}
 	calc_const_c(para->n_c, para->n,para->len_words);
@@ -326,7 +326,7 @@
 		return value;
 	}
 	else
-		cpu_close_branch_self();	
+		cpu_close_branch_self();
 #else
 	if (value!=RET_ECC_POINT_SUCCESS)
 		return value;
@@ -353,7 +353,7 @@
 
 	security.mask=INT_MASK_CLOSE;
 	security.verify=EC_PARA_VERIFY_CLOSE;
-		
+
 //	if (para->field==ECC_PRIME)  //Prime field
 	{
 		//����Qx,Qy�Ƿ���Fp��Ԫ�ص���ȷ��ʾ
@@ -380,11 +380,11 @@
 #endif
 		//����Q�Ƿ�������a��b�������Բ���߷���
 		value=ecc_verifypoint(&key->e,para);
-		
+
 		#ifdef ECC_DEBUG
 			MyPrintf("ecc_verifykey; ecc_verifypoint:::%c%c%c%c\n",value,value>>8,value>>16,value>>24);
-		#endif		
-	
+		#endif
+
 #ifdef SCHEME_SECURITY
 		cpu_open_branch_self();
 		if (value==RET_ECC_POINT_FAILED)
@@ -412,7 +412,7 @@
 			tmp4.x=tmp1;
 			tmp4.y=tmp2;
 			value=ecc_pmul(&tmp4,&key->e,para->n,para,&security,NULL,0);
-			MyPrintf("ecc_verifykey; ecc_pmul:::%c%c%c%c\n",value,value>>8,value>>16,value>>24);	
+			MyPrintf("ecc_verifykey; ecc_pmul:::%c%c%c%c\n",value,value>>8,value>>16,value>>24);
 			cpu_open_branch_self();
 			if (value!=RET_ECC_POINT_INFINITE_FAR)  //�����������Զ��
 			{
@@ -457,10 +457,10 @@
 			tmp4.x=tmp1;
 			tmp4.y=tmp2;
 			value=ecc_pmul(&tmp4,&key->e,para->n,para,&security,NULL,0);
-			
+
 			#ifdef ECC_DEBUG
 				MyPrintf("ecc_verifykey; ecc_pmul:::%c%c%c%c\n",value,value>>8,value>>16,value>>24);
-			#endif	
+			#endif
 			if (value!=RET_ECC_POINT_INFINITE_FAR)  //�����������Զ��
 				return RET_ECC_PUBLIC_KEY_FAILED;
 		}
@@ -658,7 +658,7 @@
 		len_words=para->len_words;
 		cpu_close_branch_self();
 	}
-#else	
+#else
 	if (security->mask!=INT_MASK_CLOSE)   //���ѡ����Կ����
 	{
 		mem_cpy(b_d, b, para->len_words);
@@ -684,7 +684,7 @@
 
 	//�������
 	if ((k[0] & 1 )== 0)
-		RECR |= 1 << 3;	
+		RECR |= 1 << 3;
 	value = ecc_pmul_calc(result, a, k, len_words, para);
 #ifdef SCHEME_SECURITY
 		cpu_open_branch_self();
@@ -746,7 +746,7 @@
 	}
 	else
 		cpu_close_branch_self();
-#else	
+#else
 	if (security->verify!=EC_PARA_VERIFY_CLOSE)
 	{
 		value=ecc_verifypoint(result,para);
@@ -786,8 +786,8 @@
       ecc_para *para:ecc����������ݽṹָ��
 �����*result�������ָ��
 ���أ��Ƿ�����Զ��
-      RET_ECC_POINT_SUCCESS-������Զ�㣬
-      RET_ECC_POINT_INFINITE_FAR-����Զ��
+    RET_ECC_POINT_SUCCESS-������Զ�㣬
+    RET_ECC_POINT_INFINITE_FAR-����Զ��
 *************************************************/
 uint32_t ecc_padd_ja(ecc_point_j *result,ecc_point_j *a,ecc_point_a *b,ecc_para *para)
 {
@@ -939,7 +939,7 @@
 		{
 			//�������Զ��
 			mem_cpy(result->x,CONST_LONG_ONE,para->len);
-		    mem_cpy(result->y,CONST_LONG_ONE,para->len);
+			mem_cpy(result->y,CONST_LONG_ONE,para->len);
 			mem_set(result->z,0,para->len);
 			return RET_POINT_INFINITE_FAR;
 		}
@@ -1050,8 +1050,8 @@
 
 �����*result�������ָ��
 ���أ��Ƿ�����Զ��
-      RET_ECC_POINT_SUCCESS-������Զ�㣬
-      RET_ECC_POINT_INFINITE_FAR-����Զ��
+    RET_ECC_POINT_SUCCESS-������Զ�㣬
+    RET_ECC_POINT_INFINITE_FAR-����Զ��
 *************************************************/
 uint32_t ecc_pmul_calc(ecc_point_a *result,ecc_point_a *a, uint32_t *k,uint32_t k_len,ecc_para *para)
 {
@@ -1069,7 +1069,7 @@
 	tmp_j2.x =tmp_x2;
 	tmp_j2.y =tmp_y2;
 	tmp_j2.z =tmp_z2;
-	
+
 	mem_cpy(tmp_j.x, (volatile unsigned int *)(a->x), para->len_words);
 	mem_cpy(tmp_j.y, (volatile unsigned int *)(a->y), para->len_words);
 //	mem_set(tmp_j->z, (volatile unsigned int *)CONST_LONG_ONE, para->len_words);
@@ -1090,7 +1090,7 @@
 	if (para->field == ECC_PRIME)
 	{
 		ecc_pdbl_a(result, a, para);
-		
+
 #ifdef ECC_DEBUG
 		MyPrintf("result:\n");
 		for(i=0;i<para->len_words;i++)
@@ -1099,7 +1099,7 @@
 		for(i=0;i<para->len_words;i++)
 			MyPrintf("%08x ",result->y[i]);	MyPrintf("\n\n");
 #endif
-		ecc_padd_ja(&tmp_j2, &tmp_j, result, para);	
+		ecc_padd_ja(&tmp_j2, &tmp_j, result, para);
 		calc_modsub(n1y, para->p, a->y, para->p, para->len_words);
 		calc_modsub(n3y, para->p, tmp_j2.y, para->p, para->len_words);
 		mem_cpy(p3x, tmp_j2.x, para->len_words);
@@ -1149,7 +1149,7 @@
 		mem_cpy(REDBR, (volatile unsigned int *)CONST_LONG_ONE, para->len_words);
 		mem_cpy(REDVR2, k, k_len);
 	}
-	
+
 	if ((k[0] & 1 )== 0)
 		RECR |= 1 << 3;
 	//configure the length of factor
@@ -1169,7 +1169,7 @@
 	{
 		return value;
 	}
-	
+
 	else if ((RESR & 0x4)||(RESR & 0x8))
 	{
 		#ifdef SM2_DEBUG
@@ -1183,7 +1183,7 @@
 		MyPrintf("\n RESR = 10\n");
 		#endif
 		mem_cpy(result->x, a->x, para->len_words);
-		calc_modadd_1(result->y, a->x, a->y, para->p, para->len_words);//ģ
+		calc_modadd_1(result->y, a->x, a->y, para->p, para->len_words);//������ģ��
 		return RET_ECC_POINT_SUCCESS;
 	}
 	if (result != NULL)
@@ -1225,44 +1225,44 @@
 		MyPrintf("para->p:\n");
 		for(i=0;i<para->len_words;i++)
 			MyPrintf("%08x ",para->p[i]);	MyPrintf("\n\n");
-#endif	
+#endif
 		mem_cpy(REDPR,para->p,para->len_words);
 		calc_modmul2(tmp1,a->y,a->y,para->p_c,para->len_words);
 #ifdef ECC_DEBUG
 		MyPrintf("tmp1:\n");
 		for(i=0;i<para->len_words;i++)
 			MyPrintf("%08x ",tmp1[i]);	MyPrintf("\n\n");
-#endif	
+#endif
 	calc_modmul2(tmp2,a->x,a->x,para->p_c,para->len_words);
 #ifdef ECC_DEBUG
 		MyPrintf("tmp2:\n");
 		for(i=0;i<para->len_words;i++)
 			MyPrintf("%08x ",tmp2[i]);	MyPrintf("\n\n");
-#endif	
+#endif
 		calc_modmul2(tmp2,tmp2,a->x,para->p_c,para->len_words);
 #ifdef ECC_DEBUG
 		MyPrintf("tmp2:\n");
 		for(i=0;i<para->len_words;i++)
 			MyPrintf("%08x ",tmp2[i]);	MyPrintf("\n\n");
-#endif	
+#endif
 		calc_modmul2(tmp3,para->a,a->x,para->p_c,para->len_words);
 #ifdef ECC_DEBUG
 		MyPrintf("tmp3:\n");
 		for(i=0;i<para->len_words;i++)
 			MyPrintf("%08x ",tmp3[i]);	MyPrintf("\n\n");
-#endif	
+#endif
 		calc_modadd(tmp2,tmp2,tmp3,para->p,para->len_words);
 #ifdef ECC_DEBUG
 		MyPrintf("tmp2:\n");
 		for(i=0;i<para->len_words;i++)
 			MyPrintf("%08x ",tmp2[i]);	MyPrintf("\n\n");
-#endif	
+#endif
 		calc_modadd(tmp2,tmp2,para->b,para->p,para->len_words);
 #ifdef ECC_DEBUG
 		MyPrintf("tmp2:\n");
 		for(i=0;i<para->len_words;i++)
 			MyPrintf("%08x ",tmp2[i]);	MyPrintf("\n\n");
-#endif	
+#endif
 		if (mem_cmp(tmp1,tmp2,para->len_words)!=EQUAL)
 			return RET_ECC_POINT_FAILED;
 	}
Index: yc_rsa.h
===================================================================
--- /YC3121_SDK/fw/crypt/yc_rsa.h	(revision 797)
+++ /YC3121_SDK/fw/crypt/yc_rsa.h	(working copy)
@@ -21,7 +21,7 @@
 	uint8_t  d[MAX_RSA_MODULUS_BYTES];    // RSA 私钥指数
 	uint8_t  dp[MAX_RSA_PRIME_BYTES];     // d mod (p-1)
 	uint8_t  dq[MAX_RSA_PRIME_BYTES];     // d mod (q-1)
-	uint8_t  qp[MAX_RSA_PRIME_BYTES];     // q^-1 mod p 
+	uint8_t  qp[MAX_RSA_PRIME_BYTES];     // q^-1 mod p
 	uint8_t  n_c[MAX_RSA_MODULUS_BYTES];  // 模数 n 参数 C，用于 n 的模幂运算
 	uint8_t  n_q[4];                      // 模数 n 参数 Q，用于 n 的模幂运算
 	uint8_t  p_c[MAX_RSA_PRIME_BYTES];    // 模数 p 参数 C，用于 p 的模幂运算
@@ -30,7 +30,7 @@
 	uint8_t  q_q[4];                      // 模数 q 参数 Q，用于 q 的模幂运算
 }RSA_PrivateKeyTypeDef;
 
- 
+
 typedef struct
 {
 	uint32_t bytes;                       //RSA密钥长度字节数，即 RSA 密钥为 bytes * 8bits ，由于固定参数 MAX_RSA_MODULUS_BYTES 的限定，bytes 最大值为 256
@@ -41,7 +41,7 @@
 }RSA_PublicKeyTypeDef;
 
 
-typedef struct 
+typedef struct
 {
   uint32_t bytes;                       //RSA密钥长度字节数，即 RSA 密钥为 bytes * 8bits ，由于固定参数 MAX_RSA_MODULUS_BYTES 的限定，bytes 最大值为 256
 	uint8_t  e[4];                        //RSA 公钥指数
@@ -49,7 +49,7 @@
 }RSA_PublicKeyTypeDef2;
 
 
-typedef struct 
+typedef struct
 {
   uint32_t bytes;                       //RSA密钥长度字节数，即 RSA 密钥为 bytes * 8bits ，由于固定参数 MAX_RSA_MODULUS_BYTES 的限定，bytes 最大值为 256
 	uint8_t  e[4];                        //RSA 公钥指数
@@ -103,7 +103,7 @@
 
 /**
   * @method	RSA_Public
-  * @brief	Raw RSA public-key operation. 
+  * @brief	Raw RSA public-key operation.
   * @param	output : output data buffer
   * @param	input  : input data buffer
   * @param	key    : RSA public key
@@ -115,7 +115,7 @@
 uint32_t RSA_Private_Standard(uint8_t *output,uint8_t *input, RSA_PrivateKeyTypeDef *para,rng_callback f_rng, void *p_rng);
 
 uint32_t RSA_Public(uint8_t *output, uint8_t *input, RSA_PublicKeyTypeDef *key, rng_callback f_rng, void *p_rng);
-							
+
 /**
   * @method	RSA_GenerateKey
   * @brief	Generate a RSA private key
@@ -130,7 +130,7 @@
 
 /**
   * @method	RSA_CompleteKey
-  * @brief	complete the private key by the rsa key paras p q d. 
+  * @brief	complete the private key by the rsa key paras p q d.
   * @param	key   : rsa private key point
   * @param	f_rng : true random number generation function point
   * @param	p_rng : true random number generation para
@@ -140,7 +140,7 @@
 
 /**
   * @method	RSA_CompleteKey_e
-  * @brief	complete the private key by the rsa key paras p q e. 
+  * @brief	complete the private key by the rsa key paras p q e.
   * @param	key   : rsa private key point
   * @param	f_rng : true random number generation function point
   * @param	p_rng : true random number generation para
@@ -150,7 +150,7 @@
 
 /**
   * @method	RSA_GetPrativeKey_C_Q
-  * @brief	
+  * @brief
   * @param	key   : rsa private key point
   * @param	f_rng : true random number generation function point
   * @param	p_rng : true random number generation para
@@ -160,7 +160,7 @@
 
 /**
   * @method	RSA_GetPublicKey_C_Q
-  * @brief	
+  * @brief
   * @param	key   : rsa private key point
   * @param	f_rng : true random number generation function point
   * @param	p_rng : true random number generation para
@@ -169,7 +169,7 @@
 uint32_t RSA_GetPublicKey_C_Q(RSA_PublicKeyTypeDef *key, rng_callback f_rng, void *p_rng);
 /**
   * @method	RSA_IsPrime
-  * @brief	
+  * @brief
   * @param	X     : big number array
   * @param	size  : the big number len (32bit)
   * @param	f_rng : true random number generation function point
@@ -180,7 +180,7 @@
 
 /**
   * @method	RSA_GeneratePrime
-  * @brief	
+  * @brief
   * @param	X     : big number array
   * @param	size  : the big number bits (192/256/512/1024)
   * @param	f_rng : true random number generation function point
@@ -209,7 +209,7 @@
 
 /**
   * @method	RSA_Public_Func
-  * @brief	Raw RSA public-key operation. 
+  * @brief	Raw RSA public-key operation.
   * @param	output		:output data buffer
   * @param	input		:input data buffer
   * @param	key			:RSA public key
@@ -221,6 +221,6 @@
   * @retval				:RET_RSA_SUCCESS or RET_RSA_FAILURE
   */
 uint32_t RSA_Public_Func(uint8_t *output, uint8_t *input, RSA_PublicKeyTypeDef2 *para,rng_callback f_rng, void *p_rng);
-							
+
 #endif
 
Index: yc_rsa.c
===================================================================
--- /YC3121_SDK/fw/crypt/yc_rsa.c	(revision 797)
+++ /YC3121_SDK/fw/crypt/yc_rsa.c	(working copy)
@@ -17,14 +17,14 @@
 
 void mem_rollcpy(volatile uint32_t *result,uint32_t *content,uint32_t wlen, uint32_t startflag)
 {
-	uint32_t StartPosition;	
+	uint32_t StartPosition;
 	uint32_t tmp_a;
 	//uint32_t tmp_b;
 	if(wlen == 0)
 		return;
 	cpu_open_uniform_branch_timing();
 	cpu_open_branch_self();
-/*	
+/*
 	while((tmp & 0x80000000)==0)
 	{
 		tmp = tmp<<1;
@@ -32,26 +32,26 @@
 	}
 	tmp = (1<<(31 - icnt)) - 1;
 	startflag &= tmp;
-*/	
+*/
 	//startflag = startflag%wlen;
 	tmp_a = *REDAR;
 	//tmp_b = *REDBR;
 	calc_mod(&StartPosition,&startflag,&wlen,1,1);
 	*REDAR = tmp_a;
 	//*REDBR = tmp_b;
-	
-	//StartPosition = (startflag & (wlen-1));	
+
+	//StartPosition = (startflag & (wlen-1));
 	rollcpy(result, content, wlen, StartPosition);
 
 	cpu_close_branch_self();
 	cpu_close_uniform_branch_timing();
-	
+
 }
 
 void mem_rollcpy_pq(volatile uint32_t *result,uint32_t *content,uint32_t wlen, uint32_t startflag)
 {
 
-	uint32_t StartPosition;	
+	uint32_t StartPosition;
 	uint32_t tmp_a;
 	//uint32_t tmp_b;
 	if(wlen == 0)
@@ -75,7 +75,7 @@
 	//*REDBR = tmp_b;
 	//StartPosition = (startflag & (wlen-1));
 	rollcpy_pq(result, content, wlen, StartPosition);
-	
+
 	cpu_close_branch_self();
 	cpu_close_uniform_branch_timing();
 }
@@ -83,7 +83,7 @@
 void mem_rollset(uint32_t *result,uint32_t content,uint32_t wlen, uint32_t startflag)
 {
 
-	uint32_t StartPosition;	
+	uint32_t StartPosition;
 	if(wlen == 0)
 		return;
 	cpu_open_uniform_branch_timing();
@@ -154,7 +154,7 @@
 	uint32_t tmp = 0;
 	uint32_t StartPosition;
 	uint32_t xor=0;
-	
+
 	if(wlen == 0)
 		return 0;
 	cpu_open_uniform_branch_timing();
@@ -180,7 +180,7 @@
 	xor ^= result[icnt] ;
 	result[icnt] &= 0xFFFFFFFE;
 	icnt +=1;
-s1:		
+s1:
 	if(icnt >= wlen)
 		goto s2;
 //	__asm("NOP");
@@ -238,19 +238,19 @@
 				//AND result[icnt], result[icnt], #0xFFFFFFFF
 				mov r8,result[icnt]
 				and r8,r8,#0xFFFFFFFF
-				mov result[icnt],r8				
+				mov result[icnt],r8
 				ADD icnt,icnt,#1
 				B   s1
 		s2:
 				CMP tmp,StartPosition
 				BCS s4
 				NOP
-				NOP				
+				NOP
 				MOV result[tmp], content[tmp]
 				//AND result[tmp], result[tmp], #0xFFFFFFFE
 				mov r8,result[tmp]
 				and r8,r8,#0xFFFFFFFE
-				mov result[tmp],r8					
+				mov result[tmp],r8
 				ADD tmp,tmp,#1
 
 		s3:
@@ -264,7 +264,7 @@
 				//AND result[tmp], result[tmp], #0xFFFFFFFF
 				mov r8,result[tmp]
 				and r8,r8,#0xFFFFFFFF
-				mov result[tmp],r8					
+				mov result[tmp],r8
 				ADD tmp,tmp,#1
 				B   s3
 		s4:
@@ -284,10 +284,10 @@
 	uint32_t StartPosition;
 	cpu_open_uniform_branch_timing();
 	cpu_open_branch_self();
-	
+
 	if(wlen == 0)
 		return 0;
-/*		
+/*
 	while((tmp & 0x80000000) == 0)
 	{
 		tmp = tmp<<1;
@@ -316,7 +316,7 @@
 	    mov  icnt,#0
 	    teq  icnt,StartPosition
 	    beq  s5
-	 
+
 	    adds result[icnt],a[icnt],b[icnt]
 	    add  icnt,icnt,#1
 	    teq  icnt,StartPosition
@@ -350,7 +350,7 @@
 	cpu_open_branch_self();
     rt=calc_add(result,a,b,wlen);
 	cpu_close_uniform_branch_timing();
-	cpu_close_branch_self(); 
+	cpu_close_branch_self();
 	return rt;
 }
 
@@ -401,7 +401,7 @@
 						0x4F,0xED,0x55,0x06,0x28,0x57,0x79,0xB2,
 						0x16,0xEE,0xD0,0x9B,0xD3,0x95,0x7E,0xE4,
 						0x3D,0xC2,0xF5,0xC7,0xFD,0x8C,0xBC,0xC2};
-*/	
+*/
 
 	para->e[0] = exponent;
 	para->e[1] = exponent>>8;
@@ -428,7 +428,7 @@
 // 	}
 // #endif
 	return RSA_CompleteKey_e(para, f_rng, p_rng);
-	
+
 }
 
 uint32_t RSA_GenerateKey(RSA_PrivateKeyTypeDef *para, uint32_t exponent, uint32_t nbits,
@@ -436,7 +436,6 @@
 {
 	uint8_t i = 100;
 	uint32_t ret = 0;
-
 	while (i--)
 	{
 		ret = _RSA_GenerateKey(para, exponent, nbits, f_rng, p_rng);
@@ -448,7 +447,7 @@
 
 /**
   * @method	RSA_Public
-  * @brief	Raw RSA public-key operation. 
+  * @brief	Raw RSA public-key operation.
   * @param	output		:output data buffer
   * @param	input		:input data buffer
   * @param	key			:RSA public key
@@ -460,13 +459,13 @@
 uint32_t RSA_Public(uint8_t *output, uint8_t *input, RSA_PublicKeyTypeDef *para,
 							rng_callback f_rng, void *p_rng)
 {
-    	uint32_t value;
+    uint32_t value;
 	calc_operand operand;
 //	uint8_t nc[64*4];
 	uint32_t wlen = para->bytes>>2;
 	uint8_t d_temp[MAX_RSA_MODULUS_BYTES]={0};
 	uint32_t i;
-	
+
 //	for(i=0;i<para->bytes;i++)
 //		d_temp[i] = input[para->bytes-1-i];
 	memcpy(d_temp,input,para->bytes);
@@ -474,18 +473,18 @@
 	RSA_GetPublicKey_C_Q(para,f_rng,NULL);
 //	reverse_pub(para);
 	calc_mod((uint32_t *)d_temp,(uint32_t *)d_temp,(uint32_t *)para->n,para->bytes>>2,para->bytes>>2);
-		
+
 	operand.a = (uint32_t *)d_temp;
 	operand.b = (uint32_t *)para->e;
 	operand.p = (uint32_t *)para->n;
 	operand.c = (uint32_t *)para->n_c;
 	operand.q = para->n_q[0]+(para->n_q[1]<<8)+(para->n_q[2]<<16)+(para->n_q[3]<<24);
 	value = calc_modexp((uint32_t *)output, &operand, wlen, 1);
-	
+
 //	calc_setsecurity(7);
 //	value = calc_modexp(result, &operand, wlen, 1);
 //	calc_setsecurity(0);
-	
+
 	if(value!=RET_CALC_IMPLEMENT_SUCCESS)
 	{
 //		reverse_pub(para);
@@ -507,14 +506,14 @@
 		 para->wlen: the word-length of the value pointed to by content
 		 para->e: RSA public key
 		 para->n: a pointer to RSA public modulus
-		 para->p: a pointer to prime p 
+		 para->p: a pointer to prime p
 		 para->q: a pointer to prime q
 		 para->d: a pointer to RSA private key
 		 para->n_c: a pointer to the factor c for modulus n
 		 para->n_q: the factor q for modulus n
-		 rand_bot: a pointer to a random number for base masking 
+		 rand_bot: a pointer to a random number for base masking
 		 rand_exp: a pointer to a random number for exponent masking
-		 function_mark: the pointer of function mark value, the value is initial 
+		 function_mark: the pointer of function mark value, the value is initial
 		 value set by user when inputting
 * Output: result: a pointer to a variable to store the result of para->wlen words got from RSA_Private_Standard().
 		  function_mark: the pointer of function mark value, the value is sum of
@@ -536,10 +535,10 @@
 	uint8_t d_temp[MAX_RSA_MODULUS_BYTES]={0};
 	uint32_t *content= (uint32_t *)d_temp,*result=(uint32_t *)output;
 	uint32_t rand_exp[2]= {0,0};
-	uint32_t rand_bot[2] = {0,0};	
+	uint32_t rand_bot[2] = {0,0};
 	(*f_rng)((uint8_t *)rand_exp ,8,p_rng);
 	(*f_rng)((uint8_t *)rand_bot ,8,p_rng);
-		
+
 	operand.c = (uint32_t *)para->n_c;
 	operand.p = (uint32_t *)para->n;
 	operand.q = para->n_q[0]+(para->n_q[1]<<8)+(para->n_q[2]<<16)+(para->n_q[3]<<24);
@@ -557,14 +556,14 @@
 	//bottom masking
 	//rf_inv = rf^-1 % n
 	calc_modinv2048(c_buf, rand_bot, (uint32_t *)para->n, 2, wlen);
-	
+
 	//ri = rf_inv^e % n
 	operand.a = c_buf;
 	operand.b = (uint32_t *)(para->e);
 	calc_modexp(NULL, &operand, wlen, 1);
 	//C1 = ri*C % n
 	calc_modmul2(c_buf, NULL, content, (uint32_t *)para->n_c, wlen);
-	function_mark+=0x2828;		
+	function_mark+=0x2828;
 	//exponent masking
 
 	////w = (p-1)*(q-1)
@@ -572,24 +571,24 @@
 	{
 		mem_set(result, 0, wlen); //////////////
 		return RET_RSA_IMPLEMENT_ERROR;
-	}	
+	}
 	else
 		function_mark+=0x3737;	////////////////////////////////
 	#if 0
 	mem_cpy(REDAR, para->p, wlen>>1);
 	REDAR[0]--;
 	mem_cpy(REDBR, para->q, wlen>>1);
-	REDBR[0]--;  
+	REDBR[0]--;
 	#endif
 	#if 1
 	if(*rand_bot >= *rand_exp)
-	{	
+	{
 		if(mem_rollcpy_pq(REDAR, (uint32_t *)para->p, wlen>>1, *rand_bot) != para->p_xor)
-		{	
+		{
 			return RET_RSA_IMPLEMENT_ERROR;
 		}
 		if(mem_rollcpy_pq(REDBR, (uint32_t *)para->q, wlen>>1, *rand_exp) != para->q_xor)
-		{	
+		{
 			return RET_RSA_IMPLEMENT_ERROR;
 		}
 	}
@@ -602,11 +601,11 @@
 	}
 	#endif
 	//REDAR[0]--;
-	//REDBR[0]--; 
+	//REDBR[0]--;
 
 	RECFR = (((wlen>>1)-1)<<8) | ((wlen>>1)-1);
 	calc_run(FUNC_MUL);
-	mem_cpy(d_buf, REDCR, wlen); 
+	mem_cpy(d_buf, REDCR, wlen);
 
 
 	//d1 = d+rand*w
@@ -614,32 +613,32 @@
 	mem_rollcpy(REDAR,  (uint32_t *)para->d, wlen, *rand_exp);
 	//mem_cpy(REDAR, para->d, wlen);
 	cpu_open_uniform_branch_timing();
-	cpu_open_branch_self();	
+	cpu_open_branch_self();
 	b_len = calc_add(d_buf,REDAR, d_buf, wlen);
 	cpu_close_uniform_branch_timing();
-	cpu_close_branch_self();	
+	cpu_close_branch_self();
 	//b_len = calc_rolladd(d_buf,para->d, d_buf, wlen, *rand_exp);
 	if(b_len == 1)
 		calc_add(&d_buf[wlen], &d_buf[wlen], (volatile unsigned int *)CONST_LONG_ONE, 2);
 	operand.b = d_buf;
 	b_len = wlen+2;
-	
+
 	function_mark+=0x3939;
 
 	//run
 	calc_modexp(d_buf, &operand, wlen, b_len);
 	mem_set(REDBR, 0, wlen);     //clear private key
-	
+
 	//clear bottom masking
 	mem_set(&c_buf[2],0,wlen-2);
 	mem_cpy(c_buf,rand_bot,2);
 	calc_modmul2(d_buf, c_buf, d_buf,  (uint32_t *)para->n_c, wlen);
-	
+
 	if(function_mark!=initial_mark+0xaaaa)/////////////////////////////////
-	{	
+	{
 		mem_set(result, 0, wlen); //////////////
 		return RET_RSA_IMPLEMENT_ERROR;
-	}	
+	}
 	else
 		function_mark+=0x1100;	///////
 	//inverse operation
@@ -647,11 +646,11 @@
 	function_mark+=0x1100;
 	cpu_open_branch_self();
 	if(function_mark!=initial_mark+0xccaa)/////////////////////////////////
-	{	
+	{
 		mem_set(result, 0, wlen); //////////////
 		cpu_close_branch_self();
 		return RET_RSA_IMPLEMENT_ERROR;
-	}	
+	}
 	else
 		function_mark+=0x10;	///////CCBA
 	if(mem_cmp(REDAR, content, wlen) != EQUAL)
@@ -668,14 +667,14 @@
 	}
 	else
 		cpu_close_branch_self();
-	
+
 	function_mark+=0x0012;
 	mem_cpy(result, d_buf, wlen);
 	if(function_mark!=initial_mark+0xcccc)/////////////////////////////////
-	{	
+	{
 		mem_set(result, 0, wlen); //////////////
 		return RET_RSA_IMPLEMENT_ERROR;
-	}	
+	}
 	else
 		return RET_RSA_IMPLEMENT_SUCCESS;
 }
@@ -692,8 +691,8 @@
 		 para->d: a pointer to RSA private key
 		 para->n_c: a pointer to the factor c for modulus n
 		 para->n_q: the factor q for modulus n
-		 rand_bot: a pointer to a random number for base masking 
-		 function_mark: the pointer of function mark value, the value is initial 
+		 rand_bot: a pointer to a random number for base masking
+		 function_mark: the pointer of function mark value, the value is initial
 		 value set by user when inputting
 * Output: result: a pointer to a variable to store the result of para->wlen words got from rsa_standards2().
           function_mark: the pointer of function mark value, the value is sum of
@@ -712,32 +711,32 @@
 	uint32_t c_buf[64];
 	uint32_t d_buf[64+2];
 	uint32_t initial_mark=0x1234;
-	uint32_t initial_mark2 =0x1234;	
+	uint32_t initial_mark2 =0x1234;
 	uint32_t *function_mark= &initial_mark2;
 	uint32_t rand_bot[2]= {0x321a25d, 0x54432b8a};
 	uint32_t wlen = key->bytes>>2;
 
 	RSA_GetPrativeKey_C_Q(key,f_rng,p_rng);
-	
+
 	operand.p = (uint32_t *)key->n;
 	operand.c = (uint32_t *)key->n_c;
-//	operand.q = (uint32_t *)key->n_q;	
+//	operand.q = (uint32_t *)key->n_q;
 	uint8touint32(&operand.q,key->n_q);
 
-///////////////////////////////////////////	
+///////////////////////////////////////////
 //	calc_const_c(key->n_c, key->n, wlen);
 //	calc_const_q(key->n_q, key->n);
 
 	if(*function_mark!=initial_mark)/////////////////////////////////
-	{	
+	{
 		mem_set((uint32_t *)output, 0, wlen); //////////////
 		return RET_RSA_IMPLEMENT_ERROR;
-	}	
+	}
 	else
 		*function_mark+=0x1212;	//////////////////////////
 	//bottom masking
 	//rf_inv = rf^-1 % n
-	
+
 	calc_modinv2048(c_buf, rand_bot, (uint32_t *)key->n, 2, wlen);
 	//ri = rf_inv^e % n
 	operand.a = c_buf;
@@ -752,36 +751,36 @@
 	operand.b = NULL;
 	mem_rollcpy(REDBR, (uint32_t *)key->d, wlen, *rand_bot);
 	b_len = wlen;
-	
+
 	//run
 	calc_setsecurity(7);
 	calc_modexp(d_buf, &operand, wlen, b_len);
 	calc_setsecurity(0);
 	//mem_set(REDBR, 0, wlen);     //clear private key
 	mem_set(REDBR, 0, wlen);
-	
+
 	//clear bottom masking
 	mem_set(&c_buf[2],0,wlen-2);
 	mem_cpy(c_buf,rand_bot,2);
 	calc_modmul2(d_buf, c_buf, d_buf, (uint32_t *)key->n_c, wlen);
-	
+
 	if(*function_mark!=initial_mark+0x6a6a)/////////////////////////////////
-	{	
+	{
 		mem_set((uint32_t *)output, 0, wlen); //////////////
 		return RET_RSA_IMPLEMENT_ERROR;
-	}	
+	}
 	else
 		*function_mark+=0x1100;	///////
 	//inverse operation
 	calc_modexp2(NULL, d_buf, (uint32_t *)key->e, (uint32_t *)key->n_c, wlen, 1);
-	
+
 	*function_mark+=0x1100;
 	cpu_open_branch_self();
 	if(*function_mark!=initial_mark+0x8c6a)/////////////////////////////////
-	{	
+	{
 		mem_set((uint32_t *)output, 0, wlen); //////////////
 		return RET_RSA_IMPLEMENT_ERROR;
-	}	
+	}
 	else
 		*function_mark+=0x10;	///////
 	if(mem_cmp(REDAR, (uint32_t *)input, wlen) != EQUAL)
@@ -801,15 +800,15 @@
 	*function_mark+=0x0012;
 	mem_cpy((uint32_t *)output, d_buf, wlen);
 	if(*function_mark!=initial_mark+0x8c8c)/////////////////////////////////
-	{	
+	{
 		mem_set((uint32_t *)output, 0, wlen); //////////////
 		return RET_RSA_IMPLEMENT_ERROR;
-	}	
+	}
 	else
 		return RET_RSA_SUCCESS;
-}	
+}
 */
-#endif	
+#endif
 /**
   * @method	RSA_Private
   * @brief	Raw RSA private-key operation. Useing CRT Algorithm
@@ -839,12 +838,12 @@
 
 	uint32_t rand_bot[2] = {0, 0};
 	uint32_t rand_dp[2] = {0, 0};
-	uint32_t rand_dq[2] ={0, 0};	
+	uint32_t rand_dq[2] ={0, 0};
 	uint32_t *content= (uint32_t *)d_temp,*result=(uint32_t *)output;
 	(*f_rng)((uint8_t *)rand_dp ,8,p_rng);
 	(*f_rng)((uint8_t *)rand_dq ,8,p_rng);
   	(*f_rng)((uint8_t *)rand_bot ,8,p_rng);
-  
+
 	c1=c_buf;
 	c2=&c_buf[32];
 	d1=d_buf;
@@ -856,51 +855,51 @@
 //	for(i=0;i<para->bytes;i++)
 //		d_temp[i] = input[para->bytes-1-i];
 //	memcpy_r(d_temp,d_temp,para->bytes);
-	
+
 
 	memcpy(d_temp,input,para->bytes);
-	
+
 //	reverse_pri(para);
 
 	calc_mod((uint32_t *)d_temp,(uint32_t *)d_temp,(uint32_t *)para->n,para->bytes>>2,para->bytes>>2);
 
 //	printf("data:\n");
-//	myprintf(d_temp,128);	
+//	myprintf(d_temp,128);
 
 	if(function_mark!=initial_mark)/////////////////////////////////
-	{	
+	{
 		mem_set(result, 0, wlen); //////////////
 //		reverse_pri(para);
 		return RET_RSA_FAILURE;
-	}	
+	}
 	else
 		function_mark+=0x1234;	//////////////////////////
 
-	
-	//bottom masking		
+
+	//bottom masking
 	///rf_inv=rf^-1 % n
 	calc_modinv2048(d_buf,rand_bot,(uint32_t *)para->n,2,wlen);
-	//ri=rf_inv^e % n	
-	
+	//ri=rf_inv^e % n
+
 	operand.a=d_buf;
 	operand.b=(uint32_t *)para->e;
 	operand.p=(uint32_t *)para->n;
 	operand.c=(uint32_t *)para->n_c;
 //	operand.q=para->n_q;
 	uint8touint32(&operand.q,para->n_q);
-	
+
 
 	calc_modexp(NULL,&operand,wlen,1);
 	calc_modmul2(d_buf, NULL, content, (uint32_t *)para->n_c, wlen);
 
 	function_mark+=0x2222;
-	
+
 	cpu_open_uniform_branch_timing();
-	cpu_open_branch_self();	
+	cpu_open_branch_self();
 	if((*rand_dq)&(0x01))
 	{
 		cpu_close_uniform_branch_timing();
-		cpu_close_branch_self();	
+		cpu_close_branch_self();
 		goto S1;
 	}
 	else
@@ -910,53 +909,53 @@
 		__asm("NOP");
 		__asm("NOP");
 		__asm("NOP");
-				
+
 	}
-	
 
-S0:	
+
+S0:
 	//c1 = c % q
 //	mem_rollcpy(REDBR, (uint32_t *)para->q, wlen>>1, *rand_dq);
 	if( mem_rollcpy(REDBR, (uint32_t *)para->q, wlen>>1, *rand_dq) != para->q_xor)
-	{	
-		mem_set(result, 0, wlen); 
+	{
+		mem_set(result, 0, wlen);
 		return RET_RSA_FAILURE;
-	}	
+	}
 	calc_div(NULL,c1,d_buf,NULL,wlen,wlen>>1);
-			
+
 	cpu_open_uniform_branch_timing();
-	cpu_open_branch_self();	
+	cpu_open_branch_self();
 	if((*rand_dq)&(0x01))
 	{
 		cpu_close_uniform_branch_timing();
-		cpu_close_branch_self();	
+		cpu_close_branch_self();
 		goto S2;
 	}
 	else
 	{
 		cpu_close_uniform_branch_timing();
-		cpu_close_branch_self();	
+		cpu_close_branch_self();
 		__asm("NOP");
 		__asm("NOP");
 		__asm("NOP");
 	}
-		
-S1:	
+
+S1:
 	//c2 = c % p
 //	mem_rollcpy(REDBR, (uint32_t *)para->p, wlen>>1, *rand_dp);
 	if( mem_rollcpy(REDBR, (uint32_t *)para->p, wlen>>1, *rand_dp) != para->p_xor)
-	{	
-		mem_set(result, 0, wlen); 
+	{
+		mem_set(result, 0, wlen);
 		return RET_RSA_FAILURE;
 	}
-	calc_div(NULL,c2,d_buf,NULL,wlen,wlen>>1);  
-	
+	calc_div(NULL,c2,d_buf,NULL,wlen,wlen>>1);
+
 	cpu_open_uniform_branch_timing();
-	cpu_open_branch_self();	
+	cpu_open_branch_self();
 	if((*rand_dq)&(0x01))
 	{
 		cpu_close_uniform_branch_timing();
-		cpu_close_branch_self();	
+		cpu_close_branch_self();
 		goto S0;
 	}
 	else
@@ -966,25 +965,25 @@
 		__asm("NOP");
 		__asm("NOP");
 		__asm("NOP");
-						
-	}	
-S2:	
-	
+
+	}
+S2:
+
 	if(function_mark!=initial_mark+0x3456)
-	{	
-		mem_set(result, 0, wlen); 
+	{
+		mem_set(result, 0, wlen);
 //		reverse_pri(para);
 		return RET_RSA_FAILURE;
-	}	
+	}
 	else
-		function_mark+=0x0a0a;	
+		function_mark+=0x0a0a;
 
 	cpu_open_uniform_branch_timing();
-	cpu_open_branch_self();	
+	cpu_open_branch_self();
 	if((*rand_dq)&(0x02))
 	{
 		cpu_close_uniform_branch_timing();
-		cpu_close_branch_self();	
+		cpu_close_branch_self();
 		goto S4;
 	}
 	else
@@ -994,23 +993,23 @@
 		__asm("NOP");
 		__asm("NOP");
 		__asm("NOP");
-						
-	}	
-		
-S3:	
+
+	}
+
+S3:
 	//exponent masking
 	mem_cpy(REDAR, rand_dq, 2);
 //	mem_rollcpy_pq(REDBR, (uint32_t *)para->q, wlen>>1, *(rand_dq + 1));
 	if( mem_rollcpy_pq(REDBR, (uint32_t *)para->q, wlen>>1, *rand_dq) != para->q_xor )
-	{	
-		mem_set(result, 0, wlen); 
+	{
+		mem_set(result, 0, wlen);
 		return RET_RSA_FAILURE;
 	}
-	RECFR = (((wlen>>1)-1)<<8) | 1; 
+	RECFR = (((wlen>>1)-1)<<8) | 1;
 	calc_run(FUNC_MUL);
 	mem_cpy(d1, REDCR, (wlen>>1)+2);
-	
-	
+
+
 	//d1=d+rand*w
 	mem_rollcpy(REDBR, (uint32_t *)para->dq, wlen>>1, *rand_bot);
 	b_len = calc_add_safe(d1,REDBR,d1,wlen>>1);
@@ -1018,11 +1017,11 @@
 		calc_add(&d1[wlen>>1],&d1[wlen>>1],(volatile unsigned int *)CONST_LONG_ONE,2);
 
 	cpu_open_uniform_branch_timing();
-	cpu_open_branch_self();	
+	cpu_open_branch_self();
 	if((*rand_dq)&(0x02))
 	{
 		cpu_close_uniform_branch_timing();
-		cpu_close_branch_self();	
+		cpu_close_branch_self();
 		goto S5;
 	}
 	else
@@ -1032,22 +1031,22 @@
 		__asm("NOP");
 		__asm("NOP");
 		__asm("NOP");
-						
-	}		
-	
-S4:		
+
+	}
+
+S4:
     //rand * (p-1)
 	mem_cpy(REDAR, rand_dq, 2);
 //	mem_rollcpy_pq(REDBR, (uint32_t *)para->p, wlen>>1, *rand_dp);
 	if( mem_rollcpy_pq(REDBR, (uint32_t *)para->p, wlen>>1, *rand_dp) != para->p_xor )
-	{	
-		mem_set(result, 0, wlen); 
+	{
+		mem_set(result, 0, wlen);
 		return RET_RSA_FAILURE;
-	}	
-	RECFR = (((wlen>>1)-1)<<8) | 1; 
+	}
+	RECFR = (((wlen>>1)-1)<<8) | 1;
 	calc_run(FUNC_MUL);
 	mem_cpy(d2, REDCR, (wlen>>1)+2);
-	
+
 
 	function_mark+=0x1010;
 	//d2=d+rand*w
@@ -1057,11 +1056,11 @@
 		calc_add(&d2[wlen>>1],&d2[wlen>>1],(volatile unsigned int *)CONST_LONG_ONE,2);
 
 	cpu_open_uniform_branch_timing();
-	cpu_open_branch_self();	
+	cpu_open_branch_self();
 	if((*rand_dq)&(0x02))
 	{
 		cpu_close_uniform_branch_timing();
-		cpu_close_branch_self();	
+		cpu_close_branch_self();
 		goto S3;
 	}
 	else
@@ -1071,14 +1070,14 @@
 		__asm("NOP");
 		__asm("NOP");
 		__asm("NOP");
-			
-	}		
-	
-S5:	
+
+	}
+
+S5:
 	b_len=(wlen>>1)+2;
 
 	cpu_open_uniform_branch_timing();
-	cpu_open_branch_self();	
+	cpu_open_branch_self();
 	if((*rand_dq)&(0x04))
 	{
 		cpu_close_uniform_branch_timing();
@@ -1095,49 +1094,49 @@
 		__asm("NOP");
 
 	}
-				
-S6:		
+
+S6:
 
 	operand.a=c1;
 	operand.b=d1;
 	//operand.p=para->q;
 	operand.p=NULL;
-//	mem_rollcpy(REDPR, (uint32_t *)para->q, wlen>>1, *rand_dq);	
+//	mem_rollcpy(REDPR, (uint32_t *)para->q, wlen>>1, *rand_dq);
 	if( mem_rollcpy(REDPR, (uint32_t *)para->q, wlen>>1, *rand_dq) != para->q_xor )
-	{	
-		mem_set(result, 0, wlen); 
+	{
+		mem_set(result, 0, wlen);
 		return RET_RSA_FAILURE;
 	}
 	operand.c=(uint32_t *)para->q_c;
 //	operand.q=para->q_q;
 	uint8touint32(&operand.q,para->q_q);
 	calc_modexp(m1,&operand,wlen>>1,b_len);
-	if (mem_rollcmp(REDPR,(uint32_t *)para->q,wlen>>1,*rand_dq) != CMPOK)  
-	{	
-		mem_set(result, 0, wlen); 
-		return RET_RSA_FAILURE;
-	}	
-		
-	
+	if (mem_rollcmp(REDPR,(uint32_t *)para->q,wlen>>1,*rand_dq) != CMPOK)
+	{
+		mem_set(result, 0, wlen);
+		return RET_RSA_FAILURE;
+	}
+
+
 	cpu_open_uniform_branch_timing();
-	cpu_open_branch_self();	
+	cpu_open_branch_self();
 	if((*rand_dq)&(0x04))
 	{
 		cpu_close_uniform_branch_timing();
-		cpu_close_branch_self();	
+		cpu_close_branch_self();
 		goto S8;
 	}
 	else
 	{
 		cpu_close_uniform_branch_timing();
-		cpu_close_branch_self();	
+		cpu_close_branch_self();
 		__asm("NOP");
 		__asm("NOP");
 		__asm("NOP");
-			
-	}		
 
-S7:	
+	}
+
+S7:
 	//m2 = c2^d2 % p
 	operand.a=c2;
 	operand.b=d2;
@@ -1145,26 +1144,26 @@
 	operand.p = NULL;
 //	mem_rollcpy(REDPR, (uint32_t *)para->p, wlen>>1, *(rand_dp+1));
 	if( mem_rollcpy(REDPR, (uint32_t *)para->p, wlen>>1, *rand_dp) != para->p_xor)
-	{	
-		mem_set(result, 0, wlen); 
+	{
+		mem_set(result, 0, wlen);
 		return RET_RSA_FAILURE;
 	}
 	operand.c=(uint32_t *)para->p_c;
 //	operand.q=para->p_q;
 	uint8touint32(&operand.q,para->p_q);
 	calc_modexp(m2,&operand,wlen>>1,b_len);
-	if (mem_rollcmp(REDPR,(uint32_t *)para->p,wlen>>1,*rand_dp) != CMPOK)  
-	{	
-		mem_set(result, 0, wlen); 
+	if (mem_rollcmp(REDPR,(uint32_t *)para->p,wlen>>1,*rand_dp) != CMPOK)
+	{
+		mem_set(result, 0, wlen);
 		return RET_RSA_FAILURE;
-	}	
+	}
 
 	cpu_open_uniform_branch_timing();
-	cpu_open_branch_self();	
+	cpu_open_branch_self();
 	if((*rand_dq)&(0x04))
 	{
 		cpu_close_uniform_branch_timing();
-		cpu_close_branch_self();	
+		cpu_close_branch_self();
 		goto S6;
 	}
 	else
@@ -1174,8 +1173,8 @@
 		__asm("NOP");
 		__asm("NOP");
 		__asm("NOP");
-	}		
- S8:		
+	}
+ S8:
     mem_set(REDBR,0,wlen);  //clear key register
 
 	//(m2-m1)
@@ -1185,47 +1184,47 @@
     	{
  //   		mem_rollcpy(REDBR, (uint32_t *)para->p, wlen>>1, *rand_dp);
 			if( mem_rollcpy(REDBR, (uint32_t *)para->p, wlen>>1, *rand_dp) != para->p_xor )
-			{	
-				mem_set(result, 0, wlen); 
+			{
+				mem_set(result, 0, wlen);
 				return RET_RSA_FAILURE;
 			}
 			b_len = calc_add_safe(m2,m2,REDBR,wlen>>1);
-			if (mem_rollcmp(REDBR,(uint32_t *)para->p,wlen>>1,*rand_dp) != CMPOK)  
-			{	
-				mem_set(result, 0, wlen); 
+			if (mem_rollcmp(REDBR,(uint32_t *)para->p,wlen>>1,*rand_dp) != CMPOK)
+			{
+				mem_set(result, 0, wlen);
 				return RET_RSA_FAILURE;
-			}	
-    	}while(mem_cmp(m2,m1,wlen>>1)==SMALLER && b_len==0);      
+			}
+    	}while(mem_cmp(m2,m1,wlen>>1)==SMALLER && b_len==0);
 }
-/*	else 
+/*	else
 	{
 		do
 	    	{
 	    		mem_rollcpy(REDAR, (uint32_t *)para->p, wlen>>1, *(rand_dp+1));
 				b_len = calc_add_safe(REDBR,REDBR,REDAR,wlen>>1);
-	    	}while(mem_cmp(m2,m1,wlen>>1)==SMALLER && b_len==0);      
+	    	}while(mem_cmp(m2,m1,wlen>>1)==SMALLER && b_len==0);
 	}
 */
-	
+
 	calc_sub(m2,m2,m1,wlen>>1);
-	
+
 	//(m2-m1)*(q^-1 mod p) mod p-------�޸�Ϊ2��
 
 //	mem_rollcpy(REDBR, (uint32_t *)para->p, wlen>>1, *rand_dp);
 	if( mem_rollcpy(REDBR, (uint32_t *)para->p, wlen>>1, *rand_dp) != para->p_xor )
-	{	
-		mem_set(result, 0, wlen); 
+	{
+		mem_set(result, 0, wlen);
 		return RET_RSA_FAILURE;
 	}
 	calc_div(NULL, d_buf, m2, NULL, wlen>>1, wlen>>1);
 	mem_rollcpy(REDAR, (uint32_t *)para->qp, wlen>>1, *rand_bot);
-	
+
 	//calc_modmul2(NULL, NULL, d_buf, para->p_c, wlen>>1);
-	
+
 //	mem_rollcpy(REDPR,(uint32_t *)para->p,wlen>>1,*(rand_dp+1));
 	if( mem_rollcpy(REDPR, (uint32_t *)para->p, wlen>>1, *rand_dp) != para->p_xor )
-	{	
-		mem_set(result, 0, wlen); 
+	{
+		mem_set(result, 0, wlen);
 		return RET_RSA_FAILURE;
 	}
 	mem_rollcpy(REDCR,(uint32_t *)para->p_c,wlen>>1,*(rand_bot+1));
@@ -1234,31 +1233,31 @@
 	REDQR= para->p_q[0]+(para->p_q[1]<<8)+(para->p_q[2]<<16)+(para->p_q[3]<<24);
 	RECFR=(((wlen>>1)-1)<<8) | ((wlen>>1)-1);
 	calc_run(FUNC_MODMUL_PRIME);
-	if (mem_rollcmp(REDPR,(uint32_t *)para->p,wlen>>1,*rand_dp) != CMPOK)  
-	{	
-		mem_set(result, 0, wlen); 
+	if (mem_rollcmp(REDPR,(uint32_t *)para->p,wlen>>1,*rand_dp) != CMPOK)
+	{
+		mem_set(result, 0, wlen);
 		return RET_RSA_FAILURE;
-	}	
-	
+	}
+
 	//([(m2-m1)*(q^-1 mod p) mod p])*q
 //	mem_rollcpy(REDBR, (uint32_t *)para->q, wlen>>1, *rand_dq);
 	if( mem_rollcpy(REDBR, (uint32_t *)para->q, wlen>>1, *rand_dq) != para->q_xor )
-	{	
-		mem_set(result, 0, wlen); 
+	{
+		mem_set(result, 0, wlen);
 		return RET_RSA_FAILURE;
 	}
 	calc_mul(result,NULL,NULL,wlen>>1,wlen>>1);
-	if (mem_rollcmp(REDBR,(uint32_t *)para->q,wlen>>1,*rand_dq) != CMPOK)  
-	{	
-		mem_set(result, 0, wlen); 
+	if (mem_rollcmp(REDBR,(uint32_t *)para->q,wlen>>1,*rand_dq) != CMPOK)
+	{
+		mem_set(result, 0, wlen);
 		return RET_RSA_FAILURE;
-	}	
-	
+	}
+
 	b_len=calc_add(result,result,m1,wlen>>1);
 	if (b_len==1)
 		calc_add(&result[wlen>>1],&result[wlen>>1],(volatile unsigned int *)CONST_LONG_ONE,wlen>>1);
-		
-	//clear bottom masking	
+
+	//clear bottom masking
 	mem_set(&c_buf[2],0,wlen-2);
 	mem_cpy(c_buf,rand_bot,2);
 
@@ -1270,22 +1269,22 @@
 	uint8touint32(&operand.q,para->n_q);
 
 	calc_modmul(result,&operand,wlen);
-	
+
 	if(function_mark!=initial_mark+0x4e70)/////////////////////////////////
-	{	
+	{
 		mem_set(result, 0, wlen); //////////////
 //		reverse_pri(para);
 		return RET_RSA_FAILURE;
-	}	
+	}
 	else
 		function_mark+=0x1212;	//////////////////////////
 
 	cpu_open_uniform_branch_timing();
-	cpu_open_branch_self();	
+	cpu_open_branch_self();
 	if((*rand_dq)&(0x08))
 	{
 		cpu_close_uniform_branch_timing();
-		cpu_close_branch_self();	
+		cpu_close_branch_self();
 		goto S10;
 	}
 	else
@@ -1295,25 +1294,25 @@
 		__asm("NOP");
 		__asm("NOP");
 		__asm("NOP");
-	}			
-		
-S9:		
+	}
+
+S9:
 	//c1 = c % q
 //	mem_rollcpy(REDBR, (uint32_t *)para->q, wlen>>1, *(rand_dq+1));
 	if( mem_rollcpy(REDBR, (uint32_t *)para->q, wlen>>1, *rand_dq) != para->q_xor )
-	{	
-		mem_set(result, 0, wlen); 
+	{
+		mem_set(result, 0, wlen);
 		return RET_RSA_FAILURE;
 	}
 	calc_div(NULL,c1,result,NULL,wlen,wlen>>1);
 	//c2 = c % p
 
 	cpu_open_uniform_branch_timing();
-	cpu_open_branch_self();	
+	cpu_open_branch_self();
 	if((*rand_dq)&(0x08))
 	{
 		cpu_close_uniform_branch_timing();
-		cpu_close_branch_self();	
+		cpu_close_branch_self();
 		goto S11;
 	}
 	else
@@ -1323,42 +1322,42 @@
 		__asm("NOP");
 		__asm("NOP");
 		__asm("NOP");
-	}				
-S10:	
+	}
+S10:
 //	mem_rollcpy(REDBR, (uint32_t *)para->p, wlen>>1, *(rand_dp+1));
 	if( mem_rollcpy(REDBR, (uint32_t *)para->p, wlen>>1, *rand_dp) != para->p_xor )
-	{	
-		mem_set(result, 0, wlen); 
+	{
+		mem_set(result, 0, wlen);
 		return RET_RSA_FAILURE;
 	}
 	calc_div(NULL,c2,result,NULL,wlen,wlen>>1);
-	
+
 	cpu_open_uniform_branch_timing();
-	cpu_open_branch_self();	
+	cpu_open_branch_self();
 	if((*rand_dq)&(0x08))
 	{
 		cpu_close_uniform_branch_timing();
-		cpu_close_branch_self();	
+		cpu_close_branch_self();
 		goto S9;
 	}
 	else
 	{
 		cpu_close_uniform_branch_timing();
-		cpu_close_branch_self();	
+		cpu_close_branch_self();
 		__asm("NOP");
 		__asm("NOP");
 		__asm("NOP");
-	}		
-	
+	}
 
-S11:	
+
+S11:
 
 	cpu_open_uniform_branch_timing();
-	cpu_open_branch_self();	
+	cpu_open_branch_self();
 	if((*rand_dq)&(0x10))
 	{
 		cpu_close_uniform_branch_timing();
-		cpu_close_branch_self();	
+		cpu_close_branch_self();
 		goto S13;
 	}
 	else
@@ -1368,8 +1367,8 @@
 		__asm("NOP");
 		__asm("NOP");
 		__asm("NOP");
-	}		
-S12:	
+	}
+S12:
 
 	//m1 = c1^d1 % q
 	operand.a=c1;
@@ -1378,26 +1377,26 @@
 	operand.p=NULL;
 //	mem_rollcpy(REDPR, (uint32_t *)para->q, wlen>>1, *rand_dq);
 	if( mem_rollcpy(REDPR, (uint32_t *)para->q, wlen>>1, *rand_dq) != para->q_xor)
-	{	
-		mem_set(result, 0, wlen); 
+	{
+		mem_set(result, 0, wlen);
 		return RET_RSA_FAILURE;
 	}
 	operand.c=(uint32_t *)para->q_c;
 //	operand.q=para->q_q;
 	uint8touint32(&operand.q,para->q_q);
 	calc_modexp(m1,&operand,wlen>>1, 1);
-	if (mem_rollcmp(REDPR,(uint32_t *)para->q,wlen>>1,*rand_dq) != CMPOK)  
-	{	
-		mem_set(result, 0, wlen); 
+	if (mem_rollcmp(REDPR,(uint32_t *)para->q,wlen>>1,*rand_dq) != CMPOK)
+	{
+		mem_set(result, 0, wlen);
 		return RET_RSA_FAILURE;
-	}	
-	
+	}
+
 	cpu_open_uniform_branch_timing();
-	cpu_open_branch_self();	
+	cpu_open_branch_self();
 	if((*rand_dq)&(0x10))
 	{
 		cpu_close_uniform_branch_timing();
-		cpu_close_branch_self();	
+		cpu_close_branch_self();
 		goto S14;
 	}
 	else
@@ -1407,8 +1406,8 @@
 		__asm("NOP");
 		__asm("NOP");
 		__asm("NOP");
-	}		
-S13:	
+	}
+S13:
 	//m2 = c2^d2 % p
 	operand.a=c2;
 	operand.b=(uint32_t *)para->e;
@@ -1416,26 +1415,26 @@
 	operand.p = NULL;
 //	mem_rollcpy(REDPR, (uint32_t *)para->p, wlen>>1, *rand_dp);
 	if( mem_rollcpy(REDPR, (uint32_t *)para->p, wlen>>1, *rand_dp) != para->p_xor)
-	{	
-		mem_set(result, 0, wlen); 
+	{
+		mem_set(result, 0, wlen);
 		return RET_RSA_FAILURE;
 	}
 	operand.c=(uint32_t *)para->p_c;
 //	operand.q=para->p_q;
 	uint8touint32(&operand.q,para->p_q);
 	calc_modexp(m2,&operand,wlen>>1, 1);
-	if (mem_rollcmp(REDPR,(uint32_t *)para->p,wlen>>1,*rand_dp) != CMPOK)  
-	{	
-		mem_set(result, 0, wlen); 
+	if (mem_rollcmp(REDPR,(uint32_t *)para->p,wlen>>1,*rand_dp) != CMPOK)
+	{
+		mem_set(result, 0, wlen);
 		return RET_RSA_FAILURE;
-	}	
-	
+	}
+
 	cpu_open_uniform_branch_timing();
-	cpu_open_branch_self();	
+	cpu_open_branch_self();
 	if((*rand_dq)&(0x10))
 	{
 		cpu_close_uniform_branch_timing();
-		cpu_close_branch_self();	
+		cpu_close_branch_self();
 		goto S12;
 	}
 	else
@@ -1445,10 +1444,10 @@
 		__asm("NOP");
 		__asm("NOP");
 		__asm("NOP");
-	}		
-S14:	
-	
-     	 
+	}
+S14:
+
+
 		//(m2-m1)
 	  if (mem_cmp(m2,m1,wlen>>1)==SMALLER)
 	  {
@@ -1456,35 +1455,35 @@
 	    	{
 //	    		mem_rollcpy(REDBR, (uint32_t *)para->p, wlen>>1, *rand_dq);
 			if( mem_rollcpy(REDBR, (uint32_t *)para->p, wlen>>1, *rand_dp) != para->p_xor )
-			{	
-				mem_set(result, 0, wlen); 
+			{
+				mem_set(result, 0, wlen);
 				return RET_RSA_FAILURE;
 			}
 			b_len = calc_add_safe(m2,m2,REDBR,wlen>>1);
-			if (mem_rollcmp(REDBR,(uint32_t *)para->p,wlen>>1,*rand_dp) != CMPOK)  
-			{	
-				mem_set(result, 0, wlen); 
+			if (mem_rollcmp(REDBR,(uint32_t *)para->p,wlen>>1,*rand_dp) != CMPOK)
+			{
+				mem_set(result, 0, wlen);
 				return RET_RSA_FAILURE;
-			}	
-	    	}while(mem_cmp(m2,m1,wlen>>1)==SMALLER && b_len==0);      
+			}
+	    	}while(mem_cmp(m2,m1,wlen>>1)==SMALLER && b_len==0);
 	 }
-/*	else 
+/*	else
 	{
 		do
 	    	{
 	    		mem_rollcpy(REDAR, (uint32_t *)para->p, wlen>>1, *(rand_dp+1));
 				b_len = calc_add_safe(REDBR,REDBR,REDAR,wlen>>1);
-	    	}while(mem_cmp(m2,m1,wlen>>1)==SMALLER && b_len==0);      
-	}	
+	    	}while(mem_cmp(m2,m1,wlen>>1)==SMALLER && b_len==0);
+	}
 */	calc_sub(m2,m2,m1,wlen>>1);
-	
+
 	//(m2-m1)*(q^-1 mod p) mod p
-	mem_rollcpy(REDAR, (uint32_t *)para->qp, wlen>>1, *rand_dp);	
-	//calc_modmul2(NULL, m2, NULL, para->p_c, wlen>>1);	
+	mem_rollcpy(REDAR, (uint32_t *)para->qp, wlen>>1, *rand_dp);
+	//calc_modmul2(NULL, m2, NULL, para->p_c, wlen>>1);
 //	mem_rollcpy(REDPR,(uint32_t *)para->p,wlen>>1,*(rand_dp+1));
 	if( mem_rollcpy(REDPR, (uint32_t *)para->p, wlen>>1, *rand_dp) != para->p_xor )
-	{	
-		mem_set(result, 0, wlen); 
+	{
+		mem_set(result, 0, wlen);
 		return RET_RSA_FAILURE;
 	}
 	mem_cpy(REDCR,(uint32_t *)para->p_c,wlen>>1);
@@ -1493,69 +1492,69 @@
 	REDQR=para->p_q[0]+(para->p_q[1]<<8)+(para->p_q[2]<<16)+(para->p_q[3]<<24);
 	RECFR=(((wlen>>1)-1)<<8) | ((wlen>>1)-1);
 	calc_run(FUNC_MODMUL_PRIME);
-	if (mem_rollcmp(REDPR,(uint32_t *)para->p,wlen>>1,*rand_dp) != CMPOK)  
-	{	
-		mem_set(result, 0, wlen); 
+	if (mem_rollcmp(REDPR,(uint32_t *)para->p,wlen>>1,*rand_dp) != CMPOK)
+	{
+		mem_set(result, 0, wlen);
 		return RET_RSA_FAILURE;
-	}	
-	
+	}
+
 	//([(m2-m1)*(q^-1 mod p) mod p])*q
 //	mem_rollcpy(REDBR, (uint32_t *)para->q, wlen>>1, *rand_dq);
 	if( mem_rollcpy(REDBR, (uint32_t *)para->q, wlen>>1, *rand_dq) != para->q_xor )
-	{	
-		mem_set(result, 0, wlen); 
+	{
+		mem_set(result, 0, wlen);
 		return RET_RSA_FAILURE;
 	}
 	calc_mul(d_buf,NULL,NULL,wlen>>1,wlen>>1);
 	//m=m1+([(m2-m1)*(q^-1 mod p) mod p]*q)
-	if (mem_rollcmp(REDBR,(uint32_t *)para->q,wlen>>1,*rand_dq) != CMPOK)  
-	{	
-		mem_set(result, 0, wlen); 
+	if (mem_rollcmp(REDBR,(uint32_t *)para->q,wlen>>1,*rand_dq) != CMPOK)
+	{
+		mem_set(result, 0, wlen);
 		return RET_RSA_FAILURE;
-	}	
+	}
 	b_len=calc_add(d_buf,d_buf,m1,wlen>>1);
 	if (b_len==1)
 		calc_add(&d_buf[wlen>>1],&d_buf[wlen>>1],(volatile unsigned int *)CONST_LONG_ONE,wlen>>1);
-    
+
 	function_mark+=0x4848;
 	cpu_open_branch_self();
-	if(function_mark!=initial_mark+0xa8ca) 
+	if(function_mark!=initial_mark+0xa8ca)
 	{
 		cpu_close_branch_self();
-		mem_set(result, 0, wlen);  
+		mem_set(result, 0, wlen);
 //		reverse_pri(para);
 		return RET_RSA_FAILURE;
 	}
 	else
-		function_mark+=0x1120;	 
-	
-	if (mem_rollcmp(d_buf,content,wlen,*rand_dp)!=CMPOK)  
+		function_mark+=0x1120;
+
+	if (mem_rollcmp(d_buf,content,wlen,*rand_dp)!=CMPOK)
 	{
 		cpu_close_branch_self();
 		mem_set(result, 0, wlen);
 //		reverse_pri(para);
-		return RET_RSA_FAILURE;                
+		return RET_RSA_FAILURE;
 	}
-	else if(mem_rollcmp(d_buf,content,wlen,*(rand_dp+1))!=CMPOK)  
+	else if(mem_rollcmp(d_buf,content,wlen,*(rand_dp+1))!=CMPOK)
 	{
 		cpu_close_branch_self();
 		mem_set(result, 0, wlen);
-		return RET_RSA_FAILURE;                
+		return RET_RSA_FAILURE;
 	}
 	else
 		cpu_close_branch_self();
 	function_mark+=0x22d0;
 	 if(function_mark!=initial_mark+0xdcba)/////////////////////////////////
-	{	
+	{
 		mem_set(result, 0, wlen); //////////////
 //		reverse_pri(para);
 		return RET_RSA_FAILURE;
-	}	
+	}
 	else
 	{
 //		reverse_pri(para);
 //		memcpy_r(output,output,para->bytes);
-		return RET_RSA_SUCCESS;	
+		return RET_RSA_SUCCESS;
 	}
 }
 
@@ -1574,13 +1573,10 @@
 {
 	uint32_t RSA_CLK = 0;
 	uint32_t RSA_RTN = RET_RSA_FAILURE;
-	
-	RSA_CLK = SYSCTRL_RSACLK;
-	SYSCTRL_RSACLK = 7;
-	
+
+
 	RSA_RTN = RSA_Private_crt_True(output,input,para,f_rng,p_rng);
-	
-	SYSCTRL_RSACLK = RSA_CLK;
+
 	return RSA_RTN;
 }
 
@@ -1592,7 +1588,7 @@
 * Input: rand - a pointer to a random number of len words.
          len - the word-length of the random number.
          prime - a pointer to the structure rsa_prime.
-* Output: result - a pointer to a variable of len words to store the prime 
+* Output: result - a pointer to a variable of len words to store the prime
           generated by this function.
 * Return value: none
 ***************************************************************************
@@ -1621,8 +1617,6 @@
 
 	uint32_t RSA_CLK = 0;
 
-	RSA_CLK = SYSCTRL_RSACLK;
-	SYSCTRL_RSACLK = 7;
 
 	uint32_t *rand = Grand_p_t;
  	rsa_prime *prime = NULL;
@@ -1674,14 +1668,13 @@
 			break;
  		count--;
 	}
-	SYSCTRL_RSACLK = RSA_CLK;
 	return RET_CALC_IMPLEMENT_SUCCESS;
 }
 
 /*
 ***************************************************************************
 * Name: rsa_verifyprime
-* Description: verify if the input data is a prime. 
+* Description: verify if the input data is a prime.
 * Input: prime - a pointer to an odd (>=3)to be tested for primality.
          len - the word-length of the value pointed to by prime.
          num - a number whose value is between 2 and n-2.
@@ -1700,17 +1693,17 @@
 	uint32_t s;
 	uint32_t j;
 
-	//n-1 = r*2^s, n is an odd integer 
-	//r = (n-1)>>s until r becomes an odd interger 
+	//n-1 = r*2^s, n is an odd integer
+	//r = (n-1)>>s until r becomes an odd interger
 	mem_cpy(r, prime, len);
 	r[0]--;
 	s=0;
-	while((r[0] & 1) == 0)  
-	{                          
+	while((r[0] & 1) == 0)
+	{
 		calc_sr(r, r, len, 1); //shift right 1 bits
-		s++;   
+		s++;
 	}
-	
+
 	// y = a^r mod n
 	calc_const_c(c, prime, len);
 	calc_const_q(&q, prime);
@@ -1721,11 +1714,11 @@
 	operand.p =prime;
 	operand.c = c;
 	operand.q = q;
-	calc_modexp(NULL, &operand, len, len); 
-	
-	
+	calc_modexp(NULL, &operand, len, len);
+
+
 	//if y == 1, pass
-	if(mem_cmp2(REDAR,1,len) == EQUAL)   
+	if(mem_cmp2(REDAR,1,len) == EQUAL)
 		return RET_PRIME_CHECK_PASS;
 	//if y == n-1,pass
 	//else ...
@@ -1736,20 +1729,20 @@
 	{
 		if(j==s)
 		{
-//			while(1);	
+//			while(1);
 			return RET_PRIME_CHECK_FAIL;
 		}
 		calc_modmul2(NULL, NULL, REDAR, c, len);
 		if(mem_cmp2(REDAR, 1, len) ==EQUAL)
-		{	
-//			while(1);	
+		{
+//			while(1);
 			return RET_PRIME_CHECK_FAIL;
 		}
 		j++;
 	}
-	
+
 	return RET_PRIME_CHECK_PASS;
-		
+
 }
 
 uint32_t RSA_IsPrime( uint32_t *X, uint32_t size, rng_callback f_rng, void *p_rng)
@@ -1759,7 +1752,7 @@
 	if(X[0]%2 == 0)
 		return RET_PRIME_CHECK_FAIL;
 	ret = rsa_verifyprime(X,size,3);
-//	memcpy_r((uint8_t *)X,(uint8_t *)X,size<<2);	
+//	memcpy_r((uint8_t *)X,(uint8_t *)X,size<<2);
 	return ret;
 }
 
@@ -1788,7 +1781,7 @@
 
 uint32_t CompleteKey(RSA_PrivateKeyTypeDef *key, rng_callback f_rng, void *p_rng)
 {
-	uint32_t wlen = key->bytes>>2;	
+	uint32_t wlen = key->bytes>>2;
 	//d%(p-1)
 	calc_div(NULL, (uint32_t *)key->dp, (uint32_t *)key->d, (uint32_t *)key->p, wlen, wlen>>1);
 	key->p[0]++;
@@ -1797,30 +1790,30 @@
 	key->q[0]++;
 	//q^-1%p
 	calc_modinv((uint32_t *)key->qp, (uint32_t *)key->q, (uint32_t *)key->p, wlen>>1);
-	
+
 	calc_const_c((uint32_t *)key->p_c, (uint32_t *)key->p, wlen>>1);            //factor C for prime p
 	calc_const_q((uint32_t *)key->p_q, (uint32_t *)key->p);                          //factor Q for prime p
 	calc_const_c((uint32_t *)key->q_c, (uint32_t *)key->q, wlen>>1);            //factor C for prime q
 	calc_const_q((uint32_t *)key->q_q, (uint32_t *)key->q);                          //factor Q for prime q
 	calc_mul((uint32_t *)key->n,(uint32_t *)key->p, (uint32_t *)key->q, wlen>>1, wlen>>1);
 	calc_const_c((uint32_t *)key->n_c, (uint32_t *)key->n, wlen);            //factor C for prime c
-	calc_const_q((uint32_t *)key->n_q, (uint32_t *)key->n);   
+	calc_const_q((uint32_t *)key->n_q, (uint32_t *)key->n);
 
 	key->p_xor = calculatexor((uint32_t *)key->p,0, key->bytes>>3);
 	key->q_xor = calculatexor((uint32_t *)key->q,0, key->bytes>>3);
-	
-//	reverse_pri(key);	
+
+//	reverse_pri(key);
 
 }
 
-//complete the private key by the rsa key paras p q e. 
+//complete the private key by the rsa key paras p q e.
 uint32_t RSA_CompleteKey_e(RSA_PrivateKeyTypeDef *key, rng_callback f_rng, void *p_rng)
 {
 	uint32_t tmp[64+1] = {0};
 	uint32_t wlen = key->bytes>>2;
 
 //	reverse_pq(key);
-	
+
 //if(RSA_IsPrime((uint32_t *)key->p,key->bytes>>3,f_rng,NULL) !=RET_PRIME_CHECK_PASS)
 //	return 0xff;
 //if(RSA_IsPrime((uint32_t *)key->q,key->bytes>>3,f_rng,NULL) != RET_PRIME_CHECK_PASS)
@@ -1908,17 +1901,17 @@
 //	}
 	else
 		cpu_close_branch_self();
-		
+
 	CompleteKey(key,f_rng,p_rng);
 	return RET_RSA_KEYGEN_SUCCESS;
 }
 
-//	complete the private key by the rsa key paras p q d. 
+//	complete the private key by the rsa key paras p q d.
 uint32_t RSA_CompleteKey(RSA_PrivateKeyTypeDef *key, rng_callback f_rng, void *p_rng)
 {
 	uint32_t tmp[64+64] = {0};
 	uint32_t wlen = key->bytes>>2;
-	
+
 //	memcpy_r(key->p,key->p,key->bytes>>1);
 //	memcpy_r(key->q,key->q,key->bytes>>1);
 //	memcpy_r(key->d,key->d,key->bytes);
@@ -1933,7 +1926,7 @@
 	{
 		cpu_close_branch_self();
 		return RET_RSA_RANDNUM_NOT_ACCEPT;//��ֵ̫С����ȫ����Ҫ
-		
+
 	}
 //	else if(mem_cmp2(tmp+2, 0x10000,(wlen>>1)-2) != BIGGER)
 //	{
@@ -1942,7 +1935,7 @@
 //	}
 	else
 		cpu_close_branch_self();
-	
+
 	//w=(p-1)*(q-1)
 	key->p[0]--;
 	key->q[0]--;
@@ -1963,13 +1956,13 @@
 				return RET_RSA_RANDNUM_NOT_ACCEPT;
 			uint32touint8(key->e,tmp);
 		}
-		
+
 		//(e*d)%w == 1
 		calc_mul(tmp, (uint32_t *)key->e, (uint32_t *)key->d, 1, wlen);
 		calc_div(NULL, tmp, tmp, (uint32_t *)key->n, wlen+1, wlen);
-	
-	} while(mem_cmp2(tmp, 1, wlen) != EQUAL);	
-	
+
+	} while(mem_cmp2(tmp, 1, wlen) != EQUAL);
+
 	CompleteKey(key,f_rng,p_rng);
 	return RET_RSA_KEYGEN_SUCCESS;
 }
@@ -1998,32 +1991,29 @@
 	RSA_PrivateKeyTypeDef pri_key;
 	uint32_t RSA_CLK = 0;
 	uint32_t RSA_RTN = RET_RSA_IMPLEMENT_ERROR;
-	
+
 	pri_key.bytes = para->bytes;
 	memcpy(pri_key.e, para->e, sizeof(pri_key.e));
 	memcpy(pri_key.d, para->d, sizeof(pri_key.d));
 	memcpy(pri_key.n, para->n, sizeof(pri_key.n));
-	
+
 	memset(pri_key.p,0,sizeof(pri_key.p));
 	pri_key.p_xor = 0;
 	memset(pri_key.q,0,sizeof(pri_key.q));
 	pri_key.q_xor = 0;
-	
-	RSA_CLK = SYSCTRL_RSACLK;
-	SYSCTRL_RSACLK = 7;
-	
+
+
 	RSA_GetPrativeKey_C_Q(&pri_key,f_rng,p_rng);
 	RSA_RTN = RSA_Private_Standard(output,input,&pri_key,f_rng,p_rng);
-	
-	SYSCTRL_RSACLK = RSA_CLK;
-	
+
+
 	return 	RSA_RTN;
 }
 
 
 /**
   * @method	RSA_Public_Func
-  * @brief	Raw RSA public-key operation. 
+  * @brief	Raw RSA public-key operation.
   * @param	output		:output data buffer
   * @param	input		:input data buffer
   * @param	key			:RSA public key
Index: yc_sha.h
===================================================================
--- /YC3121_SDK/fw/crypt/yc_sha.h	(revision 797)
+++ /YC3121_SDK/fw/crypt/yc_sha.h	(working copy)
@@ -83,7 +83,7 @@
   * @param	input		:input data buffer
   * @param	ibytes		:size of input data
   * @param     totallen		:size of totallen
-  * @param     step               :step = 0 head,  step = 1 middle,  step = 2 tail 
+  * @param     step               :step = 0 head,  step = 1 middle,  step = 2 tail
   * @retval 			:SHA_TYPE_ERR or SHA_CRYPT_BUSY
   */
 uint32_t SHA_Enhance(SHA_ModeTypeDef mode,  uint8_t *output, uint8_t *input,uint32_t ibytes, uint32_t totallen,
Index: yc_sha.c
===================================================================
--- /YC3121_SDK/fw/crypt/yc_sha.c	(revision 797)
+++ /YC3121_SDK/fw/crypt/yc_sha.c	(working copy)
@@ -8,7 +8,7 @@
 	if(mode != SHATYPE_SM3 && mode != SHATYPE_1 && mode != SHATYPE_256
 	   && mode != SHATYPE_224 && mode != SHATYPE_384 && mode != SHATYPE_512)
 		return RET_SHA_MODE_ERR;
-		
+
 	maxlen = mode == SHATYPE_SM3 || mode == SHATYPE_1 || mode == SHATYPE_256 || mode == SHATYPE_224 ? 64 : 128;
 	totallen = (ibytes + maxlen + maxlen/8)/maxlen*maxlen;
 	for(k = 0;k < totallen;k += maxlen)
@@ -32,7 +32,7 @@
 	if(maxlen == 64)
 	{
 		starti = 14, endi = mode == SHATYPE_1 ? 6 : mode == SHATYPE_256 || mode == SHATYPE_SM3 ? 0 : 2, stepi = 2;
-	} else 
+	} else
 	{
 		starti = 15, endi = mode == SHATYPE_512 ? 0 : 4, stepi = 1;
 	}
@@ -56,7 +56,7 @@
 	if(mode != SHATYPE_SM3 && mode != SHATYPE_1 && mode != SHATYPE_256
 	   && mode != SHATYPE_224 && mode != SHATYPE_384 && mode != SHATYPE_512)
 		return RET_SHA_MODE_ERR;
-	
+
 	maxlen = mode == SHATYPE_SM3 || mode == SHATYPE_1 || mode == SHATYPE_256 || mode == SHATYPE_224 ? 64 : 128;
 
 	if (((step < 2) && (ibytes != maxlen)) || ((step == 2) && (ibytes > maxlen)) || (step > 2))
@@ -69,9 +69,9 @@
 		for(i = j = 0;i < maxlen;i++, j++)
 		{
 			SHA_BDATA(j) = input[i];
-			
+
 			//if((j & 3) == 3 && maxlen == 64) j += 4;
-			if((j & 3) == 3 && maxlen == 64) 
+			if((j & 3) == 3 && maxlen == 64)
 			{
 				SHA_BDATA(j+1) = 0;
 				SHA_BDATA(j+2) = 0;
@@ -100,7 +100,7 @@
 				else
 					SHA_BDATA(j) = 0;
 				//if((j & 3) == 3 && maxlen == 64) j += 4;
-				if((j & 3) == 3 && maxlen == 64) 
+				if((j & 3) == 3 && maxlen == 64)
 				{
 					SHA_BDATA(j+1) = 0;
 					SHA_BDATA(j+2) = 0;
@@ -116,7 +116,7 @@
 	if(maxlen == 64)
 	{
 		starti = 14, endi = mode == SHATYPE_1 ? 6 : mode == SHATYPE_256 || mode == SHATYPE_SM3 ? 0 : 2, stepi = 2;
-	} else 
+	} else
 	{
 		starti = 15, endi = mode == SHATYPE_512 ? 0 : 4, stepi = 1;
 	}
@@ -180,7 +180,7 @@
 				j+=4;
 			}
 		}
-	
+
     bytes = istep + 1;
 
     if(isend)
Index: yc_sm2.h
===================================================================
--- /YC3121_SDK/fw/crypt/yc_sm2.h	(revision 797)
+++ /YC3121_SDK/fw/crypt/yc_sm2.h	(working copy)
@@ -67,7 +67,7 @@
   * @param	p_rng : 随机数函数参数（输入参数）
   * @retval RET_ECC_KEY_GEN_SUCCESS or RET_SM2_KEY_GEN_ERROR
   */
-uint32_t SM2_Genkey(SM2_PrivateKeyTypeDef *key, const SM2_EllipseParaTypeDef *para, 
+uint32_t SM2_Genkey(SM2_PrivateKeyTypeDef *key, const SM2_EllipseParaTypeDef *para,
                     rng_callback f_rng, void *p_rng, uint8_t config);
 
 //uint32_t SM2_Kdf(uint8_t *K, uint32_t klen, const uint8_t *Z, uint32_t zlen);
@@ -138,7 +138,7 @@
 //							uint8_t *msg, uint32_t mlen,
 //							SM2_PublicKeyTypeDef *key, SM2_EllipseParaTypeDef *para,
 //							mh_rng_callback f_rng, void *p_rng);
-					
+
 /**
   * @method	SM2_DigitalSignWith_e
   * @brief	SM2 数字签名函数
@@ -174,23 +174,23 @@
 							uint8_t *msg, uint32_t mlen,
 							SM2_PublicKeyTypeDef *key, SM2_EllipseParaTypeDef *para,
 							rng_callback f_rng, void *p_rng, uint8_t config);
-/*							
-uint32_t SM2_key_ex_equation_0(uint8_t _x[32], uint32_t *_xlen, 
+/*
+uint32_t SM2_key_ex_equation_0(uint8_t _x[32], uint32_t *_xlen,
 							const uint8_t x[32], uint32_t w);
-void SM2_key_ex_equation_1(uint8_t *t, const uint8_t *d, 
-						const uint8_t *x, const uint8_t *r, 
+void SM2_key_ex_equation_1(uint8_t *t, const uint8_t *d,
+						const uint8_t *x, const uint8_t *r,
 						SM2_EllipseParaTypeDef *para);
-void SM2_key_ex_equation_2(SM2_PointTypeDef *P, uint8_t *t, 
-						uint8_t *x, SM2_PointTypeDef *R, 
+void SM2_key_ex_equation_2(SM2_PointTypeDef *P, uint8_t *t,
+						uint8_t *x, SM2_PointTypeDef *R,
 						SM2_EllipseParaTypeDef *para, SM2_PublicKeyTypeDef *key,
 						rng_callback f_rng, void *p_rng);
 
 uint32_t SM2_key_ex_section_0(SM2_PointTypeDef *R, uint8_t *t, uint8_t *rand,
 								SM2_EllipseParaTypeDef *para, SM2_PrivateKeyTypeDef *key,
 								rng_callback f_rng, void *p_rng);
-uint32_t SM2_key_ex_section_1(uint8_t *K, uint32_t Klen, SM2_PointTypeDef *P, 
-							SM2_PointTypeDef *R, uint8_t *t, 
-							uint8_t *Za, uint8_t *Zb, 
+uint32_t SM2_key_ex_section_1(uint8_t *K, uint32_t Klen, SM2_PointTypeDef *P,
+							SM2_PointTypeDef *R, uint8_t *t,
+							uint8_t *Za, uint8_t *Zb,
 							SM2_EllipseParaTypeDef *para, SM2_PublicKeyTypeDef *key,
 							rng_callback f_rng, void *p_rng);
 uint32_t SM2_key_ex_hash(uint8_t *Hash, uint8_t HashHead,
@@ -198,6 +198,6 @@
 						SM2_PointTypeDef *Ra, SM2_PointTypeDef *Rb);
 */
 //#define SM2_DEBUG
-#endif 
+#endif
 
 
Index: yc_sm2.c
===================================================================
--- /YC3121_SDK/fw/crypt/yc_sm2.c	(revision 797)
+++ /YC3121_SDK/fw/crypt/yc_sm2.c	(working copy)
@@ -11,11 +11,6 @@
 //输出参数： K      -计算后返回的内容（二进制值）,分配空间至少为需要keylen
 //返回值：RET_SM2_KDF_SUCCESS表示成功，RET_SM2_KDF_FAILURE表示失败
 
-static void SM2_DecEncSpeed(void)
-{
-	SYSCTRL_RSACLK = 7;
-}
-
 uint32_t SM2_KDF(uint8_t *K, uint32_t klen,  uint8_t *Z, uint32_t zlen)
 {
     uint8_t cdgst[32]={0}; //摘要
@@ -85,7 +80,7 @@
 	para_t->g.x = para->g.x;
 	para_t->g.y = para->g.y;
 	para_t->n = para->n;
-	
+
 	para_t->p_c = p_c;
 	para_t->n_c = n_c;
 	para_t->n1_c = n1_c;
@@ -122,7 +117,7 @@
 	for(i=0;i<para_t->len_words;i++)
 		MyPrintf("%08x ",para_t->p_c[i]);	MyPrintf("\n");
 	MyPrintf("para_def.p_q:\n");
-	MyPrintf("%08x ",para_t->p_q);	MyPrintf("\n");		
+	MyPrintf("%08x ",para_t->p_q);	MyPrintf("\n");
 	MyPrintf("para_def.n_c:\n");
 	for(i=0;i<para_t->len_words;i++)
 		MyPrintf("%08x ",para_t->n_c[i]);	MyPrintf("\n");
@@ -137,7 +132,7 @@
 	uint32_t i;
 	for(i=0;i<len;i++)
 	{
-		data_temp[i] =((data[len-i-1]>>24)&0xff) +((data[len-i-1]>>8)&0xff00) +  ((data[len-i-1]<<8)&0xff0000) + ((data[len-i-1]<<24)&0xff000000);		
+		data_temp[i] =((data[len-i-1]>>24)&0xff) +((data[len-i-1]>>8)&0xff00) +  ((data[len-i-1]<<8)&0xff0000) + ((data[len-i-1]<<24)&0xff000000);
 	}
 }
 
@@ -219,13 +214,13 @@
 // 	mem_rollcpy_char((data_temp+index), data_1, block_size,GetTRNGData());
 // 	index += block_size;
 
-// #ifdef SM2_DEBUG	
+// #ifdef SM2_DEBUG
 // 	MyPrintf("data_temp:\n");
 // 	for(i=0;i<index;i++)
 // 		MyPrintf("%02x ",data_temp[i]);	MyPrintf("\n");
 // #endif
-// 	return SM3(Za,(uint8_t *)data_temp,index);  
-	
+// 	return SM3(Za,(uint8_t *)data_temp,index);
+
 // }
 
 uint32_t SM2_Hash_Za(uint8_t *Za, uint8_t *IDa, uint16_t IDalen, SM2_EllipseParaTypeDef *para, SM2_PublicKeyTypeDef *key, uint16_t block_size)
@@ -485,34 +480,33 @@
 							SM2_PrivateKeyTypeDef *key, SM2_EllipseParaTypeDef *para,
 							rng_callback f_rng, void *p_rng, uint8_t config)
 {
-    SM2_DecEncSpeed();
 	uint32_t i,ret;
 	calc_operand operand;
 	uint32_t *pdata;
-	
+
 	//uint32_t k[11]={0x1FB2F96F,0x260DBAAE,0xDD72B727,0xC176D925,0x4817663F,0x94F94E93,0x385C175C,0x6CB28D99,0};
 	//uint32_t k[9]={0xada186d6,0x5399b341,0x98158c60,0x97703d64,0x46d454c3,0x7a8a7b4a,0x8e24b735,0x36cd79fc,0};
 	uint32_t k[11] = {0};
 	SM2_PointTypeDef c1 = {0};
 	ecc_point_a c1_p = {0};
 	uint32_t data_temp[9]={0};
-	
+
 	ecc_security security_t = {0};
 	ecc_para para_t = {0};
-	uint32_t p_c[9]={0},n_c[9]={0},n1_c[9]={0};	
+	uint32_t p_c[9]={0},n_c[9]={0},n1_c[9]={0};
 
 	uint32_t zero[9]={0};
 	uint32_t rand_data[2];
 
 	uint32_t sm2_flow_addval = 0;
 	uint32_t sm2_flow_flag = 0;
-	
+
 	security_t.mask=INT_MASK_OPEN;
 	security_t.verify=EC_PARA_VERIFY_OPEN;
 
 	(*f_rng)((uint8_t *)rand_data,8,NULL);
 
-	
+
 	//(*f_rng)((uint8_t *)sm2_rand_val,32,NULL);
 
 
@@ -526,13 +520,13 @@
 		}
 	#else
 		//(*f_rng)((uint8_t *)k,32,NULL);
-		
+
 		for (i=0;i<8;i++)
 		{
 			k[i] = GetTRNGData();
 		}
 	#endif
-	
+
 	#ifdef SM2_FLOW_CONTROL
 		sm2_flow_addval = 0XAA;
 		sm2_flow_flag = 1;
@@ -557,7 +551,7 @@
 		MyPrintf("%08x ",rand_data[i]);	MyPrintf("\n");
 	MyPrintf("\n");
 	#endif
-	
+
 	ret = mem_cmp(k, zero, para_t.len_words);
 	if (ret == EQUAL)
 	{
@@ -569,13 +563,13 @@
 	{
 		goto get_rand;
 	}
-	
+
 	c1_p.x= c1.x;
 	c1_p.y= c1.y;
 	#ifdef SM2_FLOW_CONTROL
 		sm2_flow_addval += 0XAA55;
 	#endif
-	
+
 	ret = ecc_pmul(&c1_p,&(para_t.g), k,&para_t,&security_t,rand_data,2);
 	if(ret != RET_ECC_POINT_SUCCESS)
 		return RET_SM2_SIGN_FAILURE;
@@ -586,11 +580,11 @@
 			sm2_flow_flag = 0XAA55;
 		}
 	#endif
-	
+
 #ifdef SM2_DEBUG
 	MyPrintf("\nlen_words:");
     MyPrintf("%08x ",para_t.len_words);
- 	MyPrintf("\n ecc_pmul_calc:%c%c%c%c\n",ret,ret>>8,ret>>16,ret>>24);	
+ 	MyPrintf("\n ecc_pmul_calc:%c%c%c%c\n",ret,ret>>8,ret>>16,ret>>24);
 
 	MyPrintf("g:\n");
 	MyPrintf("g.x:\n");
@@ -599,7 +593,7 @@
 	MyPrintf("g.y:\n");
 	for(i=0;i<9;i++)
 		MyPrintf("%08x ",para_t.g.y[i]);	MyPrintf("\n");
-	
+
 	MyPrintf("k:\n");
 	for(i=0;i<9;i++)
 		MyPrintf("%08x ",k[i]);	MyPrintf("\n");
@@ -696,12 +690,12 @@
 	ret = calc_modinv(sign->s, sign->s ,para_t.n , para_t.len_words); //  (1+da) ^ -1
 #ifdef SM2_DEBUG
 
-	MyPrintf("\n calc_modinv:%c%c%c%c\n",ret,ret>>8,ret>>16,ret>>24);	
+	MyPrintf("\n calc_modinv:%c%c%c%c\n",ret,ret>>8,ret>>16,ret>>24);
 
 	MyPrintf("\n  (1+da) ^ -1 \n");
 	for(i=0;i<9;i++)
 		MyPrintf("%08x ",sign->s[i]);	MyPrintf("\n");
-#endif	
+#endif
 
 	operand.a= sign->r;
 	operand.b= key->d ;
@@ -736,12 +730,12 @@
 	#endif
 
 	if(RET_CALC_IMPLEMENT_SUCCESS != calc_modmul_base(data_temp,&operand,para_t.len_words,0))
-		return RET_SM2_SIGN_FAILURE;		
+		return RET_SM2_SIGN_FAILURE;
 #ifdef SM2_DEBUG
 	MyPrintf("\n  r* da mod n \n");
 	for(i=0;i<9;i++)
 		MyPrintf("%08x ",data_temp[i]);	MyPrintf("\n");
-#endif	
+#endif
 
 
 	#ifdef SM2_FLOW_CONTROL
@@ -780,7 +774,7 @@
 	MyPrintf("\n  s \n");
 	for(i=0;i<9;i++)
 		MyPrintf("%08x ",sign->s[i]);	MyPrintf("\n");
-#endif	
+#endif
 
 	#ifdef SM2_FLOW_CONTROL
 		if (sm2_flow_flag != 0XAA55AA77)
@@ -788,7 +782,7 @@
 			return RET_SM2_SIGN_FAILURE;
 		}
 	#endif
-	
+
 	return RET_SM2_SIGN_SUCCESS;
 }
 
@@ -797,7 +791,6 @@
 							SM2_PublicKeyTypeDef *key, SM2_EllipseParaTypeDef *para,
 							rng_callback f_rng, void *p_rng, uint8_t config)
 {
-    SM2_DecEncSpeed();
     uint32_t i,ret;
 	uint32_t z1[9],z2[9] = {0};
 	calc_operand operand;
@@ -805,10 +798,10 @@
 	ecc_point_a c1_p,c2_p,pa;
 	ecc_point_j j1,j2;
 	uint32_t t[9]={0};
-	
+
 	ecc_security security_t = {0};
 	ecc_para para_t;
-	uint32_t p_c[9]={0},n_c[9]={0},n1_c[9]={0};	
+	uint32_t p_c[9]={0},n_c[9]={0},n1_c[9]={0};
 
 	uint32_t zero[9]={0};
 
@@ -817,7 +810,7 @@
 
 	sign->r[8] = 0;
 	sign->s[8] = 0;
-	
+
 	security_t.mask=INT_MASK_OPEN;
 	security_t.verify=EC_PARA_VERIFY_OPEN;
 	sm2_step = 1;
@@ -876,11 +869,11 @@
 	MyPrintf("sign.s:\n");
 	for(i=0;i<9;i++)
 		MyPrintf("%08x ",sign->s[i]);	MyPrintf("\n");
-	
+
 	MyPrintf("\n  t \n");
 	for(i=0;i<8;i++)
 		MyPrintf("%08x ",t[i]);	MyPrintf("\n");
-#endif	
+#endif
 
 	ret = mem_rollcmp(t, zero, para_t.len_words,GetTRNGData());
 	if (ret == CMPOK)
@@ -913,9 +906,9 @@
 		sm2_flow_flag += 485;
 		sm2_step = 4;
 	#endif
-	
+
 #ifdef SM2_DEBUG
- 	MyPrintf("\n ecc_pmul_calc:%c%c%c%c\n",ret,ret>>8,ret>>16,ret>>24);	
+ 	MyPrintf("\n ecc_pmul_calc:%c%c%c%c\n",ret,ret>>8,ret>>16,ret>>24);
 	MyPrintf("c1:\n");
 	MyPrintf("x:\n");
 	for(i=0;i<9;i++)
@@ -923,7 +916,7 @@
 	MyPrintf("y:\n");
 	for(i=0;i<9;i++)
 		MyPrintf("%08x ",c1.y[i]);	MyPrintf("\n");
-#endif	
+#endif
 
 	c2_p.x= c2.x;
 	c2_p.y= c2.y;
@@ -943,7 +936,7 @@
 		sm2_step = 5;
 	#endif
 #ifdef SM2_DEBUG
- 	MyPrintf("\n ecc_pmul_calc:%c%c%c%c\n",ret,ret>>8,ret>>16,ret>>24);	
+ 	MyPrintf("\n ecc_pmul_calc:%c%c%c%c\n",ret,ret>>8,ret>>16,ret>>24);
 	MyPrintf("c2:\n");
 	MyPrintf("x:\n");
 	for(i=0;i<9;i++)
@@ -951,7 +944,7 @@
 	MyPrintf("y:\n");
 	for(i=0;i<9;i++)
 		MyPrintf("%08x ",c2.y[i]);	MyPrintf("\n");
-#endif	
+#endif
 
 	j2.x = c2_p.x;
 	j2.y = c2_p.y;
@@ -996,16 +989,16 @@
 		sm2_flow_flag += 5469;
 		sm2_step = 6;
 	#endif
-	
+
 #ifdef SM2_DEBUG
- 	MyPrintf("\n ecc_pmul_calc:%c%c%c%c\n",ret,ret>>8,ret>>16,ret>>24);	
+ 	MyPrintf("\n ecc_pmul_calc:%c%c%c%c\n",ret,ret>>8,ret>>16,ret>>24);
 	MyPrintf("x1:\n");
 	for(i=0;i<9;i++)
 		MyPrintf("%08x ",c1.x[i]);	MyPrintf("\n");
 	MyPrintf("y1:\n");
 	for(i=0;i<9;i++)
 		MyPrintf("%08x ",c1.y[i]);	MyPrintf("\n");
-#endif	
+#endif
 
 	calc_modadd_1(t,e,c1_p.x, para_t.n, (para_t.len_words > 8)? para_t.len_words : 8);
 	#ifdef SM2_FLOW_CONTROL
@@ -1016,13 +1009,13 @@
 		sm2_flow_flag *= sm2_step;
 		sm2_flow_flag += 3;
 	#endif
-	
+
 #ifdef SM2_DEBUG
 	MyPrintf("\n  t \n");
 	for(i=0;i<9;i++)
 		MyPrintf("%08x ",t[i]);	MyPrintf("\n");
-#endif	
-	
+#endif
+
 	if (CMPOK != mem_rollcmp((unsigned int *)(t),(unsigned int *)sign->r ,para_t.len_words,GetTRNGData()))
 		return RET_SM2_VERIFY_FAILURE;
 	else
@@ -1033,7 +1026,7 @@
 				return RET_SM2_VERIFY_FAILURE;
 			}
 		#endif
-		return RET_SM2_VERIFY_SUCCESS;	
+		return RET_SM2_VERIFY_SUCCESS;
 	}
 
 }
@@ -1044,7 +1037,6 @@
 					 SM2_PublicKeyTypeDef *key,  SM2_EllipseParaTypeDef *para,
 					rng_callback f_rng, void *p_rng,uint8_t config)
 {
-    SM2_DecEncSpeed();
 	uint32_t i,ret;
 
 	uint32_t k[9]={0x49DD7B4F,0x18E5388D,0x5546D490,0x8AFA1742,0x3D957514,0x5B92FD6C,0x6ECFC2B9,0x4C62EEFD};
@@ -1139,12 +1131,12 @@
 
 	c1_p.x= c1.x;
 	c1_p.y= c1.y;
-	
+
 	ret = ecc_pmul(&c1_p,&(para_t.g), k,&para_t,&security_t,NULL,0);
 	if(ret != RET_ECC_POINT_SUCCESS)
 		return RET_SM2_ENC_FAILURE;
 #ifdef SM2_DEBUG
- 	MyPrintf("\n ecc_pmul_calc:%c%c%c%c\n",ret,ret>>8,ret>>16,ret>>24);	
+ 	MyPrintf("\n ecc_pmul_calc:%c%c%c%c\n",ret,ret>>8,ret>>16,ret>>24);
 	MyPrintf("c1:\n");
 	MyPrintf("x:\n");
 	for(i=0;i<para_t.len_words;i++)
@@ -1256,7 +1248,6 @@
 					 SM2_PrivateKeyTypeDef *key,  SM2_EllipseParaTypeDef *para,
 					rng_callback f_rng, void *p_rng,uint8_t config)
 {
-    SM2_DecEncSpeed();
 	uint32_t i,ret;
 	uint32_t k[9]={0};
 	uint8_t data_temp[84]={0};
@@ -1370,7 +1361,7 @@
 	if(ret != RET_ECC_POINT_SUCCESS)
 		return RET_SM2_ENC_FAILURE;
  #ifdef SM2_DEBUG
-	MyPrintf("\n ecc_pmul_calc:%c%c%c%c\n",ret,ret>>8,ret>>16,ret>>24);	
+	MyPrintf("\n ecc_pmul_calc:%c%c%c%c\n",ret,ret>>8,ret>>16,ret>>24);
 	MyPrintf("pb:\n");
 	MyPrintf("x:\n");
 	for(i=0;i<para_t.len_words;i++)
@@ -1383,7 +1374,7 @@
 	mem_rollcpy_r_char(data_temp + key_bytes_len,(uint8_t *)pb.y,key_bytes_len,GetTRNGData());
 	ret = SM2_KDF(output ,ilen,data_temp, key_bytes_len * 2);
 #ifdef SM2_DEBUG
- 	MyPrintf("\n ecc_pmul_calc:%c%c%c%c\n",ret,ret>>8,ret>>16,ret>>24);	
+ 	MyPrintf("\n ecc_pmul_calc:%c%c%c%c\n",ret,ret>>8,ret>>16,ret>>24);
 	MyPrintf("t:\n");
 	for(i=0;i<ilen;i++)
 		MyPrintf("%02x ",  output[i]);	MyPrintf("\n");
Index: yc_sm3.h
===================================================================
--- /YC3121_SDK/fw/crypt/yc_sm3.h	(revision 797)
+++ /YC3121_SDK/fw/crypt/yc_sm3.h	(working copy)
@@ -25,9 +25,9 @@
 
 /*
  * @brief  sm3 hash check
- * @param  output     : output data buffer 
+ * @param  output     : output data buffer
  * @param  input      : input data buffer
- * @param  ibytes     : size of input data (when istep=0~1 ibytes must 64 multiples) 
+ * @param  ibytes     : size of input data (when istep=0~1 ibytes must 64 multiples)
  * @param  totalbytes : size of all input datas
  * @param  istep      : 0~2
  * @return SM3_SUCCESS or SM3_BUSY or SM3_FAILE
@@ -36,8 +36,8 @@
 
 /*
  * @brief  sm3 hash check
- * @param  output : output data buffer 
- * @param  input  : input data 
+ * @param  output : output data buffer
+ * @param  input  : input data
  * @param  istep  : number of data
  * @param  isend  : is last data
  * @return SM3_SUCCESS or SM3_BUSY or SM3_FAILE
@@ -46,7 +46,7 @@
 
 /*
  * @brief  sm3-mac
- * @param  output  : output data buffer 
+ * @param  output  : output data buffer
  * @param  input   : input data  buffer
  * @param  ibytes  : size of input buffer
  * @param  key     : key buffer
Index: yc_sm3.c
===================================================================
--- /YC3121_SDK/fw/crypt/yc_sm3.c	(revision 797)
+++ /YC3121_SDK/fw/crypt/yc_sm3.c	(working copy)
@@ -8,14 +8,14 @@
 uint32_t SM3(uint8_t *output, uint8_t *input,uint32_t ibytes)
 {
 	int i, j, k, maxlen;
-	
+
 	maxlen = 64;
 	for(k = 0;k<(ibytes/maxlen*maxlen);k = k+maxlen)
 	{
 		for(i=j=0;i<maxlen;i++,j++)
 		{
 			SHA_BDATA(j) = input[i + k];
-			if((j & 3) == 3 && maxlen == 64) 
+			if((j & 3) == 3 && maxlen == 64)
 			{
 				SHA_BDATA(j+1) = 0;
 				SHA_BDATA(j+2) = 0;
@@ -30,18 +30,18 @@
 #endif
 		SHA_CTRL = 0x05 | 0x20 | (k > 0 ? 0x10 : 0);
 		while(SHA_CTRL & 0x80);
-#ifdef SM3_DEBUG		
+#ifdef SM3_DEBUG
 		for(i=0;i<16;i++)
 			MyPrintf("%08x ",SHA_RESULT(i));	 MyPrintf("\n*....&&..*\n");
 #endif
 	}
-	
+
 	if((ibytes -k)<56)
 	{
-		for(i = j=0;i < (ibytes -k);i++,j++)		
+		for(i = j=0;i < (ibytes -k);i++,j++)
 		{
 			SHA_BDATA(j) = input[k+i];
-			if((j & 3) == 3 && maxlen == 64) 
+			if((j & 3) == 3 && maxlen == 64)
 			{
 				SHA_BDATA(j+1) = 0;
 				SHA_BDATA(j+2) = 0;
@@ -52,22 +52,22 @@
 		}
 		SHA_BDATA(j) = 0x80;
 		for(j++;j<120;j++)
-			SHA_BDATA(j) = 0;	
-		for(i = 0;i <4;i++)				
+			SHA_BDATA(j) = 0;
+		for(i = 0;i <4;i++)
 			SHA_BDATA(120+i) = (ibytes*8) >> (3 -i)*8;
-#ifdef SM3_DEBUG		
+#ifdef SM3_DEBUG
 		for(i=0;i<32;i++)
 			MyPrintf("%08x ",SHA_DATA(i));	 MyPrintf("\n*$*\n");
-#endif			
+#endif
 		SHA_CTRL = 0x05 | 0x20 | (k > 0 ? 0x10 : 0);
 		while(SHA_CTRL & 0x80);
-	}		
+	}
 	else
 	{
-		for(i = j=0;i < (ibytes -k);i++,j++)		
+		for(i = j=0;i < (ibytes -k);i++,j++)
 		{
 			SHA_BDATA(j) = input[k+i];
-			if((j & 3) == 3 && maxlen == 64) 
+			if((j & 3) == 3 && maxlen == 64)
 			{
 				SHA_BDATA(j+1) = 0;
 				SHA_BDATA(j+2) = 0;
@@ -78,31 +78,31 @@
 		}
 		SHA_BDATA(j) = 0x80;
 		for(j++;j<128;j++)
-			SHA_BDATA(j) = 0;	
-#ifdef SM3_DEBUG		
+			SHA_BDATA(j) = 0;
+#ifdef SM3_DEBUG
 		for(i=0;i<32;i++)
 			MyPrintf("%08x ",SHA_DATA(i));	 MyPrintf("\n*$*\n");
 #endif
 		SHA_CTRL = 0x05 | 0x20 | (k > 0 ? 0x10 : 0);
-		while(SHA_CTRL & 0x80);	
-#ifdef SM3_DEBUG		
+		while(SHA_CTRL & 0x80);
+#ifdef SM3_DEBUG
 		for(i=0;i<16;i++)
 			MyPrintf("%08x ",SHA_RESULT(i));	 MyPrintf("\n*=*\n");
 #endif
 		for(j=0;j<32;j++)
-			SHA_DATA(j) = 0;	
-					
-		for(i = 0;i <4;i++)				
+			SHA_DATA(j) = 0;
+
+		for(i = 0;i <4;i++)
 			SHA_BDATA(120+i) = (ibytes*8) >> (3 -i)*8;
-#ifdef SM3_DEBUG		
+#ifdef SM3_DEBUG
 		for(i=0;i<32;i++)
 			MyPrintf("%08x ",SHA_DATA(i));	 MyPrintf("\n*$*\n");
 #endif
 		SHA_CTRL = 0x05 | 0x20 | (0x10);
-		while(SHA_CTRL & 0x80);	
+		while(SHA_CTRL & 0x80);
 	}
-	
-#ifdef SM3_DEBUG		
+
+#ifdef SM3_DEBUG
 		for(i=0;i<16;i++)
 			MyPrintf("%08x ",SHA_RESULT(i));	 MyPrintf("\n*=*\n");
 #endif
@@ -120,9 +120,9 @@
 
 /*
  * @brief:sm3 hash check
- * @param:output: output data buffer 
+ * @param:output: output data buffer
  * @param:input	: input data buffer
- * @param:ibytes: size of input data (when istep=0~1 ibytes must 64 multiples) 
+ * @param:ibytes: size of input data (when istep=0~1 ibytes must 64 multiples)
  * @param:totalbytes : size of all input datas
  * @param:istep : 0~2
  * @return: SM3_SUCCESS or SM3_BUSY or SM3_FAILE
@@ -130,12 +130,12 @@
 uint32_t SM3_Enhance(uint8_t *output, uint8_t *input,uint32_t ibytes,uint32_t totalbytes,uint32_t istep)
 {
 	int i, j, maxlen;
-	
+
 	maxlen = 64;
 
 	enable_clock(CLKCLS_SHA);
-	if(((istep <  2) && (ibytes != maxlen)) || 
-	   ((istep == 2) && (ibytes >  maxlen)) || 
+	if(((istep <  2) && (ibytes != maxlen)) ||
+	   ((istep == 2) && (ibytes >  maxlen)) ||
 	   ( istep >  2))
 	{
 		return RET_SM3_FAILE;
@@ -146,7 +146,7 @@
 		for(i=j=0;i<maxlen;i++,j++)
 		{
 			SHA_BDATA(j) = input[i];
-			if((j & 3) == 3 && maxlen == 64) 
+			if((j & 3) == 3 && maxlen == 64)
 			{
 				SHA_BDATA(j+1) = 0;
 				SHA_BDATA(j+2) = 0;
@@ -160,14 +160,14 @@
 		ibytes = 0;
 	}
 
-	if(2 == istep) 
+	if(2 == istep)
 	{
 		if((ibytes) < 56)
 		{
-			for(i = j=0;i < (ibytes);i++,j++)		
+			for(i = j=0;i < (ibytes);i++,j++)
 			{
 				SHA_BDATA(j) = input[i];
-				if((j & 3) == 3 && maxlen == 64) 
+				if((j & 3) == 3 && maxlen == 64)
 				{
 					SHA_BDATA(j+1) = 0;
 					SHA_BDATA(j+2) = 0;
@@ -178,18 +178,18 @@
 			}
 			SHA_BDATA(j) = 0x80;
 			for(j++;j<120;j++)
-				SHA_BDATA(j) = 0;	
-			for(i = 0;i <4;i++)				
-				SHA_BDATA(120+i) = (totalbytes*8) >> (3 -i)*8;			
+				SHA_BDATA(j) = 0;
+			for(i = 0;i <4;i++)
+				SHA_BDATA(120+i) = (totalbytes*8) >> (3 -i)*8;
 			SHA_CTRL = 0x05 | 0x20 | 0x10;
 			while(SHA_CTRL & 0x80);
-		}		
+		}
 		else
 		{
-			for(i = j=0;i < (ibytes);i++,j++)		
+			for(i = j=0;i < (ibytes);i++,j++)
 			{
 				SHA_BDATA(j) = input[i];
-				if((j & 3) == 3 && maxlen == 64) 
+				if((j & 3) == 3 && maxlen == 64)
 				{
 					SHA_BDATA(j+1) = 0;
 					SHA_BDATA(j+2) = 0;
@@ -200,16 +200,16 @@
 			}
 			SHA_BDATA(j) = 0x80;
 			for(j++;j<128;j++)
-				SHA_BDATA(j) = 0;	
+				SHA_BDATA(j) = 0;
 			SHA_CTRL = 0x05 | 0x20 | 0x10;
-			while(SHA_CTRL & 0x80);	
+			while(SHA_CTRL & 0x80);
 			for(j=0;j<32;j++)
-				SHA_DATA(j) = 0;	
-						
-			for(i = 0;i <4;i++)				
+				SHA_DATA(j) = 0;
+
+			for(i = 0;i <4;i++)
 				SHA_BDATA(120+i) = (totalbytes*8) >> (3 -i)*8;
 			SHA_CTRL = 0x05 | 0x20 | (0x10);
-			while(SHA_CTRL & 0x80);	
+			while(SHA_CTRL & 0x80);
 		}
 		for(i = 14, j = 0;i >= 0;i -= 2, j+=4)
 		{
@@ -219,7 +219,7 @@
 			output[j+3] = SHA_RESULT(i);
 		}
 	}
-	
+
 	if(istep >  2)
 	{
 		return RET_SM3_FAILE;
@@ -229,8 +229,8 @@
 }
 /*
  * @brief:sm3 hash check
- * @param:output: output data buffer 
- * @param:input	: input data 
+ * @param:output: output data buffer
+ * @param:input	: input data
  * @param:istep: number of data
  * @param:isend : is last data
  * @return: SM3_SUCCESS or SM3_BUSY or SM3_FAILE
@@ -238,12 +238,12 @@
 uint32_t SM3_BYTE(uint8_t *output, uint8_t input,uint32_t istep,uint8_t isend)
 {
 	int i, j, maxlen,bytes;
-	
+
 	enable_clock(CLKCLS_SHA);
 
 	i = istep % 64;
 	j = ((i/4)*8 + i%4);
-	
+
 	SHA_BDATA(j) = input;
 	if((istep & 3) == 3)
 	{
@@ -261,17 +261,17 @@
 	}
 
 	bytes = istep + 1;
-	
+
 	if(isend)
 	{
 		j = (j == 127) ? 0 : j+1;
-		
+
 		SHA_BDATA(j) = 0x80;
 		if((bytes%64) < 56)
 		{
 			for(j++;j<120;j++)
-				SHA_BDATA(j) = 0;	
-			for(i = 0;i <4;i++)				
+				SHA_BDATA(j) = 0;
+			for(i = 0;i <4;i++)
 				SHA_BDATA(120+i) = (bytes*8) >> (3 -i)*8;
 			SHA_CTRL = 0x05 | 0x20 | (istep >= 63 ? 0x10 : 0);
 			while(SHA_CTRL & 0x80);
@@ -281,18 +281,18 @@
 			for(j++;j<128;j++)
 				SHA_BDATA(j) = 0;
 			SHA_CTRL = 0x05 | 0x20 | (istep >= 63 ? 0x10 : 0);
-			while(SHA_CTRL & 0x80);	
+			while(SHA_CTRL & 0x80);
 
 			for(j=0;j<32;j++)
-			SHA_DATA(j) = 0;	
-					
-			for(i = 0;i <4;i++)				
+			SHA_DATA(j) = 0;
+
+			for(i = 0;i <4;i++)
 				SHA_BDATA(120+i) = (bytes*8) >> (3 -i)*8;
-			
+
 			SHA_CTRL = 0x05 | 0x20 | (0x10);
 			while(SHA_CTRL & 0x80);
 		}
-		
+
 		for(i = 14, j = 0;i >= 0;i -= 2, j+=4)
 		{
 			output[j  ] = SHA_RESULT(i)>>24;
@@ -352,7 +352,7 @@
 						SM3_BYTE(k0, key[i],i,(i==key_len-1)?1:0);
 					}
 					sm3_mac_step += SM3_STEP1;
-				}	
+				}
 			}
 			else
 			{
@@ -436,7 +436,7 @@
 	{
 		return RET_SM3_MAC_SUCCESS;
 	}
-SM3_MAC_CALA_FAILURE:	
+SM3_MAC_CALA_FAILURE:
 	memset(output,0,32);
 	memset(tmp,0,32);
 	memset(k0,0,32);
Index: yc_sm4.h
===================================================================
--- /YC3121_SDK/fw/crypt/yc_sm4.h	(revision 797)
+++ /YC3121_SDK/fw/crypt/yc_sm4.h	(working copy)
@@ -17,13 +17,13 @@
 #define RET_SM4_RESULT_CHECK_ERROR  (('S'<<24)|('4'<<16)|('R'<<8)|('C'))
 
 
-#define SM4_TYPE_DES_ENC            (('4'<<24)|('T'<<16)|('D'<<8)|('E'))    
-#define SM4_TYPE_DES_DEC            (('4'<<24)|('T'<<16)|('D'<<8)|('D'))    
+#define SM4_TYPE_DES_ENC            (('4'<<24)|('T'<<16)|('D'<<8)|('E'))
+#define SM4_TYPE_DES_DEC            (('4'<<24)|('T'<<16)|('D'<<8)|('D'))
 
 
 #define SM4_KEY_SIZE  (128 / 8)
 #define SM4_IV_SIZE   (128 / 8)
-	
+
 typedef uint8_t SM4_KeyTypeDef[SM4_KEY_SIZE];
 typedef uint8_t SM4_IvTypeDef[SM4_IV_SIZE];
 
@@ -41,9 +41,9 @@
   * @param	iv        : initialization vector
   * @retval SM4 return value
   */
-uint32_t SM4_Enc(PACK_ModeTypeDef pack_mode, 
-                 uint8_t *output, uint32_t obytes, 
-                 uint8_t *input, uint32_t ibytes, 
+uint32_t SM4_Enc(PACK_ModeTypeDef pack_mode,
+                 uint8_t *output, uint32_t obytes,
+                 uint8_t *input, uint32_t ibytes,
                  SM4_KeyTypeDef key, SM4_IvTypeDef iv,
                  rng_callback f_rng, void *p_rng);
 
@@ -61,9 +61,9 @@
   * @param	iv        : initialization vector
   * @retval SM4 return value
   */
-uint32_t SM4_Dec(PACK_ModeTypeDef pack_mode, 
-                 uint8_t *output, uint32_t obytes, 
-                 uint8_t *input, uint32_t ibytes, 
+uint32_t SM4_Dec(PACK_ModeTypeDef pack_mode,
+                 uint8_t *output, uint32_t obytes,
+                 uint8_t *input, uint32_t ibytes,
                  SM4_KeyTypeDef key, SM4_IvTypeDef iv,
                  rng_callback f_rng, void *p_rng);
 
Index: yc_sm4.c
===================================================================
--- /YC3121_SDK/fw/crypt/yc_sm4.c	(revision 797)
+++ /YC3121_SDK/fw/crypt/yc_sm4.c	(working copy)
@@ -9,7 +9,7 @@
 	return 0;
 }
 
-uint32_t SM4_common(PACK_ModeTypeDef pack_mode,uint32_t type_mode,  uint8_t *output, uint32_t obytes, 
+uint32_t SM4_common(PACK_ModeTypeDef pack_mode,uint32_t type_mode,  uint8_t *output, uint32_t obytes,
 					 uint8_t *input, uint32_t ibytes,  SM4_KeyTypeDef key, SM4_IvTypeDef iv,
 					 rng_callback f_rng, void *p_rng)
 {
@@ -18,7 +18,7 @@
 	uint32_t count2 = 0;
 
 	uint32_t sm4_flow_flag = 0;
-	
+
 	if(ibytes%16 != 0 || ibytes == 0)
 		return RET_SM4_INPUT_SIZE_ERROR;
 	if(obytes < ibytes || obytes == 0)
@@ -35,22 +35,22 @@
 			return RET_SM4_FAILURE;
 		}
 	#endif
-	
+
 	SM4_REG0 = 0x09;
-	if(type_mode == SM4_TYPE_DES_ENC)//		
+	if(type_mode == SM4_TYPE_DES_ENC)//
 		SM4_REG1 = 1;
-	else	if(type_mode == SM4_TYPE_DES_DEC )//	
+	else	if(type_mode == SM4_TYPE_DES_DEC )//
 		SM4_REG1 = 0;
 	else
 		return RET_SM4_FAILURE;
 
-/*	if(pack_mode == CBC)//		
+/*	if(pack_mode == CBC)//
 		{
 			SM4_REG1 |= 0X02;
 			for (i=0;i<4;i++)
 				SM4_IV0[i]=(iv[i*4]<<24)+(iv[i*4+1]<<16)+(iv[i*4+2]<<8)+(iv[i*4+3]);
 		}
-	else	if(pack_mode == ECB )//	
+	else	if(pack_mode == ECB )//
 		{
 			SM4_REG1 |= 0;
 			for (i=0;i<4;i++)
@@ -61,7 +61,7 @@
 */
 	if(!checkkey(key))
 		return RET_SM4_KEY_IS_NULL;
-	
+
 	for (i=0;i<4;i++)
 	{
 		SM4_KEY0[i]=(key[i*4]<<24)+(key[i*4+1]<<16)+(key[i*4+2]<<8)+(key[i*4+3]);
@@ -89,7 +89,7 @@
 	 				SM4_IV0[i]=(iv[i*4]<<24)+(iv[i*4+1]<<16)+(iv[i*4+2]<<8)+(iv[i*4+3]);
 	  			}
 			}
-			else 
+			else
 			{
 				for (i=0;i<4;i++)
 					SM4_IV0[i]=(output[i*4+j-16]<<24)+(output[i*4+j-16+1]<<16)+(output[i*4+j-16+2]<<8)+(output[i*4+j-16+3]);
@@ -106,7 +106,7 @@
 	 				SM4_IV0[i]=(iv[i*4]<<24)+(iv[i*4+1]<<16)+(iv[i*4+2]<<8)+(iv[i*4+3]);
 	  			}
 			}
-			else 
+			else
 			{
 				for (i=0;i<4;i++)
 					SM4_IV0[i]=(input[i*4+j-16]<<24)+(input[i*4+j-16+1]<<16)+(input[i*4+j-16+2]<<8)+(input[i*4+j-16+3]);
@@ -148,15 +148,15 @@
 			count2 = count1;
 		#endif
 /*
- MyPrintf("\n DATA \n");	
+ MyPrintf("\n DATA \n");
  for(i=0;i<4;i++)
- 	MyPrintf("%08x ",SM4_DATA0[i]);	MyPrintf("\n");	
+ 	MyPrintf("%08x ",SM4_DATA0[i]);	MyPrintf("\n");
 */
 		#ifdef SM4_FLOW_CONTROL
 			sm4_flow_flag = 0XAA55;
 		#endif
-		
-		SM4_MR= 0; 
+
+		SM4_MR= 0;
 		SM4_IER = 1;
 		SM4_REG0 |= 0x06;
 		while(!(SM4_MR& 0x01));
@@ -169,10 +169,10 @@
 		#endif
 		//	MyPrintf("oooo\n ");
 
-//MyPrintf("\n RESULT \n");	
+//MyPrintf("\n RESULT \n");
 //for(i=0;i<4;i++)
-//	MyPrintf("%08x ",SM4_DATA0[i]);	MyPrintf("\n");	
-		
+//	MyPrintf("%08x ",SM4_DATA0[i]);	MyPrintf("\n");
+
 		for (i=0;i<4;i++)
 		{
 			output[(i<<2)+j]=SM4_DATA0[i]>>24;
@@ -190,13 +190,13 @@
 			}
 			count1 = count2;
 		#endif
-	}	
+	}
 
 	#ifdef SM4_FLOW_CONTROL
 		sm4_flow_flag = 0X55AA55;
 	#endif
-	
-	disable_clock(CLKCLS_SM4);	
+
+	disable_clock(CLKCLS_SM4);
 
 	#ifdef SM4_FLOW_CONTROL
 		if (sm4_flow_flag != 0X55AA55)
@@ -207,18 +207,18 @@
 	return RET_SM4_SUCCESS;
 }
 
-uint32_t SM4_Enc(PACK_ModeTypeDef pack_mode,  uint8_t *output, uint32_t obytes, 
+uint32_t SM4_Enc(PACK_ModeTypeDef pack_mode,  uint8_t *output, uint32_t obytes,
 					 uint8_t *input, uint32_t ibytes,  SM4_KeyTypeDef key, SM4_IvTypeDef iv,
 					 rng_callback f_rng, void *p_rng)
 {
 	return SM4_common( pack_mode, SM4_TYPE_DES_ENC,output, obytes,  input, ibytes, key, iv, f_rng, p_rng);
 }
 
-uint32_t SM4_Dec(PACK_ModeTypeDef pack_mode, uint8_t *output, uint32_t obytes, 
+uint32_t SM4_Dec(PACK_ModeTypeDef pack_mode, uint8_t *output, uint32_t obytes,
 					uint8_t *input, uint32_t ibytes, SM4_KeyTypeDef key, SM4_IvTypeDef iv,
 					rng_callback f_rng, void *p_rng)
 {
-	
+
 	return SM4_common( pack_mode, SM4_TYPE_DES_DEC,output, obytes,  input, ibytes, key, iv, f_rng, p_rng);
 }
 
