Index: libyc_crypt.a
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
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);
@@ -39,7 +39,7 @@
 * Return value: none
 ***************************************************************************
 */
-#ifdef AMBA 
+#ifdef AMBA
 void calc_interrupt(void)
 {
 	REINT |= REINT_rsa_int;
@@ -59,13 +59,13 @@
 */
 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,8 +73,8 @@
 ***************************************************************************
 * 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
@@ -83,7 +83,7 @@
        		0 - Duty Ratio 1/2
        		1 - Duty Ratio 1/4
     	bit3:
-       		0 - disable the measure of using fixed time in modular exponentiation. 
+       		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 +110,7 @@
 	//select hardware function and run
 	REFR = index;
 	RECR |= RECR_start;
-	
+
 	if(RECR & RECR_idle_run) //idlerun
 	{
 		do{
@@ -129,13 +129,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;
 }
 
 /*
@@ -145,7 +145,7 @@
 * 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 
+* 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 +155,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 +182,7 @@
 		mrs i,CPSR            //read the carrying from CPSR
 	}
 	carry=(i>>29) & 1;
-*/	
+*/
 
 	return carry;
 }
@@ -193,7 +193,7 @@
 * 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 
+* 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 +204,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 +220,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"
@@ -259,7 +259,7 @@
 		 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 
+* 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 +283,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 +299,7 @@
 	{
 		*(result+i) = *pdata++;
 	}
-	
+
 }
 
 
@@ -311,7 +311,7 @@
 		 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 
+* 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
 ***************************************************************************
@@ -339,7 +339,7 @@
 		 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 
+* 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
 ***************************************************************************
@@ -362,7 +362,7 @@
 * 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 
+* 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 +385,7 @@
 	{
 		result[i] = a[i] ^b[i];
 	}
-	
+
 }
 
 /*
@@ -394,9 +394,9 @@
 * 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_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 
+* 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,37 +407,37 @@
 {
 	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 
+* 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_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 
+* 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.
@@ -450,16 +450,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)
@@ -475,9 +475,9 @@
 * 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_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 
+* 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
@@ -497,7 +497,7 @@
 		 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 
+* 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
@@ -508,7 +508,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 +521,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)
@@ -537,9 +537,9 @@
 * 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_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 
+* 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
@@ -560,7 +560,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)
@@ -575,14 +575,14 @@
 * 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 
+* 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 +591,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)
@@ -616,7 +616,7 @@
 * 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 
+* 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
@@ -634,7 +634,7 @@
 * 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 
+* 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
@@ -645,7 +645,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 +661,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)
@@ -681,7 +681,7 @@
 * 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 
+* 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
@@ -699,7 +699,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 +714,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)
@@ -732,7 +732,7 @@
 		 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 
+* 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
@@ -743,7 +743,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 +756,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)
@@ -778,7 +778,7 @@
 		 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 
+* 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
@@ -793,12 +793,12 @@
 /*
 ***************************************************************************
 * Name: calc_modinv
-* Description: Perform modular inversion in prime field, and check if the 
+* 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 
+* 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
@@ -810,20 +810,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;
@@ -855,7 +855,7 @@
 * 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 
+* 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
@@ -872,8 +872,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,7 +888,7 @@
 * 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 
+* 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
@@ -907,10 +907,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,7 +921,7 @@
 * 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 
+* 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
@@ -940,7 +940,7 @@
 	//
 	RECFR=1;
 	value=calc_run(FUNC_MODINV_BIN);
-	
+
 	if (value!=RET_CALC_IMPLEMENT_SUCCESS)
 		return value;
 	if(result != NULL)
@@ -953,9 +953,9 @@
 * 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. 
+		 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 
+* 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 +968,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 +982,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 +1009,7 @@
 		else
 			bitlen--;
 	}
-	
+
 	return bitlen;
 }
 /*
@@ -1020,7 +1020,7 @@
 		 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 
+* 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 +1032,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;
-	    
+
 		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
@@ -1127,19 +1127,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 +1148,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,33 +1156,33 @@
 	*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])
@@ -1194,23 +1194,23 @@
 	        			return SMALLER;
 	        }
 	   }
-	    return EQUAL;   
-} 
+	    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)
@@ -1218,7 +1218,7 @@
 		else
 	 		return  SMALLER;
 
-} 
+}
 
 /*
 void revstr(char *str, size_t len)
@@ -1243,7 +1243,7 @@
 
 void mem_set(volatile unsigned int *s, unsigned int c, unsigned int n)
 {
-	while (n > 0) 
+	while (n > 0)
 	{
 		*s++ = c;
 		--n;
@@ -1256,14 +1256,14 @@
   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:
@@ -1308,7 +1308,7 @@
   uint32_t icnt = 0;
   uint32_t tmp = wlen;
   uint32_t StartPosition;
-  
+
   if(wlen == 0)
     return CMPERROR;
   cpu_open_uniform_branch_timing();
@@ -1455,7 +1455,7 @@
 	uint32_t tmp = wlen;
 	uint32_t StartPosition;
 	uint32_t temp=0;
-	
+
 	if(wlen == 0)
 		return ;
 	if(content == result)
@@ -1464,7 +1464,7 @@
 	cpu_open_branch_self();
 
 	StartPosition = startflag%wlen;
-		
+
 	icnt = StartPosition;
 	tmp = 0;
 s1:
@@ -1485,7 +1485,7 @@
 	tmp+=1;
 	goto s3;
 s4:
-	__asm("NOP");	
+	__asm("NOP");
 	cpu_close_branch_self();
 	cpu_close_uniform_branch_timing();
 	temp = 0;
@@ -1497,7 +1497,7 @@
 	uint32_t tmp = wlen;
 	uint32_t StartPosition;
 	uint8_t temp=0;
-	
+
 	if(wlen == 0)
 		return ;
 	if(content == result)
@@ -1526,7 +1526,7 @@
 	tmp+=1;
 	goto s3;
 s4:
-	__asm("NOP");	
+	__asm("NOP");
 	cpu_close_branch_self();
 	cpu_close_uniform_branch_timing();
 	temp = 0;
@@ -1558,7 +1558,7 @@
 		__asm("NOP");
 }
 
-#define CRYPT_LIB_VERSION 0x00010003
+#define CRYPT_LIB_VERSION 0x00010004
 uint32_t CRYPT_GetVersion(void)
 {
 	return CRYPT_LIB_VERSION;
Index: yc_crypt.lib
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
